From 05ec8efcd4342931d81b433da131a8d87af32977 Mon Sep 17 00:00:00 2001 From: jrudz Date: Thu, 8 Feb 2024 13:56:57 +0100 Subject: [PATCH] moved imports and more direct check --- atomisticparsers/gromacs/parser.py | 13 ++++++------- atomisticparsers/h5md/parser.py | 9 ++++----- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/atomisticparsers/gromacs/parser.py b/atomisticparsers/gromacs/parser.py index 86bb3b6a..032f36da 100644 --- a/atomisticparsers/gromacs/parser.py +++ b/atomisticparsers/gromacs/parser.py @@ -30,7 +30,7 @@ except Exception: logging.warning("Required module MDAnalysis not found.") MDAnalysis = False - +from ase.symbols import symbols2numbers from nomad.units import ureg from nomad.parsing.file_parser import TextParser, Quantity, FileParser from runschema.run import Run, Program, TimeRun @@ -837,12 +837,11 @@ def get_composition(children_names): ) atom_labels = self.traj_parser.get_atom_labels(n) - try: - from ase import Atoms as ase_atoms - - _ = ase_atoms(symbols=atom_labels) - except Exception: # TODO this check should be moved to the system normalizer in the new schema - atom_labels = ["X" for _ in atom_labels] + if atom_labels is not None: + try: + symbols2numbers(atom_labels) + except KeyError: + atom_labels = ["X"] * len(atom_labels) self.parse_trajectory_step( { diff --git a/atomisticparsers/h5md/parser.py b/atomisticparsers/h5md/parser.py index d0b7b09c..fff8caba 100644 --- a/atomisticparsers/h5md/parser.py +++ b/atomisticparsers/h5md/parser.py @@ -52,6 +52,7 @@ from atomisticparsers.utils import MDParser, MOL from .metainfo.h5md import ParamEntry, CalcEntry, Author from nomad.units import ureg +from ase.symbols import symbols2numbers class HDF5Parser(FileParser): @@ -583,11 +584,9 @@ def parse_system(self): atom_labels = atoms_dict.get("labels") if atom_labels is not None: try: - from ase import Atoms as ase_atoms - - _ = ase_atoms(symbols=atom_labels) - except Exception: # TODO this check should be moved to the system normalizer in the new schema - atoms_dict["labels"] = ["X" for _ in atom_labels] + symbols2numbers(atom_labels) + except KeyError: # TODO this check should be moved to the system normalizer in the new schema + atoms_dict["labels"] = ["X"] * len(atom_labels) topology = None if i_step == 0: # TODO extend to time-dependent bond lists and topologies