add option to specify charges and masses for .gro files

This commit is contained in:
sebastiankloth 2022-05-05 10:58:37 +02:00
parent dee05b44f6
commit fc975aef0c
2 changed files with 7 additions and 5 deletions

View File

@ -15,7 +15,7 @@ __version__ = '22.6.dev1'
def open(directory='', topology='*.tpr', trajectory='*.xtc', cached=False, 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. 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.') raise FileNotFoundError('Trajectory file could not be identified.')
atom_set, frames = reader.open_with_mdanalysis( 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) coords = coordinates.Coordinates(frames, atom_subset=atom_set)
if nojump: if nojump:

View File

@ -34,7 +34,8 @@ class NojumpError(Exception):
class WrongTopologyError(Exception): class WrongTopologyError(Exception):
pass 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.""" """Open a the topology and trajectory with mdanalysis."""
uni = mdanalysis.Universe(topology, trajectory, convert_units=False) uni = mdanalysis.Universe(topology, trajectory, convert_units=False)
if cached is not 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 charges = uni.atoms.charges
masses = uni.atoms.masses masses = uni.atoms.masses
elif topology.endswith('.gro'): elif topology.endswith('.gro'):
charges = None charges = charges
masses = None masses = masses
else: else:
raise WrongTopologyError('Topology file should end with ".tpr" or ".gro"') raise WrongTopologyError('Topology file should end with ".tpr" or ".gro"')
indices = None indices = None