From fc975aef0c80680da78fa908e701df96eeb96dba Mon Sep 17 00:00:00 2001 From: sebastiankloth Date: Thu, 5 May 2022 10:58:37 +0200 Subject: [PATCH] add option to specify charges and masses for .gro files --- mdevaluate/__init__.py | 5 +++-- mdevaluate/reader.py | 7 ++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/mdevaluate/__init__.py b/mdevaluate/__init__.py index c45a209..eba4812 100644 --- a/mdevaluate/__init__.py +++ b/mdevaluate/__init__.py @@ -15,7 +15,7 @@ __version__ = '22.6.dev1' def open(directory='', topology='*.tpr', trajectory='*.xtc', cached=False, - nojump=False, index_file=None): + nojump=False, index_file=None, charges=None, masses=None): """ Open a simulation from a directory. @@ -70,7 +70,8 @@ def open(directory='', topology='*.tpr', trajectory='*.xtc', cached=False, raise FileNotFoundError('Trajectory file could not be identified.') atom_set, frames = reader.open_with_mdanalysis( - top_file, traj_file, cached=cached, index_file=index_file + top_file, traj_file, cached=cached, index_file=index_file, + charges=charges, masses=masses ) coords = coordinates.Coordinates(frames, atom_subset=atom_set) if nojump: diff --git a/mdevaluate/reader.py b/mdevaluate/reader.py index d48da27..5aedb18 100755 --- a/mdevaluate/reader.py +++ b/mdevaluate/reader.py @@ -34,7 +34,8 @@ class NojumpError(Exception): class WrongTopologyError(Exception): pass -def open_with_mdanalysis(topology, trajectory, cached=False, index_file=None): +def open_with_mdanalysis(topology, trajectory, cached=False, index_file=None, + charges=None, masses=None): """Open a the topology and trajectory with mdanalysis.""" uni = mdanalysis.Universe(topology, trajectory, convert_units=False) if cached is not False: @@ -50,8 +51,8 @@ def open_with_mdanalysis(topology, trajectory, cached=False, index_file=None): charges = uni.atoms.charges masses = uni.atoms.masses elif topology.endswith('.gro'): - charges = None - masses = None + charges = charges + masses = masses else: raise WrongTopologyError('Topology file should end with ".tpr" or ".gro"') indices = None