GLYLIB  0.3.0b
amber_prmtop_init.c
Go to the documentation of this file.
00001 /* File amber_prmtop_init.c begun on or around 20080424 by BLFoley
00002         Purpose: initialize structure info for amber prmtop file read */
00003 //#include "mylib.h"
00004 #include "AMBER/amber_prmtop.h"
00005 //#include "amber_prmtop_structs.h"
00006 
00007 void amber_prmtop_init(amber_prmtop *P){
00008 int a=0,b=0,c=0;
00009 char *s,*sp,**p1,**p2,*FLG,*FOR; // strings
00010 
00011 // Set some initial values, just 'cause
00012 P[0].NATOM  =0; // total number of atoms 
00013 P[0].NTYPES =0; // total number of distinct atom types
00014 P[0].NBONH  =0; // number of bonds containing hydrogen
00015 P[0].MBONA  =0; // number of bonds not containing hydrogen
00016 P[0].NTHETH =0; // number of angles containing hydrogen
00017 P[0].MTHETA =0; // number of angles not containing hydrogen
00018 P[0].NPHIH  =0; // number of dihedrals containing hydrogen
00019 P[0].MPHIA  =0; // number of dihedrals not containing hydrogen
00020 P[0].NHPARM =0; // currently not used
00021 P[0].NPARM  =0; // currently not used
00022 P[0].NEXT   =0; // number of excluded atoms
00023 P[0].NRES   =0; // number of residues
00024 P[0].NBONA  =0; // MBONA + number of constraint bonds
00025 P[0].NTHETA =0; // MTHETA + number of constraint angles
00026 P[0].NPHIA  =0; // MPHIA + number of constraint dihedrals
00027 P[0].NUMBND =0; // number of unique bond types
00028 P[0].NUMANG =0; // number of unique angle types
00029 P[0].NPTRA  =0; // number of unique dihedral types
00030 P[0].NATYP  =0; // number of atom types in parameter file, see SOLTY below
00031 P[0].NPHB   =0; // number of distinct 10-12 hydrogen bond pair types
00032 P[0].IFPERT =0; // set to 1 if perturbation info is to be read in
00033 P[0].NBPER  =0; // number of bonds to be perturbed
00034 P[0].NGPER  =0; // number of angles to be perturbed
00035 P[0].NDPER  =0; // number of dihedrals to be perturbed
00036 P[0].MBPER  =0; // number of bonds with atoms completely in perturbed group
00037 P[0].MGPER  =0; // number of angles with atoms completely in perturbed group
00038 P[0].MDPER  =0; // number of dihedrals with atoms completely in perturbed groups
00039 P[0].IFBOX  =0; // set to 1 if standard periodic box, 2 when truncated octahedral
00040 P[0].NMXRS  =0; // number of atoms in the largest residue
00041 P[0].IFCAP  =0; // set to 1 if the CAP option from edit was specified
00042 //
00043 P[0].nS=0;
00044 P[0].nSS=0;
00045 P[0].nES=0;
00046 P[0].nFF=0;
00047 
00048 // Set integer values for strings in AMBER_PRMTOP_FLAGS 
00049 // Set number of chars per entry from AMBER_PRMTOP_FORMATS
00050 // To do this...
00051 //      see how much memory we need -- 
00052 //      loop through AMBER_PRMTOP_FLAGS and count fields between spaces
00053 a=0;
00054 b=1; // will need one more field than # of spaces
00055 while(AMBER_PRMTOP_FLAGS[a]!='\0'){
00056         if(AMBER_PRMTOP_FLAGS[a]==' ') b++;
00057         a++;}
00058 // check the FORMATS definition, just 'cause
00059 a=0;
00060 c=1; // will need one more field than # of spaces 
00061 while(AMBER_PRMTOP_FORMATS[a]!='\0'){
00062         if(AMBER_PRMTOP_FORMATS[a]==' ') c++;
00063         a++;}
00064 if(b!=c){
00065         printf("b is %d ; c is %d \n",b,c);
00066         printf("Mismatch in AMBER FLAGS and FORMATS as defined in amber_prmtop_structs.h. Exiting.\n"); 
00067         exit(1);}
00068 //      allocate memory in the amber_prmtop structure
00069 P[0].FLAGS=(char**)calloc(b,sizeof(char*));
00070 P[0].FORMATS=(int*)calloc(b,sizeof(int));
00071 // Use strtok to split the flag strings and get ascii integer variants
00072 // save each flag as the integer value of the string
00073 FLG=strdup(AMBER_PRMTOP_FLAGS);
00074 P[0].FLAGS[0]=strdup(strtok(FLG," "));
00075 for(a=1;a<b;a++){P[0].FLAGS[a]=strdup(strtok(NULL," "));}
00076 // now parse the format strings
00077 // save each format as the number of characters allocated for each datum
00078 FOR=strdup(AMBER_PRMTOP_FORMATS);
00079 p1=&FOR;
00080 s=strdup(strtok_r(FOR," ",p1)); // get a format string
00081 p2=&s;
00082 sp=strdup(strtok_r(s,"aAiIfFeE",p2)); // find the format identifier
00083 sp=strdup(strtok_r(NULL,".",p2)); // information after, but before any periods
00084 if((strchr(sp,'S')!=NULL)||(strchr(sp,'N')!=NULL)){sp[0]='0';} // EN or ES
00085 sscanf(sp,"%d",&P[0].FORMATS[0]);
00086 for(a=1;a<b;a++){
00087         s=strdup(strtok_r(NULL," ",p1)); // get a format string
00088         sp=strdup(strtok_r(s,"aAiIfFeE",p2)); // find the format identifier
00089         sp=strdup(strtok_r(NULL,".",p2)); // after, but before any periods
00090         if((strchr(sp,'S')!=NULL)||(strchr(sp,'N')!=NULL)){sp[0]='0';} // EN or ES
00091         sscanf(sp,"%d",&P[0].FORMATS[a]); 
00092         }
00093 return;
00094 }
 All Classes Files Functions Variables Typedefs Defines