Skip to content

ANI Backward Pass #3

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 43 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
43 commits
Select commit Hold shift + click to select a range
2a3867b
Complete implementation of constructing radial symmetry functions usi…
manangoel99 Jun 4, 2020
59a546d
Completed implementation of Radial and Angular AEV according to ANI-1…
manangoel99 Jun 5, 2020
4e03b97
Merge branch 'master' of https://github.com/rdkit/rdkit into ANI-Inte…
manangoel99 Jun 5, 2020
a6a2534
Complete implementation of ANI style featurization of molecules
manangoel99 Jun 6, 2020
4397761
Implemented python wrapper for SymmetryFunc and removed redundant com…
manangoel99 Jun 6, 2020
d5b89e3
Added documentation for SymmetryFunc and all it's helper functions in…
manangoel99 Jun 7, 2020
bedafc2
Code edited according to clang format
manangoel99 Jun 8, 2020
bd5d6cc
Corrected variable nomenclature to camelCase from snake_case
manangoel99 Jun 8, 2020
b9a0b39
- Changed cumsumFromZero to cumsum a generalized functions which take…
manangoel99 Jun 9, 2020
3be8ab3
Added function to calculate ANI AEVs from a flattened array of positions
manangoel99 Jun 12, 2020
15387c9
Changed some function calls to use pointers instead of copying the ar…
manangoel99 Jun 13, 2020
af2fbfe
Merge conflict resolution
manangoel99 Jun 13, 2020
2dd1927
Merge conflict fix
manangoel99 Jun 13, 2020
08fc9c3
Added new library ANIDescriptors to CMake to make sure ANI Descriptor…
manangoel99 Jun 16, 2020
74f2448
Merge branch 'master' of https://github.com/rdkit/rdkit into ANI-Forw…
manangoel99 Jun 16, 2020
80a3c05
Bug fixing in AEV featurization
manangoel99 Jun 17, 2020
1393b9f
Code clean up
manangoel99 Jun 17, 2020
881e6fd
Complete Forward propgation from AEVs to get energies by loading weig…
manangoel99 Jun 17, 2020
d4b93d9
Added support for ANI-1x and ANI-1ccx forward propogation including e…
manangoel99 Jun 18, 2020
ea10a2a
Implemented Eigen plugin to add serialize method to the Dense base cl…
manangoel99 Jun 21, 2020
378cc35
Complete forward propogation for finding atomic contributions to tota…
manangoel99 Jun 21, 2020
6d5a876
Added logic to throw error when an unsupported atom is present in the…
manangoel99 Jun 22, 2020
19c6b0f
Merge branch 'master' of https://github.com/rdkit/rdkit into ANI-Forw…
manangoel99 Jun 22, 2020
1752569
Complete Forward Progation step of ANI-1x and ANI-1ccx NNs
manangoel99 Jun 22, 2020
b854248
Merge branch 'master' of https://github.com/rdkit/rdkit into ANI-Forw…
manangoel99 Jun 22, 2020
8b8e911
Added more tests with data obtained from the QM7 dataset
manangoel99 Jun 23, 2020
b94b1b4
Added ForceFieldHelpers module for ANIForceField
manangoel99 Jun 23, 2020
1b74d26
Complete implementation of python wrappers for forward propogation th…
manangoel99 Jun 23, 2020
b5f721f
Added copyright notice to builder functions
manangoel99 Jun 24, 2020
d4d1ed4
- Refactored tests to use floating point comparisons provided by Catc…
manangoel99 Jul 7, 2020
bf9868d
- Changed generation of species vector to throw ValueErrorException w…
manangoel99 Jul 7, 2020
2d070ae
- Minor refactoring
manangoel99 Jul 7, 2020
9ddc6b3
- Overloaded serialize, deserialize and deserializeAll functions to a…
manangoel99 Jul 7, 2020
04f21b7
Merge branch 'master' of https://github.com/manangoel99/rdkit into AN…
manangoel99 Jul 7, 2020
cc6bcad
- Refactored ```ANI::AtomicContrib``` class to store weights at ```Ei…
manangoel99 Jul 13, 2020
3afe543
Merge branch 'master' of https://github.com/rdkit/rdkit into ANI-Forw…
manangoel99 Jul 14, 2020
d1460c8
Changed AEV params loading in ForceField initializtion
manangoel99 Jul 20, 2020
12c0e6d
Merge branch 'master' of https://github.com/rdkit/rdkit into ANI-Forw…
manangoel99 Jul 20, 2020
926877e
Added Parameters for generating AEVs
manangoel99 Jul 20, 2020
9fc8dff
Changed Boost serialized files to version 1.67 due to lack of backwar…
manangoel99 Jul 21, 2020
236d70d
Implemented backward prop from Energy to AEV and derivative of radial…
manangoel99 Jul 29, 2020
c6fbc71
Halfway Implementation of derivative of angular AEVs wrt input coordi…
manangoel99 Aug 4, 2020
cd3cc72
Incorrect implementation of derivatives of Angular and Radial parts o…
manangoel99 Aug 8, 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
466 changes: 466 additions & 0 deletions Code/ForceField/ANI/ANIForceField_catch.cpp

Large diffs are not rendered by default.

680 changes: 680 additions & 0 deletions Code/ForceField/ANI/AtomicContrib.cpp

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions Code/ForceField/ANI/AtomicContrib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
//
// Copyright (C) 2020 Manan Goel
//
// @@ 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 <RDGeneral/export.h>
#ifndef __RD_ANI_H__
#define __RD_ANI_H__

#include <ForceField/ForceField.h>
#include <ForceField/Contrib.h>

#ifdef RDK_HAS_EIGEN3
#include <Eigen/Dense>
#include <boost/tokenizer.hpp>
using namespace Eigen;

namespace ForceFields {
namespace ANI {

//! Atomic contribution term from Atomic Environment Vectors using ANI models
class RDKIT_FORCEFIELD_EXPORT ANIAtomContrib : public ForceFieldContrib {
public:
ANIAtomContrib(){};
//! Constructor
/*!
The contribution is found according to the AEV, atom type along with
hyperparameters and weights, biases of the nueral network

\param owner pointer to the owning ForceField
\param atomType ANI currently supports H.C, N and O
\param atomIdx index of atom in ForceField's positions
\param speciesVec vector with atom wise encoding
\param numAtoms number of atoms in the molecule
\param numLayers number of layers in the neural network
\param ensembleSize number of models in the ensemble
\param modelType model types like ANI-1x and ANI-1ccx
*/
ANIAtomContrib(ForceField *owner, int atomType, unsigned int atomIdx,
VectorXi &speciesVec, unsigned int numAtoms,
unsigned int numLayers, unsigned int ensembleSize,
std::string modelType);
double getEnergy(double *pos) const;
double getEnergy(Eigen::ArrayXXd &aev) const;
void getGrad(double *pos, double *grad) const;

/*!
Find atomic contribution according to atom's interactions with other atoms
by forward prpogation through the neural network

\param aev Atomic Environment Vector of the atom

\return Contribtution to the total energy of molecule according to
interactions
*/
double forwardProp(ArrayXXd &aev) const;

virtual ANIAtomContrib *copy() const { return new ANIAtomContrib(*this); };

private:
int d_atomType;
int d_atomIdx;
int d_numAtoms;
VectorXi d_speciesVec;
std::vector<std::vector<MatrixXd>> d_weights;
std::vector<std::vector<MatrixXd>> d_biases;
double d_selfEnergy;
unsigned int d_ensembleSize;
std::string d_modelType;
std::map<int, std::string> d_atomEncoding = {
{0, "H"}, {1, "C"}, {2, "N"}, {3, "O"}};
std::map<std::string, ArrayXXd> d_aevParams;
};

namespace Utils {
void AngularTerms_d(double cutoff, std::vector<ArrayXXd> &derivatives, ArrayXXd coordinates,
ArrayXXd &vectors12, unsigned int atomIdx, ArrayXXi &atomIndex12Angular, ArrayXXi centralAtomIndex,
const std::map<std::string, ArrayXXd> *params);
void RadialTerms_d(double cutoff, std::vector<ArrayXXd> &derivatives,
std::map<int, std::vector<int>> &addedMapping,
ArrayXXd &selectedCoordinates,
const std::map<std::string, Eigen::ArrayXXd> *params,
ArrayXXd &distances, ArrayXi &atomIndex12,
unsigned int atomIdx);
//! CELU activation function
/*!
Continuously Differentiable Exponential Linear Unit Activation function
\param input Vector from hidden layer
\param alpha hyperparameter for CELU
*/
void CELU(MatrixXd &input, double alpha);

void CELUGrad(MatrixXd &input, double alpha);

/*!
Load model weights from CSV file
\param weights Pointer to array of weights of neural network
\param model Index of model in the ensemble
\param weightType Type of weights "weight" or "bias"
\param layer Index of layer of NN
\param atomType Atomic Symbol of atom
\param modelType Architecture being used
*/
void loadFromCSV(std::vector<MatrixXd> *weights, unsigned int model,
std::string weightType, unsigned int layer,
std::string atomType, std::string modelType);

/*!
Load model weights boost serialized files
\param weights Pointer to array of weights of neural network
\param model Index of model in the ensemble
\param weightType Type of weights "weight" or "bias"
\param layer Index of layer of NN
\param atomType Atomic Symbol of atom
\param modelType Architecture being used
*/
void loadFromBin(std::vector<MatrixXd> *weights, unsigned int model,
std::string weightType, unsigned int layer,
std::string atomType, std::string modelType);

/*!
Load all model weights from a single boost serialized file
\param weights Pointer to array of weights of neural network
\param biases Pointer to array of biases of neural network
\param model Index of model in the ensemble
\param atomType Atomic Symbol of atom
\param modelType Architecture being used
*/
void loadFromBin(std::vector<MatrixXd> *weights, std::vector<MatrixXd> *biases,
unsigned int model, std::string atomType,
std::string modelType);

//! Load self energy of atom from modelType/selfEnergies file
void loadSelfEnergy(double *energy, std::string atomType,
std::string modelType);

std::vector<std::string> tokenize(const std::string &s);

} // namespace Utils
} // namespace ANI
} // namespace ForceFields
#endif
#endif
7 changes: 7 additions & 0 deletions Code/ForceField/ANI/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
if(RDK_HAS_EIGEN)
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)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model0.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model1.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model2.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model3.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model4.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model5.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model6.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1ccx/model7.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions Code/ForceField/ANI/Params/ANI-1ccx/selfEnergies
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
H,0=-0.5991501324919538
C,1=-38.03750806057356
N,2=-54.67448347695333
O,3=-75.16043537275567
Binary file not shown.
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/AEVParams/ShfR.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/AEVParams/ShfZ.bin
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model0.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model1.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model2.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model3.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model4.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model5.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model6.bin
Binary file not shown.
Binary file added Code/ForceField/ANI/Params/ANI-1x/model7.bin
Binary file not shown.
4 changes: 4 additions & 0 deletions Code/ForceField/ANI/Params/ANI-1x/selfEnergies
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
H,0=-0.600952980000
C,1=-38.08316124000
N,2=-54.70775770000
O,3=-75.19446356000
12 changes: 12 additions & 0 deletions Code/ForceField/ANI/catch_main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Copyright (C) 2020 Manan Goel
// @@ 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.
//

#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do
// this in one cpp file
#include "catch.hpp"
12 changes: 12 additions & 0 deletions Code/ForceField/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ rdkit_library(ForceField
MMFF/Params.cpp
LINK_LIBRARIES Optimizer Trajectory)

if(RDK_HAS_EIGEN)
rdkit_library(ANIForceField
ANI/AtomicContrib.cpp
LINK_LIBRARIES Optimizer Trajectory ANIDescriptors EigenSerializer)
endif(RDK_HAS_EIGEN)

rdkit_headers(Contrib.h
ForceField.h DEST ForceField)

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

add_subdirectory(UFF)
add_subdirectory(MMFF)
if(RDK_HAS_EIGEN)
add_subdirectory(ANI)
endif(RDK_HAS_EIGEN)
if(RDK_BUILD_PYTHON_WRAPPERS)
add_subdirectory(Wrap)
endif()
3 changes: 2 additions & 1 deletion Code/ForceField/Wrap/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
remove_definitions(-DRDKIT_FORCEFIELD_BUILD)
rdkit_python_extension(rdForceField ForceField.cpp
DEST ForceField
LINK_LIBRARIES ForceFieldHelpers )
LINK_LIBRARIES ForceFieldHelpers ANIForceField)
add_pytest(pyForceFieldConstraints ${CMAKE_CURRENT_SOURCE_DIR}/testConstraints.py)
add_pytest(pyForceFieldANI ${CMAKE_CURRENT_SOURCE_DIR}/testANI.py)
Loading