From 2999336dcdcbdc6a047ece712bc96ea40359718d Mon Sep 17 00:00:00 2001 From: Hong-Rui Date: Mon, 12 Jun 2023 13:08:31 +0800 Subject: [PATCH] workaround for OpenMM's bug on nb force update parameters.wq --- grand/samplers.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/grand/samplers.py b/grand/samplers.py index 7f6fc57..60a7f1c 100644 --- a/grand/samplers.py +++ b/grand/samplers.py @@ -404,6 +404,10 @@ def adjustSpecificWater(self, atoms, new_lambda): # Get lambda values lambda_vdw, lambda_ele = get_lambda_values(new_lambda) + state = self.context.getState(getPositions=True, enforcePeriodicBox=True, getEnergy=True) + positions = state.getPositions(asNumpy=True) + box_vectors = state.getPeriodicBoxVectors(asNumpy=True) + # Loop over parameters for i, atom_idx in enumerate(atoms): # Obtain original parameters @@ -420,7 +424,10 @@ def adjustSpecificWater(self, atoms, new_lambda): # Update context with new parameters self.nonbonded_force.updateParametersInContext(self.context) self.custom_nb_force.updateParametersInContext(self.context) - + + self.context.setPositions(positions) + self.context.setPeriodicBoxVectors(*box_vectors) + return None def report(self, simulation):