~ubuntu-branches/ubuntu/feisty/openbabel/feisty

« back to all changes in this revision

Viewing changes to src/formats/inchi/ichicant.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-05-14 19:46:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060514194601-h3j1wovvc42cigxl
Tags: 2.0.1-1
* New upstream release. (Closes: #341628)
* debian/patches/04_zipstream_fix.diff: Removed, applied upstream.
* debian/rules (DEB_MAKE_CHECK_TARGET): Readded.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * International Union of Pure and Applied Chemistry (IUPAC)
 
3
 * International Chemical Identifier (InChI)
 
4
 * Version 1
 
5
 * Software version 1.00
 
6
 * April 13, 2005
 
7
 * Developed at NIST
 
8
 */
 
9
 
 
10
#ifndef __INCHICANT_H__
 
11
#define __INCHICANT_H__
 
12
 
 
13
/******************************************************/
 
14
/*                                                    */
 
15
/*                 Canonicalization definitions       */
 
16
/*                                                    */
 
17
/******************************************************/
 
18
#include "ichisize.h"
 
19
 
 
20
 
 
21
#ifndef INCHI_US_SHORT_DEF
 
22
typedef signed short S_SHORT;
 
23
typedef unsigned short U_SHORT;
 
24
#define INCHI_US_SHORT_DEF
 
25
#endif
 
26
 
 
27
/*typedef unsigned long  INCHI_MODE;*/
 
28
 
 
29
typedef union tagSplitLong {
 
30
    unsigned long  ul;
 
31
    U_SHORT        us[2];
 
32
}SU_LONG;
 
33
 
 
34
#define _HI 1                            /* Intel platform */
 
35
#define _LO 0
 
36
 
 
37
#define NEIGH_LIST_LEN 4
 
38
#define U_LONG_LEN  2
 
39
 
 
40
#ifndef defined_NEIGH_LIST
 
41
typedef AT_RANK  *NEIGH_LIST;
 
42
#define defined_NEIGH_LIST
 
43
#endif
 
44
 
 
45
typedef struct tagEQUIV_INFO {
 
46
    int nNumSets;
 
47
    int *nCutVertexAtom; /* cut-vertex atom for the set of equivalent atoms */
 
48
    int *nFirstInSet;    /* first of equivalent atoms in the connected to the cut-vertex atom parts of the structure */
 
49
    int *nNumInSet;      /* number of the equivalent atoms connected to the cut-vertex atom */
 
50
    int *nAtomNo;        /* eqivalent atom number */
 
51
    int *nAddToRank;     /* number to add to the rank to normalize */
 
52
} EQUIV_INFO;
 
53
 
 
54
#define MOL_PART_MASK  (~0x0U ^ 0x07U)
 
55
 
 
56
 
 
57
typedef struct tagAtData_dch {
 
58
     char element[3];
 
59
     int valence;
 
60
   }AT_DATA;
 
61
 
 
62
 
 
63
#define MAXVAL 20       /* maximum valence */
 
64
 
 
65
#define ATOM_EL_LEN 6
 
66
 
 
67
typedef struct tagAtomInvariantBytes {
 
68
    S_CHAR cNotExactlyHillOrderNumber;
 
69
    S_CHAR cNumberOfConnections;
 
70
    /* S_CHAR cNumberOfNonHydrogenBonds; */
 
71
    S_CHAR cAtomicNumber;
 
72
#if( HYDROGENS_IN_INIT_RANKS == 1 ) 
 
73
    S_CHAR cNumberOfAttachedHydrogens;
 
74
#endif
 
75
} ATOM_INVARIANT_BYTES;
 
76
 
 
77
typedef struct tagAtomInvariant {
 
78
    /* non-isotopic part */
 
79
#if( USE_DISTANCES_FOR_RANKING == 1 )
 
80
    AT_RANK         nDistanceFromTerminal;
 
81
#endif
 
82
    ATOM_INVARIANT_BYTES b;
 
83
    AT_RANK         cNum_tautomer;        /* 0 or for tautomer endpoint: number of endpoints in the group */
 
84
    AT_RANK         cNum_tautomer_num[T_NUM_NO_ISOTOPIC]; /* 0 or numbers from t_gtroup */
 
85
    /* isotopic part */
 
86
    AT_ISO_SORT_KEY iso_sort_key;
 
87
    AT_RANK         cNum_tautomer_iso[T_NUM_ISOTOPIC]; /* 0 or numbers from t_group */
 
88
} ATOM_INVARIANT;
 
89
/**********************************/
 
90
typedef enum tagAtInvariantIndexes {
 
91
    AT_INV_HILL_ORDER,
 
92
    AT_INV_NUM_CONNECTIONS,
 
93
    AT_INV_NUM_H,
 
94
    /* for endpoint + undirected graph, otherwise 0 */
 
95
    AT_INV_NUM_TG_ENDPOINTS,
 
96
    AT_INV_TG_NUMBERS,       /* num H, num (-) */
 
97
    AT_INV_NUM_H_FIX = AT_INV_TG_NUMBERS+T_NUM_NO_ISOTOPIC,
 
98
    AT_INV_BREAK1,
 
99
    /* here compare iso sort key */
 
100
    AT_INV_TAUT_ISO = AT_INV_BREAK1,
 
101
    AT_INV_LENGTH   = AT_INV_TAUT_ISO + T_NUM_ISOTOPIC
 
102
} AT_INV_INDEXES;
 
103
 
 
104
typedef struct tagAtomInvariant2 {
 
105
    AT_NUMB         val[AT_INV_LENGTH];
 
106
    AT_ISO_SORT_KEY iso_sort_key;
 
107
    S_CHAR          iso_aux_key;
 
108
} ATOM_INVARIANT2;
 
109
 
 
110
/******************* Partition **********************************/
 
111
typedef struct tagPartition {
 
112
    AT_RANK *Rank;
 
113
    AT_NUMB *AtNumber;
 
114
} Partition;
 
115
 
 
116
/********************* BFCN *************************************/
 
117
typedef struct tagFixHOrTautCanonNumbering {
 
118
 
 
119
    int             num_at_tg;  /* = num_atoms for non-taut */
 
120
    int             num_atoms;
 
121
    int             nCanonFlags;
 
122
    NEIGH_LIST     *NeighList;  /* length = num_at_tg */
 
123
    /****************************/
 
124
    /*     base structure       */
 
125
    /****************************/
 
126
    AT_RANK        *LinearCt;      /* connection table atoms (+taut. groups, directed graph)*/
 
127
    int             nLenLinearCtAtOnly;
 
128
    int             nLenLinearCt;
 
129
    int             nMaxLenLinearCt;
 
130
 
 
131
    Partition       PartitionCt;  /* canonical numbering */
 
132
    AT_RANK        *nSymmRankCt;  /* orbits */
 
133
 
 
134
    /* orig. fixed by tautomerism H positions */
 
135
    NUM_H          *nNumHOrig;  /* original  H atoms positions + taut. info, excluding tautomeric H */
 
136
    NUM_H          *nNumH;      /* canonical H atoms positions + taut. info, excluding tautomeric H */
 
137
    int             nLenNumH;   /* length = num_atoms + 2*num_taut_groups */
 
138
 
 
139
    /* fixed H: original positions of tautomeric H; exists obly for tautomeric structures */
 
140
    NUM_H          *nNumHOrigFixH;  /* original fixed positions of tautomeric H */
 
141
    NUM_H          *nNumHFixH;      /* canonical fixed positions of tautomeric H */
 
142
    int             nLenNumHFixH;   /* length = num_atoms */
 
143
 
 
144
    /*******************************************************************************/
 
145
    /* the following exists only if isotopic and isotopic results requested        */
 
146
    /*******************************************************************************/
 
147
    Partition       PartitionCtIso;     /* canonical numbering of isotopic base structure, defined later */
 
148
    AT_RANK        *nSymmRankCtIso;     /* orbits of isotopic structure */
 
149
    AT_ISO_SORT_KEY *iso_sort_keys;     /* original isotopic sort keys for atoms and taut groups */
 
150
    AT_ISO_SORT_KEY *iso_sort_keysOrig; /* canonical isotopic sort keys for atoms and taut groups */
 
151
    int              len_iso_sort_keys;
 
152
    S_CHAR          *iso_exchg_atnos;     /* canonical: 0=> tautomeric or may have isotopic H exchanged */
 
153
    S_CHAR          *iso_exchg_atnosOrig; /* original: 0=> tautomeric or may have isotopic H exchanged */
 
154
    
 
155
} FTCN;
 
156
 
 
157
/******************** BCN *************************************/
 
158
typedef struct tagBaseCanonNumbering {
 
159
 
 
160
    AT_RANK            **pRankStack;
 
161
    int                  nMaxLenRankStack;
 
162
    int                  num_max;        /* allocated nRank[] arrays lengths in pRankStack */
 
163
    int                  num_at_tg;  /* all of the following arrays have this length */
 
164
    int                  num_atoms;
 
165
    struct tagInchiTime *ulTimeOutTime;
 
166
    FTCN                 ftcn[TAUT_NUM];
 
167
 
 
168
} BCN;
 
169
 
 
170
/***********************************
 
171
 *
 
172
 *  CANON_STAT
 
173
 */
 
174
typedef struct tagCanonStat {
 
175
    /*  statistics */
 
176
    long                 lNumBreakTies;
 
177
    long                 lNumNeighListIter;
 
178
    long                 lNumTotCT;
 
179
    long                 lNumDecreasedCT;
 
180
    long                 lNumRejectedCT;
 
181
    long                 lNumEqualCT;
 
182
    struct tagInchiTime *ulTimeOutTime;
 
183
    long                 lTotalTime;
 
184
 
 
185
    /* control */
 
186
    int                  bFirstCT;
 
187
    int                  bKeepSymmRank;
 
188
    int                  bStereoIsBetter;
 
189
 
 
190
    int nCanonFlags;
 
191
 
 
192
    /* data : */
 
193
 
 
194
    AT_NUMB          *LinearCT;        /* connection table only */
 
195
    AT_ISOTOPIC      *LinearCTIsotopic;
 
196
    AT_ISO_TGROUP    *LinearCTIsotopicTautomer;
 
197
    AT_STEREO_DBLE   *LinearCTStereoDble;
 
198
    AT_STEREO_CARB   *LinearCTStereoCarb;
 
199
    AT_STEREO_DBLE   *LinearCTStereoDbleInv;
 
200
    AT_STEREO_CARB   *LinearCTStereoCarbInv;
 
201
    AT_STEREO_DBLE   *LinearCTIsotopicStereoDble;
 
202
    AT_STEREO_CARB   *LinearCTIsotopicStereoCarb;
 
203
    AT_STEREO_DBLE   *LinearCTIsotopicStereoDbleInv;
 
204
    AT_STEREO_CARB   *LinearCTIsotopicStereoCarbInv;
 
205
    AT_TAUTOMER      *LinearCTTautomer;  /*  minimal */
 
206
 
 
207
/* second copies of line notation arrays */
 
208
 
 
209
    AT_NUMB          *LinearCT2;   /* to save non-isotopic CT */
 
210
 
 
211
    int               nLenLinearCTStereoDble;
 
212
    int               nLenLinearCTStereoDbleInv;
 
213
    int               nMaxLenLinearCTStereoDble;  /* new */
 
214
 
 
215
    int               bCmpStereo;         /* 0 => no stereo to invert;
 
216
                                             1 => StereoCtInv < StereoCt;
 
217
                                             2 => StereoCtInv = StereoCt;
 
218
                                             3 => StereoCtInv > StereoCt;
 
219
                                           */  
 
220
    int               nLenLinearCTStereoCarb;
 
221
    int               nLenLinearCTStereoCarbInv;
 
222
    int               nMaxLenLinearCTStereoCarb;  /* new */
 
223
    
 
224
    int               nLenLinearCTIsotopic;
 
225
    int               nMaxLenLinearCTIsotopic;
 
226
 
 
227
    int               nLenLinearCTIsotopicTautomer;
 
228
    int               nMaxLenLinearCTIsotopicTautomer;
 
229
 
 
230
    int               nLenLinearCT;         /* connection table only  */
 
231
    int               nLenLinearCT2;        /* connection table only, non-isotopic result  */
 
232
    int               nLenLinearCTAtOnly;   /* connection table only without tautomeric pseudoatoms  */
 
233
    int               nLenLinearCTAtOnly2;  /* connection table only, non-isotopic result without tautomeric pseudoatoms  */
 
234
    int               nMaxLenLinearCT;      /* connection table only  */
 
235
 
 
236
    int               nLenLinearCTTautomer;
 
237
    int               nMaxLenLinearCTTautomer;
 
238
    
 
239
    int               bCmpIsotopicStereo; /* 0 => no stereo to invert;
 
240
                                             1 => StereoCtInv < StereoCt;
 
241
                                             2 => StereoCtInv = StereoCt;
 
242
                                             3 => StereoCtInv > StereoCt;
 
243
                                           */  
 
244
    int               nLenLinearCTIsotopicStereoDble;
 
245
    int               nLenLinearCTIsotopicStereoDbleInv;
 
246
    int               nMaxLenLinearCTIsotopicStereoDble;
 
247
 
 
248
    int               nLenLinearCTIsotopicStereoCarb; /*  new */
 
249
    int               nLenLinearCTIsotopicStereoCarbInv; /*  new */
 
250
    int               nMaxLenLinearCTIsotopicStereoCarb;
 
251
    S_CHAR           *bRankUsedForStereo;  /* canon. rank used for stereo mapping */
 
252
    S_CHAR           *bAtomUsedForStereo;  /* 0 if not a stereo atom or during a canon. rank being mapped on this atom; */
 
253
                                           /* STEREO_AT_MARK if an unpapped stereogenic atom */
 
254
                                           /* or a number of stereogenic bonds adjacent to an atom */
 
255
    
 
256
    AT_RANK          *nPrevAtomNumber;
 
257
 
 
258
    AT_RANK          *nCanonOrd;       /* atom numbers in order of increasing canon. ranks  */
 
259
    AT_RANK          *nSymmRank;       /* symmetry numbers in order of atoms  */
 
260
    AT_RANK          *nCanonOrdTaut;   /* t-group numbers numbers in order of increasing canon. ranks  */
 
261
    AT_RANK          *nSymmRankTaut;   /* t-group symmetry numbers in order of t-groups  */
 
262
 
 
263
    AT_RANK          *nCanonOrdStereo;     /* atom numbers in order of increasing canon. ranks */
 
264
    AT_RANK          *nCanonOrdStereoInv;     /* atom numbers in order of increasing canon. ranks */
 
265
    AT_RANK          *nCanonOrdStereoTaut; /* t-group numbers in order of increasing canon. ranks */
 
266
    
 
267
    AT_RANK          *nSymmRankIsotopic;
 
268
    AT_RANK          *nCanonOrdIsotopic;        /* atom numbers in order of increasing canon. ranks */
 
269
    AT_RANK          *nSymmRankIsotopicTaut;    /* !!! */
 
270
    AT_RANK          *nCanonOrdIsotopicTaut;    /*/ t-group numbers in order of increasing canon. ranks */
 
271
 
 
272
    AT_RANK          *nCanonOrdIsotopicStereo;
 
273
    AT_RANK          *nCanonOrdIsotopicStereoInv;
 
274
    AT_RANK          *nCanonOrdIsotopicStereoTaut;    /*  !!! */
 
275
 
 
276
                      /* actual lengths if successfully calculated */
 
277
 
 
278
    int               nLenCanonOrd;               /* Superceded by any of the following > 0 */
 
279
    int               nLenCanonOrdTaut;           /* !!! Superceded by any of the following > 0 */
 
280
    int               nLenCanonOrdIsotopic;
 
281
    int               nLenCanonOrdIsotopicTaut;   /* !!! */
 
282
    int               nLenCanonOrdStereo;
 
283
    int               nLenCanonOrdStereoTaut;     /* !!! */
 
284
    int               nLenCanonOrdIsotopicStereo;
 
285
    int               nLenCanonOrdIsotopicStereoTaut; /* !!! */
 
286
 
 
287
                      /*  other */
 
288
 
 
289
    int               bHasIsotopicInTautomerGroups;
 
290
    T_GROUP_INFO     *t_group_info;
 
291
    int               bIgnoreIsotopic;
 
292
    int               bDoubleBondSquare; /* 0 or 2 */
 
293
    INCHI_MODE         nMode;
 
294
#if( bRELEASE_VERSION == 0 )
 
295
    int               bExtract;          /* for debug only */
 
296
#endif
 
297
    NEIGH_LIST       *NeighList;
 
298
    BCN              *pBCN;
 
299
    S_CHAR    *nNum_H;      /* number of terminal hydrogen atoms on each atom except tautomeric [num_atoms], in order of canonical numbers */
 
300
    S_CHAR    *nNum_H_fixed;/* number of terminal hydrogen atoms on tautomeric atoms (for non-atautomeric representation) [num_atoms] */
 
301
    S_CHAR    *nExchgIsoH;
 
302
} CANON_STAT;
 
303
 
 
304
/**************************************************/
 
305
typedef struct tagCanonData {
 
306
    
 
307
    /* same names/types as in ConTable; here the order is from original numbering */
 
308
    
 
309
    AT_NUMB *LinearCT;  /* output ?? */
 
310
    
 
311
    int      nMaxLenLinearCT;
 
312
    int      nLenLinearCT;
 
313
    int      nLenCTAtOnly;
 
314
    int      nCanonFlags;
 
315
    /* hydrogen atoms fixed in tautomeric representation:
 
316
       compare before diff sign inversion: (+) <=> Ct1->() > Ct2->() */
 
317
    NUM_H          *NumH;      
 
318
    int             lenNumH;    /* used length */
 
319
    int             maxlenNumH; /*  n + T_NUM_NO_ISOTOPIC*(n_tg-n) + 1 */
 
320
 
 
321
    /* hydrogen atoms fixed in non-tautomeric representation only:
 
322
       compare before diff sign inversion: (+) <=> Ct1->() > Ct2->() */
 
323
    NUM_H           *NumHfixed;          
 
324
    int              lenNumHfixed;       /* used length */   
 
325
    int              maxlenNumHfixed;    /* max length = n+1  */
 
326
 
 
327
    /* isotopic atoms (without tautomeric H) and isotopic tautomeric groups */
 
328
    /* note: AT_ISO_SORT_KEY and T_GROUP_ISOWT are identical types: long    */
 
329
    AT_ISO_SORT_KEY *iso_sort_key;        
 
330
    int              len_iso_sort_key;    /* used length */
 
331
    int              maxlen_iso_sort_key; /* max length = n_tg+1 */
 
332
    S_CHAR          *iso_exchg_atnos;
 
333
    int              len_iso_exchg_atnos;    /* used length */
 
334
    int              maxlen_iso_exchg_atnos;
 
335
 
 
336
    /* isotopic hydrogen atoms fixed in non-tautomeric representation only */
 
337
#if ( USE_ISO_SORT_KEY_HFIXED == 1 )       
 
338
    AT_ISO_SORT_KEY *iso_sort_key_Hfixed;     
 
339
    int              len_iso_sort_key_Hfixed;    /* used length */    
 
340
    int              maxlen_iso_sort_key_Hfixed; /* max length = n+1  */
 
341
#endif
 
342
    /* auxiliary ranking */
 
343
 
 
344
    AT_RANK  *nAuxRank;
 
345
 
 
346
    struct tagInchiTime *ulTimeOutTime;  /* timeout */
 
347
 
 
348
} CANON_DATA;
 
349
/**************************************************/
 
350
 
 
351
typedef struct tagCanonCounts {
 
352
    long     lNumBreakTies;
 
353
    long     lNumDecreasedCT;
 
354
    long     lNumRejectedCT;
 
355
    long     lNumEqualCT;
 
356
    long     lNumTotCT;
 
357
    double    dGroupSize;
 
358
    long     lNumGenerators;
 
359
    long     lNumStoredIsomorphisms;
 
360
 
 
361
} CANON_COUNTS;
 
362
/***********************************************
 
363
 tree structure: one segment
 
364
 
 
365
   canon. rank
 
366
   at.no          orig. atom numbers on which the canon. rank has been successfully mapped
 
367
   ...
 
368
   at.no          except the last at.no: it is not known if it has been mapped until all atoms are mapped
 
369
   num.at+1       number of atoms in this segment
 
370
*/
 
371
 
 
372
typedef struct tagCurTree {
 
373
    AT_NUMB   *tree;
 
374
    int       max_len;  /* allocated length of tree in sizeof(tree[0]) units */
 
375
    int       cur_len;  /* currently used length */
 
376
    int       incr_len; /* reallocation increment */
 
377
} CUR_TREE;
 
378
 
 
379
#endif /* __INCHICANT_H__ */