11 #ifndef RD_FFCONVENIENCE_H
12 #define RD_FFCONVENIENCE_H
18 namespace ForceFieldsHelper {
20 #ifdef RDK_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)
continue;
34 for (
unsigned int aidx = 0; aidx < mol->
getNumAtoms(); ++aidx) {
35 ff.
positions()[aidx] = &(*cit)->getAtomPos(aidx);
38 int needsMore = ff.
minimize(maxIters);
40 (*res)[i] = std::make_pair(needsMore, e);
45 std::vector<std::pair<int, double>> &res,
46 int numThreads,
int maxIters) {
47 std::vector<std::thread> tg;
48 for (
int ti = 0; ti < numThreads; ++ti) {
49 tg.emplace_back(std::thread(detail::OptimizeMoleculeConfsHelper_, ff, &mol,
50 &res, ti, numThreads, maxIters));
52 for (
auto &thread : tg) {
53 if (thread.joinable()) thread.join();
59 std::vector<std::pair<int, double>> &res,
62 "res.size() must be >= mol.getNumConformers()");
66 for (
unsigned int aidx = 0; aidx < mol.
getNumAtoms(); ++aidx) {
67 ff.
positions()[aidx] = &(*cit)->getAtomPos(aidx);
70 int needsMore = ff.
minimize(maxIters);
72 res[i] = std::make_pair(needsMore, e);
90 int maxIters = 1000) {
94 return std::make_pair(res, e);
111 std::vector<std::pair<int, double>> &res,
112 int numThreads = 1,
int maxIters = 1000) {
115 if (numThreads == 1) {
118 #ifdef RDK_THREADSAFE_SSS
120 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)