Hi!
I want to do some metadynamics where the collective variable is the distance between two specific particles. I am not sure how to implement the collective variable. Below is the code I have now, which I adapted from https://github.com/openmm/openmm/issues/2126. I am particularly unsure about what to put for the custom force, considering that I don't want to introduce any actual forces, just to define a degree of freedom. Is the following code on the right track or am I missing something? How can I implement this collective variable?
force = CustomBondForce("k") # k is a placeholder, there is no actual force (is this the right thing to do here?)
force.addBond(particleIdx1, particleIdx2)
distance = BiasVariable(force, minDistance, maxDistance, biasWidth=0.5, periodic=True)
enhancedSampling = Metadynamics(system, [distance], temperature=298 * kelvin, biasFactor=2, height=1.0 * kilojoules_per_mole, frequency=100)
metadynamics
- lewis martin
- Posts: 63
- Joined: Tue Mar 06, 2018 8:56 pm
Re: metadynamics
The custom force in this case never gets added to the system directly, it's just used by the metadynamics module to calculate the value of the collective variable. So you want the energy expression to evaluate to the the value of the collective variable. To do this, change
to
since r is the code for the distance between the two particles in a custombondforce. You might want to call setUsesPeriodicBoundaryConditions(True) on the custombondforce as well, since (if using PBC) the bond distance should be calculated to the nearest image. Confusingly, I would then set periodic=False within the metadynamics call
since you don't expect the maximum bond distance to be equivalent to the minimum bond distance.
Code: Select all
force = CustomBondForce("k") # k is a placeholder, there is no actual force (is this the right thing to do here?)
Code: Select all
force = CustomBondForce("r")
Code: Select all
distance = BiasVariable(force, minDistance, maxDistance, biasWidth=0.5, periodic=False)