Commit d95e723d authored by Rossen Apostolov's avatar Rossen Apostolov
Browse files

Updated the Ewald/PME tests.

parent ed1fb192
...@@ -91,19 +91,21 @@ void testEwaldExact() { ...@@ -91,19 +91,21 @@ void testEwaldExact() {
// e : 1.6022 × 10−19 C // e : 1.6022 × 10−19 C
// 4*pi*epsilon0 : 1.112 × 10−10 C²/(J m) // 4*pi*epsilon0 : 1.112 × 10−10 C²/(J m)
// a0 : 0.282 x 10-9 m (perfect cell) // a0 : 0.282 x 10-9 m (perfect cell)
// Therefore //
double exactEnergy = -14.3061e-19; // J (per ion pair) // E is then the energy per pair of ions, so for our case
exactEnergy = -7.1531e-19; // J per ion // E has to be divided by 2 (per ion), multiplied by N(avogadro), multiplied by number of particles, and divided by 1000 for kJ
exactEnergy = -430.820; // kJ/mol per ion double exactEnergy = - (1.7476 * 1.6022e-19 * 1.6022e-19 * 6.02214e+23 * numParticles) / (1.112e-10 * 0.282e-9 * 2 * 1000);
ASSERT_EQUAL_TOL(exactEnergy * numParticles , state.getPotentialEnergy(), 100*TOL); ASSERT_EQUAL_TOL(exactEnergy, state.getPotentialEnergy(), 100*TOL);
// Gromacs result // cout << "exactEnergy: " << exactEnergy << endl;
// ASSERT_EQUAL_TOL(-430494.0, state.getPotentialEnergy(), 10*TOL); // cout << "PotentialEnergy: " << state.getPotentialEnergy() << endl;
} }
void testEwaldPME() { void testEwaldPME() {
// Use amorphoush NaCl system double tol = 1e-5;
// Use amorphous NaCl system
ReferencePlatform platform; ReferencePlatform platform;
const int numParticles = 216; const int numParticles = 216;
...@@ -132,13 +134,17 @@ void testEwaldPME() { ...@@ -132,13 +134,17 @@ void testEwaldPME() {
State state1 = context.getState(State::Forces | State::Energy); State state1 = context.getState(State::Forces | State::Energy);
const vector<Vec3>& forces1 = state1.getForces(); const vector<Vec3>& forces1 = state1.getForces();
// (1) CHECK EXACT VALUE OF EWALD ENERGY // for (int i = 0 ; i < numParticles ; i++)
// cout << "f [" << i << " : ]" << forces1[i] << endl;
// (1) CHECK EXACT VALUE OF EWALD ENERGY (Against Gromacs output)
ASSERT_EQUAL_TOL(-26651.9, state1.getPotentialEnergy(), TOL); tol = 1e-5;
ASSERT_EQUAL_TOL(-36687.5, state1.getPotentialEnergy(), tol);
// (2) CHECK WHETHER THE EWALD FORCES ARE THE SAME AS THE GROMACS OUTPUT // (2) CHECK WHETHER THE EWALD FORCES ARE THE SAME AS THE GROMACS OUTPUT
// Even at tolerance 0.1 the test doesn't pass
// #include "nacl_amorph_GromacsForcesEwald.dat" tol = 1e-3;
#include "nacl_amorph_GromacsForcesEwald.dat"
// (3) CHECK SELF-CONSISTENCY // (3) CHECK SELF-CONSISTENCY
...@@ -163,22 +169,28 @@ void testEwaldPME() { ...@@ -163,22 +169,28 @@ void testEwaldPME() {
// See whether the potential energy changed by the expected amount. // See whether the potential energy changed by the expected amount.
tol = 1e-4;
State state2 = context.getState(State::Energy); State state2 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state1.getPotentialEnergy())/delta, 0.01) ASSERT_EQUAL_TOL(norm, (state2.getPotentialEnergy()-state1.getPotentialEnergy())/delta, tol)
// (4) CHECK EXACT VALUE OF PME ENERGY // (4) CHECK EXACT VALUE OF PME ENERGY
nonbonded->setNonbondedMethod(NonbondedForce::PME); nonbonded->setNonbondedMethod(NonbondedForce::PME);
context.reinitialize(); context.reinitialize();
#include "nacl_amorph.dat" #include "nacl_amorph.dat"
context.setPositions(positions); context.setPositions(positions);
State state3 = context.getState(State::Forces | State::Energy); State state3 = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(-26651.9, state3.getPotentialEnergy(), 10*TOL); tol = 1e-5;
// Gromacs PME energy for the same mesh
ASSERT_EQUAL_TOL(-36688.3, state3.getPotentialEnergy(), tol);
// Gromacs Ewald energy
tol = 1e-4;
ASSERT_EQUAL_TOL(-36687.5, state3.getPotentialEnergy(), tol);
// (5) CHECK WHETHER PME FORCES ARE THE SAME AS THE GROMACS OUTPUT // (5) CHECK WHETHER PME FORCES ARE THE SAME AS THE GROMACS OUTPUT
// Even at tolerance 0.1 the test doesn't pass tol = 1e-3;
// #include "nacl_amorph_GromacsForcesEwald.dat" #include "nacl_amorph_GromacsForcesEwald.dat"
// (6) CHECK PME FOR SELF-CONSISTENCY // (6) CHECK PME FOR SELF-CONSISTENCY
...@@ -201,7 +213,8 @@ void testEwaldPME() { ...@@ -201,7 +213,8 @@ void testEwaldPME() {
// See whether the potential energy changed by the expected amount. // See whether the potential energy changed by the expected amount.
State state4 = context.getState(State::Energy); State state4 = context.getState(State::Energy);
ASSERT_EQUAL_TOL(norm, (state4.getPotentialEnergy()-state3.getPotentialEnergy())/delta, 0.01) tol = 1e-4;
ASSERT_EQUAL_TOL(norm, (state4.getPotentialEnergy()-state3.getPotentialEnergy())/delta, tol)
} }
......
This diff is collapsed.
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