/*
 * International Chemical Identifier (InChI)
 * Version 1
 * Software version 1.04
 * September 9, 2011
 *
 * The InChI library and programs are free software developed under the
 * auspices of the International Union of Pure and Applied Chemistry (IUPAC).
 * Originally developed at NIST. Modifications and additions by IUPAC 
 * and the InChI Trust.
 *
 * IUPAC/InChI-Trust Licence No.1.0 for the 
 * International Chemical Identifier (InChI) Software version 1.04
 * Copyright (C) IUPAC and InChI Trust Limited
 * 
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the IUPAC/InChI Trust InChI Licence No.1.0, 
 * or any later version.
 * 
 * Please note that this library is distributed WITHOUT ANY WARRANTIES 
 * whatsoever, whether expressed or implied.  See the IUPAC/InChI Trust 
 * Licence for the International Chemical Identifier (InChI) Software 
 * version 1.04, October 2011 ("IUPAC/InChI-Trust InChI Licence No.1.0") 
 * for more details.
 * 
 * You should have received a copy of the IUPAC/InChI Trust InChI 
 * Licence No. 1.0 with this library; if not, please write to:
 * 
 * The InChI Trust
 * c/o FIZ CHEMIE Berlin
 *
 * Franklinstrasse 11
 * 10587 Berlin
 * GERMANY
 *
 * or email to: ulrich@inchi-trust.org.
 * 
 */


#ifndef __UTIL_H__
#define __UTIL_H__

#include "inpdef.h"

/* BILLY 8/6/04 */
#ifndef COMPILE_ALL_CPP
#ifdef __cplusplus
extern "C" {
#endif
#endif

int get_atw(const char *elname);
int get_atw_from_elnum( int nAtNum );
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 );
int extract_ChargeRadical( char *elname, int *pnRadical, int *pnCharge );
int extract_H_atoms( char *elname, S_CHAR num_iso_H[] );
int normalize_name( char* name );

int mystrncpy(char *target,const char *source,unsigned maxlen);
char* LtrimRtrim( char *p, int* nLen );

void remove_trailing_spaces( char* p );
void remove_one_lf( char* p);
void mystrrev( char *p );






#define ALPHA_BASE  27
long inchi_strtol( const char *str, const char **p, int base);
double inchi_strtod( const char *str, const char **p );

AT_NUMB *is_in_the_list( AT_NUMB *pathAtom, AT_NUMB nNextAtom, int nPathLen );
int get_periodic_table_number( const char* elname );
int is_el_a_metal( int nPeriodicNum );
int get_el_valence( int nPeriodicNum, int charge, int val_num );
int get_unusual_el_valence( int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds );
int detect_unusual_el_valence( int nPeriodicNum, int charge, int radical, int bonds_valence, int num_H, int num_bonds );
int needed_unusual_el_valence( int nPeriodicNum, int charge, int radical, int bonds_valence,
                               int actual_bonds_val, int num_H, int num_bonds );
int get_el_type( int nPeriodicNum );
int get_el_number( const char* elname );
int do_not_add_H( int nPeriodicNum );
int GetElementFormulaFromAtNum(int nAtNum, char *szElement );
int MakeRemovedProtonsString( int nNumRemovedProtons, NUM_H *nNumExchgIsotopicH, NUM_H *nNumRemovedProtonsIsotopic,
                              int bIsotopic, char *szRemovedProtons, int *num_removed_iso_H );

/* ion pairs and fixing bonds */
int num_of_H( inp_ATOM *at, int iat );
int has_other_ion_neigh( inp_ATOM *at, int iat, int iat_ion_neigh, const char *el, int el_len );
int has_other_ion_in_sphere_2(inp_ATOM *at, int iat, int iat_ion_neigh, const char *el, int el_len );
int nNoMetalNumBonds( inp_ATOM *at, int at_no );
int nNoMetalBondsValence( inp_ATOM *at, int at_no );
int nNoMetalNeighIndex( inp_ATOM *at, int at_no );
int nNoMetalOtherNeighIndex( inp_ATOM *at, int at_no, int cur_neigh );
int nNoMetalOtherNeighIndex2( inp_ATOM *at, int at_no, int cur_neigh, int cur_neigh2 );

void extract_inchi_substring(char ** buf, const char *str, size_t slen);

/* mol2atom.c */
int nBondsValToMetal( inp_ATOM* at, int iat );

/* ichi_bns.c */
int nBondsValenceInpAt( const inp_ATOM *at, int *nNumAltBonds, int *nNumWrongBonds );

int bHeteroAtomMayHaveXchgIsoH( inp_ATOM *atom, int iat );

/* IChICan2.c */
int SetBitFree( void );

void WriteCoord( char *str, double x );


extern int ERR_ELEM;
extern int nElDataLen;

/* BILLY 8/6/04 */
#ifndef COMPILE_ALL_CPP
#ifdef __cplusplus
}
#endif
#endif

#endif /* __UTIL_H__*/

