InChI
 
Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: MIT
3 * Copyright (c) 2024 IUPAC and InChI Trust
4 */
5
6#ifndef _UTIL_H_
7#define _UTIL_H_
8
9#include "inpdef.h"
10
11#define EL_NUMBER_H ((U_CHAR)1)
12#define EL_NUMBER_B ((U_CHAR)5)
13#define EL_NUMBER_C ((U_CHAR)6)
14#define EL_NUMBER_N ((U_CHAR)7)
15#define EL_NUMBER_O ((U_CHAR)8)
16#define EL_NUMBER_F ((U_CHAR)9)
17#define EL_NUMBER_SI ((U_CHAR)14)
18#define EL_NUMBER_P ((U_CHAR)15)
19#define EL_NUMBER_S ((U_CHAR)16)
20#define EL_NUMBER_CL ((U_CHAR)17)
21#define EL_NUMBER_GE ((U_CHAR)32)
22#define EL_NUMBER_AS ((U_CHAR)33)
23#define EL_NUMBER_SE ((U_CHAR)34)
24#define EL_NUMBER_BR ((U_CHAR)35)
25#define EL_NUMBER_SB ((U_CHAR)51)
26#define EL_NUMBER_TE ((U_CHAR)52)
27#define EL_NUMBER_I ((U_CHAR)53)
28#define EL_NUMBER_PO ((U_CHAR)84)
29#define EL_NUMBER_AT ((U_CHAR)85)
30
31#define EL_NUMBER_ZY ((U_CHAR)119)
32#define EL_NUMBER_ZZ ((U_CHAR)120)
33
34#ifndef COMPILE_ALL_CPP
35#ifdef __cplusplus
36extern "C" {
37#endif
38#endif
39
46int get_atomic_mass(const char *elname);
47
54int get_atomic_mass_from_elnum(int nAtNum);
55
71int 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);
72
81int extract_charges_and_radicals(char *elname, int *pnRadical, int *pnCharge);
82
90int extract_H_atoms(char *elname, S_CHAR num_iso_H[]);
91
98int normalize_string(char *name);
99
109int read_upto_delim(char **pstring, char *field, int maxlen, char *delims);
110
118int is_matching_any_delim(char c, char *delims);
119
126int dotify_non_printable_chars(char *line);
127
135char *lrtrim(char *p, int *nLen);
136
142void remove_trailing_spaces(char *p);
143
149void remove_one_lf(char *p);
150
161int mystrncpy(char *target, const char *source, unsigned maxlen);
162
168void mystrrev(char *p);
169
170#define ALPHA_BASE 27
171
180int inchi_memicmp(const void *p1, const void *p2, size_t length);
181
189int inchi_stricmp(const char *s1, const char *s2);
190
199char *inchi__strnset(char *s, int val, size_t length);
200
207char *inchi__strdup(const char *string);
208
217long inchi_strtol(const char *str, const char **p, int base);
218
226double inchi_strtod(const char *str, const char **p);
227
233void inchi_dot_decimal(char *str);
234
243AT_NUMB *is_in_the_list(AT_NUMB *pathAtom, AT_NUMB nNextAtom, int nPathLen);
244
253int *is_in_the_ilist(int *pathAtom, int nNextAtom, int nPathLen);
254
264int is_ilist_inside(int *ilist, int nlist, int *ilist2, int nlist2);
265
273void extract_inchi_substring(char **buf, const char *str, size_t slen);
274
282void extract_auxinfo_substring(char **buf, const char *str, size_t slen);
283
291int extract_orig_nums_from_auxinfo_string(char *saux, int *orig);
292
304int extract_nonstereo_eq_classes_from_auxinfo_string(char *saux, int nat, int *orig, int *have_eclass_info, int *eclass, int *eclass_by_origs);
305
315int extract_stereo_info_from_inchi_string(char *sinchi, int nat, int *orig, int *at_stereo_mark);
316
326int extract_all_backbone_bonds_from_inchi_string(char *sinchi, int *n_all_bkb_orig, int *orig, int *all_bkb_orig);
327
334int get_periodic_table_number(const char *elname);
335
342int is_el_a_metal(int nPeriodicNum);
343
352int get_el_valence(int nPeriodicNum, int charge, int val_num);
353
365int get_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds);
366
367/* Output valence that does not fit any known valences */
368
380int detect_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds);
381
394int needed_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int actual_bonds_val, int num_H, int num_bonds);
395
402int get_el_type(int nPeriodicNum);
403
410int if_skip_add_H(int nPeriodicNum);
411
419int get_element_chemical_symbol(int nAtNum, char *szElement);
420
428int get_element_or_pseudoelement_symbol(int nAtNum, char *szElement);
429
441int MakeRemovedProtonsString(int nNumRemovedProtons, NUM_H *nNumExchgIsotopicH, NUM_H *nNumRemovedProtonsIsotopic, int bIsotopic, char *szRemovedProtons, int *num_removed_iso_H);
442
443/*
444 Ion pairs and fixing bonds
445*/
446
454int num_of_H(inp_ATOM *at, int iat);
455
462U_CHAR ion_el_group(int el);
463
472int has_other_ion_neigh(inp_ATOM *at, int iat, int iat_ion_neigh);
473
482int has_other_ion_in_sphere_2(inp_ATOM *at, int iat, int iat_ion_neigh);
483
491int nNoMetalNumBonds(inp_ATOM *at, int at_no);
492
500int nNoMetalBondsValence(inp_ATOM *at, int at_no);
501
509int nNoMetalNeighIndex(inp_ATOM *at, int at_no);
510
519int nNoMetalOtherNeighIndex(inp_ATOM *at, int at_no, int cur_neigh);
520
530int nNoMetalOtherNeighIndex2(inp_ATOM *at, int at_no, int cur_neigh, int cur_neigh2);
531
539int nBondsValToMetal(inp_ATOM *at, int iat);
540
549int nBondsValenceInpAt(const inp_ATOM *at, int *nNumAltBonds, int *nNumWrongBonds);
550
558int bHeteroAtomMayHaveXchgIsoH(inp_ATOM *atom, int iat);
559
566int get_endpoint_valence(U_CHAR el_number);
567#if (KETO_ENOL_TAUT == 1)
568
575int get_endpoint_valence_KET(U_CHAR el_number);
576#endif
577
578#define MIN_ATOM_CHARGE (-2)
579#define MAX_ATOM_CHARGE 2
580#define NEUTRAL_STATE (-MIN_ATOM_CHARGE)
581#define NUM_ATOM_CHARGES (MAX_ATOM_CHARGE - MIN_ATOM_CHARGE + 1)
582#define MAX_NUM_VALENCES 5 /* max. number + 1 to provide zero termination */
583
584/* CHEMICAL ELEMENTS & ATOMIC VALENCE MODEL
585 FOR VARIOUS OXIDATION STATES
586*/
587typedef struct tagElData
588{
589 /* Element chemical symbol */
590 const char* szElName;
591 /* Average atomic mass from the Periodic Chart of the Elements
592 (Fisher cat. no. 05-702-10) */
594 /* (not used currently) Atomic mass of the most abundant isotope */
596 /* (not used currently) Exact mw of the most abundant isotope (not used) */
597 double dAtMass;
598 /* METAL or METAL2 */
599 int nType;
600 /* (not used currently) Pauling electronegativity x 10; 0 means unknown */
602 /* InChI does not add implicit H to atoms that have non-zero bSkipAddingH */
603 /* NB: was called bDoNotAddH, renamed to avoid confusion with other procedures */
607
608/* Forward declaration */
609struct tagCANON_GLOBALS;
610
617int SetBitFree(struct tagCANON_GLOBALS *pCG);
618
625void WriteCoord(char *str, double x);
626extern const int ERR_ELEM;
627extern const int nElDataLen;
628
629#ifndef COMPILE_ALL_CPP
630#ifdef __cplusplus
631}
632#endif
633#endif
634
635#ifndef INCHI_BUILD_PLATFORM
636
637#if defined(_WIN32)
638
639#if defined(_WIN64)
640#define INCHI_BUILD_PLATFORM "Windows 64-bit"
641#else
642#define INCHI_BUILD_PLATFORM "Windows 32-bit"
643#endif
644
645#elif defined(__linux__)
646
647#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 */
648#define INCHI_BUILD_PLATFORM "Linux 64-bit"
649#else
650#define INCHI_BUILD_PLATFORM "Linux 32-bit"
651#endif
652
653#elif defined(__APPLE__)
654#define INCHI_BUILD_PLATFORM "OSX"
655
656#else
657#define INCHI_BUILD_PLATFORM ""
658#endif
659#endif
660
661#ifndef INCHI_BUILD_DEBUG
662#if defined(_DEBUG)
663#define INCHI_BUILD_DEBUG " Debug"
664#else
665#define INCHI_BUILD_DEBUG ""
666#endif
667#endif
668
669#ifndef INCHI_SRC_REV
670#if defined(_DEBUG)
671#define INCHI_SRC_REV "rev. 9b6f1414ebf3+"
672#else
673#define INCHI_SRC_REV ""
674#endif
675#endif
676
677#ifndef INCHI_BUILD_COMPILER
678
679#if defined(_MSC_VER)
680
681#if _MSC_VER > 1900
682#define INCHI_BUILD_COMPILER "MS VS 2017 or later"
683#elif _MSC_VER == 1900
684#define INCHI_BUILD_COMPILER "MS VS 2015"
685#elif _MSC_VER == 1800
686#define INCHI_BUILD_COMPILER "MS VS 2013"
687#elif _MSC_VER == 1700
688#define INCHI_BUILD_COMPILER "MS VS 2012"
689#elif _MSC_VER == 1600
690#define INCHI_BUILD_COMPILER "MS VS 2010"
691#elif _MSC_VER == 1500
692#define INCHI_BUILD_COMPILER "MS VS 2008"
693#elif _MSC_VER == 1400
694#define INCHI_BUILD_COMPILER "MS VS 2005"
695#elif _MSC_VER == 1310
696#define INCHI_BUILD_COMPILER "MS VS 2003"
697#elif _MSC_VER == 1300
698#define INCHI_BUILD_COMPILER "MS VS 2002"
699#elif _MSC_VER == 1200
700#define INCHI_BUILD_COMPILER "MS VS 6.0"
701#else
702#define INCHI_BUILD_COMPILER "MS VC++ 5.0 or earlier"
703#endif
704
705#else
706
707#if defined(__GNUC__)
708#define INCHI_BUILD_COMPILER "gcc " __VERSION__ ""
709#else
710#define INCHI_BUILD_COMPILER ""
711#endif
712#endif
713
714#endif
715
716#endif /* _UTIL_H_ */
unsigned short AT_NUMB
Definition ichisize.h:10
signed short NUM_H
Definition ichisize.h:14
signed char S_CHAR
Definition inchi_api.h:78
unsigned char U_CHAR
Definition inchi_api.h:79
Definition ichicant.h:303
Definition util.h:588
double dAtMass
Definition util.h:597
int nNormAtMass
Definition util.h:595
int nElNegPauling10
Definition util.h:601
const char * szElName
Definition util.h:590
int nAtMass
Definition util.h:593
int bSkipAddingH
Definition util.h:604
S_CHAR cValence[NUM_ATOM_CHARGES][MAX_NUM_VALENCES]
Definition util.h:605
int nType
Definition util.h:599
Structure describing an input atom.
Definition inpdef.h:107
int num_of_H(inp_ATOM *at, int iat)
Get the number of hydrogens.
Definition util.c:894
int get_element_chemical_symbol(int nAtNum, char *szElement)
Finds chemical symbol for element of given number.
Definition util.c:42
int get_el_type(int nPeriodicNum)
Get the el type object.
Definition util.c:440
int extract_H_atoms(char *elname, S_CHAR num_iso_H[])
Extract H atoms from element name.
Definition util.c:535
char * inchi__strnset(char *s, int val, size_t length)
Set a string to a specified value for a given length.
Definition util.c:1786
AT_NUMB * is_in_the_list(AT_NUMB *pathAtom, AT_NUMB nNextAtom, int nPathLen)
Checks if an atom is in the list/path.
Definition util.c:825
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)
Get the number of attached hydrogens.
Definition util.c:623
int detect_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds)
Output valence that does not fit any known valences.
Definition util.c:381
int if_skip_add_H(int nPeriodicNum)
Check if no H addition allowed.
Definition util.c:181
int is_el_a_metal(int nPeriodicNum)
Check if an element is a metal.
Definition util.c:449
int extract_charges_and_radicals(char *elname, int *pnRadical, int *pnCharge)
Extract charges and radicals from element name.
Definition util.c:461
void extract_inchi_substring(char **buf, const char *str, size_t slen)
Extract InChI substring embedded into a longer string.
Definition util.c:1624
void WriteCoord(char *str, double x)
Write coordinate (double) to string.
int extract_orig_nums_from_auxinfo_string(char *saux, int *orig)
Parse AuxInfostring and get a list of original atom numbers orig[cano_num].
Definition runichi2.c:1483
int nNoMetalNeighIndex(inp_ATOM *at, int at_no)
Get the index of the first element that is not a metal.
Definition util.c:1151
int get_atomic_mass(const char *elname)
Get the atomic mass object.
Definition util.c:806
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:1524
int has_other_ion_in_sphere_2(inp_ATOM *at, int iat, int iat_ion_neigh)
Check whether an atom has ion neighbors within sphere (breath first search (BFS) up to r=2)
Definition util.c:966
double inchi_strtod(const char *str, const char **p)
Convert string to double.
Definition ichiprt2.c:2623
int inchi_stricmp(const char *s1, const char *s2)
Case-insensitive string comparison.
Definition util.c:1759
int nBondsValenceInpAt(const inp_ATOM *at, int *nNumAltBonds, int *nNumWrongBonds)
Gets the number of bond valences.
Definition ichi_bns.c:1637
void remove_one_lf(char *p)
Remove one line feed character from the end of a string.
Definition util.c:1504
char * lrtrim(char *p, int *nLen)
Trim leading and trailing spaces from a string.
Definition util.c:1568
int extract_stereo_info_from_inchi_string(char *sinchi, int nat, int *orig, int *at_stereo_mark)
Extract stereo information from InChI string.
Definition ichiread.c:12527
#define NUM_ATOM_CHARGES
Definition util.h:581
int get_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds)
Output valence needed to unambiguosly reconstruct bonds.
Definition util.c:215
int nNoMetalOtherNeighIndex(inp_ATOM *at, int at_no, int cur_neigh)
Get the index of an element that is not a metal excluding a given index.
Definition util.c:1170
int extract_all_backbone_bonds_from_inchi_string(char *sinchi, int *n_all_bkb_orig, int *orig, int *all_bkb_orig)
Extract all backbone bonds from InChI string.
Definition ichiread.c:12575
int get_endpoint_valence_KET(U_CHAR el_number)
Get the endpoint valence KET object.
Definition util.c:1295
const int nElDataLen
Definition eldata.c:185
int nBondsValToMetal(inp_ATOM *at, int iat)
Gets the number of bond valences to a metal atom.
Definition util.c:865
int get_el_valence(int nPeriodicNum, int charge, int val_num)
Get reference value of atom valence at given charge.
Definition util.c:192
#define MAX_NUM_VALENCES
Definition util.h:582
long inchi_strtol(const char *str, const char **p, int base)
Convert string to long integer.
Definition ichiprt2.c:2553
int is_matching_any_delim(char c, char *delims)
Check if a character is in the list of possible delimiters.
Definition util.c:1474
int * is_in_the_ilist(int *pathAtom, int nNextAtom, int nPathLen)
Checks if an integer is in the list/path.
Definition util.c:837
int get_endpoint_valence(U_CHAR el_number)
Get the endpoint valence object.
Definition util.c:1274
int nNoMetalOtherNeighIndex2(inp_ATOM *at, int at_no, int cur_neigh, int cur_neigh2)
Get the index of an element that is not a metal excluding a 2 given indexes.
Definition util.c:1191
void inchi_dot_decimal(char *str)
Replace the locale decimal point printed by sprintf with '.' (GH #100)
Definition ichiprt2.c:2684
int extract_nonstereo_eq_classes_from_auxinfo_string(char *saux, int nat, int *orig, int *have_eclass_info, int *eclass, int *eclass_by_origs)
Parse AuxInfostring and get non-stereo equivalence classes.
Definition runichi2.c:1521
char * inchi__strdup(const char *string)
Duplicate a string.
Definition util.c:1799
U_CHAR ion_el_group(int el)
Get the element group of an element. The base element rather than the periodic group is used to aid r...
Definition util.c:916
int is_ilist_inside(int *ilist, int nlist, int *ilist2, int nlist2)
Checks if one list of integers is inside another list (ilist in ilist2)
Definition util.c:850
int get_periodic_table_number(const char *elname)
Get the periodic table number object.
Definition util.c:117
int nNoMetalBondsValence(inp_ATOM *at, int at_no)
Returns the number of non-metal bond valences.
Definition util.c:1085
void remove_trailing_spaces(char *p)
Remove trailing spaces from a string.
Definition util.c:1492
int read_upto_delim(char **pstring, char *field, int maxlen, char *delims)
Read up to any delimiter from the string.
Definition util.c:1423
int has_other_ion_neigh(inp_ATOM *at, int iat, int iat_ion_neigh)
Check whether an atom has ion neighbors.
Definition util.c:940
int get_atomic_mass_from_elnum(int nAtNum)
Get the atomic mass from elnum object.
Definition util.c:773
int SetBitFree(struct tagCANON_GLOBALS *pCG)
Frees bit string in canonicalisation data structure.
Definition ichican2.c:3276
const int ERR_ELEM
Definition eldata.c:183
int needed_unusual_el_valence(int nPeriodicNum, int charge, int radical, int bonds_valence, int actual_bonds_val, int num_H, int num_bonds)
Output valence needed to unambiguosly reconstruct number of H.
Definition util.c:279
int bHeteroAtomMayHaveXchgIsoH(inp_ATOM *atom, int iat)
Checks whether a hetero atom may have exchangeable isotopic hydrogens.
Definition strutil.c:4860
int nNoMetalNumBonds(inp_ATOM *at, int at_no)
Returns the number of non-metal bonds.
Definition util.c:1018
struct tagElData ELDATA
int MakeRemovedProtonsString(int nNumRemovedProtons, NUM_H *nNumExchgIsotopicH, NUM_H *nNumRemovedProtonsIsotopic, int bIsotopic, char *szRemovedProtons, int *num_removed_iso_H)
Creates a string from the removed protons (?)
void extract_auxinfo_substring(char **buf, const char *str, size_t slen)
Extract AuxInfo substring embedded into a longer string.
Definition util.c:1685
int inchi_memicmp(const void *p1, const void *p2, size_t length)
Compare two memory blocks in a case-insensitive manner.
Definition util.c:1735
int dotify_non_printable_chars(char *line)
Replace non-ASCII characters with '.',.
Definition util.c:1395
void mystrrev(char *p)
Reverse a string in place.
Definition ichimake.c:2054
int get_element_or_pseudoelement_symbol(int nAtNum, char *szElement)
Finds symbol for element of given number. Accounts for (translates)pseudoelements.
Definition util.c:69
int normalize_string(char *name)
Normalize string (remove leading & trailing spaces, replace consecutive spaces with a single space,...
Definition util.c:1354