Skip to content

Commit

Permalink
126 minor fixes (#127)
Browse files Browse the repository at this point in the history
* Fix warning spectral_profile

Fix README

Move testing files to subfolders to mimic src structure

* Deleted copyright notice at the beginning of each file

* Changed __eq__ (and __ne__) for function is_equal_cell

* Fix conftest imports
  • Loading branch information
JosePizarro3 authored Sep 25, 2024
1 parent 349d80f commit 5d162aa
Show file tree
Hide file tree
Showing 46 changed files with 70 additions and 802 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@

# `nomad-simulations`

This is a plugin for [NOMAD](https://nomad-lab.eu) which contains the base sections definitions for materials science simulations. This schema can be used at any prefered level by the user, it can be modified and extended, and we welcome external collaborators.
The `nomad-simulations` is an open-source Python package for managing Materials Science simulation data. It is following the plugin architechture of [NOMAD](https://nomad-lab.eu). This package contains a set of section definitions (Python classes) with quantities (attributes) and methods defined to automate data extraction from different simulation codes. These section definitions can be used at any prefered level by the user, they can be modified and extended, and we welcome external collaborators.

Read more in the [official documentation](https://nomad-coe.github.io/nomad-simulations/) page.


## Getting started

`nomad-simulations` can be installed as a PyPI package using `pip`:

> [!WARNING]
> Unfortunately, the current plugin mechanism is not supported by the latest nomad-lab version on PyPI and therefore an index url pointing to the NOMAD Gitlab registry needs to be added.
```sh
pip install nomad-simulations
pip install nomad-simulations --index-url https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple
```


Expand Down Expand Up @@ -49,6 +55,11 @@ The plugin is still under development. If you would like to contribute, install
uv pip install -e '.[dev]'
```

**Note:** If you do not use `uv`, you need to add the `--index-url` flag as in the PyPI command for installing the package:
```sh
pip install -e '.[dev]' --index-url https://gitlab.mpcdf.mpg.de/api/v4/projects/2187/packages/pypi/simple
```


### Run the tests

Expand Down Expand Up @@ -139,7 +150,7 @@ Read the [NOMAD plugin documentation](https://nomad-lab.eu/prod/v1/staging/docs/
Modify the script under `/nomad/scripts/install_default_plugins.sh` and add the path to this repository pointing to the `@develop` branch:
```sh
<other-content-in-install_default_plugins.sh...>
pip install git+https://github.com/nomad-coe/nomad-simulations.git@develop
git+https://github.com/nomad-coe/nomad-simulations.git@develop
```

Then, go to your NOMAD folder, activate your NOMAD virtual environment and run:
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from nomad.config.models.plugins import SchemaPackageEntryPoint
from pydantic import Field

Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/atoms_state.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING, Any, Optional, Union

import ase
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/general.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/model_method.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import re
from typing import TYPE_CHECKING, Optional

Expand Down
53 changes: 24 additions & 29 deletions src/nomad_simulations/schema_packages/model_system.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import re
from typing import TYPE_CHECKING, Optional

Expand Down Expand Up @@ -308,7 +290,14 @@ def _check_positions(self, positions_1, positions_2) -> list:
break
return check_positions

def __eq__(self, other) -> bool:
def is_equal_cell(self, other) -> bool:
"""
Check if the cell is equal to an`other` cell by comparing the `positions`.
Args:
other: The other cell to compare with.
Returns:
bool: True if the cells are equal, False otherwise.
"""
# TODO implement checks on `lattice_vectors` and other quantities to ensure the equality of primitive cells
if not isinstance(other, Cell):
return False
Expand All @@ -322,14 +311,13 @@ def __eq__(self, other) -> bool:
return False
n_positions = len(self.positions)

check_positions = self._check_positions(self.positions, other.positions)
check_positions = self._check_positions(
positions_1=self.positions, positions_2=other.positions
)
if len(check_positions) != n_positions:
return False
return True

def __ne__(self, other) -> bool:
return not self.__eq__(other)

def normalize(self, archive: 'EntryArchive', logger: 'BoundLogger') -> None:
super().normalize(archive, logger)

Expand Down Expand Up @@ -373,16 +361,26 @@ def __init__(self, m_def: 'Section' = None, m_context: 'Context' = None, **kwarg
# Set the name of the section
self.name = self.m_def.name

def __eq__(self, other) -> bool:
def is_equal_cell(self, other) -> bool:
"""
Check if the atomic cell is equal to an`other` atomic cell by comparing the `positions` and
the `AtomsState[*].chemical_symbol`.
Args:
other: The other atomic cell to compare with.
Returns:
bool: True if the atomic cells are equal, False otherwise.
"""
if not isinstance(other, AtomicCell):
return False

# Compare positions using the parent sections's `__eq__` method
if not super().__eq__(other):
if not super().is_equal_cell(other=other):
return False

# Check that the `chemical_symbol` of the atoms in `cell_1` match with the ones in `cell_2`
check_positions = self._check_positions(self.positions, other.positions)
check_positions = self._check_positions(
positions_1=self.positions, positions_2=other.positions
)
try:
for atom in check_positions:
element_1 = self.atoms_state[atom[0]].chemical_symbol
Expand All @@ -393,9 +391,6 @@ def __eq__(self, other) -> bool:
return False
return True

def __ne__(self, other) -> bool:
return not self.__eq__(other)

def to_ase_atoms(self, logger: 'BoundLogger') -> Optional[ase.Atoms]:
"""
Generates an ASE Atoms object with the most basic information from the parsed `AtomicCell`
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/numerical_settings.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from itertools import accumulate, chain, tee
from typing import TYPE_CHECKING, Optional, Union

Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/outputs.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING, Optional

import numpy as np
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/physical_property.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from functools import wraps
from typing import TYPE_CHECKING, Any, Optional

Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/properties/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD.
# See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from .band_gap import ElectronicBandGap
from .band_structure import ElectronicBandStructure, ElectronicEigenvalues, Occupancy
from .energies import (
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/properties/band_gap.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING, Optional

import numpy as np
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/properties/band_structure.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING, Optional, Union

import numpy as np
Expand Down
18 changes: 0 additions & 18 deletions src/nomad_simulations/schema_packages/properties/energies.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,3 @@
#
# Copyright The NOMAD Authors.
#
# This file is part of NOMAD. See https://nomad-lab.eu for further info.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from typing import TYPE_CHECKING

import numpy as np
Expand Down
Loading

3 comments on commit 5d162aa

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%39–41
   atoms_state.py1902189%13–15, 201–204, 228, 283–284, 352–353, 355, 537, 549–550, 611–615, 630–634, 641
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   general.py89891%4–7, 121, 185, 295–296, 306
   model_method.py2657771%10–12, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 755, 766, 808–815, 853, 872, 952, 1009, 1084, 1198
   model_system.py2962392%25–27, 378, 572–575, 622–629, 803–804, 1025–1029, 1035–1036, 1044–1045, 1050, 1073
   numerical_settings.py2596176%12–14, 217, 219–220, 223–226, 230–231, 238–241, 250–253, 257–260, 262–265, 270–273, 279–282, 469–496, 571, 606–609, 633, 636, 681, 683–686, 690, 694, 741, 745–766, 821–822, 889
   outputs.py1201092%9–10, 252–255, 295–298, 323, 325, 362, 381
   physical_property.py102793%20–22, 202, 331–333
   variables.py861286%8–10, 98, 121, 145, 167, 189, 211, 233, 256, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%8–10, 135–136
   band_structure.py1232580%9–11, 232–265, 278, 285, 321–322, 325, 372–373, 378
   energies.py42979%7–9, 36, 57, 82, 103, 119, 134
   fermi_surface.py17476%7–9, 40
   forces.py22673%7–9, 36, 56, 79
   greens_function.py991387%7–9, 210–211, 214, 235–236, 239, 260–261, 264, 400
   hopping_matrix.py29583%7–9, 58, 94
   permittivity.py48883%7–9, 97–105
   spectral_profile.py26012851%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 526, 573–576, 592–593, 598–604
   thermodynamics.py752764%7–9, 35, 56, 72, 81, 90, 101, 110, 137, 147, 157, 172–174, 177, 193, 213–215, 218, 234, 254–256, 259
src/nomad_simulations/schema_packages/utils
   utils.py701480%8–11, 65–74, 83–84, 89, 92
TOTAL252449780% 

Tests Skipped Failures Errors Time
401 0 💤 0 ❌ 0 🔥 6.060s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%39–41
   atoms_state.py1902189%13–15, 201–204, 228, 283–284, 352–353, 355, 537, 549–550, 611–615, 630–634, 641
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   general.py89891%4–7, 121, 185, 295–296, 306
   model_method.py2657771%10–12, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 755, 766, 808–815, 853, 872, 952, 1009, 1084, 1198
   model_system.py2962392%25–27, 378, 572–575, 622–629, 803–804, 1025–1029, 1035–1036, 1044–1045, 1050, 1073
   numerical_settings.py2596176%12–14, 217, 219–220, 223–226, 230–231, 238–241, 250–253, 257–260, 262–265, 270–273, 279–282, 469–496, 571, 606–609, 633, 636, 681, 683–686, 690, 694, 741, 745–766, 821–822, 889
   outputs.py1201092%9–10, 252–255, 295–298, 323, 325, 362, 381
   physical_property.py102793%20–22, 202, 331–333
   variables.py861286%8–10, 98, 121, 145, 167, 189, 211, 233, 256, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%8–10, 135–136
   band_structure.py1232580%9–11, 232–265, 278, 285, 321–322, 325, 372–373, 378
   energies.py42979%7–9, 36, 57, 82, 103, 119, 134
   fermi_surface.py17476%7–9, 40
   forces.py22673%7–9, 36, 56, 79
   greens_function.py991387%7–9, 210–211, 214, 235–236, 239, 260–261, 264, 400
   hopping_matrix.py29583%7–9, 58, 94
   permittivity.py48883%7–9, 97–105
   spectral_profile.py26012851%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 526, 573–576, 592–593, 598–604
   thermodynamics.py752764%7–9, 35, 56, 72, 81, 90, 101, 110, 137, 147, 157, 172–174, 177, 193, 213–215, 218, 234, 254–256, 259
src/nomad_simulations/schema_packages/utils
   utils.py701480%8–11, 65–74, 83–84, 89, 92
TOTAL252449780% 

Tests Skipped Failures Errors Time
401 0 💤 0 ❌ 0 🔥 5.723s ⏱️

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py15287%39–41
   atoms_state.py1902189%13–15, 201–204, 228, 283–284, 352–353, 355, 537, 549–550, 611–615, 630–634, 641
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   general.py89891%4–7, 121, 185, 295–296, 306
   model_method.py2657771%10–12, 171–174, 177–184, 276–277, 297, 318–339, 355–381, 384–401, 755, 766, 808–815, 853, 872, 952, 1009, 1084, 1198
   model_system.py2962392%25–27, 378, 572–575, 622–629, 803–804, 1025–1029, 1035–1036, 1044–1045, 1050, 1073
   numerical_settings.py2596176%12–14, 217, 219–220, 223–226, 230–231, 238–241, 250–253, 257–260, 262–265, 270–273, 279–282, 469–496, 571, 606–609, 633, 636, 681, 683–686, 690, 694, 741, 745–766, 821–822, 889
   outputs.py1201092%9–10, 252–255, 295–298, 323, 325, 362, 381
   physical_property.py102793%20–22, 202, 331–333
   variables.py861286%8–10, 98, 121, 145, 167, 189, 211, 233, 256, 276
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%8–10, 135–136
   band_structure.py1232580%9–11, 232–265, 278, 285, 321–322, 325, 372–373, 378
   energies.py42979%7–9, 36, 57, 82, 103, 119, 134
   fermi_surface.py17476%7–9, 40
   forces.py22673%7–9, 36, 56, 79
   greens_function.py991387%7–9, 210–211, 214, 235–236, 239, 260–261, 264, 400
   hopping_matrix.py29583%7–9, 58, 94
   permittivity.py48883%7–9, 97–105
   spectral_profile.py26012851%9–11, 57–60, 95–98, 199–300, 356–368, 393–396, 416, 421–424, 466–502, 526, 573–576, 592–593, 598–604
   thermodynamics.py752764%7–9, 35, 56, 72, 81, 90, 101, 110, 137, 147, 157, 172–174, 177, 193, 213–215, 218, 234, 254–256, 259
src/nomad_simulations/schema_packages/utils
   utils.py701480%8–11, 65–74, 83–84, 89, 92
TOTAL252449780% 

Tests Skipped Failures Errors Time
401 0 💤 0 ❌ 0 🔥 5.760s ⏱️

Please sign in to comment.