Skip to content

Commit

Permalink
Backport fix from PR #193. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Oct 31, 2023
1 parent 8d56b9b commit 45e5897
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
27 changes: 26 additions & 1 deletion python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def addMolecules(self, molecules):

# Remove velocities if any molecules are missing them.
if self.nMolecules() > 1:
# Search for water molecules in the system.
# Search for molecules with a velocity property.
try:
mols_with_velocities = self.search(
f"mols with property velocity"
Expand All @@ -637,6 +637,19 @@ def addMolecules(self, molecules):
except:
num_vels = 0

# Search for perturbable molecules with a velocity property.
# Only consider the lambda = 0 end state.
try:
pert_mols_with_velocities = self.search(
f"mols with property velocity0"
).molecules()
num_pert_vels = len(pert_mols_with_velocities)
except:
num_pert_vels = 0

# Compute the total number of molecules with velocities.
num_vels = num_vels + num_pert_vels

# Not all molecules have velocities.
if num_vels > 0 and num_vels != self.nMolecules():
_warnings.warn(
Expand All @@ -650,6 +663,18 @@ def addMolecules(self, molecules):
_warnings.warn(
"Failed to remove 'velocity' property from all molecules!"
)
if num_pert_vels > 0:
try:
self._sire_object = _SireIO.removeProperty(
self._sire_object, "velocity0"
)
self._sire_object = _SireIO.removeProperty(
self._sire_object, "velocity1"
)
except:
_warnings.warn(
"Failed to remove 'velocity0' and 'velocity1' property from molecules!"
)

def removeMolecules(self, molecules):
"""
Expand Down
27 changes: 26 additions & 1 deletion python/BioSimSpace/_SireWrappers/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def addMolecules(self, molecules):

# Remove velocities if any molecules are missing them.
if self.nMolecules() > 1:
# Search for water molecules in the system.
# Search for molecules with a velocity property.
try:
mols_with_velocities = self.search(
f"mols with property velocity"
Expand All @@ -637,6 +637,19 @@ def addMolecules(self, molecules):
except:
num_vels = 0

# Search for perturbable molecules with a velocity property.
# Only consider the lambda = 0 end state.
try:
pert_mols_with_velocities = self.search(
f"mols with property velocity0"
).molecules()
num_pert_vels = len(pert_mols_with_velocities)
except:
num_pert_vels = 0

# Compute the total number of molecules with velocities.
num_vels = num_vels + num_pert_vels

# Not all molecules have velocities.
if num_vels > 0 and num_vels != self.nMolecules():
_warnings.warn(
Expand All @@ -650,6 +663,18 @@ def addMolecules(self, molecules):
_warnings.warn(
"Failed to remove 'velocity' property from all molecules!"
)
if num_pert_vels > 0:
try:
self._sire_object = _SireIO.removeProperty(
self._sire_object, "velocity0"
)
self._sire_object = _SireIO.removeProperty(
self._sire_object, "velocity1"
)
except:
_warnings.warn(
"Failed to remove 'velocity0' and 'velocity1' property from molecules!"
)

def removeMolecules(self, molecules):
"""
Expand Down

0 comments on commit 45e5897

Please sign in to comment.