RDKit
Open-source cheminformatics and machine learning.
types.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2016 Greg Landrum and Rational Discovery LLC
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 #ifndef RD_TYPES_H
12 #define RD_TYPES_H
13 
14 #ifdef WIN32
15 #define _USE_MATH_DEFINES
16 #endif
17 
18 #include <cmath>
19 
20 #include "Invariant.h"
21 #include "Dict.h"
22 
23 #include <vector>
24 #include <deque>
25 #include <map>
26 #include <set>
27 #include <string>
28 #include <algorithm>
29 #include <numeric>
30 #include <list>
31 #include <limits>
32 
33 #include <cstring>
34 
35 #include <boost/any.hpp>
36 #include <boost/lexical_cast.hpp>
37 
38 namespace RDKit {
39 
40  namespace detail {
41  // used in various places for computed properties
42  extern const std::string computedPropName;
43  }
44 
45 namespace common_properties {
46 ///////////////////////////////////////////////////////////////
47 // Molecule Props
48 extern const std::string _Name; // string
49 extern const std::string MolFileInfo; // string
50 extern const std::string MolFileComments; // string
51 extern const std::string _2DConf; // int (combine into dimension?)
52 extern const std::string _3DConf; // int
53 extern const std::string _doIsoSmiles; // int (should probably be removed)
54 extern const std::string extraRings; // vec<vec<int> >
55 extern const std::string _smilesAtomOutputOrder; // vec<int> computed
56 extern const std::string _StereochemDone; // int
57 extern const std::string _NeedsQueryScan; // int (bool)
58 extern const std::string _fragSMARTS; // std::string
59 extern const std::string maxAttachIdx; // int TemplEnumTools.cpp
60 extern const std::string origNoImplicit; // int (bool)
61 extern const std::string ringMembership; //? unused (molopstest.cpp)
62 
63 // Computed Values
64 // ConnectivityDescriptors
65 extern const std::string _connectivityHKDeltas;// std::vector<double> computed
66 extern const std::string _connectivityNVals; // std::vector<double> computed
67 
68 extern const std::string _crippenLogP; // double computed
69 extern const std::string _crippenLogPContribs; // std::vector<double> computed
70 
71 extern const std::string _crippenMR; // double computed
72 extern const std::string _crippenMRContribs; // std::vector<double> computed
73 
74 extern const std::string _labuteASA; // double computed
75 extern const std::string _labuteAtomContribs; // vec<double> computed
76 extern const std::string _labuteAtomHContrib; // double computed
77 
78 extern const std::string _tpsa; // double computed
79 extern const std::string _tpsaAtomContribs; // vec<double> computed
80 
81 extern const std::string numArom; // int computed (only uses in tests?)
82 extern const std::string _MMFFSanitized; // int (bool) computed
83 
84 extern const std::string _CrippenLogP; // Unused (in the basement)
85 extern const std::string _CrippenMR; // Unused (in the basement)
86 
87 ///////////////////////////////////////////////////////////////
88 // Atom Props
89 
90 // Chirality stuff
91 extern const std::string _BondsPotentialStereo; // int (or bool) COMPUTED
92 extern const std::string _CIPCode; // std::string COMPUTED
93 extern const std::string _CIPRank; // int COMPUTED
94 extern const std::string _ChiralityPossible; // int
95 extern const std::string _UnknownStereo; // int (bool) AddHs/Chirality
96 extern const std::string _ringStereoAtoms; // int vect Canon/Chiral/MolHash/MolOps//Renumber//RWmol
97 extern const std::string _ringStereochemCand; // chirality bool COMPUTED
98 extern const std::string _ringStereoWarning; // obsolete ?
99 
100 // Smiles parsing
101 extern const std::string _SmilesStart; // int
102 extern const std::string _TraversalBondIndexOrder; // ? unused
103 extern const std::string _TraversalRingClosureBond; // unsigned int
104 extern const std::string _TraversalStartPoint; // bool
105 extern const std::string _queryRootAtom; // int SLNParse/SubstructMatch
106 extern const std::string _hasMassQuery; // atom bool
107 extern const std::string _protected; // atom int (bool)
108 extern const std::string _supplementalSmilesLabel; // atom string (SmilesWrite)
109 extern const std::string _unspecifiedOrder;// atom int (bool) smarts/smiles
110 extern const std::string _RingClosures; // INT_VECT smarts/smiles/canon
111 
112 // MDL Style Properties (MolFileParser)
113 extern const std::string molAtomMapNumber; // int
114 extern const std::string molFileAlias; // string
115 extern const std::string molFileValue; // string
116 extern const std::string molInversionFlag; // int
117 extern const std::string molParity; // int
118 extern const std::string molRxnComponent; // int
119 extern const std::string molRxnRole; // int
120 extern const std::string molTotValence; // int
121 extern const std::string _MolFileRLabel; // int
122 extern const std::string _MolFileChiralFlag; // int
123 
124 extern const std::string dummyLabel; // atom string
125 
126 // Reaction Information (Reactions.cpp)
127 extern const std::string _QueryFormalCharge; // int
128 extern const std::string _QueryHCount; // int
129 extern const std::string _QueryIsotope; // int
130 extern const std::string _QueryMass; // int = round(float * 1000)
131 extern const std::string _ReactionDegreeChanged; // int (bool)
132 extern const std::string NullBond; // int (bool)
133 extern const std::string _rgroupAtomMaps;
134 extern const std::string _rgroupBonds;
135 
136 // SLN
137 extern const std::string _AtomID; // unsigned int SLNParser
138 extern const std::string _starred; // atom int COMPUTED (SLN)
139 extern const std::string _SLN_s; // string SLNAttribs (chiral info)
140 extern const std::string _Unfinished_SLN_; // int (bool)
141 
142 // Smarts Smiles
143 extern const std::string _brokenChirality; // atom bool
144 extern const std::string isImplicit; // atom int (bool)
145 extern const std::string smilesSymbol; // atom string (only used in test?)
146 
147 // Tripos
148 extern const std::string _TriposAtomType; // string Mol2FileParser
149 // missing defs for _TriposAtomName//_TriposPartialCharge...
150 
151 
152 ///////////////////////////////////////////////////////////////
153 // misc props
154 extern const std::string TWOD; // need THREED -> confusing using in TDTMol supplier
155  // converge with _2DConf?
156 extern const std::string BalabanJ; // mol double
157 extern const std::string BalanbanJ; // typo!! fix...
158 
159 extern const std::string Discrims; // FragCatalog Entry
160  // Subgraphs::DiscrimTuple (uint32,uint32,uint32)
161 extern const std::string DistanceMatrix_Paths; // boost::shared_array<double>
162  // - note, confusing creation of names in
163  // - getDistanceMat
164 
165 } // end common_properties
166 #ifndef WIN32
167 typedef long long int LONGINT;
168 #else
169 typedef __int64 LONGINT;
170 #endif
171 #ifdef max
172 #undef max // FUCK I hate this nonsense
173 #endif
174 #ifdef min
175 #undef min // FUCK I hate this nonsense
176 #endif
177 
178 extern const double MAX_DOUBLE;
179 extern const double EPS_DOUBLE;
180 extern const double SMALL_DOUBLE;
181 extern const double MAX_INT;
182 extern const double MAX_LONGINT;
183 
184 typedef unsigned int UINT;
185 typedef unsigned short USHORT;
186 typedef unsigned char UCHAR;
187 
188 typedef std::vector<int> INT_VECT;
189 typedef INT_VECT::iterator INT_VECT_I;
190 typedef INT_VECT::const_iterator INT_VECT_CI;
191 typedef INT_VECT::reverse_iterator INT_VECT_RI;
192 typedef INT_VECT::const_reverse_iterator INT_VECT_CRI;
193 
194 typedef std::list<int> INT_LIST;
195 typedef INT_LIST::iterator INT_LIST_I;
196 typedef INT_LIST::const_iterator INT_LIST_CI;
197 
198 typedef std::list<INT_VECT> LIST_INT_VECT;
199 typedef LIST_INT_VECT::iterator LIST_INT_VECT_I;
200 typedef LIST_INT_VECT::const_iterator LIST_INT_VECT_CI;
201 
202 typedef std::vector<INT_VECT> VECT_INT_VECT;
203 typedef VECT_INT_VECT::iterator VECT_INT_VECT_I;
204 typedef VECT_INT_VECT::const_iterator VECT_INT_VECT_CI;
205 
206 typedef std::vector<UINT>::const_iterator UINT_VECT_CI;
207 typedef std::vector<UINT> UINT_VECT;
208 
209 typedef std::vector<std::string>::const_iterator STR_VECT_CI;
210 typedef std::vector<std::string>::iterator STR_VECT_I;
211 typedef std::vector<std::string> STR_VECT;
212 
213 typedef std::vector<double> DOUBLE_VECT;
214 typedef DOUBLE_VECT::iterator DOUBLE_VECT_I;
215 typedef DOUBLE_VECT::const_iterator DOUBLE_VECT_CI;
216 typedef std::vector<DOUBLE_VECT> VECT_DOUBLE_VECT;
217 typedef VECT_DOUBLE_VECT::iterator VECT_DOUBLE_VECT_I;
218 typedef VECT_DOUBLE_VECT::const_iterator VECT_DOUBLE_VECT_CI;
219 
220 typedef std::map<std::string, UINT> STR_UINT_MAP;
221 typedef std::map<std::string, UINT>::const_iterator STR_UINT_MAP_CI;
222 
223 typedef std::map<int, INT_VECT> INT_INT_VECT_MAP;
224 typedef INT_INT_VECT_MAP::const_iterator INT_INT_VECT_MAP_CI;
225 
226 typedef std::map<int, int> INT_MAP_INT;
227 typedef INT_MAP_INT::iterator INT_MAP_INT_I;
228 typedef INT_MAP_INT::const_iterator INT_MAP_INT_CI;
229 
230 typedef std::deque<int> INT_DEQUE;
231 typedef INT_DEQUE::iterator INT_DEQUE_I;
232 typedef INT_DEQUE::const_iterator INT_DEQUE_CI;
233 
234 typedef std::map<int, INT_DEQUE> INT_INT_DEQ_MAP;
235 typedef INT_INT_DEQ_MAP::const_iterator INT_INT_DEQ_MAP_CI;
236 
237 typedef std::set<int> INT_SET;
238 typedef INT_SET::iterator INT_SET_I;
239 typedef INT_SET::const_iterator INT_SET_CI;
240 
241 //! functor to compare two doubles with a tolerance
242 struct ltDouble {
243  public:
244  ltDouble() : _tol(1.0e-8){};
245  bool operator()(double d1, double d2) const {
246  if (fabs(d1 - d2) < _tol) {
247  return false;
248  } else {
249  return (d1 < d2);
250  }
251  }
252 
253  private:
254  double _tol;
255 };
256 
257 //! std::map from double to integer.
258 typedef std::map<double, int, ltDouble> DOUBLE_INT_MAP;
259 
260 //! functor for returning the larger of two values
261 template <typename T>
262 struct larger_of {
263  T operator()(T arg1, T arg2) { return arg1 > arg2 ? arg1 : arg2; };
264 };
265 
266 //! functor for comparing two strings
268  bool operator()(const char *s1, const char *s2) const {
269  // std::cout << s1 << " " << s2 << " " << strcmp(s1, s2) << "\n";
270 
271  return strcmp(s1, s2) < 0;
272  };
273 };
274 
275 //! \brief calculate the union of two INT_VECTs and put the results in a
276 //! third vector
277 void Union(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res);
278 
279 //! \brief calculate the intersection of two INT_VECTs and put the results in a
280 //! third vector
281 void Intersect(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res);
282 
283 //! calculating the union of the INT_VECT's in a VECT_INT_VECT
284 /*!
285  \param rings the INT_VECT's to consider
286  \param res used to return results
287  \param exclude any values in this optional INT_VECT will be excluded
288  from the union.
289 */
290 void Union(const VECT_INT_VECT &rings, INT_VECT &res,
291  const INT_VECT *exclude = NULL);
292 
293 //! given a current combination of numbers change it to the next possible
294 // combination
295 /*!
296  \param comb the <b>sorted</b> vector to consider
297  \param tot the maximum number possible in the vector
298 
299  \return -1 on failure, the index of the last number changed on success.
300  Example:
301  for all combinations 3 of numbers between 0 and tot=5
302  given (0,1,2) the function wil return (0,1,3) etc.
303 
304 
305 */
306 int nextCombination(INT_VECT &comb, int tot);
307 
308 //! rounds a value to the closest int
309 double round(double v);
310 
311 }; // end of namespace
312 
313 #endif
const std::string _StereochemDone
const std::string _protected
std::list< int > INT_LIST
Definition: types.h:194
unsigned short USHORT
Definition: types.h:185
const std::string isImplicit
const std::string origNoImplicit
void Union(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res)
calculate the union of two INT_VECTs and put the results in a third vector
VECT_DOUBLE_VECT::iterator VECT_DOUBLE_VECT_I
Definition: types.h:217
DOUBLE_VECT::const_iterator DOUBLE_VECT_CI
Definition: types.h:215
const std::string _labuteAtomHContrib
const std::string _connectivityNVals
const std::string _rgroupAtomMaps
VECT_INT_VECT::iterator VECT_INT_VECT_I
Definition: types.h:203
const std::string _3DConf
const std::string _RingClosures
functor to compare two doubles with a tolerance
Definition: types.h:242
const double MAX_INT
double round(double v)
rounds a value to the closest int
const std::string _labuteASA
const std::string _crippenLogP
const std::string _unspecifiedOrder
std::map< std::string, UINT >::const_iterator STR_UINT_MAP_CI
Definition: types.h:221
const std::string BalabanJ
std::vector< UINT >::const_iterator UINT_VECT_CI
Definition: types.h:206
const std::string _QueryMass
const std::string MolFileInfo
std::vector< double > DOUBLE_VECT
Definition: types.h:213
const std::string _SLN_s
const std::string molTotValence
const std::string _UnknownStereo
const std::string TWOD
INT_MAP_INT::const_iterator INT_MAP_INT_CI
Definition: types.h:228
const std::string _ReactionDegreeChanged
const std::string _ringStereoWarning
T operator()(T arg1, T arg2)
Definition: types.h:263
INT_SET::iterator INT_SET_I
Definition: types.h:238
const double MAX_DOUBLE
bool operator()(double d1, double d2) const
Definition: types.h:245
const std::string _Name
const std::string molAtomMapNumber
unsigned char UCHAR
Definition: types.h:186
const std::string molParity
INT_DEQUE::const_iterator INT_DEQUE_CI
Definition: types.h:232
const std::string NullBond
INT_LIST::iterator INT_LIST_I
Definition: types.h:195
std::vector< DOUBLE_VECT > VECT_DOUBLE_VECT
Definition: types.h:216
VECT_DOUBLE_VECT::const_iterator VECT_DOUBLE_VECT_CI
Definition: types.h:218
DOUBLE_VECT::iterator DOUBLE_VECT_I
Definition: types.h:214
INT_INT_DEQ_MAP::const_iterator INT_INT_DEQ_MAP_CI
Definition: types.h:235
const std::string MolFileComments
const std::string _2DConf
const std::string extraRings
Defines the Dict class.
const std::string _Unfinished_SLN_
const std::string _supplementalSmilesLabel
const std::string _crippenMRContribs
const std::string maxAttachIdx
INT_SET::const_iterator INT_SET_CI
Definition: types.h:239
const std::string _smilesAtomOutputOrder
functor for returning the larger of two values
Definition: types.h:262
const std::string _fragSMARTS
INT_MAP_INT::iterator INT_MAP_INT_I
Definition: types.h:227
const std::string _CIPRank
const std::string dummyLabel
const std::string _labuteAtomContribs
INT_VECT::const_reverse_iterator INT_VECT_CRI
Definition: types.h:192
std::vector< INT_VECT > VECT_INT_VECT
Definition: types.h:202
const std::string _tpsa
long long int LONGINT
Definition: types.h:167
const std::string _TraversalBondIndexOrder
functor for comparing two strings
Definition: types.h:267
const std::string _queryRootAtom
std::map< std::string, UINT > STR_UINT_MAP
Definition: types.h:220
const std::string BalanbanJ
const std::string _starred
std::vector< int > INT_VECT
Definition: types.h:188
const std::string _MMFFSanitized
std::set< int > INT_SET
Definition: types.h:237
INT_VECT::reverse_iterator INT_VECT_RI
Definition: types.h:191
std::vector< std::string >::const_iterator STR_VECT_CI
Definition: types.h:209
const std::string _QueryIsotope
bool operator()(const char *s1, const char *s2) const
Definition: types.h:268
const std::string molRxnRole
const std::string _CIPCode
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
unsigned int UINT
Definition: types.h:184
const std::string molRxnComponent
INT_VECT::iterator INT_VECT_I
Definition: types.h:189
LIST_INT_VECT::iterator LIST_INT_VECT_I
Definition: types.h:199
const std::string molInversionFlag
INT_VECT::const_iterator INT_VECT_CI
Definition: types.h:190
const std::string smilesSymbol
VECT_INT_VECT::const_iterator VECT_INT_VECT_CI
Definition: types.h:204
const std::string _QueryHCount
const std::string _NeedsQueryScan
std::map< double, int, ltDouble > DOUBLE_INT_MAP
std::map from double to integer.
Definition: types.h:258
const std::string numArom
const std::string _ringStereoAtoms
INT_DEQUE::iterator INT_DEQUE_I
Definition: types.h:231
const std::string _rgroupBonds
std::map< int, int > INT_MAP_INT
Definition: types.h:226
const std::string _BondsPotentialStereo
const std::string ringMembership
const std::string _MolFileChiralFlag
std::list< INT_VECT > LIST_INT_VECT
Definition: types.h:198
const std::string _AtomID
INT_LIST::const_iterator INT_LIST_CI
Definition: types.h:196
const std::string _QueryFormalCharge
void Intersect(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res)
calculate the intersection of two INT_VECTs and put the results in a third vector ...
const std::string _crippenMR
const std::string _MolFileRLabel
const std::string molFileValue
const std::string Discrims
std::map< int, INT_DEQUE > INT_INT_DEQ_MAP
Definition: types.h:234
std::map< int, INT_VECT > INT_INT_VECT_MAP
Definition: types.h:223
const std::string _hasMassQuery
std::vector< UINT > UINT_VECT
Definition: types.h:207
const double SMALL_DOUBLE
const std::string DistanceMatrix_Paths
INT_INT_VECT_MAP::const_iterator INT_INT_VECT_MAP_CI
Definition: types.h:224
std::deque< int > INT_DEQUE
Definition: types.h:230
const std::string _crippenLogPContribs
const double EPS_DOUBLE
const std::string _TraversalRingClosureBond
const std::string _ChiralityPossible
std::vector< std::string >::iterator STR_VECT_I
Definition: types.h:210
const std::string computedPropName
const std::string _TraversalStartPoint
const std::string _ringStereochemCand
const double MAX_LONGINT
const std::string _TriposAtomType
LIST_INT_VECT::const_iterator LIST_INT_VECT_CI
Definition: types.h:200
const std::string _connectivityHKDeltas
const std::string _CrippenMR
const std::string _tpsaAtomContribs
int nextCombination(INT_VECT &comb, int tot)
given a current combination of numbers change it to the next possible
const std::string _CrippenLogP
const std::string _brokenChirality
std::vector< std::string > STR_VECT
Definition: Dict.h:26
const std::string molFileAlias
const std::string _SmilesStart
const std::string _doIsoSmiles