-
Notifications
You must be signed in to change notification settings - Fork 0
Ani numeric differentiation #5
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
base: ANI-Integration-Check
Are you sure you want to change the base?
Changes from all commits
e13a736
c59ace3
2445d20
7b8ff9b
d50c163
f3eb840
0276497
2f6ac7d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,8 +121,9 @@ 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)); | ||
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; | ||
} | ||
|
@@ -132,7 +133,39 @@ 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 { | ||
auto initEnergy = this->dp_forceField->calcEnergy(pos); | ||
|
||
// + - x movement | ||
pos[3 * this->d_atomIdx] += 1e-5; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make the displacement amount a const so that you don't have to keep repeating it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How did you pick the value There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I came up with 1e-5 with a little bit of experimentation. |
||
auto posXEnergy = this->dp_forceField->calcEnergy(pos); | ||
|
||
pos[3 * this->d_atomIdx] -= 2e-5; | ||
auto negXEnergy = this->dp_forceField->calcEnergy(pos); | ||
|
||
grad[3 * this->d_atomIdx] = (posXEnergy - negXEnergy) / (2e-5); | ||
pos[3 * this->d_atomIdx] += 1e-5; | ||
|
||
// + - Y movement | ||
pos[3 * this->d_atomIdx + 1] += 1e-5; | ||
auto posYEnergy = this->dp_forceField->calcEnergy(pos); | ||
|
||
pos[3 * this->d_atomIdx + 1] -= 2e-5; | ||
auto negYEnergy = this->dp_forceField->calcEnergy(pos); | ||
|
||
grad[3 * this->d_atomIdx + 1] = (posYEnergy - negYEnergy) / (2e-5); | ||
pos[3 * this->d_atomIdx + 1] += 1e-5; | ||
|
||
// + - Z movement | ||
pos[3 * this->d_atomIdx + 2] += 1e-5; | ||
auto posZEnergy = this->dp_forceField->calcEnergy(pos); | ||
|
||
pos[3 * this->d_atomIdx + 2] -= 2e-5; | ||
auto negZEnergy = this->dp_forceField->calcEnergy(pos); | ||
|
||
grad[3 * this->d_atomIdx + 2] = (posZEnergy - negZEnergy) / (2e-5); | ||
pos[3 * this->d_atomIdx + 2] += 1e-5; | ||
} | ||
|
||
namespace Utils { | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include <RDGeneral/export.h> | ||
#ifndef RD_ANICONVENIENCE_H_ | ||
#define RD_ANICONVENIENCE_H_ | ||
|
||
#include <ForceField/ForceField.h> | ||
#include <GraphMol/ForceFieldHelpers/FFConvenience.h> | ||
#include "Builder.h" | ||
|
||
namespace RDKit { | ||
class ROMol; | ||
namespace ANI { | ||
//! Convenience function for optimizing a molecule using ANI | ||
/* | ||
\param mol the molecule to use | ||
\param maxIters the maximum number of force-field iterations | ||
\param modelType Name of ANI style model (ANI-1x or ANI-1ccx) | ||
\param ensembleSize Number of Neural Networks inside the model | ||
\param confId the optional conformer id, if this isn't provided, the | ||
molecule's default confId will be used. | ||
|
||
\return a pair with: | ||
first: 0 if the optimization converged, 1 if more iterations are required. | ||
second: the energy | ||
*/ | ||
std::pair<int, double> ANIOptimizeMolecule(ROMol &mol, std::string modelType, | ||
unsigned int ensembleSize, | ||
int confId = -1, | ||
int maxIters = 1000) { | ||
ForceFields::ForceField *ff = | ||
ANI::constructForceField(mol, modelType, ensembleSize, confId); | ||
manangoel99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
std::pair<int, double> res = | ||
ForceFieldsHelper::OptimizeMolecule(*ff, maxIters); | ||
delete ff; | ||
manangoel99 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return res; | ||
} | ||
|
||
//! Convenience function for optimizing all of a molecule's conformations using | ||
// ANI | ||
/* | ||
\param mol the molecule to use | ||
\param res vector of (needsMore,energy) | ||
\param numThreads the number of simultaneous threads to use (only has an | ||
effect if the RDKit is compiled with thread support). | ||
If set to zero, the max supported by the system will be | ||
used. | ||
\param modelType Name of ANI style model (ANI-1x or ANI-1ccx) | ||
\param ensembleSize Number of Neural Networks inside the model | ||
*/ | ||
void ANIOptimizeMoleculeConfs(ROMol &mol, | ||
std::vector<std::pair<int, double>> &res, | ||
std::string modelType, unsigned int ensembleSize, | ||
int numThreads = 1, int maxIters = 1000) { | ||
ForceFields::ForceField *ff = | ||
ANI::constructForceField(mol, modelType, ensembleSize, -1); | ||
ForceFieldsHelper::OptimizeMoleculeConfs(mol, *ff, res, numThreads, maxIters); | ||
delete ff; | ||
} | ||
} // namespace ANI | ||
} // namespace RDKit | ||
|
||
#endif |
Uh oh!
There was an error while loading. Please reload this page.