Skip to content

Commit f8817fa

Browse files
authored
Merge pull request #438 from OpenBioSim/backport_347
Backport fix from PR #437
2 parents 3627bfc + 50bd303 commit f8817fa

2 files changed

Lines changed: 70 additions & 4 deletions

File tree

python/BioSimSpace/IO/_io.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,13 @@ def readMolecules(
592592

593593

594594
def saveMolecules(
595-
filebase, system, fileformat, match_water=True, property_map={}, **kwargs
595+
filebase,
596+
system,
597+
fileformat,
598+
match_water=True,
599+
save_velocities=True,
600+
property_map={},
601+
**kwargs,
596602
):
597603
"""
598604
Save a molecular system to file.
@@ -617,6 +623,9 @@ def saveMolecules(
617623
is being saved to a different file format to that from which it was
618624
loaded.
619625
626+
save_velocities : bool
627+
Whether to write velocities to the output files.
628+
620629
property_map : dict
621630
A dictionary that maps system "properties" to their user
622631
defined values. This allows the user to refer to properties
@@ -710,6 +719,10 @@ def saveMolecules(
710719
if not isinstance(match_water, bool):
711720
raise TypeError("'match_water' must be of type 'bool'.")
712721

722+
# Validate the save_velocities flag.
723+
if not isinstance(save_velocities, bool):
724+
raise TypeError("'save_velocities' must be of type 'bool'.")
725+
713726
# Make a list of the matched file formats.
714727
formats = []
715728

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

751+
# If the user doesn't wish to save velocities, then remap the
752+
# velocity property.
753+
if not save_velocities:
754+
_property_map["velocity"] = "null"
755+
738756
# Get the directory name.
739757
dirname = _os.path.dirname(filebase)
740758

@@ -861,7 +879,7 @@ def saveMolecules(
861879
return files
862880

863881

864-
def savePerturbableSystem(filebase, system, property_map={}):
882+
def savePerturbableSystem(filebase, system, save_velocities=True, property_map={}):
865883
"""
866884
Save a system containing a perturbable molecule. This will be written in
867885
AMBER format, with a topology file for each end state of the perturbation,
@@ -877,6 +895,9 @@ def savePerturbableSystem(filebase, system, property_map={}):
877895
system : :class:`System <BioSimSpace._SireWrappers.System>`
878896
The molecular system.
879897
898+
save_velocities : bool
899+
Whether to write velocities to the output files.
900+
880901
property_map : dict
881902
A dictionary that maps system "properties" to their user defined
882903
values. This allows the user to refer to properties with their
@@ -907,6 +928,10 @@ def savePerturbableSystem(filebase, system, property_map={}):
907928
"or a list of 'BiSimSpace._SireWrappers.Molecule' types."
908929
)
909930

931+
# Validate the save_velocities flag.
932+
if not isinstance(save_velocities, bool):
933+
raise TypeError("'save_velocities' must be of type 'bool'.")
934+
910935
# Validate the map.
911936
if not isinstance(property_map, dict):
912937
raise TypeError("'property_map' must be of type 'dict'")
@@ -926,6 +951,14 @@ def savePerturbableSystem(filebase, system, property_map={}):
926951
system0 = system.copy()
927952
system1 = system.copy()
928953

954+
# Create a copy of the property map.
955+
property_map = property_map.copy()
956+
957+
# If the user doesn't wish to save velocities, then remap the
958+
# velocity property.
959+
if not save_velocities:
960+
property_map["velocity"] = "null"
961+
929962
# Update the perturbable molecule in each system.
930963
system0.updateMolecules(
931964
pert_mol._toRegularMolecule(property_map=property_map, is_lambda1=False)

python/BioSimSpace/Sandpit/Exscientia/IO/_io.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,13 @@ def readMolecules(
592592

593593

594594
def saveMolecules(
595-
filebase, system, fileformat, match_water=True, property_map={}, **kwargs
595+
filebase,
596+
system,
597+
fileformat,
598+
match_water=True,
599+
save_velocities=True,
600+
property_map={},
601+
**kwargs,
596602
):
597603
"""
598604
Save a molecular system to file.
@@ -617,6 +623,9 @@ def saveMolecules(
617623
is being saved to a different file format to that from which it was
618624
loaded.
619625
626+
save_velocities : bool
627+
Whether to write velocities to the output files.
628+
620629
property_map : dict
621630
A dictionary that maps system "properties" to their user
622631
defined values. This allows the user to refer to properties
@@ -710,6 +719,10 @@ def saveMolecules(
710719
if not isinstance(match_water, bool):
711720
raise TypeError("'match_water' must be of type 'bool'.")
712721

722+
# Validate the save_velocities flag.
723+
if not isinstance(save_velocities, bool):
724+
raise TypeError("'save_velocities' must be of type 'bool'.")
725+
713726
# Make a list of the matched file formats.
714727
formats = []
715728

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

751+
# If the user doesn't wish to save velocities, then remap the
752+
# velocity property.
753+
if not save_velocities:
754+
_property_map["velocity"] = "null"
755+
738756
# Get the directory name.
739757
dirname = _os.path.dirname(filebase)
740758

@@ -861,7 +879,7 @@ def saveMolecules(
861879
return files
862880

863881

864-
def savePerturbableSystem(filebase, system, property_map={}):
882+
def savePerturbableSystem(filebase, system, save_velocities=True, property_map={}):
865883
"""
866884
Save a system containing a perturbable molecule. This will be written in
867885
AMBER format, with a topology file for each end state of the perturbation,
@@ -877,6 +895,9 @@ def savePerturbableSystem(filebase, system, property_map={}):
877895
system : :class:`System <BioSimSpace._SireWrappers.System>`
878896
The molecular system.
879897
898+
save_velocities : bool
899+
Whether to write velocities to the output files.
900+
880901
property_map : dict
881902
A dictionary that maps system "properties" to their user defined
882903
values. This allows the user to refer to properties with their
@@ -907,6 +928,10 @@ def savePerturbableSystem(filebase, system, property_map={}):
907928
"or a list of 'BiSimSpace._SireWrappers.Molecule' types."
908929
)
909930

931+
# Validate the save_velocities flag.
932+
if not isinstance(save_velocities, bool):
933+
raise TypeError("'save_velocities' must be of type 'bool'.")
934+
910935
# Validate the map.
911936
if not isinstance(property_map, dict):
912937
raise TypeError("'property_map' must be of type 'dict'")
@@ -926,6 +951,14 @@ def savePerturbableSystem(filebase, system, property_map={}):
926951
system0 = system.copy()
927952
system1 = system.copy()
928953

954+
# Create a copy of the property map.
955+
property_map = property_map.copy()
956+
957+
# If the user doesn't wish to save velocities, then remap the
958+
# velocity property.
959+
if not save_velocities:
960+
property_map["velocity"] = "null"
961+
929962
# Update the perturbable molecule in each system.
930963
system0.updateMolecules(
931964
pert_mol._toRegularMolecule(property_map=property_map, is_lambda1=False)

0 commit comments

Comments
 (0)