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.
- data/README +44 -0
- data/Rakefile +123 -0
- data/ext/extconf.rb +26 -0
- data/ext/ruby_inchi_main.so +0 -0
- data/ext/src/aux2atom.h +2786 -0
- data/ext/src/comdef.h +148 -0
- data/ext/src/e_0dstereo.c +3014 -0
- data/ext/src/e_0dstereo.h +31 -0
- data/ext/src/e_comdef.h +57 -0
- data/ext/src/e_ctl_data.h +147 -0
- data/ext/src/e_ichi_io.c +498 -0
- data/ext/src/e_ichi_io.h +40 -0
- data/ext/src/e_ichi_parms.c +37 -0
- data/ext/src/e_ichi_parms.h +41 -0
- data/ext/src/e_ichicomp.h +50 -0
- data/ext/src/e_ichierr.h +40 -0
- data/ext/src/e_ichimain.c +593 -0
- data/ext/src/e_ichisize.h +43 -0
- data/ext/src/e_inchi_atom.c +75 -0
- data/ext/src/e_inchi_atom.h +33 -0
- data/ext/src/e_inpdef.h +41 -0
- data/ext/src/e_mode.h +706 -0
- data/ext/src/e_mol2atom.c +649 -0
- data/ext/src/e_readinch.c +58 -0
- data/ext/src/e_readmol.c +54 -0
- data/ext/src/e_readmol.h +180 -0
- data/ext/src/e_readstru.c +251 -0
- data/ext/src/e_readstru.h +33 -0
- data/ext/src/e_util.c +284 -0
- data/ext/src/e_util.h +61 -0
- data/ext/src/extr_ct.h +251 -0
- data/ext/src/ichi.h +206 -0
- data/ext/src/ichi_bns.c +7999 -0
- data/ext/src/ichi_bns.h +231 -0
- data/ext/src/ichican2.c +5000 -0
- data/ext/src/ichicano.c +2195 -0
- data/ext/src/ichicano.h +49 -0
- data/ext/src/ichicans.c +1625 -0
- data/ext/src/ichicant.h +379 -0
- data/ext/src/ichicomn.h +260 -0
- data/ext/src/ichicomp.h +50 -0
- data/ext/src/ichidrp.h +119 -0
- data/ext/src/ichierr.h +124 -0
- data/ext/src/ichiisot.c +101 -0
- data/ext/src/ichilnct.c +286 -0
- data/ext/src/ichimain.h +132 -0
- data/ext/src/ichimak2.c +1189 -0
- data/ext/src/ichimake.c +3812 -0
- data/ext/src/ichimake.h +205 -0
- data/ext/src/ichimap1.c +851 -0
- data/ext/src/ichimap2.c +2856 -0
- data/ext/src/ichimap4.c +1609 -0
- data/ext/src/ichinorm.c +741 -0
- data/ext/src/ichinorm.h +67 -0
- data/ext/src/ichiparm.c +45 -0
- data/ext/src/ichiparm.h +1441 -0
- data/ext/src/ichiprt1.c +3612 -0
- data/ext/src/ichiprt2.c +1511 -0
- data/ext/src/ichiprt3.c +3011 -0
- data/ext/src/ichiqueu.c +1003 -0
- data/ext/src/ichiring.c +326 -0
- data/ext/src/ichiring.h +49 -0
- data/ext/src/ichisize.h +35 -0
- data/ext/src/ichisort.c +539 -0
- data/ext/src/ichister.c +3538 -0
- data/ext/src/ichister.h +35 -0
- data/ext/src/ichitaut.c +3843 -0
- data/ext/src/ichitaut.h +387 -0
- data/ext/src/ichitime.h +74 -0
- data/ext/src/inchi_api.h +670 -0
- data/ext/src/inchi_dll.c +1480 -0
- data/ext/src/inchi_dll.h +34 -0
- data/ext/src/inchi_dll_main.c +23 -0
- data/ext/src/inchi_dll_main.h +31 -0
- data/ext/src/inpdef.h +328 -0
- data/ext/src/lreadmol.h +1246 -0
- data/ext/src/mode.h +706 -0
- data/ext/src/ruby_inchi_main.c +558 -0
- data/ext/src/runichi.c +4179 -0
- data/ext/src/strutil.c +3861 -0
- data/ext/src/strutil.h +182 -0
- data/ext/src/util.c +1130 -0
- data/ext/src/util.h +85 -0
- data/lib/clean_tempfile.rb +220 -0
- data/lib/rino.rb +111 -0
- data/test/test.rb +386 -0
- metadata +130 -0
data/ext/src/ichicomp.h
ADDED
@@ -0,0 +1,50 @@
|
|
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__ */
|
data/ext/src/ichidrp.h
ADDED
@@ -0,0 +1,119 @@
|
|
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 __INCHIDRP_H__
|
11
|
+
#define __INCHIDRP_H__
|
12
|
+
|
13
|
+
#ifndef INCHI_ANSI_ONLY /* { */
|
14
|
+
/********************************************
|
15
|
+
* Parameters for the structure drawing
|
16
|
+
********************************************/
|
17
|
+
#define TDP_LEN_LBL 16 /* length of a label (label: Req., Shown, Found) */
|
18
|
+
/* #define TDP_NUM_LBL 3 */ /* number of labels */
|
19
|
+
/* #define TDP_NUM_PAR 3 */ /* number of types per label (types: B/T, I/N, S) */
|
20
|
+
typedef enum tagTblTypes {itBASIC, itISOTOPIC, itSTEREO, TDP_NUM_PAR} TBL_TYPES; /* types */
|
21
|
+
typedef enum tagTblLabels{ ilSHOWN, TDP_NUM_LBL} TBL_LABELS; /* labels */
|
22
|
+
typedef struct tagTblDrawPatms {
|
23
|
+
char ReqShownFoundTxt[TDP_NUM_LBL][TDP_LEN_LBL];
|
24
|
+
char ReqShownFound[TDP_NUM_LBL][TDP_NUM_PAR];
|
25
|
+
int nOrientation; /* 10*degrees: 0 or 2700 */
|
26
|
+
int bDrawTbl;
|
27
|
+
} TBL_DRAW_PARMS;
|
28
|
+
/*********************************************/
|
29
|
+
typedef struct tagDrawParmsSettings {
|
30
|
+
TBL_DRAW_PARMS *tdp;
|
31
|
+
unsigned long ulDisplTime;
|
32
|
+
int bOrigAtom;
|
33
|
+
int nFontSize;
|
34
|
+
} SET_DRAW_PARMS; /* input only: how to draw or calculate */
|
35
|
+
/*********************************************/
|
36
|
+
typedef struct tagReturnedDrawParms {
|
37
|
+
int bEsc;
|
38
|
+
} RET_DRAW_PARMS;
|
39
|
+
/*********************************************/
|
40
|
+
typedef struct tagPersistDrawParms {
|
41
|
+
int rcPict[4];
|
42
|
+
} PER_DRAW_PARMS; /* saved between displaying different structures */
|
43
|
+
/*********************************************/
|
44
|
+
typedef struct tagDrawParms {
|
45
|
+
SET_DRAW_PARMS sdp; /* how to draw: fill on the 1st call */
|
46
|
+
RET_DRAW_PARMS rdp; /* returned when drawing window is closed */
|
47
|
+
PER_DRAW_PARMS *pdp; /* persistent: save between calls (window size) */
|
48
|
+
#ifndef INCHI_LIB
|
49
|
+
#ifndef INCHI_ANSI_ONLY
|
50
|
+
AT_NUMB *nEquLabels; /* num_inp_atoms elements, value>0 marks atoms in the set #value */
|
51
|
+
AT_NUMB nNumEquSets; /* max mark value */
|
52
|
+
AT_NUMB nCurEquLabel; /* current mark */
|
53
|
+
#endif
|
54
|
+
#endif
|
55
|
+
} DRAW_PARMS; /* Settings: How to draw the structure */
|
56
|
+
|
57
|
+
#endif /* } INCHI_ANSI_ONLY */
|
58
|
+
|
59
|
+
#if( ACD_LABS_VERSION == 1 )
|
60
|
+
#define MAX_NUM_PATHS 5
|
61
|
+
#else
|
62
|
+
#define MAX_NUM_PATHS 4
|
63
|
+
#endif
|
64
|
+
|
65
|
+
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;
|
66
|
+
typedef struct tagInputParms {
|
67
|
+
char szSdfDataHeader[MAX_SDF_HEADER+1];
|
68
|
+
char *pSdfLabel;
|
69
|
+
char *pSdfValue;
|
70
|
+
long lSdfId;
|
71
|
+
long lMolfileNumber;
|
72
|
+
#ifndef INCHI_ANSI_ONLY
|
73
|
+
DRAW_PARMS dp;
|
74
|
+
PER_DRAW_PARMS pdp;
|
75
|
+
TBL_DRAW_PARMS tdp;
|
76
|
+
#endif
|
77
|
+
/*
|
78
|
+
-- Files --
|
79
|
+
ip->path[0] => Input
|
80
|
+
ip->path[1] => Output (INChI)
|
81
|
+
ip->path[2] => Log
|
82
|
+
ip->path[3] => Problem structures
|
83
|
+
ip->path[4] => Errors file (ACD(
|
84
|
+
|
85
|
+
*/
|
86
|
+
const char *path[MAX_NUM_PATHS];
|
87
|
+
int num_paths;
|
88
|
+
int first_struct_number;
|
89
|
+
int last_struct_number;
|
90
|
+
INPUT_TYPE nInputType;
|
91
|
+
INCHI_MODE nMode;
|
92
|
+
int bAbcNumbers;
|
93
|
+
/*int bXml;*/
|
94
|
+
int bINChIOutputOptions; /* !(ip->bINChIOutputOptions & INCHI_OUT_PLAIN_TEXT) */
|
95
|
+
int bCtPredecessors;
|
96
|
+
int bXmlStarted;
|
97
|
+
int bDisplayEachComponentINChI;
|
98
|
+
|
99
|
+
long msec_MaxTime; /* was ulMaxTime; max time to run ProsessOneStructure */
|
100
|
+
long msec_LeftTime;
|
101
|
+
|
102
|
+
long ulDisplTime; /* not used: max structure or question display time */
|
103
|
+
int bDisplay;
|
104
|
+
int bMergeAllInputStructures;
|
105
|
+
int bSaveWarningStructsAsProblem;
|
106
|
+
int bSaveAllGoodStructsAsProblem;
|
107
|
+
int bGetSdfileId;
|
108
|
+
int bGetMolfileNumber; /* read molfile number from the name line like "Structure #22" */
|
109
|
+
int bCompareComponents; /* see flags CMP_COMPONENTS, etc. */
|
110
|
+
int bDisplayCompositeResults;
|
111
|
+
int bDoNotAddH;
|
112
|
+
int bNoStructLabels;
|
113
|
+
int bChiralFlag;
|
114
|
+
int bAllowEmptyStructure;
|
115
|
+
INCHI_MODE bTautFlags;
|
116
|
+
INCHI_MODE bTautFlagsDone;
|
117
|
+
} INPUT_PARMS;
|
118
|
+
|
119
|
+
#endif /* __INCHIDRP_H__ */
|
data/ext/src/ichierr.h
ADDED
@@ -0,0 +1,124 @@
|
|
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
|
+
#define CT_ERR_FIRST (-30000)
|
22
|
+
#define CT_OVERFLOW (CT_ERR_FIRST- 0) /*(-30000) */
|
23
|
+
#define CT_LEN_MISMATCH (CT_ERR_FIRST- 1) /*(-30001) */
|
24
|
+
#define CT_OUT_OF_RAM (CT_ERR_FIRST- 2) /*(-30002) */
|
25
|
+
#define CT_RANKING_ERR (CT_ERR_FIRST- 3) /*(-30003) */
|
26
|
+
#define CT_ISOCOUNT_ERR (CT_ERR_FIRST- 4) /*(-30004) */
|
27
|
+
#define CT_TAUCOUNT_ERR (CT_ERR_FIRST- 5) /*(-30005) */
|
28
|
+
#define CT_ISOTAUCOUNT_ERR (CT_ERR_FIRST- 6) /*(-30006) */
|
29
|
+
#define CT_MAPCOUNT_ERR (CT_ERR_FIRST- 7) /*(-30007) */
|
30
|
+
#define CT_TIMEOUT_ERR (CT_ERR_FIRST- 8) /*(-30008) */
|
31
|
+
#define CT_ISO_H_ERR (CT_ERR_FIRST- 9) /*(-30009) */
|
32
|
+
#define CT_STEREOCOUNT_ERR (CT_ERR_FIRST-10) /*(-30010) */
|
33
|
+
#define CT_ATOMCOUNT_ERR (CT_ERR_FIRST-11) /*(-30011) */
|
34
|
+
#define CT_STEREOBOND_ERROR (CT_ERR_FIRST-12) /*(-30012) */
|
35
|
+
#define CT_USER_QUIT_ERR (CT_ERR_FIRST-13) /*(-30013) */
|
36
|
+
#define CT_REMOVE_STEREO_ERR (CT_ERR_FIRST-14) /*(-30014) */
|
37
|
+
#define CT_CALC_STEREO_ERR (CT_ERR_FIRST-15) /*(-30015) */
|
38
|
+
#define CT_CANON_ERR (CT_ERR_FIRST-16) /*(-30016) */
|
39
|
+
#define CT_STEREO_CANON_ERR (CT_ERR_FIRST-17) /*(-30017) */
|
40
|
+
#define CT_UNKNOWN_ERR (CT_ERR_FIRST-18) /*(-30018) */
|
41
|
+
|
42
|
+
#define CT_ERR_MIN CT_UNKNOWN_ERR
|
43
|
+
#define CT_ERR_MAX CT_ERR_FIRST
|
44
|
+
|
45
|
+
#define CHECK_OVERFLOW(Len, Maxlen) ( (Len) >= (Maxlen) )
|
46
|
+
#define RETURNED_ERROR(nVal) (CT_ERR_MIN<=(nVal) && (nVal)<=CT_ERR_MAX)
|
47
|
+
|
48
|
+
|
49
|
+
#define BNS_ERR -9999
|
50
|
+
#define BNS_WRONG_PARMS (BNS_ERR + 0) /*(-9999)*/
|
51
|
+
#define BNS_OUT_OF_RAM (BNS_ERR + 1) /*(-9998)*/
|
52
|
+
#define BNS_PROGRAM_ERR (BNS_ERR + 2) /*(-9997)*/
|
53
|
+
#define BNS_ALTPATH_OVFL (BNS_ERR + 3) /*(-9996)*/
|
54
|
+
#define BNS_BOND_ERR (BNS_ERR + 4) /*(-9995)*/
|
55
|
+
#define BNS_VERT_NUM_ERR (BNS_ERR + 5) /*(-9994)*/
|
56
|
+
#define BNS_VERT_EDGE_OVFL (BNS_ERR + 6) /*(-9993)*/
|
57
|
+
#define BNS_SET_ALTP_ERR (BNS_ERR + 7) /*(-9992)*/
|
58
|
+
#define BNS_CPOINT_ERR (BNS_ERR + 8) /*(-9991)*/
|
59
|
+
#define BNS_CANT_SET_BOND (BNS_ERR + 9) /*(-9990)*/
|
60
|
+
#define BNS_CAP_FLOW_ERR (BNS_ERR + 10) /*(-9989)*/
|
61
|
+
#define BNS_RADICAL_ERR (BNS_ERR + 11) /*(-9988)*/
|
62
|
+
#define BNS_REINIT_ERR (BNS_ERR + 12) /*(-9987)*/
|
63
|
+
|
64
|
+
#define BNS_MAX_ERR_VALUE (BNS_ERR + 19) /*(-9980)*/
|
65
|
+
|
66
|
+
#define IS_BNS_ERROR(X) (BNS_ERR <= (X) && (X) <= BNS_MAX_ERR_VALUE)
|
67
|
+
|
68
|
+
|
69
|
+
#define INCHI_INP_ERROR_ERR 40
|
70
|
+
#define INCHI_INP_ERROR_RET (-1)
|
71
|
+
|
72
|
+
#define INCHI_INP_FATAL_ERR 1
|
73
|
+
#define INCHI_INP_FATAL_RET 0
|
74
|
+
|
75
|
+
#define INCHI_INP_EOF_ERR 11
|
76
|
+
#define INCHI_INP_EOF_RET 0
|
77
|
+
|
78
|
+
#ifndef INCHI_ALL_CPP
|
79
|
+
#ifdef __cplusplus
|
80
|
+
extern "C" {
|
81
|
+
#endif
|
82
|
+
#endif
|
83
|
+
|
84
|
+
extern int (*UserAction)(void); /* callback */
|
85
|
+
extern int (*ConsoleQuit)(void); /* Console user issued CTRL+C etc. */
|
86
|
+
|
87
|
+
#ifndef INCHI_ALL_CPP
|
88
|
+
#ifdef __cplusplus
|
89
|
+
}
|
90
|
+
#endif
|
91
|
+
#endif
|
92
|
+
|
93
|
+
#define LOG_MASK_WARN 1
|
94
|
+
#define LOG_MASK_ERR 2
|
95
|
+
#define LOG_MASK_FATAL 4
|
96
|
+
|
97
|
+
#define LOG_MASK_ALL (LOG_MASK_WARN | LOG_MASK_ERR | LOG_MASK_FATAL)
|
98
|
+
#define LOG_MASK_NO_WARN (LOG_MASK_ERR | LOG_MASK_FATAL)
|
99
|
+
|
100
|
+
#ifdef INCHI_LIB
|
101
|
+
#include <stdarg.h>
|
102
|
+
|
103
|
+
#ifndef INCHI_ALL_CPP
|
104
|
+
#ifdef __cplusplus
|
105
|
+
extern "C" {
|
106
|
+
#endif
|
107
|
+
#endif
|
108
|
+
|
109
|
+
extern void (*FWPRINT) (const char * format, va_list argptr );
|
110
|
+
extern void (*DRAWDATA) ( struct DrawData * pDrawData);
|
111
|
+
extern int (*DRAWDATA_EXISTS) ( int nComponent, int nType, int bReconnected );
|
112
|
+
extern struct DrawData * (*GET_DRAWDATA) ( int nComponent, int nType, int bReconnected );
|
113
|
+
|
114
|
+
#ifndef INCHI_ALL_CPP
|
115
|
+
#ifdef __cplusplus
|
116
|
+
}
|
117
|
+
#endif
|
118
|
+
#endif
|
119
|
+
|
120
|
+
#endif
|
121
|
+
|
122
|
+
#define USER_ACTION_QUIT 1
|
123
|
+
|
124
|
+
#endif /* __INCHIERR_H__ */
|
data/ext/src/ichiisot.c
ADDED
@@ -0,0 +1,101 @@
|
|
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
|
+
|
14
|
+
#include "mode.h"
|
15
|
+
|
16
|
+
#include "comdef.h"
|
17
|
+
#include "extr_ct.h"
|
18
|
+
#include "ichitaut.h"
|
19
|
+
#include "ichicant.h"
|
20
|
+
#include "ichicomn.h"
|
21
|
+
|
22
|
+
#ifdef NEVER
|
23
|
+
/**********************************************************************************/
|
24
|
+
int unpack_iso_sort_key( AT_ISO_SORT_KEY iso_sort_key, S_CHAR *num_1H, S_CHAR *num_2H, S_CHAR *num_3H, S_CHAR *iso_atw_diff )
|
25
|
+
{
|
26
|
+
int is_negative;
|
27
|
+
AT_ISO_SORT_KEY HOnlyAtwPart;
|
28
|
+
static const AT_ISO_SORT_KEY MultAtwDiff = AT_ISO_SORT_KEY_MULT*AT_ISO_SORT_KEY_MULT*AT_ISO_SORT_KEY_MULT;
|
29
|
+
if ( !iso_sort_key ) {
|
30
|
+
*num_1H = *num_2H = *num_3H = *iso_atw_diff = 0;
|
31
|
+
return 0;
|
32
|
+
} else
|
33
|
+
if ( iso_sort_key < 0 ) {
|
34
|
+
is_negative = 1;
|
35
|
+
iso_sort_key = -iso_sort_key;
|
36
|
+
HOnlyAtwPart = MultAtwDiff - iso_sort_key % MultAtwDiff;
|
37
|
+
iso_sort_key += HOnlyAtwPart;
|
38
|
+
} else {
|
39
|
+
is_negative = 0;
|
40
|
+
HOnlyAtwPart = iso_sort_key % MultAtwDiff;
|
41
|
+
iso_sort_key -= HOnlyAtwPart;
|
42
|
+
}
|
43
|
+
|
44
|
+
iso_sort_key /= MultAtwDiff;
|
45
|
+
|
46
|
+
*num_1H = (S_CHAR)(HOnlyAtwPart % AT_ISO_SORT_KEY_MULT);
|
47
|
+
HOnlyAtwPart /= AT_ISO_SORT_KEY_MULT;
|
48
|
+
*num_2H = (S_CHAR)(HOnlyAtwPart % AT_ISO_SORT_KEY_MULT);
|
49
|
+
HOnlyAtwPart /= AT_ISO_SORT_KEY_MULT;
|
50
|
+
*num_3H = (S_CHAR)(HOnlyAtwPart % AT_ISO_SORT_KEY_MULT);
|
51
|
+
|
52
|
+
*iso_atw_diff = (S_CHAR)(is_negative? -iso_sort_key : iso_sort_key);
|
53
|
+
|
54
|
+
return 1;
|
55
|
+
}
|
56
|
+
#endif
|
57
|
+
|
58
|
+
/**********************************************************************************/
|
59
|
+
AT_ISO_SORT_KEY make_iso_sort_key( int iso_atw_diff, int num_1H, int num_2H, int num_3H)
|
60
|
+
{
|
61
|
+
AT_ISO_SORT_KEY iso_sort_key = 0, mult=1;
|
62
|
+
|
63
|
+
iso_sort_key += mult * num_1H;
|
64
|
+
mult *= AT_ISO_SORT_KEY_MULT;
|
65
|
+
iso_sort_key += mult * num_2H;
|
66
|
+
mult *= AT_ISO_SORT_KEY_MULT;
|
67
|
+
iso_sort_key += mult * num_3H;
|
68
|
+
mult *= AT_ISO_SORT_KEY_MULT;
|
69
|
+
iso_sort_key += mult * iso_atw_diff;
|
70
|
+
return iso_sort_key;
|
71
|
+
}
|
72
|
+
/**********************************************************************************/
|
73
|
+
/* set sp_ATOM isotopic sort keys */
|
74
|
+
int set_atom_iso_sort_keys( int num_at, sp_ATOM *at, T_GROUP_INFO* t_group_info, int *bHasIsotopicInTautomerGroups )
|
75
|
+
{
|
76
|
+
int i, num_isotopic = 0, bMergedTgroup;
|
77
|
+
AT_ISO_SORT_KEY iso_sort_key;
|
78
|
+
T_GROUP *t_group =
|
79
|
+
(t_group_info &&
|
80
|
+
t_group_info->t_group &&
|
81
|
+
t_group_info->num_t_groups > 0)? t_group_info->t_group : NULL;
|
82
|
+
|
83
|
+
if ( bHasIsotopicInTautomerGroups )
|
84
|
+
*bHasIsotopicInTautomerGroups = 0;
|
85
|
+
for ( i = 0; i < num_at; i ++ ) {
|
86
|
+
bMergedTgroup = (t_group_info && t_group_info->nIsotopicEndpointAtomNumber && (at[i].cFlags & AT_FLAG_ISO_H_POINT));
|
87
|
+
if ( (!at[i].endpoint || !t_group) && !bMergedTgroup ) {
|
88
|
+
iso_sort_key = make_iso_sort_key(at[i].iso_atw_diff, at[i].num_iso_H[0], at[i].num_iso_H[1], at[i].num_iso_H[2]);
|
89
|
+
} else {
|
90
|
+
/* H isotopes go to the tautomer part of the CT (name) */
|
91
|
+
/* if (at[i].endpoint && t_group) ... */
|
92
|
+
iso_sort_key = make_iso_sort_key(at[i].iso_atw_diff, 0, 0, 0);
|
93
|
+
if ( bHasIsotopicInTautomerGroups )
|
94
|
+
*bHasIsotopicInTautomerGroups += (at[i].num_iso_H[0] || at[i].num_iso_H[1] || at[i].num_iso_H[2] || bMergedTgroup);
|
95
|
+
}
|
96
|
+
at[i].iso_sort_key = iso_sort_key;
|
97
|
+
num_isotopic += (iso_sort_key != 0);
|
98
|
+
}
|
99
|
+
return num_isotopic;
|
100
|
+
}
|
101
|
+
|
data/ext/src/ichilnct.c
ADDED
@@ -0,0 +1,286 @@
|
|
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 <limits.h>
|
13
|
+
#include <math.h>
|
14
|
+
#include <float.h>
|
15
|
+
#include <string.h>
|
16
|
+
#include <ctype.h>
|
17
|
+
|
18
|
+
/* for use in the InChI library */
|
19
|
+
|
20
|
+
#include "mode.h"
|
21
|
+
#include "inchi_api.h"
|
22
|
+
#include "util.h"
|
23
|
+
#include "ichierr.h"
|
24
|
+
#include "ichicomp.h"
|
25
|
+
|
26
|
+
#define my_fgetsTab l_my_fgetsTab
|
27
|
+
#define my_fgetsTab1 l_my_fgetsTab1
|
28
|
+
#define my_fgets l_my_fgets
|
29
|
+
#define str_fgetc l_str_fgetc
|
30
|
+
#define str_fgets l_str_fgets
|
31
|
+
#define str_fgetsTab l_str_fgetsTab
|
32
|
+
|
33
|
+
#define INChIToInchi_Atom l_INChIToInchi_Atom
|
34
|
+
|
35
|
+
int INChIToInchi_Input( INCHI_FILE *inp_molfile, inchi_Input *orig_at_data, int bMergeAllInputStructures,
|
36
|
+
int bDoNotAddH, INPUT_TYPE nInputType,
|
37
|
+
char *pSdfLabel, char *pSdfValue, long *lSdfId, INCHI_MODE *pInpAtomFlags,
|
38
|
+
int *err, char *pStrErr );
|
39
|
+
|
40
|
+
/* This contains executable code. Included in lReadAux.c, e_ReadINCH.c, ReadINCH.c, */
|
41
|
+
#include "aux2atom.h"
|
42
|
+
|
43
|
+
extern int bLibInchiSemaphore;
|
44
|
+
/*****************************************************************************************************/
|
45
|
+
EXPIMP_TEMPLATE INCHI_API int INCHI_DECL Get_inchi_Input_FromAuxInfo(
|
46
|
+
char *szInchiAuxInfo, int bDoNotAddH, InchiInpData *pInchiInp )
|
47
|
+
{
|
48
|
+
INCHI_FILE inp;
|
49
|
+
int num_at, nRet = inchi_Ret_OKAY, err = 0;
|
50
|
+
INCHI_MODE bChiral = 0;
|
51
|
+
/* the input string may contain the following line: "Structure NNN. HHH=VVV" */
|
52
|
+
long lNumber; /* structure number NNN from the input */
|
53
|
+
char szHeader[MAX_SDF_HEADER]; /* stucture label header HHH from the input */
|
54
|
+
char szLabel[MAX_SDF_VALUE]; /* stucture label VVV from the input */
|
55
|
+
if ( bLibInchiSemaphore ) { /* does not work properly under sufficient stress */
|
56
|
+
return inchi_Ret_BUSY;
|
57
|
+
}
|
58
|
+
bLibInchiSemaphore = 1;
|
59
|
+
|
60
|
+
if ( pInchiInp && pInchiInp->pInp ) {
|
61
|
+
/* clear output fields */
|
62
|
+
inchi_Input *pInp = pInchiInp->pInp;
|
63
|
+
char *szOptions = pInp->szOptions;
|
64
|
+
memset( pInchiInp, 0, sizeof(*pInchiInp) );
|
65
|
+
memset( pInp, 0, sizeof(*pInp) );
|
66
|
+
pInp->szOptions = szOptions;
|
67
|
+
pInchiInp->pInp = pInp;
|
68
|
+
} else {
|
69
|
+
bLibInchiSemaphore = 0;
|
70
|
+
return inchi_Ret_ERROR;
|
71
|
+
}
|
72
|
+
szHeader[0] = '\0';
|
73
|
+
szLabel[0] = '\0';
|
74
|
+
lNumber = 0;
|
75
|
+
/* prepare input string pointers */
|
76
|
+
inp.pStr = szInchiAuxInfo;
|
77
|
+
inp.nUsedLength = strlen(szInchiAuxInfo);
|
78
|
+
inp.nAllocatedLength = inp.nUsedLength+1;
|
79
|
+
inp.nPtr = 0;
|
80
|
+
|
81
|
+
num_at = INChIToInchi_Input( &inp, pInchiInp->pInp, 1, bDoNotAddH, INPUT_INCHI_PLAIN,
|
82
|
+
szHeader, szLabel, &lNumber, &bChiral,
|
83
|
+
&err, pInchiInp->szErrMsg );
|
84
|
+
pInchiInp->bChiral = bChiral;
|
85
|
+
if ( num_at <= 0 ) {
|
86
|
+
if ( 10 < err && err < 20 ) {
|
87
|
+
nRet = inchi_Ret_EOF;
|
88
|
+
} else
|
89
|
+
if ( err == 9 ) {
|
90
|
+
nRet = inchi_Ret_ERROR; /* sdfile bypassed to $$$$ */
|
91
|
+
} else
|
92
|
+
if ( err && err < 30 ) {
|
93
|
+
nRet = inchi_Ret_FATAL;
|
94
|
+
} else
|
95
|
+
if ( 98 == err ) {
|
96
|
+
nRet = inchi_Ret_WARNING; /* empty AuxInfo */
|
97
|
+
} else
|
98
|
+
if ( err ) {
|
99
|
+
nRet = inchi_Ret_ERROR;
|
100
|
+
} else
|
101
|
+
if ( pInchiInp->szErrMsg[0] ) {
|
102
|
+
nRet = inchi_Ret_WARNING;
|
103
|
+
}
|
104
|
+
}
|
105
|
+
if ( nRet != inchi_Ret_OKAY && nRet != inchi_Ret_WARNING ) {
|
106
|
+
Free_inchi_Input( pInchiInp->pInp );
|
107
|
+
pInchiInp->bChiral = 0;
|
108
|
+
}
|
109
|
+
bLibInchiSemaphore = 0;
|
110
|
+
return nRet;
|
111
|
+
}
|
112
|
+
/*****************************************************************************************************/
|
113
|
+
EXPIMP_TEMPLATE INCHI_API void INCHI_DECL Free_inchi_Input( inchi_Input *pInp )
|
114
|
+
{
|
115
|
+
FreeInchi_Atom( &pInp->atom );
|
116
|
+
FreeInchi_Stereo0D ( &pInp->stereo0D );
|
117
|
+
pInp->num_atoms = 0;
|
118
|
+
pInp->num_stereo0D = 0;
|
119
|
+
}
|
120
|
+
|
121
|
+
|
122
|
+
/*#endif*/ /* INCHI_MAIN */
|
123
|
+
|
124
|
+
#ifndef INCHI_LIBRARY
|
125
|
+
#error "INCHI_LIBRARY MUST be defined here"
|
126
|
+
#endif
|
127
|
+
|
128
|
+
|
129
|
+
/**********************************************************************************/
|
130
|
+
int INChIToInchi_Input( INCHI_FILE *inp_molfile, inchi_Input *orig_at_data, int bMergeAllInputStructures,
|
131
|
+
int bDoNotAddH, INPUT_TYPE nInputType,
|
132
|
+
char *pSdfLabel, char *pSdfValue, long *lSdfId, INCHI_MODE *pInpAtomFlags,
|
133
|
+
int *err, char *pStrErr )
|
134
|
+
{
|
135
|
+
/* inp_ATOM *at = NULL; */
|
136
|
+
int num_dimensions_new;
|
137
|
+
int num_inp_bonds_new;
|
138
|
+
int num_inp_atoms_new;
|
139
|
+
int num_inp_0D_new;
|
140
|
+
inchi_Atom *at_new = NULL;
|
141
|
+
inchi_Atom *at_old = NULL;
|
142
|
+
inchi_Stereo0D *stereo0D_new = NULL;
|
143
|
+
inchi_Stereo0D *stereo0D_old = NULL;
|
144
|
+
int nNumAtoms = 0, nNumStereo0D = 0;
|
145
|
+
MOL_COORD *szCoordNew = NULL;
|
146
|
+
MOL_COORD *szCoordOld = NULL;
|
147
|
+
int i, j;
|
148
|
+
|
149
|
+
if ( pStrErr ) {
|
150
|
+
pStrErr[0] = '\0';
|
151
|
+
}
|
152
|
+
|
153
|
+
/*FreeOrigAtData( orig_at_data );*/
|
154
|
+
if ( lSdfId )
|
155
|
+
*lSdfId = 0;
|
156
|
+
do {
|
157
|
+
|
158
|
+
at_old = orig_at_data? orig_at_data->atom : NULL; /* save pointer to the previous allocation */
|
159
|
+
stereo0D_old = orig_at_data? orig_at_data->stereo0D : NULL;
|
160
|
+
szCoordOld = NULL;
|
161
|
+
num_inp_atoms_new =
|
162
|
+
INChIToInchi_Atom( inp_molfile, orig_at_data? &stereo0D_new:NULL, &num_inp_0D_new,
|
163
|
+
bDoNotAddH, nInputType, orig_at_data? &at_new:NULL, MAX_ATOMS,
|
164
|
+
&num_dimensions_new, &num_inp_bonds_new,
|
165
|
+
pSdfLabel, pSdfValue, lSdfId, pInpAtomFlags, err, pStrErr );
|
166
|
+
if ( num_inp_atoms_new <= 0 && !*err ) {
|
167
|
+
MOLFILE_ERR_SET (*err, 0, "Empty structure");
|
168
|
+
*err = 98;
|
169
|
+
} else
|
170
|
+
if ( orig_at_data && !num_inp_atoms_new && 10 < *err && *err < 20 && orig_at_data->num_atoms > 0 && bMergeAllInputStructures ) {
|
171
|
+
*err = 0; /* end of file */
|
172
|
+
break;
|
173
|
+
} else
|
174
|
+
if ( num_inp_atoms_new > 0 && orig_at_data ) {
|
175
|
+
/* merge pOrigDataTmp + orig_at_data => pOrigDataTmp; */
|
176
|
+
nNumAtoms = num_inp_atoms_new + orig_at_data->num_atoms;
|
177
|
+
nNumStereo0D = num_inp_0D_new + orig_at_data->num_stereo0D;
|
178
|
+
if ( nNumAtoms >= MAX_ATOMS ) {
|
179
|
+
MOLFILE_ERR_SET (*err, 0, "Too many atoms");
|
180
|
+
*err = 70;
|
181
|
+
orig_at_data->num_atoms = -1;
|
182
|
+
} else
|
183
|
+
if ( !at_old ) {
|
184
|
+
/* the first structure */
|
185
|
+
orig_at_data->atom = at_new; at_new = NULL;
|
186
|
+
orig_at_data->num_atoms = num_inp_atoms_new; num_inp_atoms_new = 0;
|
187
|
+
orig_at_data->stereo0D = stereo0D_new; stereo0D_new = NULL;
|
188
|
+
orig_at_data->num_stereo0D = num_inp_0D_new; num_inp_0D_new = 0;
|
189
|
+
} else
|
190
|
+
if ( orig_at_data->atom = CreateInchi_Atom( nNumAtoms ) ) {
|
191
|
+
/* switch at_new <--> orig_at_data->at; */
|
192
|
+
if ( orig_at_data->num_atoms ) {
|
193
|
+
memcpy( orig_at_data->atom, at_old, orig_at_data->num_atoms * sizeof(orig_at_data->atom[0]) );
|
194
|
+
/* adjust numbering in the newly read structure */
|
195
|
+
for ( i = 0; i < num_inp_atoms_new; i ++ ) {
|
196
|
+
for ( j = 0; j < at_new[i].num_bonds; j ++ ) {
|
197
|
+
at_new[i].neighbor[j] += orig_at_data->num_atoms;
|
198
|
+
}
|
199
|
+
}
|
200
|
+
}
|
201
|
+
FreeInchi_Atom( &at_old );
|
202
|
+
/* copy newly read structure */
|
203
|
+
memcpy( orig_at_data->atom + orig_at_data->num_atoms,
|
204
|
+
at_new,
|
205
|
+
num_inp_atoms_new * sizeof(orig_at_data->atom[0]) );
|
206
|
+
/* copy newly read 0D stereo */
|
207
|
+
if ( num_inp_0D_new > 0 && stereo0D_new ) {
|
208
|
+
if ( orig_at_data->stereo0D = CreateInchi_Stereo0D( nNumStereo0D ) ) {
|
209
|
+
memcpy( orig_at_data->stereo0D, stereo0D_old, orig_at_data->num_stereo0D * sizeof(orig_at_data->stereo0D[0]) );
|
210
|
+
/* adjust numbering in the newly read structure */
|
211
|
+
for ( i = 0; i < num_inp_0D_new; i ++ ) {
|
212
|
+
if ( stereo0D_new[i].central_atom >= 0 ) {
|
213
|
+
stereo0D_new[i].central_atom += orig_at_data->num_atoms;
|
214
|
+
}
|
215
|
+
for ( j = 0; j < 4; j ++ ) {
|
216
|
+
stereo0D_new[i].neighbor[j] += orig_at_data->num_atoms;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
FreeInchi_Stereo0D( &stereo0D_old );
|
220
|
+
memcpy( orig_at_data->stereo0D+orig_at_data->num_stereo0D,
|
221
|
+
stereo0D_new,
|
222
|
+
num_inp_0D_new * sizeof(orig_at_data->stereo0D[0]) );
|
223
|
+
} else {
|
224
|
+
num_inp_0D_new = 0;
|
225
|
+
MOLFILE_ERR_SET (*err, 0, "Out of RAM");
|
226
|
+
*err = -1;
|
227
|
+
}
|
228
|
+
} else {
|
229
|
+
num_inp_0D_new = 0;
|
230
|
+
}
|
231
|
+
/* update lengths */
|
232
|
+
orig_at_data->num_atoms += num_inp_atoms_new;
|
233
|
+
orig_at_data->num_stereo0D += num_inp_0D_new;
|
234
|
+
} else {
|
235
|
+
MOLFILE_ERR_SET (*err, 0, "Out of RAM");
|
236
|
+
*err = -1;
|
237
|
+
}
|
238
|
+
} else
|
239
|
+
if ( num_inp_atoms_new > 0 ) {
|
240
|
+
nNumAtoms += num_inp_atoms_new;
|
241
|
+
}
|
242
|
+
FreeInchi_Atom( &at_new );
|
243
|
+
num_inp_atoms_new = 0;
|
244
|
+
FreeInchi_Stereo0D( &stereo0D_new );
|
245
|
+
num_inp_0D_new = 0;
|
246
|
+
|
247
|
+
} while ( !*err && bMergeAllInputStructures );
|
248
|
+
/*
|
249
|
+
if ( !*err ) {
|
250
|
+
orig_at_data->num_components =
|
251
|
+
MarkDisconnectedComponents( orig_at_data );
|
252
|
+
if ( orig_at_data->num_components == 0 ) {
|
253
|
+
MOLFILE_ERR_SET (*err, 0, "No components found");
|
254
|
+
*err = 99;
|
255
|
+
}
|
256
|
+
if ( orig_at_data->num_components < 0 ) {
|
257
|
+
MOLFILE_ERR_SET (*err, 0, "Too many components");
|
258
|
+
*err = 99;
|
259
|
+
}
|
260
|
+
}
|
261
|
+
*/
|
262
|
+
if ( szCoordNew ) {
|
263
|
+
inchi_free( szCoordNew );
|
264
|
+
}
|
265
|
+
if ( at_new ) {
|
266
|
+
inchi_free( at_new );
|
267
|
+
}
|
268
|
+
/*
|
269
|
+
if ( !*err ) {
|
270
|
+
if ( ReconcileAllCmlBondParities( orig_at_data->atom, orig_at_data->num_atoms ) ) {
|
271
|
+
MOLFILE_ERR_SET (*err, 0, "Cannot reconcile stereobond parities");
|
272
|
+
if (!orig_at_data->num_atoms) {
|
273
|
+
*err = 1;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}
|
277
|
+
*/
|
278
|
+
if ( *err ) {
|
279
|
+
FreeInchi_Input( orig_at_data );
|
280
|
+
}
|
281
|
+
if ( *err && !(10 < *err && *err < 20) && pStrErr && !pStrErr[0] ) {
|
282
|
+
MOLFILE_ERR_SET (*err, 0, "Unknown error"); /* <BRKPT> */
|
283
|
+
}
|
284
|
+
return orig_at_data? orig_at_data->num_atoms : nNumAtoms;
|
285
|
+
}
|
286
|
+
|