Skip to content

Commit

Permalink
Added check_archive to utils and normalize() of atoms_state.py and mo…
Browse files Browse the repository at this point in the history
…del_system.py classes
  • Loading branch information
JosePizarro3 committed Mar 12, 2024
1 parent ece52c7 commit 99fb694
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/nomad_simulations/atoms_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from nomad.datamodel.data import ArchiveSection
from nomad.datamodel.metainfo.annotations import ELNAnnotation

from .utils import RussellSaundersState
from .utils import RussellSaundersState, check_archive


class OrbitalsState(ArchiveSection):
Expand Down Expand Up @@ -308,6 +308,8 @@ def resolve_degeneracy(self) -> Optional[int]:
return degeneracy

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
super().normalize(archive, logger)

# General checks for physical quantum numbers and symbols
Expand Down Expand Up @@ -387,6 +389,8 @@ def resolve_occupation(self, logger: BoundLogger) -> Optional[np.float64]:
return None

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
super().normalize(archive, logger)

# Check if n_excited_electrons is between 0 and 1
Expand Down Expand Up @@ -555,6 +559,8 @@ def resolve_u_effective(self, logger: BoundLogger) -> Optional[np.float64]:
return self.u_interaction - self.j_local_exchange_interaction

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
super().normalize(archive, logger)

# Obtain (u, up, j_hunds_coupling) from slater_integrals
Expand Down Expand Up @@ -663,6 +669,8 @@ def resolve_atomic_number(self, logger: BoundLogger) -> Optional[int]:
return None

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
super().normalize(archive, logger)

# Get chemical_symbol from atomic_number and viceversa
Expand Down
15 changes: 14 additions & 1 deletion src/nomad_simulations/model_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
from nomad.datamodel.metainfo.annotations import ELNAnnotation

from .atoms_state import AtomsState
from .utils import get_sibling_section, is_not_representative
from .utils import get_sibling_section, is_not_representative, check_archive


class GeometricSpace(Entity):
Expand Down Expand Up @@ -209,6 +209,9 @@ def get_geometric_space_for_atomic_cell(self, logger: BoundLogger) -> None:
self.volume = cell.volume * ureg.angstrom**3

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return

# Skip normalization for `Entity`
try:
self.get_geometric_space_for_atomic_cell(logger)
Expand Down Expand Up @@ -290,6 +293,8 @@ class Cell(GeometricSpace):
)

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
super().normalize(archive, logger)


Expand Down Expand Up @@ -371,6 +376,8 @@ def to_ase_atoms(self, logger: BoundLogger) -> Optional[ase.Atoms]:
return ase_atoms

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
super().normalize(archive, logger)


Expand Down Expand Up @@ -629,6 +636,8 @@ def resolve_bulk_symmetry(
return primitive_atomic_cell, conventional_atomic_cell

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
atomic_cell = get_sibling_section(
section=self, sibling_section_name='atomic_cell', logger=logger
)
Expand Down Expand Up @@ -718,6 +727,8 @@ def resolve_chemical_formulas(self, formula: Formula) -> None:
self.anonymous = formula.format('anonymous')

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
atomic_cell = get_sibling_section(
section=self, sibling_section_name='atomic_cell', logger=logger
)
Expand Down Expand Up @@ -963,6 +974,8 @@ def resolve_system_type_and_dimensionality(
return system_type, dimensionality

def normalize(self, archive, logger) -> None:
if not check_archive(archive, logger):
return
super().normalize(archive, logger)

# We don't need to normalize if the system is not representative
Expand Down
7 changes: 6 additions & 1 deletion src/nomad_simulations/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from .utils import get_sibling_section, RussellSaundersState, is_not_representative
from .utils import (
get_sibling_section,
RussellSaundersState,
is_not_representative,
check_archive,
)
17 changes: 17 additions & 0 deletions src/nomad_simulations/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,20 @@ def is_not_representative(model_system, logger: BoundLogger = None):
logger.warning('The `ModelSystem` was not found to be representative.')
return True
return False


def check_archive(archive: ArchiveSection, logger: BoundLogger = None):
"""
Checks if the given `Archive` is empty and logs a warning.
Args:
archive (ArchiveSection): The `ArchiveSection` to check.
logger (BoundLogger): The logger to log messages.
Returns:
(bool): True if the archive is empty, False otherwise.
"""
if not archive:
logger.warning('The `archive` is empty.')
return False
return True

0 comments on commit 99fb694

Please sign in to comment.