Skip to content

Commit

Permalink
Add MMFF94s tests and MMFF94 + dielectric constant unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ghutchis committed Sep 2, 2019
1 parent 3a8126f commit 166b7bd
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 18 deletions.
2 changes: 1 addition & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ set(origtests
unitcell
)
set (atom_parts 1 2 3 4)
set (ffmmff94_parts 1 2)
set (ffmmff94_parts 1 2 3 4 5 6)
set (math_parts 1 2 3 4)
set (pdbreadfile_parts 1 2 3 4)

Expand Down
59 changes: 42 additions & 17 deletions test/ffmmff94.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
Some portions Copyright (C) 2008 Geoffrey R. Hutchison
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Expand Down Expand Up @@ -40,7 +40,7 @@ using namespace OpenBabel;

int currentTest = 0;

void GenerateEnergies(string molecules_file, string results_file)
void GenerateEnergies(string molecules_file, string results_file, string method, double epsilon = 1.0)
{
std::ifstream ifs;
if (!SafeOpen(ifs, molecules_file.c_str()))
Expand All @@ -53,18 +53,19 @@ void GenerateEnergies(string molecules_file, string results_file)
OBMol mol;
OBConversion conv(&ifs, &cout);
char buffer[BUFF_SIZE];

if(! conv.SetInAndOutFormats("SDF","SDF"))
{
cerr << "SDF format is not loaded" << endl;
return;
}

OBForceField* pFF = OBForceField::FindForceField("MMFF94");
OBForceField* pFF = OBForceField::FindForceField(method);
OB_REQUIRE(pFF != NULL);

pFF->SetLogFile(&cout);
pFF->SetLogLevel(OBFF_LOGLVL_NONE);
pFF->SetDielectricConstant(epsilon);

for (;ifs;)
{
Expand All @@ -77,7 +78,7 @@ void GenerateEnergies(string molecules_file, string results_file)
cerr << "Could not setup force field on molecule: " << mol.GetTitle() << endl;
return;
}

// Don't compute gradients
sprintf(buffer, "%15.5f\n", pFF->Energy(false));
ofs << buffer;
Expand All @@ -87,7 +88,7 @@ void GenerateEnergies(string molecules_file, string results_file)
return;
}

void TestFile(string filename, string results_file)
void TestFile(string filename, string results_file, string method, double epsilon = 1.0)
{
std::ifstream mifs;
if (!SafeOpen(mifs, filename.c_str()))
Expand All @@ -113,12 +114,13 @@ void TestFile(string filename, string results_file)
cout << "Bail out! SDF format is not loaded" << endl;
return;
}
OBForceField* pFF = OBForceField::FindForceField("MMFF94");

OBForceField* pFF = OBForceField::FindForceField(method);
OB_REQUIRE(pFF != NULL);

pFF->SetLogFile(&cout);
pFF->SetLogLevel(OBFF_LOGLVL_NONE);
pFF->SetDielectricConstant(epsilon);

double energy;
while(mifs)
Expand All @@ -132,7 +134,7 @@ void TestFile(string filename, string results_file)
cout << "Bail out! error reading reference data" << endl;
return;
}

if (!pFF->Setup(mol)) {
cout << "Bail out! could not setup force field on " << mol.GetTitle() << endl;
return;
Expand Down Expand Up @@ -164,7 +166,7 @@ void TestFile(string filename, string results_file)
int ffmmff94(int argc, char* argv[])
{
int defaultchoice = 1;

int choice = defaultchoice;

if (argc > 1) {
Expand All @@ -174,22 +176,46 @@ int ffmmff94(int argc, char* argv[])
}
}

string testdatadir = TESTDATADIR;

if (choice == 99)
{
GenerateEnergies(testdatadir + "forcefield.sdf", testdatadir + "mmff94results.txt", "MMFF94");
GenerateEnergies(testdatadir + "more-mmff94.sdf", testdatadir + "more-mmff94results.txt", "MMFF94"); // provided by Paolo Tosco
GenerateEnergies(testdatadir + "forcefield.sdf", testdatadir + "mmff94sresults.txt", "MMFF94s");
GenerateEnergies(testdatadir + "more-mmff94.sdf", testdatadir + "more-mmff94sresults.txt", "MMFF94s"); // ditto
GenerateEnergies(testdatadir + "forcefield.sdf", testdatadir + "mmff94e4results.txt", "MMFF94", 4.0);
GenerateEnergies(testdatadir + "more-mmff94.sdf", testdatadir + "more-mmff94e4results.txt", "MMFF94", 4.0); // provided by Paolo Tosco

return 0;
}

// Define location of file formats for testing
#ifdef FORMATDIR
char env[BUFF_SIZE];
snprintf(env, BUFF_SIZE, "BABEL_LIBDIR=%s", FORMATDIR);
putenv(env);
#endif

string testdatadir = TESTDATADIR;
#endif

cout << "# Testing MMFF94 Force Field..." << endl;
switch(choice) {
case 1:
TestFile(testdatadir + "forcefield.sdf", testdatadir + "mmff94results.txt");
TestFile(testdatadir + "forcefield.sdf", testdatadir + "mmff94results.txt", "MMFF94");
break;
case 2:
TestFile(testdatadir + "more-mmff94.sdf", testdatadir + "more-mmff94results.txt"); // provided by Paolo Tosco
TestFile(testdatadir + "more-mmff94.sdf", testdatadir + "more-mmff94results.txt", "MMFF94"); // provided by Paolo Tosco
break;
case 3:
TestFile(testdatadir + "forcefield.sdf", testdatadir + "mmff94sresults.txt", "MMFF94s");
break;
case 4:
TestFile(testdatadir + "more-mmff94.sdf", testdatadir + "more-mmff94sresults.txt", "MMFF94s"); // ditto
break;
case 5:
TestFile(testdatadir + "forcefield.sdf", testdatadir + "mmff94e4results.txt", "MMFF94", 4.0);
break;
case 6:
TestFile(testdatadir + "more-mmff94.sdf", testdatadir + "more-mmff94e4sresults.txt", "MMFF94", 4.0);
break;
default:
cout << "Test number " << choice << " does not exist!\n";
Expand All @@ -199,4 +225,3 @@ int ffmmff94(int argc, char* argv[])
// Passed tests
return 0;
}

18 changes: 18 additions & 0 deletions test/files/mmff94e4results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
81.07932
2.91283
-3.69683
4.24811
21.22882
118.74484
105.47746
20.86046
1207.63670
-0.14958
100.53756
82.09361
64.68310
81.07932
316.34690
35.71481
44.77390
72.62709
18 changes: 18 additions & 0 deletions test/files/mmff94sresults.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
68.11491
8.64766
-28.35351
-2.84895
21.22882
118.74484
79.03067
18.04199
1207.63670
-113.74578
112.23600
107.75248
93.43627
68.11491
312.57114
19.17321
39.99337
14.10039
8 changes: 8 additions & 0 deletions test/files/more-mmff94e4results.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
69.34483
11.26353
3.80210
-2.68512
16.18134
35.18203
-2.57316
62.69012
8 changes: 8 additions & 0 deletions test/files/more-mmff94sresults.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
122.63436
-32.54562
-78.13560
-86.79596
-30.86445
95.98183
-156.37352
204.36981

0 comments on commit 166b7bd

Please sign in to comment.