Skip to content

Commit

Permalink
moved imports and more direct check
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Feb 8, 2024
1 parent dfe4adf commit 05ec8ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
13 changes: 6 additions & 7 deletions atomisticparsers/gromacs/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
{
Expand Down
9 changes: 4 additions & 5 deletions atomisticparsers/h5md/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 05ec8ef

Please sign in to comment.