Skip to content

Commit f217b5e

Browse files
committed
Additional pass at cleaning up SHAKE Charge Constraint algorithm. The changes include accurately calculating a constraint force and scaling it down by a factor of 100 as determined through testing. Removal of the afric term opens up the use of the constraint with other integrators.
1 parent bb10e08 commit f217b5e

File tree

2 files changed

+7
-11
lines changed

2 files changed

+7
-11
lines changed

modules/algorithms/src/main/java/ffx/algorithms/dynamics/integrators/Stochastic.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,11 @@ public void preForce(Potential potential) throws RuntimeException {
230230
// then find new atom positions and half-step velocities via Verlet recursion.
231231
x[i] += (v[i] * vFriction[i] + a[i] * afric + prand);
232232
v[i] = v[i] * pfric + 0.5 * a[i] * vFriction[i];
233-
234-
if(useConstraints){
235-
africArray[i] = afric;
236-
}
237233
}
238234
if (useConstraints) {
239235
for(Constraint c : constraints){
240236
if(c instanceof ShakeChargeConstraint){
241-
((ShakeChargeConstraint) c).applyChargeConstraintToStep(x, africArray, mass, dt);
237+
((ShakeChargeConstraint) c).applyChargeConstraintToStep(x, mass);
242238
double velScale = 1.0 / dt;
243239
for (int i = 0; i < nVariables; i++) {
244240
v[i] = velScale * (x[i] - xPrior[i]);

modules/potential/src/main/java/ffx/potential/constraint/ShakeChargeConstraint.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import ffx.numerics.Constraint;
44

5+
import static ffx.utilities.Constants.KCAL_TO_GRAM_ANG2_PER_PS2;
6+
57
public class ShakeChargeConstraint implements Constraint {
68
final int nConstraints;
79
final double tol;
@@ -23,11 +25,9 @@ public void applyConstraintToStep(final double[] xPrior, double[] xNew, final do
2325
* Journal of chemical theory and computation 12.3 (2016): 1040-1051.
2426
* https://pubs.acs.org/doi/epdf/10.1021/acs.jctc.5b01160
2527
* @param x
26-
* @param afric
2728
* @param masses
28-
* @param dt
2929
*/
30-
public void applyChargeConstraintToStep(final double[] x, final double[] afric, final double[] masses, final double dt){
30+
public void applyChargeConstraintToStep(final double[] x, final double[] masses){
3131
boolean done = false;
3232
int iter = 0;
3333
while(!done){
@@ -41,13 +41,13 @@ public void applyChargeConstraintToStep(final double[] x, final double[] afric,
4141
totalInverseMass += (1.0 / masses[i]);
4242
}
4343
double delta = totalLambda - c;
44-
4544
if (Math.abs(delta) > tol) {
4645
done = false;
47-
double term = delta / (dt * dt * totalInverseMass);
46+
double term = delta / totalInverseMass;
4847
for (int i = 0; i < nConstraints; i++) {
4948
double g = -term * Math.sin(2 * x[i]);
50-
x[i] = x[i] + g * afric[i];
49+
// Scale constraint force by 0.01 was determined to improve convergence of constraint through testing
50+
x[i] = x[i] - (g * -KCAL_TO_GRAM_ANG2_PER_PS2 / masses[i]) * 0.01;
5151
}
5252
}
5353
if(iter >= maxIters){

0 commit comments

Comments
 (0)