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
|
//
// 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 {
python::list rdkitValidate(MolStandardize::RDKitValidation &self,
const ROMol &mol, const bool reportAllFailures) {
python::list res;
std::vector<MolStandardize::ValidationErrorInfo> errout =
self.validate(mol, reportAllFailures);
for (auto &query : errout) {
std::string msg = query.message();
res.append(msg);
}
return res;
}
MolStandardize::MolVSValidation *getMolVSValidation(
python::object validations) {
std::vector<boost::shared_ptr<MolStandardize::MolVSValidations>> vs;
std::unique_ptr<
std::vector<boost::shared_ptr<MolStandardize::MolVSValidations>>>
pvect = pythonObjectToVect<
boost::shared_ptr<MolStandardize::MolVSValidations>>(validations);
for (auto v : *pvect) {
vs.push_back(v->copy());
}
return new MolStandardize::MolVSValidation(vs);
}
python::list molVSvalidateHelper(MolStandardize::MolVSValidation &self,
const ROMol &mol, bool reportAllFailures) {
python::list s;
std::vector<MolStandardize::ValidationErrorInfo> errout =
self.validate(mol, reportAllFailures);
for (auto &query : errout) {
s.append(query.message());
}
return s;
}
MolStandardize::AllowedAtomsValidation *getAllowedAtomsValidation(
python::object atoms) {
std::unique_ptr<std::vector<Atom *>> p_atomList =
pythonObjectToVect<Atom *>(atoms);
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);
}
python::list allowedAtomsValidate(MolStandardize::AllowedAtomsValidation &self,
const ROMol &mol,
const bool reportAllFailures) {
python::list res;
std::vector<MolStandardize::ValidationErrorInfo> errout =
self.validate(mol, reportAllFailures);
for (auto &query : errout) {
std::string msg = query.message();
res.append(msg);
}
return res;
}
MolStandardize::DisallowedAtomsValidation *getDisallowedAtomsValidation(
python::object atoms) {
std::unique_ptr<std::vector<Atom *>> p_atomList =
pythonObjectToVect<Atom *>(atoms);
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 disallowedAtomsValidate(
MolStandardize::DisallowedAtomsValidation &self, const ROMol &mol,
const bool reportAllFailures) {
python::list res;
std::vector<MolStandardize::ValidationErrorInfo> errout =
self.validate(mol, reportAllFailures);
for (auto &query : errout) {
std::string msg = query.message();
res.append(msg);
}
return res;
}
python::list standardizeSmilesHelper(const std::string &smiles) {
python::list res;
std::vector<MolStandardize::ValidationErrorInfo> errout =
MolStandardize::validateSmiles(smiles);
for (auto &query : errout) {
std::string msg = query.message();
res.append(msg);
}
return res;
}
} // namespace
struct validate_wrapper {
static void wrap() {
std::string docString = "";
python::class_<MolStandardize::RDKitValidation, boost::noncopyable>(
"RDKitValidation", python::init<>())
.def("validate", rdkitValidate,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures") = false),
"");
python::class_<MolStandardize::MolVSValidations, boost::noncopyable>(
"MolVSValidations", python::no_init)
.def("run", &MolStandardize::MolVSValidations::run,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures"), python::arg("errors")),
"");
python::class_<MolStandardize::NoAtomValidation,
python::bases<MolStandardize::MolVSValidations>>(
"NoAtomValidation", python::init<>())
.def("run", &MolStandardize::NoAtomValidation::run,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures"), python::arg("errors")),
"");
python::class_<MolStandardize::FragmentValidation,
python::bases<MolStandardize::MolVSValidations>>(
"FragmentValidation", python::init<>())
.def("run", &MolStandardize::FragmentValidation::run,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures"), python::arg("errors")),
"");
python::class_<MolStandardize::NeutralValidation,
python::bases<MolStandardize::MolVSValidations>>(
"NeutralValidation", python::init<>())
.def("run", &MolStandardize::NeutralValidation::run,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures"), python::arg("errors")),
"");
python::class_<MolStandardize::IsotopeValidation,
python::bases<MolStandardize::MolVSValidations>>(
"IsotopeValidation", python::init<>())
.def("run", &MolStandardize::IsotopeValidation::run,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures"), python::arg("errors")),
"");
python::class_<MolStandardize::MolVSValidation, boost::noncopyable>(
"MolVSValidation")
.def("__init__", python::make_constructor(&getMolVSValidation))
.def("validate", molVSvalidateHelper,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures") = false),
"");
python::class_<MolStandardize::AllowedAtomsValidation, boost::noncopyable>(
"AllowedAtomsValidation", python::no_init)
.def("__init__", python::make_constructor(&getAllowedAtomsValidation))
.def("validate", allowedAtomsValidate,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures") = false),
"");
;
python::class_<MolStandardize::DisallowedAtomsValidation,
boost::noncopyable>("DisallowedAtomsValidation",
python::no_init)
.def("__init__",
python::make_constructor(&getDisallowedAtomsValidation))
.def("validate", disallowedAtomsValidate,
(python::arg("self"), python::arg("mol"),
python::arg("reportAllFailures") = false),
"");
python::def("ValidateSmiles", standardizeSmilesHelper, (python::arg("mol")),
docString.c_str());
}
};
void wrap_validate() { validate_wrapper::wrap(); }
|