RDKit
Open-source cheminformatics and machine learning.
DebugTrace.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2014 Novartis Institutes for BioMedical Research
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 #pragma once
11 #include <stdio.h>
12 #include <string.h>
13 #include <stddef.h>
14 #include <time.h>
15 #include <iostream>
16 #ifdef WIN32
17 #define _CRT_SECURE_NO_WARNINGS
18 #include <Windows.h> // for Winmm.lib timeGetTime()
19 #ifdef _DEBUG // check memory leaks
20 #include <crtdbg.h>
21 #define _CRTDBG_MAP_ALLOC
22 #ifndef new
23 #define new new( _NORMAL_BLOCK, __FILE__, __LINE__)
24 #endif
25 #endif
26 #else
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <sys/time.h>
30 #include <sys/resource.h>
31 #endif
32 
33 // SELECT ALGORITHM OPTIONS by comment some lines to exclude additional or experimental optimisations:
34 
35 #define SEED_GROW_DEEP // fast and works much times faster (but it can depend on molecules)
36 //#define EXCLUDE_WRONG_COMPOSITION // fast but with a little effect, because amount of external bonds usually is very small.
37 // Exclude mismatched bonds combinations during seed growing (2^N-1 stage)
38 
39 #define FAST_SUBSTRUCT_CACHE // based on a hash of Morgan code
40 #define DUP_SUBSTRUCT_CACHE // based on list of query atoms and bonds. For rings where seeds growing in both directions throw the same ring.
41 
42 #define FAST_INCREMENTAL_MATCH // fast and some time very usefull. request PRECOMPUTED_TABLES_MATCH
43 // previous match result based match checking without finding new matched substructure location in the target
44 
45 #define VERBOSE_STATISTICS_ON
46 
47 
48 #ifdef WIN32
49 #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
50 
51 struct timezone {
52  int tz_minuteswest; // minutes W of Greenwich
53  int tz_dsttime; // type of dst correction
54 };
55 
56 static inline int gettimeofday(struct timeval *tv, struct timezone *tz) {
57  FILETIME ft;
58  unsigned __int64 tmpres = 0;
59  static int tzflag;
60 
61  if (NULL != tv) {
62  GetSystemTimeAsFileTime(&ft);
63 
64  tmpres |= ft.dwHighDateTime;
65  tmpres <<= 32;
66  tmpres |= ft.dwLowDateTime;
67 
68  //converting file time to unix epoch
69  tmpres -= DELTA_EPOCH_IN_MICROSECS;
70  tmpres /= 10; //convert into microseconds
71  tv->tv_sec = (long)(tmpres / 1000000UL);
72  tv->tv_usec = (long)(tmpres % 1000000UL);
73  }
74 
75  if (NULL != tz) {
76  if (!tzflag) {
77  _tzset();
78  tzflag++;
79  }
80  tz->tz_minuteswest = _timezone / 60;
81  tz->tz_dsttime = _daylight;
82  }
83  return 0;
84 }
85 #endif
86 
87 static inline unsigned long long nanoClock (void) { // actually returns microseconds
88  struct timeval t;
89  gettimeofday(&t, (struct timezone*)0);
90  return t.tv_usec + t.tv_sec * 1000000ULL;
91 }
92 
93 namespace RDKit {
94  namespace FMCS {
95 
96 #ifdef VERBOSE_STATISTICS_ON
97 
98 // compute statistics of really very very fast calls.
99 // It a bit decrease overal performance, but might be interested for investigation purpose (only)
100 //#define VERBOSE_STATISTICS_FASTCALLS_ON
101 
102  struct ExecStatistics {
103  unsigned TotalSteps, MCSFoundStep;
104  unsigned long long MCSFoundTime;
105  unsigned InitialSeed, MismatchedInitialSeed;
106  unsigned Seed, RemainingSizeRejected;
107  unsigned SeedCheck, SingleBondExcluded;
108  unsigned MatchCall, MatchCallTrue;
109  unsigned FastMatchCall, FastMatchCallTrue, SlowMatchCallTrue;
110  unsigned ExactMatchCall, ExactMatchCallTrue; // hash cache
111  unsigned FindHashInCache, HashKeyFoundInCache;
112  unsigned AtomCompareCalls, BondCompareCalls; // long long
113  unsigned AtomFunctorCalls, BondFunctorCalls; // long long
114  unsigned WrongCompositionRejected, WrongCompositionDetected;
115  unsigned DupCacheFound, DupCacheFoundMatch;
116 
117  ExecStatistics() : TotalSteps(0), MCSFoundStep(0)
118  , MCSFoundTime(nanoClock())
119  , InitialSeed(0), MismatchedInitialSeed(0)
120  , Seed(0), RemainingSizeRejected(0)
121  , SeedCheck(0), SingleBondExcluded(0), MatchCall(0), MatchCallTrue(0)
122  , FastMatchCall(0), FastMatchCallTrue(0), SlowMatchCallTrue(0)
123  , ExactMatchCall(0), ExactMatchCallTrue(0)
124  , FindHashInCache(0), HashKeyFoundInCache(0)
125  , AtomCompareCalls(0), BondCompareCalls(0)
126  , AtomFunctorCalls(0), BondFunctorCalls(0)
127  , WrongCompositionRejected(0), WrongCompositionDetected(0)
128  , DupCacheFound(0), DupCacheFoundMatch(0)
129  {}
130  };
131 #endif
132 
133  }
134 }
static unsigned long long nanoClock(void)
Definition: DebugTrace.h:87
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
unsigned long long MCSFoundTime
Definition: DebugTrace.h:104