Files
rdkit/Code/GraphMol/Deprotect/Wrap/DeprotectWrap.cpp
Paolo Tosco 2b4202867e Add Python modules to generate stubs and automatically patch docstrings (#6919)
* - added gen_rdkit_stubs Python module to generate rdkit-stubs
- added patch_rdkit_docstrings Python module to patch existing C++ sources to fix docstrings missing self parameter and add named parameters taken from C++ signatures where possible
- added rdkit-stubs/CMakeLists.txt to build rdkit-stubs as part of the RDKit build
- added an option to CMakeLists.txt to enable building rdkit-stubs as part of the RDKit build (defaults to OFF)

* fixed CMakeLists.txt, rdkit-stubs/CMakeLists.txt and a doctest

* - added missing cmp_func parameter
- fixed case with overloads with optional parameters
- do not trim params if expected_param_count == -1
- add dummy parameter names if we could not find any
- keep into account member functions when making up parameter names
- address __init__ and make_constructor __init__ functions
- fix incorrectly assigned staticmethods

* patched sources

* address residual few remarks

---------

Co-authored-by: ptosco <paolo.tosco@novartis.com>
2023-11-30 04:54:18 +01:00

109 lines
4.2 KiB
C++

//
// Copyright (C) 2020-2021 Brian P Kelley and other RDKit contributors
//
// @@ 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 <RDBoost/Wrap.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/Deprotect/Deprotect.h>
namespace python = boost::python;
namespace RDKit {
boost::shared_ptr<ROMol> DeprotectWrap(const ROMol &mol,
const python::object &iterable) {
if (iterable != python::object()) {
std::vector<Deprotect::DeprotectData> deprotections;
pythonObjectToVect<Deprotect::DeprotectData>(iterable, deprotections);
return Deprotect::deprotect(mol, deprotections);
} else {
return Deprotect::deprotect(mol, Deprotect::getDeprotections());
}
}
bool DeprotectInPlaceWrap(ROMol &mol, const python::object &iterable) {
RWMol &rwmol = static_cast<RWMol &>(mol);
if (iterable != python::object()) {
std::vector<Deprotect::DeprotectData> deprotections;
pythonObjectToVect<Deprotect::DeprotectData>(iterable, deprotections);
return Deprotect::deprotectInPlace(rwmol, deprotections);
} else {
return Deprotect::deprotectInPlace(rwmol, Deprotect::getDeprotections());
}
}
//! Make a copy so we don't try and change a const vector
std::vector<Deprotect::DeprotectData> GetDeprotectionsWrap() {
return Deprotect::getDeprotections();
}
} // namespace RDKit
struct deprotect_wrap {
static void wrap() {
const char *constructor_doc =
"Construct a new DeprotectData instance.\n"
" >>> reaction_class = \"amine\"\n"
" >>> reaction_smarts = "
"\"[C;R0][C;R0]([C;R0])([O;R0][C;R0](=[O;R0])[NX3;H0,H1:1])C>>[N:1]\"\n"
" >>> abbreviation = \"Boc\"\n"
" >>> full_name = \"tert-butyloxycarbonyl\"\n"
" >>> data = DeprotectData(reaction_class, reaction_smarts, "
"abbreviation, full_name)\n"
" >>> assert data.isValid()\n"
"\n";
const char *deprotect_doc_string =
"DeprotectData class, contains a single deprotection reaction and "
"information\n"
"\n"
" deprotectdata.deprotection_class - functional group being protected\n"
" deprotectdata.reaction_smarts - reaction smarts used for "
"deprotection\n"
" deprotectdata.abbreviation - common abbreviation for the protecting "
"group\n"
" deprotectdata.full_name - full name for the protecting group\n"
"\n"
"\n";
RegisterVectorConverter<RDKit::Deprotect::DeprotectData>(
"DeprotectDataVect");
python::class_<RDKit::Deprotect::DeprotectData>(
"DeprotectData", deprotect_doc_string,
python::init<std::string, std::string, std::string, std::string>(
constructor_doc,
python::args("self", "deprotection_class", "reaction_smarts",
"abbreviation", "full_name")))
.def_readonly("deprotection_class",
&RDKit::Deprotect::DeprotectData::deprotection_class)
.def_readonly("full_name", &RDKit::Deprotect::DeprotectData::full_name)
.def_readonly("abbreviation",
&RDKit::Deprotect::DeprotectData::abbreviation)
.def_readonly("reaction_smarts",
&RDKit::Deprotect::DeprotectData::reaction_smarts)
.def_readonly("example", &RDKit::Deprotect::DeprotectData::example)
.def("isValid", &RDKit::Deprotect::DeprotectData::isValid,
python::args("self"),
"Returns True if the DeprotectData has a valid reaction");
python::def("GetDeprotections", &RDKit::GetDeprotectionsWrap,
"Return the default list of deprotections");
python::def(
"Deprotect", &RDKit::DeprotectWrap,
(python::arg("mol"), python::arg("deprotections") = python::object()),
"Return the deprotected version of the molecule.");
python::def(
"DeprotectInPlace", &RDKit::DeprotectInPlaceWrap,
(python::arg("mol"), python::arg("deprotections") = python::object()),
"Deprotects the molecule in place.");
}
};
void wrap_deprotect() { deprotect_wrap::wrap(); }