GLYLIB
0.3.0b
|
00001 // File load_atypes.c begun on 20071128 by BLFoley 00002 // Purpose: load database of atom types into atype 00003 // substructure within a types superstructure 00004 // NOTE! T needs to be initialized -before- calling 00005 // this function! 00006 #include <mylib.h> 00007 #include <general.h> 00008 #include <molecules.h> 00009 #include <declarations.h> 00010 //#include "../inc/mylib.h" 00011 //#include "../inc/general.h" 00012 //#include "../inc/molecules.h" 00013 //#include "../inc/declarations.h" 00014 00015 void load_atypes(fileset F, types *T){ 00016 char line[10001],*entry; 00017 int test=0,la=0,numbnd=0; 00018 F.F=myfopen(F.N,"r"); // 00019 while(fgets(line,10000,F.F)!=NULL){// while not end of file 00020 if(line[0]!='#'){//check that the line does not start with a hash 00021 if(strchr(line,EOF)!=NULL){read_eek("EOF",F.N);} 00022 T[0].na++;// increment and allocate 00023 T[0].a=(atype*)realloc(T[0].a,T[0].na*sizeof(atype)); 00024 // read data into structure by splitting on the : token 00025 //strcpy(entry,strtok(line,":")); // get atomic number 00026 test=sscanf(strtok(line,":"),"%d",&T[0].a[T[0].na-1].n); 00027 if(test!=1){mywhine("load_atypes: error reading atomic number");} 00028 T[0].a[T[0].na-1].N=strdup(strtok(NULL,":")); // get atom name 00029 T[0].a[T[0].na-1].NT=strdup(strtok(NULL,":")); // get element name 00030 //strcpy(entry,strtok(NULL,":")); // get mass 00031 test=sscanf(strtok(NULL,":"),"%lf",&T[0].a[T[0].na-1].m); 00032 if(test!=1){mywhine("load_atypes: error reading atomic mass");} 00033 T[0].a[T[0].na-1].desc=strdup(strtok(NULL,":")); // get description 00034 entry=strdup(strtok(NULL,":")); // get bonding info 00035 test=sscanf(strtok(NULL,":"),"%d",&T[0].a[T[0].na-1].nlp);// get number lone pairs 00036 if(test!=1){mywhine("load_atypes: error reading number of lone pairs");} 00037 // split bonding info 00038 if(strchr(entry,'(')==NULL){mywhine("load_atypes: bonding field does not contain bond orders");} 00039 test=sscanf(strtok(entry,"("),"%d",&T[0].a[T[0].na-1].nb);// get number typical bonds 00040 if(test!=1){mywhine("load_atypes: error reading number of typical bonds");} 00041 numbnd=T[0].a[T[0].na-1].nb; 00042 if(numbnd==0){ 00043 numbnd=1; 00044 T[0].a[T[0].na-1].bo=(double*)calloc(1,sizeof(double)); 00045 test=sscanf(strtok(NULL,",)"),"%lf",&T[0].a[T[0].na-1].bo[0]);// get bond order 00046 if(test!=1){mywhine("load_atypes: error reading bond order");} 00047 if(T[0].a[T[0].na-1].bo[0]!=0) T[0].a[T[0].na-1].nb=-1; 00048 } 00049 else{ 00050 T[0].a[T[0].na-1].bo=(double*)calloc(numbnd,sizeof(double)); 00051 for(la=0;la<numbnd;la++){ 00052 test=sscanf(strtok(NULL,",)"),"%lf",&T[0].a[T[0].na-1].bo[la]);// get bond order 00053 if(test!=1){mywhine("load_atypes: error reading bond order");} 00054 } 00055 } 00056 } // close if line is not a comment 00057 }// close while not EOF 00058 // return; 00059 return; 00060 }