diff --git a/src/nomad_simulations/atoms_state.py b/src/nomad_simulations/atoms_state.py index fd3e1382..b30045ed 100644 --- a/src/nomad_simulations/atoms_state.py +++ b/src/nomad_simulations/atoms_state.py @@ -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): @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/src/nomad_simulations/model_system.py b/src/nomad_simulations/model_system.py index c60125f4..f1b80cfe 100644 --- a/src/nomad_simulations/model_system.py +++ b/src/nomad_simulations/model_system.py @@ -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): @@ -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) @@ -290,6 +293,8 @@ class Cell(GeometricSpace): ) def normalize(self, archive, logger) -> None: + if not check_archive(archive, logger): + return super().normalize(archive, logger) @@ -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) @@ -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 ) @@ -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 ) @@ -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 diff --git a/src/nomad_simulations/utils/__init__.py b/src/nomad_simulations/utils/__init__.py index a0a83520..ae2f5acf 100644 --- a/src/nomad_simulations/utils/__init__.py +++ b/src/nomad_simulations/utils/__init__.py @@ -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, +) diff --git a/src/nomad_simulations/utils/utils.py b/src/nomad_simulations/utils/utils.py index 1f116dfc..0b8a2f3b 100644 --- a/src/nomad_simulations/utils/utils.py +++ b/src/nomad_simulations/utils/utils.py @@ -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