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 extern const std::string internalRgroupSmiles;
167 
168 } // end common_properties
169 #ifndef WIN32
170 typedef long long int LONGINT;
171 #else
172 typedef __int64 LONGINT;
173 #endif
174 #ifdef max
175 #undef max // FUCK I hate this nonsense
176 #endif
177 #ifdef min
178 #undef min // FUCK I hate this nonsense
179 #endif
180 
181 extern const double MAX_DOUBLE;
182 extern const double EPS_DOUBLE;
183 extern const double SMALL_DOUBLE;
184 extern const double MAX_INT;
185 extern const double MAX_LONGINT;
186 
187 typedef unsigned int UINT;
188 typedef unsigned short USHORT;
189 typedef unsigned char UCHAR;
190 
191 typedef std::vector<int> INT_VECT;
192 typedef INT_VECT::iterator INT_VECT_I;
193 typedef INT_VECT::const_iterator INT_VECT_CI;
194 typedef INT_VECT::reverse_iterator INT_VECT_RI;
195 typedef INT_VECT::const_reverse_iterator INT_VECT_CRI;
196 
197 typedef std::list<int> INT_LIST;
198 typedef INT_LIST::iterator INT_LIST_I;
199 typedef INT_LIST::const_iterator INT_LIST_CI;
200 
201 typedef std::list<INT_VECT> LIST_INT_VECT;
202 typedef LIST_INT_VECT::iterator LIST_INT_VECT_I;
203 typedef LIST_INT_VECT::const_iterator LIST_INT_VECT_CI;
204 
205 typedef std::vector<INT_VECT> VECT_INT_VECT;
206 typedef VECT_INT_VECT::iterator VECT_INT_VECT_I;
207 typedef VECT_INT_VECT::const_iterator VECT_INT_VECT_CI;
208 
209 typedef std::vector<UINT>::const_iterator UINT_VECT_CI;
210 typedef std::vector<UINT> UINT_VECT;
211 
212 typedef std::vector<std::string>::const_iterator STR_VECT_CI;
213 typedef std::vector<std::string>::iterator STR_VECT_I;
214 typedef std::vector<std::string> STR_VECT;
215 
216 typedef std::vector<double> DOUBLE_VECT;
217 typedef DOUBLE_VECT::iterator DOUBLE_VECT_I;
218 typedef DOUBLE_VECT::const_iterator DOUBLE_VECT_CI;
219 typedef std::vector<DOUBLE_VECT> VECT_DOUBLE_VECT;
220 typedef VECT_DOUBLE_VECT::iterator VECT_DOUBLE_VECT_I;
221 typedef VECT_DOUBLE_VECT::const_iterator VECT_DOUBLE_VECT_CI;
222 
223 typedef std::map<std::string, UINT> STR_UINT_MAP;
224 typedef std::map<std::string, UINT>::const_iterator STR_UINT_MAP_CI;
225 
226 typedef std::map<int, INT_VECT> INT_INT_VECT_MAP;
227 typedef INT_INT_VECT_MAP::const_iterator INT_INT_VECT_MAP_CI;
228 
229 typedef std::map<int, int> INT_MAP_INT;
230 typedef INT_MAP_INT::iterator INT_MAP_INT_I;
231 typedef INT_MAP_INT::const_iterator INT_MAP_INT_CI;
232 
233 typedef std::deque<int> INT_DEQUE;
234 typedef INT_DEQUE::iterator INT_DEQUE_I;
235 typedef INT_DEQUE::const_iterator INT_DEQUE_CI;
236 
237 typedef std::map<int, INT_DEQUE> INT_INT_DEQ_MAP;
238 typedef INT_INT_DEQ_MAP::const_iterator INT_INT_DEQ_MAP_CI;
239 
240 typedef std::set<int> INT_SET;
241 typedef INT_SET::iterator INT_SET_I;
242 typedef INT_SET::const_iterator INT_SET_CI;
243 
244 //! functor to compare two doubles with a tolerance
245 struct ltDouble {
246  public:
247  ltDouble() : _tol(1.0e-8){};
248  bool operator()(double d1, double d2) const {
249  if (fabs(d1 - d2) < _tol) {
250  return false;
251  } else {
252  return (d1 < d2);
253  }
254  }
255 
256  private:
257  double _tol;
258 };
259 
260 //! std::map from double to integer.
261 typedef std::map<double, int, ltDouble> DOUBLE_INT_MAP;
262 
263 //! functor for returning the larger of two values
264 template <typename T>
265 struct larger_of {
266  T operator()(T arg1, T arg2) { return arg1 > arg2 ? arg1 : arg2; };
267 };
268 
269 //! functor for comparing two strings
271  bool operator()(const char *s1, const char *s2) const {
272  // std::cout << s1 << " " << s2 << " " << strcmp(s1, s2) << "\n";
273 
274  return strcmp(s1, s2) < 0;
275  };
276 };
277 
278 //! \brief calculate the union of two INT_VECTs and put the results in a
279 //! third vector
280 void Union(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res);
281 
282 //! \brief calculate the intersection of two INT_VECTs and put the results in a
283 //! third vector
284 void Intersect(const INT_VECT &r1, const INT_VECT &r2, INT_VECT &res);
285 
286 //! calculating the union of the INT_VECT's in a VECT_INT_VECT
287 /*!
288  \param rings the INT_VECT's to consider
289  \param res used to return results
290  \param exclude any values in this optional INT_VECT will be excluded
291  from the union.
292 */
293 void Union(const VECT_INT_VECT &rings, INT_VECT &res,
294  const INT_VECT *exclude = NULL);
295 
296 //! given a current combination of numbers change it to the next possible
297 // combination
298 /*!
299  \param comb the <b>sorted</b> vector to consider
300  \param tot the maximum number possible in the vector
301 
302  \return -1 on failure, the index of the last number changed on success.
303  Example:
304  for all combinations 3 of numbers between 0 and tot=5
305  given (0,1,2) the function wil return (0,1,3) etc.
306 
307 
308 */
309 int nextCombination(INT_VECT &comb, int tot);
310 
311 //! rounds a value to the closest int
312 double round(double v);
313 
314 }; // end of namespace
315 
316 #endif
const std::string _StereochemDone
const std::string _protected
std::list< int > INT_LIST
Definition: types.h:197
unsigned short USHORT
Definition: types.h:188
const std::string isImplicit
const std::string origNoImplicit
bool operator()(double d1, double d2) const
Definition: types.h:248
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:220
DOUBLE_VECT::const_iterator DOUBLE_VECT_CI
Definition: types.h:218
const std::string _labuteAtomHContrib
const std::string _connectivityNVals
const std::string _rgroupAtomMaps
VECT_INT_VECT::iterator VECT_INT_VECT_I
Definition: types.h:206
const std::string _3DConf
const std::string _RingClosures
functor to compare two doubles with a tolerance
Definition: types.h:245
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:224
const std::string BalabanJ
std::vector< UINT >::const_iterator UINT_VECT_CI
Definition: types.h:209
const std::string _QueryMass
const std::string MolFileInfo
std::vector< double > DOUBLE_VECT
Definition: types.h:216
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:231
const std::string _ReactionDegreeChanged
const std::string _ringStereoWarning
T operator()(T arg1, T arg2)
Definition: types.h:266
INT_SET::iterator INT_SET_I
Definition: types.h:241
const double MAX_DOUBLE
const std::string _Name
const std::string molAtomMapNumber
unsigned char UCHAR
Definition: types.h:189
const std::string molParity
INT_DEQUE::const_iterator INT_DEQUE_CI
Definition: types.h:235
const std::string NullBond
INT_LIST::iterator INT_LIST_I
Definition: types.h:198
std::vector< DOUBLE_VECT > VECT_DOUBLE_VECT
Definition: types.h:219
VECT_DOUBLE_VECT::const_iterator VECT_DOUBLE_VECT_CI
Definition: types.h:221
DOUBLE_VECT::iterator DOUBLE_VECT_I
Definition: types.h:217
INT_INT_DEQ_MAP::const_iterator INT_INT_DEQ_MAP_CI
Definition: types.h:238
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:242
const std::string _smilesAtomOutputOrder
functor for returning the larger of two values
Definition: types.h:265
const std::string _fragSMARTS
INT_MAP_INT::iterator INT_MAP_INT_I
Definition: types.h:230
const std::string _CIPRank
const std::string dummyLabel
const std::string _labuteAtomContribs
INT_VECT::const_reverse_iterator INT_VECT_CRI
Definition: types.h:195
std::vector< INT_VECT > VECT_INT_VECT
Definition: types.h:205
const std::string _tpsa
long long int LONGINT
Definition: types.h:170
const std::string _TraversalBondIndexOrder
functor for comparing two strings
Definition: types.h:270
const std::string _queryRootAtom
std::map< std::string, UINT > STR_UINT_MAP
Definition: types.h:223
const std::string BalanbanJ
const std::string _starred
std::vector< int > INT_VECT
Definition: types.h:191
const std::string _MMFFSanitized
std::set< int > INT_SET
Definition: types.h:240
INT_VECT::reverse_iterator INT_VECT_RI
Definition: types.h:194
std::vector< std::string >::const_iterator STR_VECT_CI
Definition: types.h:212
const std::string _QueryIsotope
bool operator()(const char *s1, const char *s2) const
Definition: types.h:271
const std::string molRxnRole
const std::string _CIPCode
Std stuff.
Definition: Atom.h:29
unsigned int UINT
Definition: types.h:187
const std::string molRxnComponent
INT_VECT::iterator INT_VECT_I
Definition: types.h:192
LIST_INT_VECT::iterator LIST_INT_VECT_I
Definition: types.h:202
const std::string molInversionFlag
INT_VECT::const_iterator INT_VECT_CI
Definition: types.h:193
const std::string smilesSymbol
VECT_INT_VECT::const_iterator VECT_INT_VECT_CI
Definition: types.h:207
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:261
const std::string internalRgroupSmiles
const std::string numArom
const std::string _ringStereoAtoms
INT_DEQUE::iterator INT_DEQUE_I
Definition: types.h:234
const std::string _rgroupBonds
std::map< int, int > INT_MAP_INT
Definition: types.h:229
const std::string _BondsPotentialStereo
const std::string ringMembership
const std::string _MolFileChiralFlag
std::list< INT_VECT > LIST_INT_VECT
Definition: types.h:201
const std::string _AtomID
INT_LIST::const_iterator INT_LIST_CI
Definition: types.h:199
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:237
std::map< int, INT_VECT > INT_INT_VECT_MAP
Definition: types.h:226
const std::string _hasMassQuery
std::vector< UINT > UINT_VECT
Definition: types.h:210
const double SMALL_DOUBLE
const std::string DistanceMatrix_Paths
INT_INT_VECT_MAP::const_iterator INT_INT_VECT_MAP_CI
Definition: types.h:227
std::deque< int > INT_DEQUE
Definition: types.h:233
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:213
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:203
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