"vscode:/vscode.git/clone" did not exist on "5a25b4ec533f6f7a4e9717b993049c9e3f15b208"
Commit 5e1a87fb authored by peastman's avatar peastman
Browse files

Merge pull request #1142 from peastman/tests

Refactored test cases
parents b11af401 cece0cdb
ASSERT_EQUAL_VEC(Vec3( 1.53862e+01, -9.40085e+01, 8.09974e+01), forces1[0], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.16025e+01, 3.42647e+01, 7.90920e+01), forces1[1], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.96273e+01, 7.80017e+01, 7.38545e+00), forces1[2], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.28843e+01, -1.89277e+01, -2.54913e+02), forces1[3], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.22785e+01, -3.88301e+01, -2.81351e+02), forces1[4], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.09090e+02, 1.75451e+02, -1.29874e+02), forces1[5], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.95616e+02, 5.36132e+02, -4.55554e+02), forces1[6], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.85944e+02, -1.19523e+02, 7.88721e+01), forces1[7], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.13615e+02, -6.17221e+01, 1.57270e+02), forces1[8], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.66977e+01, -6.36326e+01, 1.65651e+02), forces1[9], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.62216e+00, 1.13905e+02, -5.46500e+01), forces1[10], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.21610e+01, 2.96483e+01, -6.34852e+01), forces1[11], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.01658e+01, 1.07406e+02, 2.69335e+01), forces1[12], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.14730e+01, 9.63730e+01, 1.37884e+02), forces1[13], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.45980e+02, 2.47183e+01, 1.30466e+02), forces1[14], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.15321e+01, 2.08457e+02, 4.15324e+02), forces1[15], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.53856e+02, 6.74890e+01, -7.69439e+01), forces1[16], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.56804e+02, 1.82869e+02, 2.35455e+02), forces1[17], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.78646e+02, 4.16416e+01, -2.55139e+02), forces1[18], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.51530e+01, 3.24295e+01, 1.87664e+01), forces1[19], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.04660e+02, -2.25016e+02, 5.95159e+01), forces1[20], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.93048e+01, 3.22523e+01, 1.06075e+02), forces1[21], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.84792e+01, 1.15745e+02, 9.08190e+01), forces1[22], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.22807e+01, -3.30640e+01, 2.38179e+01), forces1[23], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.10281e+01, 5.37699e+01, 1.70935e+02), forces1[24], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.55507e+01, 2.52756e+02, 1.34829e+02), forces1[25], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.62832e+01, -6.20729e+01, -9.53832e+01), forces1[26], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.93262e+01, -8.64360e+01, -9.20284e+01), forces1[27], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.72500e+00, -1.78213e+02, 1.54062e+01), forces1[28], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.46320e+02, 1.93997e+01, -1.06660e+01), forces1[29], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.02138e+01, 1.84585e+02, -1.96791e+02), forces1[30], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.44392e+01, -1.63547e+02, -1.34078e+02), forces1[31], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.64487e+01, -1.01917e+02, -2.94291e+01), forces1[32], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.62979e+02, -8.44104e+01, 4.45776e+00), forces1[33], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.37054e+02, -1.64893e+01, 1.62445e+02), forces1[34], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.79879e+02, -1.28158e+02, 1.46225e+02), forces1[35], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.18701e+02, 1.96825e+01, 1.78171e+02), forces1[36], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.05936e+01, -1.32890e+02, 3.44742e+01), forces1[37], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.00952e+01, -2.04575e+02, 1.62082e+02), forces1[38], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.48119e+02, -5.51581e+01, 7.61226e+01), forces1[39], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.54706e+02, -7.79318e+01, -1.19613e+02), forces1[40], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.99297e+02, 1.36546e+02, 1.92910e+02), forces1[41], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.30607e+02, 9.45022e+01, -1.15484e+02), forces1[42], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.87492e+01, 3.38234e+01, -1.13593e+02), forces1[43], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.13434e+01, 1.75865e+02, 7.10201e+01), forces1[44], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.98165e+02, -1.81350e+02, -1.38226e+02), forces1[45], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.58294e+02, -1.74709e+02, -1.91109e+02), forces1[46], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.09248e+02, -1.57551e+02, -2.54299e+02), forces1[47], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.75881e+01, -1.06801e+02, -8.62635e+01), forces1[48], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.96592e+02, -1.56687e+01, -9.07580e+01), forces1[49], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.07471e+02, -1.59465e+02, 1.41495e+01), forces1[50], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.97824e+02, -1.58296e+01, -3.62499e+01), forces1[51], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.93794e+01, 2.56345e+01, 5.39562e+01), forces1[52], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.00946e+02, 1.34042e+02, 8.37801e+01), forces1[53], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.44101e+01, 1.04507e+02, -7.20338e+00), forces1[54], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.36940e+02, 1.45544e+02, 7.49711e+01), forces1[55], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.50152e+00, 2.02504e+02, 1.20796e+02), forces1[56], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.94096e+02, -4.04458e+01, 5.69722e+01), forces1[57], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.39977e+01, -1.51534e+02, -4.73434e+01), forces1[58], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.19892e+01, -9.31361e+01, -3.38910e+01), forces1[59], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.17884e+01, 1.00547e+02, -1.33243e+02), forces1[60], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.71112e+01, 6.21495e+01, 1.61566e+02), forces1[61], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.56825e+01, 6.35038e+01, -1.08713e+02), forces1[62], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.42227e+02, 2.10144e+02, 1.68761e+02), forces1[63], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.92938e+02, -1.15636e+02, -2.42672e+02), forces1[64], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.46946e+01, 1.75845e+02, 2.87636e+01), forces1[65], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.35161e+01, -3.00661e+01, -1.51624e+02), forces1[66], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.77087e+01, 1.55190e+02, 2.57432e+01), forces1[67], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.98358e+00, -2.76639e+02, -2.72293e+01), forces1[68], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.05003e+02, 1.07560e+02, 3.34506e+01), forces1[69], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.18245e+01, -1.75537e+01, -9.57309e+01), forces1[70], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.67253e+02, 5.59922e-01, 1.01207e+02), forces1[71], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.62670e+02, -6.88248e+01, -4.21201e+02), forces1[72], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.18113e+02, -5.78800e+01, -2.27353e+02), forces1[73], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.64922e+00, 9.21166e+01, -8.93683e+01), forces1[74], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.12201e+02, -3.27194e+01, 1.34264e+02), forces1[75], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.44131e+01, -7.40189e+01, 1.05403e+02), forces1[76], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.25775e+01, -1.36797e+02, 2.73836e+02), forces1[77], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.10304e+01, 7.16395e+01, 4.68672e+02), forces1[78], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.93444e+01, -2.15029e+02, -6.63119e+01), forces1[79], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.55389e+02, -3.73611e+02, 1.19751e+02), forces1[80], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.45909e+02, -1.24787e+02, 3.49148e+01), forces1[81], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.32739e+01, 2.95694e+02, -5.37526e+01), forces1[82], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.54390e+02, 4.53455e+02, -2.26764e+02), forces1[83], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.41532e+02, 4.99625e+01, -2.51478e+02), forces1[84], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.44295e+02, 3.25984e+02, -1.78338e+02), forces1[85], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.41100e+02, 7.63283e+01, 1.44488e+02), forces1[86], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.38640e+00, 2.32776e+02, 7.67636e+01), forces1[87], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.02516e+01, 2.34037e+02, 1.90372e+02), forces1[88], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.91986e+01, 6.06007e+01, -2.82869e+01), forces1[89], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.17690e+01, 2.95809e+02, 8.76127e+01), forces1[90], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.68695e+02, 3.01744e+02, -4.89279e+01), forces1[91], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.69699e+01, -8.28133e+01, 1.45608e+02), forces1[92], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.06525e+02, -1.67708e+02, -8.84405e+01), forces1[93], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.24225e+02, -2.54622e+02, 6.45408e+01), forces1[94], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.17139e+01, 8.98704e+01, 1.46449e+02), forces1[95], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.77809e+01, -7.22944e+00, -1.54716e+02), forces1[96], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.09684e+01, -7.69721e+01, 4.92171e+01), forces1[97], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.39983e+01, -1.04019e+01, -1.19765e+02), forces1[98], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.69240e+02, -4.03667e+02, -1.80224e+01), forces1[99], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.94854e+01, 1.06162e+02, 2.06747e+02), forces1[100], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.37669e+02, 1.53252e+02, 2.04131e+02), forces1[101], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.32814e+02, 6.44910e+01, -3.37777e+02), forces1[102], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.66103e+02, 8.69357e+01, -1.09283e+02), forces1[103], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.18540e+01, 6.11078e+01, -1.30500e+02), forces1[104], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.89128e+02, -2.65106e+02, -1.28996e+02), forces1[105], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.45378e+01, -3.81579e+02, -1.11586e+02), forces1[106], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.79366e+01, -2.27092e+02, 2.32158e+02), forces1[107], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.14303e+02, 1.21953e+02, 3.08605e+01), forces1[108], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.95355e+02, 2.38433e+02, -3.78260e+01), forces1[109], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.25306e+02, -5.62806e+01, 2.93849e+02), forces1[110], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.32541e+02, 1.53253e+02, 1.18339e+02), forces1[111], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.26061e+02, 1.22366e+02, 6.31712e+00), forces1[112], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.68565e+02, 9.40491e+01, 4.12643e+01), forces1[113], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.19917e+02, -1.43527e+02, -2.21682e+02), forces1[114], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.93757e+01, 9.98556e+01, 7.38225e+01), forces1[115], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.87240e+01, -7.40610e+01, 1.37672e+02), forces1[116], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.90455e+01, -9.52131e+01, -4.21601e+02), forces1[117], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.97078e+02, 2.45509e+02, 9.26765e+01), forces1[118], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.98206e+02, 1.14032e+02, 8.71204e+01), forces1[119], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.19803e+02, 1.82722e+01, -3.52888e+00), forces1[120], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.30623e+02, 7.51475e-01, -4.84435e+01), forces1[121], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.02126e+01, 5.55326e+01, 2.67927e+00), forces1[122], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.87364e+02, 1.76214e+02, -3.09445e+02), forces1[123], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.85190e+02, -1.63720e+02, -7.15048e+01), forces1[124], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.65174e+02, -1.33924e+02, -6.94217e+01), forces1[125], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.39913e+00, 2.52232e+01, 5.05709e+01), forces1[126], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.63349e+02, 9.56277e+01, 5.30812e+01), forces1[127], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.92027e+01, -9.44704e+01, -7.51200e+00), forces1[128], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.24094e+02, 7.38856e+01, 1.76005e+02), forces1[129], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.92944e+01, 3.02317e+02, 1.39375e+02), forces1[130], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.66291e+01, 1.41333e+02, 6.15473e+00), forces1[131], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.36178e+01, -1.58532e+01, -8.84526e+00), forces1[132], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.48146e+01, -3.41461e+01, -5.24216e+01), forces1[133], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.99809e+01, 1.02879e+01, -5.01739e+01), forces1[134], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.62285e+02, -4.90274e+01, 3.03601e+01), forces1[135], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.06458e+02, -3.96124e+01, 1.03454e+02), forces1[136], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.29243e+02, 6.18585e+01, -1.77272e+02), forces1[137], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.15853e+02, 2.19635e+02, -4.11751e+02), forces1[138], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.16425e+01, 8.23178e+01, 4.42405e+02), forces1[139], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.21858e+01, 4.82821e+01, 1.93947e+02), forces1[140], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.03450e+00, 2.30768e+01, 4.96796e+01), forces1[141], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.67572e+01, 7.23375e+01, 6.32957e+01), forces1[142], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.67345e+01, 1.26459e+01, 8.78382e+01), forces1[143], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.43687e+02, 1.76648e+01, 3.89767e+01), forces1[144], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.77056e+01, -9.46510e+01, -1.60263e+02), forces1[145], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.49800e+01, -2.68488e+01, 4.35106e+01), forces1[146], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.46710e+02, -5.25895e+01, -5.40524e+01), forces1[147], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.33729e+01, -4.69399e+01, -7.85015e+01), forces1[148], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.78265e+02, 3.19667e+00, -1.14997e+02), forces1[149], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.93773e+02, 7.50014e+01, -6.05331e+01), forces1[150], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.41372e+02, 1.04392e+02, -1.69148e+02), forces1[151], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.16023e+01, -7.84331e+00, -3.50072e+01), forces1[152], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.91752e+02, -8.75055e+01, 2.06764e+01), forces1[153], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.24104e+01, 2.55823e+02, 5.03937e+01), forces1[154], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.44493e+01, -1.88359e+02, -2.96664e+02), forces1[155], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.95569e+01, -1.48556e+02, -3.25981e+01), forces1[156], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.87067e+01, -3.24463e+01, -4.72036e+01), forces1[157], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.57426e+01, -4.76206e+01, -4.60343e+01), forces1[158], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.72900e+01, 5.41697e-01, -1.00543e+02), forces1[159], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.18469e+01, -6.73531e+00, 1.21198e+02), forces1[160], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.22925e+01, -1.12784e+01, 1.43764e+02), forces1[161], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.83447e+00, -1.45820e+01, -1.70105e+02), forces1[162], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.76068e+01, -7.28345e+00, -1.56973e+02), forces1[163], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.79090e+01, -1.92976e+02, -1.29871e+02), forces1[164], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.93110e+01, -1.12724e+02, 2.45046e+01), forces1[165], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.69833e+02, -9.82967e+01, 5.93923e+01), forces1[166], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.02085e+02, 9.27636e+00, 6.98988e+01), forces1[167], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.84338e+01, 1.41909e+02, -4.11691e+01), forces1[168], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.23626e+02, -1.04296e+02, 4.77490e+01), forces1[169], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.37003e+01, 4.13719e+01, 1.29790e+02), forces1[170], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.42874e+02, -8.32344e+01, -3.05737e+01), forces1[171], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.41293e+01, 7.66533e+01, 1.00918e+02), forces1[172], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.02752e+02, -3.11320e+01, -2.04248e+01), forces1[173], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.71192e+01, -3.13758e+02, 2.83511e+02), forces1[174], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.43170e+02, 1.60859e+02, 6.31587e+01), forces1[175], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.26734e+02, 1.91452e+02, -1.93402e+00), forces1[176], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.10931e+02, -1.64391e+01, -6.86948e+01), forces1[177], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.38600e+01, 2.32825e+02, -5.25593e+00), forces1[178], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.54520e+01, -1.88445e+02, -4.29131e+01), forces1[179], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.24785e+02, -1.05275e+02, -2.98944e+01), forces1[180], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.05063e+02, -6.53701e+01, 3.24520e+01), forces1[181], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.53521e+01, -9.04667e+01, -1.59980e+01), forces1[182], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.53764e+01, -3.04915e+01, 1.37888e+02), forces1[183], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.08932e+02, -9.35386e+01, -1.80955e+01), forces1[184], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.64566e+02, -1.70413e+02, -1.27317e+01), forces1[185], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.22672e+02, -3.22897e+02, 3.76674e+00), forces1[186], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.09547e+01, 3.37045e+02, -2.28878e+02), forces1[187], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.33946e+01, -1.01157e+02, -5.42970e+01), forces1[188], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.88672e+01, 2.85116e+01, -8.06985e-01), forces1[189], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.46034e+01, 1.78114e+02, -8.00020e+01), forces1[190], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.94640e+01, -7.09864e+01, 1.32544e+02), forces1[191], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.87772e+01, 8.20162e+01, -9.03433e+01), forces1[192], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.88680e+00, 8.72448e+01, -2.61573e+01), forces1[193], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.28593e+01, 2.51197e+00, -5.73722e+01), forces1[194], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.80417e+01, -7.37577e+01, 1.00134e+02), forces1[195], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.56974e+01, 6.72072e+00, -3.81539e+01), forces1[196], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.19232e+01, -3.54500e+01, 8.29318e+01), forces1[197], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.04113e+01, -4.41970e+01, 1.03326e+02), forces1[198], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.90881e+01, -1.12057e+02, 4.49403e+01), forces1[199], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.92007e+01, 3.55272e+01, -2.40127e+02), forces1[200], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.43562e+02, 6.23027e+02, -2.49264e+02), forces1[201], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.76198e+02, -3.02372e+02, 1.62332e+02), forces1[202], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.20299e+02, -2.27586e+02, 5.80333e+01), forces1[203], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.39488e+01, -1.07027e+00, -2.95203e+01), forces1[204], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.73263e+01, -1.08485e+02, 5.71183e+00), forces1[205], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.00039e+01, -2.49895e+02, 3.39192e+01), forces1[206], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.29623e+01, 1.32732e+02, 2.08741e+01), forces1[207], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.25554e+02, -1.56772e+01, -1.08164e+02), forces1[208], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.38717e+01, 1.52424e+01, 4.36131e+01), forces1[209], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.76367e+01, 1.13676e+02, -8.52759e+01), forces1[210], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.96298e+01, -9.30520e+01, -2.23851e+01), forces1[211], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.75027e+01, 1.64821e+02, 6.78676e+01), forces1[212], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.64028e+02, 3.12107e+01, 8.76753e+01), forces1[213], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.72632e+01, 5.28099e+01, 1.69700e+01), forces1[214], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.40135e+02, -7.08379e+01, -1.93293e+02), forces1[215], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.76562e+01, 2.29918e+02, 1.30609e+02), forces1[216], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.81640e+01, -2.90103e+02, 1.36757e+00), forces1[217], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.79291e+01, -2.93974e+02, 1.15436e+02), forces1[218], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.17338e+02, 1.11581e+02, 3.46029e+01), forces1[219], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.13346e+01, 3.15582e+01, 8.34550e+01), forces1[220], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.57677e+01, 1.77750e+01, 1.01067e+02), forces1[221], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.49827e+02, 8.44938e+01, 1.82793e+02), forces1[222], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.35999e+02, -1.89848e+02, -2.50760e+02), forces1[223], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.41970e+02, -1.87691e+02, -2.44756e+02), forces1[224], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.37302e+02, 8.71479e+01, -2.13793e+02), forces1[225], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.45010e+01, 2.44686e+02, -1.46416e+02), forces1[226], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.31020e+02, 1.28244e+02, 7.71140e+01), forces1[227], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.53744e+01, 1.29065e+02, 2.11056e+02), forces1[228], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.21924e+01, 9.95419e+00, -1.07719e+02), forces1[229], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.85756e+01, 9.52314e+01, 8.76358e+01), forces1[230], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.93957e+00, 1.53656e+02, -1.13339e+02), forces1[231], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.02172e+02, 8.87905e+01, -2.13701e+02), forces1[232], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.68099e+01, 1.91141e+02, 4.82221e+01), forces1[233], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.92679e+02, -2.47187e+02, 6.66851e+01), forces1[234], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.09980e+02, -1.43568e+02, -3.01739e+01), forces1[235], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.33167e+02, -3.32798e+02, 5.34600e+01), forces1[236], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.24223e+01, 9.76875e+00, 4.47725e+01), forces1[237], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.69405e+01, -8.41132e+01, -5.38952e+01), forces1[238], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.12010e+01, 1.44242e+01, -1.42070e+01), forces1[239], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.96477e+02, -4.50656e+02, 1.11329e+02), forces1[240], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.39163e+02, 1.76905e+02, 5.32392e+00), forces1[241], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.19746e+02, 1.76406e+02, 1.08727e+01), forces1[242], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.59625e+01, 1.08166e+01, 1.58314e+02), forces1[243], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.06176e+00, 1.91897e+01, 1.04092e+02), forces1[244], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.25838e+02, -4.67771e+00, -5.29138e+01), forces1[245], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.85855e+01, 1.78805e+01, -1.25884e+02), forces1[246], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.10798e+02, 9.15074e+01, 1.95780e+02), forces1[247], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.10572e+01, -1.48442e+02, 4.74169e+01), forces1[248], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.25479e+02, 2.55010e+01, 8.47576e+01), forces1[249], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.10701e+02, -6.73355e+01, 1.19913e+02), forces1[250], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.70376e+01, -6.37904e+00, 1.26145e+02), forces1[251], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.37588e+02, 1.02142e+02, 3.67769e+02), forces1[252], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.52584e+01, -7.07147e+01, 1.73165e+02), forces1[253], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.33450e+01, -2.18105e+02, -1.55636e+02), forces1[254], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.29365e+02, 7.78338e+01, -3.82730e+01), forces1[255], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.57375e+02, -6.66875e+01, -5.81031e+01), forces1[256], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.78245e+01, -1.40991e+01, 3.12933e+01), forces1[257], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.87648e+01, 2.74231e+02, 7.27232e+01), forces1[258], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.14936e+02, 1.20339e+01, -1.48413e+02), forces1[259], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.06217e+02, -3.13647e+01, -1.68616e+02), forces1[260], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.25106e+02, -2.60277e+02, -1.61136e+02), forces1[261], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.70346e+02, -9.32224e+00, -5.51717e+01), forces1[262], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.83465e+01, -2.28314e+02, -2.29566e+02), forces1[263], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.96075e+01, 1.48719e+02, 9.34688e+01), forces1[264], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.71370e+02, 1.70586e+02, -9.94963e+01), forces1[265], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.40521e+01, -1.08310e+02, 3.14259e+01), forces1[266], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.40452e+02, -2.41911e+02, 1.64059e+02), forces1[267], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.58929e+02, -1.31148e+02, -5.32733e+01), forces1[268], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.63751e+01, -2.73274e+02, -8.70685e+00), forces1[269], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.31634e+02, 2.19012e+02, -9.03802e+01), forces1[270], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.18020e+02, -1.92997e+01, -5.66165e+00), forces1[271], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.73518e+01, -3.11848e+01, -1.30020e+02), forces1[272], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.17466e+01, -3.68264e+02, 2.52209e+02), forces1[273], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.05037e+02, -1.84548e+02, -2.29593e+02), forces1[274], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.33053e+02, -1.07748e+02, -3.35660e+02), forces1[275], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.26641e+00, -2.78635e+00, -6.24895e+01), forces1[276], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.89712e+01, -4.30328e+01, -1.35221e+02), forces1[277], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.08792e+01, 8.56090e+01, 7.01326e+01), forces1[278], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.41320e+01, 1.50690e+02, -3.83537e+01), forces1[279], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.77423e+01, 7.38950e+01, 4.53469e+01), forces1[280], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.26780e+02, 1.02539e+02, -1.85815e+02), forces1[281], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.00799e+01, 1.14102e+02, -1.69102e+02), forces1[282], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.76513e+01, 8.40729e+01, 4.44592e+01), forces1[283], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.26467e+01, 5.77168e+01, 6.22600e+01), forces1[284], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.50347e+02, 3.61081e+02, -9.77920e+00), forces1[285], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.74580e+01, -5.17134e+01, -4.47767e+02), forces1[286], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.34437e+01, -3.97370e+02, -1.13442e+02), forces1[287], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.99880e+01, 2.09852e+02, 5.14899e+02), forces1[288], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.66190e+02, -2.26561e+02, 2.12404e+02), forces1[289], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.70999e+02, -2.62349e+02, -1.29205e+01), forces1[290], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.14337e+01, 5.49849e+01, 1.43268e+02), forces1[291], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.68620e+02, 3.93466e+00, 5.58857e+01), forces1[292], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.80270e+02, -1.13992e+01, 5.41069e+01), forces1[293], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.97739e+00, 1.29408e+02, -5.46560e+01), forces1[294], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.63236e+02, -1.28719e+02, 3.12749e+02), forces1[295], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.22808e+01, 1.12193e+02, 7.28319e+01), forces1[296], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.99596e+01, 2.53709e+02, 4.53500e+01), forces1[297], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.27720e+01, 8.59763e+01, 6.45557e+01), forces1[298], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.27058e+02, 1.22472e+01, 1.29561e+01), forces1[299], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.06664e+01, -9.58809e+01, -3.53582e+01), forces1[300], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.53970e+01, 5.12101e+01, 1.16686e+02), forces1[301], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.73120e+02, -1.27943e+02, -7.31003e+01), forces1[302], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.71294e+01, 2.17024e+02, 9.31014e+01), forces1[303], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.68161e+01, -1.85137e+02, 1.09745e+02), forces1[304], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.01521e+02, 5.92488e+00, -4.76997e+01), forces1[305], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.65074e+02, -7.65780e+01, -1.09596e+02), forces1[306], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.97306e+01, 3.84936e+01, 3.18940e+02), forces1[307], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.03733e+01, -3.14806e+01, -1.59317e+02), forces1[308], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.43092e+01, -1.29125e+02, 1.63512e+02), forces1[309], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.96060e+02, 5.77380e+01, -1.44479e+02), forces1[310], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.06352e+01, 5.46684e+00, 1.26620e+02), forces1[311], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.68377e+01, 1.94905e+02, 2.46429e+02), forces1[312], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.30349e+02, 9.49772e+01, -1.35362e+02), forces1[313], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.38512e+01, 6.40803e+01, 8.45394e+00), forces1[314], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.42175e+01, -1.59403e+00, -1.30405e+02), forces1[315], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.35848e+01, -4.54779e+00, -1.44903e+02), forces1[316], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.11989e+02, -1.18639e+01, -1.17828e+02), forces1[317], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.49970e+02, 6.35046e+01, -2.88805e+01), forces1[318], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.44126e+01, -6.56825e+01, -1.14100e+02), forces1[319], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.77255e+01, -3.66261e+01, -1.19649e+02), forces1[320], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.97007e+01, 1.88165e+01, 4.66627e+01), forces1[321], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.11016e+01, 1.60276e+01, -8.72109e+01), forces1[322], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.62297e+01, 1.86600e+02, 7.68552e+01), forces1[323], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.39138e+02, 2.21671e+02, 8.47440e+01), forces1[324], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.74277e+02, -6.06765e+01, -4.23965e+01), forces1[325], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.63159e+02, -6.13787e+01, -2.54964e+01), forces1[326], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.00529e+01, -6.56450e+01, -3.53408e+01), forces1[327], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.27153e+01, -9.16080e+01, -6.10037e+00), forces1[328], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.07795e+01, -6.31786e+01, 3.97424e+01), forces1[329], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.69043e+01, 2.05417e+02, -1.55673e+02), forces1[330], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.55098e+01, 6.25556e+01, -9.57571e+01), forces1[331], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.75174e+00, -7.00953e+01, -1.65779e+01), forces1[332], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.48906e+02, -9.37035e+01, -1.37237e+02), forces1[333], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.05834e+02, -1.77865e+02, -2.97998e+02), forces1[334], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.28005e+02, -1.09597e+02, -1.57769e+02), forces1[335], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.72019e+01, -2.11978e+02, -5.75568e+01), forces1[336], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.47436e+00, -2.09055e+01, 9.54998e+01), forces1[337], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.00282e+01, -1.18118e+02, 7.20331e+01), forces1[338], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.27051e+01, 3.88512e+01, -3.37338e+02), forces1[339], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.92361e+02, 4.97166e+01, -2.72135e+02), forces1[340], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.01809e+02, 3.12384e+01, -1.44869e+02), forces1[341], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.70524e+01, 6.01604e+01, -1.29958e+01), forces1[342], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.75977e+01, -6.85964e+01, 5.29205e+01), forces1[343], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.82625e+01, 5.36498e+01, -1.27179e+02), forces1[344], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.48158e+02, 1.18954e+01, 1.03589e+02), forces1[345], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.76540e+01, 8.31945e+01, 6.88425e-01), forces1[346], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.36393e+01, 5.97150e+00, 5.92665e+01), forces1[347], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.35596e+01, -3.45187e+01, -8.71186e+01), forces1[348], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.14736e+01, 1.99758e+01, 3.17942e+01), forces1[349], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.15299e+01, -6.78140e+01, -1.20761e+02), forces1[350], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.48161e+02, 1.61995e+02, -2.00364e+01), forces1[351], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.91715e+02, 4.15257e+01, -1.01480e+02), forces1[352], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.53537e+02, 2.47464e+01, -9.32184e+01), forces1[353], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.26331e+02, -1.50752e+02, 3.87836e+02), forces1[354], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.80549e+02, -1.04529e+02, 2.64609e+02), forces1[355], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.33299e+00, -1.04191e+02, 2.43081e+02), forces1[356], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.49417e+02, -2.10331e+02, -2.12391e+02), forces1[357], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.64496e+01, -8.65224e+01, 2.09075e+02), forces1[358], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.26786e+02, -1.04116e+02, 2.42460e+02), forces1[359], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.67930e+01, 5.02589e+01, 7.66782e+01), forces1[360], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.64137e+01, -5.87259e+01, 1.21975e+02), forces1[361], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.49708e+02, -5.25609e+01, -2.18329e+02), forces1[362], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.57850e+02, 5.04311e+02, -5.05894e+01), forces1[363], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.62212e+01, -2.94583e+02, 1.54045e+02), forces1[364], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.61638e+01, -1.84431e+02, 1.13710e+02), forces1[365], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.06173e+02, 9.36425e+01, 2.20592e+02), forces1[366], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.52623e+02, 1.46025e+02, 8.97291e+01), forces1[367], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.54323e+01, 2.26018e+02, 3.46087e+02), forces1[368], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.27183e+02, -2.09440e+01, -1.89634e+02), forces1[369], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.73506e+02, 2.01241e+02, 5.03574e+01), forces1[370], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.14771e+02, 1.73517e+02, 2.04777e+02), forces1[371], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.08803e+02, -4.69136e+01, 3.13410e+01), forces1[372], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.70333e+01, -9.14230e+01, 2.67645e+01), forces1[373], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.42054e+01, -1.04732e+02, -1.88134e+00), forces1[374], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.41157e+02, -1.07118e+02, 1.67297e+02), forces1[375], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.48356e+01, -8.47055e+01, 2.43285e+02), forces1[376], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.80449e+01, -1.46446e+02, 1.85386e+01), forces1[377], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.80687e+00, -6.96210e+01, 1.25177e+01), forces1[378], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.23687e+01, -9.93136e+01, 1.45164e+00), forces1[379], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.95215e+00, 1.37747e+01, 4.23959e+00), forces1[380], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.62211e+01, 5.78277e+02, 3.68049e+01), forces1[381], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.65270e+02, -1.15374e+02, 1.18132e+02), forces1[382], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.66667e+02, -8.49100e+01, 2.96994e+02), forces1[383], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.99785e+02, 2.24069e+02, 2.30458e+01), forces1[384], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.83662e+01, 2.02857e+01, 5.16795e+01), forces1[385], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.30910e+02, -2.01579e+02, 1.48973e+02), forces1[386], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.48803e+01, -2.39996e+02, -6.71369e+01), forces1[387], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.45565e+02, -2.03246e+02, -2.90114e+02), forces1[388], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.28809e+01, 1.07210e+02, 5.79218e+01), forces1[389], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.33045e+01, 4.29217e+01, -2.51884e+01), forces1[390], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.01216e+02, 7.87171e+01, -8.84528e+01), forces1[391], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.94984e+01, -1.82575e+00, 6.60948e+01), forces1[392], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.01760e+01, 1.13645e+02, 1.03720e+02), forces1[393], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.02227e+01, -1.82477e+02, -1.93295e+02), forces1[394], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.88739e+01, -7.04682e+01, -1.97902e+02), forces1[395], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.08208e+02, 2.04314e+02, -9.77061e+01), forces1[396], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.97001e+02, -3.37469e+01, 1.30428e+02), forces1[397], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.39859e+01, 1.55789e+02, 9.33634e+01), forces1[398], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.71075e+01, 1.01907e+02, -1.62363e+02), forces1[399], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.51477e+02, -1.49509e+02, 2.38020e+01), forces1[400], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.62232e+02, 1.06486e+02, 1.02031e+02), forces1[401], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.24938e+01, 1.19921e+02, -9.62759e+01), forces1[402], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.56992e+01, -1.10020e+02, 1.49108e+02), forces1[403], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.10656e+01, 2.79604e+01, 1.91755e+02), forces1[404], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.74338e+00, -7.08051e+01, -1.05929e+02), forces1[405], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.64700e+02, -1.27130e+02, -5.91595e+01), forces1[406], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.30385e+01, 2.08802e+01, -3.57840e+01), forces1[407], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.08287e+02, 2.29771e+01, -2.26233e+02), forces1[408], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.58650e+02, -1.14832e+02, -1.67121e+02), forces1[409], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.19177e+02, 9.05557e+01, 3.00496e+02), forces1[410], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.59854e+01, -1.24855e+02, 1.73507e+02), forces1[411], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.01537e+02, -3.21500e+01, -1.62947e+02), forces1[412], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.68513e+01, 7.25403e+01, 1.10509e+02), forces1[413], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.74676e+01, 1.99661e+02, -3.30448e+02), forces1[414], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.89877e+02, -5.06918e+01, 2.07261e+02), forces1[415], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.05311e+01, 7.99589e+01, -9.81659e+01), forces1[416], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.19039e+02, 7.86478e+01, -1.36094e+02), forces1[417], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.39276e+01, 1.04302e+02, -1.99319e+02), forces1[418], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.07836e+01, -7.02154e+01, -3.20077e+01), forces1[419], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.04021e+01, -2.95668e+01, -9.62964e+01), forces1[420], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.13789e+01, 2.11057e+01, -7.24998e+01), forces1[421], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.89102e+01, -6.59244e+01, -8.40365e+01), forces1[422], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.19672e+02, -4.01191e+01, 6.57098e+01), forces1[423], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.87553e+01, -8.69171e+01, 2.43178e+01), forces1[424], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.67881e+01, -1.94017e+02, 4.85473e+01), forces1[425], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.07150e+02, -1.99734e+02, -2.09862e+01), forces1[426], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.36179e+02, 1.95193e+01, -1.32315e+02), forces1[427], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.23323e+02, -6.31094e+01, -8.32846e+01), forces1[428], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.02495e+00, -1.45980e+02, 5.02494e+02), forces1[429], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.25222e+01, 1.02561e+02, 1.77325e+01), forces1[430], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.12695e+02, 3.15051e+02, -4.46404e+01), forces1[431], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.92031e+02, -9.89024e+01, -3.74688e+02), forces1[432], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.43199e+01, 7.50213e+01, 1.10375e+02), forces1[433], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.10558e+01, 2.43859e+02, 5.47498e+01), forces1[434], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.97703e+01, -1.48364e+02, -1.17638e+02), forces1[435], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.62397e+01, 4.88941e+01, -2.71595e+02), forces1[436], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.31340e+01, -8.20624e+01, 1.16191e+02), forces1[437], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.38517e+02, -7.62394e+01, -5.88168e+00), forces1[438], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.62851e+01, 6.72427e+01, -1.80434e+01), forces1[439], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.58861e+02, 1.15957e+02, -3.78160e+01), forces1[440], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.51803e+02, -4.12446e+01, -8.91525e+01), forces1[441], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.61287e+01, -1.36689e+02, -9.23537e+00), forces1[442], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.82943e+02, 1.05844e+02, -1.72148e+02), forces1[443], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.55236e+01, 9.18378e+01, 1.24360e+01), forces1[444], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.01227e+01, 8.39026e+01, 3.96741e+02), forces1[445], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.87558e+01, 5.47395e+01, -5.73402e+00), forces1[446], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.60796e+02, -5.52985e+01, 3.17802e+01), forces1[447], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.11619e+02, 1.11090e+02, 1.51495e+02), forces1[448], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.78213e+01, -1.33902e+02, 1.13590e+02), forces1[449], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.74607e+02, -2.79326e+02, -1.00171e+02), forces1[450], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.47808e+01, -1.29366e+02, -1.92232e+02), forces1[451], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.75509e+00, 1.63688e+01, -3.24829e+02), forces1[452], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.93082e+01, -2.44679e+02, 7.91941e+01), forces1[453], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.41263e+01, 9.35389e+01, 9.69223e+01), forces1[454], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.76713e+02, 1.98982e+02, 2.68113e+01), forces1[455], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.79544e+01, 6.96513e+01, -1.90320e+02), forces1[456], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.34104e+02, 2.74828e+01, -3.93803e+01), forces1[457], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.28254e+02, -1.35572e+02, -4.32733e+01), forces1[458], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.28600e+01, 3.07094e+00, -3.78996e+01), forces1[459], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.03587e+02, 1.77989e+02, -6.99490e+01), forces1[460], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.08656e+02, -4.54770e+01, -6.76500e+01), forces1[461], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.71838e+01, 5.19782e+01, -2.94923e+01), forces1[462], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.40301e+02, 2.74572e+02, -3.56579e+01), forces1[463], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.03587e+01, -3.16257e+01, -7.72873e+01), forces1[464], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.67138e+02, -7.24846e+01, -6.24143e+01), forces1[465], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.03813e+00, 9.49458e+01, 3.72519e+01), forces1[466], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.14010e+01, 6.47582e+01, 1.42218e+02), forces1[467], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.20325e+01, 1.99039e+02, 3.65580e+02), forces1[468], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.42970e+02, -8.88587e+01, 1.72171e+02), forces1[469], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.90803e+01, -2.60758e+02, 1.15577e+02), forces1[470], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.52557e+02, -8.51485e+00, -1.82612e+02), forces1[471], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 5.19978e+00, 1.82368e+02, 4.96817e+01), forces1[472], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.60405e+02, -5.75249e+01, 4.30526e+01), forces1[473], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.05782e+01, -1.01381e+02, 5.21152e+01), forces1[474], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.98251e-01, 1.60005e+02, 2.94808e+01), forces1[475], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.38812e+02, -2.31535e+02, 1.88049e+02), forces1[476], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.81939e+01, 1.28753e+02, -1.67824e+02), forces1[477], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.23875e+02, 1.55757e+02, -2.79290e+02), forces1[478], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.68146e+01, 8.00636e+01, 1.82356e+00), forces1[479], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.81555e+02, -2.44338e+02, -1.67866e+02), forces1[480], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.60882e+02, 1.64545e+02, 1.24397e+02), forces1[481], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.43347e+02, 1.22527e+02, 2.15375e+02), forces1[482], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.75592e+02, -3.02264e+02, 3.12921e+02), forces1[483], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.42347e+02, 1.64524e+02, 1.46878e+02), forces1[484], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.44791e+00, 6.90323e+01, -3.86573e+01), forces1[485], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.00184e+02, -1.07891e+02, 3.14068e+01), forces1[486], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.40711e+01, 1.27511e+01, 5.66277e+01), forces1[487], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.74580e+02, -1.14306e+02, -1.37535e+02), forces1[488], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.98657e+01, 2.19658e+02, -7.96343e+01), forces1[489], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.90069e+02, 1.36943e+02, -1.78217e+02), forces1[490], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.64334e+01, 2.56388e+02, -8.52711e+01), forces1[491], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.38510e+01, -1.61329e+02, 2.59550e+02), forces1[492], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-8.11033e+01, -7.18533e+01, 7.75259e+00), forces1[493], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.05854e+02, 3.14397e+02, -4.61488e+02), forces1[494], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.69218e+02, 1.76533e+02, 2.08605e+02), forces1[495], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.06655e+01, -6.09886e+02, -6.99069e+01), forces1[496], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.19305e+02, -1.88157e+02, 1.20294e+02), forces1[497], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.74817e+01, -1.67738e+01, -7.85411e+00), forces1[498], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.56252e+00, -4.35681e+01, -6.24241e+01), forces1[499], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.73399e+01, 1.15493e+02, 9.92190e+01), forces1[500], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.58626e+01, 9.15080e+01, 3.20924e+00), forces1[501], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.09582e+01, -1.76054e+01, 6.71996e+00), forces1[502], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.59525e+01, 1.83369e+02, -1.70381e+02), forces1[503], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.32243e+01, 3.37044e+01, -6.27663e+01), forces1[504], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.91590e+01, -5.93696e+01, -7.26003e+01), forces1[505], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.74042e+00, 7.24544e+01, 5.83752e+01), forces1[506], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.35769e+01, 4.35961e+02, 7.54309e+01), forces1[507], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.81578e+02, -1.82955e+02, -1.36110e+02), forces1[508], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.53200e+02, -2.25646e+01, -1.26235e+02), forces1[509], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.02017e+01, 7.54878e+01, -9.98370e+01), forces1[510], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.56935e+01, 7.19882e+00, -3.07487e+02), forces1[511], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.60290e+01, 4.63810e+01, -1.39429e+02), forces1[512], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.36883e+02, -2.71943e+02, 1.90138e+01), forces1[513], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.95573e+01, -1.31976e+02, -1.48737e+02), forces1[514], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.61876e+02, 1.02997e+02, -1.00309e+02), forces1[515], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.73595e+00, 3.79678e+01, 9.45418e+01), forces1[516], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.60218e+00, -7.40917e+01, -2.21371e+01), forces1[517], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.27199e+02, 1.31094e+02, 1.12529e+02), forces1[518], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.04103e+02, 4.69682e+01, -1.18068e+02), forces1[519], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.12794e+01, -1.26833e+02, -4.04741e+01), forces1[520], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.09384e+01, 1.86161e+02, 3.95213e+01), forces1[521], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.91470e+02, 8.17955e+01, -9.25509e+01), forces1[522], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.33121e+01, 7.77548e-01, -1.48384e+02), forces1[523], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.52149e+02, -1.00219e+02, -7.57906e+01), forces1[524], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.46003e+02, -1.03331e+01, 1.17347e+01), forces1[525], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.09634e+00, 1.43847e+02, -1.42581e+02), forces1[526], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.68641e+02, 6.25042e+01, -7.01507e+01), forces1[527], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.49802e+01, 2.37203e+02, -2.40370e+02), forces1[528], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.85669e+01, -1.41784e+02, 4.28138e+01), forces1[529], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.75729e+01, -3.33632e+02, 1.31688e+02), forces1[530], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.04035e+02, 1.12452e+02, 7.19995e+01), forces1[531], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.61972e+00, 5.32166e+01, -9.89477e+01), forces1[532], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.19982e+01, -2.20164e+02, 9.06987e-01), forces1[533], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.71185e+01, -7.67379e+01, 8.12237e+01), forces1[534], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.80057e+01, -1.09793e+02, -2.04253e+01), forces1[535], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.16821e+02, 1.20240e+02, 5.96457e+01), forces1[536], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.64018e+01, 6.17819e+01, 9.91575e+01), forces1[537], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.55515e+01, -9.66187e+01, -8.19956e+00), forces1[538], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.17947e+01, -1.53378e+01, 1.27485e+00), forces1[539], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.02055e+02, 7.70776e+01, 1.14883e+02), forces1[540], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.43124e+01, 9.43473e+01, 8.60578e+01), forces1[541], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.81264e+01, -1.32125e+02, 2.56224e+01), forces1[542], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.25842e+01, -1.26725e+02, -8.30650e+01), forces1[543], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.50125e+01, -6.20165e+01, 2.58080e+01), forces1[544], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.55319e+01, -1.59769e+01, -7.15921e+01), forces1[545], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.34804e+01, 4.08590e+02, -8.70023e+01), forces1[546], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.53654e+01, -2.03185e+02, -4.39618e+01), forces1[547], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.62931e+01, -2.78936e+02, 5.62579e+00), forces1[548], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.92745e+01, -9.69829e+01, -3.54599e+01), forces1[549], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.58047e+01, -8.17034e+01, 5.89773e+01), forces1[550], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.75002e+01, -7.94191e+01, 7.55542e+01), forces1[551], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-9.53611e+01, 1.20621e+02, 1.49809e+02), forces1[552], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.63438e+01, -6.24402e+01, -1.12122e+01), forces1[553], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.11429e+02, -4.56045e+01, -4.59567e+01), forces1[554], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.28516e+02, -4.47595e+00, 1.81453e+02), forces1[555], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.33297e+02, 1.44805e+02, -4.27640e+01), forces1[556], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.16740e+02, -7.65847e+00, 7.66024e+01), forces1[557], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.77942e+02, -1.45939e+02, 8.07326e+01), forces1[558], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.68632e+02, 2.69537e+02, 1.22007e+02), forces1[559], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.12709e+02, 6.01408e+01, 1.54041e+02), forces1[560], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.27652e+02, -5.25610e+01, -9.60596e+01), forces1[561], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.14047e+02, -2.01466e+01, -4.96293e+01), forces1[562], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.09791e+02, 4.12161e+01, 1.83442e+02), forces1[563], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.49134e+02, -4.62596e+00, 2.20999e+01), forces1[564], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.30637e+02, -3.75250e+01, 4.14259e+01), forces1[565], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.75025e+02, 3.85962e+01, 5.80226e+01), forces1[566], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.98389e+00, -1.23933e+02, 1.30628e+02), forces1[567], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.05449e+01, -1.14065e+02, 9.70791e+01), forces1[568], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.60462e+01, -9.53328e+01, 9.89856e+01), forces1[569], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.13288e+01, -1.44056e+01, 1.39952e+02), forces1[570], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.42917e+01, 1.66166e+01, 1.91947e+02), forces1[571], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.13590e+02, -1.55874e+02, -1.13269e+02), forces1[572], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.42809e+02, 3.88945e+02, 1.47303e+02), forces1[573], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.29792e+02, -1.91594e+02, -4.64513e+01), forces1[574], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.06517e+02, -3.17549e+02, 9.06953e+00), forces1[575], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.35062e+02, -3.38933e+01, -9.66009e+01), forces1[576], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.67609e+02, 1.26402e+02, -4.97788e+01), forces1[577], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.05138e+00, 1.07362e+02, -1.02375e+02), forces1[578], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.22771e+02, -7.72250e+01, 1.66501e+02), forces1[579], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.95650e+01, 8.12102e+00, 1.03117e+02), forces1[580], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.75584e+02, 2.88991e+01, -1.17320e+02), forces1[581], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-6.91275e+01, 8.38319e+01, 4.97708e+01), forces1[582], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.51951e+02, 1.60368e+02, -2.06266e+02), forces1[583], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.31889e+01, -2.02781e+02, -8.72161e+01), forces1[584], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.92408e+02, -1.87100e+01, 2.05541e+02), forces1[585], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.73554e+02, -5.01580e+00, 2.66621e+02), forces1[586], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.59561e+02, 9.15584e+00, 1.28235e+02), forces1[587], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.11016e+01, 7.42097e+01, -4.28122e+01), forces1[588], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.03537e+02, 2.10837e+01, -1.33908e+02), forces1[589], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.16906e+01, -1.58535e+01, 4.67992e+01), forces1[590], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.44325e+02, -2.46328e+00, -1.81854e+01), forces1[591], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-5.30320e+01, 9.72891e+01, 2.06240e+01), forces1[592], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.36896e+01, 1.33852e+02, 5.19553e+01), forces1[593], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 9.50875e+00, -1.63962e+02, -7.41674e+01), forces1[594], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.07601e+02, -8.54691e+01, 3.11595e+01), forces1[595], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.65770e+02, -4.64405e+01, 8.34911e+01), forces1[596], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.44367e+01, -1.84108e+02, 1.39835e+02), forces1[597], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.24114e+02, 2.50886e+01, 2.54009e+01), forces1[598], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.16187e+02, -4.85179e+01, 1.32305e+02), forces1[599], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.37446e+01, -3.29674e+01, 1.16326e+02), forces1[600], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.68011e+01, -1.00073e+02, 8.04682e+01), forces1[601], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-4.83294e+01, -1.73859e+02, 1.36328e+01), forces1[602], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.83292e+01, 1.39303e+02, -1.01045e+02), forces1[603], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.07133e+01, 1.29633e+02, -1.90943e+02), forces1[604], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.55543e+02, 7.87557e+01, 9.29806e+01), forces1[605], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.64013e+02, -2.60759e+01, 1.75076e+02), forces1[606], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.33794e+02, -1.63774e+02, -6.37393e+01), forces1[607], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.54235e+02, 2.41512e+02, 1.60676e+02), forces1[608], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.17775e+02, 6.48107e+01, 3.84545e+01), forces1[609], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.04735e+01, 2.01260e+01, 2.39831e+01), forces1[610], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.38884e+02, 1.20777e+02, -5.46490e+01), forces1[611], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.07723e+02, 2.58444e+02, 1.48247e+02), forces1[612], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.01470e+02, -6.94941e+01, -2.70882e+02), forces1[613], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.21667e+01, -1.98769e+02, -1.54892e+02), forces1[614], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.80724e+02, 4.52486e+01, 1.40398e+02), forces1[615], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 3.86820e+02, -7.75719e+00, -1.08164e+01), forces1[616], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.42790e+02, 4.80985e+01, -6.18837e+00), forces1[617], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.76946e+02, -1.97796e+02, 2.44731e+01), forces1[618], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.47411e+02, 2.23512e+02, -4.11150e+01), forces1[619], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.04834e+01, 5.22527e+01, -2.27808e+01), forces1[620], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.52307e+02, 7.40937e+01, 1.12984e+02), forces1[621], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.32953e+01, -1.29608e+02, 1.32966e+02), forces1[622], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.23861e+01, -1.19511e+02, 1.00268e+02), forces1[623], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.50610e+01, -1.46388e+02, -7.77507e+01), forces1[624], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 8.62300e+01, -1.37666e+02, -1.20764e+02), forces1[625], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.47310e+01, -1.47118e+02, -5.18370e+01), forces1[626], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.62932e+01, 7.13690e+01, 1.43985e+02), forces1[627], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.96823e+01, -3.58054e+01, -1.45690e+02), forces1[628], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.18087e+00, 1.85480e+01, 9.50527e+01), forces1[629], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.74362e+00, 1.43052e+01, -4.25871e+01), forces1[630], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.97525e+02, -1.59562e+01, 1.90143e+01), forces1[631], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 2.57292e+01, -2.08667e+02, 2.11507e+01), forces1[632], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.01669e+01, -1.07214e+02, -2.53008e+01), forces1[633], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.18560e+02, 4.41674e+01, -1.78058e+02), forces1[634], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.93301e+00, 5.90508e+01, -3.94824e+01), forces1[635], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-7.81815e+01, 8.73784e+01, -6.35956e+01), forces1[636], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.52356e+01, 1.30136e+02, 1.52025e+01), forces1[637], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.66178e+02, -5.94385e+01, -1.04578e+02), forces1[638], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-1.19123e+02, -1.75069e+02, -2.04114e+00), forces1[639], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-3.92283e+01, 5.61702e+01, 1.27395e+02), forces1[640], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 4.74836e-01, -2.04058e+02, -4.01525e+01), forces1[641], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 6.92669e+01, 6.04519e+00, 4.03163e+01), forces1[642], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.08236e+01, 1.26554e+02, -8.63729e+01), forces1[643], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.88180e+02, -1.08833e+02, -1.18964e+02), forces1[644], 10*TOL);
ASSERT_EQUAL_VEC(Vec3(-2.76077e+01, -2.97113e+02, 5.08198e+02), forces1[645], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 1.84023e+02, 3.56521e+02, -2.17616e+02), forces1[646], 10*TOL);
ASSERT_EQUAL_VEC(Vec3( 7.81607e+01, 3.17356e+02, -1.40920e+02), forces1[647], 10*TOL);
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/AndersenThermostat.h"
#include "openmm/Context.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
void testTemperature() {
const int numParticles = 8;
const double temp = 100.0;
const double collisionFreq = 10.0;
const int numSteps = 5000;
System system;
VerletIntegrator integrator(0.003);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(2.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
AndersenThermostat* thermostat = new AndersenThermostat(temp, collisionFreq);
system.addForce(thermostat);
ASSERT(!thermostat->usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; ++i)
positions[i] = Vec3((i%2 == 0 ? 2 : -2), (i%4 < 2 ? 2 : -2), (i < 4 ? 2 : -2));
context.setPositions(positions);
context.setVelocitiesToTemperature(temp);
// Let it equilibrate.
integrator.step(10000);
// Now run it for a while and see if the temperature is correct.
double ke = 0.0;
for (int i = 0; i < numSteps; ++i) {
State state = context.getState(State::Energy);
ke += state.getKineticEnergy();
integrator.step(10);
}
ke /= numSteps;
double expected = 0.5*numParticles*3*BOLTZ*temp;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1);
}
void testConstraints() {
const int numParticles = 8;
const double temp = 100.0;
const double collisionFreq = 10.0;
const int numSteps = 15000;
System system;
VerletIntegrator integrator(0.004);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(2.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
system.addConstraint(0, 1, 1);
system.addConstraint(1, 2, 1);
system.addConstraint(2, 3, 1);
system.addConstraint(3, 0, 1);
system.addConstraint(4, 5, 1);
system.addConstraint(5, 6, 1);
system.addConstraint(6, 7, 1);
system.addConstraint(7, 4, 1);
AndersenThermostat* thermostat = new AndersenThermostat(temp, collisionFreq);
system.addForce(thermostat);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(1, 0, 0);
positions[2] = Vec3(1, 1, 0);
positions[3] = Vec3(0, 1, 0);
positions[4] = Vec3(1, 0, 1);
positions[5] = Vec3(1, 1, 1);
positions[6] = Vec3(0, 1, 1);
positions[7] = Vec3(0, 0, 1);
context.setPositions(positions);
context.setVelocitiesToTemperature(temp);
// Let it equilibrate.
integrator.step(5000);
// Now run it for a while and see if the temperature is correct.
double ke = 0.0;
for (int i = 0; i < numSteps; ++i) {
State state = context.getState(State::Energy);
ke += state.getKineticEnergy();
integrator.step(1);
}
ke /= numSteps;
double expected = 0.5*(numParticles*3-system.getNumConstraints())*BOLTZ*temp;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1);
}
void testRandomSeed() {
const int numParticles = 8;
const double temp = 100.0;
const double collisionFreq = 10.0;
System system;
VerletIntegrator integrator(0.01);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(2.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
AndersenThermostat* thermostat = new AndersenThermostat(temp, collisionFreq);
system.addForce(thermostat);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
for (int i = 0; i < numParticles; ++i) {
positions[i] = Vec3((i%2 == 0 ? 2 : -2), (i%4 < 2 ? 2 : -2), (i < 4 ? 2 : -2));
velocities[i] = Vec3(0, 0, 0);
}
// Try twice with the same random seed.
thermostat->setRandomNumberSeed(5);
Context context(system, integrator, platform);
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state1 = context.getState(State::Positions);
context.reinitialize();
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state2 = context.getState(State::Positions);
// Try twice with a different random seed.
thermostat->setRandomNumberSeed(10);
context.reinitialize();
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state3 = context.getState(State::Positions);
context.reinitialize();
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state4 = context.getState(State::Positions);
// Compare the results.
for (int i = 0; i < numParticles; i++) {
for (int j = 0; j < 3; j++) {
ASSERT(state1.getPositions()[i][j] == state2.getPositions()[i][j]);
ASSERT(state3.getPositions()[i][j] == state4.getPositions()[i][j]);
ASSERT(state1.getPositions()[i][j] != state3.getPositions()[i][j]);
}
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testTemperature();
testConstraints();
testRandomSeed();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/BrownianIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testSingleBond() {
System system;
system.addParticle(2.0);
system.addParticle(2.0);
double dt = 0.01;
BrownianIntegrator integrator(0, 0.1, dt);
HarmonicBondForce* forceField = new HarmonicBondForce();
forceField->addBond(0, 1, 1.5, 1);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(-1, 0, 0);
positions[1] = Vec3(1, 0, 0);
context.setPositions(positions);
// This is simply an overdamped harmonic oscillator, so compare it to the analytical solution.
double rate = 2*1.0/(0.1*2.0);
for (int i = 0; i < 1000; ++i) {
State state = context.getState(State::Positions | State::Velocities);
double time = state.getTime();
double expectedDist = 1.5+0.5*std::exp(-rate*time);
ASSERT_EQUAL_VEC(Vec3(-0.5*expectedDist, 0, 0), state.getPositions()[0], 0.02);
ASSERT_EQUAL_VEC(Vec3(0.5*expectedDist, 0, 0), state.getPositions()[1], 0.02);
if (i > 0) {
double expectedSpeed = -0.5*rate*std::exp(-rate*(time-0.5*dt));
ASSERT_EQUAL_VEC(Vec3(-0.5*expectedSpeed, 0, 0), state.getVelocities()[0], 0.11);
ASSERT_EQUAL_VEC(Vec3(0.5*expectedSpeed, 0, 0), state.getVelocities()[1], 0.11);
}
integrator.step(1);
}
}
void testTemperature() {
const int numParticles = 8;
const int numBonds = numParticles-1;
const double temp = 10.0;
System system;
BrownianIntegrator integrator(temp, 2.0, 0.01);
HarmonicBondForce* forceField = new HarmonicBondForce();
for (int i = 0; i < numParticles; ++i)
system.addParticle(2.0);
for (int i = 0; i < numBonds; ++i)
forceField->addBond(i, i+1, 1.0, 5.0);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; ++i)
positions[i] = Vec3(i, 0, 0);
context.setPositions(positions);
// Let it equilibrate.
integrator.step(10000);
// Now run it for a while and see if the temperature is correct.
double pe = 0.0;
const int steps = 50000;
for (int i = 0; i < steps; ++i) {
State state = context.getState(State::Energy);
pe += state.getPotentialEnergy();
integrator.step(1);
}
pe /= steps;
double expected = 0.5*numBonds*BOLTZ*temp;
ASSERT_USUALLY_EQUAL_TOL(expected, pe, 0.1*expected);
}
void testConstraints() {
const int numParticles = 8;
const int numConstraints = 5;
const double temp = 20.0;
System system;
BrownianIntegrator integrator(temp, 2.0, 0.001);
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(10.0);
forceField->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
system.addConstraint(0, 1, 1.0);
system.addConstraint(1, 2, 1.0);
system.addConstraint(2, 3, 1.0);
system.addConstraint(4, 5, 1.0);
system.addConstraint(6, 7, 1.0);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; ++i) {
positions[i] = Vec3(i, 0, 0);
velocities[i] = Vec3(genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5);
}
context.setPositions(positions);
context.setVelocities(velocities);
// Simulate it and see whether the constraints remain satisfied.
for (int i = 0; i < 1000; ++i) {
State state = context.getState(State::Positions);
for (int j = 0; j < numConstraints; ++j) {
int particle1, particle2;
double distance;
system.getConstraintParameters(j, particle1, particle2, distance);
Vec3 p1 = state.getPositions()[particle1];
Vec3 p2 = state.getPositions()[particle2];
double dist = std::sqrt((p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1])+(p1[2]-p2[2])*(p1[2]-p2[2]));
ASSERT_EQUAL_TOL(distance, dist, 1e-4);
}
integrator.step(1);
}
}
void testConstrainedMasslessParticles() {
System system;
system.addParticle(0.0);
system.addParticle(1.0);
system.addConstraint(0, 1, 1.5);
vector<Vec3> positions(2);
positions[0] = Vec3(-1, 0, 0);
positions[1] = Vec3(1, 0, 0);
BrownianIntegrator integrator(300.0, 2.0, 0.01);
bool failed = false;
try {
// This should throw an exception.
Context context(system, integrator, platform);
}
catch (exception& ex) {
failed = true;
}
ASSERT(failed);
// Now make both particles massless, which should work.
system.setParticleMass(1, 0.0);
Context context(system, integrator, platform);
context.setPositions(positions);
context.setVelocitiesToTemperature(300.0);
integrator.step(1);
State state = context.getState(State::Velocities);
ASSERT_EQUAL(0.0, state.getVelocities()[0][0]);
}
void testRandomSeed() {
const int numParticles = 8;
const double temp = 100.0;
const double collisionFreq = 10.0;
System system;
BrownianIntegrator integrator(temp, 2.0, 0.001);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(2.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
for (int i = 0; i < numParticles; ++i) {
positions[i] = Vec3((i%2 == 0 ? 2 : -2), (i%4 < 2 ? 2 : -2), (i < 4 ? 2 : -2));
velocities[i] = Vec3(0, 0, 0);
}
// Try twice with the same random seed.
integrator.setRandomNumberSeed(5);
Context context(system, integrator, platform);
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state1 = context.getState(State::Positions);
context.reinitialize();
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state2 = context.getState(State::Positions);
// Try twice with a different random seed.
integrator.setRandomNumberSeed(10);
context.reinitialize();
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state3 = context.getState(State::Positions);
context.reinitialize();
context.setPositions(positions);
context.setVelocities(velocities);
integrator.step(10);
State state4 = context.getState(State::Positions);
// Compare the results.
for (int i = 0; i < numParticles; i++) {
for (int j = 0; j < 3; j++) {
ASSERT(state1.getPositions()[i][j] == state2.getPositions()[i][j]);
ASSERT(state3.getPositions()[i][j] == state4.getPositions()[i][j]);
ASSERT(state1.getPositions()[i][j] != state3.getPositions()[i][j]);
}
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testSingleBond();
testTemperature();
testConstraints();
testConstrainedMasslessParticles();
testRandomSeed();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CMAPTorsionForce.h"
#include "openmm/PeriodicTorsionForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testCMAPTorsions() {
const int mapSize = 36;
// Create two systems: one with a pair of periodic torsions, and one with a CMAP torsion
// that approximates the same force.
System system1;
for (int i = 0; i < 5; i++)
system1.addParticle(1.0);
PeriodicTorsionForce* periodic = new PeriodicTorsionForce();
periodic->addTorsion(0, 1, 2, 3, 2, M_PI/4, 1.5);
periodic->addTorsion(1, 2, 3, 4, 3, M_PI/3, 2.0);
system1.addForce(periodic);
ASSERT(!periodic->usesPeriodicBoundaryConditions());
ASSERT(!system1.usesPeriodicBoundaryConditions());
System system2;
for (int i = 0; i < 5; i++)
system2.addParticle(1.0);
CMAPTorsionForce* cmap = new CMAPTorsionForce();
vector<double> mapEnergy(mapSize*mapSize);
for (int i = 0; i < mapSize; i++) {
double angle1 = i*2*M_PI/mapSize;
double energy1 = 1.5*(1+cos(2*angle1-M_PI/4));
for (int j = 0; j < mapSize; j++) {
double angle2 = j*2*M_PI/mapSize;
double energy2 = 2.0*(1+cos(3*angle2-M_PI/3));
mapEnergy[i+j*mapSize] = energy1+energy2;
}
}
cmap->addMap(mapSize, mapEnergy);
cmap->addTorsion(0, 0, 1, 2, 3, 1, 2, 3, 4);
system2.addForce(cmap);
ASSERT(!cmap->usesPeriodicBoundaryConditions());
ASSERT(!system2.usesPeriodicBoundaryConditions());
// Set the atoms in various positions, and verify that both systems give equal forces and energy.
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(5);
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context c1(system1, integrator1, platform);
Context c2(system2, integrator2, platform);
for (int i = 0; i < 50; i++) {
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
c1.setPositions(positions);
c2.setPositions(positions);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
for (int i = 0; i < system1.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], 0.05);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), 1e-3);
}
}
void testChangingParameters() {
// Create a system with two maps and one torsion.
const int mapSize = 8;
System system;
for (int i = 0; i < 5; i++)
system.addParticle(1.0);
CMAPTorsionForce* cmap = new CMAPTorsionForce();
vector<double> mapEnergy1(mapSize*mapSize);
vector<double> mapEnergy2(mapSize*mapSize);
for (int i = 0; i < mapSize; i++) {
double angle1 = i*2*M_PI/mapSize;
double energy1 = cos(angle1);
for (int j = 0; j < mapSize; j++) {
double angle2 = j*2*M_PI/mapSize;
double energy2 = 10*sin(angle2);
mapEnergy1[i+j*mapSize] = energy1+energy2;
mapEnergy2[i+j*mapSize] = energy1-energy2;
}
}
cmap->addMap(mapSize, mapEnergy1);
cmap->addMap(mapSize, mapEnergy2);
cmap->addTorsion(0, 0, 1, 2, 3, 1, 2, 3, 4);
system.addForce(cmap);
// Set particle positions so angle1=0 and angle2=PI/4.
vector<Vec3> positions(5);
positions[0] = Vec3(0, 0, 1);
positions[1] = Vec3(0, 0, 0);
positions[2] = Vec3(1, 0, 0);
positions[3] = Vec3(1, 0, 1);
positions[4] = Vec3(0.5, -0.5, 1);
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
// Check that the energy is correct.
double energy = context.getState(State::Energy).getPotentialEnergy();
ASSERT_EQUAL_TOL(1+10*sin(M_PI/4), energy, 1e-5);
// Modify the parameters.
cmap->setTorsionParameters(0, 1, 0, 1, 2, 3, 1, 2, 3, 4);
for (int i = 0; i < mapSize*mapSize; i++)
mapEnergy2[i] *= 2.0;
cmap->setMapParameters(1, mapSize, mapEnergy2);
cmap->updateParametersInContext(context);
// See if the results are correct.
energy = context.getState(State::Energy).getPotentialEnergy();
ASSERT_EQUAL_TOL(2-20*sin(M_PI/4), energy, 1e-5);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testCMAPTorsions();
testChangingParameters();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/CMMotionRemover.h"
#include "openmm/Context.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/VerletIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
Vec3 calcCM(const vector<Vec3>& values, System& system) {
Vec3 cm;
for (int j = 0; j < system.getNumParticles(); ++j) {
cm[0] += values[j][0]*system.getParticleMass(j);
cm[1] += values[j][1]*system.getParticleMass(j);
cm[2] += values[j][2]*system.getParticleMass(j);
}
return cm;
}
void testMotionRemoval(Integrator& integrator) {
const int numParticles = 8;
System system;
HarmonicBondForce* bonds = new HarmonicBondForce();
bonds->addBond(2, 3, 2.0, 0.5);
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(i+1);
nonbonded->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(nonbonded);
CMMotionRemover* remover = new CMMotionRemover();
system.addForce(remover);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; ++i) {
positions[i] = Vec3((i%2 == 0 ? 2 : -2), (i%4 < 2 ? 2 : -2), (i < 4 ? 2 : -2));
velocities[i] = Vec3(genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5);
}
context.setPositions(positions);
context.setVelocities(velocities);
// Now run it for a while and see if the center of mass remains fixed.
Vec3 cmPos = calcCM(context.getState(State::Positions).getPositions(), system);
for (int i = 0; i < 1000; ++i) {
integrator.step(1);
State state = context.getState(State::Positions | State::Velocities);
Vec3 pos = calcCM(state.getPositions(), system);
ASSERT_EQUAL_VEC(cmPos, pos, 1e-2);
Vec3 vel = calcCM(state.getVelocities(), system);
if (i > 0) {
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), vel, 1e-2);
}
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
LangevinIntegrator langevin(0.0, 1e-5, 0.01);
testMotionRemoval(langevin);
VerletIntegrator verlet(0.01);
testMotionRemoval(verlet);
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2012-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/AndersenThermostat.h"
#include "openmm/Context.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <sstream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void compareStates(State& s1, State& s2) {
ASSERT_EQUAL_TOL(s1.getTime(), s2.getTime(), TOL);
int numParticles = s1.getPositions().size();
for (int i = 0; i < numParticles; i++) {
ASSERT_EQUAL_VEC(s1.getPositions()[i], s2.getPositions()[i], TOL);
ASSERT_EQUAL_VEC(s1.getVelocities()[i], s2.getVelocities()[i], TOL);
Vec3 a1, b1, c1, a2, b2, c2;
s1.getPeriodicBoxVectors(a1, b1, c1);
s2.getPeriodicBoxVectors(a2, b2, c2);
ASSERT_EQUAL_VEC(a1, a2, TOL);
ASSERT_EQUAL_VEC(b1, b2, TOL);
ASSERT_EQUAL_VEC(c1, c2, TOL);
for (map<string, double>::const_iterator iter = s1.getParameters().begin(); iter != s1.getParameters().end(); ++iter)
ASSERT_EQUAL(iter->second, (*s2.getParameters().find(iter->first)).second);
}
}
void testSetState() {
const int numParticles = 10;
const double boxSize = 3.0;
const double temperature = 200.0;
System system;
system.addForce(new AndersenThermostat(0.0, 100.0));
NonbondedForce* nonbonded = new NonbondedForce();
system.addForce(nonbonded);
nonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
vector<Vec3> positions(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.0);
nonbonded->addParticle(i%2 == 0 ? 0.1 : -0.1, 0.2, 0.1);
positions[i] = Vec3(boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt));
}
VerletIntegrator integrator(0.001);
Context context(system, integrator, platform);
context.setPositions(positions);
context.setPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
context.setParameter(AndersenThermostat::Temperature(), temperature);
// Run for a little while.
integrator.step(100);
// Record the current state.
State s1 = context.getState(State::Positions | State::Velocities | State::Parameters);
// Continue the simulation for a few more steps and record a partial state.
integrator.step(10);
State s2 = context.getState(State::Positions);
// Restore the original state and see if everything gets restored correctly.
context.setPeriodicBoxVectors(Vec3(2*boxSize, 0, 0), Vec3(0, 2*boxSize, 0), Vec3(0, 0, 2*boxSize));
context.setParameter(AndersenThermostat::Temperature(), temperature+10);
context.setState(s1);
State s3 = context.getState(State::Positions | State::Velocities | State::Parameters);
compareStates(s1, s3);
// Set the partial state and see if the correct things were set.
context.setState(s2);
State s4 = context.getState(State::Positions | State::Velocities | State::Parameters);
for (int i = 0; i < numParticles; i++) {
ASSERT_EQUAL_VEC(s2.getPositions()[i], s4.getPositions()[i], TOL);
ASSERT_EQUAL_VEC(s1.getVelocities()[i], s4.getVelocities()[i], TOL);
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testSetState();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomAngleForce.h"
#include "openmm/HarmonicAngleForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testAngles() {
// Create a system using a CustomAngleForce.
System customSystem;
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
CustomAngleForce* custom = new CustomAngleForce("scale*k*(theta-theta0)^2");
custom->addPerAngleParameter("theta0");
custom->addPerAngleParameter("k");
custom->addGlobalParameter("scale", 0.5);
vector<double> parameters(2);
parameters[0] = 1.5;
parameters[1] = 0.8;
custom->addAngle(0, 1, 2, parameters);
parameters[0] = 2.0;
parameters[1] = 0.5;
custom->addAngle(1, 2, 3, parameters);
customSystem.addForce(custom);
ASSERT(!custom->usesPeriodicBoundaryConditions());
ASSERT(!customSystem.usesPeriodicBoundaryConditions());
// Create an identical system using a HarmonicAngleForce.
System harmonicSystem;
harmonicSystem.addParticle(1.0);
harmonicSystem.addParticle(1.0);
harmonicSystem.addParticle(1.0);
harmonicSystem.addParticle(1.0);
HarmonicAngleForce* harmonic = new HarmonicAngleForce();
harmonic->addAngle(0, 1, 2, 1.5, 0.8);
harmonic->addAngle(1, 2, 3, 2.0, 0.5);
harmonicSystem.addForce(harmonic);
// Set the atoms in various positions, and verify that both systems give identical forces and energy.
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(4);
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context c1(customSystem, integrator1, platform);
Context c2(harmonicSystem, integrator2, platform);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
c1.setPositions(positions);
c2.setPositions(positions);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), TOL);
}
// Try changing the angle parameters and make sure it's still correct.
parameters[0] = 1.6;
parameters[1] = 0.9;
custom->setAngleParameters(0, 0, 1, 2, parameters);
parameters[0] = 2.1;
parameters[1] = 0.6;
custom->setAngleParameters(1, 1, 2, 3, parameters);
custom->updateParametersInContext(c1);
harmonic->setAngleParameters(0, 0, 1, 2, 1.6, 0.9);
harmonic->setAngleParameters(1, 1, 2, 3, 2.1, 0.6);
harmonic->updateParametersInContext(c2);
{
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
c1.setPositions(positions);
c2.setPositions(positions);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), TOL);
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testAngles();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomBondForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testBonds() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomBondForce* forceField = new CustomBondForce("scale*k*(r-r0)^2");
forceField->addPerBondParameter("r0");
forceField->addPerBondParameter("k");
forceField->addGlobalParameter("scale", 0.5);
vector<double> parameters(2);
parameters[0] = 1.5;
parameters[1] = 0.8;
forceField->addBond(0, 1, parameters);
parameters[0] = 1.2;
parameters[1] = 0.7;
forceField->addBond(1, 2, parameters);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 2, 0);
positions[1] = Vec3(0, 0, 0);
positions[2] = Vec3(1, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
{
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0, -0.8*0.5, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0.7*0.2, 0, 0), forces[2], TOL);
ASSERT_EQUAL_VEC(Vec3(-forces[0][0]-forces[2][0], -forces[0][1]-forces[2][1], -forces[0][2]-forces[2][2]), forces[1], TOL);
ASSERT_EQUAL_TOL(0.5*0.8*0.5*0.5 + 0.5*0.7*0.2*0.2, state.getPotentialEnergy(), TOL);
}
// Try changing the bond parameters and make sure it's still correct.
parameters[0] = 1.6;
parameters[1] = 0.9;
forceField->setBondParameters(0, 0, 1, parameters);
parameters[0] = 1.3;
parameters[1] = 0.8;
forceField->setBondParameters(1, 1, 2, parameters);
forceField->updateParametersInContext(context);
state = context.getState(State::Forces | State::Energy);
{
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0, -0.9*0.4, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0.8*0.3, 0, 0), forces[2], TOL);
ASSERT_EQUAL_VEC(Vec3(-forces[0][0]-forces[2][0], -forces[0][1]-forces[2][1], -forces[0][2]-forces[2][2]), forces[1], TOL);
ASSERT_EQUAL_TOL(0.5*0.9*0.4*0.4 + 0.5*0.8*0.3*0.3, state.getPotentialEnergy(), TOL);
}
}
void testManyParameters() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomBondForce* forceField = new CustomBondForce("(a+b+c+d+e+f+g+h+i)*r");
forceField->addPerBondParameter("a");
forceField->addPerBondParameter("b");
forceField->addPerBondParameter("c");
forceField->addPerBondParameter("d");
forceField->addPerBondParameter("e");
forceField->addPerBondParameter("f");
forceField->addPerBondParameter("g");
forceField->addPerBondParameter("h");
forceField->addPerBondParameter("i");
vector<double> parameters(forceField->getNumPerBondParameters());
for (int i = 0; i < parameters.size(); i++)
parameters[i] = i;
forceField->addBond(0, 1, parameters);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(0, 2.5, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double f = 1+2+3+4+5+6+7+8;
ASSERT_EQUAL_VEC(Vec3(0, f, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -f, 0), forces[1], TOL);
ASSERT_EQUAL_TOL(f*2.5, state.getPotentialEnergy(), TOL);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testBonds();
testManyParameters();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomCentroidBondForce.h"
#include "openmm/CustomCompoundBondForce.h"
#include "openmm/System.h"
#include "openmm/TabulatedFunction.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testHarmonicBond() {
System system;
system.addParticle(1.0);
system.addParticle(2.0);
system.addParticle(3.0);
system.addParticle(4.0);
system.addParticle(5.0);
CustomCentroidBondForce* force = new CustomCentroidBondForce(2, "k*distance(g1,g2)^2");
force->addPerBondParameter("k");
vector<int> particles1;
particles1.push_back(0);
particles1.push_back(1);
vector<int> particles2;
particles2.push_back(2);
particles2.push_back(3);
particles2.push_back(4);
force->addGroup(particles1);
force->addGroup(particles2);
vector<int> groups;
groups.push_back(0);
groups.push_back(1);
vector<double> parameters;
parameters.push_back(1.0);
force->addBond(groups, parameters);
system.addForce(force);
ASSERT(!system.usesPeriodicBoundaryConditions());
// The center of mass of group 0 is (1.5, 0, 0).
vector<Vec3> positions(5);
positions[0] = Vec3(2.5, 0, 0);
positions[1] = Vec3(1, 0, 0);
// The center of mass of group 1 is (-1, 0, 0).
positions[2] = Vec3(-6, 0, 0);
positions[3] = Vec3(-1, 0, 0);
positions[4] = Vec3(2, 0, 0);
// Check the forces and energy.
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(2.5*2.5, state.getPotentialEnergy(), TOL);
ASSERT_EQUAL_VEC(Vec3(-2*2.5*(1.0/3.0), 0, 0), state.getForces()[0], TOL);
ASSERT_EQUAL_VEC(Vec3(-2*2.5*(2.0/3.0), 0, 0), state.getForces()[1], TOL);
ASSERT_EQUAL_VEC(Vec3(2*2.5*(3.0/12.0), 0, 0), state.getForces()[2], TOL);
ASSERT_EQUAL_VEC(Vec3(2*2.5*(4.0/12.0), 0, 0), state.getForces()[3], TOL);
ASSERT_EQUAL_VEC(Vec3(2*2.5*(5.0/12.0), 0, 0), state.getForces()[4], TOL);
// Update the per-bond parameter and see if the results change.
parameters[0] = 2.0;
force->setBondParameters(0, groups, parameters);
force->updateParametersInContext(context);
state = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(2*2.5*2.5, state.getPotentialEnergy(), TOL);
ASSERT_EQUAL_VEC(Vec3(-4*2.5*(1.0/3.0), 0, 0), state.getForces()[0], TOL);
ASSERT_EQUAL_VEC(Vec3(-4*2.5*(2.0/3.0), 0, 0), state.getForces()[1], TOL);
ASSERT_EQUAL_VEC(Vec3(4*2.5*(3.0/12.0), 0, 0), state.getForces()[2], TOL);
ASSERT_EQUAL_VEC(Vec3(4*2.5*(4.0/12.0), 0, 0), state.getForces()[3], TOL);
ASSERT_EQUAL_VEC(Vec3(4*2.5*(5.0/12.0), 0, 0), state.getForces()[4], TOL);
// All the particles should be treated as a single molecule.
vector<std::vector<int> > molecules = context.getMolecules();
ASSERT_EQUAL(1, molecules.size());
ASSERT_EQUAL(5, molecules[0].size());
}
void testComplexFunction() {
int numParticles = 5;
System system;
for (int i = 0; i < numParticles; i++)
system.addParticle(2.0);
vector<double> table(20);
for (int i = 0; i < 20; i++)
table[i] = sin(0.11*i);
// When every group contains only one particle, a CustomCentroidBondForce is identical to a
// CustomCompoundBondForce. Use that to test a complicated energy function with lots of terms.
CustomCompoundBondForce* compound = new CustomCompoundBondForce(4, "x1+y2+z4+fn(distance(p1,p2))*angle(p3,p2,p4)+scale*dihedral(p2,p1,p4,p3)");
CustomCentroidBondForce* centroid = new CustomCentroidBondForce(4, "x1+y2+z4+fn(distance(g1,g2))*angle(g3,g2,g4)+scale*dihedral(g2,g1,g4,g3)");
compound->addGlobalParameter("scale", 0.5);
centroid->addGlobalParameter("scale", 0.5);
compound->addTabulatedFunction("fn", new Continuous1DFunction(table, -1, 10));
centroid->addTabulatedFunction("fn", new Continuous1DFunction(table, -1, 10));
// Add two bonds to the CustomCompoundBondForce.
vector<int> particles(4);
vector<double> parameters;
particles[0] = 0;
particles[1] = 1;
particles[2] = 2;
particles[3] = 3;
compound->addBond(particles, parameters);
particles[0] = 2;
particles[1] = 4;
particles[2] = 3;
particles[3] = 1;
compound->addBond(particles, parameters);
// Add identical bonds to the CustomCentroidBondForce. As a stronger test, make sure that
// group number is different from particle number.
vector<int> groupMembers(1);
groupMembers[0] = 3;
centroid->addGroup(groupMembers);
groupMembers[0] = 0;
centroid->addGroup(groupMembers);
groupMembers[0] = 1;
centroid->addGroup(groupMembers);
groupMembers[0] = 2;
centroid->addGroup(groupMembers);
groupMembers[0] = 4;
centroid->addGroup(groupMembers);
vector<int> groups(4);
groups[0] = 1;
groups[1] = 2;
groups[2] = 3;
groups[3] = 0;
centroid->addBond(groups, parameters);
groups[0] = 3;
groups[1] = 4;
groups[2] = 0;
groups[3] = 2;
centroid->addBond(groups, parameters);
// Add both forces as different force groups, and create a context.
centroid->setForceGroup(1);
system.addForce(compound);
system.addForce(centroid);
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
// Evaluate the force and energy for various positions and see if they match.
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(numParticles);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < numParticles; j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
context.setPositions(positions);
State state1 = context.getState(State::Forces | State::Energy, false, 1<<0);
State state2 = context.getState(State::Forces | State::Energy, false, 1<<1);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), TOL);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], TOL);
}
}
void testCustomWeights() {
System system;
system.addParticle(1.0);
system.addParticle(2.0);
system.addParticle(3.0);
system.addParticle(4.0);
CustomCentroidBondForce* force = new CustomCentroidBondForce(2, "distance(g1,g2)^2");
vector<int> particles(2);
vector<double> weights(2);
particles[0] = 0;
particles[1] = 1;
weights[0] = 0.5;
weights[1] = 1.5;
force->addGroup(particles, weights);
particles[0] = 2;
particles[1] = 3;
weights[0] = 2.0;
weights[1] = 1.0;
force->addGroup(particles, weights);
vector<int> groups;
groups.push_back(0);
groups.push_back(1);
vector<double> parameters;
force->addBond(groups, parameters);
system.addForce(force);
// The center of mass of group 0 is (0, 1, 0).
vector<Vec3> positions(4);
positions[0] = Vec3(0, 4, 0);
positions[1] = Vec3(0, 0, 0);
// The center of mass of group 1 is (0, 10, 0).
positions[2] = Vec3(0, 9, 0);
positions[3] = Vec3(0, 12, 0);
// Check the forces and energy.
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(9.0*9.0, state.getPotentialEnergy(), TOL);
ASSERT_EQUAL_VEC(Vec3(0, 2*9*(0.5/2.0), 0), state.getForces()[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 2*9*(1.5/2.0), 0), state.getForces()[1], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -2*9*(2.0/3.0), 0), state.getForces()[2], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -2*9*(1.0/3.0), 0), state.getForces()[3], TOL);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testHarmonicBond();
testComplexFunction();
testCustomWeights();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2012-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#ifdef WIN32
#define _USE_MATH_DEFINES // Needed to get M_PI
#endif
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "ReferencePlatform.h"
#include "openmm/CustomCompoundBondForce.h"
#include "openmm/HarmonicAngleForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/PeriodicTorsionForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testBond() {
// Create a system using a CustomCompoundBondForce.
System customSystem;
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
CustomCompoundBondForce* custom = new CustomCompoundBondForce(4, "0.5*kb*((distance(p1,p2)-b0)^2+(distance(p2,p3)-b0)^2)+0.5*ka*(angle(p2,p3,p4)-a0)^2+kt*(1+cos(dihedral(p1,p2,p3,p4)-t0))");
custom->addPerBondParameter("kb");
custom->addPerBondParameter("ka");
custom->addPerBondParameter("kt");
custom->addPerBondParameter("b0");
custom->addPerBondParameter("a0");
custom->addPerBondParameter("t0");
vector<int> particles(4);
particles[0] = 0;
particles[1] = 1;
particles[2] = 3;
particles[3] = 2;
vector<double> parameters(6);
parameters[0] = 1.5;
parameters[1] = 0.8;
parameters[2] = 0.6;
parameters[3] = 1.1;
parameters[4] = 2.9;
parameters[5] = 1.3;
custom->addBond(particles, parameters);
customSystem.addForce(custom);
ASSERT(!custom->usesPeriodicBoundaryConditions());
ASSERT(!customSystem.usesPeriodicBoundaryConditions());
// Create an identical system using standard forces.
System standardSystem;
standardSystem.addParticle(1.0);
standardSystem.addParticle(1.0);
standardSystem.addParticle(1.0);
standardSystem.addParticle(1.0);
HarmonicBondForce* bonds = new HarmonicBondForce();
bonds->addBond(0, 1, 1.1, 1.5);
bonds->addBond(1, 3, 1.1, 1.5);
standardSystem.addForce(bonds);
HarmonicAngleForce* angles = new HarmonicAngleForce();
angles->addAngle(1, 3, 2, 2.9, 0.8);
standardSystem.addForce(angles);
PeriodicTorsionForce* torsions = new PeriodicTorsionForce();
torsions->addTorsion(0, 1, 3, 2, 1, 1.3, 0.6);
standardSystem.addForce(torsions);
// Set the atoms in various positions, and verify that both systems give identical forces and energy.
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context c1(customSystem, integrator1, platform);
Context c2(standardSystem, integrator2, platform);
vector<Vec3> positions(4);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
c1.setPositions(positions);
c2.setPositions(positions);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), TOL);
}
// Try changing the bond parameters and make sure it's still correct.
parameters[0] = 1.6;
parameters[3] = 1.3;
custom->setBondParameters(0, particles, parameters);
custom->updateParametersInContext(c1);
bonds->setBondParameters(0, 0, 1, 1.3, 1.6);
bonds->setBondParameters(1, 1, 3, 1.3, 1.6);
bonds->updateParametersInContext(c2);
{
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = s1.getForces();
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), TOL);
}
}
void testPositionDependence() {
System customSystem;
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
CustomCompoundBondForce* custom = new CustomCompoundBondForce(2, "scale1*distance(p1,p2)+scale2*x1+2*y2");
custom->addGlobalParameter("scale1", 0.3);
custom->addGlobalParameter("scale2", 0.2);
vector<int> particles(2);
particles[0] = 1;
particles[1] = 0;
vector<double> parameters;
custom->addBond(particles, parameters);
customSystem.addForce(custom);
vector<Vec3> positions(2);
positions[0] = Vec3(1.5, 1, 0);
positions[1] = Vec3(0.5, 1, 0);
VerletIntegrator integrator(0.01);
Context context(customSystem, integrator, platform);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(0.3*1.0+0.2*0.5+2*1, state.getPotentialEnergy(), 1e-5);
ASSERT_EQUAL_VEC(Vec3(-0.3, -2, 0), state.getForces()[0], 1e-5);
ASSERT_EQUAL_VEC(Vec3(0.3-0.2, 0, 0), state.getForces()[1], 1e-5);
}
void testContinuous2DFunction() {
const int xsize = 10;
const int ysize = 11;
const double xmin = 0.4;
const double xmax = 1.1;
const double ymin = 0.0;
const double ymax = 0.9;
System system;
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomCompoundBondForce* forceField = new CustomCompoundBondForce(1, "fn(x1,y1)+1");
vector<int> particles(1, 0);
forceField->addBond(particles, vector<double>());
vector<double> table(xsize*ysize);
for (int i = 0; i < xsize; i++) {
for (int j = 0; j < ysize; j++) {
double x = xmin + i*(xmax-xmin)/xsize;
double y = ymin + j*(ymax-ymin)/ysize;
table[i+xsize*j] = sin(0.25*x)*cos(0.33*y);
}
}
forceField->addTabulatedFunction("fn", new Continuous2DFunction(xsize, ysize, table, xmin, xmax, ymin, ymax));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(1);
for (double x = xmin-0.15; x < xmax+0.2; x += 0.1) {
for (double y = ymin-0.15; y < ymax+0.2; y += 0.1) {
positions[0] = Vec3(x, y, 1.5);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double energy = 1;
Vec3 force(0, 0, 0);
if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) {
energy = sin(0.25*x)*cos(0.33*y)+1;
force[0] = -0.25*cos(0.25*x)*cos(0.33*y);
force[1] = 0.3*sin(0.25*x)*sin(0.33*y);
}
ASSERT_EQUAL_VEC(force, forces[0], 0.1);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 0.05);
}
}
}
void testContinuous3DFunction() {
const int xsize = 10;
const int ysize = 11;
const int zsize = 12;
const double xmin = 0.4;
const double xmax = 1.1;
const double ymin = 0.0;
const double ymax = 0.9;
const double zmin = 0.2;
const double zmax = 1.3;
System system;
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomCompoundBondForce* forceField = new CustomCompoundBondForce(1, "fn(x1,y1,z1)+1");
vector<int> particles(1, 0);
forceField->addBond(particles, vector<double>());
vector<double> table(xsize*ysize*zsize);
for (int i = 0; i < xsize; i++) {
for (int j = 0; j < ysize; j++) {
for (int k = 0; k < zsize; k++) {
double x = xmin + i*(xmax-xmin)/xsize;
double y = ymin + j*(ymax-ymin)/ysize;
double z = zmin + k*(zmax-zmin)/zsize;
table[i+xsize*j+xsize*ysize*k] = sin(0.25*x)*cos(0.33*y)*(1+z);
}
}
}
forceField->addTabulatedFunction("fn", new Continuous3DFunction(xsize, ysize, zsize, table, xmin, xmax, ymin, ymax, zmin, zmax));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(1);
for (double x = xmin-0.15; x < xmax+0.2; x += 0.1) {
for (double y = ymin-0.15; y < ymax+0.2; y += 0.1) {
for (double z = zmin-0.15; z < zmax+0.2; z += 0.1) {
positions[0] = Vec3(x, y, z);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double energy = 1;
Vec3 force(0, 0, 0);
if (x >= xmin && x <= xmax && y >= ymin && y <= ymax && z >= zmin && z <= zmax) {
energy = sin(0.25*x)*cos(0.33*y)*(1.0+z)+1;
force[0] = -0.25*cos(0.25*x)*cos(0.33*y)*(1.0+z);
force[1] = 0.3*sin(0.25*x)*sin(0.33*y)*(1.0+z);
force[2] = -sin(0.25*x)*cos(0.33*y);
}
ASSERT_EQUAL_VEC(force, forces[0], 0.1);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 0.05);
}
}
}
}
void testMultipleBonds() {
// Two compound bonds using Urey-Bradley example from API doc
System customSystem;
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
CustomCompoundBondForce* custom = new CustomCompoundBondForce(3,
"0.5*(kangle*(angle(p1,p2,p3)-theta0)^2+kbond*(distance(p1,p3)-r0)^2)");
custom->addPerBondParameter("kangle");
custom->addPerBondParameter("kbond");
custom->addPerBondParameter("theta0");
custom->addPerBondParameter("r0");
vector<double> parameters(4);
parameters[0] = 1.0;
parameters[1] = 1.0;
parameters[2] = 2 * M_PI / 3;
parameters[3] = sqrt(3.0) / 2;
vector<int> particles0(3);
particles0[0] = 0;
particles0[1] = 1;
particles0[2] = 2;
vector<int> particles1(3);
particles1[0] = 1;
particles1[1] = 2;
particles1[2] = 3;
custom->addBond(particles0, parameters);
custom->addBond(particles1, parameters);
customSystem.addForce(custom);
vector<Vec3> positions(4);
positions[0] = Vec3(0, 0.5, 0);
positions[1] = Vec3(0, 0, 0);
positions[2] = Vec3(0.5, 0, 0);
positions[3] = Vec3(0.6, 0, 0.4);
VerletIntegrator integrator(0.01);
Context context(customSystem, integrator, platform);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(0.199, state.getPotentialEnergy(), 1e-3);
vector<Vec3> forces(state.getForces());
ASSERT_EQUAL_VEC(Vec3(-1.160, 0.112, 0.0), forces[0], 1e-3);
ASSERT_EQUAL_VEC(Vec3(0.927, 1.047, -0.638), forces[1], 1e-3);
ASSERT_EQUAL_VEC(Vec3(-0.543, -1.160, 0.721), forces[2], 1e-3);
ASSERT_EQUAL_VEC(Vec3(0.776, 0.0, -0.084), forces[3], 1e-3);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testBond();
testPositionDependence();
testContinuous2DFunction();
testContinuous3DFunction();
testMultipleBonds();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomExternalForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testForce() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomExternalForce* forceField = new CustomExternalForce("scale*(x+yscale*(y-y0)^2)");
forceField->addPerParticleParameter("y0");
forceField->addPerParticleParameter("yscale");
forceField->addGlobalParameter("scale", 0.5);
vector<double> parameters(2);
parameters[0] = 0.5;
parameters[1] = 2.0;
forceField->addParticle(0, parameters);
parameters[0] = 1.5;
parameters[1] = 3.0;
forceField->addParticle(2, parameters);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 2, 0);
positions[1] = Vec3(0, 0, 1);
positions[2] = Vec3(1, 0, 1);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
{
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(-0.5, -0.5*2.0*2.0*1.5, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(-0.5, 0.5*3.0*2.0*1.5, 0), forces[2], TOL);
ASSERT_EQUAL_TOL(0.5*(1.0 + 2.0*1.5*1.5 + 3.0*1.5*1.5), state.getPotentialEnergy(), TOL);
}
// Try changing the parameters and make sure it's still correct.
parameters[0] = 1.4;
parameters[1] = 3.5;
forceField->setParticleParameters(1, 2, parameters);
forceField->updateParametersInContext(context);
state = context.getState(State::Forces | State::Energy);
{
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(-0.5, -0.5*2.0*2.0*1.5, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(-0.5, 0.5*3.5*2.0*1.4, 0), forces[2], TOL);
ASSERT_EQUAL_TOL(0.5*(1.0 + 2.0*1.5*1.5 + 3.5*1.4*1.4), state.getPotentialEnergy(), TOL);
}
}
void testManyParameters() {
System system;
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomExternalForce* forceField = new CustomExternalForce("xscale*(x-x0)^2+yscale*(y-y0)^2+zscale*(z-z0)^2");
forceField->addPerParticleParameter("x0");
forceField->addPerParticleParameter("y0");
forceField->addPerParticleParameter("z0");
forceField->addPerParticleParameter("xscale");
forceField->addPerParticleParameter("yscale");
forceField->addPerParticleParameter("zscale");
vector<double> parameters(6);
parameters[0] = 1.0;
parameters[1] = 2.0;
parameters[2] = 3.0;
parameters[3] = 0.1;
parameters[4] = 0.2;
parameters[5] = 0.3;
forceField->addParticle(0, parameters);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(1);
positions[0] = Vec3(0, -1, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(2*0.1*1.0, 2*0.2*3.0, 2*0.3*3.0), forces[0], TOL);
ASSERT_EQUAL_TOL(0.1*1*1 + 0.2*3*3 + 0.3*3*3, state.getPotentialEnergy(), TOL);
}
void testPeriodic() {
Vec3 vx(5, 0, 0);
Vec3 vy(0, 6, 0);
Vec3 vz(1, 2, 7);
double x0 = 51, y0 = -17, z0 = 11.2;
System system;
system.setDefaultPeriodicBoxVectors(vx, vy, vz);
system.addParticle(1.0);
CustomExternalForce* force = new CustomExternalForce("periodicdistance(x, y, z, x0, y0, z0)^2");
force->addPerParticleParameter("x0");
force->addPerParticleParameter("y0");
force->addPerParticleParameter("z0");
vector<double> params(3);
params[0] = x0;
params[1] = y0;
params[2] = z0;
force->addParticle(0, params);
system.addForce(force);
ASSERT(force->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
vector<Vec3> positions(1);
positions[0] = Vec3(0, 2, 0);
context.setPositions(positions);
for (int i = 0; i < 100; i++) {
State state = context.getState(State::Positions | State::Forces | State::Energy);
// Apply periodic boundary conditions to the difference between the two positions.
Vec3 delta = Vec3(x0, y0, z0)-state.getPositions()[0];
delta -= vz*floor(delta[2]/vz[2]+0.5);
delta -= vy*floor(delta[1]/vy[1]+0.5);
delta -= vx*floor(delta[0]/vx[0]+0.5);
// Verify that the force and energy are correct.
ASSERT_EQUAL_VEC(delta*2, state.getForces()[0], TOL);
ASSERT_EQUAL_TOL(delta.dot(delta), state.getPotentialEnergy(), TOL);
integrator.step(1);
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testForce();
testManyParameters();
testPeriodic();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "sfmt/SFMT.h"
#include "openmm/Context.h"
#include "openmm/CustomGBForce.h"
#include "openmm/GBSAOBCForce.h"
#include "openmm/OpenMMException.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testOBC(GBSAOBCForce::NonbondedMethod obcMethod, CustomGBForce::NonbondedMethod customMethod) {
const int numMolecules = 70;
const int numParticles = numMolecules*2;
const double boxSize = 10.0;
const double cutoff = 2.0;
// Create two systems: one with a GBSAOBCForce, and one using a CustomGBForce to implement the same interaction.
System standardSystem;
System customSystem;
for (int i = 0; i < numParticles; i++) {
standardSystem.addParticle(1.0);
customSystem.addParticle(1.0);
}
standardSystem.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0.0, 0.0), Vec3(0.0, boxSize, 0.0), Vec3(0.0, 0.0, boxSize));
customSystem.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0.0, 0.0), Vec3(0.0, boxSize, 0.0), Vec3(0.0, 0.0, boxSize));
GBSAOBCForce* obc = new GBSAOBCForce();
CustomGBForce* custom = new CustomGBForce();
obc->setCutoffDistance(cutoff);
custom->setCutoffDistance(cutoff);
custom->addPerParticleParameter("q");
custom->addPerParticleParameter("radius");
custom->addPerParticleParameter("scale");
custom->addGlobalParameter("solventDielectric", obc->getSolventDielectric());
custom->addGlobalParameter("soluteDielectric", obc->getSoluteDielectric());
custom->addComputedValue("I", "step(r+sr2-or1)*0.5*(1/L-1/U+0.25*(1/U^2-1/L^2)*(r-sr2*sr2/r)+0.5*log(L/U)/r+C);"
"U=r+sr2;"
"C=2*(1/or1-1/L)*step(sr2-r-or1);"
"L=max(or1, D);"
"D=abs(r-sr2);"
"sr2 = scale2*or2;"
"or1 = radius1-0.009; or2 = radius2-0.009", CustomGBForce::ParticlePairNoExclusions);
custom->addComputedValue("B", "1/(1/or-tanh(1*psi-0.8*psi^2+4.85*psi^3)/radius);"
"psi=I*or; or=radius-0.009", CustomGBForce::SingleParticle);
custom->addEnergyTerm("28.3919551*(radius+0.14)^2*(radius/B)^6-0.5*138.935485*(1/soluteDielectric-1/solventDielectric)*q^2/B", CustomGBForce::SingleParticle);
string invCutoffString = "";
if (obcMethod != GBSAOBCForce::NoCutoff) {
stringstream s;
s<<(1.0/cutoff);
invCutoffString = s.str();
}
custom->addEnergyTerm("138.935485*(1/soluteDielectric-1/solventDielectric)*q1*q2*("+invCutoffString+"-1/f);"
"f=sqrt(r^2+B1*B2*exp(-r^2/(4*B1*B2)))", CustomGBForce::ParticlePairNoExclusions);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<double> params(3);
for (int i = 0; i < numMolecules; i++) {
if (i < numMolecules/2) {
obc->addParticle(1.0, 0.2, 0.5);
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.5;
custom->addParticle(params);
obc->addParticle(-1.0, 0.1, 0.5);
params[0] = -1.0;
params[1] = 0.1;
custom->addParticle(params);
}
else {
obc->addParticle(1.0, 0.2, 0.8);
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.8;
custom->addParticle(params);
obc->addParticle(-1.0, 0.1, 0.8);
params[0] = -1.0;
params[1] = 0.1;
custom->addParticle(params);
}
positions[2*i] = Vec3(boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt));
positions[2*i+1] = Vec3(positions[2*i][0]+1.0, positions[2*i][1], positions[2*i][2]);
velocities[2*i] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
velocities[2*i+1] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
}
obc->setNonbondedMethod(obcMethod);
custom->setNonbondedMethod(customMethod);
standardSystem.addForce(obc);
customSystem.addForce(custom);
if (customMethod == CustomGBForce::CutoffPeriodic) {
ASSERT(custom->usesPeriodicBoundaryConditions());
ASSERT(obc->usesPeriodicBoundaryConditions());
ASSERT(standardSystem.usesPeriodicBoundaryConditions());
ASSERT(customSystem.usesPeriodicBoundaryConditions());
}
else {
ASSERT(!custom->usesPeriodicBoundaryConditions());
ASSERT(!obc->usesPeriodicBoundaryConditions());
ASSERT(!standardSystem.usesPeriodicBoundaryConditions());
ASSERT(!customSystem.usesPeriodicBoundaryConditions());
}
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context context1(standardSystem, integrator1, platform);
context1.setPositions(positions);
context1.setVelocities(velocities);
State state1 = context1.getState(State::Forces | State::Energy);
Context context2(customSystem, integrator2, platform);
context2.setPositions(positions);
context2.setVelocities(velocities);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-4);
for (int i = 0; i < numParticles; i++) {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-4);
}
// Try changing the particle parameters and make sure it's still correct.
for (int i = 0; i < numMolecules/2; i++) {
obc->setParticleParameters(2*i, 1.1, 0.3, 0.6);
params[0] = 1.1;
params[1] = 0.3;
params[2] = 0.6;
custom->setParticleParameters(2*i, params);
obc->setParticleParameters(2*i+1, -1.1, 0.2, 0.4);
params[0] = -1.1;
params[1] = 0.2;
params[2] = 0.4;
custom->setParticleParameters(2*i+1, params);
}
obc->updateParametersInContext(context1);
custom->updateParametersInContext(context2);
state1 = context1.getState(State::Forces | State::Energy);
state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-4);
for (int i = 0; i < numParticles; i++) {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-4);
}
}
void testMembrane() {
const int numMolecules = 70;
const int numParticles = numMolecules*2;
const double boxSize = 10.0;
// Create a system with an implicit membrane.
System system;
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.0);
}
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0.0, 0.0), Vec3(0.0, boxSize, 0.0), Vec3(0.0, 0.0, boxSize));
CustomGBForce* custom = new CustomGBForce();
custom->setCutoffDistance(2.0);
custom->addPerParticleParameter("q");
custom->addPerParticleParameter("radius");
custom->addPerParticleParameter("scale");
custom->addGlobalParameter("thickness", 3);
custom->addGlobalParameter("solventDielectric", 78.3);
custom->addGlobalParameter("soluteDielectric", 1);
custom->addComputedValue("Imol", "step(r+sr2-or1)*0.5*(1/L-1/U+0.25*(1/U^2-1/L^2)*(r-sr2*sr2/r)+0.5*log(L/U)/r+C);"
"U=r+sr2;"
"C=2*(1/or1-1/L)*step(sr2-r-or1);"
"L=max(or1, D);"
"D=abs(r-sr2);"
"sr2 = scale2*or2;"
"or1 = radius1-0.009; or2 = radius2-0.009", CustomGBForce::ParticlePairNoExclusions);
custom->addComputedValue("Imem", "(1/radius+2*log(2)/thickness)/(1+exp(7.2*(abs(z)+radius-0.5*thickness)))", CustomGBForce::SingleParticle);
custom->addComputedValue("B", "1/(1/or-tanh(1*psi-0.8*psi^2+4.85*psi^3)/radius);"
"psi=max(Imol,Imem)*or; or=radius-0.009", CustomGBForce::SingleParticle);
custom->addEnergyTerm("28.3919551*(radius+0.14)^2*(radius/B)^6-0.5*138.935456*(1/soluteDielectric-1/solventDielectric)*q^2/B", CustomGBForce::SingleParticle);
custom->addEnergyTerm("-138.935456*(1/soluteDielectric-1/solventDielectric)*q1*q2/f;"
"f=sqrt(r^2+B1*B2*exp(-r^2/(4*B1*B2)))", CustomGBForce::ParticlePairNoExclusions);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<double> params(3);
for (int i = 0; i < numMolecules; i++) {
if (i < numMolecules/2) {
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.5;
custom->addParticle(params);
params[0] = -1.0;
params[1] = 0.1;
custom->addParticle(params);
}
else {
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.8;
custom->addParticle(params);
params[0] = -1.0;
params[1] = 0.1;
custom->addParticle(params);
}
positions[2*i] = Vec3(boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt));
positions[2*i+1] = Vec3(positions[2*i][0]+1.0, positions[2*i][1], positions[2*i][2]);
velocities[2*i] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
velocities[2*i+1] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
}
system.addForce(custom);
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
context.setVelocities(velocities);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
norm = std::sqrt(norm);
const double stepSize = 1e-2;
double step = 0.5*stepSize/norm;
vector<Vec3> positions2(numParticles), positions3(numParticles);
for (int i = 0; i < (int) positions.size(); ++i) {
Vec3 p = positions[i];
Vec3 f = forces[i];
positions2[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
positions3[i] = Vec3(p[0]+f[0]*step, p[1]+f[1]*step, p[2]+f[2]*step);
}
context.setPositions(positions2);
State state2 = context.getState(State::Energy);
context.setPositions(positions3);
State state3 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state3.getPotentialEnergy())/stepSize, 1e-3);
}
void testTabulatedFunction() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomGBForce* force = new CustomGBForce();
force->addComputedValue("a", "0", CustomGBForce::ParticlePair);
force->addEnergyTerm("fn(r)+1", CustomGBForce::ParticlePair);
force->addParticle(vector<double>());
force->addParticle(vector<double>());
vector<double> table;
for (int i = 0; i < 21; i++)
table.push_back(std::sin(0.25*i));
force->addTabulatedFunction("fn", new Continuous1DFunction(table, 1.0, 6.0));
system.addForce(force);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (int i = 1; i < 30; i++) {
// Check interpolated values.
double x = (7.0/30.0)*i;
positions[1] = Vec3(x, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double force = (x < 1.0 || x > 6.0 ? 0.0 : -std::cos(x-1.0));
double energy = (x < 1.0 || x > 6.0 ? 0.0 : std::sin(x-1.0))+1.0;
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], 0.1);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], 0.1);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 0.02);
}
for (int i = 1; i < 20; i++) {
// These values are exactly on table points, so they should match more precisely.
double x = 0.25*i+1.0;
positions[1] = Vec3(x, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Energy);
double energy = (x < 1.0 || x > 6.0 ? 0.0 : std::sin(x-1.0))+1.0;
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 1e-4);
}
}
void testMultipleChainRules() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomGBForce* force = new CustomGBForce();
force->addComputedValue("a", "2*r", CustomGBForce::ParticlePair);
force->addComputedValue("b", "a+1", CustomGBForce::SingleParticle);
force->addComputedValue("c", "2*b+a", CustomGBForce::SingleParticle);
force->addEnergyTerm("0.1*a+1*b+10*c", CustomGBForce::SingleParticle); // 0.1*(2*r) + 2*r+1 + 10*(3*a+2) = 0.2*r + 2*r+1 + 40*r+20+20*r = 62.2*r+21
force->addParticle(vector<double>());
force->addParticle(vector<double>());
system.addForce(force);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (int i = 1; i < 5; i++) {
positions[1] = Vec3(i, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(124.4, 0, 0), forces[0], 1e-4);
ASSERT_EQUAL_VEC(Vec3(-124.4, 0, 0), forces[1], 1e-4);
ASSERT_EQUAL_TOL(2*(62.2*i+21), state.getPotentialEnergy(), 0.02);
}
}
void testPositionDependence() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomGBForce* force = new CustomGBForce();
force->addComputedValue("a", "r", CustomGBForce::ParticlePair);
force->addComputedValue("b", "a+x*y", CustomGBForce::SingleParticle);
force->addEnergyTerm("b*z", CustomGBForce::SingleParticle);
force->addEnergyTerm("b1+b2", CustomGBForce::ParticlePair); // = 2*r+x1*y1+x2*y2
force->addParticle(vector<double>());
force->addParticle(vector<double>());
system.addForce(force);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
vector<Vec3> forces(2);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < 5; i++) {
positions[0] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
positions[1] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
Vec3 delta = positions[0]-positions[1];
double r = sqrt(delta.dot(delta));
double energy = 2*r+positions[0][0]*positions[0][1]+positions[1][0]*positions[1][1];
for (int j = 0; j < 2; j++)
energy += positions[j][2]*(r+positions[j][0]*positions[j][1]);
Vec3 force1(-(1+positions[0][2])*delta[0]/r-(1+positions[0][2])*positions[0][1]-(1+positions[1][2])*delta[0]/r,
-(1+positions[0][2])*delta[1]/r-(1+positions[0][2])*positions[0][0]-(1+positions[1][2])*delta[1]/r,
-(1+positions[0][2])*delta[2]/r-(r+positions[0][0]*positions[0][1])-(1+positions[1][2])*delta[2]/r);
Vec3 force2((1+positions[0][2])*delta[0]/r+(1+positions[1][2])*delta[0]/r-(1+positions[1][2])*positions[1][1],
(1+positions[0][2])*delta[1]/r+(1+positions[1][2])*delta[1]/r-(1+positions[1][2])*positions[1][0],
(1+positions[0][2])*delta[2]/r+(1+positions[1][2])*delta[2]/r-(r+positions[1][0]*positions[1][1]));
ASSERT_EQUAL_VEC(force1, forces[0], 1e-4);
ASSERT_EQUAL_VEC(force2, forces[1], 1e-4);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 0.02);
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
norm = std::sqrt(norm);
const double stepSize = 1e-3;
double step = 0.5*stepSize/norm;
vector<Vec3> positions2(2), positions3(2);
for (int i = 0; i < (int) positions.size(); ++i) {
Vec3 p = positions[i];
Vec3 f = forces[i];
positions2[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
positions3[i] = Vec3(p[0]+f[0]*step, p[1]+f[1]*step, p[2]+f[2]*step);
}
context.setPositions(positions2);
State state2 = context.getState(State::Energy);
context.setPositions(positions3);
State state3 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state3.getPotentialEnergy())/stepSize, 1e-3);
}
}
void testExclusions() {
for (int i = 0; i < 4; i++) {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomGBForce* force = new CustomGBForce();
force->addComputedValue("a", "r", i < 2 ? CustomGBForce::ParticlePair : CustomGBForce::ParticlePairNoExclusions);
force->addEnergyTerm("a", CustomGBForce::SingleParticle);
force->addEnergyTerm("(1+a1+a2)*r", i%2 == 0 ? CustomGBForce::ParticlePair : CustomGBForce::ParticlePairNoExclusions);
force->addParticle(vector<double>());
force->addParticle(vector<double>());
force->addExclusion(0, 1);
system.addForce(force);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(1, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double f, energy;
switch (i)
{
case 0: // e = 0
f = 0;
energy = 0;
break;
case 1: // e = r
f = 1;
energy = 1;
break;
case 2: // e = 2r
f = 2;
energy = 2;
break;
case 3: // e = 3r + 2r^2
f = 7;
energy = 5;
break;
default:
ASSERT(false);
}
ASSERT_EQUAL_VEC(Vec3(f, 0, 0), forces[0], 1e-4);
ASSERT_EQUAL_VEC(Vec3(-f, 0, 0), forces[1], 1e-4);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 1e-4);
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
norm = std::sqrt(norm);
if (norm > 0) {
const double stepSize = 1e-3;
double step = stepSize/norm;
for (int i = 0; i < (int) positions.size(); ++i) {
Vec3 p = positions[i];
Vec3 f = forces[i];
positions[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
}
context.setPositions(positions);
State state2 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state.getPotentialEnergy())/stepSize, 1e-3*abs(state.getPotentialEnergy()));
}
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testOBC(GBSAOBCForce::NoCutoff, CustomGBForce::NoCutoff);
testOBC(GBSAOBCForce::CutoffNonPeriodic, CustomGBForce::CutoffNonPeriodic);
testOBC(GBSAOBCForce::CutoffPeriodic, CustomGBForce::CutoffPeriodic);
testMembrane();
testTabulatedFunction();
testMultipleChainRules();
testPositionDependence();
testExclusions();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomHbondForce.h"
#include "openmm/HarmonicAngleForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/PeriodicTorsionForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testHbond() {
// Create a system using a CustomHbondForce.
System customSystem;
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
CustomHbondForce* custom = new CustomHbondForce("0.5*kr*(distance(d1,a1)-r0)^2 + 0.5*ktheta*(angle(a1,d1,d2)-theta0)^2 + 0.5*kpsi*(angle(d1,a1,a2)-psi0)^2 + kchi*(1+cos(n*dihedral(a3,a2,a1,d1)-chi0))");
custom->addPerDonorParameter("r0");
custom->addPerDonorParameter("theta0");
custom->addPerDonorParameter("psi0");
custom->addPerAcceptorParameter("chi0");
custom->addPerAcceptorParameter("n");
custom->addGlobalParameter("kr", 0.4);
custom->addGlobalParameter("ktheta", 0.5);
custom->addGlobalParameter("kpsi", 0.6);
custom->addGlobalParameter("kchi", 0.7);
vector<double> parameters(3);
parameters[0] = 1.5;
parameters[1] = 1.7;
parameters[2] = 1.9;
custom->addDonor(1, 0, -1, parameters);
parameters.resize(2);
parameters[0] = 2.1;
parameters[1] = 2;
custom->addAcceptor(2, 3, 4, parameters);
custom->setCutoffDistance(10.0);
customSystem.addForce(custom);
ASSERT(!custom->usesPeriodicBoundaryConditions());
ASSERT(!customSystem.usesPeriodicBoundaryConditions());
// Create an identical system using HarmonicBondForce, HarmonicAngleForce, and PeriodicTorsionForce.
System standardSystem;
standardSystem.addParticle(1.0);
standardSystem.addParticle(1.0);
standardSystem.addParticle(1.0);
standardSystem.addParticle(1.0);
standardSystem.addParticle(1.0);
HarmonicBondForce* bond = new HarmonicBondForce();
bond->addBond(1, 2, 1.5, 0.4);
standardSystem.addForce(bond);
HarmonicAngleForce* angle = new HarmonicAngleForce();
angle->addAngle(0, 1, 2, 1.7, 0.5);
angle->addAngle(1, 2, 3, 1.9, 0.6);
standardSystem.addForce(angle);
PeriodicTorsionForce* torsion = new PeriodicTorsionForce();
torsion->addTorsion(1, 2, 3, 4, 2, 2.1, 0.7);
standardSystem.addForce(torsion);
// Set the atoms in various positions, and verify that both systems give identical forces and energy.
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(5);
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context c1(customSystem, integrator1, platform);
Context c2(standardSystem, integrator2, platform);
for (int i = 0; i < 10; i++) {
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(2.0*genrand_real2(sfmt), 2.0*genrand_real2(sfmt), 2.0*genrand_real2(sfmt));
c1.setPositions(positions);
c2.setPositions(positions);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s2.getForces()[i], s1.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s2.getPotentialEnergy(), s1.getPotentialEnergy(), TOL);
}
// Try changing the parameters and make sure it's still correct.
parameters.resize(3);
parameters[0] = 1.4;
parameters[1] = 1.7;
parameters[2] = 1.9;
custom->setDonorParameters(0, 1, 0, -1, parameters);
parameters.resize(2);
parameters[0] = 2.2;
parameters[1] = 2;
custom->setAcceptorParameters(0, 2, 3, 4, parameters);
bond->setBondParameters(0, 1, 2, 1.4, 0.4);
torsion->setTorsionParameters(0, 1, 2, 3, 4, 2, 2.2, 0.7);
custom->updateParametersInContext(c1);
bond->updateParametersInContext(c2);
torsion->updateParametersInContext(c2);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s2.getForces()[i], s1.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s2.getPotentialEnergy(), s1.getPotentialEnergy(), TOL);
}
void testExclusions() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomHbondForce* custom = new CustomHbondForce("(distance(d1,a1)-1)^2");
custom->addDonor(0, 1, -1, vector<double>());
custom->addDonor(1, 0, -1, vector<double>());
custom->addAcceptor(2, 0, -1, vector<double>());
custom->addExclusion(1, 0);
system.addForce(custom);
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(0, 2, 0);
positions[2] = Vec3(2, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(2, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(-2, 0, 0), forces[2], TOL);
ASSERT_EQUAL_TOL(1.0, state.getPotentialEnergy(), TOL);
}
void testCutoff() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomHbondForce* custom = new CustomHbondForce("(distance(d1,a1)-1)^2");
custom->addDonor(0, 1, -1, vector<double>());
custom->addDonor(1, 0, -1, vector<double>());
custom->addAcceptor(2, 0, -1, vector<double>());
custom->setNonbondedMethod(CustomHbondForce::CutoffNonPeriodic);
custom->setCutoffDistance(2.5);
system.addForce(custom);
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(0, 3, 0);
positions[2] = Vec3(2, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(2, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(-2, 0, 0), forces[2], TOL);
ASSERT_EQUAL_TOL(1.0, state.getPotentialEnergy(), TOL);
}
void testCustomFunctions() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomHbondForce* custom = new CustomHbondForce("foo(distance(d1,a1))");
custom->addDonor(1, 0, -1, vector<double>());
custom->addDonor(2, 0, -1, vector<double>());
custom->addAcceptor(0, 1, -1, vector<double>());
vector<double> function(2);
function[0] = 0;
function[1] = 1;
custom->addTabulatedFunction("foo", new Continuous1DFunction(function, 0, 10));
system.addForce(custom);
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(0, 2, 0);
positions[2] = Vec3(2, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0.1, 0.1, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -0.1, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(-0.1, 0, 0), forces[2], TOL);
ASSERT_EQUAL_TOL(0.1*2+0.1*2, state.getPotentialEnergy(), TOL);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testHbond();
testExclusions();
testCutoff();
testCustomFunctions();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/AndersenThermostat.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/CustomIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
/**
* Test a simple leapfrog integrator on a single bond.
*/
void testSingleBond() {
System system;
system.addParticle(2.0);
system.addParticle(2.0);
const double dt = 0.01;
CustomIntegrator integrator(dt);
integrator.addComputePerDof("v", "v+dt*f/m");
integrator.addComputePerDof("x", "x+dt*v");
integrator.setKineticEnergyExpression("m*v1*v1/2; v1=v+0.5*dt*f/m");
HarmonicBondForce* forceField = new HarmonicBondForce();
forceField->addBond(0, 1, 1.5, 1);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(-1, 0, 0);
positions[1] = Vec3(1, 0, 0);
context.setPositions(positions);
vector<Vec3> velocities(2);
velocities[0] = Vec3(-0.5*dt*0.5*0.5, 0, 0);
velocities[1] = Vec3(0.5*dt*0.5*0.5, 0, 0);
context.setVelocities(velocities);
// This is simply a harmonic oscillator, so compare it to the analytical solution.
const double freq = 1.0;;
for (int i = 0; i < 1000; ++i) {
State state = context.getState(State::Positions | State::Velocities | State::Energy);
double time = state.getTime();
double expectedDist = 1.5+0.5*std::cos(freq*time);
ASSERT_EQUAL_VEC(Vec3(-0.5*expectedDist, 0, 0), state.getPositions()[0], 1e-4);
ASSERT_EQUAL_VEC(Vec3(0.5*expectedDist, 0, 0), state.getPositions()[1], 1e-4);
double expectedSpeed = -0.5*freq*std::sin(freq*(time-dt/2));
ASSERT_EQUAL_VEC(Vec3(-0.5*expectedSpeed, 0, 0), state.getVelocities()[0], 1e-4);
ASSERT_EQUAL_VEC(Vec3(0.5*expectedSpeed, 0, 0), state.getVelocities()[1], 1e-4);
double energy = state.getKineticEnergy()+state.getPotentialEnergy();
ASSERT_EQUAL_TOL(0.5*0.5*0.5, energy, 1e-4);
integrator.step(1);
}
}
/**
* Test an integrator that enforces constraints.
*/
void testConstraints() {
const int numParticles = 8;
const double temp = 500.0;
System system;
CustomIntegrator integrator(0.002);
integrator.addPerDofVariable("oldx", 0);
integrator.addComputePerDof("v", "v+dt*f/m");
integrator.addComputePerDof("oldx", "x");
integrator.addComputePerDof("x", "x+dt*v");
integrator.addConstrainPositions();
integrator.addComputePerDof("v", "(x-oldx)/dt");
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(i%2 == 0 ? 5.0 : 10.0);
forceField->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
for (int i = 0; i < numParticles-1; ++i)
system.addConstraint(i, i+1, 1.0);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; ++i) {
positions[i] = Vec3(i/2, (i+1)/2, 0);
velocities[i] = Vec3(genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5);
}
context.setPositions(positions);
context.setVelocities(velocities);
// Simulate it and see whether the constraints remain satisfied.
double initialEnergy = 0.0;
for (int i = 0; i < 1000; ++i) {
State state = context.getState(State::Positions | State::Energy);
for (int j = 0; j < system.getNumConstraints(); ++j) {
int particle1, particle2;
double distance;
system.getConstraintParameters(j, particle1, particle2, distance);
Vec3 p1 = state.getPositions()[particle1];
Vec3 p2 = state.getPositions()[particle2];
double dist = std::sqrt((p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1])+(p1[2]-p2[2])*(p1[2]-p2[2]));
ASSERT_EQUAL_TOL(distance, dist, 2e-5);
}
double energy = state.getKineticEnergy()+state.getPotentialEnergy();
if (i == 1)
initialEnergy = energy;
else if (i > 1)
ASSERT_EQUAL_TOL(initialEnergy, energy, 0.01);
integrator.step(1);
}
}
/**
* Test an integrator that applies constraints directly to velocities.
*/
void testVelocityConstraints() {
const int numParticles = 10;
System system;
CustomIntegrator integrator(0.002);
integrator.addPerDofVariable("x1", 0);
integrator.addComputePerDof("v", "v+0.5*dt*f/m");
integrator.addComputePerDof("x", "x+dt*v");
integrator.addComputePerDof("x1", "x");
integrator.addConstrainPositions();
integrator.addComputePerDof("v", "v+0.5*dt*f/m+(x-x1)/dt");
integrator.addConstrainVelocities();
integrator.setConstraintTolerance(1e-5);
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(i%2 == 0 ? 5.0 : 10.0);
forceField->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
// Constrain the first three particles with SHAKE.
system.addConstraint(0, 1, 1.0);
system.addConstraint(1, 2, 1.0);
// Constrain the next three with SETTLE.
system.addConstraint(3, 4, 1.0);
system.addConstraint(5, 4, 1.0);
system.addConstraint(3, 5, sqrt(2.0));
// Constraint the rest with CCMA.
for (int i = 6; i < numParticles-1; ++i)
system.addConstraint(i, i+1, 1.0);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; ++i) {
positions[i] = Vec3(i/2, (i+1)/2, 0);
velocities[i] = Vec3(genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5);
}
context.setPositions(positions);
context.setVelocities(velocities);
// Simulate it and see whether the constraints remain satisfied.
double initialEnergy = 0.0;
for (int i = 0; i < 1000; ++i) {
integrator.step(2);
State state = context.getState(State::Positions | State::Velocities | State::Energy);
for (int j = 0; j < system.getNumConstraints(); ++j) {
int particle1, particle2;
double distance;
system.getConstraintParameters(j, particle1, particle2, distance);
Vec3 p1 = state.getPositions()[particle1];
Vec3 p2 = state.getPositions()[particle2];
double dist = std::sqrt((p1[0]-p2[0])*(p1[0]-p2[0])+(p1[1]-p2[1])*(p1[1]-p2[1])+(p1[2]-p2[2])*(p1[2]-p2[2]));
ASSERT_EQUAL_TOL(distance, dist, 2e-5);
if (i > 0) {
Vec3 v1 = state.getVelocities()[particle1];
Vec3 v2 = state.getVelocities()[particle2];
double vel = (v1-v2).dot(p1-p2);
ASSERT_EQUAL_TOL(0.0, vel, 2e-5);
}
}
double energy = state.getKineticEnergy()+state.getPotentialEnergy();
if (i == 0)
initialEnergy = energy;
else if (i > 0)
ASSERT_EQUAL_TOL(initialEnergy, energy, 0.01);
}
}
void testConstrainedMasslessParticles() {
System system;
system.addParticle(0.0);
system.addParticle(1.0);
system.addConstraint(0, 1, 1.5);
vector<Vec3> positions(2);
positions[0] = Vec3(-1, 0, 0);
positions[1] = Vec3(1, 0, 0);
CustomIntegrator integrator(0.002);
integrator.addPerDofVariable("oldx", 0);
integrator.addComputePerDof("v", "v+dt*f/m");
integrator.addComputePerDof("oldx", "x");
integrator.addComputePerDof("x", "x+dt*v");
integrator.addConstrainPositions();
integrator.addComputePerDof("v", "(x-oldx)/dt");
bool failed = false;
try {
// This should throw an exception.
Context context(system, integrator, platform);
}
catch (exception& ex) {
failed = true;
}
ASSERT(failed);
// Now make both particles massless, which should work.
system.setParticleMass(1, 0.0);
Context context(system, integrator, platform);
context.setPositions(positions);
context.setVelocitiesToTemperature(300.0);
integrator.step(1);
State state = context.getState(State::Velocities | State::Positions);
ASSERT_EQUAL(0.0, state.getVelocities()[0][0]);
}
/**
* Test an integrator with an AndersenThermostat to see if updateContextState()
* is being handled correctly.
*/
void testWithThermostat() {
const int numParticles = 8;
const double temp = 100.0;
const double collisionFreq = 10.0;
const int numSteps = 5000;
System system;
CustomIntegrator integrator(0.003);
integrator.addUpdateContextState();
integrator.addComputePerDof("v", "v+dt*f/m");
integrator.addComputePerDof("x", "x+dt*v");
NonbondedForce* forceField = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(2.0);
forceField->addParticle((i%2 == 0 ? 1.0 : -1.0), 1.0, 5.0);
}
system.addForce(forceField);
AndersenThermostat* thermostat = new AndersenThermostat(temp, collisionFreq);
system.addForce(thermostat);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
for (int i = 0; i < numParticles; ++i)
positions[i] = Vec3((i%2 == 0 ? 2 : -2), (i%4 < 2 ? 2 : -2), (i < 4 ? 2 : -2));
context.setPositions(positions);
context.setVelocitiesToTemperature(temp);
// Let it equilibrate.
integrator.step(10000);
// Now run it for a while and see if the temperature is correct.
double ke = 0.0;
for (int i = 0; i < numSteps; ++i) {
State state = context.getState(State::Energy);
ke += state.getKineticEnergy();
integrator.step(10);
}
ke /= numSteps;
double expected = 0.5*numParticles*3*BOLTZ*temp;
ASSERT_USUALLY_EQUAL_TOL(expected, ke, 0.1);
}
/**
* Test a Monte Carlo integrator that uses global variables and depends on energy.
*/
void testMonteCarlo() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
CustomIntegrator integrator(0.1);
const double kT = BOLTZ*300.0;
integrator.addGlobalVariable("kT", kT);
integrator.addGlobalVariable("oldE", 0);
integrator.addGlobalVariable("accept", 0);
integrator.addPerDofVariable("oldx", 0);
integrator.addComputeGlobal("oldE", "energy");
integrator.addComputePerDof("oldx", "x");
integrator.addComputePerDof("x", "x+dt*gaussian");
integrator.addComputeGlobal("accept", "step(exp((oldE-energy)/kT)-uniform)");
integrator.addComputePerDof("x", "select(accept, x, oldx)");
HarmonicBondForce* forceField = new HarmonicBondForce();
forceField->addBond(0, 1, 2.0, 10.0);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(-1, 0, 0);
positions[1] = Vec3(1, 0, 0);
context.setPositions(positions);
// Compute the histogram of distances and see if it satisfies a Boltzmann distribution.
const int numBins = 100;
const double maxDist = 4.0;
const int numIterations = 5000;
vector<int> counts(numBins, 0);
for (int i = 0; i < numIterations; ++i) {
integrator.step(10);
State state = context.getState(State::Positions);
Vec3 delta = state.getPositions()[0]-state.getPositions()[1];
double dist = sqrt(delta.dot(delta));
if (dist < maxDist)
counts[(int) (numBins*dist/maxDist)]++;
}
vector<double> expected(numBins, 0);
double sum = 0;
for (int i = 0; i < numBins; i++) {
double dist = (i+0.5)*maxDist/numBins;
expected[i] = dist*dist*exp(-5.0*(dist-2)*(dist-2)/kT);
sum += expected[i];
}
for (int i = 0; i < numBins; i++)
ASSERT_USUALLY_EQUAL_TOL((double) counts[i]/numIterations, expected[i]/sum, 0.01);
}
/**
* Test the ComputeSum operation.
*/
void testSum() {
const int numParticles = 200;
const double boxSize = 10;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nb = new NonbondedForce();
system.addForce(nb);
vector<Vec3> positions(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; i++) {
system.addParticle(i%10 == 0 ? 0.0 : 1.5);
nb->addParticle(i%2 == 0 ? 0.1 : -0.1, 0.1, 1);
bool close = true;
while (close) {
positions[i] = Vec3(boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt));
close = false;
for (int j = 0; j < i; ++j) {
Vec3 delta = positions[i]-positions[j];
if (delta.dot(delta) < 1)
close = true;
}
}
}
CustomIntegrator integrator(0.005);
integrator.addGlobalVariable("ke", 0);
integrator.addComputePerDof("v", "v+dt*f/m");
integrator.addComputePerDof("x", "x+dt*v");
integrator.addComputeSum("ke", "m*v*v/2");
Context context(system, integrator, platform);
context.setPositions(positions);
// See if the sum is being computed correctly.
for (int i = 0; i < 100; ++i) {
State state = context.getState(State::Energy);
ASSERT_EQUAL_TOL(state.getKineticEnergy(), integrator.getGlobalVariable(0), 1e-5);
integrator.step(1);
}
}
/**
* Test an integrator that both uses and modifies a context parameter.
*/
void testParameter() {
System system;
system.addParticle(1.0);
AndersenThermostat* thermostat = new AndersenThermostat(0.1, 0.1);
system.addForce(thermostat);
CustomIntegrator integrator(0.1);
integrator.addGlobalVariable("temp", 0);
integrator.addComputeGlobal("temp", "AndersenTemperature");
integrator.addComputeGlobal("AndersenTemperature", "temp*2");
Context context(system, integrator, platform);
// See if the parameter is being used correctly.
for (int i = 0; i < 10; i++) {
integrator.step(1);
ASSERT_EQUAL_TOL(context.getParameter("AndersenTemperature"), 0.1*(1<<(i+1)), 1e-10);
}
}
/**
* Test random number distributions.
*/
void testRandomDistributions() {
const int numParticles = 100;
const int numBins = 20;
const int numSteps = 100;
System system;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
CustomIntegrator integrator(0.1);
integrator.addPerDofVariable("a", 0);
integrator.addPerDofVariable("b", 0);
integrator.addComputePerDof("a", "uniform");
integrator.addComputePerDof("b", "gaussian");
Context context(system, integrator, platform);
// See if the random numbers are distributed correctly.
vector<int> bins(numBins);
double mean = 0.0;
double var = 0.0;
double skew = 0.0;
double kurtosis = 0.0;
vector<Vec3> values;
for (int i = 0; i < numSteps; i++) {
integrator.step(1);
integrator.getPerDofVariable(0, values);
for (int i = 0; i < numParticles; i++)
for (int j = 0; j < 3; j++) {
double v = values[i][j];
ASSERT(v >= 0 && v < 1);
bins[(int) (v*numBins)]++;
}
integrator.getPerDofVariable(1, values);
for (int i = 0; i < numParticles; i++)
for (int j = 0; j < 3; j++) {
double v = values[i][j];
mean += v;
var += v*v;
skew += v*v*v;
kurtosis += v*v*v*v;
}
}
// Check the distribution of uniform randoms.
int numValues = numParticles*numSteps*3;
double expected = numValues/(double) numBins;
double tol = 4*sqrt(expected);
for (int i = 0; i < numBins; i++)
ASSERT(bins[i] >= expected-tol && bins[i] <= expected+tol);
// Check the distribution of gaussian randoms.
mean /= numValues;
var /= numValues;
skew /= numValues;
kurtosis /= numValues;
double c2 = var-mean*mean;
double c3 = skew-3*var*mean+2*mean*mean*mean;
double c4 = kurtosis-4*skew*mean-3*var*var+12*var*mean*mean-6*mean*mean*mean*mean;
ASSERT_EQUAL_TOL(0.0, mean, 3.0/sqrt((double) numValues));
ASSERT_EQUAL_TOL(1.0, c2, 3.0/pow(numValues, 1.0/3.0));
ASSERT_EQUAL_TOL(0.0, c3, 3.0/pow(numValues, 1.0/4.0));
ASSERT_EQUAL_TOL(0.0, c4, 3.0/pow(numValues, 1.0/4.0));
}
/**
* Test getting and setting per-DOF variables.
*/
void testPerDofVariables() {
const int numParticles = 200;
const double boxSize = 10;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
NonbondedForce* nb = new NonbondedForce();
system.addForce(nb);
nb->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
vector<Vec3> positions(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.5);
nb->addParticle(i%2 == 0 ? 1 : -1, 0.1, 1);
bool close = true;
while (close) {
positions[i] = Vec3(boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt));
close = false;
for (int j = 0; j < i; ++j) {
Vec3 delta = positions[i]-positions[j];
if (delta.dot(delta) < 0.1)
close = true;
}
}
}
CustomIntegrator integrator(0.01);
integrator.addPerDofVariable("temp", 0);
integrator.addPerDofVariable("pos", 0);
integrator.addComputePerDof("v", "v+dt*f/m");
integrator.addComputePerDof("x", "x+dt*v");
integrator.addComputePerDof("pos", "x");
Context context(system, integrator, platform);
context.setPositions(positions);
vector<Vec3> initialValues(numParticles);
for (int i = 0; i < numParticles; i++)
initialValues[i] = Vec3(i+0.1, i+0.2, i+0.3);
integrator.setPerDofVariable(0, initialValues);
// Run a simulation, then query per-DOF values and see if they are correct.
vector<Vec3> values;
for (int i = 0; i < 100; ++i) {
integrator.step(1);
State state = context.getState(State::Positions);
integrator.getPerDofVariable(0, values);
for (int j = 0; j < numParticles; j++)
ASSERT_EQUAL_VEC(initialValues[j], values[j], 1e-5);
integrator.getPerDofVariable(1, values);
for (int j = 0; j < numParticles; j++)
ASSERT_EQUAL_VEC(state.getPositions()[j], values[j], 1e-5);
}
}
/**
* Test evaluating force groups separately.
*/
void testForceGroups() {
System system;
system.addParticle(2.0);
system.addParticle(2.0);
CustomIntegrator integrator(0.01);
integrator.addPerDofVariable("outf", 0);
integrator.addPerDofVariable("outf1", 0);
integrator.addPerDofVariable("outf2", 0);
integrator.addGlobalVariable("oute", 0);
integrator.addGlobalVariable("oute1", 0);
integrator.addGlobalVariable("oute2", 0);
integrator.addComputePerDof("outf", "f");
integrator.addComputePerDof("outf1", "f1");
integrator.addComputePerDof("outf2", "f2");
integrator.addComputeGlobal("oute", "energy");
integrator.addComputeGlobal("oute1", "energy1");
integrator.addComputeGlobal("oute2", "energy2");
HarmonicBondForce* bonds = new HarmonicBondForce();
bonds->addBond(0, 1, 1.5, 1.1);
bonds->setForceGroup(1);
system.addForce(bonds);
NonbondedForce* nb = new NonbondedForce();
nb->addParticle(0.2, 1, 0);
nb->addParticle(0.2, 1, 0);
nb->setForceGroup(2);
system.addForce(nb);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(-1, 0, 0);
positions[1] = Vec3(1, 0, 0);
context.setPositions(positions);
// See if the various forces are computed correctly.
integrator.step(1);
vector<Vec3> f, f1, f2;
double e1 = 0.5*1.1*0.5*0.5;
double e2 = 138.935456*0.2*0.2/2.0;
integrator.getPerDofVariable(0, f);
integrator.getPerDofVariable(1, f1);
integrator.getPerDofVariable(2, f2);
ASSERT_EQUAL_VEC(Vec3(1.1*0.5, 0, 0), f1[0], 1e-5);
ASSERT_EQUAL_VEC(Vec3(-1.1*0.5, 0, 0), f1[1], 1e-5);
ASSERT_EQUAL_VEC(Vec3(-138.935456*0.2*0.2/4.0, 0, 0), f2[0], 1e-5);
ASSERT_EQUAL_VEC(Vec3(138.935456*0.2*0.2/4.0, 0, 0), f2[1], 1e-5);
ASSERT_EQUAL_VEC(f1[0]+f2[0], f[0], 1e-5);
ASSERT_EQUAL_VEC(f1[1]+f2[1], f[1], 1e-5);
ASSERT_EQUAL_TOL(e1, integrator.getGlobalVariable(1), 1e-5);
ASSERT_EQUAL_TOL(e2, integrator.getGlobalVariable(2), 1e-5);
ASSERT_EQUAL_TOL(e1+e2, integrator.getGlobalVariable(0), 1e-5);
// Make sure they also match the values returned by the Context.
State s = context.getState(State::Forces | State::Energy, false);
State s1 = context.getState(State::Forces | State::Energy, false, 2);
State s2 = context.getState(State::Forces | State::Energy, false, 4);
vector<Vec3> c, c1, c2;
c = context.getState(State::Forces, false).getForces();
c1 = context.getState(State::Forces, false, 2).getForces();
c2 = context.getState(State::Forces, false, 4).getForces();
ASSERT_EQUAL_VEC(f[0], c[0], 1e-5);
ASSERT_EQUAL_VEC(f[1], c[1], 1e-5);
ASSERT_EQUAL_VEC(f1[0], c1[0], 1e-5);
ASSERT_EQUAL_VEC(f1[1], c1[1], 1e-5);
ASSERT_EQUAL_VEC(f2[0], c2[0], 1e-5);
ASSERT_EQUAL_VEC(f2[1], c2[1], 1e-5);
ASSERT_EQUAL_TOL(s.getPotentialEnergy(), integrator.getGlobalVariable(0), 1e-5);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), integrator.getGlobalVariable(1), 1e-5);
ASSERT_EQUAL_TOL(s2.getPotentialEnergy(), integrator.getGlobalVariable(2), 1e-5);
}
/**
* Test a multiple time step r-RESPA integrator.
*/
void testRespa() {
const int numParticles = 8;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(4, 0, 0), Vec3(0, 4, 0), Vec3(0, 0, 4));
CustomIntegrator integrator(0.002);
integrator.addComputePerDof("v", "v+0.5*dt*f1/m");
for (int i = 0; i < 2; i++) {
integrator.addComputePerDof("v", "v+0.5*(dt/2)*f0/m");
integrator.addComputePerDof("x", "x+(dt/2)*v");
integrator.addComputePerDof("v", "v+0.5*(dt/2)*f0/m");
}
integrator.addComputePerDof("v", "v+0.5*dt*f1/m");
HarmonicBondForce* bonds = new HarmonicBondForce();
for (int i = 0; i < numParticles-2; i++)
bonds->addBond(i, i+1, 1.0, 0.5);
system.addForce(bonds);
NonbondedForce* nb = new NonbondedForce();
nb->setCutoffDistance(2.0);
nb->setNonbondedMethod(NonbondedForce::Ewald);
for (int i = 0; i < numParticles; ++i) {
system.addParticle(i%2 == 0 ? 5.0 : 10.0);
nb->addParticle((i%2 == 0 ? 0.2 : -0.2), 0.5, 5.0);
}
nb->setForceGroup(1);
nb->setReciprocalSpaceForceGroup(0);
system.addForce(nb);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; ++i) {
positions[i] = Vec3(i/2, (i+1)/2, 0);
velocities[i] = Vec3(genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5);
}
context.setPositions(positions);
context.setVelocities(velocities);
// Simulate it and monitor energy conservations.
double initialEnergy = 0.0;
for (int i = 0; i < 1000; ++i) {
State state = context.getState(State::Energy);
double energy = state.getKineticEnergy()+state.getPotentialEnergy();
if (i == 1)
initialEnergy = energy;
else if (i > 1)
ASSERT_EQUAL_TOL(initialEnergy, energy, 0.05);
integrator.step(2);
}
}
void testIfBlock() {
System system;
system.addParticle(2.0);
system.addParticle(2.0);
const double dt = 0.01;
CustomIntegrator integrator(dt);
integrator.addGlobalVariable("a", 0);
integrator.addGlobalVariable("b", 0);
integrator.addComputeGlobal("b", "1");
integrator.beginIfBlock("a < 3.5");
integrator.addComputeGlobal("b", "a+1");
integrator.endBlock();
Context context(system, integrator, platform);
// Set "a" to 1.7 and verify that "b" gets set to a+1.
integrator.setGlobalVariable(0, 1.7);
integrator.step(1);
ASSERT_EQUAL_TOL(2.7, integrator.getGlobalVariable(1), 1e-6);
// Now set it to a value that should cause the block to be skipped.
integrator.setGlobalVariable(0, 4.1);
integrator.step(1);
ASSERT_EQUAL_TOL(1.0, integrator.getGlobalVariable(1), 1e-6);
}
void testWhileBlock() {
System system;
system.addParticle(2.0);
system.addParticle(2.0);
const double dt = 0.01;
CustomIntegrator integrator(dt);
integrator.addGlobalVariable("a", 0);
integrator.addGlobalVariable("b", 0);
integrator.addComputeGlobal("b", "1");
integrator.beginWhileBlock("b <= a");
integrator.addComputeGlobal("b", "b+1");
integrator.endBlock();
Context context(system, integrator, platform);
// Try a case where the loop should be skipped.
integrator.setGlobalVariable(0, -3.3);
integrator.step(1);
ASSERT_EQUAL_TOL(1.0, integrator.getGlobalVariable(1), 1e-6);
// In this case it should be executed exactly once.
integrator.setGlobalVariable(0, 1.2);
integrator.step(1);
ASSERT_EQUAL_TOL(2.0, integrator.getGlobalVariable(1), 1e-6);
// In this case, it should be executed several times.
integrator.setGlobalVariable(0, 5.3);
integrator.step(1);
ASSERT_EQUAL_TOL(6.0, integrator.getGlobalVariable(1), 1e-6);
}
/**
* Test modifying a global variable, then using it in a per-DOF computation.
*/
void testChangingGlobal() {
System system;
system.addParticle(1.0);
CustomIntegrator integrator(0.1);
integrator.addGlobalVariable("g", 0);
integrator.addPerDofVariable("a", 0);
integrator.addPerDofVariable("b", 0);
integrator.addComputeGlobal("g", "g+1");
integrator.addComputePerDof("a", "0.5");
integrator.addComputePerDof("b", "a+g");
Context context(system, integrator, platform);
// See if everything is being calculated correctly..
for (int i = 0; i < 10; i++) {
integrator.step(1);
ASSERT_EQUAL_TOL(i+1.0, integrator.getGlobalVariable(0), 1e-5);
vector<Vec3> values;
integrator.getPerDofVariable(1, values);
ASSERT_EQUAL_VEC(Vec3(i+1.5, i+1.5, i+1.5), values[0], 1e-5);
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testSingleBond();
testConstraints();
testVelocityConstraints();
testConstrainedMasslessParticles();
testWithThermostat();
testMonteCarlo();
testSum();
testParameter();
testRandomDistributions();
testPerDofVariables();
testForceGroups();
testRespa();
testIfBlock();
testWhileBlock();
testChangingGlobal();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2014-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#ifdef WIN32
#define _USE_MATH_DEFINES // Needed to get M_PI
#endif
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomCompoundBondForce.h"
#include "openmm/CustomManyParticleForce.h"
#include "openmm/System.h"
#include "openmm/TabulatedFunction.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
Vec3 computeDelta(const Vec3& pos1, const Vec3& pos2, bool periodic, const Vec3* periodicBoxVectors) {
Vec3 diff = pos1-pos2;
if (periodic) {
diff -= periodicBoxVectors[2]*floor(diff[2]/periodicBoxVectors[2][2]+0.5);
diff -= periodicBoxVectors[1]*floor(diff[1]/periodicBoxVectors[1][1]+0.5);
diff -= periodicBoxVectors[0]*floor(diff[0]/periodicBoxVectors[0][0]+0.5);
}
return diff;
}
void validateAxilrodTeller(CustomManyParticleForce* force, const vector<Vec3>& positions, const vector<const int*>& expectedSets, double boxSize, bool triclinic) {
// Create a System and Context.
int numParticles = force->getNumParticles();
CustomManyParticleForce::NonbondedMethod nonbondedMethod = force->getNonbondedMethod();
System system;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
Vec3 boxVectors[3];
if (triclinic) {
boxVectors[0] = Vec3(boxSize, 0, 0);
boxVectors[1] = Vec3(0.2*boxSize, boxSize, 0);
boxVectors[2] = Vec3(-0.3*boxSize, -0.1*boxSize, boxSize);
}
else {
boxVectors[0] = Vec3(boxSize, 0, 0);
boxVectors[1] = Vec3(0, boxSize, 0);
boxVectors[2] = Vec3(0, 0, boxSize);
}
system.setDefaultPeriodicBoxVectors(boxVectors[0], boxVectors[1], boxVectors[2]);
system.addForce(force);
if (force->getNonbondedMethod() == CustomManyParticleForce::CutoffPeriodic) {
ASSERT(force->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
}
else {
ASSERT(!force->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
}
VerletIntegrator integrator(0.001);
Context context(system, integrator, platform);
context.setPositions(positions);
State state1 = context.getState(State::Forces | State::Energy);
double c = context.getParameter("C");
// See if the energy matches the expected value.
double expectedEnergy = 0;
bool periodic = (nonbondedMethod == CustomManyParticleForce::CutoffPeriodic);
for (int i = 0; i < (int) expectedSets.size(); i++) {
int p1 = expectedSets[i][0];
int p2 = expectedSets[i][1];
int p3 = expectedSets[i][2];
Vec3 d12 = computeDelta(positions[p2], positions[p1], periodic, boxVectors);
Vec3 d13 = computeDelta(positions[p3], positions[p1], periodic, boxVectors);
Vec3 d23 = computeDelta(positions[p3], positions[p2], periodic, boxVectors);
double r12 = sqrt(d12.dot(d12));
double r13 = sqrt(d13.dot(d13));
double r23 = sqrt(d23.dot(d23));
double ctheta1 = d12.dot(d13)/(r12*r13);
double ctheta2 = -d12.dot(d23)/(r12*r23);
double ctheta3 = d13.dot(d23)/(r13*r23);
double rprod = r12*r13*r23;
expectedEnergy += c*(1+3*ctheta1*ctheta2*ctheta3)/(rprod*rprod*rprod);
}
ASSERT_EQUAL_TOL(expectedEnergy, state1.getPotentialEnergy(), 1e-5);
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
const vector<Vec3>& forces = state1.getForces();
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
norm = std::sqrt(norm);
const double stepSize = 1e-3;
double step = 0.5*stepSize/norm;
vector<Vec3> positions2(numParticles), positions3(numParticles);
for (int i = 0; i < (int) positions.size(); ++i) {
Vec3 p = positions[i];
Vec3 f = forces[i];
positions2[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
positions3[i] = Vec3(p[0]+f[0]*step, p[1]+f[1]*step, p[2]+f[2]*step);
}
context.setPositions(positions2);
State state2 = context.getState(State::Energy);
context.setPositions(positions3);
State state3 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state3.getPotentialEnergy())/stepSize, 1e-4);
}
void validateStillingerWeber(CustomManyParticleForce* force, const vector<Vec3>& positions, const vector<const int*>& expectedSets, double boxSize) {
// Create a System and Context.
int numParticles = force->getNumParticles();
CustomManyParticleForce::NonbondedMethod nonbondedMethod = force->getNonbondedMethod();
System system;
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
system.addForce(force);
VerletIntegrator integrator(0.001);
Context context(system, integrator, platform);
context.setPositions(positions);
State state1 = context.getState(State::Forces | State::Energy);
double L = context.getParameter("L");
double eps = context.getParameter("eps");
double a = context.getParameter("a");
double gamma = context.getParameter("gamma");
double sigma = context.getParameter("sigma");
// See if the energy matches the expected value.
double expectedEnergy = 0;
for (int i = 0; i < (int) expectedSets.size(); i++) {
int p1 = expectedSets[i][0];
int p2 = expectedSets[i][1];
int p3 = expectedSets[i][2];
Vec3 d12 = positions[p2]-positions[p1];
Vec3 d13 = positions[p3]-positions[p1];
Vec3 d23 = positions[p3]-positions[p2];
if (nonbondedMethod == CustomManyParticleForce::CutoffPeriodic) {
for (int j = 0; j < 3; j++) {
d12[j] -= floor(d12[j]/boxSize+0.5f)*boxSize;
d13[j] -= floor(d13[j]/boxSize+0.5f)*boxSize;
d23[j] -= floor(d23[j]/boxSize+0.5f)*boxSize;
}
}
double r12 = sqrt(d12.dot(d12));
double r13 = sqrt(d13.dot(d13));
double r23 = sqrt(d23.dot(d23));
double ctheta1 = d12.dot(d13)/(r12*r13);
double ctheta2 = -d12.dot(d23)/(r12*r23);
double ctheta3 = d13.dot(d23)/(r13*r23);
expectedEnergy += L*eps*(ctheta1+1.0/3.0)*(ctheta1+1.0/3.0)*exp(sigma*gamma/(r12-a*sigma))*exp(sigma*gamma/(r13-a*sigma));
}
ASSERT_EQUAL_TOL(expectedEnergy, state1.getPotentialEnergy(), 1e-5);
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
const vector<Vec3>& forces = state1.getForces();
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
norm = std::sqrt(norm);
const double stepSize = 1e-3;
double step = 0.5*stepSize/norm;
vector<Vec3> positions2(numParticles), positions3(numParticles);
for (int i = 0; i < (int) positions.size(); ++i) {
Vec3 p = positions[i];
Vec3 f = forces[i];
positions2[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
positions3[i] = Vec3(p[0]+f[0]*step, p[1]+f[1]*step, p[2]+f[2]*step);
}
context.setPositions(positions2);
State state2 = context.getState(State::Energy);
context.setPositions(positions3);
State state3 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state3.getPotentialEnergy())/stepSize, 1e-4);
}
void testNoCutoff() {
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"C*(1+3*cos(theta1)*cos(theta2)*cos(theta3))/(r12*r13*r23)^3;"
"theta1=angle(p1,p2,p3); theta2=angle(p2,p3,p1); theta3=angle(p3,p1,p2);"
"r12=distance(p1,p2); r13=distance(p1,p3); r23=distance(p2,p3)");
force->addGlobalParameter("C", 1.5);
vector<double> params;
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(1, 0, 0));
positions.push_back(Vec3(0, 1.1, 0.3));
positions.push_back(Vec3(0.4, 0, -0.8));
int sets[4][3] = {{0,1,2}, {1,2,3}, {2,3,0}, {3,0,1}};
vector<const int*> expectedSets(&sets[0], &sets[4]);
validateAxilrodTeller(force, positions, expectedSets, 2.0, false);
}
void testCutoff() {
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"C*(1+3*cos(theta1)*cos(theta2)*cos(theta3))/(r12*r13*r23)^3;"
"theta1=angle(p1,p2,p3); theta2=angle(p2,p3,p1); theta3=angle(p3,p1,p2);"
"r12=distance(p1,p2); r13=distance(p1,p3); r23=distance(p2,p3)");
force->addGlobalParameter("C", 1.5);
force->setNonbondedMethod(CustomManyParticleForce::CutoffNonPeriodic);
force->setCutoffDistance(1.55);
vector<double> params;
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(1, 0, 0));
positions.push_back(Vec3(0, 1.1, 0.3));
positions.push_back(Vec3(0.4, 0, -0.8));
positions.push_back(Vec3(0.2, 0.5, -0.1));
int sets[7][3] = {{0,1,2}, {0,1,3}, {0,1,4}, {0,2,4}, {0,3,4}, {1,2,4}, {1,3,4}};
vector<const int*> expectedSets(&sets[0], &sets[7]);
validateAxilrodTeller(force, positions, expectedSets, 2.0, false);
}
void testPeriodic() {
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"C*(1+3*cos(theta1)*cos(theta2)*cos(theta3))/(r12*r13*r23)^3;"
"theta1=angle(p1,p2,p3); theta2=angle(p2,p3,p1); theta3=angle(p3,p1,p2);"
"r12=distance(p1,p2); r13=distance(p1,p3); r23=distance(p2,p3)");
force->addGlobalParameter("C", 1.5);
force->setNonbondedMethod(CustomManyParticleForce::CutoffPeriodic);
force->setCutoffDistance(1.05);
vector<double> params;
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(1, 0, 0));
positions.push_back(Vec3(0, 1.1, 0.3));
positions.push_back(Vec3(0.4, 0, -0.8));
positions.push_back(Vec3(0.2, 0.5, -0.1));
double boxSize = 2.1;
int sets[5][3] = {{0,1,3}, {0,1,4}, {0,2,4}, {0,3,4}, {1,3,4}};
vector<const int*> expectedSets(&sets[0], &sets[5]);
validateAxilrodTeller(force, positions, expectedSets, boxSize, false);
}
void testTriclinic() {
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"C*(1+3*cos(theta1)*cos(theta2)*cos(theta3))/(r12*r13*r23)^3;"
"theta1=angle(p1,p2,p3); theta2=angle(p2,p3,p1); theta3=angle(p3,p1,p2);"
"r12=distance(p1,p2); r13=distance(p1,p3); r23=distance(p2,p3)");
force->addGlobalParameter("C", 1.5);
force->setNonbondedMethod(CustomManyParticleForce::CutoffPeriodic);
force->setCutoffDistance(1.05);
vector<double> params;
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(1, 0, 0));
positions.push_back(Vec3(0, 1.1, 0.3));
positions.push_back(Vec3(0.4, 0, -0.8));
positions.push_back(Vec3(0.2, 0.5, -0.1));
double boxSize = 2.1;
int sets[4][3] = {{0,1,3}, {0,1,4}, {0,3,4}, {1,3,4}};
vector<const int*> expectedSets(&sets[0], &sets[4]);
validateAxilrodTeller(force, positions, expectedSets, boxSize, true);
}
void testExclusions() {
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"C*(1+3*cos(theta1)*cos(theta2)*cos(theta3))/(r12*r13*r23)^3;"
"theta1=angle(p1,p2,p3); theta2=angle(p2,p3,p1); theta3=angle(p3,p1,p2);"
"r12=distance(p1,p2); r13=distance(p1,p3); r23=distance(p2,p3)");
force->addGlobalParameter("C", 1.5);
vector<double> params;
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(1, 0, 0));
positions.push_back(Vec3(0, 1.1, 0.3));
positions.push_back(Vec3(0.4, 0, -0.8));
positions.push_back(Vec3(0.2, 0.5, -0.1));
force->addExclusion(0, 2);
force->addExclusion(0, 3);
int sets[5][3] = {{0,1,4}, {1,2,3}, {1,2,4}, {1,3,4}, {2,3,4}};
vector<const int*> expectedSets(&sets[0], &sets[5]);
validateAxilrodTeller(force, positions, expectedSets, 2.0, false);
}
void testAllTerms() {
int numParticles = 4;
// Create a system with a CustomManyParticleForce.
System system1;
CustomManyParticleForce* force1 = new CustomManyParticleForce(4,
"distance(p1,p2)+angle(p1,p4,p3)+dihedral(p1,p3,p2,p4)+x1+y4+z3");
system1.addForce(force1);
vector<double> params;
for (int i = 0; i < numParticles; i++) {
system1.addParticle(1.0);
force1->addParticle(params, i);
}
set<int> filter;
filter.insert(0);
force1->setTypeFilter(0, filter);
filter.clear();
filter.insert(1);
force1->setTypeFilter(1, filter);
filter.clear();
filter.insert(3);
force1->setTypeFilter(2, filter);
filter.clear();
filter.insert(2);
force1->setTypeFilter(3, filter);
// Create a system that use a CustomCompoundBondForce to compute exactly the same interactions.
System system2;
CustomCompoundBondForce* force2 = new CustomCompoundBondForce(4,
"distance(p1,p2)+angle(p1,p3,p4)+dihedral(p1,p4,p2,p3)+x1+y3+z4");
system2.addForce(force2);
vector<int> particles;
particles.push_back(0);
particles.push_back(1);
particles.push_back(2);
particles.push_back(3);
force2->addBond(particles, params);
for (int i = 0; i < numParticles; i++)
system2.addParticle(1.0);
// Create contexts for both of them.
vector<Vec3> positions;
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; i++)
positions.push_back(Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt)));
VerletIntegrator integrator1(0.001);
VerletIntegrator integrator2(0.001);
Context context1(system1, integrator1, platform);
Context context2(system2, integrator2, platform);
context1.setPositions(positions);
context2.setPositions(positions);
// See if they produce identical forces and energies.
State state1 = context1.getState(State::Forces | State::Energy);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state2.getPotentialEnergy(), state1.getPotentialEnergy(), 1e-4);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state2.getForces()[i], state1.getForces()[i], 1e-4);
}
void testParameters() {
// Create a system.
int numParticles = 5;
System system;
CustomManyParticleForce* force = new CustomManyParticleForce(3, "C*scale1*scale2*scale3*(distance(p1,p2)+distance(p2,p3)+distance(p1,p3))");
force->addGlobalParameter("C", 2.0);
force->addPerParticleParameter("scale");
vector<double> params(1);
vector<Vec3> positions;
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; i++) {
params[0] = i+1;
force->addParticle(params);
positions.push_back(Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt)));
system.addParticle(1.0);
}
system.addForce(force);
VerletIntegrator integrator(0.001);
Context context(system, integrator, platform);
context.setPositions(positions);
// See if the energy is correct.
State state = context.getState(State::Energy);
double expectedEnergy = 0;
for (int i = 0; i < numParticles; i++)
for (int j = i+1; j < numParticles; j++)
for (int k = j+1; k < numParticles; k++) {
Vec3 d12 = positions[j]-positions[i];
Vec3 d13 = positions[k]-positions[i];
Vec3 d23 = positions[k]-positions[j];
double r12 = sqrt(d12.dot(d12));
double r13 = sqrt(d13.dot(d13));
double r23 = sqrt(d23.dot(d23));
expectedEnergy += 2.0*(i+1)*(j+1)*(k+1)*(r12+r13+r23);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), 1e-5);
// Modify the parameters.
context.setParameter("C", 3.5);
for (int i = 0; i < numParticles; i++) {
params[0] = 0.5*i-0.1;
force->setParticleParameters(i, params, 0);
}
force->updateParametersInContext(context);
// See if the energy is still correct.
state = context.getState(State::Energy);
expectedEnergy = 0;
for (int i = 0; i < numParticles; i++)
for (int j = i+1; j < numParticles; j++)
for (int k = j+1; k < numParticles; k++) {
Vec3 d12 = positions[j]-positions[i];
Vec3 d13 = positions[k]-positions[i];
Vec3 d23 = positions[k]-positions[j];
double r12 = sqrt(d12.dot(d12));
double r13 = sqrt(d13.dot(d13));
double r23 = sqrt(d23.dot(d23));
expectedEnergy += 3.5*(0.5*i-0.1)*(0.5*j-0.1)*(0.5*k-0.1)*(r12+r13+r23);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), 1e-5);
}
void testTabulatedFunctions() {
int numParticles = 5;
// Create two tabulated functions.
vector<double> values;
values.push_back(0.0);
values.push_back(50.0);
Continuous1DFunction* f1 = new Continuous1DFunction(values, 0, 100);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<double> c(numParticles);
for (int i = 0; i < numParticles; i++)
c[i] = genrand_real2(sfmt);
values.resize(numParticles*numParticles*numParticles);
for (int i = 0; i < numParticles; i++)
for (int j = 0; j < numParticles; j++)
for (int k = 0; k < numParticles; k++)
values[i+numParticles*j+numParticles*numParticles*k] = c[i]+c[j]+c[k];
Discrete3DFunction* f2 = new Discrete3DFunction(numParticles, numParticles, numParticles, values);
// Create a system.
System system;
CustomManyParticleForce* force = new CustomManyParticleForce(3, "f1(distance(p1,p2)+distance(p2,p3)+distance(p1,p3))*f2(atom1, atom2, atom3)");
force->addPerParticleParameter("atom");
force->addTabulatedFunction("f1", f1);
force->addTabulatedFunction("f2", f2);
vector<double> params(1);
vector<Vec3> positions;
for (int i = 0; i < numParticles; i++) {
params[0] = i;
force->addParticle(params);
positions.push_back(Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt)));
system.addParticle(1.0);
}
system.addForce(force);
VerletIntegrator integrator(0.001);
Context context(system, integrator, platform);
context.setPositions(positions);
// See if the energy is correct.
State state = context.getState(State::Energy);
double expectedEnergy = 0;
for (int i = 0; i < numParticles; i++)
for (int j = i+1; j < numParticles; j++)
for (int k = j+1; k < numParticles; k++) {
Vec3 d12 = positions[j]-positions[i];
Vec3 d13 = positions[k]-positions[i];
Vec3 d23 = positions[k]-positions[j];
double r12 = sqrt(d12.dot(d12));
double r13 = sqrt(d13.dot(d13));
double r23 = sqrt(d23.dot(d23));
expectedEnergy += 0.5*(r12+r13+r23)*(c[i]+c[j]+c[k]);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), 1e-5);
}
void testTypeFilters() {
// Create a system.
System system;
for (int i = 0; i < 5; i++)
system.addParticle(1.0);
CustomManyParticleForce* force = new CustomManyParticleForce(3, "c1*(distance(p1,p2)+distance(p1,p3))");
force->addPerParticleParameter("c");
double c[] = {1.0, 2.0, 1.3, 1.5, -2.1};
int type[] = {0, 1, 0, 1, 5};
vector<double> params(1);
for (int i = 0; i < 5; i++) {
params[0] = c[i];
force->addParticle(params, type[i]);
}
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(1, 0, 0));
positions.push_back(Vec3(0, 1.1, 0.3));
positions.push_back(Vec3(0.4, 0, -0.8));
positions.push_back(Vec3(0.2, 0.5, -0.1));
set<int> f1, f2;
f1.insert(0);
f2.insert(1);
f2.insert(5);
force->setTypeFilter(0, f1);
force->setTypeFilter(1, f2);
force->setTypeFilter(2, f2);
system.addForce(force);
VerletIntegrator integrator(0.001);
Context context(system, integrator, platform);
context.setPositions(positions);
// See if the energy is correct.
State state = context.getState(State::Energy);
double expectedEnergy = 0;
int sets[6][3] = {{0,1,3}, {0,1,4}, {0,3,4}, {2,1,3}, {2,1,4}, {2,3,4}};
for (int i = 0; i < 6; i++) {
int p1 = sets[i][0];
int p2 = sets[i][1];
int p3 = sets[i][2];
Vec3 d12 = positions[p2]-positions[p1];
Vec3 d13 = positions[p3]-positions[p1];
double r12 = sqrt(d12.dot(d12));
double r13 = sqrt(d13.dot(d13));
expectedEnergy += c[p1]*(r12+r13);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), 1e-5);
}
void testLargeSystem() {
int gridSize = 8;
int numParticles = gridSize*gridSize*gridSize;
double boxSize = 3.0;
double spacing = boxSize/gridSize;
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"C*(1+3*cos(theta1)*cos(theta2)*cos(theta3))/(r12*r13*r23)^3;"
"theta1=angle(p1,p2,p3); theta2=angle(p2,p3,p1); theta3=angle(p3,p1,p2);"
"r12=distance(p1,p2); r13=distance(p1,p3); r23=distance(p2,p3)");
force->addGlobalParameter("C", 1.5);
force->setNonbondedMethod(CustomManyParticleForce::CutoffPeriodic);
force->setCutoffDistance(0.6);
vector<double> params;
vector<Vec3> positions;
System system;
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < gridSize; i++)
for (int j = 0; j < gridSize; j++)
for (int k = 0; k < gridSize; k++) {
force->addParticle(params);
positions.push_back(Vec3((i+0.4*genrand_real2(sfmt))*spacing, (j+0.4*genrand_real2(sfmt))*spacing, (k+0.4*genrand_real2(sfmt))*spacing));
system.addParticle(1.0);
}
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
system.addForce(force);
VerletIntegrator integrator1(0.001);
VerletIntegrator integrator2(0.001);
Context context1(system, integrator1, Platform::getPlatformByName("Reference"));
Context context2(system, integrator2, platform);
context1.setPositions(positions);
context2.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-4);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-4);
}
void testCentralParticleModeNoCutoff() {
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"L*eps*(cos(theta1)+1/3)^2*exp(sigma*gamma/(r12-a*sigma))*exp(sigma*gamma/(r13-a*sigma));"
"r12 = distance(p1,p2); r13 = distance(p1,p3); theta1 = angle(p3,p1,p2)");
force->setPermutationMode(CustomManyParticleForce::UniqueCentralParticle);
force->addGlobalParameter("L", 23.13);
force->addGlobalParameter("eps", 25.894776);
force->addGlobalParameter("a", 1.8);
force->addGlobalParameter("sigma", 0.23925);
force->addGlobalParameter("gamma", 1.2);
vector<double> params;
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(0.1, 0, 0));
positions.push_back(Vec3(0, 0.11, 0.03));
positions.push_back(Vec3(0.04, 0, -0.08));
int sets[12][3] = {{0,1,2}, {0,1,3}, {0,2,3}, {1,0,2}, {1,0,3}, {1, 2, 3}, {2,0,1}, {2,0,3}, {2, 1, 3}, {3,0,1}, {3,0,2}, {3,1,2}};
vector<const int*> expectedSets(&sets[0], &sets[12]);
validateStillingerWeber(force, positions, expectedSets, 2.0);
}
void testCentralParticleModeCutoff() {
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"L*eps*(cos(theta1)+1/3)^2*exp(sigma*gamma/(r12-a*sigma))*exp(sigma*gamma/(r13-a*sigma));"
"r12 = distance(p1,p2); r13 = distance(p1,p3); theta1 = angle(p3,p1,p2)");
force->setPermutationMode(CustomManyParticleForce::UniqueCentralParticle);
force->addGlobalParameter("L", 23.13);
force->addGlobalParameter("eps", 25.894776);
force->addGlobalParameter("a", 1.8);
force->addGlobalParameter("sigma", 0.23925);
force->addGlobalParameter("gamma", 1.2);
force->setNonbondedMethod(CustomManyParticleForce::CutoffNonPeriodic);
force->setCutoffDistance(0.155);
vector<double> params;
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
force->addParticle(params);
vector<Vec3> positions;
positions.push_back(Vec3(0, 0, 0));
positions.push_back(Vec3(0.1, 0, 0));
positions.push_back(Vec3(0, 0.11, 0.03));
positions.push_back(Vec3(0.04, 0, -0.08));
int sets[8][3] = {{0,1,2}, {0,1,3}, {0,2,3}, {1,0,2}, {1,0,3}, {1, 2, 3}, {2,0,1}, {3,0,1}};
vector<const int*> expectedSets(&sets[0], &sets[8]);
validateStillingerWeber(force, positions, expectedSets, 2.0);
}
void testCentralParticleModeLargeSystem() {
int gridSize = 8;
int numParticles = gridSize*gridSize*gridSize;
double boxSize = 2.0;
double spacing = boxSize/gridSize;
CustomManyParticleForce* force = new CustomManyParticleForce(3,
"L*eps*(cos(theta1)+1/3)^2*exp(sigma*gamma/(r12-a*sigma))*exp(sigma*gamma/(r13-a*sigma));"
"r12 = distance(p1,p2); r13 = distance(p1,p3); theta1 = angle(p3,p1,p2)");
force->setPermutationMode(CustomManyParticleForce::UniqueCentralParticle);
force->addGlobalParameter("L", 23.13);
force->addGlobalParameter("eps", 25.894776);
force->addGlobalParameter("a", 1.8);
force->addGlobalParameter("sigma", 0.23925);
force->addGlobalParameter("gamma", 1.2);
force->setNonbondedMethod(CustomManyParticleForce::CutoffPeriodic);
force->setCutoffDistance(1.8*0.23925);
vector<double> params;
vector<Vec3> positions;
System system;
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < gridSize; i++)
for (int j = 0; j < gridSize; j++)
for (int k = 0; k < gridSize; k++) {
force->addParticle(params);
positions.push_back(Vec3((i+0.4*genrand_real2(sfmt))*spacing, (j+0.4*genrand_real2(sfmt))*spacing, (k+0.4*genrand_real2(sfmt))*spacing));
system.addParticle(1.0);
}
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
system.addForce(force);
VerletIntegrator integrator1(0.001);
VerletIntegrator integrator2(0.001);
Context context1(system, integrator1, Platform::getPlatformByName("Reference"));
Context context2(system, integrator2, platform);
context1.setPositions(positions);
context2.setPositions(positions);
State state1 = context1.getState(State::Forces | State::Energy);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-4);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-4);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testNoCutoff();
testCutoff();
testPeriodic();
testTriclinic();
testExclusions();
testAllTerms();
testParameters();
testTabulatedFunctions();
testTypeFilters();
testLargeSystem();
testCentralParticleModeNoCutoff();
testCentralParticleModeCutoff();
testCentralParticleModeLargeSystem();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#ifdef WIN32
#define _USE_MATH_DEFINES // Needed to get M_PI
#endif
#include "openmm/internal/AssertionUtilities.h"
#include "sfmt/SFMT.h"
#include "openmm/Context.h"
#include "openmm/CustomNonbondedForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testSimpleExpression() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("-0.1*r^3");
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(2, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double force = 0.1*3*(2*2);
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], TOL);
ASSERT_EQUAL_TOL(-0.1*(2*2*2), state.getPotentialEnergy(), TOL);
}
void testParameters() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("scale*a*(r*b)^3; a=a1*a2; b=c+b1+b2");
forceField->addPerParticleParameter("a");
forceField->addPerParticleParameter("b");
forceField->addGlobalParameter("scale", 3.0);
forceField->addGlobalParameter("c", -1.0);
vector<double> params(2);
params[0] = 1.5;
params[1] = 2.0;
forceField->addParticle(params);
params[0] = 2.0;
params[1] = 3.0;
forceField->addParticle(params);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(2, 0, 0);
context.setPositions(positions);
context.setParameter("scale", 1.0);
context.setParameter("c", 0.0);
State state = context.getState(State::Forces | State::Energy);
vector<Vec3> forces = state.getForces();
double force = -3.0*3*5.0*(10*10);
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], TOL);
ASSERT_EQUAL_TOL(3.0*(10*10*10), state.getPotentialEnergy(), TOL);
// Try changing the global parameters and make sure it's still correct.
context.setParameter("scale", 1.5);
context.setParameter("c", 1.0);
state = context.getState(State::Forces | State::Energy);
forces = state.getForces();
force = -1.5*3.0*3*6.0*(12*12);
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], TOL);
ASSERT_EQUAL_TOL(1.5*3.0*(12*12*12), state.getPotentialEnergy(), TOL);
// Try changing the per-particle parameters and make sure it's still correct.
params[0] = 1.6;
params[1] = 2.1;
forceField->setParticleParameters(0, params);
params[0] = 1.9;
params[1] = 2.8;
forceField->setParticleParameters(1, params);
forceField->updateParametersInContext(context);
state = context.getState(State::Forces | State::Energy);
forces = state.getForces();
force = -1.5*1.6*1.9*3*5.9*(11.8*11.8);
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], TOL);
ASSERT_EQUAL_TOL(1.5*1.6*1.9*(11.8*11.8*11.8), state.getPotentialEnergy(), TOL);
}
void testManyParameters() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("(a1*a2+b1*b2+c1*c2+d1*d2+e1*e2)*r");
forceField->addPerParticleParameter("a");
forceField->addPerParticleParameter("b");
forceField->addPerParticleParameter("c");
forceField->addPerParticleParameter("d");
forceField->addPerParticleParameter("e");
vector<double> params(5);
params[0] = 1.0;
params[1] = 2.0;
params[2] = 3.0;
params[3] = 4.0;
params[4] = 5.0;
forceField->addParticle(params);
params[0] = 1.1;
params[1] = 1.2;
params[2] = 1.3;
params[3] = 1.4;
params[4] = 1.5;
forceField->addParticle(params);
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(2, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
vector<Vec3> forces = state.getForces();
double force = 1*1.1 + 2*1.2 + 3*1.3 + 4*1.4 + 5*1.5;
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[1], TOL);
ASSERT_EQUAL_TOL(2*force, state.getPotentialEnergy(), TOL);
}
void testExclusions() {
System system;
VerletIntegrator integrator(0.01);
CustomNonbondedForce* nonbonded = new CustomNonbondedForce("a*r; a=a1+a2");
nonbonded->addPerParticleParameter("a");
vector<double> params(1);
vector<Vec3> positions(4);
for (int i = 0; i < 4; i++) {
system.addParticle(1.0);
params[0] = i+1;
nonbonded->addParticle(params);
positions[i] = Vec3(i, 0, 0);
}
nonbonded->addExclusion(0, 1);
nonbonded->addExclusion(1, 2);
nonbonded->addExclusion(2, 3);
nonbonded->addExclusion(0, 2);
nonbonded->addExclusion(1, 3);
system.addForce(nonbonded);
Context context(system, integrator, platform);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(1+4, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[2], TOL);
ASSERT_EQUAL_VEC(Vec3(-(1+4), 0, 0), forces[3], TOL);
ASSERT_EQUAL_TOL((1+4)*3.0, state.getPotentialEnergy(), TOL);
}
void testCutoff() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("r");
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
forceField->setNonbondedMethod(CustomNonbondedForce::CutoffNonPeriodic);
forceField->setCutoffDistance(2.5);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(0, 2, 0);
positions[2] = Vec3(0, 3, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0, 1, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -1, 0), forces[2], TOL);
ASSERT_EQUAL_TOL(2.0+1.0, state.getPotentialEnergy(), TOL);
}
void testPeriodic() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("r");
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
forceField->setNonbondedMethod(CustomNonbondedForce::CutoffPeriodic);
forceField->setCutoffDistance(2.0);
system.setDefaultPeriodicBoxVectors(Vec3(4, 0, 0), Vec3(0, 4, 0), Vec3(0, 0, 4));
system.addForce(forceField);
ASSERT(forceField->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(3);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(0, 2.1, 0);
positions[2] = Vec3(0, 3, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0, -2, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 2, 0), forces[1], TOL);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[2], TOL);
ASSERT_EQUAL_TOL(1.9+1+0.9, state.getPotentialEnergy(), TOL);
}
void testTriclinic() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
Vec3 a(3.1, 0, 0);
Vec3 b(0.4, 3.5, 0);
Vec3 c(-0.1, -0.5, 4.0);
system.setDefaultPeriodicBoxVectors(a, b, c);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* nonbonded = new CustomNonbondedForce("r");
nonbonded->addParticle(vector<double>());
nonbonded->addParticle(vector<double>());
nonbonded->setNonbondedMethod(CustomNonbondedForce::CutoffPeriodic);
const double cutoff = 1.5;
nonbonded->setCutoffDistance(cutoff);
system.addForce(nonbonded);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int iteration = 0; iteration < 50; iteration++) {
// Generate random positions for the two particles.
positions[0] = a*genrand_real2(sfmt) + b*genrand_real2(sfmt) + c*genrand_real2(sfmt);
positions[1] = a*genrand_real2(sfmt) + b*genrand_real2(sfmt) + c*genrand_real2(sfmt);
context.setPositions(positions);
// Loop over all possible periodic copies and find the nearest one.
Vec3 delta;
double distance2 = 100.0;
for (int i = -1; i < 2; i++)
for (int j = -1; j < 2; j++)
for (int k = -1; k < 2; k++) {
Vec3 d = positions[1]-positions[0]+a*i+b*j+c*k;
if (d.dot(d) < distance2) {
delta = d;
distance2 = d.dot(d);
}
}
double distance = sqrt(distance2);
// See if the force and energy are correct.
State state = context.getState(State::Forces | State::Energy);
if (distance >= cutoff) {
ASSERT_EQUAL(0.0, state.getPotentialEnergy());
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), state.getForces()[0], 0);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), state.getForces()[1], 0);
}
else {
const Vec3 force = delta/sqrt(delta.dot(delta));
ASSERT_EQUAL_TOL(distance, state.getPotentialEnergy(), TOL);
ASSERT_EQUAL_VEC(force, state.getForces()[0], TOL);
ASSERT_EQUAL_VEC(-force, state.getForces()[1], TOL);
}
}
}
void testContinuous1DFunction() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("fn(r)+1");
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
vector<double> table;
for (int i = 0; i < 21; i++)
table.push_back(sin(0.25*i));
forceField->addTabulatedFunction("fn", new Continuous1DFunction(table, 1.0, 6.0));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (int i = 1; i < 30; i++) {
double x = (7.0/30.0)*i;
positions[1] = Vec3(x, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double force = (x < 1.0 || x > 6.0 ? 0.0 : -cos(x-1.0));
double energy = (x < 1.0 || x > 6.0 ? 0.0 : sin(x-1.0))+1.0;
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], 0.1);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], 0.1);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 0.02);
}
for (int i = 1; i < 20; i++) {
double x = 0.25*i+1.0;
positions[1] = Vec3(x, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Energy);
double energy = (x < 1.0 || x > 6.0 ? 0.0 : sin(x-1.0))+1.0;
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 1e-4);
}
}
void testContinuous2DFunction() {
const int xsize = 20;
const int ysize = 21;
const double xmin = 0.4;
const double xmax = 1.5;
const double ymin = 0.0;
const double ymax = 2.1;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("fn(r,a)+1");
forceField->addGlobalParameter("a", 0.0);
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
vector<double> table(xsize*ysize);
for (int i = 0; i < xsize; i++) {
for (int j = 0; j < ysize; j++) {
double x = xmin + i*(xmax-xmin)/xsize;
double y = ymin + j*(ymax-ymin)/ysize;
table[i+xsize*j] = sin(0.25*x)*cos(0.33*y);
}
}
forceField->addTabulatedFunction("fn", new Continuous2DFunction(xsize, ysize, table, xmin, xmax, ymin, ymax));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (double x = xmin-0.15; x < xmax+0.2; x += 0.1) {
for (double y = ymin-0.15; y < ymax+0.2; y += 0.1) {
positions[1] = Vec3(x, 0, 0);
context.setParameter("a", y);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double energy = 1;
double force = 0;
if (x >= xmin && x <= xmax && y >= ymin && y <= ymax) {
energy = sin(0.25*x)*cos(0.33*y)+1.0;
force = -0.25*cos(0.25*x)*cos(0.33*y);
}
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], 0.1);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], 0.1);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 0.02);
}
}
}
void testContinuous3DFunction() {
const int xsize = 10;
const int ysize = 11;
const int zsize = 12;
const double xmin = 0.6;
const double xmax = 1.1;
const double ymin = 0.0;
const double ymax = 0.7;
const double zmin = 0.2;
const double zmax = 0.9;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("fn(r,a,b)+1");
forceField->addGlobalParameter("a", 0.0);
forceField->addGlobalParameter("b", 0.0);
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
vector<double> table(xsize*ysize*zsize);
for (int i = 0; i < xsize; i++) {
for (int j = 0; j < ysize; j++) {
for (int k = 0; k < zsize; k++) {
double x = xmin + i*(xmax-xmin)/xsize;
double y = ymin + j*(ymax-ymin)/ysize;
double z = zmin + k*(zmax-zmin)/zsize;
table[i+xsize*j+xsize*ysize*k] = sin(0.25*x)*cos(0.33*y)*(1+z);
}
}
}
forceField->addTabulatedFunction("fn", new Continuous3DFunction(xsize, ysize, zsize, table, xmin, xmax, ymin, ymax, zmin, zmax));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (double x = xmin-0.15; x < xmax+0.2; x += 0.1) {
for (double y = ymin-0.15; y < ymax+0.2; y += 0.1) {
for (double z = zmin-0.15; z < zmax+0.2; z += 0.1) {
positions[1] = Vec3(x, 0, 0);
context.setParameter("a", y);
context.setParameter("b", z);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
double energy = 1;
double force = 0;
if (x >= xmin && x <= xmax && y >= ymin && y <= ymax && z >= zmin && z <= zmax) {
energy = sin(0.25*x)*cos(0.33*y)*(1.0+z)+1.0;
force = -0.25*cos(0.25*x)*cos(0.33*y)*(1.0+z);
}
ASSERT_EQUAL_VEC(Vec3(-force, 0, 0), forces[0], 0.1);
ASSERT_EQUAL_VEC(Vec3(force, 0, 0), forces[1], 0.1);
ASSERT_EQUAL_TOL(energy, state.getPotentialEnergy(), 0.05);
}
}
}
}
void testDiscrete1DFunction() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("fn(r-1)+1");
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
vector<double> table;
for (int i = 0; i < 21; i++)
table.push_back(sin(0.25*i));
forceField->addTabulatedFunction("fn", new Discrete1DFunction(table));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (int i = 0; i < (int) table.size(); i++) {
positions[1] = Vec3(i+1, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[0], 1e-6);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], 1e-6);
ASSERT_EQUAL_TOL(table[i]+1.0, state.getPotentialEnergy(), 1e-6);
}
}
void testDiscrete2DFunction() {
const int xsize = 10;
const int ysize = 5;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("fn(r-1,a)+1");
forceField->addGlobalParameter("a", 0.0);
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
vector<double> table;
for (int i = 0; i < xsize; i++)
for (int j = 0; j < ysize; j++)
table.push_back(sin(0.25*i)+cos(0.33*j));
forceField->addTabulatedFunction("fn", new Discrete2DFunction(xsize, ysize, table));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (int i = 0; i < (int) table.size(); i++) {
positions[1] = Vec3((i%xsize)+1, 0, 0);
context.setPositions(positions);
context.setParameter("a", i/xsize);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[0], 1e-6);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], 1e-6);
ASSERT_EQUAL_TOL(table[i]+1.0, state.getPotentialEnergy(), 1e-6);
}
}
void testDiscrete3DFunction() {
const int xsize = 8;
const int ysize = 5;
const int zsize = 6;
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* forceField = new CustomNonbondedForce("fn(r-1,a,b)+1");
forceField->addGlobalParameter("a", 0.0);
forceField->addGlobalParameter("b", 0.0);
forceField->addParticle(vector<double>());
forceField->addParticle(vector<double>());
vector<double> table;
for (int i = 0; i < xsize; i++)
for (int j = 0; j < ysize; j++)
for (int k = 0; k < zsize; k++)
table.push_back(sin(0.25*i)+cos(0.33*j)+0.12345*k);
forceField->addTabulatedFunction("fn", new Discrete3DFunction(xsize, ysize, zsize, table));
system.addForce(forceField);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
for (int i = 0; i < (int) table.size(); i++) {
positions[1] = Vec3((i%xsize)+1, 0, 0);
context.setPositions(positions);
context.setParameter("a", (i/xsize)%ysize);
context.setParameter("b", i/(xsize*ysize));
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[0], 1e-6);
ASSERT_EQUAL_VEC(Vec3(0, 0, 0), forces[1], 1e-6);
ASSERT_EQUAL_TOL(table[i]+1.0, state.getPotentialEnergy(), 1e-6);
}
}
void testCoulombLennardJones() {
const int numMolecules = 300;
const int numParticles = numMolecules*2;
const double boxSize = 20.0;
// Create two systems: one with a NonbondedForce, and one using a CustomNonbondedForce to implement the same interaction.
System standardSystem;
System customSystem;
for (int i = 0; i < numParticles; i++) {
standardSystem.addParticle(1.0);
customSystem.addParticle(1.0);
}
NonbondedForce* standardNonbonded = new NonbondedForce();
CustomNonbondedForce* customNonbonded = new CustomNonbondedForce("4*eps*((sigma/r)^12-(sigma/r)^6)+138.935456*q/r; q=q1*q2; sigma=0.5*(sigma1+sigma2); eps=sqrt(eps1*eps2)");
customNonbonded->addPerParticleParameter("q");
customNonbonded->addPerParticleParameter("sigma");
customNonbonded->addPerParticleParameter("eps");
vector<Vec3> positions(numParticles);
vector<Vec3> velocities(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<double> params(3);
for (int i = 0; i < numMolecules; i++) {
if (i < numMolecules/2) {
standardNonbonded->addParticle(1.0, 0.2, 0.1);
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.1;
customNonbonded->addParticle(params);
standardNonbonded->addParticle(-1.0, 0.1, 0.1);
params[0] = -1.0;
params[1] = 0.1;
customNonbonded->addParticle(params);
}
else {
standardNonbonded->addParticle(1.0, 0.2, 0.2);
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.2;
customNonbonded->addParticle(params);
standardNonbonded->addParticle(-1.0, 0.1, 0.2);
params[0] = -1.0;
params[1] = 0.1;
customNonbonded->addParticle(params);
}
positions[2*i] = Vec3(boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt));
positions[2*i+1] = Vec3(positions[2*i][0]+1.0, positions[2*i][1], positions[2*i][2]);
velocities[2*i] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
velocities[2*i+1] = Vec3(genrand_real2(sfmt), genrand_real2(sfmt), genrand_real2(sfmt));
standardNonbonded->addException(2*i, 2*i+1, 0.0, 1.0, 0.0);
customNonbonded->addExclusion(2*i, 2*i+1);
}
standardNonbonded->setNonbondedMethod(NonbondedForce::NoCutoff);
customNonbonded->setNonbondedMethod(CustomNonbondedForce::NoCutoff);
standardSystem.addForce(standardNonbonded);
customSystem.addForce(customNonbonded);
ASSERT(!customNonbonded->usesPeriodicBoundaryConditions());
ASSERT(!customSystem.usesPeriodicBoundaryConditions());
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context context1(standardSystem, integrator1, platform);
Context context2(customSystem, integrator2, platform);
context1.setPositions(positions);
context2.setPositions(positions);
context1.setVelocities(velocities);
context2.setVelocities(velocities);
State state1 = context1.getState(State::Forces | State::Energy);
State state2 = context2.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(state1.getPotentialEnergy(), state2.getPotentialEnergy(), 1e-4);
for (int i = 0; i < numParticles; i++) {
ASSERT_EQUAL_VEC(state1.getForces()[i], state2.getForces()[i], 1e-4);
}
}
void testSwitchingFunction() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
CustomNonbondedForce* nonbonded = new CustomNonbondedForce("10/r^2");
vector<double> params;
nonbonded->addParticle(params);
nonbonded->addParticle(params);
nonbonded->setNonbondedMethod(CustomNonbondedForce::CutoffNonPeriodic);
nonbonded->setCutoffDistance(2.0);
nonbonded->setUseSwitchingFunction(true);
nonbonded->setSwitchingDistance(1.5);
system.addForce(nonbonded);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
// Compute the interaction at various distances.
for (double r = 1.0; r < 2.5; r += 0.1) {
positions[1] = Vec3(r, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
// See if the energy is correct.
double expectedEnergy = 10/(r*r);
double switchValue;
if (r <= 1.5)
switchValue = 1;
else if (r >= 2.0)
switchValue = 0;
else {
double t = (r-1.5)/0.5;
switchValue = 1+t*t*t*(-10+t*(15-t*6));
}
ASSERT_EQUAL_TOL(switchValue*expectedEnergy, state.getPotentialEnergy(), TOL);
// See if the force is the gradient of the energy.
double delta = 1e-3;
positions[1] = Vec3(r-delta, 0, 0);
context.setPositions(positions);
double e1 = context.getState(State::Energy).getPotentialEnergy();
positions[1] = Vec3(r+delta, 0, 0);
context.setPositions(positions);
double e2 = context.getState(State::Energy).getPotentialEnergy();
ASSERT_EQUAL_TOL((e2-e1)/(2*delta), state.getForces()[0][0], 1e-3);
}
}
void testLongRangeCorrection() {
// Create a box of particles.
int gridSize = 5;
int numParticles = gridSize*gridSize*gridSize;
double boxSize = gridSize*0.7;
double cutoff = boxSize/3;
System standardSystem;
System customSystem;
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
NonbondedForce* standardNonbonded = new NonbondedForce();
CustomNonbondedForce* customNonbonded = new CustomNonbondedForce("4*eps*((sigma/r)^12-(sigma/r)^6); sigma=0.5*(sigma1+sigma2); eps=sqrt(eps1*eps2)");
customNonbonded->addPerParticleParameter("sigma");
customNonbonded->addPerParticleParameter("eps");
vector<Vec3> positions(numParticles);
int index = 0;
vector<double> params1(2);
params1[0] = 1.1;
params1[1] = 0.5;
vector<double> params2(2);
params2[0] = 1;
params2[1] = 1;
for (int i = 0; i < gridSize; i++)
for (int j = 0; j < gridSize; j++)
for (int k = 0; k < gridSize; k++) {
standardSystem.addParticle(1.0);
customSystem.addParticle(1.0);
if (index%2 == 0) {
standardNonbonded->addParticle(0, params1[0], params1[1]);
customNonbonded->addParticle(params1);
}
else {
standardNonbonded->addParticle(0, params2[0], params2[1]);
customNonbonded->addParticle(params2);
}
positions[index] = Vec3(i*boxSize/gridSize, j*boxSize/gridSize, k*boxSize/gridSize);
index++;
}
standardNonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
customNonbonded->setNonbondedMethod(CustomNonbondedForce::CutoffPeriodic);
standardNonbonded->setCutoffDistance(cutoff);
customNonbonded->setCutoffDistance(cutoff);
standardSystem.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
customSystem.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
standardNonbonded->setUseDispersionCorrection(true);
customNonbonded->setUseLongRangeCorrection(true);
standardNonbonded->setUseSwitchingFunction(true);
customNonbonded->setUseSwitchingFunction(true);
standardNonbonded->setSwitchingDistance(0.8*cutoff);
customNonbonded->setSwitchingDistance(0.8*cutoff);
standardSystem.addForce(standardNonbonded);
customSystem.addForce(customNonbonded);
// Compute the correction for the standard force.
Context context1(standardSystem, integrator1, platform);
context1.setPositions(positions);
double standardEnergy1 = context1.getState(State::Energy).getPotentialEnergy();
standardNonbonded->setUseDispersionCorrection(false);
context1.reinitialize();
context1.setPositions(positions);
double standardEnergy2 = context1.getState(State::Energy).getPotentialEnergy();
// Compute the correction for the custom force.
Context context2(customSystem, integrator2, platform);
context2.setPositions(positions);
double customEnergy1 = context2.getState(State::Energy).getPotentialEnergy();
customNonbonded->setUseLongRangeCorrection(false);
context2.reinitialize();
context2.setPositions(positions);
double customEnergy2 = context2.getState(State::Energy).getPotentialEnergy();
// See if they agree.
ASSERT_EQUAL_TOL(standardEnergy1-standardEnergy2, customEnergy1-customEnergy2, 1e-4);
}
void testInteractionGroups() {
const int numParticles = 6;
System system;
VerletIntegrator integrator(0.01);
CustomNonbondedForce* nonbonded = new CustomNonbondedForce("v1+v2");
nonbonded->addPerParticleParameter("v");
vector<double> params(1, 0.001);
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.0);
nonbonded->addParticle(params);
params[0] *= 10;
}
set<int> set1, set2, set3, set4;
set1.insert(2);
set2.insert(0);
set2.insert(1);
set2.insert(2);
set2.insert(3);
set2.insert(4);
set2.insert(5);
nonbonded->addInteractionGroup(set1, set2); // Particle 2 interacts with every other particle.
set3.insert(0);
set3.insert(1);
set4.insert(4);
set4.insert(5);
nonbonded->addInteractionGroup(set3, set4); // Particles 0 and 1 interact with 4 and 5.
nonbonded->addExclusion(1, 2); // Add an exclusion to make sure it gets skipped.
system.addForce(nonbonded);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
context.setPositions(positions);
State state = context.getState(State::Energy);
double expectedEnergy = 331.423; // Each digit is the number of interactions a particle particle is involved in.
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), TOL);
}
void testLargeInteractionGroup() {
const int numMolecules = 300;
const int numParticles = numMolecules*2;
const double boxSize = 20.0;
// Create a large system.
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
for (int i = 0; i < numParticles; i++)
system.addParticle(1.0);
CustomNonbondedForce* nonbonded = new CustomNonbondedForce("4*eps*((sigma/r)^12-(sigma/r)^6)+138.935456*q/r; q=q1*q2; sigma=0.5*(sigma1+sigma2); eps=sqrt(eps1*eps2)");
nonbonded->addPerParticleParameter("q");
nonbonded->addPerParticleParameter("sigma");
nonbonded->addPerParticleParameter("eps");
vector<Vec3> positions(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<double> params(3);
for (int i = 0; i < numMolecules; i++) {
if (i < numMolecules/2) {
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.1;
nonbonded->addParticle(params);
params[0] = -1.0;
params[1] = 0.1;
nonbonded->addParticle(params);
}
else {
params[0] = 1.0;
params[1] = 0.2;
params[2] = 0.2;
nonbonded->addParticle(params);
params[0] = -1.0;
params[1] = 0.1;
nonbonded->addParticle(params);
}
positions[2*i] = Vec3(boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt), boxSize*genrand_real2(sfmt));
positions[2*i+1] = Vec3(positions[2*i][0]+1.0, positions[2*i][1], positions[2*i][2]);
nonbonded->addExclusion(2*i, 2*i+1);
}
nonbonded->setNonbondedMethod(CustomNonbondedForce::CutoffPeriodic);
system.addForce(nonbonded);
// Compute the forces.
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
State state1 = context.getState(State::Forces);
// Modify the force so only one particle interacts with everything else.
set<int> set1, set2;
set1.insert(151);
for (int i = 0; i < numParticles; i++)
set2.insert(i);
nonbonded->addInteractionGroup(set1, set2);
context.reinitialize();
context.setPositions(positions);
State state2 = context.getState(State::Forces);
// The force on that one particle should be the same.
ASSERT_EQUAL_VEC(state1.getForces()[151], state2.getForces()[151], 1e-4);
// Modify the interaction group so it includes all interactions. This should now reproduce the original forces
// on all atoms.
for (int i = 0; i < numParticles; i++)
set1.insert(i);
nonbonded->setInteractionGroupParameters(0, set1, set2);
context.reinitialize();
context.setPositions(positions);
State state3 = context.getState(State::Forces);
for (int i = 0; i < numParticles; i++)
ASSERT_EQUAL_VEC(state1.getForces()[i], state3.getForces()[i], 1e-4);
}
void testInteractionGroupLongRangeCorrection() {
const int numParticles = 10;
const double boxSize = 10.0;
const double cutoff = 0.5;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
CustomNonbondedForce* nonbonded = new CustomNonbondedForce("c1*c2*r^-4");
nonbonded->addPerParticleParameter("c");
vector<Vec3> positions(numParticles);
vector<double> params(1);
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.0);
params[0] = (i%2 == 0 ? 1.1 : 2.0);
nonbonded->addParticle(params);
positions[i] = Vec3(0.5*i, 0, 0);
}
nonbonded->setNonbondedMethod(CustomNonbondedForce::CutoffPeriodic);
nonbonded->setCutoffDistance(cutoff);
system.addForce(nonbonded);
// Setup nonbonded groups. They involve 1 interaction of type AA,
// 2 of type BB, and 5 of type AB.
set<int> set1, set2, set3, set4, set5;
set1.insert(0);
set1.insert(1);
set1.insert(2);
nonbonded->addInteractionGroup(set1, set1);
set2.insert(3);
set3.insert(4);
set3.insert(6);
set3.insert(8);
nonbonded->addInteractionGroup(set2, set3);
set4.insert(5);
set5.insert(7);
set5.insert(9);
nonbonded->addInteractionGroup(set4, set5);
// Compute energy with and without the correction.
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
double energy1 = context.getState(State::Energy).getPotentialEnergy();
nonbonded->setUseLongRangeCorrection(true);
context.reinitialize();
context.setPositions(positions);
double energy2 = context.getState(State::Energy).getPotentialEnergy();
// Check the result.
double sum = (1.1*1.1 + 2*2.0*2.0 + 5*1.1*2.0)*2.0;
int numPairs = (numParticles*(numParticles+1))/2;
double expected = 2*M_PI*numParticles*numParticles*sum/(numPairs*boxSize*boxSize*boxSize);
ASSERT_EQUAL_TOL(expected, energy2-energy1, 1e-4);
}
void testMultipleCutoffs() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
// Add multiple nonbonded forces that have different cutoffs.
CustomNonbondedForce* nonbonded1 = new CustomNonbondedForce("2*r");
nonbonded1->addParticle(vector<double>());
nonbonded1->addParticle(vector<double>());
nonbonded1->setNonbondedMethod(CustomNonbondedForce::CutoffNonPeriodic);
nonbonded1->setCutoffDistance(2.5);
system.addForce(nonbonded1);
CustomNonbondedForce* nonbonded2 = new CustomNonbondedForce("3*r");
nonbonded2->addParticle(vector<double>());
nonbonded2->addParticle(vector<double>());
nonbonded2->setNonbondedMethod(CustomNonbondedForce::CutoffNonPeriodic);
nonbonded2->setCutoffDistance(2.9);
nonbonded2->setForceGroup(1);
system.addForce(nonbonded2);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(0, 0, 0);
for (double r = 2.4; r < 3.2; r += 0.2) {
positions[1][1] = r;
context.setPositions(positions);
double e1 = (r < 2.5 ? 2.0*r : 0.0);
double e2 = (r < 2.9 ? 3.0*r : 0.0);
double f1 = (r < 2.5 ? 2.0 : 0.0);
double f2 = (r < 2.9 ? 3.0 : 0.0);
// Check the first force.
State state = context.getState(State::Forces | State::Energy, false, 1);
ASSERT_EQUAL_VEC(Vec3(0, f1, 0), state.getForces()[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -f1, 0), state.getForces()[1], TOL);
ASSERT_EQUAL_TOL(e1, state.getPotentialEnergy(), TOL);
// Check the second force.
state = context.getState(State::Forces | State::Energy, false, 2);
ASSERT_EQUAL_VEC(Vec3(0, f2, 0), state.getForces()[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -f2, 0), state.getForces()[1], TOL);
ASSERT_EQUAL_TOL(e2, state.getPotentialEnergy(), TOL);
// Check the sum of both forces.
state = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_VEC(Vec3(0, f1+f2, 0), state.getForces()[0], TOL);
ASSERT_EQUAL_VEC(Vec3(0, -f1-f2, 0), state.getForces()[1], TOL);
ASSERT_EQUAL_TOL(e1+e2, state.getPotentialEnergy(), TOL);
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testSimpleExpression();
testParameters();
testExclusions();
testCutoff();
testPeriodic();
testTriclinic();
testContinuous1DFunction();
testContinuous2DFunction();
testContinuous3DFunction();
testDiscrete1DFunction();
testDiscrete2DFunction();
testDiscrete3DFunction();
testCoulombLennardJones();
testSwitchingFunction();
testLongRangeCorrection();
testInteractionGroups();
testLargeInteractionGroup();
testInteractionGroupLongRangeCorrection();
testMultipleCutoffs();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#ifdef WIN32
#define _USE_MATH_DEFINES // Needed to get M_PI
#endif
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomTorsionForce.h"
#include "openmm/PeriodicTorsionForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testTorsions() {
// Create a system using a CustomTorsionForce.
System customSystem;
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
customSystem.addParticle(1.0);
CustomTorsionForce* custom = new CustomTorsionForce("k*(1+cos(n*theta-theta0))");
custom->addPerTorsionParameter("theta0");
custom->addPerTorsionParameter("n");
custom->addGlobalParameter("k", 0.5);
vector<double> parameters(2);
parameters[0] = 1.5;
parameters[1] = 1;
custom->addTorsion(0, 1, 2, 3, parameters);
parameters[0] = 2.0;
parameters[1] = 2;
custom->addTorsion(1, 2, 3, 4, parameters);
customSystem.addForce(custom);
ASSERT(!custom->usesPeriodicBoundaryConditions());
ASSERT(!customSystem.usesPeriodicBoundaryConditions());
// Create an identical system using a PeriodicTorsionForce.
System harmonicSystem;
harmonicSystem.addParticle(1.0);
harmonicSystem.addParticle(1.0);
harmonicSystem.addParticle(1.0);
harmonicSystem.addParticle(1.0);
harmonicSystem.addParticle(1.0);
VerletIntegrator integrator(0.01);
PeriodicTorsionForce* periodic = new PeriodicTorsionForce();
periodic->addTorsion(0, 1, 2, 3, 1, 1.5, 0.5);
periodic->addTorsion(1, 2, 3, 4, 2, 2.0, 0.5);
harmonicSystem.addForce(periodic);
// Set the atoms in various positions, and verify that both systems give identical forces and energy.
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(5);
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context c1(customSystem, integrator1, platform);
Context c2(harmonicSystem, integrator2, platform);
for (int i = 0; i < 50; i++) {
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
c1.setPositions(positions);
c2.setPositions(positions);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), TOL);
}
// Try changing the torsion parameters and make sure it's still correct.
parameters[0] = 1.6;
parameters[1] = 2;
custom->setTorsionParameters(0, 0, 1, 2, 3, parameters);
parameters[0] = 2.1;
parameters[1] = 3;
custom->setTorsionParameters(1, 1, 2, 3, 4, parameters);
custom->updateParametersInContext(c1);
periodic->setTorsionParameters(0, 0, 1, 2, 3, 2, 1.6, 0.5);
periodic->setTorsionParameters(1, 1, 2, 3, 4, 3, 2.1, 0.5);
periodic->updateParametersInContext(c2);
{
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
c1.setPositions(positions);
c2.setPositions(positions);
State s1 = c1.getState(State::Forces | State::Energy);
State s2 = c2.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = s1.getForces();
for (int i = 0; i < customSystem.getNumParticles(); i++)
ASSERT_EQUAL_VEC(s1.getForces()[i], s2.getForces()[i], TOL);
ASSERT_EQUAL_TOL(s1.getPotentialEnergy(), s2.getPotentialEnergy(), TOL);
}
}
void testRange() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
CustomTorsionForce* custom = new CustomTorsionForce("theta");
custom->addTorsion(0, 1, 2, 3, vector<double>());
system.addForce(custom);
// Set the atoms in various positions, and verify that the angle is always in the expected range.
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
vector<Vec3> positions(4);
VerletIntegrator integrator(0.01);
double minAngle = 1000;
double maxAngle = -1000;
Context context(system, integrator, platform);
for (int i = 0; i < 100; i++) {
for (int j = 0; j < (int) positions.size(); j++)
positions[j] = Vec3(5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt), 5.0*genrand_real2(sfmt));
context.setPositions(positions);
double angle = context.getState(State::Energy).getPotentialEnergy();
if (angle < minAngle)
minAngle = angle;
if (angle > maxAngle)
maxAngle = angle;
}
ASSERT(minAngle >= -M_PI);
ASSERT(maxAngle <= M_PI);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testTorsions();
testRange();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "ReferencePlatform.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/VerletIntegrator.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/NonbondedForceImpl.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
void testEwaldExact() {
// Use a NaCl crystal to compare the calculated and Madelung energies
const int numParticles = 1000;
const double cutoff = 1.0;
const double boxSize = 2.82;
const double ewaldTol = 1e-5;
System system;
for (int i = 0; i < numParticles/2; i++)
system.addParticle(22.99);
for (int i = 0; i < numParticles/2; i++)
system.addParticle(35.45);
VerletIntegrator integrator(0.01);
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < numParticles/2; i++)
nonbonded->addParticle(1.0, 1.0,0.0);
for (int i = 0; i < numParticles/2; i++)
nonbonded->addParticle(-1.0, 1.0,0.0);
nonbonded->setNonbondedMethod(NonbondedForce::Ewald);
nonbonded->setCutoffDistance(cutoff);
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
nonbonded->setEwaldErrorTolerance(ewaldTol);
system.addForce(nonbonded);
Context context(system, integrator, platform);
vector<Vec3> positions(numParticles);
#include "nacl_crystal.dat"
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces = state.getForces();
// The potential energy of an ion in a crystal is
// E = - (M*e^2/ 4*pi*epsilon0*a0),
// where
// M : Madelung constant (dimensionless, for FCC cells such as NaCl it is 1.7476)
// e : 1.6022 × 10−19 C
// 4*pi*epsilon0: 1.112 × 10−10 C²/(J m)
// a0 : 0.282 x 10-9 m (perfect cell)
//
// E is then the energy per pair of ions, so for our case
// E has to be divided by 2 (per ion), multiplied by N(avogadro), multiplied by number of particles, and divided by 1000 for kJ
double exactEnergy = - (1.7476 * 1.6022e-19 * 1.6022e-19 * 6.02214e+23 * numParticles) / (1.112e-10 * 0.282e-9 * 2 * 1000);
//cout << "exact\t\t: " << exactEnergy << endl;
//cout << "calc\t\t: " << state.getPotentialEnergy() << endl;
ASSERT_EQUAL_TOL(exactEnergy, state.getPotentialEnergy(), 100*ewaldTol);
}
void testEwaldPME(bool includeExceptions) {
// Use amorphous NaCl system for the tests
const int numParticles = 894;
const double cutoff = 1.2;
const double boxSize = 3.00646;
double tol = 1e-5;
ReferencePlatform reference;
System system;
NonbondedForce* nonbonded = new NonbondedForce();
nonbonded->setNonbondedMethod(NonbondedForce::Ewald);
nonbonded->setCutoffDistance(cutoff);
nonbonded->setEwaldErrorTolerance(tol);
for (int i = 0; i < numParticles/2; i++)
system.addParticle(22.99);
for (int i = 0; i < numParticles/2; i++)
system.addParticle(35.45);
for (int i = 0; i < numParticles/2; i++)
nonbonded->addParticle(1.0, 1.0,0.0);
for (int i = 0; i < numParticles/2; i++)
nonbonded->addParticle(-1.0, 1.0,0.0);
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
system.addForce(nonbonded);
vector<Vec3> positions(numParticles);
#include "nacl_amorph.dat"
if (includeExceptions) {
// Add some exclusions.
for (int i = 0; i < numParticles-1; i++) {
Vec3 delta = positions[i]-positions[i+1];
if (sqrt(delta.dot(delta)) < 0.5*cutoff)
nonbonded->addException(i, i+1, i%2 == 0 ? 0.0 : 0.5, 1.0, 0.0);
}
}
// (1) Check whether this matches the Reference platform when using Ewald Method
VerletIntegrator integrator1(0.01);
VerletIntegrator integrator2(0.01);
Context context(system, integrator1, platform);
Context referenceContext(system, integrator2, reference);
context.setPositions(positions);
referenceContext.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
State referenceState = referenceContext.getState(State::Forces | State::Energy);
tol = 1e-2;
for (int i = 0; i < numParticles; i++) {
ASSERT_EQUAL_VEC(referenceState.getForces()[i], state.getForces()[i], tol);
}
tol = 1e-5;
ASSERT_EQUAL_TOL(referenceState.getPotentialEnergy(), state.getPotentialEnergy(), tol);
if (!includeExceptions)
ASSERT_EQUAL_TOL(-3.82047e+05, state.getPotentialEnergy(), 1e-5); // Value from Gromacs
// (2) Check whether Ewald method is self-consistent
double norm = 0.0;
for (int i = 0; i < numParticles; ++i) {
Vec3 f = state.getForces()[i];
norm += f[0]*f[0] + f[1]*f[1] + f[2]*f[2];
}
norm = std::sqrt(norm);
const double delta = 5e-3;
double step = delta/norm;
for (int i = 0; i < numParticles; ++i) {
Vec3 p = positions[i];
Vec3 f = state.getForces()[i];
positions[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
}
VerletIntegrator integrator3(0.01);
Context context2(system, integrator3, platform);
context2.setPositions(positions);
tol = 1e-2;
State state2 = context2.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state.getPotentialEnergy())/delta, tol)
// (3) Check whether this matches the Reference platform when using PME
nonbonded->setNonbondedMethod(NonbondedForce::PME);
context.reinitialize();
referenceContext.reinitialize();
context.setPositions(positions);
referenceContext.setPositions(positions);
state = context.getState(State::Forces | State::Energy);
referenceState = referenceContext.getState(State::Forces | State::Energy);
tol = 1e-2;
for (int i = 0; i < numParticles; i++) {
ASSERT_EQUAL_VEC(referenceState.getForces()[i], state.getForces()[i], tol);
}
tol = 1e-5;
ASSERT_EQUAL_TOL(referenceState.getPotentialEnergy(), state.getPotentialEnergy(), tol);
if (!includeExceptions)
ASSERT_EQUAL_TOL(-3.82047e+05, state.getPotentialEnergy(), 1e-3); // Value from Gromacs
// (4) Check whether PME method is self-consistent
norm = 0.0;
for (int i = 0; i < numParticles; ++i) {
Vec3 f = state.getForces()[i];
norm += f[0]*f[0] + f[1]*f[1] + f[2]*f[2];
}
norm = std::sqrt(norm);
step = delta/norm;
for (int i = 0; i < numParticles; ++i) {
Vec3 p = positions[i];
Vec3 f = state.getForces()[i];
positions[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
}
VerletIntegrator integrator4(0.01);
Context context3(system, integrator4, platform);
context3.setPositions(positions);
tol = 1e-2;
State state3 = context3.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state3.getPotentialEnergy()-state.getPotentialEnergy())/delta, tol)
}
void testTriclinic() {
// Create a triclinic box containing eight particles.
System system;
system.setDefaultPeriodicBoxVectors(Vec3(2.5, 0, 0), Vec3(0.5, 3.0, 0), Vec3(0.7, 0.9, 3.5));
for (int i = 0; i < 8; i++)
system.addParticle(1.0);
NonbondedForce* force = new NonbondedForce();
system.addForce(force);
force->setNonbondedMethod(NonbondedForce::PME);
force->setCutoffDistance(1.0);
force->setPMEParameters(3.45891, 32, 40, 48);
for (int i = 0; i < 4; i++)
force->addParticle(-1, 0.440104, 0.4184); // Cl parameters
for (int i = 0; i < 4; i++)
force->addParticle(1, 0.332840, 0.0115897); // Na parameters
vector<Vec3> positions(8);
positions[0] = Vec3(1.744, 2.788, 3.162);
positions[1] = Vec3(1.048, 0.762, 2.340);
positions[2] = Vec3(2.489, 1.570, 2.817);
positions[3] = Vec3(1.027, 1.893, 3.271);
positions[4] = Vec3(0.937, 0.825, 0.009);
positions[5] = Vec3(2.290, 1.887, 3.352);
positions[6] = Vec3(1.266, 1.111, 2.894);
positions[7] = Vec3(0.933, 1.862, 3.490);
// Compute the forces and energy.
VerletIntegrator integ(0.001);
Context context(system, integ, platform);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
// Compare them to values computed by Gromacs.
double expectedEnergy = -963.370;
vector<Vec3> expectedForce(8);
expectedForce[0] = Vec3(4.25253e+01, -1.23503e+02, 1.22139e+02);
expectedForce[1] = Vec3(9.74752e+01, 1.68213e+02, 1.93169e+02);
expectedForce[2] = Vec3(-1.50348e+02, 1.29165e+02, 3.70435e+02);
expectedForce[3] = Vec3(9.18644e+02, -3.52571e+00, -1.34772e+03);
expectedForce[4] = Vec3(-1.61193e+02, 9.01528e+01, -7.12904e+01);
expectedForce[5] = Vec3(2.82630e+02, 2.78029e+01, -3.72864e+02);
expectedForce[6] = Vec3(-1.47454e+02, -2.14448e+02, -3.55789e+02);
expectedForce[7] = Vec3(-8.82195e+02, -7.39132e+01, 1.46202e+03);
for (int i = 0; i < 8; i++) {
ASSERT_EQUAL_VEC(expectedForce[i], state.getForces()[i], 1e-4);
}
ASSERT_EQUAL_TOL(expectedEnergy, state.getPotentialEnergy(), 1e-4);
}
void testErrorTolerance(NonbondedForce::NonbondedMethod method) {
// Create a cloud of random point charges.
const int numParticles = 51;
const double boxWidth = 5.0;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxWidth, 0, 0), Vec3(0, boxWidth, 0), Vec3(0, 0, boxWidth));
NonbondedForce* force = new NonbondedForce();
system.addForce(force);
vector<Vec3> positions(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.0);
force->addParticle(-1.0+i*2.0/(numParticles-1), 1.0, 0.0);
positions[i] = Vec3(boxWidth*genrand_real2(sfmt), boxWidth*genrand_real2(sfmt), boxWidth*genrand_real2(sfmt));
}
force->setNonbondedMethod(method);
// For various values of the cutoff and error tolerance, see if the actual error is reasonable.
for (double cutoff = 1.0; cutoff < boxWidth/2; cutoff *= 1.2) {
force->setCutoffDistance(cutoff);
vector<Vec3> refForces;
double norm = 0.0;
for (double tol = 5e-5; tol < 1e-3; tol *= 2.0) {
force->setEwaldErrorTolerance(tol);
VerletIntegrator integrator(0.01);
Context context(system, integrator, platform);
context.setPositions(positions);
State state = context.getState(State::Forces);
if (refForces.size() == 0) {
refForces = state.getForces();
for (int i = 0; i < numParticles; i++)
norm += refForces[i].dot(refForces[i]);
norm = sqrt(norm);
}
else {
double diff = 0.0;
for (int i = 0; i < numParticles; i++) {
Vec3 delta = refForces[i]-state.getForces()[i];
diff += delta.dot(delta);
}
diff = sqrt(diff)/norm;
ASSERT(diff < 2*tol);
}
if (method == NonbondedForce::PME) {
// See if the PME parameters were calculated correctly.
double expectedAlpha, actualAlpha;
int expectedSize[3], actualSize[3];
NonbondedForceImpl::calcPMEParameters(system, *force, expectedAlpha, expectedSize[0], expectedSize[1], expectedSize[2]);
force->getPMEParametersInContext(context, actualAlpha, actualSize[0], actualSize[1], actualSize[2]);
ASSERT_EQUAL_TOL(expectedAlpha, actualAlpha, 1e-5);
for (int i = 0; i < 3; i++) {
ASSERT(actualSize[i] >= expectedSize[i]);
ASSERT(actualSize[i] < expectedSize[i]+10);
}
}
}
}
}
void testPMEParameters() {
// Create a cloud of random point charges.
const int numParticles = 51;
const double boxWidth = 4.7;
System system;
system.setDefaultPeriodicBoxVectors(Vec3(boxWidth, 0, 0), Vec3(0, boxWidth, 0), Vec3(0, 0, boxWidth));
NonbondedForce* force = new NonbondedForce();
system.addForce(force);
vector<Vec3> positions(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numParticles; i++) {
system.addParticle(1.0);
force->addParticle(-1.0+i*2.0/(numParticles-1), 1.0, 0.0);
positions[i] = Vec3(boxWidth*genrand_real2(sfmt), boxWidth*genrand_real2(sfmt), boxWidth*genrand_real2(sfmt));
}
force->setNonbondedMethod(NonbondedForce::PME);
// Compute the energy with an error tolerance of 1e-3.
force->setEwaldErrorTolerance(1e-3);
VerletIntegrator integrator1(0.01);
Context context1(system, integrator1, platform);
context1.setPositions(positions);
double energy1 = context1.getState(State::Energy).getPotentialEnergy();
// Try again with an error tolerance of 1e-4.
force->setEwaldErrorTolerance(1e-4);
VerletIntegrator integrator2(0.01);
Context context2(system, integrator2, platform);
context2.setPositions(positions);
double energy2 = context2.getState(State::Energy).getPotentialEnergy();
// Now explicitly set the parameters. These should match the values that were
// used for tolerance 1e-3.
force->setPMEParameters(2.49291157051793, 32, 32, 32);
VerletIntegrator integrator3(0.01);
Context context3(system, integrator3, platform);
context3.setPositions(positions);
double energy3 = context3.getState(State::Energy).getPotentialEnergy();
ASSERT_EQUAL_TOL(energy1, energy3, 1e-6);
ASSERT(fabs((energy1-energy2)/energy1) > 1e-5);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testEwaldExact();
testEwaldPME(false);
testEwaldPME(true);
testTriclinic();
testErrorTolerance(NonbondedForce::Ewald);
testErrorTolerance(NonbondedForce::PME);
testPMEParameters();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "ReferencePlatform.h"
#include "openmm/GBSAOBCForce.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/NonbondedForce.h"
#include "SimTKOpenMMRealType.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testSingleParticle() {
System system;
system.addParticle(2.0);
LangevinIntegrator integrator(0, 0.1, 0.01);
GBSAOBCForce* gbsa = new GBSAOBCForce();
NonbondedForce* nonbonded = new NonbondedForce();
gbsa->addParticle(0.5, 0.15, 1);
nonbonded->addParticle(0.5, 1, 0);
system.addForce(gbsa);
system.addForce(nonbonded);
ASSERT(!gbsa->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(1);
positions[0] = Vec3(0, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Energy);
double bornRadius = 0.15-0.009; // dielectric offset
double eps0 = EPSILON0;
double bornEnergy = (-0.5*0.5/(8*PI_M*eps0))*(1.0/gbsa->getSoluteDielectric()-1.0/gbsa->getSolventDielectric())/bornRadius;
double extendedRadius = 0.15+0.14; // probe radius
double nonpolarEnergy = 4*PI_M*2.25936*extendedRadius*extendedRadius*std::pow(0.15/bornRadius, 6.0);
ASSERT_EQUAL_TOL((bornEnergy+nonpolarEnergy), state.getPotentialEnergy(), 0.01);
// Change the parameters and see if it is still correct.
gbsa->setParticleParameters(0, 0.4, 0.25, 1);
gbsa->updateParametersInContext(context);
state = context.getState(State::Energy);
bornRadius = 0.25-0.009; // dielectric offset
bornEnergy = (-0.4*0.4/(8*PI_M*eps0))*(1.0/gbsa->getSoluteDielectric()-1.0/gbsa->getSolventDielectric())/bornRadius;
extendedRadius = 0.25+0.14;
nonpolarEnergy = 4*PI_M*2.25936*extendedRadius*extendedRadius*std::pow(0.25/bornRadius, 6.0);
ASSERT_EQUAL_TOL((bornEnergy+nonpolarEnergy), state.getPotentialEnergy(), 0.01);
}
void testGlobalSettings() {
System system;
system.addParticle(2.0);
LangevinIntegrator integrator(0, 0.1, 0.01);
GBSAOBCForce* gbsa = new GBSAOBCForce();
gbsa->addParticle(0.5, 0.15, 1);
const double soluteDielectric = 2.1;
const double solventDielectric = 35.0;
const double surfaceAreaEnergy = 0.75;
gbsa->setSoluteDielectric(soluteDielectric);
gbsa->setSolventDielectric(solventDielectric);
gbsa->setSurfaceAreaEnergy(surfaceAreaEnergy);
system.addForce(gbsa);
ASSERT(!gbsa->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(1);
positions[0] = Vec3(0, 0, 0);
context.setPositions(positions);
State state = context.getState(State::Energy);
double bornRadius = 0.15-0.009; // dielectric offset
double eps0 = EPSILON0;
double bornEnergy = (-0.5*0.5/(8*PI_M*eps0))*(1.0/soluteDielectric-1.0/solventDielectric)/bornRadius;
double extendedRadius = 0.15+0.14; // probe radius
double nonpolarEnergy = 4*PI_M*surfaceAreaEnergy*extendedRadius*extendedRadius*std::pow(0.15/bornRadius, 6.0);
ASSERT_EQUAL_TOL((bornEnergy+nonpolarEnergy), state.getPotentialEnergy(), 0.01);
}
void testCutoffAndPeriodic() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
LangevinIntegrator integrator(0, 0.1, 0.01);
GBSAOBCForce* gbsa = new GBSAOBCForce();
NonbondedForce* nonbonded = new NonbondedForce();
gbsa->addParticle(-1, 0.15, 1);
nonbonded->addParticle(-1, 1, 0);
gbsa->addParticle(1, 0.15, 1);
nonbonded->addParticle(1, 1, 0);
const double cutoffDistance = 3.0;
const double boxSize = 10.0;
nonbonded->setCutoffDistance(cutoffDistance);
gbsa->setCutoffDistance(cutoffDistance);
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
system.addForce(gbsa);
system.addForce(nonbonded);
vector<Vec3> positions(2);
positions[0] = Vec3(0, 0, 0);
positions[1] = Vec3(2, 0, 0);
// Calculate the forces for both cutoff and periodic with two different atom positions.
nonbonded->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
gbsa->setNonbondedMethod(GBSAOBCForce::CutoffNonPeriodic);
ASSERT(!nonbonded->usesPeriodicBoundaryConditions());
ASSERT(!gbsa->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
context.setPositions(positions);
State state1 = context.getState(State::Forces);
nonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
gbsa->setNonbondedMethod(GBSAOBCForce::CutoffPeriodic);
ASSERT(nonbonded->usesPeriodicBoundaryConditions());
ASSERT(gbsa->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
context.reinitialize();
context.setPositions(positions);
State state2 = context.getState(State::Forces);
positions[1][0]+= boxSize;
nonbonded->setNonbondedMethod(NonbondedForce::CutoffNonPeriodic);
gbsa->setNonbondedMethod(GBSAOBCForce::CutoffNonPeriodic);
ASSERT(!nonbonded->usesPeriodicBoundaryConditions());
ASSERT(!gbsa->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
context.reinitialize();
context.setPositions(positions);
State state3 = context.getState(State::Forces);
nonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
gbsa->setNonbondedMethod(GBSAOBCForce::CutoffPeriodic);
ASSERT(nonbonded->usesPeriodicBoundaryConditions());
ASSERT(gbsa->usesPeriodicBoundaryConditions());
ASSERT(system.usesPeriodicBoundaryConditions());
context.reinitialize();
context.setPositions(positions);
State state4 = context.getState(State::Forces);
// All forces should be identical, exception state3 which should be zero.
ASSERT_EQUAL_VEC(state1.getForces()[0], state2.getForces()[0], 0.01);
ASSERT_EQUAL_VEC(state1.getForces()[1], state2.getForces()[1], 0.01);
ASSERT_EQUAL_VEC(state1.getForces()[0], state4.getForces()[0], 0.01);
ASSERT_EQUAL_VEC(state1.getForces()[1], state4.getForces()[1], 0.01);
ASSERT_EQUAL_VEC(state3.getForces()[0], Vec3(0, 0, 0), 0.01);
ASSERT_EQUAL_VEC(state3.getForces()[1], Vec3(0, 0, 0), 0.01);
}
void testForce(int numParticles, NonbondedForce::NonbondedMethod method, GBSAOBCForce::NonbondedMethod method2) {
ReferencePlatform reference;
System system;
GBSAOBCForce* gbsa = new GBSAOBCForce();
NonbondedForce* nonbonded = new NonbondedForce();
for (int i = 0; i < numParticles; ++i) {
system.addParticle(1.0);
double charge = i%2 == 0 ? -1 : 1;
gbsa->addParticle(charge, 0.15, 1);
nonbonded->addParticle(charge, 1, 0);
}
nonbonded->setNonbondedMethod(method);
gbsa->setNonbondedMethod(method2);
nonbonded->setCutoffDistance(3.0);
gbsa->setCutoffDistance(3.0);
int grid = (int) floor(0.5+pow(numParticles, 1.0/3.0));
if (method == NonbondedForce::CutoffPeriodic) {
double boxSize = (grid+1)*1.1;
system.setDefaultPeriodicBoxVectors(Vec3(boxSize, 0, 0), Vec3(0, boxSize, 0), Vec3(0, 0, boxSize));
}
system.addForce(gbsa);
system.addForce(nonbonded);
LangevinIntegrator integrator1(0, 0.1, 0.01);
LangevinIntegrator integrator2(0, 0.1, 0.01);
Context context(system, integrator1, platform);
Context refContext(system, integrator2, reference);
// Set random (but uniformly distributed) positions for all the particles.
vector<Vec3> positions(numParticles);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < grid; i++)
for (int j = 0; j < grid; j++)
for (int k = 0; k < grid; k++)
positions[i*grid*grid+j*grid+k] = Vec3(i*1.1, j*1.1, k*1.1);
for (int i = 0; i < numParticles; ++i)
positions[i] = positions[i] + Vec3(0.5*genrand_real2(sfmt), 0.5*genrand_real2(sfmt), 0.5*genrand_real2(sfmt));
context.setPositions(positions);
refContext.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
State refState = refContext.getState(State::Forces | State::Energy);
// Make sure this agrees with the Reference platform.
double norm = 0.0;
double diff = 0.0;
for (int i = 0; i < numParticles; ++i) {
Vec3 f = state.getForces()[i];
norm += f[0]*f[0] + f[1]*f[1] + f[2]*f[2];
Vec3 delta = f-refState.getForces()[i];
diff += delta[0]*delta[0] + delta[1]*delta[1] + delta[2]*delta[2];
}
norm = std::sqrt(norm);
diff = std::sqrt(diff);
ASSERT_EQUAL_TOL(0.0, diff, 0.001*norm);
ASSERT_EQUAL_TOL(state.getPotentialEnergy(), refState.getPotentialEnergy(), 1e-3);
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
// (This doesn't work with cutoffs, since the energy changes discontinuously at the cutoff distance.)
if (method == NonbondedForce::NoCutoff)
{
const double delta = 0.3;
double step = 0.5*delta/norm;
vector<Vec3> positions2(numParticles), positions3(numParticles);
for (int i = 0; i < numParticles; ++i) {
Vec3 p = positions[i];
Vec3 f = state.getForces()[i];
positions2[i] = Vec3(p[0]-f[0]*step, p[1]-f[1]*step, p[2]-f[2]*step);
positions3[i] = Vec3(p[0]+f[0]*step, p[1]+f[1]*step, p[2]+f[2]*step);
}
context.setPositions(positions2);
State state2 = context.getState(State::Energy);
context.setPositions(positions3);
State state3 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state3.getPotentialEnergy())/delta, 1e-2)
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testSingleParticle();
testGlobalSettings();
testCutoffAndPeriodic();
for (int i = 5; i < 11; i++) {
testForce(i*i*i, NonbondedForce::NoCutoff, GBSAOBCForce::NoCutoff);
testForce(i*i*i, NonbondedForce::CutoffNonPeriodic, GBSAOBCForce::CutoffNonPeriodic);
testForce(i*i*i, NonbondedForce::CutoffPeriodic, GBSAOBCForce::CutoffPeriodic);
}
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors.s *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/HarmonicAngleForce.h"
#include "openmm/System.h"
#include "openmm/VerletIntegrator.h"
#include "SimTKOpenMMRealType.h"
#include <iostream>
#include <vector>
using namespace OpenMM;
using namespace std;
const double TOL = 1e-5;
void testAngles() {
System system;
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
HarmonicAngleForce* forceField = new HarmonicAngleForce();
forceField->addAngle(0, 1, 2, PI_M/3, 1.1);
forceField->addAngle(1, 2, 3, PI_M/2, 1.2);
system.addForce(forceField);
ASSERT(!forceField->usesPeriodicBoundaryConditions());
ASSERT(!system.usesPeriodicBoundaryConditions());
Context context(system, integrator, platform);
vector<Vec3> positions(4);
positions[0] = Vec3(0, 1, 0);
positions[1] = Vec3(0, 0, 0);
positions[2] = Vec3(1, 0, 0);
positions[3] = Vec3(2, 1, 0);
context.setPositions(positions);
State state = context.getState(State::Forces | State::Energy);
{
const vector<Vec3>& forces = state.getForces();
double torque1 = 1.1*PI_M/6;
double torque2 = 1.2*PI_M/4;
ASSERT_EQUAL_VEC(Vec3(torque1, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(-0.5*torque2, 0.5*torque2, 0), forces[3], TOL); // reduced by sqrt(2) due to the bond length, another sqrt(2) due to the angle
ASSERT_EQUAL_VEC(Vec3(forces[0][0]+forces[1][0]+forces[2][0]+forces[3][0], forces[0][1]+forces[1][1]+forces[2][1]+forces[3][1], forces[0][2]+forces[1][2]+forces[2][2]+forces[3][2]), Vec3(0, 0, 0), TOL);
ASSERT_EQUAL_TOL(0.5*1.1*(PI_M/6)*(PI_M/6) + 0.5*1.2*(PI_M/4)*(PI_M/4), state.getPotentialEnergy(), TOL);
}
// Try changing the angle parameters and make sure it's still correct.
forceField->setAngleParameters(0, 0, 1, 2, PI_M/3.1, 1.3);
forceField->setAngleParameters(1, 1, 2, 3, PI_M/2.1, 1.4);
forceField->updateParametersInContext(context);
state = context.getState(State::Forces | State::Energy);
{
const vector<Vec3>& forces = state.getForces();
double dtheta1 = (PI_M/2)-(PI_M/3.1);
double dtheta2 = (3*PI_M/4)-(PI_M/2.1);
double torque1 = 1.3*dtheta1;
double torque2 = 1.4*dtheta2;
ASSERT_EQUAL_VEC(Vec3(torque1, 0, 0), forces[0], TOL);
ASSERT_EQUAL_VEC(Vec3(-0.5*torque2, 0.5*torque2, 0), forces[3], TOL); // reduced by sqrt(2) due to the bond length, another sqrt(2) due to the angle
ASSERT_EQUAL_VEC(Vec3(forces[0][0]+forces[1][0]+forces[2][0]+forces[3][0], forces[0][1]+forces[1][1]+forces[2][1]+forces[3][1], forces[0][2]+forces[1][2]+forces[2][2]+forces[3][2]), Vec3(0, 0, 0), TOL);
ASSERT_EQUAL_TOL(0.5*1.3*dtheta1*dtheta1 + 0.5*1.4*dtheta2*dtheta2, state.getPotentialEnergy(), TOL);
}
}
void runPlatformTests();
int main(int argc, char* argv[]) {
try {
initializeTests(argc, argv);
testAngles();
runPlatformTests();
}
catch(const exception& e) {
cout << "exception: " << e.what() << endl;
return 1;
}
cout << "Done" << endl;
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment