rino 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,593 @@
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
+ /*#define ADD_WIN_CTLC*/
11
+
12
+ #if( defined( WIN32 ) && defined( _CONSOLE ) && defined(_MSC_VER) && _MSC_VER >= 800 && defined(ADD_WIN_CTLC) )
13
+ #include <windows.h>
14
+ #endif
15
+
16
+
17
+ /* #define CREATE_0D_PARITIES */ /* uncomment to replace coordinates and 2D-parirties with 0D-parities */
18
+ /* #define MAKE_INCHI_FROM_AUXINFO */ /* uncomment to create the second InChI out of AuxInfo and compare */
19
+ #define NEIGH_ONLY_ONCE /* comment out to include each bond in both neighboring atoms adjacency lists */
20
+
21
+ #include <stdio.h>
22
+ #include <stdlib.h>
23
+
24
+ #include <string.h>
25
+ #include <ctype.h>
26
+ #include <stdarg.h>
27
+ #include <errno.h>
28
+ #include <limits.h>
29
+ #include <float.h>
30
+
31
+ #include "e_mode.h"
32
+ #include "inchi_api.h"
33
+ #include "e_inchi_atom.h"
34
+ #include "e_ctl_data.h"
35
+ #include "e_ichi_parms.h"
36
+ #include "e_util.h"
37
+ #include "e_ichi_io.h"
38
+ #include "e_ichierr.h"
39
+ #include "e_readstru.h"
40
+ #include "e_ichicomp.h"
41
+ #ifdef CREATE_0D_PARITIES
42
+ #include "e_0dstereo.h"
43
+ #endif
44
+
45
+ int e_MakeOutputHeader( char *pSdfLabel, char *pSdfValue, long lSdfId, int num_inp, char *pStr1, char *pStr2 );
46
+ char *e_GetChiralFlagString( int bChiralFlagOn );
47
+
48
+
49
+ /* console-specific */
50
+ /*****************************************************************
51
+ *
52
+ * Ctrl+C trap; works under Win32 + MS VC++
53
+ *
54
+ *****************************************************************/
55
+ #ifndef INCHI_LIB
56
+
57
+ int e_bInterrupted = 0;
58
+ #if( defined( _WIN32 ) && defined( _CONSOLE ) )
59
+
60
+ #if( defined(_MSC_VER) && _MSC_VER >= 800 && defined(ADD_WIN_CTLC) )
61
+ BOOL WINAPI MyHandlerRoutine(
62
+ DWORD dwCtrlType /* control signal type */
63
+ ) {
64
+ if ( dwCtrlType == CTRL_C_EVENT ||
65
+ dwCtrlType == CTRL_BREAK_EVENT ||
66
+ dwCtrlType == CTRL_CLOSE_EVENT ||
67
+ dwCtrlType == CTRL_LOGOFF_EVENT ) {
68
+ e_bInterrupted = 1;
69
+ return TRUE;
70
+ }
71
+ return FALSE;
72
+ }
73
+ #endif
74
+ int WasInterrupted(void) {
75
+ #ifdef _DEBUG
76
+ if ( e_bInterrupted ) {
77
+ int stop=1; /* for debug only <BRKPT> */
78
+ }
79
+ #endif
80
+ return e_bInterrupted;
81
+ }
82
+
83
+ #endif
84
+
85
+ #define EXIT_ON_ERR
86
+ #define REPEAT_ALL 0
87
+ /********************************************************************/
88
+ int main( int argc, char *argv[ ] )
89
+ {
90
+
91
+ STRUCT_DATA struct_data;
92
+ STRUCT_DATA *sd = &struct_data;
93
+ FILE *inp_file = NULL, *output_file = NULL, *log_file = NULL, *prb_file = NULL;
94
+
95
+ long num_inp, num_err, num_output;
96
+ char szSdfDataValue[MAX_SDF_VALUE+1];
97
+ const char *p1, *p2;
98
+
99
+ unsigned long ulDisplTime = 0; /* infinite, milliseconds */
100
+ unsigned long ulTotalProcessingTime = 0;
101
+ INPUT_PARMS inp_parms;
102
+ INPUT_PARMS *ip = &inp_parms;
103
+ char szInchiCmdLine[512];
104
+
105
+ inchi_Input inchi_inp, *pInp = &inchi_inp;
106
+ inchi_Output inchi_out, *pOut = &inchi_out;
107
+
108
+
109
+ int bReleaseVersion = bRELEASE_VERSION;
110
+ #define nStrLen 256
111
+ char pStrInchiId[nStrLen], pStrLogId[nStrLen];
112
+ int nRet = 0, nRet1, i, k, tot_len;
113
+ int inp_index, out_index;
114
+ long lSdfId;
115
+ int nStructNo;
116
+
117
+ #if ( defined(REPEAT_ALL) && REPEAT_ALL > 0 )
118
+ int num_repeat = REPEAT_ALL;
119
+ #endif
120
+
121
+
122
+ #if( TRACE_MEMORY_LEAKS == 1 )
123
+ _CrtSetDbgFlag(_CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF);
124
+ /* for execution outside of the VC++ debugger uncomment one of the following two */
125
+ /*#define MY_REPORT_FILE _CRTDBG_FILE_STDERR */
126
+ /*#define MY_REPORT_FILE _CRTDBG_FILE_STDOUT */
127
+ #ifdef MY_REPORT_FILE
128
+ _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
129
+ _CrtSetReportFile( _CRT_WARN, MY_REPORT_FILE );
130
+ _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
131
+ _CrtSetReportFile( _CRT_ERROR, MY_REPORT_FILE );
132
+ _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
133
+ _CrtSetReportFile( _CRT_ASSERT, MY_REPORT_FILE );
134
+ #else
135
+ _CrtSetReportMode(_CRT_WARN | _CRT_ERROR, _CRTDBG_MODE_DEBUG);
136
+ #endif
137
+ /* turn on floating point exceptions */
138
+ {
139
+ /* Get the default control word. */
140
+ int cw = _controlfp( 0,0 );
141
+
142
+ /* Set the exception masks OFF, turn exceptions on. */
143
+ /*cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_INEXACT|EM_ZERODIVIDE|EM_DENORMAL);*/
144
+ cw &=~(EM_OVERFLOW|EM_UNDERFLOW|EM_ZERODIVIDE|EM_DENORMAL);
145
+
146
+ /* Set the control word. */
147
+ _controlfp( cw, MCW_EM );
148
+
149
+ }
150
+ #endif
151
+
152
+ /*****************************************************************
153
+ *
154
+ * Set Ctrl+C trap; works under Win32 + MS VC++
155
+ *
156
+ *****************************************************************/
157
+ #if( defined( _WIN32 ) && defined( _CONSOLE ) && defined(_MSC_VER) && _MSC_VER >= 800 && defined(ADD_WIN_CTLC))
158
+ if ( SetConsoleCtrlHandler( MyHandlerRoutine, 1 ) ) {
159
+ /*ConsoleQuit = WasInterrupted*/;
160
+ }
161
+ #endif
162
+
163
+
164
+
165
+ #if ( defined(REPEAT_ALL) && REPEAT_ALL > 0 )
166
+ repeat:
167
+ inp_file = output_file = log_file = prb_file = NULL;
168
+ #endif
169
+
170
+ num_inp = 0;
171
+ num_err = 0;
172
+ num_output = 0;
173
+
174
+ if ( argc < 2 || argc==2 && ( argv[1][0]==INCHI_OPTION_PREFX ) &&
175
+ (!strcmp(argv[1]+1, "?") || !stricmp(argv[1]+1, "help") ) ) {
176
+ e_HelpCommandLineParms(stdout);
177
+ return 0;
178
+ }
179
+ /* original input structure */
180
+ memset( pInp, 0, sizeof(*pInp) );
181
+ memset( pOut, 0, sizeof(*pOut) );
182
+
183
+ memset( szSdfDataValue , 0, sizeof( szSdfDataValue ) );
184
+
185
+ /* explicitly cast to (const char **) to avoid a warning about "incompatible pointer type":*/
186
+ if ( 0 > e_ReadCommandLineParms( argc, (const char **)argv, ip, szSdfDataValue, &ulDisplTime, bReleaseVersion, NULL ) ) {
187
+ goto exit_function;
188
+ }
189
+ if ( !e_OpenFiles( &inp_file, &output_file, &log_file, &prb_file, ip ) ) {
190
+ goto exit_function;
191
+ }
192
+ if ( ip->bNoStructLabels ) {
193
+ ip->pSdfLabel = NULL;
194
+ ip->pSdfValue = NULL;
195
+ } else
196
+ if ( ip->nInputType == INPUT_INCHI_PLAIN ||
197
+ ip->nInputType == INPUT_INCHI_XML ||
198
+ ip->nInputType == INPUT_CMLFILE ) {
199
+ /* the input may contain both the header and the label of the structure */
200
+ if ( !ip->pSdfLabel )
201
+ ip->pSdfLabel = ip->szSdfDataHeader;
202
+ if ( !ip->pSdfValue )
203
+ ip->pSdfValue = szSdfDataValue;
204
+ }
205
+ e_PrintInputParms( log_file, ip );
206
+ pStrInchiId[0] = '\0';
207
+ /******************************************************************/
208
+ /* Main cycle */
209
+ /* read input structures and create their InChI */
210
+ ulTotalProcessingTime = 0;
211
+
212
+ out_index = 0;
213
+ while ( !e_bInterrupted ) {
214
+ int bHasTimeout = 0;
215
+ if ( ip->last_struct_number && num_inp >= ip->last_struct_number ) {
216
+ nRet = _IS_EOF; /* simulate end of file */
217
+ goto exit_function;
218
+ }
219
+ /* create command line */
220
+ szInchiCmdLine[0] = '\0';
221
+ for ( i = 1; i < argc; i ++ ) {
222
+ if ( argv[i] && INCHI_OPTION_PREFX == argv[i][0] && argv[i][1] ) {
223
+ /* omit certrain options */
224
+ if ( !memicmp( argv[i]+1, "start:", 6) ||
225
+ !memicmp( argv[i]+1, "end:", 4) ||
226
+ !stricmp( argv[i]+1, "Tabbed" )
227
+ ) {
228
+ continue;
229
+ }
230
+ if ( !memicmp( argv[i]+1, "w", 1 ) && isdigit( UCINT argv[i][2] ) ) {
231
+ bHasTimeout = 1;
232
+ }
233
+ /* add option to szInchiCmdLine */
234
+ if ( strlen(szInchiCmdLine)+strlen(argv[i]) + 4 < sizeof(szInchiCmdLine) ) {
235
+ if ( szInchiCmdLine[0] )
236
+ strcat( szInchiCmdLine, " " );
237
+ k = ( !(k=strcspn( argv[i], " \t" )) || argv[i][k] ); /* k means enclose in "" */
238
+ if ( k )
239
+ strcat( szInchiCmdLine, "\"" );
240
+ strcat( szInchiCmdLine, argv[i] );
241
+ if ( k )
242
+ strcat( szInchiCmdLine, "\"" );
243
+ } else {
244
+ e_my_fprintf( stderr, "Too many options. Option \"%s\" ignored\n", argv[i] );
245
+ }
246
+ }
247
+ }
248
+ if ( !bHasTimeout ) {
249
+ /* add default timeout option -W60: 60 seconds */
250
+ char p1[] = " W60";
251
+ p1[1] = INCHI_OPTION_PREFX;
252
+ if ( strlen(szInchiCmdLine) + strlen( p1 ) < sizeof(szInchiCmdLine) ) {
253
+ strcat( szInchiCmdLine, p1 );
254
+ } else {
255
+ e_my_fprintf( stderr, "Too many options. Option \"%s\" ignored\n", p1 );
256
+ }
257
+ }
258
+
259
+ inp_index = out_index;
260
+ /* read one structure from input */
261
+ e_FreeInchi_Input( pInp );
262
+ //e_my_fprintf( stderr, "\rStructure: %d.................\r", num_inp+1 );
263
+ nRet = e_ReadStructure( sd, ip, inp_file, log_file, output_file, prb_file, pInp, num_inp+1,
264
+ /* for CML:*/ inp_index, &out_index );
265
+ /* simulate INChI structure header */
266
+ lSdfId = ( ip->bGetSdfileId )? ip->lSdfId : 0; /* if requested then CAS r.n. otherwise struct. number*/
267
+ nStructNo = ( ip->lMolfileNumber > 0 )? ip->lMolfileNumber : num_inp+1;
268
+ e_MakeOutputHeader( ip->pSdfLabel, ip->pSdfValue, lSdfId, nStructNo, pStrInchiId, pStrLogId );
269
+ if ( sd->pStrErrStruct && sd->pStrErrStruct[0] ) {
270
+ p1 = "; ";
271
+ p2 = sd->pStrErrStruct;
272
+ } else {
273
+ p1 = p2 = "";
274
+ }
275
+ /* e_ReadStructure() outputs the error/warning messages, so we do not need to re-output them here */
276
+ switch ( nRet ) {
277
+ case _IS_FATAL:
278
+ num_inp ++;
279
+ num_err ++;
280
+ goto exit_function;
281
+ case _IS_EOF:
282
+ //e_my_fprintf( stderr, "\rStructure %d could not be read: Detected end of file. \r", num_inp+1 );
283
+ goto exit_function;
284
+ case _IS_ERROR:
285
+ num_inp ++;
286
+ num_err ++;
287
+ continue;
288
+ case _IS_SKIP:
289
+ num_inp ++;
290
+ continue;
291
+ }
292
+ if ( nRet != _IS_WARNING ) {
293
+ //e_my_fprintf( stderr, "\r%s \r", pStrLogId );
294
+ }
295
+ /* chiral flag */
296
+ /* *****************************************************************************
297
+ * Chiral flags are set in:
298
+ * - RunICHI.c #1610 -- ReadTheStructure() -- cInChI, wInChI
299
+ * - e_IchiMain.c #273 -- main() -- C example of calling InChI dll (here)
300
+ * - inchi_dll.c #1662 -- ExtractOneStructure -- InChI dll code
301
+ *******************************************************************************/
302
+
303
+ p1 = NULL;
304
+ if ( (ip->nMode & REQ_MODE_CHIR_FLG_STEREO) && (ip->nMode & REQ_MODE_STEREO) &&
305
+ ( ip->bChiralFlag & (FLAG_SET_INP_AT_CHIRAL | FLAG_SET_INP_AT_NONCHIRAL) ) ) {
306
+ ; /* cmd line has priority over the chiral flag in Molfile */
307
+ } else
308
+ if ( sd->bChiralFlag & FLAG_INP_AT_CHIRAL ) {
309
+ p1 = e_GetChiralFlagString( 1 ); /* input file has chiral flag */
310
+ } else
311
+ if ( (ip->nMode & REQ_MODE_CHIR_FLG_STEREO) && (ip->nMode & REQ_MODE_STEREO) ||
312
+ (sd->bChiralFlag & FLAG_INP_AT_NONCHIRAL) ) { /* fix 04/05/2005 D.T.*/
313
+ /* chiral flag requested (/SUCF) or input has non-chiral flag */
314
+ p1 = e_GetChiralFlagString( 0 );
315
+ }
316
+ if ( p1 ) {
317
+ if ( strlen(szInchiCmdLine) + strlen( p1 ) < sizeof(szInchiCmdLine) ) {
318
+ strcat( szInchiCmdLine, p1 );
319
+ } else {
320
+ e_my_fprintf( stderr, "Too many options. Option \"%s\" ignored\n", p1 );
321
+ }
322
+ }
323
+
324
+ /* create INChI for each connected component of the structure and optionally display them */
325
+ /* output INChI for the whole structure */
326
+ FreeINCHI ( pOut );
327
+ pInp->szOptions = szInchiCmdLine;
328
+ #ifdef CREATE_0D_PARITIES
329
+ if ( !pInp->stereo0D && !pInp->num_stereo0D ) {
330
+ int bPointedEdgeStereo = (0 != (TG_FLAG_POINTED_EDGE_STEREO & ip->bTautFlags));
331
+ set_0D_stereo_parities( pInp, bPointedEdgeStereo );
332
+ Clear3D2Dstereo(pInp);
333
+ }
334
+ #endif
335
+ #ifdef NEIGH_ONLY_ONCE
336
+ e_RemoveRedundantNeighbors( pInp );
337
+ #endif
338
+ /********************************************
339
+ *
340
+ * CREATE INCHI
341
+ *
342
+ ********************************************/
343
+ nRet1 = GetINCHI( pInp, pOut );
344
+
345
+ ulTotalProcessingTime += sd->ulStructTime;
346
+ nRet = nRet1;
347
+ #ifdef MAKE_INCHI_FROM_AUXINFO
348
+ /**************************************************
349
+ *
350
+ * CREATE one more INCHI FROM AuxInfo and compare
351
+ *
352
+ * it to to the first INCHI
353
+ *
354
+ * Note: This should double the elapsed CPU time
355
+ *
356
+ **************************************************/
357
+ if ( nRet1 == inchi_Ret_OKAY || nRet1 == inchi_Ret_WARNING ) {
358
+ char *szInchiAuxInfo = pOut->szAuxInfo, *p1 /* shadowing previous definition */;
359
+ int bDoNotAddH = ip->bDoNotAddH;
360
+ int nRet2;
361
+ inchi_Input inchi_inp2, *pInp2 = &inchi_inp2;
362
+ inchi_Output inchi_out2, *pOut2 = &inchi_out2;
363
+ InchiInpData idat;
364
+ /* setup input for Get_inchi_Input_FromAuxInfo */
365
+ idat.pInp = pInp2;
366
+ pInp2->szOptions = NULL; /* not needed */
367
+
368
+ /* Make InChI input out of AuxInfo */
369
+ nRet2 = Get_inchi_Input_FromAuxInfo( szInchiAuxInfo, bDoNotAddH, &idat );
370
+
371
+ if ( inchi_Ret_OKAY == nRet2 || inchi_Ret_WARNING == nRet2 ) {
372
+ /* set chiral flag */
373
+ p1 = NULL;
374
+ if ( (ip->nMode & REQ_MODE_CHIR_FLG_STEREO) && (ip->nMode & REQ_MODE_STEREO) &&
375
+ ( ip->bChiralFlag & (FLAG_SET_INP_AT_CHIRAL | FLAG_SET_INP_AT_NONCHIRAL) ) ) {
376
+ ; /* cmd line has priority over the chiral flag in Molfile */
377
+ } else
378
+ if ( idat.bChiral & FLAG_INP_AT_CHIRAL ) { /* fix 04/05/2005 D.T.*/
379
+ p1 = e_GetChiralFlagString( 1 ); /* input file has chiral flag */
380
+ } else
381
+ if ( (ip->nMode & REQ_MODE_CHIR_FLG_STEREO) && (ip->nMode & REQ_MODE_STEREO) ||
382
+ (idat.bChiral & FLAG_INP_AT_NONCHIRAL) ) { /* fix 04/05/2005 D.T.*/
383
+ /* chiral flag requested (/SUCF) or input has non-chiral flag */
384
+ p1 = e_GetChiralFlagString( 0 );
385
+ }
386
+ if ( p1 ) {
387
+ if ( strlen(szInchiCmdLine) + strlen( p1 ) < sizeof(szInchiCmdLine) ) {
388
+ strcat( szInchiCmdLine, p1 );
389
+ } else {
390
+ e_my_fprintf( stderr, "Too many options. Option \"%s\" ignored\n", p1 );
391
+ }
392
+ }
393
+
394
+ /* Make InChI out of InChI input out of AuxInfo */
395
+ pInp2->szOptions = pInp->szOptions;
396
+ memset( pOut2, 0, sizeof(*pOut2) );
397
+ nRet2 = GetINCHI( pInp2, pOut2 );
398
+ /* Compare the two InChI */
399
+ if ( nRet2 == inchi_Ret_OKAY || nRet2 == inchi_Ret_WARNING ) {
400
+ if ( !pOut2->szInChI || strcmp( pOut->szInChI, pOut2->szInChI ) ) {
401
+ e_my_fprintf( stderr, "InChI from AuxInfo Is Different!\n" );
402
+ }
403
+ } else {
404
+ e_my_fprintf( stderr, "InChI from AuxInfo could not be produced: \"%s\"\n", pOut2->szMessage );
405
+ }
406
+ FreeINCHI( pOut2 );
407
+ }
408
+ Free_inchi_Input( pInp2 );
409
+ }
410
+ #endif
411
+
412
+ /*****************************/
413
+ /* output err/warn */
414
+ /*****************************/
415
+ if ( pOut->szMessage && pOut->szMessage[0] ) {
416
+ p1 = "; ";
417
+ p2 = pOut->szMessage;
418
+ } else {
419
+ p1 = p2 = "";
420
+ }
421
+ switch ( nRet ) {
422
+ case inchi_Ret_UNKNOWN:
423
+ case inchi_Ret_FATAL: /* fatal processing error -- typically, memory allocation error */
424
+ num_inp ++;
425
+ num_err ++;
426
+ #if( defined(EXIT_ON_ERR) && defined(REPEAT_ALL) && REPEAT_ALL > 0 )
427
+ num_repeat = 0;
428
+ #endif
429
+ e_my_fprintf( log_file, "Fatal Error (No INChI%s%s) %s\n", p1, p2, pStrLogId );
430
+ goto exit_function;
431
+ case inchi_Ret_EOF: /* typically, no input structure provided or help requested */
432
+ /* output previous structure number and message */
433
+ e_my_fprintf( log_file, "End of file detected after structure %d\n", num_inp );
434
+ goto exit_function;
435
+ case inchi_Ret_ERROR:
436
+ num_inp ++;
437
+ num_err ++;
438
+ e_my_fprintf( log_file, "Error (No INChI%s%s) %s\n", p1, p2, pStrLogId );
439
+ #if( defined(EXIT_ON_ERR) && defined(REPEAT_ALL) && REPEAT_ALL > 0 )
440
+ num_repeat = 0;
441
+ goto exit_function;
442
+ #endif
443
+ continue;
444
+ case inchi_Ret_SKIP:
445
+ num_inp ++;
446
+ e_my_fprintf( log_file, "Skipped %s\n", pStrLogId );
447
+ goto exit_function;
448
+ case inchi_Ret_OKAY:
449
+ break;
450
+ case inchi_Ret_WARNING:
451
+ e_my_fprintf( log_file, "Warning (%s) %s\n", p2, pStrLogId );
452
+ break; /* ok */
453
+ }
454
+
455
+ num_inp ++;
456
+ tot_len = 0;
457
+ if ( pOut->szInChI && pOut->szInChI[0] ) {
458
+ if (ip->bINChIOutputOptions & INCHI_OUT_SDFILE_ONLY ) {
459
+ /*****************************/
460
+ /* output SDfile */
461
+ /*****************************/
462
+ char *start;
463
+ unsigned len;
464
+ int bAddLabel = 0;
465
+ /*******************************************************************************/
466
+ /* output a SDfile. pOut->szInChI contains Molfile ending with "$$$$\n" line. */
467
+ /* Replace the 1st line with the structure number */
468
+ /* Replace the last line with the SDfile header, label, and new "$$$$\n" line */
469
+ /*******************************************************************************/
470
+ /* 1. remove the 1st line (later replace it with the actual structure number) */
471
+ if ( start = strchr( pOut->szInChI, '\n' ) ) {
472
+ e_inchi_print( output_file, "Structure #%ld", nStructNo );
473
+ } else {
474
+ start = pOut->szInChI;
475
+ }
476
+ /* 2. SDfile header and data: write zero to the 1st byte of
477
+ * the last line "$$$$\n" to remove this line with purpose to relpace it */
478
+ if ( ip->pSdfLabel && ip->pSdfLabel[0] && ip->pSdfValue && ip->pSdfValue[0] &&
479
+ (len = strlen(start)) && len > 5 && '$' == start[len-5] && '\n' == start[len-6] ) {
480
+ start[len-5] = '\0';
481
+ bAddLabel = 1;
482
+ }
483
+ /* 3. Output the whole Molfile */
484
+ e_inchi_print( output_file, "%s", start );
485
+ if ( bAddLabel ) {
486
+ e_inchi_print( output_file, "> <%s>\n%s\n\n$$$$\n", ip->pSdfLabel, ip->pSdfValue );
487
+ }
488
+
489
+ } else {
490
+ /*****************************/
491
+ /* output InChI */
492
+ /*****************************/
493
+ int bTabbed = 0 != ( ip->bINChIOutputOptions & INCHI_OUT_TABBED_OUTPUT );
494
+ int bAuxInfo = !( ip->bINChIOutputOptions & INCHI_OUT_ONLY_AUX_INFO ) &&
495
+ pOut->szAuxInfo && pOut->szAuxInfo[0];
496
+ const char *pLF = "\n";
497
+ const char *pTAB = bTabbed? "\t" : pLF;
498
+ if ( !ip->bNoStructLabels ) {
499
+ /* or print a previously created label string */
500
+ e_inchi_print( output_file, "%s%s", pStrInchiId, pTAB );
501
+ }
502
+ /* output INChI Identifier */
503
+ e_inchi_print( output_file, "%s%s", pOut->szInChI, bAuxInfo? pTAB : pLF );
504
+ /* output INChI Aux Info */
505
+ if ( bAuxInfo ) {
506
+ e_inchi_print( output_file, "%s\n",pOut->szAuxInfo );
507
+ }
508
+ }
509
+ }
510
+ }
511
+
512
+ exit_function:
513
+ e_my_fprintf( log_file, "\nProcessed %d structure%s, %d error%s.\n",
514
+ num_inp, (num_inp==1)?"":"s", num_err, (num_err==1)?"":"s" );
515
+
516
+
517
+ e_FreeInchi_Input( pInp );
518
+ FreeINCHI ( pOut );
519
+
520
+ #if( ADD_CMLPP == 1 )
521
+ /* BILLY 8/6/04 */
522
+ /* free CML memory */
523
+ FreeCml ();
524
+ FreeCmlDoc( 1 );
525
+ #endif
526
+
527
+ if ( inp_file && inp_file != stdin) {
528
+ fclose ( inp_file );
529
+ }
530
+ if ( prb_file ) {
531
+ fclose ( prb_file );
532
+ }
533
+ if ( output_file && output_file != stdout ) {
534
+ fclose( output_file );
535
+ }
536
+
537
+ if ( log_file && log_file != stderr ) {
538
+ fclose( log_file );
539
+ }
540
+ for ( i = 0; i < MAX_NUM_PATHS; i ++ ) {
541
+ if ( ip->path[i] ) {
542
+ e_inchi_free( (void*) ip->path[i] ); /* cast deliberately discards 'const' qualifier */
543
+ ip->path[i] = NULL;
544
+ }
545
+ }
546
+
547
+ #if ( defined(REPEAT_ALL) && REPEAT_ALL > 0 )
548
+ if ( --num_repeat > 0 ) {
549
+ goto repeat;
550
+ }
551
+ #endif
552
+
553
+
554
+ return 0;
555
+ }
556
+
557
+
558
+ #endif
559
+
560
+ /**********************************************************/
561
+ int e_MakeOutputHeader( char *pSdfLabel, char *pSdfValue, long lSdfId, int num_inp, char *pStr1, char *pStr2 )
562
+ {
563
+ int tot_len1 = 0, tot_len2 = 0;
564
+ pStr1[0] = '\0';
565
+ if ( !(pSdfLabel && pSdfLabel[0]) && !(pSdfValue && pSdfValue[0]) ) {
566
+ tot_len1 = sprintf( pStr1, "Structure: %d", num_inp );
567
+ tot_len2 = sprintf( pStr2, "structure #%d", num_inp );
568
+ } else {
569
+ tot_len1 = sprintf( pStr1, "Structure: %d.%s%s%s%s",
570
+ num_inp,
571
+ SDF_LBL_VAL(pSdfLabel, pSdfValue) );
572
+
573
+ tot_len2 = sprintf( pStr2, "structure #%d.%s%s%s%s",
574
+ num_inp,
575
+ SDF_LBL_VAL(pSdfLabel, pSdfValue) );
576
+ if ( lSdfId ) {
577
+ tot_len1 += sprintf( pStr1 + tot_len1, ":%ld", lSdfId );
578
+ tot_len2 += sprintf( pStr2 + tot_len2, ":%ld", lSdfId );
579
+ }
580
+ }
581
+ return tot_len1;
582
+ }
583
+ /************************************************************/
584
+ char *e_GetChiralFlagString( int bChiralFlagOn )
585
+ {
586
+ static char szChiralFlag[64];
587
+ szChiralFlag[0] = ' ';
588
+ szChiralFlag[1] = INCHI_OPTION_PREFX;
589
+ sprintf( szChiralFlag+2, "ChiralFlag%s", bChiralFlagOn? "On":"Off" );
590
+ return szChiralFlag;
591
+ }
592
+
593
+
@@ -0,0 +1,43 @@
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
+
14
+ typedef unsigned short AT_NUMB;
15
+ typedef unsigned short AT_RANK;
16
+ #define AT_RANK_MASK ((AT_RANK)~0)
17
+
18
+ typedef signed short NUM_H;
19
+ #define MAX_ATOMS 1024
20
+
21
+ #define CHAR_MASK 0xFF
22
+
23
+ typedef unsigned long INCHI_MODE;
24
+
25
+ #define LEN_COORD 10
26
+ #define NUM_COORD 3
27
+ typedef char MOL_COORD[LEN_COORD*NUM_COORD + NUM_COORD-1]; /*copied 30 bytes from MOLfile */
28
+
29
+ typedef enum tagInputType { INPUT_NONE=0, INPUT_MOLFILE=1, INPUT_SDFILE=2, INPUT_INCHI_XML=3, INPUT_INCHI_PLAIN=4, INPUT_CMLFILE=5, INPUT_MAX } INPUT_TYPE;
30
+
31
+ /* other types */
32
+
33
+ #define UCINT (int)(unsigned char)
34
+ #ifndef INCHI_US_CHAR_DEF
35
+ typedef signed char S_CHAR;
36
+ typedef unsigned char U_CHAR;
37
+ #define INCHI_US_CHAR_DEF
38
+ #endif
39
+
40
+
41
+
42
+ #endif /* ___INCHISIZE_H__ */
43
+