/*********************************************************************/ /*Program: amber7toqcd */ /*Author: Ting Wang */ /*Email: ting.wang@eml.villa-bosch.de */ /*Institution: European Media Laboratory */ /*Date: May, 2002 */ /*Purpose: convert AMBER7 Top and Crd files into CHARMM qcd file for use in UHBD */ /*COMPILATION: cc -o amber7toqcd amber7toqcd.c -lm */ /*USAGE: >amber7toqcd xleap.top xleap.crd xleap.qcd */ #include #include #include #define MAX_NSPM 1000 /* Max total number of molecules*/ #define MAX_ATOM 11000 /* Max number of atoms */ #define MAX_RES 700 /* Max number of Residues */ #define MAX_BONDTYPE 500 /* Max number of bonds */ #define MAX_NBONH 6530 /* Max number of bonds containing H */ #define MAX_NBONA 6530 /* Max number of bonds not containing H */ #define MAX_ANGLETYPE 900 /* Max number of angles */ #define MAX_NTHETH 11500 /* Max number of angles containing H */ #define MAX_NTHETA 7500 /* Max number of angles not containing H */ #define MAX_DIHTYPE 900 /* Max number of dihedrals */ #define MAX_NPHIH 21500 /* Max number of dihedrals containing H */ #define MAX_NPHIA 12500 /* Max number of dihedrals not containing H */ #define MAX_NEXT 65500 /* Max number of excluded atoms */ #define MAX_NTYPES 50 /* Max number of atom potential types, FF95 has 41 types */ #define MAX_NTTYP MAX_NTYPES*(MAX_NTYPES+1)/2 /* Max number of atom potential types, FF95 has 41 types */ #define MAX_NPHB 200 /* Max number of 10-12 hbond pair types */ int main ( int argc, /* Number of args */ char ** argv) /* Arg list */ { FILE *ftop,*fcrd,*fqcd; int NATOM, NTYPES, NBONH, MBONA, NTHETH, MTHETA, NPHIH, MPHIA, NHPARM, NPARM, NEXT, NRES, NBONA, NTHETA, NPHIA, NUMBND, NUMANG, NPTRA, NATYP, NPHB, IFPERT, NBPER, NGPER, NDPER, MBPER, MGPER, MDPER, IFBOX, NMXRS, IFCAP; int IPTRES, IPTATM, NSPSOL, NSPSTR; char IGRAPH[MAX_ATOM][6], LABRES[MAX_RES][6]; char ISYMBL[MAX_ATOM][6]/* ATOM TYPE */, ITREE[MAX_ATOM][6]/* TREE TYPE*/; int IAC[MAX_ATOM], NUMEX[MAX_ATOM], ICO[MAX_NTYPES*MAX_NTYPES],IPRES[MAX_RES]; int IBH[MAX_NBONH],JBH[MAX_NBONH],ICBH[MAX_NBONH],IB[MAX_NBONA],JB[MAX_NBONA],ICB[MAX_NBONA]; int ITH[MAX_NTHETH],JTH[MAX_NTHETH],KTH[MAX_NTHETH],ICTH[MAX_NTHETH]; int IT[MAX_NTHETA],JT[MAX_NTHETA],KT[MAX_NTHETA],ICT[MAX_NTHETA]; int IPH[MAX_NPHIH],JPH[MAX_NPHIH],KPH[MAX_NPHIH],LPH[MAX_NPHIH],ICPH[MAX_NPHIH]; int IP[MAX_NPHIA],JP[MAX_NPHIA],KP[MAX_NPHIA],LP[MAX_NPHIA],ICP[MAX_NPHIA],NATEX[MAX_NEXT]; /*int IH[MAX_NPHIA],JH[MAX_NPHIA],KH[MAX_NPHIA], LH[MAX_NPHIA], ICH[MAX_NPHIA];*/ int JOIN[MAX_ATOM], IROTAT[MAX_ATOM], NSPM, NSP[MAX_NSPM]; float CHRG[MAX_ATOM], AMASS[MAX_ATOM]; float RK[MAX_BONDTYPE],REQ[MAX_BONDTYPE],TK[MAX_ANGLETYPE],TEQ[MAX_ANGLETYPE],PK[MAX_DIHTYPE],PN[MAX_DIHTYPE],PHASE[MAX_DIHTYPE]; float SOLTY[MAX_NTYPES],CN1[MAX_NTTYP], CN2[MAX_NTTYP]; float ASOL[MAX_NPHB],BSOL[MAX_NPHB],HBCUT[MAX_NPHB]/*NO Longer in use*/; float BETA, BOXT[3],RAD[MAX_NTYPES]; float XYZ[3][MAX_ATOM]; int i,j,k,res_i,NUM_ATOM,NTTYP,index; int snapshot,res_bn,res_bs,contact,m,mask,list[MAX_ATOM][2]; float distance; char coords[50]; char temp[120]; int skip; if((ftop = fopen(argv[1] , "r"))==NULL) {printf("Top file can not be opened .\n");exit(0);} if((fcrd = fopen(argv[2] , "r"))==NULL) {printf("Crd file can not be opened .\n");exit(0);} if((fqcd = fopen(argv[3], "w"))==NULL) {printf("OUT File can not be written .\n");exit(0);} /* Initialize Variables */ IPTRES = 0; /* Final residue that is considered part of the solute */ IPTATM = 0; NSPSOL = 0; /* the first solvent "molecule" */ NSPSTR = 0; /* for (skip=1;skip<=6;skip++) fscanf(ftop,"\n"); */ /* Skip the first 6 line */ for (skip=1;skip<=6;skip++) fgets(temp,100,ftop); /* Skip the first 6 line */ /* read the numbers */ fscanf(ftop,"%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ); /* printf("NATOM=%d, NTYPES=%d, IFCAP=%d",NATOM, NTYPES, IFCAP); */ if (NUMBND > MAX_BONDTYPE||NUMANG > MAX_ANGLETYPE||NPTRA > MAX_DIHTYPE ||NPHB > MAX_NPHB||NATYP > MAX_NTYPES ||NBONH > MAX_NBONH||NBONA > MAX_NBONA||NTHETH > MAX_NTHETH ||NTHETA > MAX_NTHETA||NPHIH > MAX_NPHIH||NPHIA > MAX_NPHIA ||NEXT > MAX_NEXT||NATOM > MAX_ATOM ||NRES > MAX_RES) { printf(" Exceed memory limits:\n"); printf("NUMBND (MAX %d) = %d", MAX_BONDTYPE,NUMBND); printf("NUMANG (MAX %d) = %d", MAX_ANGLETYPE,NUMANG); printf("NPTRA (MAX %d) = %d", MAX_DIHTYPE,NPTRA); printf("NPHB (MAX %d) = %d", MAX_NPHB,NPHB); printf("NATYP (MAX %d) = %d", MAX_NTYPES,NATYP); printf("NBONH (MAX %d) = %d", MAX_NBONH,NBONH); printf("NBONA (MAX %d) = %d", MAX_NBONA,NBONA); printf("NTHETH (MAX %d) = %d", MAX_NTHETH,NTHETH); printf("NTHETA (MAX %d) = %d", MAX_NTHETA,NTHETA); printf("NPHIH (MAX %d) = %d", MAX_NPHIH,NPHIH); printf("NPHIA (MAX %d) = %d", MAX_NPHIA,NPHIA); printf("NEXT (MAX %d) = %d", MAX_NEXT,NEXT); printf("NATOM (MAX %d) = %d", MAX_ATOM,NATOM); printf("NRES (MAX %d) = %d", MAX_RES,NRES); } /*------------ read charges, masses, atom types, etc...*/ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NATOM; i++) fscanf(ftop,"%4s", IGRAPH[i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NATOM; i++) fscanf(ftop,"%f", [i]); /*NOTE: here %16.8f will lead mistake */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NATOM; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NATOM; i++) fscanf(ftop,"%d", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NATOM; i++) fscanf(ftop,"%d", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NTYPES*NTYPES; i++) fscanf(ftop,"%d", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NRES; i++) fscanf(ftop,"%4s", LABRES[i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NRES; i++) fscanf(ftop,"%d", [i]); /*----------------- READ THE PARAMETERS ----------------*/ NTTYP = NTYPES*(NTYPES+1)/2; fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NUMBND; i++) fscanf(ftop,"%f",[i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NUMBND; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NUMANG; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NUMANG; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NPTRA; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NPTRA; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NPTRA; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NATYP; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NTTYP; i++) fscanf(ftop,"%f", [i]); fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ fgets(temp,100,ftop); /* Skip the first 3 line */ for (i=1; i<=NTTYP; i++) fscanf(ftop,"%f", [i]); for (k=1; k<=NTYPES; k++) { RAD[k]=0.0; index = ICO[NTYPES*(k-1)+k]; if (index > 0) { if (CN2[index]!=0.0) { RAD[k] = (2.0*CN1[index])/CN2[index]; RAD[k] = pow(RAD[k],1.0/6.0)/2.0; }/* end CN2 */ }/* end index >0 */ }/* end for k<=NTYPES */ for (i=1; i<=NATOM; i++) { CHRG[i] = CHRG[i]/18.2223; AMASS[i] = 1.0/AMASS[i]; } /*--------------- READ XYZ coordinates--------------------------*/ fscanf(fcrd,"\n");/*Skip the first line */ fscanf(fcrd,"%d\n",_ATOM); if (NUM_ATOM!=NATOM) {printf(" readcrd: atom numbers do not match\n");exit(0);} for (i=1; i<=NATOM; i++) fscanf(fcrd,"%f%f%f",[0][i],[1][i],[2][i]); /*---------write the pdb file with CHARMM qcd format, for the use in UHBD---*/ res_i = 1; for (i=1; i<=NATOM; i++) { if (res_i==NRES) fprintf(fqcd,"ATOM%6d %3s %-4s %8.3f%8.3f%8.3f%8.3f%8.3f\n", res_i, LABRES[res_i], IGRAPH[i],XYZ[0][i],XYZ[1][i],XYZ[2][i], CHRG[i],RAD[IAC[i]]); else if (res_i < NRES) { if (i==IPRES[res_i+1]) res_i++; fprintf(fqcd,"ATOM%6d %3s %-4s %8.3f%8.3f%8.3f%8.3f%8.3f\n", res_i, LABRES[res_i], IGRAPH[i],XYZ[0][i],XYZ[1][i],XYZ[2][i], CHRG[i],RAD[IAC[i]]); } /* end of if res_i< NRES */ } /* end of for i<=NATOM */ fclose(ftop); fclose(fcrd); fclose(fqcd); return(1); }