Ejemplo n.º 1
0
python::tuple getCrippenO3AForConfs(
    ROMol &prbMol, ROMol &refMol, int numThreads,
    python::list prbCrippenContribs, python::list refCrippenContribs,
    int refCid = -1, bool reflect = false, unsigned int maxIters = 50,
    unsigned int options = 0, python::list constraintMap = python::list(),
    python::list constraintWeights = python::list()) {
    MatchVectType *cMap =
        (python::len(constraintMap) ? _translateAtomMap(constraintMap) : NULL);
    RDNumeric::DoubleVector *cWts = NULL;
    if (cMap) {
        cWts = _translateWeights(constraintWeights);
        if (cWts) {
            if ((*cMap).size() != (*cWts).size()) {
                throw_value_error(
                    "The number of weights should match the number of constraints");
            }
        }
        for (unsigned int i = 0; i < (*cMap).size(); ++i) {
            if (((*cMap)[i].first < 0) ||
                    ((*cMap)[i].first >= rdcast<int>(prbMol.getNumAtoms())) ||
                    ((*cMap)[i].second < 0) ||
                    ((*cMap)[i].second >= rdcast<int>(refMol.getNumAtoms()))) {
                throw_value_error("Constrained atom idx out of range");
            }
            if ((prbMol[(*cMap)[i].first]->getAtomicNum() == 1) ||
                    (refMol[(*cMap)[i].second]->getAtomicNum() == 1)) {
                throw_value_error("Constrained atoms must be heavy atoms");
            }
        }
    }
    unsigned int prbNAtoms = prbMol.getNumAtoms();
    std::vector<double> prbLogpContribs(prbNAtoms);
    unsigned int refNAtoms = refMol.getNumAtoms();
    std::vector<double> refLogpContribs(refNAtoms);

    if ((prbCrippenContribs != python::list()) &&
            (python::len(prbCrippenContribs) == prbNAtoms)) {
        for (unsigned int i = 0; i < prbNAtoms; ++i) {
            python::tuple logpMRTuple =
                python::extract<python::tuple>(prbCrippenContribs[i]);
            prbLogpContribs[i] = python::extract<double>(logpMRTuple[0]);
        }
    } else {
        std::vector<double> prbMRContribs(prbNAtoms);
        std::vector<unsigned int> prbAtomTypes(prbNAtoms);
        std::vector<std::string> prbAtomTypeLabels(prbNAtoms);
        Descriptors::getCrippenAtomContribs(prbMol, prbLogpContribs, prbMRContribs,
                                            true, &prbAtomTypes,
                                            &prbAtomTypeLabels);
    }
    if ((refCrippenContribs != python::list()) &&
            (python::len(refCrippenContribs) == refNAtoms)) {
        for (unsigned int i = 0; i < refNAtoms; ++i) {
            python::tuple logpMRTuple =
                python::extract<python::tuple>(refCrippenContribs[i]);
            refLogpContribs[i] = python::extract<double>(logpMRTuple[0]);
        }
    } else {
        std::vector<double> refMRContribs(refNAtoms);
        std::vector<unsigned int> refAtomTypes(refNAtoms);
        std::vector<std::string> refAtomTypeLabels(refNAtoms);
        Descriptors::getCrippenAtomContribs(refMol, refLogpContribs, refMRContribs,
                                            true, &refAtomTypes,
                                            &refAtomTypeLabels);
    }
    std::vector<boost::shared_ptr<O3A> > res;
    {
        NOGIL gil;
        getO3AForProbeConfs(prbMol, refMol, &prbLogpContribs, &refLogpContribs, res,
                            numThreads, MolAlign::O3A::CRIPPEN, refCid, reflect,
                            maxIters, options, cMap, cWts);
    }
    python::list pyres;
    for (unsigned int i = 0; i < res.size(); ++i) {
        pyres.append(new PyO3A(res[i]));
    }

    if (cMap) {
        delete cMap;
    }
    if (cWts) {
        delete cWts;
    }

    return python::tuple(pyres);
}
Ejemplo n.º 2
0
PyO3A *getCrippenO3A(ROMol &prbMol, ROMol &refMol,
                     python::list prbCrippenContribs,
                     python::list refCrippenContribs, int prbCid = -1,
                     int refCid = -1, bool reflect = false,
                     unsigned int maxIters = 50, unsigned int options = 0,
                     python::list constraintMap = python::list(),
                     python::list constraintWeights = python::list()) {
  MatchVectType *cMap =
      (python::len(constraintMap) ? _translateAtomMap(constraintMap) : nullptr);
  RDNumeric::DoubleVector *cWts = nullptr;
  if (cMap) {
    cWts = _translateWeights(constraintWeights);
    if (cWts) {
      if ((*cMap).size() != (*cWts).size()) {
        throw_value_error(
            "The number of weights should match the number of constraints");
      }
    }
    for (auto &i : (*cMap)) {
      if ((i.first < 0) || (i.first >= rdcast<int>(prbMol.getNumAtoms())) ||
          (i.second < 0) || (i.second >= rdcast<int>(refMol.getNumAtoms()))) {
        throw_value_error("Constrained atom idx out of range");
      }
      if ((prbMol[i.first]->getAtomicNum() == 1) ||
          (refMol[i.second]->getAtomicNum() == 1)) {
        throw_value_error("Constrained atoms must be heavy atoms");
      }
    }
  }
  unsigned int prbNAtoms = prbMol.getNumAtoms();
  std::vector<double> prbLogpContribs(prbNAtoms);
  unsigned int refNAtoms = refMol.getNumAtoms();
  std::vector<double> refLogpContribs(refNAtoms);

  if ((prbCrippenContribs != python::list()) &&
      (python::len(prbCrippenContribs) == prbNAtoms)) {
    for (unsigned int i = 0; i < prbNAtoms; ++i) {
      python::tuple logpMRTuple =
          python::extract<python::tuple>(prbCrippenContribs[i]);
      prbLogpContribs[i] = python::extract<double>(logpMRTuple[0]);
    }
  } else {
    std::vector<double> prbMRContribs(prbNAtoms);
    std::vector<unsigned int> prbAtomTypes(prbNAtoms);
    std::vector<std::string> prbAtomTypeLabels(prbNAtoms);
    Descriptors::getCrippenAtomContribs(prbMol, prbLogpContribs, prbMRContribs,
                                        true, &prbAtomTypes,
                                        &prbAtomTypeLabels);
  }
  if ((refCrippenContribs != python::list()) &&
      (python::len(refCrippenContribs) == refNAtoms)) {
    for (unsigned int i = 0; i < refNAtoms; ++i) {
      python::tuple logpMRTuple =
          python::extract<python::tuple>(refCrippenContribs[i]);
      refLogpContribs[i] = python::extract<double>(logpMRTuple[0]);
    }
  } else {
    std::vector<double> refMRContribs(refNAtoms);
    std::vector<unsigned int> refAtomTypes(refNAtoms);
    std::vector<std::string> refAtomTypeLabels(refNAtoms);
    Descriptors::getCrippenAtomContribs(refMol, refLogpContribs, refMRContribs,
                                        true, &refAtomTypes,
                                        &refAtomTypeLabels);
  }
  O3A *o3a;
  {
    NOGIL gil;
    o3a = new MolAlign::O3A(prbMol, refMol, &prbLogpContribs, &refLogpContribs,
                            MolAlign::O3A::CRIPPEN, prbCid, refCid, reflect,
                            maxIters, options, cMap, cWts);
  }
  auto *pyO3A = new PyO3A(o3a);
  if (cMap) {
    delete cMap;
  }
  if (cWts) {
    delete cWts;
  }

  return pyO3A;
}