1 /* 2 * International Chemical Identifier (InChI) 3 * Version 1 4 * Software version 1.04 5 * September 9, 2011 6 * 7 * The InChI library and programs are free software developed under the 8 * auspices of the International Union of Pure and Applied Chemistry (IUPAC). 9 * Originally developed at NIST. Modifications and additions by IUPAC 10 * and the InChI Trust. 11 * 12 * IUPAC/InChI-Trust Licence for the International Chemical Identifier (InChI) 13 * Software version 1.0. 14 * Copyright (C) IUPAC and InChI Trust Limited 15 * 16 * This library is free software; you can redistribute it and/or modify it under the 17 * terms of the IUPAC/InChI Trust Licence for the International Chemical Identifier 18 * (InChI) Software version 1.0; either version 1.0 of the License, or 19 * (at your option) any later version. 20 * 21 * This library is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 24 * See the IUPAC/InChI Trust Licence for the International Chemical Identifier (InChI) 25 * Software version 1.0 for more details. 26 * 27 * You should have received a copy of the IUPAC/InChI Trust Licence for the 28 * International Chemical Identifier (InChI) Software version 1.0 along with 29 * this library; if not, write to: 30 * 31 * The InChI Trust 32 * c/o FIZ CHEMIE Berlin 33 * Franklinstrasse 11 34 * 10587 Berlin 35 * GERMANY 36 * 37 */ 38 39 40 /* input/output format */ 41 #ifndef __INPDEF_H__ 42 #define __INPDEF_H__ 43 44 /*^^^ */ 45 #include "mode.h" 46 #include "incomdef.h" 47 #include "ichidrp.h" 48 /*^^^ */ 49 50 #define bDrawingLabelLeftShift endpoint /* for drawing only */ 51 typedef S_SHORT ST_CAP_FLOW; 52 53 /* inp_ATOM::at_type */ 54 #define ATT_NONE 0x0000 55 #define ATT_ACIDIC_CO 0x0001 56 #define ATT_ACIDIC_S 0x0002 57 #define ATT_OO 0x0004 58 #define ATT_ZOO 0x0008 59 #define ATT_NO 0x0010 60 #define ATT_N_O 0x0020 61 #define ATT_ATOM_N 0x0040 62 #define ATT_ATOM_P 0x0080 63 #define ATT_OTHER_NEG_O 0x0100 64 #define ATT_OTHER_ZO 0x0200 /* -Z=O or =Z=O */ 65 #define ATT_OH_MINUS 0x0400 /* OH(-), O=O,S,Se,Te */ 66 #define ATT_O_PLUS 0x0800 /* -OH2(+), =OH(+), -OH(+)-, OH3(+), =O(+)-, etc; O=O,S,Se,Te */ 67 #define ATT_PROTON 0x1000 68 #define ATT_HalAnion 0x2000 69 #define ATT_HalAcid 0x4000 70 #if ( FIX_NP_MINUS_BUG == 1 ) 71 #define ATT_NP_MINUS_V23 0x8000 /* =N(-) or =P(-) where = previously was triple */ 72 #endif 73 74 #define AT_FLAG_ISO_H_POINT 0x01 /* may have isotopic H */ 75 76 #define PERIODIC_NUMBER_H 1 77 78 #ifndef NUMH 79 #define NUM_ISO_H(AT,N) (AT[N].num_iso_H[0]+AT[N].num_iso_H[1]+AT[N].num_iso_H[2]) 80 #define NUMH(AT,N) (AT[N].num_H+NUM_ISO_H(AT,N)) 81 #endif 82 83 #define FlagSC_0D 1 /* bUsed0DParity */ 84 #define FlagSB_0D 2 /* bUsed0DParity */ 85 86 #define SB_PARITY_FLAG 0x38 /* mask for disconnected metal parity if it is different */ 87 #define SB_PARITY_SHFT 3 /* number of right shift bits to get disconnected metal parity */ 88 #define SB_PARITY_MASK 0x07 89 #define SB_PARITY_1(X) (X & SB_PARITY_MASK) /* refers to connected structure */ 90 #define SB_PARITY_2(X) (((X) >> SB_PARITY_SHFT) & SB_PARITY_MASK) /* refers to connected structure */ 91 92 93 94 typedef struct tagInputAtom { 95 char elname[ATOM_EL_LEN]; /* chem. element name */ 96 U_CHAR el_number; /* number of the element in the Periodic Table */ 97 AT_NUMB neighbor[MAXVAL]; /* positions (from 0) of the neighbors in the inp_ATOM array */ 98 AT_NUMB orig_at_number; /* original atom number */ 99 AT_NUMB orig_compt_at_numb; /* atom number within the component before terminal H removal */ 100 S_CHAR bond_stereo[MAXVAL]; /* 1=Up,4=Either,6=Down; this atom is at the pointing wedge, 101 negative => on the opposite side; 3=Either double bond */ 102 U_CHAR bond_type[MAXVAL]; /* 1..4; 4="aromatic", should be discouraged on input */ 103 104 S_CHAR valence; /* number of bonds = number of neighbors */ 105 S_CHAR chem_bonds_valence; /* sum of bond types (type 4 needs special treatment) */ 106 S_CHAR num_H; /* number of implicit hydrogens including D and T */ 107 S_CHAR num_iso_H[NUM_H_ISOTOPES]; /* number of implicit 1H, 2H(D), 3H(T) < 16 */ 108 S_CHAR iso_atw_diff; /* =0 => natural isotopic abundances */ 109 /* >0 => (mass) - (mass of the most abundant isotope) + 1 */ 110 /* <0 => (mass) - (mass of the most abundant isotope) */ 111 S_CHAR charge; /* charge */ 112 S_CHAR radical; /* RADICAL_SINGLET, RADICAL_DOUBLET, or RADICAL_TRIPLET */ 113 S_CHAR bAmbiguousStereo; 114 S_CHAR cFlags; /* AT_FLAG_ISO_H_POINT */ 115 AT_NUMB at_type; /* ATT_NONE, ATT_ACIDIC */ 116 AT_NUMB component; /* number of the structure component > 0 */ 117 AT_NUMB endpoint; /* id of a tautomeric group */ 118 AT_NUMB c_point; /* id of a positive charge group */ 119 double x; 120 double y; 121 double z; 122 /* cml 0D parities */ 123 S_CHAR bUsed0DParity; /* bit=1 => stereobond; bit=2 => stereocenter */ 124 /* cml tetrahedral parity */ 125 S_CHAR p_parity; 126 AT_NUMB p_orig_at_num[MAX_NUM_STEREO_ATOM_NEIGH]; 127 /* cml bond parities */ 128 S_CHAR sb_ord[MAX_NUM_STEREO_BONDS]; /* stereo bond/neighbor ordering number, starts from 0 */ 129 /* neighbors on both sides of stereobond have same sign=> trans/T/E, diff. signs => cis/C/Z */ 130 S_CHAR sn_ord[MAX_NUM_STEREO_BONDS]; /* ord. num. of the neighbor adjacent to the SB; starts from 0; 131 -1 means removed explicit H */ 132 /* neighbors on both sides of stereobond have same parity => trans/T/E/2, diff. parities => cis/C/Z/1 */ 133 S_CHAR sb_parity[MAX_NUM_STEREO_BONDS]; 134 AT_NUMB sn_orig_at_num[MAX_NUM_STEREO_BONDS]; /* orig. at number of sn_ord[] neighbors */ 135 136 #if ( FIND_RING_SYSTEMS == 1 ) 137 S_CHAR bCutVertex; 138 AT_NUMB nRingSystem; 139 AT_NUMB nNumAtInRingSystem; 140 AT_NUMB nBlockSystem; 141 142 #if ( FIND_RINS_SYSTEMS_DISTANCES == 1 ) 143 AT_NUMB nDistanceFromTerminal; /* terminal atom or ring system has 1, next has 2, etc. */ 144 #endif 145 146 #endif 147 } inp_ATOM; 148 149 typedef struct tagOrigAtom { 150 /* initially filled out by MolfileToOrigAtom */ 151 /* may be changed by disconnecting salts and disconnecting metals */ 152 inp_ATOM *at; 153 int num_dimensions; 154 int num_inp_bonds; 155 int num_inp_atoms; 156 /* may be changed by disconnecting salts and disconnecting metals */ 157 int num_components; /* set by MarkDisconnectedComponents() and disconnecting metals */ 158 int bDisconnectSalts; /* whether salt disconnection is possible */ 159 int bDisconnectCoord; /* 0 if no disconnection needed else (Num Implicit H to disconnect)+1 */ 160 #if ( bRELEASE_VERSION == 0 ) 161 int bExtract; 162 #endif 163 AT_NUMB *nCurAtLen; /* has max_num_components elements */ 164 AT_NUMB *nOldCompNumber; /* 0 or component number in previous numbering */ 165 int nNumEquSets; /* number of found component equivalence sets */ 166 AT_NUMB *nEquLabels; /* num_inp_atoms elements, value>0 marks atoms in the set #value */ 167 AT_NUMB *nSortedOrder; /* num_components elements, values = 1..num_components; only if num_components > 1 */ 168 int bSavedInINCHI_LIB[INCHI_NUM]; 169 int bPreprocessed[INCHI_NUM]; 170 MOL_COORD *szCoord; 171 } ORIG_ATOM_DATA; 172 173 typedef struct tagOriginalStruct { 174 int num_atoms; 175 char *szAtoms; 176 char *szBonds; 177 char *szCoord; 178 } ORIG_STRUCT; 179 180 typedef struct tagAtomParmsForDrawing { 181 char at_string[ATOM_INFO_LEN]; 182 int DrawingLabelLeftShift; 183 int DrawingLabelLength; 184 AT_NUMB nCanonNbr; /* if zero then do not use all data for the atom */ 185 AT_NUMB nCanonEquNbr; 186 AT_NUMB nTautGroupCanonNbr; 187 AT_NUMB nTautGroupEquNbr; 188 S_CHAR cFlags; /* AT_FLAG_ISO_H_POINT */ 189 #ifdef DISPLAY_DEBUG_DATA 190 int nDebugData; 191 #endif 192 S_CHAR cHighlightTheAtom; 193 S_CHAR cStereoCenterParity; 194 S_CHAR cStereoBondParity[MAX_STEREO_BONDS]; 195 S_CHAR cStereoBondWarning[MAX_STEREO_BONDS]; 196 S_CHAR cStereoBondNumber[MAX_STEREO_BONDS]; 197 } inf_ATOM; 198 199 200 #define INF_STEREO_ABS 0x0001 201 #define INF_STEREO_REL 0x0002 202 #define INF_STEREO_RAC 0x0004 203 #define INF_STEREO_NORM 0x0008 204 #define INF_STEREO_INV 0x0010 205 #define INF_STEREO 0x0020 206 #define INF_STEREO_ABS_REL_RAC (INF_STEREO_ABS | INF_STEREO_REL | INF_STEREO_RAC) 207 #define INF_STEREO_NORM_INV (INF_STEREO_NORM | INF_STEREO_INV) 208 209 #define MAX_LEN_REMOVED_PROTONS 128 210 211 typedef struct tagInfoAtomData { 212 inf_ATOM *at; 213 int num_at; 214 AT_NUMB StereoFlags; 215 AT_NUMB num_components; 216 AT_NUMB *pStereoFlags; 217 218 int nNumRemovedProtons; 219 int num_removed_iso_H; /* number of exchangable isotopic H */ 220 NUM_H num_iso_H[NUM_H_ISOTOPES]; /* number of exchangable isotopic H */ 221 char szRemovedProtons[MAX_LEN_REMOVED_PROTONS]; 222 } INF_ATOM_DATA; 223 224 typedef struct tagInputAtomData { 225 inp_ATOM *at; 226 inp_ATOM *at_fixed_bonds; /* tautomeric case, added or removed H */ 227 int num_at; 228 int num_removed_H; 229 int num_bonds; 230 int num_isotopic; 231 int bExists; 232 int bDeleted; 233 int bHasIsotopicLayer; 234 int bTautomeric; 235 int bTautPreprocessed; 236 int nNumRemovedProtons; 237 NUM_H nNumRemovedProtonsIsotopic[NUM_H_ISOTOPES]; /* isotopic composition of removed protons, not included in num_iso_H[] */ 238 NUM_H num_iso_H[NUM_H_ISOTOPES]; /* isotopic H on tautomeric atoms and those in nIsotopicEndpointAtomNumber */ 239 INCHI_MODE bTautFlags; 240 INCHI_MODE bTautFlagsDone; 241 INCHI_MODE bNormalizationFlags; 242 } INP_ATOM_DATA; 243 typedef INP_ATOM_DATA INP_ATOM_DATA2[TAUT_NUM]; 244 245 typedef struct tagNormCanonFlags { 246 INCHI_MODE bTautFlags[INCHI_NUM][TAUT_NUM]; 247 INCHI_MODE bTautFlagsDone[INCHI_NUM][TAUT_NUM]; 248 INCHI_MODE bNormalizationFlags[INCHI_NUM][TAUT_NUM]; 249 int nCanonFlags[INCHI_NUM][TAUT_NUM]; 250 } NORM_CANON_FLAGS; 251 252 typedef struct tagCompositeAtomData { 253 inp_ATOM *at; 254 int num_at; 255 int num_removed_H; 256 int num_bonds; 257 int num_isotopic; 258 int bExists; 259 int bDeleted; /* unused */ 260 int bHasIsotopicLayer; 261 int bTautomeric; 262 int nNumRemovedProtons; 263 NUM_H nNumRemovedProtonsIsotopic[NUM_H_ISOTOPES]; /* isotopic composition of removed protons, not included in num_iso_H[] */ 264 NUM_H num_iso_H[NUM_H_ISOTOPES]; /* isotopic H on tautomeric atoms and those in nIsotopicEndpointAtomNumber */ 265 266 AT_NUMB *nOffsetAtAndH; 267 int num_components; 268 } COMP_ATOM_DATA; 269 /* 270 typedef COMP_ATOM_DATA COMP_ATOM_DATA3[TAUT_NUM+1]; 271 */ 272 #define ADD_LEN_STRUCT_FPTRS 100 /* allocation increments */ 273 typedef long INCHI_FPTR; 274 typedef struct tagStructFptrs { 275 INCHI_FPTR *fptr; /* input: fptr[cur_fptr] = file pointer to the structure to read */ 276 /* output: fptr[cur_fptr+1] = file pointer to the next structure or EOF */ 277 int len_fptr; /* allocated length of fptr */ 278 int cur_fptr; /* input: k-1 to read the kth struct, k = 1, 2, 3,...; left unchanged; struct number := cur_fptr+1 */ 279 int max_fptr; /* length of the filled out portion of fptr */ 280 } STRUCT_FPTRS; 281 282 #define FLAG_INP_AT_CHIRAL 1 283 #define FLAG_INP_AT_NONCHIRAL 2 284 #define FLAG_SET_INP_AT_CHIRAL 4 285 #define FLAG_SET_INP_AT_NONCHIRAL 8 286 287 /* BILLY 8/6/04 */ 288 #ifndef COMPILE_ALL_CPP 289 #ifdef __cplusplus 290 extern "C" { 291 #endif 292 #endif 293 294 int MolfileToInpAtom( FILE *inp_molfile, int bDoNotAddH, inp_ATOM **at, MOL_COORD **szCoord, int max_num_at, 295 int *num_dimensions, int *num_bonds, const char *pSdfLabel, char *pSdfValue, 296 long *Id, long *lMolfileNumber, INCHI_MODE *pInpAtomFlags, int *err, char *pStrErr ); 297 int MolfileToOrigAtom( FILE *inp_molfile, ORIG_ATOM_DATA *orig_at_data, int bMergeAllInputStructures, 298 int bGetOrigCoord, int bDoNotAddH, 299 const char *pSdfLabel, char *pSdfValue, long *lSdfId, long *lMolfileNumber, 300 INCHI_MODE *pInpAtomFlags, int *err, char *pStrErr ); 301 int INChIToOrigAtom( INCHI_IOSTREAM *inp_molfile, ORIG_ATOM_DATA *orig_at_data, int bMergeAllInputStructures, 302 int bGetOrigCoord, int bDoNotAddH, int vABParityUnknown, INPUT_TYPE nInputType, 303 char *pSdfLabel, char *pSdfValue, long *lSdfId, 304 INCHI_MODE *pInpAtomFlags, int *err, char *pStrErr ); 305 306 int MarkDisconnectedComponents( ORIG_ATOM_DATA *orig_at_data, int bProcessOldCompNumbers ); 307 int DisconnectSalts( ORIG_ATOM_DATA *orig_inp_data, int bDisconnect ); 308 int DisconnectMetals( ORIG_ATOM_DATA *orig_inp_data, int bCheckMetalValence, INCHI_MODE *bTautFlagsDone ); 309 int bMayDisconnectMetals( ORIG_ATOM_DATA *orig_inp_data, int bCheckMetalValence, INCHI_MODE *bTautFlagsDone ); 310 int bHasMetalAtom( ORIG_ATOM_DATA *orig_inp_data ); 311 int FixAdjacentRadicals( int num_inp_atoms, inp_ATOM *at ); /* FIX_ADJ_RAD == 1 */ 312 int fix_odd_things( int num_atoms, inp_ATOM *at, int bFixBug, int bFixNonUniformDraw ); 313 int post_fix_odd_things( int num_atoms, inp_ATOM *at ); 314 int remove_ion_pairs( int num_atoms, inp_ATOM *at ); 315 316 int bFoundFeature( inp_ATOM *at, int num_atoms ); 317 int CopyMOLfile(FILE *inp_file, long fPtrStart, long fPtrEnd, FILE *prb_file, long nNumb); 318 319 void FreeInpAtom( inp_ATOM **at ); 320 void FreeInfAtom( inf_ATOM **at ); 321 void FreeOrigAtData( ORIG_ATOM_DATA *orig_at_data ); 322 void FreeInpAtomData( INP_ATOM_DATA *inp_at_data ); 323 void FreeCompAtomData( COMP_ATOM_DATA *inp_at_data ); 324 void FreeInfoAtomData( INF_ATOM_DATA *inf_at_data ); 325 326 int FixUnkn0DStereoBonds(inp_ATOM *at, int num_at); 327 328 inf_ATOM *CreateInfAtom( int num_atoms ); 329 inp_ATOM *CreateInpAtom( int num_atoms ); 330 331 int CreateInfoAtomData( INF_ATOM_DATA *inf_at_data, int num_atoms, int num_components ); 332 int AllocateInfoAtomData( INF_ATOM_DATA *inf_at_data, int num_atoms, int num_components ); 333 int DuplicateInfoAtomData( INF_ATOM_DATA *inf_at_data_to, const INF_ATOM_DATA *inf_at_data_from); 334 int CreateInpAtomData( INP_ATOM_DATA *inp_at_data, int num_atoms, int create_at_fixed_bonds ); 335 int CreateCompAtomData( COMP_ATOM_DATA *inp_at_data, int num_atoms, int num_components, int bIntermediateTaut ); 336 #ifndef COMPILE_ANSI_ONLY 337 int DisplayInputStructure( char *szOutputString, inp_ATOM *at, INF_ATOM_DATA *inf_at_data, int num_at, DRAW_PARMS *dp ); 338 #endif 339 void PrintFileName( const char *fmt, FILE *output_file, const char *szFname ); 340 void MySleep( unsigned long ms ); 341 342 #ifndef __ICHITIME_H__ 343 struct tagInchiTime; 344 int bInchiTimeIsOver( struct tagInchiTime *TickEnd ); 345 #endif 346 347 int get_endpoint_valence( U_CHAR el_number ); 348 #if ( KETO_ENOL_TAUT == 1 ) 349 int get_endpoint_valence_KET( U_CHAR el_number ); 350 #endif 351 352 #if ( TEST_RENUMB_ATOMS == 1 ) /* { */ 353 int CopyInpAtomData( INP_ATOM_DATA *dest_inp_at_data, INP_ATOM_DATA *src_inp_at_data ); 354 void RenumbInpAtomData( INP_ATOM_DATA *dest_inp_at_data, INP_ATOM_DATA *src_inp_at_data, AT_RANK *new_ord ); 355 void MakeNewOrd( int num_atoms, AT_RANK *new_ord ); 356 #endif 357 358 int ReconcileAllCmlBondParities( inp_ATOM *at, int num_atoms, int bDisconnected ); 359 360 361 /* BILLY 8/6/04 */ 362 #ifndef COMPILE_ALL_CPP 363 #ifdef __cplusplus 364 } 365 #endif 366 #endif 367 368 #endif /* __INPDEF_H__ */ 369