InChI
 
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/*
2 * International Chemical Identifier (InChI)
3 * Version 1
4 * Software version 1.07
5 * April 30, 2024
6 *
7 * MIT License
8 *
9 * Copyright (c) 2024 IUPAC and InChI Trust
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice shall be included in all
19 * copies or substantial portions of the Software.
20 *
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 * SOFTWARE.
28 *
29 * The InChI library and programs are free software developed under the
30 * auspices of the International Union of Pure and Applied Chemistry (IUPAC).
31 * Originally developed at NIST.
32 * Modifications and additions by IUPAC and the InChI Trust.
33 * Some portions of code were developed/changed by external contributors
34 * (either contractor or volunteer) which are listed in the file
35 * 'External-contributors' included in this distribution.
36 *
37 * info@inchi-trust.org
38 *
39 */
40
41#ifndef _UTIL_H_
42#define _UTIL_H_
43
44#include "inpdef.h"
45
46
47#define EL_NUMBER_H ((U_CHAR) 1)
48#define EL_NUMBER_B ((U_CHAR) 5)
49#define EL_NUMBER_C ((U_CHAR) 6)
50#define EL_NUMBER_N ((U_CHAR) 7)
51#define EL_NUMBER_O ((U_CHAR) 8)
52#define EL_NUMBER_F ((U_CHAR) 9)
53#define EL_NUMBER_SI ((U_CHAR) 14)
54#define EL_NUMBER_P ((U_CHAR) 15)
55#define EL_NUMBER_S ((U_CHAR) 16)
56#define EL_NUMBER_CL ((U_CHAR) 17)
57#define EL_NUMBER_GE ((U_CHAR) 32)
58#define EL_NUMBER_AS ((U_CHAR) 33)
59#define EL_NUMBER_SE ((U_CHAR) 34)
60#define EL_NUMBER_BR ((U_CHAR) 35)
61#define EL_NUMBER_SB ((U_CHAR) 51)
62#define EL_NUMBER_TE ((U_CHAR) 52)
63#define EL_NUMBER_I ((U_CHAR) 53)
64#define EL_NUMBER_PO ((U_CHAR) 84)
65#define EL_NUMBER_AT ((U_CHAR) 85)
66
67#define EL_NUMBER_ZY ((U_CHAR)119)
68#define EL_NUMBER_ZZ ((U_CHAR)120)
69
70#ifndef COMPILE_ALL_CPP
71#ifdef __cplusplus
72extern "C"
73{
74#endif
75#endif
76
83 int get_atomic_mass(const char *elname);
84
91 int get_atomic_mass_from_elnum(int nAtNum);
92 int get_num_H(const char *elname,
93 int inp_num_H,
94 S_CHAR num_iso_H[],
95 int charge,
96 int radical,
97 int chem_bonds_valence,
98 int atom_input_valence,
99 int bAliased,
100 int bDoNotAddH,
101 int bHasMetalNeighbor);
102 int extract_charges_and_radicals(char *elname,
103 int *pnRadical,
104 int *pnCharge);
105 int extract_H_atoms(char *elname, S_CHAR num_iso_H[]);
106
107 int normalize_string(char *name);
108 int read_upto_delim(char **pstring, char *field, int maxlen, char *delims);
109 int is_matching_any_delim(char c, char *delims);
110 int dotify_non_printable_chars(char *line);
111 char *lrtrim(char *p, int *nLen);
112 void remove_trailing_spaces(char *p);
113 void remove_one_lf(char *p);
114 int mystrncpy(char *target,
115 const char *source,
116 unsigned maxlen);
117 void mystrrev(char *p);
118
119#define ALPHA_BASE 27
120
121 int inchi_memicmp(const void *p1, const void *p2, size_t length);
122 int inchi_stricmp(const char *s1, const char *s2);
123 char *inchi__strnset(char *s, int val, size_t length);
124 char *inchi__strdup(const char *string);
125
126 long inchi_strtol(const char *str, const char **p, int base);
127 double inchi_strtod(const char *str, const char **p);
128 AT_NUMB *is_in_the_list(AT_NUMB *pathAtom, AT_NUMB nNextAtom, int nPathLen);
129 int *is_in_the_ilist(int *pathAtom, int nNextAtom, int nPathLen);
130 int is_ilist_inside(int *ilist, int nlist, int *ilist2, int nlist2);
131
132 void extract_inchi_substring(char **buf, const char *str, size_t slen);
133 void extract_auxinfo_substring(char **buf, const char *str, size_t slen);
134 int extract_orig_nums_from_auxinfo_string(char *saux, int *orig);
135 int extract_nonstereo_eq_classes_from_auxinfo_string(char *saux, int nat, int *orig,
136 int *have_eclass_info, int *eclass,
137 int *eclass_by_origs);
138 int extract_stereo_info_from_inchi_string(char *sinchi, int nat, int *orig, int *at_stereo_mark);
139 int extract_all_backbone_bonds_from_inchi_string(char *sinchi, int *n_all_bkb_orig, int *orig, int *all_bkb_orig);
140
141 int get_periodic_table_number(const char *elname);
142 int is_el_a_metal(int nPeriodicNum);
143 int get_el_valence(int nPeriodicNum,
144 int charge,
145 int val_num);
146 int get_unusual_el_valence(int nPeriodicNum,
147 int charge,
148 int radical,
149 int bonds_valence,
150 int num_H,
151 int num_bonds);
152
153 /* Output valence that does not fit any known valences */
154 int detect_unusual_el_valence(int nPeriodicNum,
155 int charge,
156 int radical,
157 int bonds_valence,
158 int num_H,
159 int num_bonds);
160 int needed_unusual_el_valence(int nPeriodicNum,
161 int charge,
162 int radical,
163 int bonds_valence,
164 int actual_bonds_val,
165 int num_H,
166 int num_bonds);
167 int get_el_type(int nPeriodicNum);
168 int if_skip_add_H(int nPeriodicNum);
169 int get_element_chemical_symbol(int nAtNum,
170 char *szElement);
172 char *szElement);
173 int MakeRemovedProtonsString(int nNumRemovedProtons,
174 NUM_H *nNumExchgIsotopicH,
175 NUM_H *nNumRemovedProtonsIsotopic,
176 int bIsotopic,
177 char *szRemovedProtons,
178 int *num_removed_iso_H);
179
180 /*
181 Ion pairs and fixing bonds
182 */
183
184 int num_of_H(inp_ATOM *at, int iat);
185 U_CHAR ion_el_group(int el);
186 int has_other_ion_neigh(inp_ATOM *at, int iat, int iat_ion_neigh);
187 int has_other_ion_in_sphere_2(inp_ATOM *at, int iat, int iat_ion_neigh);
188 int nNoMetalNumBonds(inp_ATOM *at, int at_no);
189 int nNoMetalBondsValence(inp_ATOM *at, int at_no);
190 int nNoMetalNeighIndex(inp_ATOM *at, int at_no);
191 int nNoMetalOtherNeighIndex(inp_ATOM *at, int at_no, int cur_neigh);
192 int nNoMetalOtherNeighIndex2(inp_ATOM *at, int at_no, int cur_neigh, int cur_neigh2);
193 int nBondsValToMetal(inp_ATOM *at, int iat);
194 int nBondsValenceInpAt(const inp_ATOM *at, int *nNumAltBonds, int *nNumWrongBonds);
195 int bHeteroAtomMayHaveXchgIsoH(inp_ATOM *atom, int iat);
196 int get_endpoint_valence(U_CHAR el_number);
197#if (KETO_ENOL_TAUT == 1)
198 int get_endpoint_valence_KET(U_CHAR el_number);
199#endif
200
201 /* Forward declaration */
202 struct tagCANON_GLOBALS;
203
204 int SetBitFree(struct tagCANON_GLOBALS *pCG);
205 void WriteCoord(char *str, double x);
206 extern const int ERR_ELEM;
207 extern const int nElDataLen;
208
209#ifndef COMPILE_ALL_CPP
210#ifdef __cplusplus
211}
212#endif
213#endif
214
215#ifndef INCHI_BUILD_PLATFORM
216
217#if defined(_WIN32)
218
219#if defined(_WIN64)
220#define INCHI_BUILD_PLATFORM "Windows 64-bit"
221#else
222#define INCHI_BUILD_PLATFORM "Windows 32-bit"
223#endif
224
225#elif defined(__linux__)
226
227#if defined(__x86_64__) || defined(__ppc64__) || defined(__aarch64__) /* djb-rwth: macro added for 64-bit ARM CPUs -- GH issue #10, thanks to Vincent F. Scalfani */
228#define INCHI_BUILD_PLATFORM "Linux 64-bit"
229#else
230#define INCHI_BUILD_PLATFORM "Linux 32-bit"
231#endif
232
233#elif defined(__APPLE__)
234#define INCHI_BUILD_PLATFORM "OSX"
235
236#else
237#define INCHI_BUILD_PLATFORM ""
238#endif
239#endif
240
241#ifndef INCHI_BUILD_DEBUG
242#if defined(_DEBUG)
243#define INCHI_BUILD_DEBUG " Debug"
244#else
245#define INCHI_BUILD_DEBUG ""
246#endif
247#endif
248
249#ifndef INCHI_SRC_REV
250#if defined(_DEBUG)
251#define INCHI_SRC_REV "rev. 9b6f1414ebf3+"
252#else
253#define INCHI_SRC_REV ""
254#endif
255#endif
256
257#ifndef INCHI_BUILD_COMPILER
258
259#if defined(_MSC_VER)
260
261#if _MSC_VER > 1900
262#define INCHI_BUILD_COMPILER "MS VS 2017 or later"
263#elif _MSC_VER == 1900
264#define INCHI_BUILD_COMPILER "MS VS 2015"
265#elif _MSC_VER == 1800
266#define INCHI_BUILD_COMPILER "MS VS 2013"
267#elif _MSC_VER == 1700
268#define INCHI_BUILD_COMPILER "MS VS 2012"
269#elif _MSC_VER == 1600
270#define INCHI_BUILD_COMPILER "MS VS 2010"
271#elif _MSC_VER == 1500
272#define INCHI_BUILD_COMPILER "MS VS 2008"
273#elif _MSC_VER == 1400
274#define INCHI_BUILD_COMPILER "MS VS 2005"
275#elif _MSC_VER == 1310
276#define INCHI_BUILD_COMPILER "MS VS 2003"
277#elif _MSC_VER == 1300
278#define INCHI_BUILD_COMPILER "MS VS 2002"
279#elif _MSC_VER == 1200
280#define INCHI_BUILD_COMPILER "MS VS 6.0"
281#else
282#define INCHI_BUILD_COMPILER "MS VC++ 5.0 or earlier"
283#endif
284
285#else
286
287#if defined(__GNUC__)
288#define INCHI_BUILD_COMPILER "gcc " __VERSION__ ""
289#else
290#define INCHI_BUILD_COMPILER ""
291#endif
292#endif
293
294#endif
295
296#endif /* _UTIL_H_ */
unsigned short AT_NUMB
Definition ichisize.h:45
signed short NUM_H
Definition ichisize.h:49
signed char S_CHAR
Definition inchi_api.h:113
unsigned char U_CHAR
Definition inchi_api.h:114
Definition ichicant.h:338
Definition inpdef.h:110
int num_of_H(inp_ATOM *at, int iat)
Definition util.c:1087
int get_element_chemical_symbol(int nAtNum, char *szElement)
Definition util.c:284
int get_el_type(int nPeriodicNum)
Definition util.c:652
int extract_H_atoms(char *elname, S_CHAR num_iso_H[])
Definition util.c:743
char * inchi__strnset(char *s, int val, size_t length)
Definition util.c:1973
AT_NUMB * is_in_the_list(AT_NUMB *pathAtom, AT_NUMB nNextAtom, int nPathLen)
Definition util.c:1021
int get_num_H(const char *elname, int inp_num_H, S_CHAR num_iso_H[], int charge, int radical, int chem_bonds_valence, int atom_input_valence, int bAliased, int bDoNotAddH, int bHasMetalNeighbor)
Definition util.c:830
int detect_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds)
Definition util.c:594
int if_skip_add_H(int nPeriodicNum)
Definition util.c:407
int is_el_a_metal(int nPeriodicNum)
Definition util.c:661
int extract_charges_and_radicals(char *elname, int *pnRadical, int *pnCharge)
Definition util.c:671
void extract_inchi_substring(char **buf, const char *str, size_t slen)
Definition util.c:1804
void WriteCoord(char *str, double x)
int extract_orig_nums_from_auxinfo_string(char *saux, int *orig)
Definition runichi2.c:1385
int nNoMetalNeighIndex(inp_ATOM *at, int at_no)
Definition util.c:1346
int get_atomic_mass(const char *elname)
Get the atomic mass object.
Definition util.c:1003
int mystrncpy(char *target, const char *source, unsigned maxlen)
Copies up to maxlen characters INCLUDING end null from source to target. Fills out the rest of the ta...
Definition util.c:1712
int has_other_ion_in_sphere_2(inp_ATOM *at, int iat, int iat_ion_neigh)
Definition util.c:1164
double inchi_strtod(const char *str, const char **p)
Definition ichiprt2.c:2211
int inchi_stricmp(const char *s1, const char *s2)
Definition util.c:1947
int nBondsValenceInpAt(const inp_ATOM *at, int *nNumAltBonds, int *nNumWrongBonds)
Definition ichi_bns.c:1671
void remove_one_lf(char *p)
Remove one line feed character from the end of the string.
Definition util.c:1689
char * lrtrim(char *p, int *nLen)
Remove leading and trailing white spaces.
Definition util.c:1749
int extract_stereo_info_from_inchi_string(char *sinchi, int nat, int *orig, int *at_stereo_mark)
Definition ichiread.c:12464
int get_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds)
Definition util.c:431
int nNoMetalOtherNeighIndex(inp_ATOM *at, int at_no, int cur_neigh)
Definition util.c:1364
int extract_all_backbone_bonds_from_inchi_string(char *sinchi, int *n_all_bkb_orig, int *orig, int *all_bkb_orig)
Definition ichiread.c:12512
int get_endpoint_valence_KET(U_CHAR el_number)
Definition util.c:1482
const int nElDataLen
Definition util.c:274
int nBondsValToMetal(inp_ATOM *at, int iat)
Definition util.c:1059
int get_el_valence(int nPeriodicNum, int charge, int val_num)
Definition util.c:417
long inchi_strtol(const char *str, const char **p, int base)
Definition ichiprt2.c:2192
int is_matching_any_delim(char c, char *delims)
Check if a character is in the list of possible delimiters.
Definition util.c:1655
int * is_in_the_ilist(int *pathAtom, int nNextAtom, int nPathLen)
Definition util.c:1033
int get_endpoint_valence(U_CHAR el_number)
Definition util.c:1463
int nNoMetalOtherNeighIndex2(inp_ATOM *at, int at_no, int cur_neigh, int cur_neigh2)
Definition util.c:1384
int extract_nonstereo_eq_classes_from_auxinfo_string(char *saux, int nat, int *orig, int *have_eclass_info, int *eclass, int *eclass_by_origs)
Definition runichi2.c:1423
char * inchi__strdup(const char *string)
Definition util.c:1985
U_CHAR ion_el_group(int el)
Definition util.c:1115
int is_ilist_inside(int *ilist, int nlist, int *ilist2, int nlist2)
Definition util.c:1045
int get_periodic_table_number(const char *elname)
Definition util.c:355
int nNoMetalBondsValence(inp_ATOM *at, int at_no)
Definition util.c:1281
void remove_trailing_spaces(char *p)
Remove trailing spaces from a string.
Definition util.c:1674
int read_upto_delim(char **pstring, char *field, int maxlen, char *delims)
Definition util.c:1602
int has_other_ion_neigh(inp_ATOM *at, int iat, int iat_ion_neigh)
Definition util.c:1139
int get_atomic_mass_from_elnum(int nAtNum)
Get the atomic mass from elnum object.
Definition util.c:973
int SetBitFree(struct tagCANON_GLOBALS *pCG)
Definition ichican2.c:3259
const int ERR_ELEM
Definition util.c:273
int needed_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int actual_bonds_val, int num_H, int num_bonds)
Definition util.c:494
int bHeteroAtomMayHaveXchgIsoH(inp_ATOM *atom, int iat)
Definition strutil.c:4040
int nNoMetalNumBonds(inp_ATOM *at, int at_no)
Definition util.c:1215
int MakeRemovedProtonsString(int nNumRemovedProtons, NUM_H *nNumExchgIsotopicH, NUM_H *nNumRemovedProtonsIsotopic, int bIsotopic, char *szRemovedProtons, int *num_removed_iso_H)
void extract_auxinfo_substring(char **buf, const char *str, size_t slen)
Definition util.c:1869
int inchi_memicmp(const void *p1, const void *p2, size_t length)
Compare two memory blocks in a case-insensitive manner.
Definition util.c:1924
int dotify_non_printable_chars(char *line)
Definition util.c:1575
void mystrrev(char *p)
Definition ichimake.c:2090
int get_element_or_pseudoelement_symbol(int nAtNum, char *szElement)
Definition util.c:310
int normalize_string(char *name)
Definition util.c:1535