rino 0.1.0 → 0.2.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 (104) hide show
  1. data/Rakefile +1 -1
  2. data/ext/extconf.rb +1 -24
  3. data/ext/libinchi.so +0 -0
  4. data/ext/src/aux2atom.h +120 -39
  5. data/ext/src/comdef.h +3 -3
  6. data/ext/src/dispstru.c +2547 -0
  7. data/ext/src/dispstru.h +73 -0
  8. data/ext/src/extr_ct.h +5 -2
  9. data/ext/src/ichi.h +27 -11
  10. data/ext/src/ichi_bns.c +1800 -254
  11. data/ext/src/ichi_bns.h +205 -4
  12. data/ext/src/ichican2.c +197 -86
  13. data/ext/src/ichicano.c +8 -13
  14. data/ext/src/ichicano.h +2 -2
  15. data/ext/src/ichicans.c +11 -6
  16. data/ext/src/ichicant.h +2 -2
  17. data/ext/src/ichicomn.h +2 -2
  18. data/ext/src/ichicomp.h +19 -4
  19. data/ext/src/ichidrp.h +9 -5
  20. data/ext/src/ichierr.h +5 -3
  21. data/ext/src/ichiisot.c +2 -2
  22. data/ext/src/ichimain.c +461 -0
  23. data/ext/src/ichimain.h +23 -15
  24. data/ext/src/ichimak2.c +6 -6
  25. data/ext/src/ichimake.c +843 -42
  26. data/ext/src/ichimake.h +4 -2
  27. data/ext/src/ichimap1.c +5 -5
  28. data/ext/src/ichimap2.c +2 -2
  29. data/ext/src/ichimap4.c +34 -21
  30. data/ext/src/ichinorm.c +11 -5
  31. data/ext/src/ichinorm.h +3 -2
  32. data/ext/src/ichiparm.c +2 -2
  33. data/ext/src/ichiparm.h +232 -30
  34. data/ext/src/ichiprt1.c +35 -11
  35. data/ext/src/ichiprt2.c +78 -7
  36. data/ext/src/ichiprt3.c +300 -120
  37. data/ext/src/ichiqueu.c +17 -2
  38. data/ext/src/ichiread.c +6932 -0
  39. data/ext/src/ichiring.c +3 -2
  40. data/ext/src/ichiring.h +2 -2
  41. data/ext/src/ichirvr1.c +4891 -0
  42. data/ext/src/ichirvr2.c +6344 -0
  43. data/ext/src/ichirvr3.c +5499 -0
  44. data/ext/src/ichirvr4.c +3177 -0
  45. data/ext/src/ichirvr5.c +1166 -0
  46. data/ext/src/ichirvr6.c +1287 -0
  47. data/ext/src/ichirvr7.c +2319 -0
  48. data/ext/src/ichirvrs.h +882 -0
  49. data/ext/src/ichisize.h +2 -2
  50. data/ext/src/ichisort.c +5 -5
  51. data/ext/src/ichister.c +281 -86
  52. data/ext/src/ichister.h +9 -3
  53. data/ext/src/ichitaut.c +208 -9
  54. data/ext/src/ichitaut.h +13 -11
  55. data/ext/src/ichitime.h +16 -2
  56. data/ext/src/inchicmp.h +107 -0
  57. data/ext/src/inpdef.h +6 -3
  58. data/ext/src/libinchi_wrap.c +912 -0
  59. data/ext/src/lreadmol.h +34 -31
  60. data/ext/src/mode.h +244 -7
  61. data/ext/src/mol2atom.c +1060 -0
  62. data/ext/src/mol2atom.h +31 -0
  63. data/ext/src/readinch.c +239 -0
  64. data/ext/src/readmol.c +28 -0
  65. data/ext/src/{e_readmol.h → readmol.h} +7 -9
  66. data/ext/src/runichi.c +251 -177
  67. data/ext/src/strutil.c +444 -238
  68. data/ext/src/strutil.h +150 -11
  69. data/ext/src/util.c +176 -118
  70. data/ext/src/util.h +15 -3
  71. data/lib/rino.rb +71 -3
  72. data/test/test.rb +33 -4
  73. metadata +22 -34
  74. data/ext/ruby_inchi_main.so +0 -0
  75. data/ext/src/e_0dstereo.c +0 -3014
  76. data/ext/src/e_0dstereo.h +0 -31
  77. data/ext/src/e_comdef.h +0 -57
  78. data/ext/src/e_ctl_data.h +0 -147
  79. data/ext/src/e_ichi_io.c +0 -498
  80. data/ext/src/e_ichi_io.h +0 -40
  81. data/ext/src/e_ichi_parms.c +0 -37
  82. data/ext/src/e_ichi_parms.h +0 -41
  83. data/ext/src/e_ichicomp.h +0 -50
  84. data/ext/src/e_ichierr.h +0 -40
  85. data/ext/src/e_ichimain.c +0 -593
  86. data/ext/src/e_ichisize.h +0 -43
  87. data/ext/src/e_inchi_atom.c +0 -75
  88. data/ext/src/e_inchi_atom.h +0 -33
  89. data/ext/src/e_inpdef.h +0 -41
  90. data/ext/src/e_mode.h +0 -706
  91. data/ext/src/e_mol2atom.c +0 -649
  92. data/ext/src/e_readinch.c +0 -58
  93. data/ext/src/e_readmol.c +0 -54
  94. data/ext/src/e_readstru.c +0 -251
  95. data/ext/src/e_readstru.h +0 -33
  96. data/ext/src/e_util.c +0 -284
  97. data/ext/src/e_util.h +0 -61
  98. data/ext/src/ichilnct.c +0 -286
  99. data/ext/src/inchi_api.h +0 -670
  100. data/ext/src/inchi_dll.c +0 -1480
  101. data/ext/src/inchi_dll.h +0 -34
  102. data/ext/src/inchi_dll_main.c +0 -23
  103. data/ext/src/inchi_dll_main.h +0 -31
  104. data/ext/src/ruby_inchi_main.c +0 -558
