11 #ifndef _RD_O3AALIGNMOLECULES_H_
12 #define _RD_O3AALIGNMOLECULES_H_
24 #include <boost/shared_ptr.hpp>
25 #include <boost/multi_array.hpp>
26 #include <boost/dynamic_bitset.hpp>
40 return ((x < 1.0e-10) && (x > -1.0e-10));
43 class O3AConstraintVect;
59 unsigned int d_prbIdx;
60 unsigned int d_refIdx;
73 void append(
unsigned int prbIdx,
unsigned int refIdx,
double weight) {
75 o3aConstraint->d_idx = d_count;
76 o3aConstraint->d_prbIdx = prbIdx;
77 o3aConstraint->d_refIdx = refIdx;
78 o3aConstraint->d_weight = weight;
79 d_o3aConstraintVect.emplace_back(o3aConstraint);
80 std::sort(d_o3aConstraintVect.begin(), d_o3aConstraintVect.end(),
81 d_compareO3AConstraint);
84 std::vector<boost::shared_ptr<O3AConstraint>>::size_type
size() {
85 return d_o3aConstraintVect.size();
88 return d_o3aConstraintVect[i].get();
92 unsigned int d_count{0};
93 std::vector<boost::shared_ptr<O3AConstraint>> d_o3aConstraintVect;
94 static bool d_compareO3AConstraint(boost::shared_ptr<O3AConstraint> a,
95 boost::shared_ptr<O3AConstraint> b) {
97 (a->d_prbIdx != b->d_prbIdx)
98 ? (a->d_prbIdx < b->d_prbIdx)
99 : ((a->d_refIdx != b->d_refIdx)
100 ? (a->d_refIdx < b->d_refIdx)
101 : ((a->d_weight != b->d_weight) ? (a->d_weight > b->d_weight)
102 : (a->d_idx < b->d_idx))));
135 inline int get(
const unsigned int y,
const unsigned int x)
const {
136 PRECONDITION(y < d_h.shape()[0],
"Invalid index on MolHistogram");
137 PRECONDITION(x < d_h.shape()[1],
"Invalid index on MolHistogram");
142 boost::multi_array<int, 2> d_h;
156 d_cost(
boost::extents[dim][dim]){};
158 int getCost(
const unsigned int i,
const unsigned int j) {
159 PRECONDITION(i < d_cost.shape()[0],
"Invalid index on LAP.cost");
160 PRECONDITION(j < d_cost.shape()[1],
"Invalid index on LAP.cost");
164 PRECONDITION(i < d_rowSol.size(),
"Invalid index on LAP.rowSol");
171 int (*costFunc)(
const unsigned int,
const unsigned int,
176 std::vector<int> d_rowSol;
177 std::vector<int> d_colSol;
178 std::vector<int> d_free;
179 std::vector<int> d_colList;
180 std::vector<int> d_matches;
181 std::vector<int> d_d;
182 std::vector<int> d_v;
183 std::vector<int> d_pred;
184 boost::multi_array<int, 2> d_cost;
192 : d_prbConf(prbConf),
194 d_o3aConstraintVect(o3aConstraintVect){};
197 : d_prbConf(other.d_prbConf),
198 d_refConf(other.d_refConf),
199 d_o3aConstraintVect(other.d_o3aConstraintVect),
200 d_SDMPtrVect(other.d_SDMPtrVect.size()) {
201 for (
unsigned int i = 0; i < d_SDMPtrVect.size(); ++i) {
202 d_SDMPtrVect[i] = boost::shared_ptr<SDMElement>(
new SDMElement());
203 memcpy(d_SDMPtrVect[i].get(), other.d_SDMPtrVect[i].get(),
209 if (
this == &other)
return *
this;
210 d_prbConf = other.d_prbConf;
211 d_refConf = other.d_refConf;
212 d_o3aConstraintVect = other.d_o3aConstraintVect;
213 d_SDMPtrVect.resize(other.d_SDMPtrVect.size());
214 for (
unsigned int i = 0; i < d_SDMPtrVect.size(); ++i) {
215 d_SDMPtrVect[i] = boost::shared_ptr<SDMElement>(
new SDMElement());
216 memcpy(d_SDMPtrVect[i].get(), other.d_SDMPtrVect[i].get(),
225 const boost::dynamic_bitset<> &refHvyAtoms,
226 const boost::dynamic_bitset<> &prbHvyAtoms);
229 const unsigned int,
void *),
233 double (*weightFunc)(
const unsigned int,
234 const unsigned int,
void *),
236 unsigned int size() {
return d_SDMPtrVect.size(); }
239 typedef struct SDMElement {
248 O3AConstraintVect *d_o3aConstraintVect;
249 std::vector<boost::shared_ptr<SDMElement>> d_SDMPtrVect;
250 static bool compareSDMScore(boost::shared_ptr<SDMElement> a,
251 boost::shared_ptr<SDMElement> b) {
252 return ((a->score != b->score)
253 ? (a->score < b->score)
254 : ((a->cost != b->cost)
255 ? (a->cost < b->cost)
256 : ((a->idx[0] != b->idx[0]) ? (a->idx[0] < b->idx[0])
257 : (a->idx[1] < b->idx[1]))));
259 static bool compareSDMDist(boost::shared_ptr<SDMElement> a,
260 boost::shared_ptr<SDMElement> b) {
261 double aWeight = (a->o3aConstraint ? a->o3aConstraint->getWeight() : 0.0);
262 double bWeight = (b->o3aConstraint ? b->o3aConstraint->getWeight() : 0.0);
263 return ((aWeight != bWeight)
264 ? (aWeight > bWeight)
265 : ((a->sqDist != b->sqDist)
266 ? (a->sqDist < b->sqDist)
267 : ((a->idx[0] != b->idx[0]) ? (a->idx[0] < b->idx[0])
268 : (a->idx[1] < b->idx[1]))));
275 typedef enum { MMFF94 = 0, CRIPPEN } AtomTypeScheme;
278 const int refCid = -1,
const bool reflect =
false,
279 const unsigned int maxIters = 50,
unsigned int options = 0,
284 O3A(
int (*costFunc)(
const unsigned int,
const unsigned int,
double,
void *),
285 double (*weightFunc)(
const unsigned int,
const unsigned int,
void *),
286 double (*scoringFunc)(
const unsigned int,
const unsigned int,
void *),
287 void *data,
ROMol &prbMol,
const ROMol &refMol,
const int prbCid,
288 const int refCid,
const boost::dynamic_bitset<> &prbHvyAtoms,
289 const boost::dynamic_bitset<> &refHvyAtoms,
const bool reflect =
false,
290 const unsigned int maxIters = 50,
unsigned int options = 0,
292 ROMol *extWorkPrbMol =
nullptr,
LAP *extLAP =
nullptr,
295 if (d_o3aMatchVect) {
296 delete d_o3aMatchVect;
304 double score() {
return d_o3aScore; };
310 const ROMol *d_refMol;
314 unsigned int d_maxIters;
321 const int seed = -1);
325 const unsigned int refIdx,
326 double hSum,
void *data);
328 const unsigned int refIdx,
331 const unsigned int refIdx,
334 const unsigned int refIdx,
335 double hSum,
void *data);
337 const unsigned int refIdx,
340 const unsigned int refIdx,
344 ROMol &prbMol,
const ROMol &refMol,
void *prbProp,
void *refProp,
345 std::vector<boost::shared_ptr<O3A>> &res,
int numThreads = 1,
347 const bool reflect =
false,
const unsigned int maxIters = 50,
348 unsigned int options = 0,
const MatchVectType *constraintMap =
nullptr,
#define PRECONDITION(expr, mess)
Defines the primary molecule class ROMol as well as associated typedefs.
void computeMinCostPath(const int dim)
int getRowSol(const unsigned int i)
int getCost(const unsigned int i, const unsigned int j)
void computeCostMatrix(const ROMol &prbMol, const MolHistogram &prbHist, const ROMol &refMol, const MolHistogram &refHist, O3AConstraintVect *o3aConstraintVect, int(*costFunc)(const unsigned int, const unsigned int, double, void *), void *data, const unsigned int n_bins=O3_MAX_H_BINS)
int get(const unsigned int y, const unsigned int x) const
MolHistogram(const ROMol &mol, const double *dmat, bool cleanupDmat=false)
std::vector< boost::shared_ptr< O3AConstraint > >::size_type size()
O3AConstraint * operator[](unsigned int i)
void append(unsigned int prbIdx, unsigned int refIdx, double weight)
double trans(RDGeom::Transform3D &trans)
O3A(int(*costFunc)(const unsigned int, const unsigned int, double, void *), double(*weightFunc)(const unsigned int, const unsigned int, void *), double(*scoringFunc)(const unsigned int, const unsigned int, void *), void *data, ROMol &prbMol, const ROMol &refMol, const int prbCid, const int refCid, const boost::dynamic_bitset<> &prbHvyAtoms, const boost::dynamic_bitset<> &refHvyAtoms, const bool reflect=false, const unsigned int maxIters=50, unsigned int options=0, O3AConstraintVect *o3aConstraintVect=nullptr, ROMol *extWorkPrbMol=nullptr, LAP *extLAP=nullptr, MolHistogram *extPrbHist=nullptr, MolHistogram *extRefHist=nullptr)
O3A(ROMol &prbMol, const ROMol &refMol, void *prbProp, void *refProp, AtomTypeScheme atomTypes=MMFF94, const int prbCid=-1, const int refCid=-1, const bool reflect=false, const unsigned int maxIters=50, unsigned int options=0, const MatchVectType *constraintMap=nullptr, const RDNumeric::DoubleVector *constraintWeights=nullptr, LAP *extLAP=nullptr, MolHistogram *extPrbHist=nullptr, MolHistogram *extRefHist=nullptr)
AtomTypeScheme
pre-defined atom typing schemes
const RDNumeric::DoubleVector * weights()
const RDKit::MatchVectType * matches()
void fillFromLAP(LAP &lap)
void fillFromDist(double threshold, const boost::dynamic_bitset<> &refHvyAtoms, const boost::dynamic_bitset<> &prbHvyAtoms)
SDM & operator=(const SDM &other)
double scoreAlignment(double(*scoringFunc)(const unsigned int, const unsigned int, void *), void *data)
void prepareMatchWeightsVect(RDKit::MatchVectType &matchVect, RDNumeric::DoubleVector &weights, double(*weightFunc)(const unsigned int, const unsigned int, void *), void *data)
SDM(const Conformer *prbConf=nullptr, const Conformer *refConf=nullptr, O3AConstraintVect *o3aConstraintVect=nullptr)
A class to represent vectors of numbers.
#define RDKIT_MOLALIGN_EXPORT
std::vector< Point3D > POINT3D_VECT
RDKIT_MOLALIGN_EXPORT void getO3AForProbeConfs(ROMol &prbMol, const ROMol &refMol, void *prbProp, void *refProp, std::vector< boost::shared_ptr< O3A >> &res, int numThreads=1, O3A::AtomTypeScheme atomTypes=O3A::MMFF94, const int refCid=-1, const bool reflect=false, const unsigned int maxIters=50, unsigned int options=0, const MatchVectType *constraintMap=nullptr, const RDNumeric::DoubleVector *constraintWeights=nullptr)
const int O3_MAX_WEIGHT_COEFF
const int O3_LARGE_NEGATIVE_WEIGHT
const int O3_DEFAULT_CONSTRAINT_WEIGHT
RDKIT_MOLALIGN_EXPORT double o3aCrippenWeightFunc(const unsigned int prbIdx, const unsigned int refIdx, void *data)
const double O3_SDM_THRESHOLD_START
const double O3_RMSD_THRESHOLD
const double O3_CRIPPEN_WEIGHT
const double O3_CHARGE_COEFF
const double O3_RANDOM_TRANS_COEFF
const unsigned int O3_MAX_SDM_ITERATIONS
const double O3_SDM_THRESHOLD_STEP
const double O3_CRIPPEN_COEFF
RDKIT_MOLALIGN_EXPORT int o3aMMFFCostFunc(const unsigned int prbIdx, const unsigned int refIdx, double hSum, void *data)
RDKIT_MOLALIGN_EXPORT const RDGeom::POINT3D_VECT * reflect(const Conformer &conf)
const unsigned int O3_MAX_SDM_THRESHOLD_ITER
const double O3_SCORING_FUNCTION_BETA
RDKIT_MOLALIGN_EXPORT void randomTransform(ROMol &mol, const int cid=-1, const int seed=-1)
const unsigned int O3_MAX_H_BINS
const double O3_SCORING_FUNCTION_ALPHA
bool isDoubleZero(const double x)
const double O3_THRESHOLD_DIFF_DISTANCE
RDKIT_MOLALIGN_EXPORT int o3aCrippenCostFunc(const unsigned int prbIdx, const unsigned int refIdx, double hSum, void *data)
RDKIT_MOLALIGN_EXPORT double o3aCrippenScoringFunc(const unsigned int prbIdx, const unsigned int refIdx, void *data)
RDKIT_MOLALIGN_EXPORT double o3aMMFFScoringFunc(const unsigned int prbIdx, const unsigned int refIdx, void *data)
const double O3_CHARGE_WEIGHT
const double O3_SCORE_THRESHOLD
RDKIT_MOLALIGN_EXPORT double o3aMMFFWeightFunc(const unsigned int prbIdx, const unsigned int refIdx, void *data)
std::vector< std::pair< int, int > > MatchVectType
used to return matches from substructure searching, The format is (queryAtomIdx, molAtomIdx)
double score(const std::vector< size_t > &permutation, const std::vector< std::vector< RGroupMatch >> &matches, const std::set< int > &labels)
const Conformer * refConf
const Conformer * prbConf