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) 2020 Greg Landrum and T5 Informatics GmbH
//
// @@ 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 <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <GraphMol/GraphMol.h>
#include <RDBoost/Wrap.h>
#include <GraphMol/Abbreviations/Abbreviations.h>
namespace python = boost::python;
using namespace RDKit;
namespace {
ROMol *condenseMolAbbreviationsHelper(const ROMol *mol,
python::object pyabbrevs,
double maxCoverage, bool sanitize) {
RWMol *res = new RWMol(*mol);
auto abbrevs =
pythonObjectToVect<Abbreviations::AbbreviationDefinition>(pyabbrevs);
Abbreviations::condenseMolAbbreviations(*res, *abbrevs, maxCoverage,
sanitize);
return rdcast<ROMol *>(res);
}
ROMol *condenseAbbreviationSGroupHelper(const ROMol *mol) {
RWMol *res = new RWMol(*mol);
Abbreviations::condenseAbbreviationSubstanceGroups(*res);
return rdcast<ROMol *>(res);
}
ROMol *labelMolAbbreviationsHelper(const ROMol *mol, python::object pyabbrevs,
double maxCoverage) {
RWMol *res = new RWMol(*mol);
auto abbrevs =
pythonObjectToVect<Abbreviations::AbbreviationDefinition>(pyabbrevs);
Abbreviations::labelMolAbbreviations(*res, *abbrevs, maxCoverage);
return rdcast<ROMol *>(res);
}
} // namespace
BOOST_PYTHON_MODULE(rdAbbreviations) {
python::scope().attr("__doc__") =
"Module containing functions for working with molecular abbreviations";
// RegisterVectorConverter<Abbreviations::AbbreviationMatch>();
RegisterVectorConverter<Abbreviations::AbbreviationDefinition>();
python::class_<Abbreviations::AbbreviationDefinition>(
"AbbreviationDefinition", "Abbreviation Definition", python::init<>())
.def_readwrite("label", &Abbreviations::AbbreviationDefinition::label,
"the label")
.def_readwrite(
"displayLabel", &Abbreviations::AbbreviationDefinition::displayLabel,
"the label in a drawing when the bond comes from the right")
.def_readwrite("displayLabelW",
&Abbreviations::AbbreviationDefinition::displayLabelW,
"the label in a drawing when the bond comes from the west")
.def_readwrite(
"mol", &Abbreviations::AbbreviationDefinition::mol,
"the query molecule (should have a dummy as the first atom)");
python::def("GetDefaultAbbreviations",
&Abbreviations::Utils::getDefaultAbbreviations,
"returns a list of the default abbreviation definitions");
python::def("GetDefaultLinkers", &Abbreviations::Utils::getDefaultLinkers,
"returns a list of the default linker definitions");
python::def("ParseAbbreviations", &Abbreviations::Utils::parseAbbreviations,
(python::arg("text"), python::arg("removeExtraDummies") = false,
python::arg("allowConnectionToDummies") = false),
"returns a set of abbreviation definitions from a string");
python::def("ParseLinkers", &Abbreviations::Utils::parseLinkers,
(python::arg("text")),
"returns a set of linker definitions from a string");
python::def(
"CondenseMolAbbreviations", &condenseMolAbbreviationsHelper,
(python::arg("mol"), python::arg("abbrevs"),
python::arg("maxCoverage") = 0.4, python::arg("sanitize") = true),
python::return_value_policy<python::manage_new_object>(),
"Finds and replaces abbreviations in a molecule. The result is not sanitized.");
python::def("LabelMolAbbreviations", &labelMolAbbreviationsHelper,
(python::arg("mol"), python::arg("abbrevs"),
python::arg("maxCoverage") = 0.4),
python::return_value_policy<python::manage_new_object>(),
"Finds abbreviations and adds to them to a molecule as \"SUP\" "
"SubstanceGroups");
python::def(
"CondenseAbbreviationSubstanceGroups", &condenseAbbreviationSGroupHelper,
(python::arg("mol")),
python::return_value_policy<python::manage_new_object>(),
"Finds and replaces abbrevation (i.e. \"SUP\") substance groups in a "
"molecule. The result is not sanitized.");
}
|