Skip to content

Commit

Permalink
Merge pull request #26 from choderalab/bugfix-fractional-ion
Browse files Browse the repository at this point in the history
Bugfix for Swapper.update_fractional_ion
  • Loading branch information
bas-rustenburg authored Oct 10, 2017
2 parents c113ab4 + c2e4248 commit 5070cb3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
6 changes: 3 additions & 3 deletions saltswap/swapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -808,9 +808,9 @@ def update_fractional_ion(self, residue_index, initial_force, final_force, fract
molecule = [atom for atom in self.mutable_residues[residue_index].atoms()]
atm_index = 0
for atom in molecule:
charge = (1 - fraction) * initial_force[atm_index]["charge"] + fraction * final_force["charge"]
sigma = (1 - fraction) * initial_force[atm_index]["sigma"] + fraction * final_force["sigma"]
epsilon = (1 - fraction) * initial_force[atm_index]["epsilon"] + fraction * final_force["epsilon"]
charge = (1 - fraction) * initial_force[atm_index]["charge"] + fraction * final_force[atm_index]["charge"]
sigma = (1 - fraction) * initial_force[atm_index]["sigma"] + fraction * final_force[atm_index]["sigma"]
epsilon = (1 - fraction) * initial_force[atm_index]["epsilon"] + fraction * final_force[atm_index]["epsilon"]
self.forces_to_update.setParticleParameters(atom.index, charge=charge, sigma=sigma, epsilon=epsilon)
atm_index += 1

Expand Down
18 changes: 18 additions & 0 deletions saltswap/tests/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,3 +372,21 @@ def test_ghmc_mcmc_sampler(self):
delta_chem=0, nprop=1, npert=5)
sampler.multimove(nmoves=2, mdsteps=1, saltsteps=1)

def test_update_fractional_ion(self):
"""
Test the functionality of the Swapper.update_fractional_ion method.
"""
integrator,context,swapper = self._create_langevin_system()
#Randomly select a water molecule:
water_index = np.random.choice(a=np.where(swapper.stateVector == 0)[0], size=1)[0]

#Completely change this molecule's non-bonded parameters to an anion:
swapper.update_fractional_ion(water_index, swapper.water_parameters, swapper.anion_parameters, fraction=1.0)

#Push change to context:
swapper.forces_to_update.updateParametersInContext(context)

# Update the state vector to keep track of this change: 0 is for water, 1 is for cations, and 2 is for anions.
swapper.stateVector[water_index] = 2


2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
name='saltswap',
author='Gregory A. Ross',
author_email='gregory.ross@choderalab.org',
version='0.1dev',
version='0.5.2',
url='https://github.com/choderalab/saltswap',
packages=['saltswap', 'saltswap.tests'],
license='MIT',
Expand Down

0 comments on commit 5070cb3

Please sign in to comment.