Skip to content

Commit

Permalink
Handle multiple velocity properties per molecule. [closes #196]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Nov 7, 2023
1 parent 4b0ba24 commit 7d35a09
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
22 changes: 10 additions & 12 deletions python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,19 +640,16 @@ def addMolecules(self, molecules):

# 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
for mol in self.getPerturbableMolecules():
# Add perturbable velocities.
if mol._sire_object.hasProperty("velocity0"):
num_vels += 1
# Remove non-perturbable velocities to avoid double counting.
elif mol._sire_object.hasProperty("velocity"):
num_vels -= 1

# Not all molecules have velocities.
if num_vels > 0 and num_vels != self.nMolecules():
if num_vels > 0 and num_vels < self.nMolecules():
_warnings.warn(
"Not all molecules have velocities. The 'velocity' property will be removed."
)
Expand Down Expand Up @@ -2384,7 +2381,8 @@ def _set_water_topology(self, format, is_crystal=False, property_map={}):
The format to convert to: either "AMBER" or "GROMACS".
is_crystal : bool
Whether to label as rystal waters.
Whether to label as crystal waters. This is only used when solvating
so that crystal waters aren't removed when adding ions.
property_map : dict
A dictionary that maps system "properties" to their user defined
Expand Down
22 changes: 10 additions & 12 deletions python/BioSimSpace/_SireWrappers/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,19 +640,16 @@ def addMolecules(self, molecules):

# 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
for mol in self.getPerturbableMolecules():
# Add perturbable velocities.
if mol._sire_object.hasProperty("velocity0"):
num_vels += 1
# Remove non-perturbable velocities to avoid double counting.
elif mol._sire_object.hasProperty("velocity"):
num_vels -= 1

# Not all molecules have velocities.
if num_vels > 0 and num_vels != self.nMolecules():
if num_vels > 0 and num_vels < self.nMolecules():
_warnings.warn(
"Not all molecules have velocities. The 'velocity' property will be removed."
)
Expand Down Expand Up @@ -2304,7 +2301,8 @@ def _set_water_topology(self, format, is_crystal=False, property_map={}):
The format to convert to: either "AMBER" or "GROMACS".
is_crystal : bool
Whether to label as rystal waters.
Whether to label as crystal waters. This is only used when solvating
so that crystal waters aren't removed when adding ions.
property_map : dict
A dictionary that maps system "properties" to their user defined
Expand Down

0 comments on commit 7d35a09

Please sign in to comment.