Skip to content

Commit f9aa5cb

Browse files
Added parsing of masses and (partial) charges
1 parent fc5dffd commit f9aa5cb

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

src/nomad_simulation_parsers/parsers/gromacs/parser.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,28 @@ def get_atom_labels(self, index: int = 0) -> list[str]:
531531
labels = ['CGX'] * len(labels)
532532
return labels
533533

534+
def get_atom_parameters(self) -> list[dict[str, Any]]:
535+
"""Return per-atom topology parameters as a list of dicts.
536+
537+
Each dict contains 'label' (str) plus, when available from MDAnalysis:
538+
'mass' (float, amu) and 'charge' (float, elementary charge).
539+
"""
540+
labels = self.get_atom_labels(0)
541+
result: list[dict[str, Any]] = [{'label': lbl} for lbl in labels]
542+
universe = self.data_object.universe
543+
if universe is not None:
544+
try:
545+
for i, mass in enumerate(universe.atoms.masses):
546+
result[i]['mass'] = float(mass)
547+
except Exception:
548+
pass
549+
try:
550+
for i, charge in enumerate(universe.atoms.charges):
551+
result[i]['charge'] = float(charge)
552+
except Exception:
553+
pass
554+
return result
555+
534556
def get_outputs(self) -> list[dict[str, Any]]:
535557
outputs = []
536558
for step in self._thermodynamic_steps:
@@ -566,10 +588,15 @@ def get_bond_list(self) -> np.ndarray | None:
566588
return result
567589

568590
def get_configurations(self) -> list[dict[str, Any]]:
591+
# Topology is frame-independent; compute once at index 0.
592+
atom_parameters = self.get_atom_parameters()
593+
n_atoms = self.data_object.get_n_atoms(0)
594+
569595
configurations = []
570596
for n, _ in enumerate(self._trajectory_steps_sampled):
571597
config = dict(
572-
labels=self.get_atom_labels(n),
598+
n_atoms=n_atoms,
599+
labels=atom_parameters,
573600
positions=self.data_object.get_positions(n),
574601
velocities=self.data_object.get_velocities(n),
575602
lattice_vectors=self.data_object.get_lattice_vectors(n),

src/nomad_simulation_parsers/schema_packages/gromacs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,14 @@ class Program(general.Program):
9797

9898

9999
class AtomsState(model_system.AtomsState):
100-
add_mapping_annotation(model_system.AtomsState.label, TPR_KEY, '.@')
100+
add_mapping_annotation(model_system.AtomsState.label, TPR_KEY, '.label')
101+
add_mapping_annotation(model_system.AtomsState.mass, TPR_KEY, '.mass', unit='amu')
102+
add_mapping_annotation(
103+
model_system.AtomsState.partial_charge,
104+
TPR_KEY,
105+
'.charge',
106+
unit='elementary_charge',
107+
)
101108

102109

103110
class AtomicCell(model_system.Representation):

0 commit comments

Comments
 (0)