Skip to content

Commit 25129cc

Browse files
Extended atom parameter parsing to include chemical_symbol and atomic_number, if available
1 parent eef88b1 commit 25129cc

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

src/nomad_simulation_parsers/parsers/gromacs/log_parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def init_quantities(self):
149149
r'Input Parameters:\s*\n([\s\S]+?)\n\n',
150150
str_operation=str_to_input_parameters,
151151
),
152-
Quantity('maximum_force', r'Norm of force\s*([\s\S]+?)\n\n', flatten=False),
152+
Quantity('maximum_force', r'Maximum force\s*=\s*([\d.eE+\-]+)'),
153153
Quantity(
154154
'step',
155155
r'(Step\s*Time[\s\S]+?Energies[\s\S]+?\n\n)',

src/nomad_simulation_parsers/parsers/gromacs/parser.py

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -593,12 +593,33 @@ def get_atom_labels(self, index: int = 0) -> list[str]:
593593
def get_atom_parameters(self) -> list[dict[str, Any]]:
594594
"""Return per-atom topology parameters as a list of dicts.
595595
596-
Each dict contains 'label' (str) plus, when available from MDAnalysis:
597-
'mass' (float, amu) and 'charge' (float, elementary charge).
596+
Each dict contains:
597+
- 'label' (str): raw force-field site name (e.g. 'OW', 'HW1', 'CA')
598+
- 'element' (str): chemical element symbol (e.g. 'O', 'H', 'C'),
599+
absent for coarse-grained or unresolvable atoms
600+
- 'mass' (float, amu): atomic mass when available from MDAnalysis
601+
- 'charge' (float, elementary charge): partial charge when available
598602
"""
599-
labels = self.get_atom_labels(0)
600-
result: list[dict[str, Any]] = [{'label': lbl} for lbl in labels]
601-
universe = self.data_object.universe
603+
atoms_info = {}
604+
if self.data_object is not None and hasattr(self.data_object, 'get'):
605+
atoms_info = self.data_object.get('atoms_info', {}) or {}
606+
raw_names = atoms_info.get('names', []) or []
607+
elements = atoms_info.get('elements', []) or []
608+
# Fall back to get_atom_labels when atoms_info is not populated (e.g. in tests)
609+
if not raw_names and not elements:
610+
fallback = self.get_atom_labels(0)
611+
raw_names = fallback
612+
elements = fallback
613+
n_atoms = max(len(raw_names), len(elements))
614+
result: list[dict[str, Any]] = []
615+
for i in range(n_atoms):
616+
label = raw_names[i] if i < len(raw_names) else None
617+
element = elements[i] if i < len(elements) else None
618+
entry: dict[str, Any] = {'label': label or element or 'CGX'}
619+
if element and element != 'CGX':
620+
entry['element'] = element
621+
result.append(entry)
622+
universe = getattr(self.data_object, 'universe', None)
602623
if universe is not None:
603624
try:
604625
for i, mass in enumerate(universe.atoms.masses):
@@ -949,7 +970,7 @@ def write_to_archive(self):
949970

950971
self._parse_data_section()
951972

952-
# self._parse_workflow_section()
973+
self._parse_workflow_section()
953974

954975
for parser in [
955976
self._simulation_parser,

src/nomad_simulation_parsers/schema_packages/gromacs.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class Program(general.Program):
9898

9999
class AtomsState(model_system.AtomsState):
100100
add_mapping_annotation(model_system.AtomsState.label, TPR_KEY, '.label')
101+
add_mapping_annotation(model_system.AtomsState.chemical_symbol, TPR_KEY, '.element')
101102
add_mapping_annotation(model_system.AtomsState.mass, TPR_KEY, '.mass', unit='amu')
102103
add_mapping_annotation(
103104
model_system.AtomsState.partial_charge,

0 commit comments

Comments
 (0)