Skip to content

Commit

Permalink
Merge pull request #193 from OpenBioSim/fix_192
Browse files Browse the repository at this point in the history
Fix issue #192
  • Loading branch information
lohedges authored Oct 31, 2023
2 parents cb92227 + accc097 commit 4b0ba24
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 @@ -629,7 +629,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 @@ -638,6 +638,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 @@ -651,6 +664,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 @@ -629,7 +629,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 @@ -638,6 +638,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 @@ -651,6 +664,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 4b0ba24

Please sign in to comment.