Skip to content

Commit

Permalink
added branch composition to the modelsystem normalizer
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed May 28, 2024
1 parent aa86732 commit 2b9e6b7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
28 changes: 26 additions & 2 deletions src/nomad_simulations/model_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

from nomad import config
from nomad.units import ureg
from nomad.atomutils import Formula, get_normalized_wyckoff, search_aflow_prototype
from nomad.atomutils import Formula, get_normalized_wyckoff, search_aflow_prototype, get_composition

from nomad.metainfo import Quantity, SubSection, SectionProxy, MEnum, Section, Context
from nomad.datamodel.data import ArchiveSection
Expand Down Expand Up @@ -901,6 +901,16 @@ class ModelSystem(System):
""",
)

composition_formula = Quantity(
type=str,
shape=[],
description="""
The overall composition of the system with respect to its subsystems.
The syntax for a system composed of X and Y with x and y components of each,
respectively, is X(x)Y(y).
""",
)

model_system = SubSection(sub_section=SectionProxy('ModelSystem'), repeats=True)

def resolve_system_type_and_dimensionality(
Expand Down Expand Up @@ -967,6 +977,20 @@ def normalize(self, archive, logger) -> None:
if is_not_representative(self, logger):
return

# Traversing the System Hierarchy
def set_branch_composition(system, subsystems):
subsystems_labels = [subsystem.get("branch_label") for subsystem in subsystems]
system.composition = get_composition(subsystems_labels)

def traverse_system_recurs(system):
subsystems = system.get("model_system")
if subsystems:
set_branch_composition(system, subsystems)
for subsystem in subsystems:
traverse_system_recurs(subsystem)

traverse_system_recurs(self)

# Extracting ASE Atoms object from the originally parsed AtomicCell section
if self.cell is None or len(self.cell) == 0:
logger.warning(
Expand Down Expand Up @@ -1000,4 +1024,4 @@ def normalize(self, archive, logger) -> None:
if sec_chemical_formula.m_cache:
self.elemental_composition = sec_chemical_formula.m_cache.get(
'elemental_composition', []
)
)
3 changes: 2 additions & 1 deletion src/nomad_simulations/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ def is_not_representative(model_system, logger: BoundLogger):
if model_system is None:
logger.warning('The `ModelSystem` is empty.')
return None
#? Can we somehow only print this warning once in the case of many systems?
if not model_system.is_representative:
logger.warning('The `ModelSystem` was not found to be representative.')
# logger.warning('The `ModelSystem` was not found to be representative.')
return True
return False

0 comments on commit 2b9e6b7

Please sign in to comment.