1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
//
// Copyright (C) 2018 Susan H. Leung
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDBoost/Wrap.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/MolStandardize/Validate.h>
namespace python = boost::python;
using namespace RDKit;
namespace {
struct ValidationMethodWrap
: MolStandardize::ValidationMethod,
python::wrapper<MolStandardize::ValidationMethod> {
std::vector<MolStandardize::ValidationErrorInfo> validate(
const ROMol &mol, bool reportAllFailures) const override {
return this->get_override("validate")(mol, reportAllFailures);
}
std::shared_ptr<MolStandardize::ValidationMethod> copy() const override {
return this->get_override("copy")();
}
};
// Wrap ValidationMethod::validate and convert the returned
// vector into a python list of strings
python::list pythonValidateMethod(const MolStandardize::ValidationMethod &self,
const ROMol &mol, bool reportAllFailures) {
python::list res;
std::vector<MolStandardize::ValidationErrorInfo> errout =
self.validate(mol, reportAllFailures);
for (const auto &msg : errout) {
res.append(msg);
}
return res;
}
MolStandardize::MolVSValidation *getMolVSValidation(
python::object validations) {
std::vector<std::shared_ptr<MolStandardize::ValidationMethod>> vs;
auto pvect =
pythonObjectToVect<std::shared_ptr<MolStandardize::ValidationMethod>>(
validations);
if (!pvect) {
throw_value_error("validations argument must be non-empty");
}
for (auto v : *pvect) {
vs.push_back(v->copy());
}
return new MolStandardize::MolVSValidation(vs);
}
MolStandardize::AllowedAtomsValidation *getAllowedAtomsValidation(
python::object atoms) {
auto p_atomList = pythonObjectToVect<Atom *>(atoms);
if (!p_atomList) {
throw_value_error("allowedAtoms argument must be non-empty");
}
std::vector<std::shared_ptr<Atom>> satoms;
for (auto ap : *p_atomList) {
satoms.push_back(std::shared_ptr<Atom>(ap->copy()));
}
return new MolStandardize::AllowedAtomsValidation(satoms);
}
MolStandardize::DisallowedAtomsValidation *getDisallowedAtomsValidation(
python::object atoms) {
auto p_atomList = pythonObjectToVect<Atom *>(atoms);
if (!p_atomList) {
throw_value_error("disallowedAtoms must be non-empty");
}
std::vector<std::shared_ptr<Atom>> satoms;
for (auto ap : *p_atomList) {
satoms.push_back(std::shared_ptr<Atom>(ap->copy()));
}
return new MolStandardize::DisallowedAtomsValidation(satoms);
}
python::list standardizeSmilesHelper(const std::string &smiles) {
python::list res;
std::vector<MolStandardize::ValidationErrorInfo> errout =
MolStandardize::validateSmiles(smiles);
for (const auto &msg : errout) {
res.append(msg);
}
return res;
}
} // namespace
struct validate_wrapper {
static void wrap() {
std::string docString = "";
python::class_<ValidationMethodWrap, boost::noncopyable>("ValidationMethod")
.def("validate", pythonValidateMethod,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures") = false),
"");
python::class_<MolStandardize::RDKitValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("RDKitValidation")
.def(python::init<bool>(python::arg("allowEmptyMolecules") = false))
.def_readwrite("allowEmptyMolecules",
&MolStandardize::RDKitValidation::allowEmptyMolecules);
python::class_<MolStandardize::NoAtomValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("NoAtomValidation");
python::class_<MolStandardize::FragmentValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("FragmentValidation");
python::class_<MolStandardize::NeutralValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("NeutralValidation");
python::class_<MolStandardize::IsotopeValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("IsotopeValidation")
.def(python::init<bool>(python::arg("strict") = false))
.def_readwrite("strict", &MolStandardize::IsotopeValidation::strict);
python::class_<MolStandardize::MolVSValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("MolVSValidation")
.def("__init__", python::make_constructor(&getMolVSValidation));
python::class_<MolStandardize::AllowedAtomsValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("AllowedAtomsValidation",
python::no_init)
.def("__init__", python::make_constructor(&getAllowedAtomsValidation));
python::class_<MolStandardize::DisallowedAtomsValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("DisallowedAtomsValidation",
python::no_init)
.def("__init__",
python::make_constructor(&getDisallowedAtomsValidation));
python::class_<MolStandardize::FeaturesValidation,
python::bases<MolStandardize::ValidationMethod>>(
"FeaturesValidation")
.def(python::init<bool, bool, bool, bool, bool, bool>(
(python::arg("allowEnhancedStereo") = false,
python::arg("allowAromaticBondType") = false,
python::arg("allowDativeBondType") = false,
python::arg("allowQueries") = false,
python::arg("allowDummmies") = false,
python::arg("allowAtomAliases") = false)))
.def_readwrite("allowEnhancedStereo",
&MolStandardize::FeaturesValidation::allowEnhancedStereo)
.def_readwrite(
"allowAromaticBondType",
&MolStandardize::FeaturesValidation::allowAromaticBondType)
.def_readwrite("allowDativeBondType",
&MolStandardize::FeaturesValidation::allowDativeBondType)
.def_readwrite("allowQueries",
&MolStandardize::FeaturesValidation::allowQueries)
.def_readwrite("allowDummies",
&MolStandardize::FeaturesValidation::allowDummies)
.def_readwrite("allowAtomAliases",
&MolStandardize::FeaturesValidation::allowAtomAliases);
python::class_<MolStandardize::DisallowedRadicalValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("DisallowedRadicalValidation");
python::class_<MolStandardize::Is2DValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("Is2DValidation")
.def(python::init<double>(python::arg("threshold") = 1e-3))
.def_readwrite("threshold", &MolStandardize::Is2DValidation::threshold);
python::class_<MolStandardize::Layout2DValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("Layout2DValidation")
.def(python::init<double, double, bool, bool, double>(
(python::arg("clashLimit") = 0.15,
python::arg("bondLengthLimit") = 25.,
python::arg("allowLongBondsInRings") = true,
python::arg("allowAtomBondClashExemption") = true,
python::arg("minMedianBondLength") = false)))
.def_readwrite("clashLimit",
&MolStandardize::Layout2DValidation::clashLimit)
.def_readwrite("bondLengthLimit",
&MolStandardize::Layout2DValidation::bondLengthLimit)
.def_readwrite(
"allowLongBondsInRings",
&MolStandardize::Layout2DValidation::allowLongBondsInRings)
.def_readwrite(
"allowAtomBondClashExemption",
&MolStandardize::Layout2DValidation::allowAtomBondClashExemption)
.def_readwrite(
"minMedianBondLength",
&MolStandardize::Layout2DValidation::minMedianBondLength);
python::class_<MolStandardize::StereoValidation,
python::bases<MolStandardize::ValidationMethod>,
boost::noncopyable>("StereoValidation");
python::def("ValidateSmiles", standardizeSmilesHelper, (python::arg("mol")),
docString.c_str());
}
};
void wrap_validate() { validate_wrapper::wrap(); }
|