Skip to content

Cookbook entry #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 32 commits into
base: ANI-Integration-Check
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
e13a736
Merge branch 'master' of https://github.com/rdkit/rdkit into ANI-Forw…
manangoel99 Aug 16, 2020
c59ace3
- Removed unnecessary array type casts to make AEV generation faster
manangoel99 Aug 16, 2020
2445d20
Implemented numeric differentiation of predicted energy by perturbing…
manangoel99 Aug 16, 2020
7b8ff9b
Changed documentation according to changes made
manangoel99 Aug 17, 2020
d50c163
- Added ANI Convenience functions
manangoel99 Aug 17, 2020
f3eb840
Merge branch 'ANI-Integration-Check' into ANI-NumericDifferentiation
manangoel99 Aug 17, 2020
0276497
Fixed error caused during merge conflict resolution
manangoel99 Aug 17, 2020
2f6ac7d
Minor edit in ANI ForceFieldHelper Test
manangoel99 Aug 17, 2020
5dbd514
Added cmake flag to build ANI components only when explicitly specified
manangoel99 Aug 19, 2020
b003e94
ANI Default build turned on
manangoel99 Aug 19, 2020
7fe8731
GraphMol Depedency added to ANI Descriptors
manangoel99 Aug 19, 2020
fcf75d6
Added ForceField dependency to ANIForceField Library
manangoel99 Aug 19, 2020
f50a35f
Added boost portable binary archive
manangoel99 Aug 20, 2020
578c605
Removed ANI weights from the repo
manangoel99 Aug 21, 2020
735c5fb
Merge Conflict Fix
manangoel99 Aug 21, 2020
e7de5e7
Fixed CMake to not generate ANI related functions on windows
manangoel99 Aug 22, 2020
cf80d5c
Added ANI Params folder to .gitignore
manangoel99 Aug 23, 2020
3998399
Added cookbook entry on how to use ANI convenience functions in python
manangoel99 Aug 23, 2020
d3cd327
Minor error fix in cookbook
manangoel99 Aug 23, 2020
080739b
Minor error fix in cookbook
manangoel99 Aug 23, 2020
003e93d
Added target compile definitions
manangoel99 Aug 24, 2020
7bd3acf
Merge branch 'ANI-CMakeFix' of https://github.com/manangoel99/rdkit i…
manangoel99 Aug 24, 2020
2bbf6e5
Minor error fix in cookbook
manangoel99 Aug 24, 2020
56f2623
Added python tests for ANI ForceFieldHelpers convenience functions
manangoel99 Aug 25, 2020
ca0256a
Merge branch 'master' of https://github.com/rdkit/rdkit into Cookbook…
manangoel99 Aug 25, 2020
91f7218
Updated entry number in cookbook
manangoel99 Aug 25, 2020
fdc5ffe
Merge branch 'ANI-Integration-Check' into CookbookEntry
manangoel99 Aug 25, 2020
c1f462f
Removed ANI Params stored by default so that they can be pulled from …
manangoel99 Aug 25, 2020
98b6812
Updated code to correct clang format
manangoel99 Aug 25, 2020
c259a81
Fix #3365 (#3366)
greglandrum Aug 26, 2020
f487861
Changed code to load weights from Data
manangoel99 Aug 28, 2020
4dd8f2e
Merge branch 'master' of https://github.com/rdkit/rdkit into Cookbook…
manangoel99 Aug 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ __pycache__/
/Code/GraphMol/SmilesParse/smiles.tab.cpp
/Code/GraphMol/SmilesParse/smiles.tab.hpp

/Data/ANIParams

/External/**/*.tar.gz
/External/**/*.zip
/External/catch/catch/
Expand Down
30 changes: 30 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ add_dependencies(rdkit_base catch)
option(RDK_BUILD_SWIG_WRAPPERS "build the SWIG wrappers" OFF )
option(RDK_BUILD_PYTHON_WRAPPERS "build the standard python wrappers" ON )
option(RDK_BUILD_COMPRESSED_SUPPLIERS "build in support for compressed MolSuppliers" OFF )
option(RDK_BUILD_ANI "build support for ANI style ForceField" OFF)
option(RDK_BUILD_INCHI_SUPPORT "build the rdkit inchi wrapper" OFF )
option(RDK_BUILD_AVALON_SUPPORT "install support for the avalon toolkit. Use the variable AVALONTOOLS_DIR to set the location of the source." OFF )
option(RDK_BUILD_PGSQL "build the PostgreSQL cartridge" OFF )
Expand Down Expand Up @@ -380,6 +381,35 @@ if(RDK_BUILD_DESCRIPTORS3D)
endif(EIGEN3_FOUND)
endif(RDK_BUILD_DESCRIPTORS3D)