@@ -1,40 +0,0 @@
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 __ICHI_IO_H__
11
- #define __ICHI_IO_H__
12
-
13
-
14
- #ifndef INCHI_ALL_CPP
15
- #ifdef __cplusplus
16
- extern "C" {
17
- #endif
18
- #endif
19
-
20
-
21
- char* fgets_up_to_lf( char* line, int line_len, FILE* inp );
22
- int my_fgetsUpToLfOrTab( char *szLine, int len, FILE *f );
23
-
24
- int e_my_fgetsTab( char *szLine, int len, FILE *f, int *bTooLongLine );
25
- int e_my_fgetsTab1( char *szLine, int len, FILE *f, int *bTooLongLine );
26
-
27
- int e_inchi_print( FILE* f, const char* lpszFormat, ... );
28
- int e_my_fprintf( FILE* f, const char* lpszFormat, ... );
29
- void e_PrintFileName( const char *fmt, FILE *output_file, const char *szFname );
30
- unsigned long e_ulMyGetTickCount( int bStart );
31
- unsigned long e_ulMyTickCountDiff( unsigned long ulTickEnd, unsigned long ulTickStart );
32
-
33
- #ifndef INCHI_ALL_CPP
34
- #ifdef __cplusplus
35
- }
36
- #endif
37
- #endif
38
-
39
-
40
- #endif /* __ICHI_IO_H__ */
@@ -1,37 +0,0 @@
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 <stdlib.h>
12
- #include <string.h>
13
- #include <ctype.h>
14
- #include <errno.h>
15
- #include <limits.h>
16
-
17
- #include "e_mode.h"
18
- #include "inchi_api.h"
19
- #include "e_ctl_data.h"
20
- #include "e_ichi_io.h"
21
- #include "e_ichi_parms.h"
22
- #include "e_util.h"
23
- #include "e_ichicomp.h"
24
-
25
- #define DetectInputINChIFileType e_DetectInputINChIFileType
26
- #define ReadCommandLineParms e_ReadCommandLineParms
27
- #define mystrncpy e_mystrncpy
28
- #define my_fprintf e_my_fprintf
29
- #define LtrimRtrim e_LtrimRtrim
30
- #define PrintInputParms e_PrintInputParms
31
- #define OpenFiles e_OpenFiles
32
- #define PrintFileName e_PrintFileName
33
- #define HelpCommandLineParms e_HelpCommandLineParms
34
- #define inchi_print_nodisplay fprintf
35
-
36
- #include "ichiparm.h"
37
-
@@ -1,41 +0,0 @@
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 __ICHI_PARMS_H__
11
- #define __ICHI_PARMS_H__
12
-
13
-
14
-
15
- #ifndef INCHI_ALL_CPP
16
- #ifdef __cplusplus
17
- extern "C" {
18
- #endif
19
- #endif
20
-
21
-
22
- int e_ReadCommandLineParms( int argc, const char *argv[], INPUT_PARMS *ip, char *szSdfDataValue,
23
- unsigned long *ulDisplTime, int bReleaseVersion, INCHI_FILE *log_file );
24
-
25
- int e_PrintInputParms( INCHI_FILE *log_file, INPUT_PARMS *ip );
26
- int e_OpenFiles( FILE **inp_file, FILE **output_file, FILE **log_file, FILE **prb_file, INPUT_PARMS *ip );
27
- void e_HelpCommandLineParms( INCHI_FILE *f );
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
- #ifndef INCHI_ALL_CPP
36
- #ifdef __cplusplus
37
- }
38
- #endif
39
- #endif
40
-
41
- #endif /* __ICHI_PARMS_H__ */
@@ -1,50 +0,0 @@
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 __INCHI_COMPAT_H__
11
- #define __INCHI_COMPAT_H__
12
-
13
- /* compatibility */
14
-
15
- #if( defined(__GNUC__) && defined(__MINGW32__) && __GNUC__ == 3 && __GNUC_MINOR__ == 2 && __GNUC_PATCHLEVEL__ == 0 && defined(_WIN32) )
16
- /* replace with the proper definition for GNU gcc & MinGW-2.0.0-3 (mingw special 20020817-1), gcc 3.2 core */
17
- #define my_va_start(A,B) ((A)=(va_list)__builtin_next_arg(lpszFormat))
18
- #else
19
- #define my_va_start va_start
20
- #endif
21
-
22
-
23
-
24
- /* ANSI redefinitions */
25
- #ifdef INCHI_ANSI_ONLY /* { */
26
- #ifndef __isascii
27
- #define __isascii(val) ((unsigned)(val) <= 0x7F)
28
- #endif
29
-
30
- /* #ifndef __GNUC__ */
31
- /* these non-ANSI functions are implemented in gcc */
32
- #include <stdio.h>
33
- /* this #include provides size_t definition */
34
- /* implementation is located in util.c */
35
- #if ( !defined(_MSC_VER) || defined(__STDC__) && __STDC__ == 1 )
36
- /* support (VC++ Language extensions) = OFF && defined(INCHI_ANSI_ONLY) */
37
- int memicmp (const void*, const void*, size_t);
38
- int stricmp( const char *s1, const char *s2 );
39
- char *_strnset( char *string, int c, size_t count );
40
- char *_strdup( const char *string );
41
- #endif
42
- /* #endif */
43
-
44
- #endif /* } */
45
-
46
- #define inchi_max(a,b) (((a)>(b))?(a):(b))
47
- #define inchi_min(a,b) (((a)<(b))?(a):(b))
48
-
49
-
50
- #endif /* __INCHI_COMPAT_H__ */
@@ -1,40 +0,0 @@
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 __INCHIERR_H__
11
- #define __INCHIERR_H__
12
-
13
- #define _IS_OKAY 0
14
- #define _IS_WARNING 1
15
- #define _IS_ERROR 2 /* Microsoft defined its own IS_ERROR() macro */
16
- #define _IS_FATAL 3
17
- #define _IS_UNKNOWN 4 /* unknown error: used in INChI DLL only */
18
- #define _IS_EOF -1 /* end of file */
19
- #define _IS_SKIP -2
20
-
21
-
22
-
23
- #define INCHI_INP_ERROR_ERR 40
24
- #define INCHI_INP_ERROR_RET (-1)
25
-
26
- #define INCHI_INP_FATAL_ERR 1
27
- #define INCHI_INP_FATAL_RET 0
28
-
29
- #define INCHI_INP_EOF_ERR 11
30
- #define INCHI_INP_EOF_RET 0
31
-
32
- #define LOG_MASK_WARN 1
33
- #define LOG_MASK_ERR 2
34
- #define LOG_MASK_FATAL 4
35
-
36
- #define LOG_MASK_ALL (LOG_MASK_WARN | LOG_MASK_ERR | LOG_MASK_FATAL)
37
- #define LOG_MASK_NO_WARN (LOG_MASK_ERR | LOG_MASK_FATAL)
38
-
39
-
40
- #endif /* __INCHIERR_H__ */
@@ -1,593 +0,0 @@
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
-