11#ifndef RD_FFCONVENIENCE_H
12#define RD_FFCONVENIENCE_H
21#ifdef RDK_BUILD_THREADSAFE_SSS
22inline void OptimizeMoleculeConfsHelper_(
24 std::vector<std::pair<int, double>> *res,
unsigned int threadIdx,
25 unsigned int numThreads,
int maxIters) {
29 "res->size() must be >= mol->getNumConformers()");
34 if (i % numThreads != threadIdx) {
37 for (
unsigned int aidx = 0; aidx < mol->
getNumAtoms(); ++aidx) {
38 ff.
positions()[aidx] = &(*cit)->getAtomPos(aidx);
41 int needsMore = ff.
minimize(maxIters);
43 (*res)[i] = std::make_pair(needsMore, e);
47inline void OptimizeMoleculeConfsMT(
ROMol &mol,
49 std::vector<std::pair<int, double>> &res,
50 int numThreads,
int maxIters) {
51 std::vector<std::thread> tg;
52 for (
int ti = 0; ti < numThreads; ++ti) {
53 tg.emplace_back(std::thread(detail::OptimizeMoleculeConfsHelper_, ff, &mol,
54 &res, ti, numThreads, maxIters));
56 for (
auto &thread : tg) {
57 if (thread.joinable()) {
65 std::vector<std::pair<int, double>> &res,
68 "res.size() must be >= mol.getNumConformers()");
72 for (
unsigned int aidx = 0; aidx < mol.
getNumAtoms(); ++aidx) {
73 ff.
positions()[aidx] = &(*cit)->getAtomPos(aidx);
76 int needsMore = ff.
minimize(maxIters);
78 res[i] = std::make_pair(needsMore, e);
96 int maxIters = 1000) {
100 return std::make_pair(res, e);
117 std::vector<std::pair<int, double>> &res,
118 int numThreads = 1,
int maxIters = 1000) {
121 if (numThreads == 1) {
124#ifdef RDK_BUILD_THREADSAFE_SSS
126 detail::OptimizeMoleculeConfsMT(mol, ff, res, numThreads, maxIters);
139 ROMol &mol,
int confId = -1) {
140 auto res = std::make_unique<ForceFields::ForceField>();
142 for (
auto &pt : conf.getPositions()) {
143 res->positions().push_back(&pt);
#define PRECONDITION(expr, mess)
Defines the primary molecule class ROMol as well as associated typedefs.
A class to store forcefields and handle minimization.
double calcEnergy(std::vector< double > *contribs=nullptr) const
RDGeom::PointPtrVect & positions()
returns a reference to our points (a PointPtrVect)
void initialize()
does initialization
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
const Conformer & getConformer(int id=-1) const
ConformerIterator beginConformers()
ConformerIterator endConformers()
void OptimizeMoleculeConfsST(ROMol &mol, ForceFields::ForceField &ff, std::vector< std::pair< int, double > > &res, int maxIters)
void OptimizeMoleculeConfs(ROMol &mol, ForceFields::ForceField &ff, std::vector< std::pair< int, double > > &res, int numThreads=1, int maxIters=1000)
std::unique_ptr< ForceFields::ForceField > createEmptyForceFieldForMol(ROMol &mol, int confId=-1)
std::pair< int, double > OptimizeMolecule(ForceFields::ForceField &ff, int maxIters=1000)
unsigned int getNumThreadsToUse(int target)