if(RDK_BUILD_ANI)
find_package(Eigen3)
if(EIGEN3_FOUND)
set(RDK_HAS_EIGEN ON)
if(NOT WIN32)
target_compile_definitions(rdkit_base INTERFACE "-DRDK_HAS_EIGEN3" "-DRDK_BUILD_ANI")
target_link_libraries(rdkit_base INTERFACE Eigen3::Eigen)
set(ANIParamsDir "${CMAKE_CURRENT_SOURCE_DIR}/Data/ANIParams")
if(NOT EXISTS "${ANIParamsDir}/ANI-1x/selfEnergies")
set(RELEASE_NO "1.0")
downloadAndCheckMD5("https://github.com/rdkit/rdkit_ANI_weights/archive/v${RELEASE_NO}.tar.gz"
"${CMAKE_CURRENT_SOURCE_DIR}/ANIWeights-v${RELEASE_NO}.tar.gz" "")
execute_process(COMMAND ${CMAKE_COMMAND} -E tar zxf
${CMAKE_CURRENT_SOURCE_DIR}/ANIWeights-v${RELEASE_NO}.tar.gz
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
file(RENAME "${CMAKE_CURRENT_SOURCE_DIR}/rdkit_ANI_weights-${RELEASE_NO}/Params" "${CMAKE_CURRENT_SOURCE_DIR}/Data/ANIParams")
file(REMOVE_RECURSE "${CMAKE_CURRENT_SOURCE_DIR}/rdkit_ANI_weights-${RELEASE_NO}")
file(REMOVE "${CMAKE_CURRENT_SOURCE_DIR}/ANIWeights-v${RELEASE_NO}.tar.gz")
endif()
endif()
else(EIGEN3_FOUND)
message("Eigen3 not found, disabling the ANI build.")
set(RDK_BUILD_ANI OFF)
endif(EIGEN3_FOUND)
if(WIN32)
message("ANI not supported on Windows")
set(RDK_BUILD_ANI OFF)
endif(WIN32)
endif(RDK_BUILD_ANI)

find_package (Threads)
set(RDKit_THREAD_LIBS Threads::Threads)
Expand Down
58 changes: 50 additions & 8 deletions Code/ForceField/ANI/AtomicContrib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ ANIAtomContrib::ANIAtomContrib(ForceField *owner, int atomType,
// Different values for means of the gaussian symmetry functions
std::string path = getenv("RDBASE");
std::string paramFilePath =
path + "/Code/ForceField/ANI/Params/" + modelType + "/AEVParams/";
path + "/Data/ANIParams/" + modelType + "/AEVParams/";

// Weights for the radial symmetry functions
ArrayXd ShfR;
Expand Down Expand Up @@ -121,8 +121,10 @@ double ANIAtomContrib::forwardProp(ArrayXXd &aev) const {
}

double ANIAtomContrib::getEnergy(double *pos) const {
auto aev = RDKit::Descriptors::ANI::AtomicEnvironmentVector(
pos, this->d_speciesVec, this->d_numAtoms, &(this->d_aevParams));
PRECONDITION(pos != nullptr, "Positions array is NULL");
ArrayXXd aev;
RDKit::Descriptors::ANI::AtomicEnvironmentVector(
aev, pos, this->d_speciesVec, this->d_numAtoms, &(this->d_aevParams));
ArrayXXd row = aev.row(this->d_atomIdx);
return this->ANIAtomContrib::forwardProp(row) + this->d_selfEnergy;
}
Expand All @@ -132,7 +134,43 @@ double ANIAtomContrib::getEnergy(Eigen::ArrayXXd &aev) const {
return this->ANIAtomContrib::forwardProp(row) + this->d_selfEnergy;
}

void ANIAtomContrib::getGrad(double *pos, double *grad) const {}
void ANIAtomContrib::getGrad(double *pos, double *grad) const {
PRECONDITION(pos != nullptr, "Positions are null");
PRECONDITION(grad != nullptr, "Gradient array is null");
double displacement = 1e-5;

// + - x movement
pos[3 * this->d_atomIdx] += displacement;
auto posXEnergy = this->dp_forceField->calcEnergy(pos);

pos[3 * this->d_atomIdx] -= 2 * displacement;
auto negXEnergy = this->dp_forceField->calcEnergy(pos);

grad[3 * this->d_atomIdx] = (posXEnergy - negXEnergy) / (2 * displacement);
pos[3 * this->d_atomIdx] += displacement;

// + - Y movement
pos[3 * this->d_atomIdx + 1] += displacement;
auto posYEnergy = this->dp_forceField->calcEnergy(pos);

pos[3 * this->d_atomIdx + 1] -= 2 * displacement;
auto negYEnergy = this->dp_forceField->calcEnergy(pos);

grad[3 * this->d_atomIdx + 1] =
(posYEnergy - negYEnergy) / (2 * displacement);
pos[3 * this->d_atomIdx + 1] += displacement;

// + - Z movement
pos[3 * this->d_atomIdx + 2] += displacement;
auto posZEnergy = this->dp_forceField->calcEnergy(pos);

pos[3 * this->d_atomIdx + 2] -= 2 * displacement;
auto negZEnergy = this->dp_forceField->calcEnergy(pos);

grad[3 * this->d_atomIdx + 2] =
(posZEnergy - negZEnergy) / (2 * displacement);
pos[3 * this->d_atomIdx + 2] += displacement;
}

namespace Utils {

Expand All @@ -155,8 +193,9 @@ std::vector<std::string> tokenize(const std::string &s) {
void loadFromBin(std::vector<MatrixXd> *weights, unsigned int model,
std::string weightType, unsigned int layer,
std::string atomType, std::string modelType) {
PRECONDITION(weights != nullptr, "Vector of weights is NULL");
std::string path = getenv("RDBASE");
std::string paramFile = path + "/Code/ForceField/ANI/Params/" + modelType +
std::string paramFile = path + "/Data/ANIParams/" + modelType +
"/model" + std::to_string(model) + "/" + atomType +
"_" + std::to_string(layer) + "_" + weightType +
".bin";
Expand All @@ -168,8 +207,10 @@ void loadFromBin(std::vector<MatrixXd> *weights, unsigned int model,
void loadFromBin(std::vector<MatrixXd> *weights, std::vector<MatrixXd> *biases,
unsigned int model, std::string atomType,
std::string modelType) {
PRECONDITION(weights != nullptr, "Weights array is null");
PRECONDITION(biases != nullptr, "Biases array is null");
std::string path = getenv("RDBASE");
std::string paramFile = path + "/Code/ForceField/ANI/Params/" + modelType +
std::string paramFile = path + "/Data/ANIParams/" + modelType +
"/model" + std::to_string(model) + ".bin";
std::vector<MatrixXf> floatWeights, floatBiases;
RDNumeric::EigenSerializer::deserializeAll(&floatWeights, &floatBiases,
Expand All @@ -183,8 +224,9 @@ void loadFromBin(std::vector<MatrixXd> *weights, std::vector<MatrixXd> *biases,
void loadFromCSV(std::vector<MatrixXd> *weights, unsigned int model,
std::string weightType, unsigned int layer,
std::string atomType, std::string modelType) {
PRECONDITION(weights != nullptr, "Weights array is null");
std::string path = getenv("RDBASE");
std::string paramFile = path + "/Code/ForceField/ANI/Params/" + modelType +
std::string paramFile = path + "/Data/ANIParams/" + modelType +
"/model" + std::to_string(model) + "/" + atomType +
"_" + std::to_string(layer) + "_" + weightType;

Expand Down Expand Up @@ -227,7 +269,7 @@ void loadSelfEnergy(double *energy, std::string atomType,
std::string modelType) {
std::string path = getenv("RDBASE");
std::string filePath =
path + "/Code/ForceField/ANI/Params/" + modelType + "/selfEnergies";
path + "/Data/ANIParams/" + modelType + "/selfEnergies";

std::ifstream selfEnergyFile(filePath.c_str());
if (!selfEnergyFile.good()) {
Expand Down
4 changes: 2 additions & 2 deletions Code/ForceField/ANI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if(RDK_HAS_EIGEN)
if(RDK_BUILD_ANI)
rdkit_catch_test(ANIForceFieldCatchTest ANIForceField_catch.cpp catch_main.cpp
LINK_LIBRARIES
DistGeomHelpers ForceFieldHelpers
FileParsers MolTransforms SmilesParse
SubstructMatch MolAlign ANIDescriptors ANIForceField)
endif(RDK_HAS_EIGEN)
endif(RDK_BUILD_ANI)
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/AEVParams/EtaR.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/AEVParams/ShfA.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/AEVParams/ShfR.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/AEVParams/ShfZ.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/AEVParams/etaA.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/AEVParams/zeta.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model0.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model1.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model2.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model3.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model4.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model5.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model6.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1ccx/model7.bin
Binary file not shown.
4 changes: 0 additions & 4 deletions Code/ForceField/ANI/Params/ANI-1ccx/selfEnergies

This file was deleted.

Binary file removed Code/ForceField/ANI/Params/ANI-1x/AEVParams/EtaR.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/AEVParams/ShfA.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/AEVParams/ShfR.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/AEVParams/ShfZ.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/AEVParams/etaA.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/AEVParams/zeta.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model0.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model1.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model2.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model3.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model4.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model5.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model6.bin
Binary file not shown.
Binary file removed Code/ForceField/ANI/Params/ANI-1x/model7.bin
Binary file not shown.
4 changes: 0 additions & 4 deletions Code/ForceField/ANI/Params/ANI-1x/selfEnergies

This file was deleted.

15 changes: 8 additions & 7 deletions Code/ForceField/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ rdkit_library(ForceField
LINK_LIBRARIES Optimizer Trajectory)
target_compile_definitions(ForceField PRIVATE RDKIT_FORCEFIELD_BUILD)

if(RDK_HAS_EIGEN)
if(RDK_BUILD_ANI)
rdkit_library(ANIForceField
ANI/AtomicContrib.cpp
LINK_LIBRARIES Optimizer Trajectory ANIDescriptors EigenSerializer)
endif(RDK_HAS_EIGEN)
LINK_LIBRARIES Optimizer Trajectory ANIDescriptors EigenSerializer ForceField)
target_compile_definitions(ANIForceField PRIVATE RDKIT_ANIFORCEFIELD_BUILD)
endif(RDK_BUILD_ANI)

rdkit_headers(Contrib.h
ForceField.h DEST ForceField)
Expand Down Expand Up @@ -47,15 +48,15 @@ rdkit_headers(MMFF/AngleBend.h
MMFF/TorsionConstraint.h
MMFF/PositionConstraint.h
MMFF/Params.h DEST ForceField/MMFF)
if(RDK_HAS_EIGEN)
if(RDK_BUILD_ANI)
rdkit_headers(ANI/AtomicContrib.h DEST ForceField/ANI)
endif(RDK_HAS_EIGEN)
endif(RDK_BUILD_ANI)

add_subdirectory(UFF)
add_subdirectory(MMFF)
if(RDK_HAS_EIGEN)
if(RDK_BUILD_ANI)
add_subdirectory(ANI)
endif(RDK_HAS_EIGEN)
endif(RDK_BUILD_ANI)
if(RDK_BUILD_PYTHON_WRAPPERS)
add_subdirectory(Wrap)
endif()
9 changes: 8 additions & 1 deletion Code/ForceField/Wrap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
remove_definitions(-DRDKIT_FORCEFIELD_BUILD)
if(RDK_BUILD_ANI)
rdkit_python_extension(rdForceField ForceField.cpp
DEST ForceField
LINK_LIBRARIES ForceFieldHelpers ANIForceField)
LINK_LIBRARIES ForceFieldHelpers ANIForceField ANIForceFieldHelpers)
add_pytest(pyForceFieldANI ${CMAKE_CURRENT_SOURCE_DIR}/testANI.py)
else()
rdkit_python_extension(rdForceField ForceField.cpp
DEST ForceField
LINK_LIBRARIES ForceFieldHelpers)
endif(RDK_BUILD_ANI)
add_pytest(pyForceFieldConstraints ${CMAKE_CURRENT_SOURCE_DIR}/testConstraints.py)
add_pytest(pyForceFieldANI ${CMAKE_CURRENT_SOURCE_DIR}/testANI.py)
6 changes: 4 additions & 2 deletions Code/ForceField/Wrap/ForceField.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
#include <ForceField/MMFF/AngleConstraint.h>
#include <ForceField/MMFF/TorsionConstraint.h>
#include <ForceField/MMFF/PositionConstraint.h>
#ifdef RDK_BUILD_ANI
#include <ForceField/ANI/AtomicContrib.h>
#endif
#include "PyForceField.h"

using namespace ForceFields;
namespace python = boost::python;

#ifdef RDK_HAS_EIGEN3
#ifdef RDK_BUILD_ANI
void ANIAddAtomContrib(PyForceField *self, python::list speciesVec,
int atomType, unsigned int atomIdx,
unsigned int numAtoms, unsigned int numLayers,
Expand Down Expand Up @@ -428,7 +430,7 @@ BOOST_PYTHON_MODULE(rdForceField) {
(python::arg("self"), python::arg("idx"), python::arg("maxDispl"),
python::arg("forceConstant")),
"Adds a position constraint to the MMFF force field.")
#ifdef RDK_HAS_EIGEN3
#ifdef RDK_BUILD_ANI
.def("AddANIAtomContrib", ANIAddAtomContrib,
(python::arg("self"), python::arg("speciesVec"),
python::arg("atomType"), python::arg("atomIdx"),
Expand Down
Loading