Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions python/BioSimSpace/IO/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,13 @@ def readMolecules(


def saveMolecules(
filebase, system, fileformat, match_water=True, property_map={}, **kwargs
filebase,
system,
fileformat,
match_water=True,
save_velocities=True,
property_map={},
**kwargs,
):
"""
Save a molecular system to file.
Expand All @@ -617,6 +623,9 @@ def saveMolecules(
is being saved to a different file format to that from which it was
loaded.

save_velocities : bool
Whether to write velocities to the output files.

property_map : dict
A dictionary that maps system "properties" to their user
defined values. This allows the user to refer to properties
Expand Down Expand Up @@ -710,6 +719,10 @@ def saveMolecules(
if not isinstance(match_water, bool):
raise TypeError("'match_water' must be of type 'bool'.")

# Validate the save_velocities flag.
if not isinstance(save_velocities, bool):
raise TypeError("'save_velocities' must be of type 'bool'.")

# Make a list of the matched file formats.
formats = []

Expand All @@ -735,6 +748,11 @@ def saveMolecules(
if _gmx_path is not None and ("GROMACS_PATH" not in _property_map):
_property_map["GROMACS_PATH"] = _gmx_path

# If the user doesn't wish to save velocities, then remap the
# velocity property.
if not save_velocities:
_property_map["velocity"] = "null"

# Get the directory name.
dirname = _os.path.dirname(filebase)

Expand Down Expand Up @@ -861,7 +879,7 @@ def saveMolecules(
return files


def savePerturbableSystem(filebase, system, property_map={}):
def savePerturbableSystem(filebase, system, save_velocities=True, property_map={}):
"""
Save a system containing a perturbable molecule. This will be written in
AMBER format, with a topology file for each end state of the perturbation,
Expand All @@ -877,6 +895,9 @@ def savePerturbableSystem(filebase, system, property_map={}):
system : :class:`System <BioSimSpace._SireWrappers.System>`
The molecular system.

save_velocities : bool
Whether to write velocities to the output files.

property_map : dict
A dictionary that maps system "properties" to their user defined
values. This allows the user to refer to properties with their
Expand Down Expand Up @@ -907,6 +928,10 @@ def savePerturbableSystem(filebase, system, property_map={}):
"or a list of 'BiSimSpace._SireWrappers.Molecule' types."
)

# Validate the save_velocities flag.
if not isinstance(save_velocities, bool):
raise TypeError("'save_velocities' must be of type 'bool'.")

# Validate the map.
if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")
Expand All @@ -926,6 +951,14 @@ def savePerturbableSystem(filebase, system, property_map={}):
system0 = system.copy()
system1 = system.copy()

# Create a copy of the property map.
property_map = property_map.copy()

# If the user doesn't wish to save velocities, then remap the
# velocity property.
if not save_velocities:
property_map["velocity"] = "null"

# Update the perturbable molecule in each system.
system0.updateMolecules(
pert_mol._toRegularMolecule(property_map=property_map, is_lambda1=False)
Expand Down
37 changes: 35 additions & 2 deletions python/BioSimSpace/Sandpit/Exscientia/IO/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,13 @@ def readMolecules(


def saveMolecules(
filebase, system, fileformat, match_water=True, property_map={}, **kwargs
filebase,
system,
fileformat,
match_water=True,
save_velocities=True,
property_map={},
**kwargs,
):
"""
Save a molecular system to file.
Expand All @@ -617,6 +623,9 @@ def saveMolecules(
is being saved to a different file format to that from which it was
loaded.

save_velocities : bool
Whether to write velocities to the output files.

property_map : dict
A dictionary that maps system "properties" to their user
defined values. This allows the user to refer to properties
Expand Down Expand Up @@ -710,6 +719,10 @@ def saveMolecules(
if not isinstance(match_water, bool):
raise TypeError("'match_water' must be of type 'bool'.")

# Validate the save_velocities flag.
if not isinstance(save_velocities, bool):
raise TypeError("'save_velocities' must be of type 'bool'.")

# Make a list of the matched file formats.
formats = []

Expand All @@ -735,6 +748,11 @@ def saveMolecules(
if _gmx_path is not None and ("GROMACS_PATH" not in _property_map):
_property_map["GROMACS_PATH"] = _gmx_path

# If the user doesn't wish to save velocities, then remap the
# velocity property.
if not save_velocities:
_property_map["velocity"] = "null"

# Get the directory name.
dirname = _os.path.dirname(filebase)

Expand Down Expand Up @@ -861,7 +879,7 @@ def saveMolecules(
return files


def savePerturbableSystem(filebase, system, property_map={}):
def savePerturbableSystem(filebase, system, save_velocities=True, property_map={}):
"""
Save a system containing a perturbable molecule. This will be written in
AMBER format, with a topology file for each end state of the perturbation,
Expand All @@ -877,6 +895,9 @@ def savePerturbableSystem(filebase, system, property_map={}):
system : :class:`System <BioSimSpace._SireWrappers.System>`
The molecular system.

save_velocities : bool
Whether to write velocities to the output files.

property_map : dict
A dictionary that maps system "properties" to their user defined
values. This allows the user to refer to properties with their
Expand Down Expand Up @@ -907,6 +928,10 @@ def savePerturbableSystem(filebase, system, property_map={}):
"or a list of 'BiSimSpace._SireWrappers.Molecule' types."
)

# Validate the save_velocities flag.
if not isinstance(save_velocities, bool):
raise TypeError("'save_velocities' must be of type 'bool'.")

# Validate the map.
if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")
Expand All @@ -926,6 +951,14 @@ def savePerturbableSystem(filebase, system, property_map={}):
system0 = system.copy()
system1 = system.copy()

# Create a copy of the property map.
property_map = property_map.copy()

# If the user doesn't wish to save velocities, then remap the
# velocity property.
if not save_velocities:
property_map["velocity"] = "null"

# Update the perturbable molecule in each system.
system0.updateMolecules(
pert_mol._toRegularMolecule(property_map=property_map, is_lambda1=False)
Expand Down
Loading