11 #ifndef RD_FFCONVENIENCE_H
12 #define RD_FFCONVENIENCE_H
18 namespace ForceFieldsHelper {
20 #ifdef RDK_BUILD_THREADSAFE_SSS
22 std::vector<std::pair<int, double>> *res,
23 unsigned int threadIdx,
24 unsigned int numThreads,
int maxIters) {
28 "res->size() must be >= mol->getNumConformers()");
33 if (i % numThreads != threadIdx) {
36 for (
unsigned int aidx = 0; aidx < mol->
getNumAtoms(); ++aidx) {
37 ff.
positions()[aidx] = &(*cit)->getAtomPos(aidx);
40 int needsMore = ff.
minimize(maxIters);
42 (*res)[i] = std::make_pair(needsMore, e);
47 std::vector<std::pair<int, double>> &res,
48 int numThreads,
int maxIters) {
49 std::vector<std::thread> tg;
50 for (
int ti = 0; ti < numThreads; ++ti) {
51 tg.emplace_back(std::thread(detail::OptimizeMoleculeConfsHelper_, ff, &mol,
52 &res, ti, numThreads, maxIters));
54 for (
auto &thread : tg) {
55 if (thread.joinable()) {
63 std::vector<std::pair<int, double>> &res,
66 "res.size() must be >= mol.getNumConformers()");
70 for (
unsigned int aidx = 0; aidx < mol.
getNumAtoms(); ++aidx) {
71 ff.
positions()[aidx] = &(*cit)->getAtomPos(aidx);
74 int needsMore = ff.
minimize(maxIters);
76 res[i] = std::make_pair(needsMore, e);
94 int maxIters = 1000) {
98 return std::make_pair(res, e);
115 std::vector<std::pair<int, double>> &res,
116 int numThreads = 1,
int maxIters = 1000) {
119 if (numThreads == 1) {
122 #ifdef RDK_BUILD_THREADSAFE_SSS
124 detail::OptimizeMoleculeConfsMT(mol, ff, res, numThreads, maxIters);
#define PRECONDITION(expr, mess)
A class to store forcefields and handle minimization.
double calcEnergy(std::vector< double > *contribs=nullptr) const
void initialize()
does initialization
RDGeom::PointPtrVect & positions()
returns a reference to our points (a PointPtrVect)
int minimize(unsigned int snapshotFreq, RDKit::SnapshotVect *snapshotVect, unsigned int maxIts=200, double forceTol=1e-4, double energyTol=1e-6)
minimizes the energy of the system by following gradients
unsigned int getNumConformers() const
unsigned int getNumAtoms() const
returns our number of atoms
ConformerIterator beginConformers()
ConformerIterator endConformers()
void OptimizeMoleculeConfsST(ROMol &mol, ForceFields::ForceField &ff, std::vector< std::pair< int, double >> &res, int maxIters)
std::pair< int, double > OptimizeMolecule(ForceFields::ForceField &ff, int maxIters=1000)
void OptimizeMoleculeConfs(ROMol &mol, ForceFields::ForceField &ff, std::vector< std::pair< int, double >> &res, int numThreads=1, int maxIters=1000)
unsigned int getNumThreadsToUse(int target)