rino 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. data/README +44 -0
  2. data/Rakefile +123 -0
  3. data/ext/extconf.rb +26 -0
  4. data/ext/ruby_inchi_main.so +0 -0
  5. data/ext/src/aux2atom.h +2786 -0
  6. data/ext/src/comdef.h +148 -0
  7. data/ext/src/e_0dstereo.c +3014 -0
  8. data/ext/src/e_0dstereo.h +31 -0
  9. data/ext/src/e_comdef.h +57 -0
  10. data/ext/src/e_ctl_data.h +147 -0
  11. data/ext/src/e_ichi_io.c +498 -0
  12. data/ext/src/e_ichi_io.h +40 -0
  13. data/ext/src/e_ichi_parms.c +37 -0
  14. data/ext/src/e_ichi_parms.h +41 -0
  15. data/ext/src/e_ichicomp.h +50 -0
  16. data/ext/src/e_ichierr.h +40 -0
  17. data/ext/src/e_ichimain.c +593 -0
  18. data/ext/src/e_ichisize.h +43 -0
  19. data/ext/src/e_inchi_atom.c +75 -0
  20. data/ext/src/e_inchi_atom.h +33 -0
  21. data/ext/src/e_inpdef.h +41 -0
  22. data/ext/src/e_mode.h +706 -0
  23. data/ext/src/e_mol2atom.c +649 -0
  24. data/ext/src/e_readinch.c +58 -0
  25. data/ext/src/e_readmol.c +54 -0
  26. data/ext/src/e_readmol.h +180 -0
  27. data/ext/src/e_readstru.c +251 -0
  28. data/ext/src/e_readstru.h +33 -0
  29. data/ext/src/e_util.c +284 -0
  30. data/ext/src/e_util.h +61 -0
  31. data/ext/src/extr_ct.h +251 -0
  32. data/ext/src/ichi.h +206 -0
  33. data/ext/src/ichi_bns.c +7999 -0
  34. data/ext/src/ichi_bns.h +231 -0
  35. data/ext/src/ichican2.c +5000 -0
  36. data/ext/src/ichicano.c +2195 -0
  37. data/ext/src/ichicano.h +49 -0
  38. data/ext/src/ichicans.c +1625 -0
  39. data/ext/src/ichicant.h +379 -0
  40. data/ext/src/ichicomn.h +260 -0
  41. data/ext/src/ichicomp.h +50 -0
  42. data/ext/src/ichidrp.h +119 -0
  43. data/ext/src/ichierr.h +124 -0
  44. data/ext/src/ichiisot.c +101 -0
  45. data/ext/src/ichilnct.c +286 -0
  46. data/ext/src/ichimain.h +132 -0
  47. data/ext/src/ichimak2.c +1189 -0
  48. data/ext/src/ichimake.c +3812 -0
  49. data/ext/src/ichimake.h +205 -0
  50. data/ext/src/ichimap1.c +851 -0
  51. data/ext/src/ichimap2.c +2856 -0
  52. data/ext/src/ichimap4.c +1609 -0
  53. data/ext/src/ichinorm.c +741 -0
  54. data/ext/src/ichinorm.h +67 -0
  55. data/ext/src/ichiparm.c +45 -0
  56. data/ext/src/ichiparm.h +1441 -0
  57. data/ext/src/ichiprt1.c +3612 -0
  58. data/ext/src/ichiprt2.c +1511 -0
  59. data/ext/src/ichiprt3.c +3011 -0
  60. data/ext/src/ichiqueu.c +1003 -0
  61. data/ext/src/ichiring.c +326 -0
  62. data/ext/src/ichiring.h +49 -0
  63. data/ext/src/ichisize.h +35 -0
  64. data/ext/src/ichisort.c +539 -0
  65. data/ext/src/ichister.c +3538 -0
  66. data/ext/src/ichister.h +35 -0
  67. data/ext/src/ichitaut.c +3843 -0
  68. data/ext/src/ichitaut.h +387 -0
  69. data/ext/src/ichitime.h +74 -0
  70. data/ext/src/inchi_api.h +670 -0
  71. data/ext/src/inchi_dll.c +1480 -0
  72. data/ext/src/inchi_dll.h +34 -0
  73. data/ext/src/inchi_dll_main.c +23 -0
  74. data/ext/src/inchi_dll_main.h +31 -0
  75. data/ext/src/inpdef.h +328 -0
  76. data/ext/src/lreadmol.h +1246 -0
  77. data/ext/src/mode.h +706 -0
  78. data/ext/src/ruby_inchi_main.c +558 -0
  79. data/ext/src/runichi.c +4179 -0
  80. data/ext/src/strutil.c +3861 -0
  81. data/ext/src/strutil.h +182 -0
  82. data/ext/src/util.c +1130 -0
  83. data/ext/src/util.h +85 -0
  84. data/lib/clean_tempfile.rb +220 -0
  85. data/lib/rino.rb +111 -0
  86. data/test/test.rb +386 -0
  87. metadata +130 -0
