From a79b6cd1e47f51f0ee98cf729f82e1b5258dbaac Mon Sep 17 00:00:00 2001 From: Bas Rustenburg Date: Tue, 10 Oct 2017 13:16:42 -0400 Subject: [PATCH 1/4] Update version number in setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 00e7d46..855c3ee 100644 --- a/setup.py +++ b/setup.py @@ -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', From f3ada48939e31608443d28b26d05e3fefc79bb09 Mon Sep 17 00:00:00 2001 From: Bas Rustenburg Date: Tue, 10 Oct 2017 13:20:30 -0400 Subject: [PATCH 2/4] Fix bug pertaining to indexing in Swapper.update_fractional_ion Why: A bug existed in Swapper.update_fractional_atom that caused a TypeError during runtime. The final_force array wasn't indexed by atom, but by parameter name. This lead to a TypeError at runtime because instead it was indexed with a the string "charge", instead of an index such as atm_index. What: This commit adds indexing final_force by atm_index to the relevant lines in Swapper. --- saltswap/swapper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/saltswap/swapper.py b/saltswap/swapper.py index e0ee505..bda60d8 100644 --- a/saltswap/swapper.py +++ b/saltswap/swapper.py @@ -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 From 7846edcdc057844e56f9f679605cd88ef986430e Mon Sep 17 00:00:00 2001 From: Bas Rustenburg Date: Tue, 10 Oct 2017 13:28:31 -0400 Subject: [PATCH 3/4] Add unit test for update_fractional_ion Why: This test should ensure that the function works as intended, and should aid in catching future bugs. What: * A basic example of updating ions using the swapper.update_fractional_ion method has been implemented as a unit test. --- saltswap/tests/test_simulation.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/saltswap/tests/test_simulation.py b/saltswap/tests/test_simulation.py index 881b549..4647062 100644 --- a/saltswap/tests/test_simulation.py +++ b/saltswap/tests/test_simulation.py @@ -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) + + #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 + + From c2e4248d25786a2a6faec192e53e41ba0981021c Mon Sep 17 00:00:00 2001 From: Bas Rustenburg Date: Tue, 10 Oct 2017 13:45:47 -0400 Subject: [PATCH 4/4] Fix test bug Why: The random.choice method returns an array, but what is needed is an integer. What: * Added [0] to extract the integer --- saltswap/tests/test_simulation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/saltswap/tests/test_simulation.py b/saltswap/tests/test_simulation.py index 4647062..64795ba 100644 --- a/saltswap/tests/test_simulation.py +++ b/saltswap/tests/test_simulation.py @@ -378,7 +378,7 @@ def test_update_fractional_ion(self): """ 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) + 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)