Skip to content

Commit

Permalink
Issue schrodinger#52: Add a test that templates are used
Browse files Browse the repository at this point in the history
Adds a test that when coordgen is run on the template files,
the templates are actually used. Does this by reading the
template files into molecules and then running
generateCoordinates(). It looks like the template matching code
adds the "rigid" property to any atom that had matched a
template, so that's what is checked here.
  • Loading branch information
d-b-w committed Feb 14, 2020
1 parent dd13806 commit f769d40
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ target_link_libraries(test_coordgen coordgen ${maeparser_LIBRARIES} ${boost_link
# Set the path for the input files
get_filename_component(TEST_SAMPLES_PATH ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE)
target_compile_definitions(test_coordgen PRIVATE "TEST_SAMPLES_PATH=\"${TEST_SAMPLES_PATH}\"")
target_compile_definitions(test_coordgen PRIVATE "SOURCE_DIR=\"${PROJECT_SOURCE_DIR}\"")

add_test(NAME test_coordgen COMMAND ${CMAKE_BINARY_DIR}/test/test_coordgen
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/test)
62 changes: 61 additions & 1 deletion test/test_coordgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

#include <boost/filesystem.hpp>
#include <boost/test/unit_test.hpp>
#include <unordered_set>

#include "../sketcherMinimizer.h"
#include "../sketcherMinimizerMaths.h"

#include "maeparser/MaeConstants.hpp"
#include "maeparser/Reader.hpp"

using std::unordered_set;
using namespace schrodinger;

const boost::filesystem::path test_samples_path(TEST_SAMPLES_PATH);
Expand Down Expand Up @@ -50,7 +52,9 @@ bool areBondsNearIdeal(sketcherMinimizerMolecule& mol,

return passed;
}
}

} // unnamed namespace


BOOST_AUTO_TEST_CASE(SampleTest)
{
Expand Down Expand Up @@ -83,3 +87,59 @@ BOOST_AUTO_TEST_CASE(SampleTest)
auto indices = getReportingIndices(*mol);
BOOST_CHECK(areBondsNearIdeal(*mol, indices));
}


BOOST_AUTO_TEST_CASE(TemplateTest)
{
///
// Do the structures in the templates file get the same coordinates that
// were supplied in the templates file?

const boost::filesystem::path source_dir(SOURCE_DIR);
const std::string templates_file = (source_dir / "templates.mae").string();

// Known issues. See issue #52
const unordered_set<size_t> no_match = {1, 8, 19, 20, 22, 32, 43, 53, 65, 66, 67};
// 32 is odd. minimization removes atoms?? But it matches??
const unordered_set<size_t> match_incorrectly = {18, 27};

mae::Reader r(templates_file);
std::shared_ptr<mae::Block> b;
size_t template_index = 0;
while ((b = r.next(mae::CT_BLOCK)) != nullptr) {
if (no_match.count(template_index) > 0 || template_index != 32) {
++template_index;
continue;
}

auto* mol = mol_from_mae_block(*b);
BOOST_REQUIRE(mol != nullptr);
const auto original_atom_count = mol->getAtoms().size();

sketcherMinimizer minimizer;
minimizer.setTemplateFileDir(source_dir.string());

minimizer.initialize(mol); // minimizer takes ownership of mol
minimizer.runGenerateCoordinates();

BOOST_CHECK_EQUAL(original_atom_count, mol->getAtoms().size());

bool any_rigid = false;
bool all_rigid = true;
for (auto a: mol->getAtoms()) {
if (a->rigid) {
any_rigid = true;
} else {
all_rigid = false;
}
}
const bool matches_incorrectly = match_incorrectly.count(template_index) > 0;
if (matches_incorrectly) {
BOOST_CHECK_MESSAGE(any_rigid, "No template found for " << template_index);
} else {
BOOST_CHECK_MESSAGE(all_rigid, "Not all atoms templated for " << template_index);
}

++template_index;
}
}

0 comments on commit f769d40

Please sign in to comment.