/* CHARMM */ void wcharmm(char *filename, char *ifilename, int atomnum, ATOM * atom, int bondnum, BOND * bond, CONTROLINFO cinfo, MOLINFO minfo) { char tmpchar[MAXCHAR]; size_t copied_size; wac("ANTECHAMBER_PREP.AC0", atomnum, atom, bondnum, bond, cinfo, minfo); system("cp -rf ANTECHAMBER_PREP.AC0 ANTECHAMBER_PREP.AC"); /*part1: if intype is not prepi, prepc and ac, judge atom type*/ if ((strcmp(cinfo.intype, "prepi") != 0 && strcmp(cinfo.intype, "prepc") != 0 && strcmp(cinfo.intype, "5") != 0 && strcmp(cinfo.intype, "6") != 0 && strcmp(cinfo.intype, "ac") != 0 && strcmp(cinfo.intype, "1") != 0) || cinfo.prediction_index == 1 || cinfo.prediction_index == 3) { copied_size = build_exe_path(tmpchar, "atomtype", sizeof tmpchar, 1); strncat(tmpchar, " -i ANTECHAMBER_PREP.AC0 -o ANTECHAMBER_PREP.AC" " -p ", sizeof tmpchar - copied_size); strncat(tmpchar, minfo.atom_type_def, sizeof tmpchar - strlen(tmpchar) ); if(cinfo.intstatus == 2) fprintf(stdout, "\nRunning: %s\n", tmpchar); system(tmpchar); } copied_size = build_exe_path(tmpchar, "charmmgen", sizeof tmpchar, 1); strncat(tmpchar, " -i ANTECHAMBER_PREP.AC -f ac -o ", sizeof tmpchar - copied_size); strncat(tmpchar, filename, sizeof tmpchar - strlen(tmpchar) ); strcat(tmpchar, " -r "); strcat(tmpchar, minfo.resname); if(cinfo.intstatus == 2) fprintf(stdout, "\nRunning: %s\n", tmpchar); system(tmpchar); /* system("rm -f ANTECHAMBER_PREP.AC");*/ }
int main(int argc, char *argv[]) { int i; int status = 0; char command[MAXCHAR]; size_t copied_size; amberhome = (char *) getenv("AMBERHOME"); if( amberhome == NULL ){ fprintf( stdout, "AMBERHOME is not set!\n" ); exit(1); } if (strcmp(COLORTEXT, "YES") == 0 || strcmp(COLORTEXT, "yes") == 0) { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("[31mUsage: respgen -i[0m input file name(ac)\n" "[31m -o[0m output file name\n" "[31m -l[0m maximum path length (default is -1, only recommand to use\n" " when the program takes long time to finish or causes core dump.)\n" " If applied, a value of 8 to 10 should good)\n" "[31m -f[0m output file format (resp1 or resp2) \n" "[32m resp0[0m - evaluation the current charges \n" "[32m resp1[0m - first stage resp fitting \n" "[32m resp2[0m - second stage resp fitting\n" "[32m iresp0[0m - evaluation the current charges for polarizable model\n" "[32m iresp1[0m- first stage of i_resp fitting \n" "[32m iresp2[0m- second stage of i_resp fitting\n" "[32m resp3[0m - one-stage resp fitting\n" "[32m resp4[0m - calculating ESP from point charges\n" "[32m resp5[0m - no-equalization\n" "[31m -e[0m equalizing atomic charge, default is 1\n" "[32m 0[0m not use \n" "[32m 1[0m by atomic paths\n" "[32m 2[0m by atomic paths and structural information, i.e. E/Z confirgurations\n" "[31m -a[0m additional input data (predefined charges, atom groups etc).)\n" "[31m -n[0m number of conformations (default is 1)\n" "[31m -w[0m weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } if (argc != 7 && argc != 9 && argc != 11 && argc != 13 && argc != 15 && argc != 17) { printf("[31mUsage: respgen -i[0m input file name(ac)\n" "[31m -o[0m output file name\n" "[31m -l[0m maximum path length (default is -1, only recommand to use\n" " when the program takes long time to finish or causes core dump.)\n" " If applied, a value of 8 to 10 should good)\n" "[31m -f[0m output file format (resp1 or resp2) \n" "[32m resp0[0m - evaluation the current charges \n" "[32m resp1[0m - first stage resp fitting \n" "[32m resp2[0m - second stage resp fitting\n" "[32m iresp0[0m - evaluation the current charges for polarizable model\n" "[32m iresp1[0m- first stage of i_resp fitting \n" "[32m iresp2[0m- second stage of i_resp fitting\n" "[32m resp3[0m - one-stage resp fitting\n" "[32m resp4[0m - calculating ESP from point charges\n" "[32m resp5[0m - no-equalization\n" "[31m -e[0m equalizing atomic charge, default is 1\n" "[32m 0[0m not use \n" "[32m 1[0m by atomic paths\n" "[32m 2[0m by atomic paths and structural information, i.e. E/Z confirgurations\n" "[31m -a[0m additional input data (predefined charges, atom groups etc).)\n" "[31m -n[0m number of conformations (default is 1)\n" "[31m -w[0m weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } } else { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf("Usage respgen -i input file name(ac)\n"); printf(" -o output file name\n"); printf(" -l maximum path length (default is -1, only recommand to use\n"); printf(" when the program takes long time to finish or causes core dump.)\n"); printf(" If applied, a value of 8 to 10 should good)\n"); printf(" -f output file format (resp1 or resp2)\n"); printf(" resp0 - evaluation the current charges \n"); printf(" resp1 - first stage resp fitting\n"); printf(" resp2 - second stage resp fitting \n"); printf(" iresp0 - evaluation the current charges for polarizable model \n"); printf(" iresp1- first stage of i_resp fitting\n"); printf(" iresp2- second stage of i_resp fitting \n"); printf(" resp3 - one-stage resp fitting\n"); printf(" resp4 - calculating ESP from point charges \n"); printf(" resp5 - no-equalization \n"); printf(" -e equalizing atomic charge, default is 1\n"); printf(" 0 not use \n"); printf(" 1 by atomic paths\n"); printf(" 2 by atomic paths and structural information, i.e. E/Z confirgurations\n"); printf(" -a additional input data (predefined charges, atom groups etc).)\n"); printf(" -n number of conformations (default is 1)\n"); printf(" -w weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } if (argc != 7 && argc != 9 && argc != 11 && argc != 13 && argc != 15 && argc != 17) { printf("Usage respgen -i input file name(ac)\n"); printf(" -o output file name\n"); printf(" -l maximum path length (default is -1, only recommand to use\n"); printf(" when the program takes long time to finish or causes core dump.)\n"); printf(" If applied, a value of 8 to 10 should good)\n"); printf(" -f output file format (resp1 or resp2)\n"); printf(" resp0 - evaluation the current charges \n"); printf(" resp1 - first stage resp fitting\n"); printf(" resp2 - second stage resp fitting \n"); printf(" iresp0 - evaluation the current charges for polarizable model \n"); printf(" iresp1- first stage of i_resp fitting\n"); printf(" iresp2- second stage of i_resp fitting \n"); printf(" resp3 - one-stage resp fitting\n"); printf(" resp4 - calculating ESP from point charges \n"); printf(" resp5 - no-equalization \n"); printf(" -e equalizing atomic charge, default is 1\n"); printf(" 0 not use \n"); printf(" 1 by atomic paths\n"); printf(" 2 by atomic paths and structural information, i.e. E/Z confirgurations\n"); printf(" -a additional input data (predefined charges, atom groups etc).)\n"); printf(" -w weight of charge constraint, in default, 0.0005 for resp1 and 0.001 fore resp2\n"); exit(1); } } method = -1; max_path_length = -1; for (i = 1; i < argc; i += 2) { if (strcmp(argv[i], "-i") == 0) strcpy(ifilename, argv[i + 1]); if (strcmp(argv[i], "-o") == 0) strcpy(ofilename, argv[i + 1]); if (strcmp(argv[i], "-a") == 0) { strcpy(afilename, argv[i + 1]); iaddinfo = 1; } if (strcmp(argv[i], "-n") == 0) nconf = atoi(argv[i+1]); if (strcmp(argv[i], "-l") == 0) max_path_length = atoi(argv[i+1]); if (strcmp(argv[i], "-f") == 0) { if (strcmp("resp", argv[i + 1]) == 0) method = -1; if (strcmp("resp0", argv[i + 1]) == 0) method = 0; if (strcmp("resp1", argv[i + 1]) == 0) { method = 1; weight = 0.0005; } if (strcmp("resp2", argv[i + 1]) == 0) { method = 2; weight = 0.001; } if (strcmp("resp3", argv[i + 1]) == 0) method = 3; if (strcmp("iresp1", argv[i + 1]) == 0) { method = 4; weight = 0.0005; } if (strcmp("iresp2", argv[i + 1]) == 0) { method = 5; weight = 0.001; } if (strcmp("resp4", argv[i + 1]) == 0) { method = 6; weight = 0.000; } if (strcmp("iresp0", argv[i + 1]) == 0) method = 7; if (strcmp("resp5", argv[i + 1]) == 0) { method = 8; weight = 0.0005; } } if (strcmp(argv[i], "-w") == 0) weight = atof(argv[i+1]); if (strcmp(argv[i], "-e") == 0) iequ = atoi(argv[i+1]); } if(nconf < 1) { printf("\nNumber of conformations must be equal to or larger than 1"); exit(1); } if(iequ != 0 && iequ != 1 && iequ !=2) iequ = 1; default_cinfo(&cinfo); default_minfo(&minfo); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stdout, "memory allocation error for *atom\n"); exit(1); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stdout, "memory allocation error for *bond\n"); exit(1); } for (i = 0; i < cinfo.maxbond; ++i) { bond[i].jflag = -1; /* bond type has not been assigned */ } overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; free(atom); free(bond); atom = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom == NULL) { fprintf(stdout, "memory allocation error for *atom\n"); exit(1); } bond = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond == NULL) { fprintf(stdout, "memory allocation error for *bond\n"); exit(1); } int i; for (i = 0; i < cinfo.maxbond; ++i) { bond[i].jflag = -1; /* bond type has not been assigned */ } overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); } atomicnum(atomnum, atom); adjustatomname(atomnum, atom, 1); if(minfo.dcharge >= -9990) charge = minfo.dcharge; equ_atom_id = (int *) malloc(sizeof(int) * atomnum); if (equ_atom_id == NULL) { fprintf(stdout, "memory allocation error for *equ_atom_id\n"); exit(1); } for (i = 0; i < atomnum; i++) equ_atom_id[i] = -1; if(method == 3) { atqwt = (double *) malloc(sizeof(double) * atomnum); if (atqwt == NULL) { fprintf(stdout, "memory allocation error for *atqwt\n"); exit(1); } refcharge = (double *) malloc(sizeof(double) * atomnum); if (refcharge == NULL) { fprintf(stdout, "memory allocation error for *refcharge\n"); exit(1); } for(i=0;i<atomnum;i++) { atqwt[i] = 0; refcharge[i] = 0; } // now read in atomic weights and reference charge parameters pfilename[0] = '\0'; strcpy(pfilename, amberhome); strcat(pfilename, "/dat/antechamber/RESPPARM.DAT"); readparm(pfilename); wac("ANTECHAMBER_RESP.AC", atomnum, atom, bondnum, bond, cinfo, minfo); copied_size = build_exe_path(command, "atomtype -i ANTECHAMBER_RESP.AC -o ANTECHAMBER_RESP_AT.AC -d ", sizeof command, 1 ); dfilename[0] = '\0'; strcpy(dfilename, amberhome); strcat(dfilename, "/dat/antechamber/ATOMTYPE_RESP.DEF"); strncat(command, dfilename, MAXCHAR - copied_size ); if (cinfo.intstatus == 2) fprintf(stdout, "Running: %s\n", command); status = system(command); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" in respgen.c properly, exit\n", command); exit(1); } assignparm("ANTECHAMBER_RESP_AT.AC"); } if(iequ == 1) identify_equatom(atomnum, atom, equ_atom_id, max_path_length, bondnum, bond, 0); if(iequ == 2) identify_equatom(atomnum, atom, equ_atom_id, max_path_length, bondnum, bond, 1); icharge = (int *) malloc(sizeof(int) * atomnum); if (icharge == NULL) { fprintf(stdout, "memory allocation error for *icharge in respin()\n"); exit(1); } pcharge = (double *) malloc(sizeof(double) * atomnum); if (pcharge == NULL) { fprintf(stdout, "memory allocation error for *pcharge in respin()\n"); exit(1); } for(i=0;i<atomnum;i++) { pcharge[i] = 0.0; icharge[i] = 0; } if(iaddinfo == 1) { if ((fpaddinfo = fopen(afilename, "r")) == NULL) { fprintf(stdout, "Cannot open the additional file %s to read in main(), exit\n", afilename); exit(1); } if ((fpcharge = fopen("QIN", "w")) == NULL) { fprintf(stdout, "Cannot open file QIN, exit\n"); exit(1); } readinfo(); } respin(method); if(iaddinfo == 1) { fclose(fpcharge); fclose(fpaddinfo); } printf("\n"); /* free(atom); free(selectindex); free(selectelement); free(equ_atom_id); free(pathnum); free(pathatomnum); for (i =0 ;i <atomnum; i++) free(pathscore[i]); */ return (0); }
int main(int argc, char *argv[]) { int i,j,k; int overflow_flag = 0; int count; int atid1, atid2; int resid1, resid2; int oldresid; int suc; double sum; double x,y,z; char line[MAXCHAR]; char defstr[MAXCHAR]; char atomname[MAXCHAR]; amberhome = (char *) getenv("AMBERHOME"); if( amberhome == NULL ){ fprintf( stdout, "AMBERHOME is not set!\n" ); exit(1); } if (strcmp(COLORTEXT, "YES") == 0 || strcmp(COLORTEXT, "yes") == 0) { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf ("[31mUsage: match -i [0m input file name \n" "[31m -r [0m reference file name \n" "[31m -f [0m format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n" "[31m -o [0m output file name\n" "[31m -l [0m run log file name, default is \"match.log\"\n" "[31m -s [0m selection mode\n" "[34m 0:[0m use all atoms (the default)\n" "[34m 1:[0m specify atom names\n" "[34m 2:[0m use atom defination file\n" "[34m 3:[0m use residue defination file - original residue IDs\n" "[34m 4:[0m use residue defination file - renumbered residue IDs\n" "[31m -ds [0mdefinition string if selection modes of '1' or '3' or '4'\n" "[31m [0me.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n" "[31m -df [0mdefinition file if selection mode of '2' or '3' or '4'\n" "[31m [0mrecords take a form of 'ATOM atom_id_input atom_id_reference'\n" "[31m [0mor 'RES res_id_input res_id_reference'\n" "[31m -n [0m number of atoms participating ls-fitting,\n" "[31m [0m default is -1, which implies to use all the selected atoms\n" "[31m -m [0m matrix file, default is \"match.matrix\"\n" "[31m -t [0m job type:\n" "[35m 0:[0m calculate rms only, need -i and -r\n" "[35m 1:[0m lsfit, need -i, -r and -o the default\n" "[35m 2:[0m translation/rotation, need -i, -o and -m\n"); exit(0); } if (argc != 23 && argc != 21 && argc != 19 && argc != 17 && argc != 15 && argc != 13 && argc != 11 && argc !=9 && argc !=7 && argc !=5) { printf ("[31mUsage: match -i [0m input file name \n" "[31m -r [0m reference file name \n" "[31m -f [0m format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n" "[31m -o [0m output file name\n" "[31m -l [0m run log file name, default is \"match.log\"\n" "[31m -s [0m selection mode\n" "[34m 0:[0m use all atoms (the default)\n" "[34m 1:[0m specify atom names\n" "[34m 2:[0m use atom defination file\n" "[34m 3:[0m use residue defination file - original residue IDs\n" "[34m 4:[0m use residue defination file - renumbered residue IDs\n" "[31m -ds [0mdefinition string if selection modes of '1' or '3' or '4'\n" "[31m [0me.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n" "[31m -df [0mdefinition file if selection mode of '2' or '3' or '4'\n" "[31m [0mrecords take a form of 'ATOM atom_id_input atom_id_reference'\n" "[31m [0mor 'RES res_id_input res_id_reference'\n" "[31m -n [0m number of atoms participating ls-fitting,\n" "[31m [0m default is -1, which implies to use all the selected atoms\n" "[31m -m [0m matrix file, default is \"match.matrix\"\n" "[31m -t [0m job type:\n" "[35m 0:[0m calculate rms only, need -i and -r\n" "[35m 1:[0m lsfit, need -i, -r and -o the default\n" "[35m 2:[0m translation/rotation, need -i, -o and -m\n"); exit(0); } } else { if (argc == 2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "-H") == 0)) { printf ("Usage: match -i input file name \n" " -r reference file name \n" " -f format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n" " -o output file name\n" " -l run log file name, default is \"match.log\"\n" " -s selection mode\n" " 0: use all atoms (the default)\n" " 1: specify atom names\n" " 2: use atom defination file\n" " 3: use residue defination file - original residue IDs\n" " 4: use residue defination file - renumbered residue IDs\n" " -ds definition string if selection modes of '1' or '3' or '4'\n" " e.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n" " -df definition file if selection mode of '2' or '3' or '4'\n" " records take a form of 'ATOM atom_id_input atom_id_reference'\n" " or 'RES res_id_input res_id_reference'\n" " -n number of atoms participating ls-fitting,\n" " default is -1, which implies to use all the selected atoms\n" " -m matrix file, default is \"match.matrix\"\n" " -t job type:\n" " 0: calculate rms only, need -i and -r\n" " 1: lsfit, need -i, -r and -o the default\n" " 2: translation/rotation, need -i, -o and -m\n"); exit(0); } if (argc != 23 && argc != 21 && argc != 19 && argc != 17 && argc != 15 && argc != 13 && argc != 11 && argc !=9 && argc !=7 && argc !=5) { printf ("Usage: match -i input file name \n" " -r reference file name \n" " -f format: 1-pdb (the default), 2-ac, 3-mol2, 4-sdf, 5-crd/rst\n" " -o output file name\n" " -l run log file name, default is \"match.log\"\n" " -s selection mode\n" " 0: use all atoms (the default)\n" " 1: specify atom names\n" " 2: use atom defination file\n" " 3: use residue defination file - original residue IDs\n" " 4: use residue defination file - renumbered residue IDs\n" " -ds definition string if selection modes of '1' or '3' or '4'\n" " e.g. 'C,N,O,CA', or 'HET' which stands for heavy atoms for '-ds 1')\n" " -df definition file if selection mode of '2' or '3' or '4'\n" " records take a form of 'ATOM atom_id_input atom_id_reference'\n" " or 'RES res_id_input res_id_reference'\n" " -n number of atoms participating ls-fitting,\n" " default is -1, which implies to use all the selected atoms\n" " -m matrix file, default is \"match.matrix\"\n" " -t job type:\n" " 0: calculate rms only, need -i and -r\n" " 1: lsfit, need -i, -r and -o the default\n" " 2: translation/rotation, need -i, -o and -m\n"); exit(0); } } for (i = 1; i < argc; i += 2) { if (strcmp(argv[i], "-i") == 0) { strcpy(ifilename, argv[i + 1]); iinput = 1; } if (strcmp(argv[i], "-f") == 0) format=atoi(argv[i+1]); if (strcmp(argv[i], "-o") == 0) { strcpy(ofilename, argv[i + 1]); ioutput = 1; } if (strcmp(argv[i], "-r") == 0) { strcpy(rfilename, argv[i + 1]); iref = 1; } if (strcmp(argv[i], "-s") == 0) stype = atoi(argv[i+1]); if (strcmp(argv[i], "-ds") == 0) strcpy(def_atomname_str, argv[i + 1]); if (strcmp(argv[i], "-df") == 0) strcpy(def_filename, argv[i + 1]); if (strcmp(argv[i], "-m") == 0) { strcpy(mfilename, argv[i + 1]); imatrix = 1; } if (strcmp(argv[i], "-t") == 0) jobtype = atoi(argv[i+1]); if (strcmp(argv[i], "-n") == 0) nsel = atoi(argv[i+1]); if (strcmp(argv[i], "-l") == 0) strcpy(lfilename, argv[i + 1]); } if(jobtype !=0 && jobtype != 1 && jobtype != 2) jobtype = 1; if(format != 1 && format != 2 && format != 3 && format != 4 && format != 5) format = 1; if(jobtype == 0) if(iinput == 0 || iref == 0) { fprintf(stderr, "RMS calculation needs an input and a reference files, exit\n"); exit(0); } if(jobtype == 1) if(iinput == 0 || ioutput == 0 || iref == 0) { fprintf(stderr, "The least-square fitting calculation needs an input, an output and a reference files, exit\n"); exit(0); } if(jobtype == 2) if(iinput == 0 || ioutput == 0) { fprintf(stderr, "The translation/rotation job needs an input and an output files, exit\n"); exit(0); } if(jobtype == 0 || jobtype == 1) { if ((fplog = fopen(lfilename, "w")) == NULL) { fprintf(stderr, "Cannot open log file %s to write, exit\n", lfilename); exit(1); } } /* read in input files*/ memory(0, MAXATOM, MAXBOND, MAXRING); if(format == 1) { overflow_flag = rpdb(ifilename, &atomnum, atom, cinfo, minfo, 0); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rpdb(ifilename, &atomnum, atom, cinfo, minfo, 0); } } if(format == 2) { overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rac(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo); } } if(format == 3) { overflow_flag = rmol2(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rmol2(ifilename, &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); } } if(format == 4) { overflow_flag = rmdl(ifilename, &atomnum, atom, &bondnum, bond, cinfo, minfo); if (overflow_flag) { cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rmdl(ifilename, &atomnum, atom, &bondnum, bond, cinfo, minfo); } } if(format == 5) { overflow_flag = rrst(ifilename, &atomnum, atom, cinfo); if (overflow_flag) { cinfo.maxatom = atomnum + 10; memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rrst(ifilename, &atomnum, atom, cinfo); } } free(bond); free(ring); free(arom); cinfo.maxatom = MAXATOM; cinfo.maxbond = MAXBOND; cinfo.maxring = MAXRING; ref_memory(0, MAXATOM, MAXBOND, MAXRING); if(format == 1) { overflow_flag = rpdb(rfilename, &refatomnum, refatom, cinfo, minfo, 0); if (overflow_flag) { cinfo.maxatom = refatomnum + 10; cinfo.maxbond = refbondnum + 10; ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rpdb(rfilename, &refatomnum, refatom, cinfo, minfo, 0); } } if(format == 2) { overflow_flag = rac(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo); if (overflow_flag) { cinfo.maxatom = refatomnum + 10; cinfo.maxbond = refbondnum + 10; ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rac(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo); } } if(format == 3) { overflow_flag = rmol2(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo, 0); if (overflow_flag) { cinfo.maxatom = refatomnum + 10; cinfo.maxbond = refbondnum + 10; ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rmol2(rfilename, &refatomnum, refatom, &refbondnum, refbond, &cinfo, &minfo, 0); } } if(format == 4) { overflow_flag = rmdl(rfilename, &refatomnum, refatom, &refbondnum, refbond, cinfo, minfo); if (overflow_flag) { cinfo.maxatom = refatomnum + 10; cinfo.maxbond = refbondnum + 10; ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rmdl(rfilename, &refatomnum, refatom, &refbondnum, refbond, cinfo, minfo); } } if(format == 5) { overflow_flag = rrst(rfilename, &refatomnum, refatom, cinfo); if (overflow_flag) { cinfo.maxatom = refatomnum + 10; ref_memory(7, cinfo.maxatom, cinfo.maxbond, cinfo.maxring); overflow_flag = rrst(rfilename, &refatomnum, refatom, cinfo); } } free(refbond); free(refring); free(refarom); if(debug == 1) { for(i=0;i<atomnum;i++) printf("ATOM %5d %5s %5s %5d %8.3lf %8.3lf %8.3lf\n", i+1, atom[i].name, atom[i].aa, atom[i].resno, atom[i].x, atom[i].y, atom[i].z); for(i=0;i<refatomnum;i++) printf("ATOM %5d %5s %5s %5d %8.3lf %8.3lf %8.3lf\n", i+1, refatom[i].name, refatom[i].aa, refatom[i].resno, refatom[i].x, refatom[i].y, refatom[i].z); } if(jobtype == 0 || jobtype == 1) { fit_atom = (FITATOM *) malloc(sizeof(FITATOM) * atomnum); if (fit_atom == NULL) { fprintf(stderr, "memory allocation error for *fit_atom\n"); exit(1); } fit_refatom = (FITATOM *) malloc(sizeof(FITATOM) * refatomnum); if (fit_refatom == NULL) { fprintf(stderr, "memory allocation error for *fit_refatom\n"); exit(1); } if(stype == 0) { for(i=0;i<atomnum;i++) { fit_atom[i].x=atom[i].x; fit_atom[i].y=atom[i].y; fit_atom[i].z=atom[i].z; } for(i=0;i<refatomnum;i++) { fit_refatom[i].x=refatom[i].x; fit_refatom[i].y=refatom[i].y; fit_refatom[i].z=refatom[i].z; } fit_atomnum = atomnum; fit_refatomnum = refatomnum; } if(stype == 1) { count = 0; for(i=0;i <= strlen(def_atomname_str);i++) { if(def_atomname_str[i]==' ') continue; if(def_atomname_str[i]==',') def_atomname_str[i] = ' '; defstr[count] = def_atomname_str[i]; count++; } sscanf(defstr, "%s", atomname); strcpy(def_atomname[ndef_atomname].str, atomname); ndef_atomname++; for(i=1;i<strlen(defstr);i++) if(defstr[i] == ' ') { sscanf(&defstr[i], "%s", atomname); strcpy(def_atomname[ndef_atomname].str, atomname); ndef_atomname++; } for(i=0;i<atomnum;i++) { suc = 0; for(j=0;j<ndef_atomname;j++) { if(strcmp(def_atomname[j].str, atom[i].name) == 0) { suc = 1; break; } if(strcmp(def_atomname[j].str, "HET") == 0) if(atom[i].name[0] != 'H') { suc = 1; break; } } if(suc == 1) { fit_atom[fit_atomnum].x=atom[i].x; fit_atom[fit_atomnum].y=atom[i].y; fit_atom[fit_atomnum].z=atom[i].z; fit_atomnum++; } } for(i=0;i<refatomnum;i++) { suc = 0; for(j=0;j<ndef_atomname;j++) { if(strcmp(def_atomname[j].str, refatom[i].name) == 0) { suc = 1; break; } if(strcmp(def_atomname[j].str, "HET") == 0) if(refatom[i].name[0] != 'H') { suc = 1; break; } } if(suc == 1) { fit_refatom[fit_refatomnum].x=refatom[i].x; fit_refatom[fit_refatomnum].y=refatom[i].y; fit_refatom[fit_refatomnum].z=refatom[i].z; fit_refatomnum++; } } } if(stype == 2) { if ((fpdef = fopen(def_filename, "r")) == NULL) { fprintf(stderr, "Cannot open file %s, exit\n", def_filename); exit(1); } count = 0; for(;;) { if (fgets(line, MAXCHAR, fpdef) == NULL) break; if(strncmp(line, "ATOM", 4) == 0) { sscanf(&line[4], "%d%d", &atid1, &atid2); atid1--; atid2--; fit_atom[count].x=atom[atid1].x; fit_atom[count].y=atom[atid1].y; fit_atom[count].z=atom[atid1].z; fit_refatom[count].x=refatom[atid2].x; fit_refatom[count].y=refatom[atid2].y; fit_refatom[count].z=refatom[atid2].z; count++; } } fit_atomnum = count; fit_refatomnum = count; fclose(fpdef); } if(stype == 3 || stype == 4) { /*first of all, read in atom name definition strings*/ count = 0; for(i=0;i <= strlen(def_atomname_str);i++) { if(def_atomname_str[i]==' ') continue; if(def_atomname_str[i]==',') def_atomname_str[i] = ' '; defstr[count] = def_atomname_str[i]; count++; } sscanf(defstr, "%s", atomname); strcpy(def_atomname[ndef_atomname].str, atomname); ndef_atomname++; for(i=1;i<strlen(defstr);i++) if(defstr[i] == ' ') { sscanf(&defstr[i], "%s", atomname); if(strcmp(atomname, "HET") == 0) { fprintf(stderr, "Warning: HET cannot be defined with -s of 3\n"); continue; } strcpy(def_atomname[ndef_atomname].str, atomname); ndef_atomname++; } if(debug == 1) { for(i=0;i<ndef_atomname;i++) printf("DEF %5d %5s\n", i+1, def_atomname[i].str); } if(stype == 4) { count = 0; oldresid = -99999; for(i=0;i<atomnum;i++) { if(atom[i].resno != oldresid) { oldresid = atom[i].resno; count++; } atom[i].resno = count; } count = 0; oldresid = -99999; for(i=0;i<refatomnum;i++) { if(refatom[i].resno != oldresid) { oldresid = refatom[i].resno; count++; } refatom[i].resno = count; } } /* now working on residue definition file */ if ((fpdef = fopen(def_filename, "r")) == NULL) { fprintf(stderr, "Cannot open file %s, exit\n", def_filename); exit(1); } count = 0; for(;;) { if (fgets(line, MAXCHAR, fpdef) == NULL) break; if(strncmp(line, "RES", 3) == 0) { sscanf(&line[3], "%d%d", &resid1, &resid2); if(debug == 1) printf("RES %5d %5d\n", resid1, resid2); for(i=0; i< ndef_atomname; i++) { atid1 = -1; atid2 = -1; for(j=0;j<atomnum;j++) if(strcmp(def_atomname[i].str, atom[j].name) == 0 && atom[j].resno == resid1) { atid1 = j; break; } for(j=0;j<refatomnum;j++) if(strcmp(def_atomname[i].str, refatom[j].name) == 0 && refatom[j].resno == resid2) { atid2 = j; break; } if(atid1 >= 0 && atid2 >= 0) { fit_atom[count].x=atom[atid1].x; fit_atom[count].y=atom[atid1].y; fit_atom[count].z=atom[atid1].z; fit_refatom[count].x=refatom[atid2].x; fit_refatom[count].y=refatom[atid2].y; fit_refatom[count].z=refatom[atid2].z; count++; } } } } fit_atomnum = count; fit_refatomnum = count; fclose(fpdef); } if(fit_atomnum != fit_refatomnum || fit_atomnum <=0) { fprintf(stderr, "\nThe numumber of fitting atoms in input file (%d) is different from the number of fitting atoms in ref file (%d)", fit_atomnum, fit_refatomnum); exit(0); } if(nsel > 0 && fit_atomnum > nsel) fit_atomnum = nsel; if(fit_atomnum <= 0) { fprintf(stderr, "\nThe number of fitting atoms is smaller than or equal to zero, exit!"); exit(1); } sum = 0; for(i=0;i<fit_atomnum;i++) { sum+=(fit_atom[i].x-fit_refatom[i].x) * (fit_atom[i].x-fit_refatom[i].x); sum+=(fit_atom[i].y-fit_refatom[i].y) * (fit_atom[i].y-fit_refatom[i].y); sum+=(fit_atom[i].z-fit_refatom[i].z) * (fit_atom[i].z-fit_refatom[i].z); } rms = sqrt(sum/fit_atomnum); fprintf(fplog, "The rmsd before least-square fitting is %9.4lf\n", rms); fprintf(fplog, "Number of atoms participate least-square fitting is %9d\n", fit_atomnum); fprintf(stdout, "\nThe rmsd before least-square fitting is %9.4lf", rms); fprintf(stdout, "\nNumber of atoms participate least-square fitting is %9d", fit_atomnum); if(jobtype == 0) { fclose(fplog); return 0; } if ((fpmatrix = fopen(mfilename, "w")) == NULL) { fprintf(stderr, "Cannot open file %s, exit\n", mfilename); exit(1); } rms = lsfit(fit_refatom, fit_atom, fit_atomnum) ; for(i=0;i<fit_atomnum;i++) { x=CG0[0]+ROT[0][0]*(fit_atom[i].x-CG1[0])+ ROT[0][1]*(fit_atom[i].y-CG1[1])+ ROT[0][2]*(fit_atom[i].z-CG1[2]); y=CG0[1]+ROT[1][0]*(fit_atom[i].x-CG1[0])+ ROT[1][1]*(fit_atom[i].y-CG1[1])+ ROT[1][2]*(fit_atom[i].z-CG1[2]); z=CG0[2]+ROT[2][0]*(fit_atom[i].x-CG1[0])+ ROT[2][1]*(fit_atom[i].y-CG1[1])+ ROT[2][2]*(fit_atom[i].z-CG1[2]); sum =(x-fit_refatom[i].x) * (x-fit_refatom[i].x); sum+=(y-fit_refatom[i].y) * (y-fit_refatom[i].y); sum+=(z-fit_refatom[i].z) * (z-fit_refatom[i].z); sum = sqrt(sum); fprintf(fplog, "ATOM %5d %9.3lf %9.3lf %9.3lf ", i+1, fit_atom[i].x, fit_atom[i].y, fit_atom[i].z); fprintf(fplog, "REFATOM %9.3lf %9.3lf %9.3lf %9.3lf\n", fit_refatom[i].x, fit_refatom[i].y, fit_refatom[i].z, sum); } fclose(fpmatrix); fprintf(fplog, "\nThe rmsd after least-square fitting is %9.4lf\n", rms); fprintf(stdout, "\nThe rmsd after least-square fitting is %9.4lf\n", rms); fclose(fplog); } if(jobtype == 2) rmatrix(mfilename); if(jobtype == 1 || jobtype == 2) { for(i=0;i<atomnum;i++) { x=CG0[0]+ROT[0][0]*(atom[i].x-CG1[0])+ ROT[0][1]*(atom[i].y-CG1[1])+ ROT[0][2]*(atom[i].z-CG1[2]); y=CG0[1]+ROT[1][0]*(atom[i].x-CG1[0])+ ROT[1][1]*(atom[i].y-CG1[1])+ ROT[1][2]*(atom[i].z-CG1[2]); z=CG0[2]+ROT[2][0]*(atom[i].x-CG1[0])+ ROT[2][1]*(atom[i].y-CG1[1])+ ROT[2][2]*(atom[i].z-CG1[2]); atom[i].x = x; atom[i].y = y; atom[i].z = z; } if(format == 1) wpdb(ofilename, atomnum, atom); if(format == 2) wac(ofilename, atomnum, atom, bondnum, bond, cinfo, minfo); if(format == 3) wmol2(ofilename, atomnum, atom, bondnum, bond, arom, cinfo, minfo); if(format == 4) wmdl(ofilename, atomnum, atom, bondnum, bond, cinfo); if(format == 5) wrst(ofilename, atomnum, atom); } return 0; }