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
|
//
// Copyright (C) 2018 Greg Landrum
//
// @@ 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/python.h>
#include <GraphMol/GraphMol.h>
#include <RDBoost/Wrap.h>
#include <GraphMol/MolInterchange/MolInterchange.h>
namespace python = boost::python;
namespace {
python::tuple JSONToMols(const std::string &jsonBlock,
python::object pyparams) {
RDKit::MolInterchange::JSONParseParameters params;
if (pyparams) {
params =
python::extract<RDKit::MolInterchange::JSONParseParameters>(pyparams);
} else {
params = RDKit::MolInterchange::defaultJSONParseParameters;
}
auto mols = RDKit::MolInterchange::JSONDataToMols(jsonBlock, params);
python::list result;
for (auto &mol : mols) {
result.append(mol);
}
return python::tuple(result);
}
std::string MolsToJSON(const python::object &mols) {
auto pymols = pythonObjectToVect<const RDKit::ROMol *>(mols);
return RDKit::MolInterchange::MolsToJSONData(*pymols);
}
}
BOOST_PYTHON_MODULE(rdMolInterchange) {
python::scope().attr("__doc__") =
"Module containing functions for interchange of molecules.\n"
"Note that this should be considered beta and that the format\n"
" and API will very likely change in future releases.";
python::class_<RDKit::MolInterchange::JSONParseParameters,
boost::noncopyable>("JSONParseParameters",
"Paramters controlling the JSON parser")
.def_readwrite(
"setAromaticBonds",
&RDKit::MolInterchange::JSONParseParameters::setAromaticBonds,
"set bond types to aromatic for bonds flagged aromatic")
.def_readwrite(
"strictValenceCheck",
&RDKit::MolInterchange::JSONParseParameters::strictValenceCheck,
"be strict when checking atom valences")
.def_readwrite(
"parseConformers",
&RDKit::MolInterchange::JSONParseParameters::parseConformers,
"parse conformers in the JSON")
.def_readwrite(
"parseProperties",
&RDKit::MolInterchange::JSONParseParameters::parseProperties,
"parse molecular properties in the JSON");
std::string docString;
docString =
"Convert a single molecule to JSON\n\
\n\
ARGUMENTS:\n\
- mol: the molecule to work with\n\
RETURNS:\n\
a string\n";
python::def("MolToJSON", (std::string(*)(const RDKit::ROMol &))
RDKit::MolInterchange::MolToJSONData,
(python::arg("mol")), docString.c_str());
docString =
"Convert a set of molecules to JSON\n\
\n\
ARGUMENTS:\n\
- mols: the molecules to work with\n\
RETURNS:\n\
a string\n";
python::def("MolsToJSON", MolsToJSON, (python::arg("mols")),
docString.c_str());
docString =
"Convert JSON to a tuple of molecules\n\
\n\
ARGUMENTS:\n\
- jsonBlock: the molecule to work with\n\
- params: (optional) JSONParseParameters controlling the JSON parsing\n\
RETURNS:\n\
a tuple of Mols\n";
python::def(
"JSONToMols", JSONToMols,
(python::arg("jsonBlock"), python::arg("params") = python::object()),
docString.c_str());
}
|