1 //
2 //  Copyright (C) Greg Landrum 2007-2017
3 //
4 //   @@ All Rights Reserved @@
5 //  This file is part of the RDKit.
6 //  The contents are covered by the terms of the BSD license
7 //  which is included in the file license.txt, found at the root
8 //  of the RDKit source tree.
9 //
10 
11 #define NO_IMPORT_ARRAY
12 #include <RDBoost/python.h>
13 #include <RDBoost/Wrap.h>
14 
15 #include <GraphMol/RDKitBase.h>
16 #include <RDGeneral/types.h>
17 
18 namespace python = boost::python;
19 
20 namespace {
21 using namespace RDKit;
atomRings(const RingInfo * self)22 python::object atomRings(const RingInfo *self) {
23   python::list res;
24   for (const auto &ring : self->atomRings()) {
25     res.append(python::tuple(ring));
26   }
27   return python::tuple(res);
28 }
bondRings(const RingInfo * self)29 python::object bondRings(const RingInfo *self) {
30   python::list res;
31   for (const auto &ring : self->bondRings()) {
32     res.append(python::tuple(ring));
33   }
34   return python::tuple(res);
35 }
36 
37 #ifdef RDK_USE_URF
atomRingFamilies(const RingInfo * self)38 python::object atomRingFamilies(const RingInfo *self) {
39   python::list res;
40   for (const auto &ring : self->atomRingFamilies()) {
41     res.append(python::tuple(ring));
42   }
43   return python::tuple(res);
44 }
bondRingFamilies(const RingInfo * self)45 python::object bondRingFamilies(const RingInfo *self) {
46   python::list res;
47   for (const auto &ring : self->bondRingFamilies()) {
48     res.append(python::tuple(ring));
49   }
50   return python::tuple(res);
51 }
52 #endif
53 
addRing(RingInfo * self,python::object atomRing,python::object bondRing)54 void addRing(RingInfo *self,python::object atomRing, python::object bondRing){
55   unsigned int nAts = python::extract<unsigned int>(atomRing.attr("__len__")());
56   unsigned int nBnds = python::extract<unsigned int>(bondRing.attr("__len__")());
57   if (nAts != nBnds) {
58     throw_value_error("list sizes must match");
59   }
60   if (!self->isInitialized()) {
61     self->initialize();
62   }
63   INT_VECT aring(nAts);
64   INT_VECT bring(nAts);
65   for (unsigned int i = 0; i < nAts; ++i) {
66     aring[i] = python::extract<int>(atomRing[i])();
67     bring[i] = python::extract<int>(bondRing[i])();
68   }
69   self->addRing(aring,bring);
70 }
71 }
72 
73 namespace RDKit {
74 std::string classDoc = "contains information about a molecule's rings\n";
75 
76 struct ringinfo_wrapper {
wrapRDKit::ringinfo_wrapper77   static void wrap() {
78     python::class_<RingInfo>("RingInfo", classDoc.c_str(), python::no_init)
79         .def("IsAtomInRingOfSize", &RingInfo::isAtomInRingOfSize)
80         .def("MinAtomRingSize", &RingInfo::minAtomRingSize)
81         .def("IsBondInRingOfSize", &RingInfo::isBondInRingOfSize)
82         .def("MinBondRingSize", &RingInfo::minBondRingSize)
83         .def("NumAtomRings", &RingInfo::numAtomRings)
84         .def("NumBondRings", &RingInfo::numBondRings)
85         .def("NumRings", &RingInfo::numRings)
86         .def("AtomRings", atomRings)
87         .def("BondRings", bondRings)
88 #ifdef RDK_USE_URF
89         .def("NumRingFamilies", &RingInfo::numRingFamilies)
90         .def("NumRelevantCycles", &RingInfo::numRelevantCycles)
91         .def("AtomRingFamilies", atomRingFamilies)
92         .def("BondRingFamilies", bondRingFamilies)
93         .def("AreRingFamiliesInitialized", &RingInfo::areRingFamiliesInitialized)
94 #endif
95         .def("AddRing", addRing, (python::arg("self"),python::arg("atomIds"),python::arg("bondIds")),
96          "Adds a ring to the set. Be very careful with this operation.");
97   };
98 };
99 }  // end of namespace
wrap_ringinfo()100 void wrap_ringinfo() { RDKit::ringinfo_wrapper::wrap(); }
101