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