Files
rdkit/Code/GraphMol/ForceFieldHelpers/catch_tests.cpp
Kevin Boyd af6347963f Condense MMFF Contribs into single contrib per type. (#8175)
* Condense MMFF electrostatics and contrib instances.

Previously, a separate contrib had been added for each common term.
Each of these required a separate allocation, and a separate dynamic dispatch
on call. This change moves to an SOA style, making data access contiguous and
drastically reducing the number of calls.

* Make suggested copyright fixes and svn artifact removals
2025-01-29 06:18:09 +01:00

55 lines
1.9 KiB
C++

//
// Copyright (C) 2024-2025 Niels Maeder and other RDKit contributors
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <cmath>
#include <RDGeneral/test.h>
#include <catch2/catch_all.hpp>
#include <GraphMol/SmilesParse/SmilesParse.h>
#include <ForceField/MMFF/Params.h>
#include <ForceField/MMFF/BondStretch.h>
#include "FFConvenience.h"
using namespace RDKit;
TEST_CASE("Test empty force field") {
auto mol =
"CCCO |(-1.28533,-0.0567758,0.434662;-0.175447,0.695786,-0.299881;0.918409,-0.342619,-0.555572;1.30936,-0.801512,0.71705)|"_smiles;
REQUIRE(mol);
SECTION("basics") {
auto forceField = ForceFieldsHelper::createEmptyForceFieldForMol(*mol);
REQUIRE(forceField);
forceField->initialize();
CHECK(forceField->minimize() == 0);
CHECK(forceField->calcEnergy() == 0.0);
REQUIRE(forceField->numPoints() == mol->getNumAtoms());
REQUIRE(forceField->positions().size() == mol->getNumAtoms());
auto dist = forceField->distance(0, 1);
auto pos1 = mol->getConformer().getAtomPos(0);
auto pos2 = mol->getConformer().getAtomPos(1);
CHECK(dist == (pos2 - pos1).length());
}
SECTION("add contrib and minimize") {
auto forceField = ForceFieldsHelper::createEmptyForceFieldForMol(*mol);
forceField->initialize();
auto params = ForceFields::MMFF::MMFFBond{6.0, 100.0};
auto *contrib = new ForceFields::MMFF::BondStretchContrib(forceField.get());
contrib->addTerm(0, 1, &params);
forceField->contribs().push_back(ForceFields::ContribPtr(contrib));
CHECK(forceField->minimize() == 0);
CHECK(std::round(forceField->distance(0, 1)) == 100);
auto pos1 = mol->getConformer().getAtomPos(0);
auto pos2 = mol->getConformer().getAtomPos(1);
auto dist = (pos2 - pos1).length();
CHECK(std::round(dist) == 100);
}
}