Skip to content

Commit 0b00585

Browse files
Fixed system hierarchy not being fully parsed, added tests/data/protein_small, updated tests
1 parent be8797f commit 0b00585

File tree

15 files changed

+13700
-51
lines changed

15 files changed

+13700
-51
lines changed

src/nomad_simulation_parsers/parsers/gromacs/mdanalysis_parser.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,10 @@ def _create_monomer_group(
473473
)
474474
monomer_group.setdefault('sub_systems', []).append(residue)
475475

476+
# Set composition formula as RESTYPE(count)
477+
monomer_count = len(restype_resids)
478+
monomer_group['composition_formula'] = f'{restype}({monomer_count})'
479+
476480
return monomer_group
477481

478482
def _add_residue_hierarchy(

src/nomad_simulation_parsers/parsers/gromacs/parser.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,16 +540,31 @@ def get_subsystems_from_dict(
540540
Returns:
541541
List of subsystem dicts from this level
542542
"""
543+
# Debug: log what we're receiving
544+
source_keys = list(source.keys()) if isinstance(source, dict) else []
545+
has_hierarchy = (
546+
hasattr(self, '_subsystems_hierarchy') and self._subsystems_hierarchy
547+
)
548+
self.logger.info(
549+
'get_subsystems_from_dict called: source_keys=%s, has_hierarchy=%s',
550+
source_keys,
551+
has_hierarchy,
552+
)
543553

544554
# Root call: return the full hierarchy
545555
if hasattr(self, '_subsystems_hierarchy') and self._subsystems_hierarchy:
546556
# Check if this is the root call by looking at source keys
547557
if 'n_atoms' in source and 'sub_systems' not in source:
558+
self.logger.info(
559+
'Returning full hierarchy (%d items)',
560+
len(self._subsystems_hierarchy),
561+
)
548562
result = self._subsystems_hierarchy
549563
return result
550564

551565
# Nested call: extract from dict's sub_systems key
552566
subsystems = source.get('sub_systems', []) if isinstance(source, dict) else []
567+
self.logger.info('Returning nested subsystems (%d items)', len(subsystems))
553568

554569
return subsystems
555570

@@ -723,6 +738,7 @@ def get_sub_systems(
723738
class GromacsArchiveWriter(MDParser):
724739
def __init__(self, **kwargs):
725740
self._simulation_parser = GromacsMetainfoParser()
741+
self._simulation_parser.max_nested_level = 10
726742
self._log_parser = GromacsLogParser(text_parser=GromacsLogTextParser())
727743
self._mdp_parser = GromacsMDPParser(text_parser=GromacsMDPTextParser())
728744
self._edr_parser = GromacsEDRParser(edr_parser=GromacsEDRFileParser())

src/nomad_simulation_parsers/parsers/utils/mdanalysisparser.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def universe(self) -> MDAUniverse | None:
114114
self.mainfile, *self.auxilliary_files, **self.options
115115
)
116116
except Exception as e:
117-
self.logger.warning('Error creating MDAnalysis universe.', exc_info=e)
117+
self.logger.error('Error creating MDAnalysis universe.', exc_info=e)
118118
self.universe_error = e
119119
return self._file_handler
120120

@@ -175,9 +175,11 @@ def parse(self, quantity_key: str = None, **kwargs):
175175
('names', lambda: ['CGX'] * self.universe.atoms.n_atoms),
176176
(
177177
'moltypes',
178-
lambda: self.get_fragtypes()
179-
if hasattr(self.universe.atoms, 'fragments')
180-
else None,
178+
lambda: (
179+
self.get_fragtypes()
180+
if hasattr(self.universe.atoms, 'fragments')
181+
else None
182+
),
181183
),
182184
('molnums', lambda: getattr(self.universe.atoms, 'fragindices', None)),
183185
('resnames', lambda: self._results['atoms_info'].get('resids')),

src/nomad_simulation_parsers/schema_packages/gromacs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,6 @@ class ModelSystem(model_system.ModelSystem):
124124
add_mapping_annotation(model_system.ModelSystem.velocities, TPR_KEY, '.velocities')
125125
add_mapping_annotation(model_system.ModelSystem.positions, TPR_KEY, '.positions')
126126
add_mapping_annotation(model_system.ModelSystem.bond_list, TPR_KEY, '.bond_list')
127-
# sub_systems: recursively extract from nested dicts via function call
128-
# Pass '.@' as first argument (current node dict) to function
129-
add_mapping_annotation(
130-
model_system.ModelSystem.sub_systems,
131-
TPR_KEY,
132-
('get_subsystems_from_dict', ['.@']),
133-
)
134127
add_mapping_annotation(model_system.AtomsState.m_def, TPR_KEY, '.labels')
135128

136129

@@ -141,6 +134,13 @@ class ModelSystem(model_system.ModelSystem):
141134

142135
# Subsystem hierarchy annotations (apply to all ModelSystem instances including
143136
# subsystems)
137+
# sub_systems: recursively extract from nested dicts via function call
138+
# Pass '.@' as first argument (current node dict) to function
139+
add_mapping_annotation(
140+
model_system.ModelSystem.sub_systems,
141+
TPR_KEY,
142+
('get_subsystems_from_dict', ['.@']),
143+
)
144144
add_mapping_annotation(model_system.ModelSystem.name, TPR_KEY, '.name')
145145
add_mapping_annotation(
146146
model_system.ModelSystem.composition_formula, TPR_KEY, '.composition_formula'

0 commit comments

Comments
 (0)