#include "pdb.h" typedef struct char8 { char name[8] ; } char8 ; double atom_vdw[ MAX_ATOM_TYPE ] ; double atom_covalent[ MAX_ATOM_TYPE ] ; double atom_charge[ MAX_ATOM_TYPE ] ; char8 atom_type_names[ MAX_ATOM_TYPE ] = {0}; /* MBG: 26 April 1996. These routines had a rather annoying bug. Basically, the problem is when find_atom_definitions() returns 0, it can be interpreted two ways: either there is a serious error or we've found atom type 0. This obviously leads to problems. To get around this, I have changed the indexing in the atom_* arrays to start at 1 instead of 0 (as marked below). */ char * atom_type_name(int index) { return atom_type_names[index].name ; } int find_type_definition (char *name) { int ii ; /* ii used to start at 0 ! */ for (ii =1 ; ii < MAX_ATOM_TYPE ; ii++) { char *k = atom_type_names[ii].name ; if (k == NULL ) break ; if(!strncmp(name, k,8) ) return ii ; } serious_error(1, "Unknown atom type", name) ; return 0 ; } int allocate_atom_type(char *name) { int ii ; /* ii used to start at 0 ! */ for (ii =1 ; ii < MAX_ATOM_TYPE ; ii++) { char *k = atom_type_names[ii].name ; if (k[0] == '\0') { strncpy(k,name,8); return ii ; } if ( !strncmp(name, k ,8) ) return ii ; } serious_error(1, "Too many atom types","") ; return 0 ; } void read_atom_types (FILE *ff) { char string[200] ; while (fgets(string,200,ff) != NULL) { char name [200] ; double charge,vdw,covalent; int ii ; ii = sscanf(string, LF_STRING_02, name,&vdw,&covalent,&charge) ; if (ii > 0) { if (ii < 3) serious_error(1, "Something wrong in atom type", string) ; ii = allocate_atom_type(name) ; atom_charge[ii] = charge; atom_covalent[ii] = covalent; atom_vdw[ii] = vdw; } } }