File: Bond.cpp

package info (click to toggle)
rdkit 201809.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 123,688 kB
  • sloc: cpp: 230,509; python: 70,501; java: 6,329; ansic: 5,427; sql: 1,899; yacc: 1,739; lex: 1,243; makefile: 445; xml: 229; fortran: 183; sh: 123; cs: 93
file content (329 lines) | stat: -rw-r--r-- 13,499 bytes parent folder | download
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
//
//  Copyright (C) 2003-2017 Rational Discovery LLC
//
//   @@ 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.
//

#define NO_IMPORT_ARRAY
#include <RDBoost/python.h>
#include <string>
#include "props.hpp"

#include <GraphMol/RDKitBase.h>
#include <GraphMol/QueryBond.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <GraphMol/SmilesParse/SmartsWrite.h>
#include <RDGeneral/types.h>

namespace python = boost::python;
namespace RDKit {

void expandQuery(QueryBond *self, const QueryBond *other,
                 Queries::CompositeQueryType how, bool maintainOrder) {
  if (other->hasQuery()) {
    const QueryBond::QUERYBOND_QUERY *qry = other->getQuery();
    self->expandQuery(qry->copy(), how, maintainOrder);
  }
}

int BondHasProp(const Bond *bond, const char *key) {
  int res = bond->hasProp(key);
  return res;
}

template <class T>
void BondSetProp(const Bond *bond, const char *key, const T &val) {
  bond->setProp<T>(key, val);
}
void BondClearProp(const Bond *bond, const char *key) {
  if (!bond->hasProp(key)) {
    return;
  }
  bond->clearProp(key);
}

bool BondIsInRing(const Bond *bond) {
  if (!bond->getOwningMol().getRingInfo()->isInitialized()) {
    MolOps::findSSSR(bond->getOwningMol());
  }
  return bond->getOwningMol().getRingInfo()->numBondRings(bond->getIdx()) != 0;
}

bool BondIsInRingSize(const Bond *bond, int size) {
  if (!bond->getOwningMol().getRingInfo()->isInitialized()) {
    MolOps::findSSSR(bond->getOwningMol());
  }
  return bond->getOwningMol().getRingInfo()->isBondInRingOfSize(bond->getIdx(),
                                                                size);
  return false;
}

INT_VECT getBondStereoAtoms(const Bond *bond) { return bond->getStereoAtoms(); }

std::string BondGetSmarts(const Bond *bond, bool allBondsExplicit) {
  std::string res;
  if (bond->hasQuery()) {
    res = SmartsWrite::GetBondSmarts(static_cast<const QueryBond *>(bond));
  } else {
    res = SmilesWrite::GetBondSmiles(bond, -1, false, allBondsExplicit);
  }
  return res;
}

std::string bondClassDoc =
    "The class to store Bonds.\n\
Note: unlike Atoms, is it currently impossible to construct Bonds from\n\
Python.\n";
struct bond_wrapper {
  static void wrap() {
    python::class_<Bond>("Bond", bondClassDoc.c_str(), python::no_init)

        .def("GetOwningMol", &Bond::getOwningMol,
             "Returns the Mol that owns this bond.\n",
             python::return_value_policy<python::reference_existing_object>())

        .def("GetBondType", &Bond::getBondType,
             "Returns the type of the bond as a BondType\n")
        .def("SetBondType", &Bond::setBondType,
             "Set the type of the bond as a BondType\n")
        .def("GetBondTypeAsDouble", &Bond::getBondTypeAsDouble,
             "Returns the type of the bond as a double (i.e. 1.0 for SINGLE, "
             "1.5 for AROMATIC, 2.0 for DOUBLE)\n")

        .def("GetBondDir", &Bond::getBondDir,
             "Returns the type of the bond as a BondDir\n")
        .def("SetBondDir", &Bond::setBondDir,
             "Set the type of the bond as a BondDir\n")

        .def("GetStereo", &Bond::getStereo,
             "Returns the stereo configuration of the bond as a BondStereo\n")
        .def("SetStereo", &Bond::setStereo,
             "Set the stereo configuration of the bond as a BondStereo\n")
        .def("GetStereoAtoms", getBondStereoAtoms,
             "Returns the indices of the atoms setting this bond's "
             "stereochemistry.\n")
        .def("SetStereoAtoms", &Bond::setStereoAtoms,
             "Set the indices of the atoms setting this bond's "
             "stereochemistry.\n")

        .def("GetValenceContrib",
             (double (Bond::*)(const Atom *) const) & Bond::getValenceContrib,
             "Returns the contribution of the bond to the valence of an "
             "Atom.\n\n"
             "  ARGUMENTS:\n\n"
             "    - atom: the Atom to consider.\n")

        .def("GetIsAromatic", &Bond::getIsAromatic)
        .def("SetIsAromatic", &Bond::setIsAromatic)

        .def("GetIsConjugated", &Bond::getIsConjugated,
             "Returns whether or not the bond is considered to be conjugated.")
        .def("SetIsConjugated", &Bond::setIsConjugated)

        .def("GetIdx", &Bond::getIdx,
             "Returns the bond's index (ordering in the molecule)\n")

        .def("GetBeginAtomIdx", &Bond::getBeginAtomIdx,
             "Returns the index of the bond's first atom.\n")
        .def("GetEndAtomIdx", &Bond::getEndAtomIdx,
             "Returns the index of the bond's first atom.\n")
        .def("GetOtherAtomIdx", &Bond::getOtherAtomIdx,
             "Given the index of one of the bond's atoms, returns the\n"
             "index of the other.\n")

        .def("GetBeginAtom", &Bond::getBeginAtom,
             python::return_value_policy<python::reference_existing_object>(),
             "Returns the bond's first atom.\n")
        .def("GetEndAtom", &Bond::getEndAtom,
             python::return_value_policy<python::reference_existing_object>(),
             "Returns the bond's second atom.\n")
        .def("GetOtherAtom", &Bond::getOtherAtom,
             python::return_value_policy<python::reference_existing_object>(),
             "Given one of the bond's atoms, returns the other one.\n")

        // FIX: query stuff
        .def("Match", (bool (Bond::*)(const Bond *) const) & Bond::Match,
             "Returns whether or not this bond matches another Bond.\n\n"
             "  Each Bond (or query Bond) has a query function which is\n"
             "  used for this type of matching.\n\n"
             "  ARGUMENTS:\n"
             "    - other: the other Bond to which to compare\n")

        .def("IsInRingSize", BondIsInRingSize,
             "Returns whether or not the bond is in a ring of a particular "
             "size.\n\n"
             "  ARGUMENTS:\n"
             "    - size: the ring size to look for\n")
        .def("IsInRing", BondIsInRing,
             "Returns whether or not the bond is in a ring of any size.\n\n")

        .def("HasQuery", &Bond::hasQuery,
             "Returns whether or not the bond has an associated query\n\n")

        .def("DescribeQuery", describeQuery,
             "returns a text description of the query. Primarily intended for "
             "debugging purposes.\n\n")

        .def("GetSmarts", BondGetSmarts,
             (python::arg("bond"), python::arg("allBondsExplicit") = false),
             "returns the SMARTS (or SMILES) string for a Bond")

        // properties
        .def("SetProp", BondSetProp<std::string>,
             (python::arg("self"), python::arg("key"), python::arg("val")),
             "Sets a bond property\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to be set (a string).\n"
             "    - value: the property value (a string).\n\n")

        .def("GetProp", GetProp<Bond, std::string>,
             "Returns the value of the property.\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to return (a string).\n\n"
             "  RETURNS: a string\n\n"
             "  NOTE:\n"
             "    - If the property has not been set, a KeyError exception "
             "will be raised.\n")

        .def("SetIntProp", BondSetProp<int>,
             (python::arg("self"), python::arg("key"), python::arg("val")),
             "Sets a bond property\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to be set (a string).\n"
             "    - value: the property value (an int).\n\n")

        .def("SetUnsignedProp", BondSetProp<unsigned int>,
             (python::arg("self"), python::arg("key"), python::arg("val")),
             "Sets a bond property\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to be set (a string).\n"
             "    - value: the property value (an int >= 0).\n\n")

        .def("GetIntProp", GetProp<Bond, int>,
             "Returns the value of the property.\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to return (an int).\n\n"
             "  RETURNS: an int\n\n"
             "  NOTE:\n"
             "    - If the property has not been set, a KeyError exception "
             "will be raised.\n")

        .def("GetUnsignedProp", GetProp<Bond, unsigned int>,
             "Returns the value of the property.\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to return (an unsigned "
             "integer).\n\n"
             "  RETURNS: an int (Python has no unsigned type)\n\n"
             "  NOTE:\n"
             "    - If the property has not been set, a KeyError exception "
             "will be raised.\n")

        .def("SetDoubleProp", BondSetProp<double>,
             (python::arg("self"), python::arg("key"), python::arg("val")),
             "Sets a bond property\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to be set (a string).\n"
             "    - value: the property value (a double).\n\n")

        .def("GetDoubleProp", GetProp<Bond, double>,
             "Returns the value of the property.\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to return (a double).\n\n"
             "  RETURNS: a double\n\n"
             "  NOTE:\n"
             "    - If the property has not been set, a KeyError exception "
             "will be raised.\n")

        .def("SetBoolProp", BondSetProp<bool>,
             (python::arg("self"), python::arg("key"), python::arg("val")),
             "Sets a bond property\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to be set (a string).\n"
             "    - value: the property value (a boolean).\n\n")

        .def("GetBoolProp", GetProp<Bond, bool>,
             "Returns the value of the property.\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to return (a boolean).\n\n"
             "  RETURNS: a boolean\n\n"
             "  NOTE:\n"
             "    - If the property has not been set, a KeyError exception "
             "will be raised.\n")

        .def("HasProp", BondHasProp,
             "Queries a Bond to see if a particular property has been "
             "assigned.\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to check for (a string).\n")

        .def("ClearProp", BondClearProp,
             "Removes a particular property from an Bond (does nothing if not "
             "already set).\n\n"
             "  ARGUMENTS:\n"
             "    - key: the name of the property to be removed.\n")

        .def("GetPropNames", &Bond::getPropList,
             (python::arg("self"), python::arg("includePrivate") = false,
              python::arg("includeComputed") = false),
             "Returns a list of the properties set on the Bond.\n\n")

        .def("GetPropsAsDict", GetPropsAsDict<Bond>,
             (python::arg("self"), python::arg("includePrivate") = true,
              python::arg("includeComputed") = true),
             "Returns a dictionary of the properties set on the Bond.\n"
             " n.b. some properties cannot be converted to python types.\n")

        ;

    python::enum_<Bond::BondType>("BondType")
        .value("UNSPECIFIED", Bond::UNSPECIFIED)
        .value("SINGLE", Bond::SINGLE)
        .value("DOUBLE", Bond::DOUBLE)
        .value("TRIPLE", Bond::TRIPLE)
        .value("QUADRUPLE", Bond::QUADRUPLE)
        .value("QUINTUPLE", Bond::QUINTUPLE)
        .value("HEXTUPLE", Bond::HEXTUPLE)
        .value("ONEANDAHALF", Bond::ONEANDAHALF)
        .value("TWOANDAHALF", Bond::TWOANDAHALF)
        .value("THREEANDAHALF", Bond::THREEANDAHALF)
        .value("FOURANDAHALF", Bond::FOURANDAHALF)
        .value("FIVEANDAHALF", Bond::FIVEANDAHALF)
        .value("AROMATIC", Bond::AROMATIC)
        .value("IONIC", Bond::IONIC)
        .value("HYDROGEN", Bond::HYDROGEN)
        .value("THREECENTER", Bond::THREECENTER)
        .value("DATIVEONE", Bond::DATIVEONE)
        .value("DATIVE", Bond::DATIVE)
        .value("DATIVEL", Bond::DATIVEL)
        .value("DATIVER", Bond::DATIVER)
        .value("OTHER", Bond::OTHER)
        .value("ZERO", Bond::ZERO);
    python::enum_<Bond::BondDir>("BondDir")
        .value("NONE", Bond::NONE)
        .value("BEGINWEDGE", Bond::BEGINWEDGE)
        .value("BEGINDASH", Bond::BEGINDASH)
        .value("ENDDOWNRIGHT", Bond::ENDDOWNRIGHT)
        .value("ENDUPRIGHT", Bond::ENDUPRIGHT)
        .value("EITHERDOUBLE", Bond::EITHERDOUBLE)
        .value("UNKNOWN", Bond::UNKNOWN);
    python::enum_<Bond::BondStereo>("BondStereo")
        .value("STEREONONE", Bond::STEREONONE)
        .value("STEREOANY", Bond::STEREOANY)
        .value("STEREOZ", Bond::STEREOZ)
        .value("STEREOE", Bond::STEREOE)
        .value("STEREOCIS", Bond::STEREOCIS)
        .value("STEREOTRANS", Bond::STEREOTRANS);

    bondClassDoc =
        "The class to store QueryBonds.\n\
These cannot currently be constructed directly from Python\n";
    python::class_<QueryBond, python::bases<Bond>>(
        "QueryBond", bondClassDoc.c_str(), python::no_init);
  };
};
}  // end of namespace
void wrap_bond() { RDKit::bond_wrapper::wrap(); }