@@ -0,0 +1,326 @@
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
+ #include <stdio.h>
11
+ #include <string.h>
12
+
13
+ #include "mode.h"
14
+
15
+ #include "inpdef.h"
16
+ #include "extr_ct.h"
17
+ #include "ichiring.h"
18
+
19
+ /* local prototypes */
20
+ int GetMinRingSize( inp_ATOM* atom, QUEUE *q, AT_RANK *nAtomLevel, S_CHAR *cSource, AT_RANK nMaxRingSize );
21
+
22
+
23
+
24
+
25
+ /*******************************************************************/
26
+ /* add to the queue */
27
+ int QueueAdd( QUEUE *q, QINT_TYPE *Val );
28
+ /* read & remove from the queue */
29
+ int QueueGet( QUEUE *q, QINT_TYPE *Val );
30
+ /* read from the queue */
31
+ int QueueGetAny( QUEUE *q, QINT_TYPE *, int ord );
32
+ /* initialize the queue */
33
+ int QueueReinit( QUEUE *q );
34
+ /* current queue length */
35
+ int QueueLength( QUEUE *q );
36
+ /* number of used queue internal elements */
37
+ int QueueWrittenLength( QUEUE *q );
38
+
39
+
40
+ #if( QUEUE_QINT == 1 ) /* { */
41
+
42
+ QUEUE *QueueCreate( int nTotLength, int nSize )
43
+ {
44
+ QUEUE *q = NULL;
45
+ QINT_TYPE *Val = NULL;
46
+ if ( nTotLength < 1 || nSize != (int)sizeof(QINT_TYPE) ||
47
+ !(q = (QUEUE *) inchi_calloc( 1, sizeof(QUEUE)) ) ||
48
+ !(Val = (QINT_TYPE *) inchi_calloc( nTotLength, nSize) )) {
49
+ if ( q ) inchi_free(q);
50
+ return NULL;
51
+ }
52
+ q->Val = Val;
53
+ /* q->nSize = nSize; */
54
+ q->nTotLength = nTotLength;
55
+ return q;
56
+ }
57
+ int QueueAdd( QUEUE *q, QINT_TYPE *Val )
58
+ {
59
+ if ( q && Val && q->nLength < q->nTotLength ) {
60
+ q->Val[ (q->nFirst + q->nLength) % q->nTotLength ] = *Val;
61
+ q->nLength ++;
62
+ return q->nLength;
63
+ }
64
+ return -1;
65
+ }
66
+ int QueueGet( QUEUE *q, QINT_TYPE *Val )
67
+ {
68
+ if ( q && Val && q->nLength > 0 ) {
69
+ *Val = q->Val[ q->nFirst ];
70
+ /* new: do not allow to overwrite the retrieved value */
71
+ q->nFirst = (q->nFirst == q->nTotLength - 1)? 0 : q->nFirst + 1;
72
+ q->nLength --;
73
+ /* -- old --
74
+ if ( -- q->nLength ) {
75
+ q->nFirst = (q->nFirst == q->nTotLength - 1)? 0 : q->nFirst + 1;
76
+ }
77
+ */
78
+ return q->nLength;
79
+ }
80
+ return -1;
81
+ }
82
+ int QueueGetAny( QUEUE *q, QINT_TYPE *Val, int ord )
83
+ {
84
+ if ( 0 <= ord && ord < q->nTotLength ) {
85
+ *Val = q->Val[ ord ];
86
+ return 1; /* success */
87
+ } else {
88
+ return -1; /* error */
89
+ }
90
+ }
91
+
92
+ #else /* } QUEUE_QINT == 1 { */
93
+
94
+ QUEUE *QueueCreate( int nTotLength, int nSize )
95
+ {
96
+ QUEUE *q = NULL;
97
+ QINT_TYPE *Val = NULL;
98
+ if ( nTotLength < 1 || nSize < 1 ||
99
+ !(q = (QUEUE *) inchi_calloc( 1, sizeof(QUEUE)) ) ||
100
+ !(Val = (QINT_TYPE *) inchi_calloc( nTotLength, nSize) )) {
101
+ if ( q ) inchi_free(q);
102
+ return NULL;
103
+ }
104
+ q->Val = Val;
105
+ q->nSize = nSize;
106
+ q->nTotLength = nTotLength;
107
+ return q;
108
+ }
109
+ int QueueAdd( QUEUE *q, QINT_TYPE *Val )
110
+ {
111
+ if ( q && Val && q->nLength < q->nTotLength ) {
112
+ memcpy( (char*)q->Val + ((q->nFirst + q->nLength) % q->nTotLength)*q->nSize, Val, q->nSize);
113
+ q->nLength ++;
114
+ return q->nLength;
115
+ }
116
+ return -1;
117
+ }
118
+ int QueueGet( QUEUE *q, QINT_TYPE *Val )
119
+ {
120
+ if ( q && Val && q->nLength > 0 ) {
121
+ memcpy( Val, (char*)q->Val + q->nFirst * q->nSize, q->nSize);
122
+ if ( -- q->nLength ) {
123
+ q->nFirst = (q->nFirst == q->nTotLength - 1)? 0 : q->nFirst + 1;
124
+ }
125
+ return q->nLength;
126
+ }
127
+ return -1;
128
+ }
129
+ int QueueGetAny( QUEUE *q, QINT_TYPE *Val, int ord )
130
+ {
131
+ if ( 0 <= ord && ord < q->nTotLength ) {
132
+ memcpy( Val, (char*)q->Val + ord * q->nSize, q->nSize);
133
+ return 1; /* success */
134
+ } else {
135
+ return -1; /* error */
136
+ }
137
+ }
138
+
139
+ #endif /* } QUEUE_QINT == 1 */
140
+
141
+ QUEUE *QueueDelete( QUEUE *q )
142
+ {
143
+ if ( q ) {
144
+ if ( q->Val ) inchi_free(q->Val);
145
+ inchi_free( q );
146
+ }
147
+ return NULL;
148
+ }
149
+ int QueueReinit( QUEUE *q )
150
+ {
151
+ if ( q ) {
152
+ q->nFirst = 0;
153
+ q->nLength = 0;
154
+ /* memset( q->Val, 0, q->nTotLength*sizeof(q->Val[0])); */ /* for debug only */
155
+ return q->nTotLength;
156
+ }
157
+ return -1;
158
+ }
159
+ int QueueLength( QUEUE *q )
160
+ {
161
+ if ( q ) {
162
+ return q->nLength;
163
+ } else {
164
+ return 0;
165
+ }
166
+ }
167
+ int QueueWrittenLength( QUEUE *q )
168
+ {
169
+ if ( q ) {
170
+ int len = q->nFirst+q->nLength;
171
+ return (len > q->nTotLength)? q->nTotLength : len;
172
+ } else {
173
+ return 0;
174
+ }
175
+ }
176
+
177
+ /**********************************************************************************/
178
+ /* BFS: Breadth First Search */
179
+ int GetMinRingSize( inp_ATOM* atom, QUEUE *q, AT_RANK *nAtomLevel, S_CHAR *cSource, AT_RANK nMaxRingSize )
180
+ {
181
+ int qLen, i, j;
182
+ AT_RANK nCurLevel, nRingSize, nMinRingSize=MAX_ATOMS+1;
183
+ qInt at_no, next;
184
+ int iat_no, inext;
185
+
186
+ while ( qLen = QueueLength( q ) ) {
187
+ /* traverse the next level (next outer ring) */
188
+ for ( i = 0; i < qLen; i ++ ) {
189
+ if ( 0 <= QueueGet( q, &at_no ) ) {
190
+ iat_no = (int)at_no;
191
+ nCurLevel = nAtomLevel[iat_no] + 1;
192
+ if ( 2*nCurLevel > nMaxRingSize + 4 ) {
193
+ /* 2*nCurLevel = nRingSize + 3 + k, k = 0 or 1 */
194
+ if ( nMinRingSize < MAX_ATOMS+1 ) {
195
+ return (nMinRingSize >= nMaxRingSize)? 0 : nMinRingSize;
196
+ }
197
+ return 0; /* min. ring size > nMaxRingSize */
198
+ }
199
+ for ( j = 0; j < atom[iat_no].valence; j ++ ) {
200
+ next = (qInt)atom[iat_no].neighbor[j];
201
+ inext = (int)next;
202
+ if ( !nAtomLevel[inext] ) {
203
+ /* the at_no neighbor has not been traversed yet. Add it to the queue */
204
+ if ( 0 <= QueueAdd( q, &next ) ) {
205
+ nAtomLevel[inext] = nCurLevel;
206
+ cSource[inext] = cSource[iat_no]; /* keep the path number */
207
+ } else {
208
+ return -1; /* error */
209
+ }
210
+ } else
211
+ if ( nAtomLevel[inext]+1 >= nCurLevel &&
212
+ cSource[inext] != cSource[iat_no]
213
+ /* && cSource[(int)next] != -1 */
214
+ ) {
215
+ /* found a ring closure */
216
+ /* debug */
217
+ if ( cSource[inext] == -1 ) {
218
+ return -1; /* error */
219
+ }
220
+ if ( (nRingSize = nAtomLevel[inext] + nCurLevel - 2) < nMinRingSize ) {
221
+ nMinRingSize = nRingSize;
222
+ }
223
+ /* return (nRingSize >= nMaxRingSize)? 0 : nRingSize; */
224
+ }
225
+ }
226
+ } else {
227
+ return -1; /* error */
228
+ }
229
+ }
230
+ }
231
+
232
+ if ( nMinRingSize < MAX_ATOMS+1 ) {
233
+ return (nMinRingSize >= nMaxRingSize)? 0 : nMinRingSize;
234
+ }
235
+
236
+ return 0;
237
+ }
238
+ /*******************************************************************/
239
+ /* Return value:
240
+ 0: nMaxRingSize < 3 or
241
+ min. ring size >= nMaxRingSize or
242
+ not a ring bond (the last is currently impossible: bond is known to belong to a ring system.
243
+ n>0: min. ring size < nMaxRingSize
244
+ n<0: error
245
+
246
+ Input:
247
+ atom[]
248
+ at_no number of the 1st atom adjacent to the bond
249
+ neigh_ord ordering number of the bond in question: at[at_no].bond_type[neigh_ord]
250
+ q queue structure
251
+ nAtomLevel work array, DFS distance
252
+ cSource work array, origin mark
253
+ */
254
+
255
+ int is_bond_in_Nmax_memb_ring( inp_ATOM* atom, int at_no, int neigh_ord, QUEUE *q, AT_RANK *nAtomLevel, S_CHAR *cSource, AT_RANK nMaxRingSize )
256
+ {
257
+ int nMinRingSize = -1, i;
258
+ qInt n;
259
+ int nTotLen;
260
+
261
+ if ( nMaxRingSize < 3 ) {
262
+ return 0;
263
+ }
264
+
265
+ QueueReinit( q );
266
+
267
+ /* mark the starting atom */
268
+ nAtomLevel[at_no] = 1;
269
+ cSource[at_no] = -1;
270
+ /* add neighbors */
271
+ for ( i = 0; i < atom[at_no].valence; i ++ ) {
272
+ n = (qInt)atom[at_no].neighbor[i];
273
+ nAtomLevel[(int)n] = 2;
274
+ cSource[(int)n] = 1 + (i==neigh_ord);
275
+ QueueAdd( q, &n );
276
+ }
277
+
278
+ nMinRingSize = GetMinRingSize( atom, q, nAtomLevel, cSource, nMaxRingSize );
279
+ /* cleanup */
280
+ nTotLen = QueueWrittenLength( q );
281
+ for ( i = 0; i < nTotLen; i ++ ) {
282
+ if ( 0 < QueueGetAny( q, &n, i ) ) {
283
+ nAtomLevel[(int)n] = 0;
284
+ cSource[(int)n] = 0;
285
+ }
286
+ }
287
+ nAtomLevel[at_no] = 0;
288
+ cSource[at_no] = 0;
289
+
290
+
291
+ /*
292
+ if ( nAtomLevel )
293
+ inchi_free ( nAtomLevel );
294
+ if ( cSource )
295
+ inchi_free ( cSource );
296
+ QueueDelete( q );
297
+ */
298
+ return nMinRingSize;
299
+ }
300
+ /*******************************************************************/
301
+ int is_atom_in_3memb_ring( inp_ATOM* atom, int at_no )
302
+ {
303
+ AT_NUMB neigh_neigh;
304
+ int i, j, k, val, val_neigh, neigh;
305
+
306
+ if ( atom[at_no].nNumAtInRingSystem < 3 ) {
307
+ return 0;
308
+ }
309
+
310
+ for ( i = 0, val = atom[at_no].valence; i < val; i ++ ) {
311
+ neigh = (int)atom[at_no].neighbor[i];
312
+ if ( atom[at_no].nRingSystem != atom[neigh].nRingSystem )
313
+ continue;
314
+ for ( j = 0, val_neigh = atom[neigh].valence; j < val_neigh; j ++ ) {
315
+ neigh_neigh = atom[neigh].neighbor[j];
316
+ if ( (int)neigh_neigh == at_no )
317
+ continue;
318
+ for ( k = 0; k < val; k ++ ) {
319
+ if ( atom[at_no].neighbor[k] == neigh_neigh ) {
320
+ return 1;
321
+ }
322
+ }
323
+ }
324
+ }
325
+ return 0;
326
+ }
@@ -0,0 +1,49 @@
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 __INCHIRING_H__
11
+ #define __INCHIRING_H__
12
+ #define QUEUE_QINT 1
13
+ typedef AT_RANK qInt; /* queue optimization: known type */
14
+
15
+ #if( QUEUE_QINT == 1 )
16
+ #define QINT_TYPE qInt
17
+ #else
18
+ #define QINT_TYPE void
19
+ #endif
20
+
21
+ typedef struct tagQieue {
22
+ QINT_TYPE *Val;
23
+ int nTotLength;
24
+ int nFirst; /* element to remove if nLength > 0 */
25
+ int nLength; /* (nFirst + nLength) is next free position */
26
+ #if( QUEUE_QINT != 1 )
27
+ int nSize;
28
+ #endif
29
+ }QUEUE;
30
+
31
+ #ifndef INCHI_ALL_CPP
32
+ #ifdef __cplusplus
33
+ extern "C" {
34
+ #endif
35
+ #endif
36
+
37
+ QUEUE *QueueCreate( int nTotLength, int nSize );
38
+ QUEUE *QueueDelete( QUEUE *q );
39
+ int is_bond_in_Nmax_memb_ring( inp_ATOM* atom, int at_no, int neigh_ord, QUEUE *q, AT_RANK *nAtomLevel, S_CHAR *cSource, AT_RANK nMaxRingSize );
40
+ int is_atom_in_3memb_ring( inp_ATOM* atom, int at_no );
41
+
42
+ #ifndef INCHI_ALL_CPP
43
+ #ifdef __cplusplus
44
+ }
45
+ #endif
46
+ #endif
47
+
48
+
49
+ #endif /* __INCHIRING_H__ */
@@ -0,0 +1,35 @@
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 ___INCHISIZE_H__
11
+ #define ___INCHISIZE_H__
12
+
13
+ typedef unsigned short AT_NUMB;
14
+ typedef unsigned short AT_RANK;
15
+ #define AT_RANK_MASK ((AT_RANK)~0)
16
+
17
+ typedef signed short NUM_H;
18
+ #define MAX_ATOMS 1024
19
+
20
+
21
+ #define CHAR_MASK 0xFF
22
+
23
+
24
+ typedef AT_RANK *pAT_RANK;
25
+ typedef pAT_RANK *ppAT_RANK;
26
+
27
+ typedef unsigned long INCHI_MODE;
28
+
29
+ #define LEN_COORD 10
30
+ #define NUM_COORD 3
31
+ typedef char MOL_COORD[LEN_COORD*NUM_COORD + NUM_COORD-1]; /*copied 30 bytes from MOLfile */
32
+
33
+
34
+ #endif /* ___INCHISIZE_H__ */
35
+