# define CONVERG 0.00001 # define GASMAXITER 500 # define DAMPFACTOR 0.5 GASTEIGER gas[MAXGAS]; MOLINFO minfo2; void wpdb_optimized(char *filename, int atomnum, ATOM atom[] ,int flag) { ATOM *atom_tmp; int i; /* when read in a mopout file, always output a pdb file that has the optimized coordinates */ atom_tmp = (ATOM *) malloc(sizeof(ATOM) * atomnum); if (atom_tmp == NULL) { fprintf(stdout, "memory allocation error for *atom_tmp\n"); exit(1); } for(i=0;i atomnum) break; } fclose(fpin); // if ((*minfo).usercharge < -9990) if ((*minfo).icharge < -9990) (*minfo).icharge = intcharge(atomnum, atom); } /*CHARGE METHOD : READ CHARGE */ void rcharge(char *filename, int atomnum, ATOM atom[], CONTROLINFO cinfo, MOLINFO *minfo) { FILE *fpcharge; char line[MAXCHAR]; int i,j; int flag; int break_flag = 0; int ncol = 0; double chg[10]; if ((fpcharge = fopen(filename, "r")) == NULL) { fprintf(stdout, "Cannot open charge file to read: %s , exit\n", filename); exit(1); } i = 0; flag = 0; for (;;) { if (fgets(line, MAXCHAR, fpcharge) == NULL) { /* printf("\nFinished reading file %s", filename); */ break; } sscanf(line, "%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf", &chg[0], &chg[1], &chg[2], &chg[3], &chg[4], &chg[5], &chg[6], &chg[7], &chg[8], &chg[9]); // check how many colums per line if(flag == 0) { for(j = 0; j 0) { sprintf(str_max_path_len, "%d", cinfo.max_path_length); use_max_path_len = 1; } copied_size = build_exe_path(tmpchar1, "espgen", sizeof tmpchar1, 1); strncat(tmpchar1, " -o ANTECHAMBER.ESP -i ", sizeof tmpchar1 - copied_size ); strncat(tmpchar1, filename, sizeof tmpchar1 - strlen(tmpchar1) ); copied_size = build_exe_path(tmpchar2, "respgen", sizeof tmpchar2, 1); strncat(tmpchar2, " -i ANTECHAMBER_RESP.AC -o ANTECHAMBER_RESP1.IN" " -f resp1 -e ", sizeof tmpchar2 - copied_size); strcat(tmpchar2, str_eqcharge); if(use_max_path_len == 1) { strcat(tmpchar2, " -l "); strcat(tmpchar2, str_max_path_len); } copied_size = build_exe_path(tmpchar3, "respgen", sizeof tmpchar3, 1); strncat(tmpchar3, " -i ANTECHAMBER_RESP.AC -o ANTECHAMBER_RESP2.IN" " -f resp2 -e ", sizeof tmpchar3 - copied_size); strcat(tmpchar3, str_eqcharge); if(use_max_path_len == 1) { strcat(tmpchar3, " -l "); strcat(tmpchar3, str_max_path_len); } copied_size = build_exe_path(tmpchar4, "resp", sizeof tmpchar4, 1 ); copied_size = build_exe_path(tmpchar5, "resp", sizeof tmpchar5, 1 ); /* run espgen: */ if (cinfo.intstatus == 2) fprintf(stdout, "\nRunning: %s\n\n", tmpchar1); status = system(tmpchar1); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" in resp() of charge.c properly, exit\n", tmpchar1); exit(1); } /* run respgen to make ANTECHAMBER_RESP1.IN: */ if (cinfo.intstatus == 2) fprintf(stdout, "\nRunning: %s\n\n", tmpchar2); status = system(tmpchar2); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" in resp() of charge.c properly, exit\n", tmpchar2); exit(1); } /* run respgen to make ANTECHAMBER_RESP2.IN: */ if (cinfo.intstatus == 2) fprintf(stdout, "\nRunning: %s\n\n", tmpchar3); status = system(tmpchar3); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" in resp() of charge.c properly, exit\n", tmpchar3); exit(1); } /* run first stage of resp: */ strcat(tmpchar4, " -O -i ANTECHAMBER_RESP1.IN -o ANTECHAMBER_RESP1.OUT -e ANTECHAMBER.ESP -t qout"); if (cinfo.intstatus == 2) fprintf(stdout, "\nRunning: %s\n\n", tmpchar4); status = system(tmpchar4); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" in resp() of charge.c properly, exit\n", tmpchar4 ); exit(1); } /* run second stage of resp: */ strcat(tmpchar5, " -O -i ANTECHAMBER_RESP2.IN -o ANTECHAMBER_RESP2.OUT -e ANTECHAMBER.ESP -q qout -t QOUT"); if (cinfo.intstatus == 2) fprintf(stdout, "\nRunning: %s\n\n", tmpchar5); status = system(tmpchar5); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" in resp() of charge.c properly, exit\n", tmpchar5 ); exit(1); } rcharge("QOUT", atomnum, atom, cinfo, &minfo); } /* CHARGE METHOD : BCC-AM1 */ void bccharge(int atomnum, ATOM atom[], int bondnum, BOND bond[], AROM arom[], CONTROLINFO *cinfo, MOLINFO *minfo) { int i,j; int atomnum_tmp; int bondnum_tmp; int status = 0; ATOM *atom_tmp; BOND *bond_tmp; int *equ_atom_id; char tmpchar[MAXCHAR]; char tmpchar1[MAXCHAR]; char tmpchar2[MAXCHAR]; size_t copied_size; int nequatom; double tcharge; // find equal atoms and force their charge same if((*minfo).eqcharge ==1 || (*minfo).eqcharge == 2) { 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); } if((*minfo).eqcharge == 1) identify_equatom(atomnum, atom, equ_atom_id, (*cinfo).max_path_length, bondnum, bond, 0); if((*minfo).eqcharge == 2) identify_equatom(atomnum, atom, equ_atom_id, (*cinfo).max_path_length, bondnum, bond, 1); for(i=0;i x[j]) { xx = gas[gasparmindex[j]].d; q = (x[i] - x[j]) / xx * pow(DAMPFACTOR, iteration + 1); gaschargea[i] -= q; gaschargea[j] += q; } } iteration++; /* printf("\nIteration %5d", iteration); for (i = 0; i < atomnum; i++) printf("\n%5d %5s %8.4lf %8.4lf", i+1, atom[i].name, gaschargep[i], gaschargea[i]); */ rmsd = rmscal(atomnum, gaschargep, gaschargea); } while (rmsd > CONVERG && iteration < GASMAXITER); for (i = 0; i < atomnum; i++) atom[i].charge = gaschargea[i]; free(gasparmindex); free(x); free(gaschargep); free(gaschargea); } void gascharge(int atomnum, ATOM atom[], int bondnum, BOND bond[], CONTROLINFO cinfo, MOLINFO *minfo) { int i; int atomnum_tmp; int bondnum_tmp; int status = 0; ATOM *atom_tmp; BOND *bond_tmp; int gasparmnum = 0; char tmpchar1[MAXCHAR]; char tmpchar2[MAXCHAR]; size_t copied_size; GASTEIGER *gas; gas = (GASTEIGER *) malloc(sizeof(GASTEIGER) * MAXGAS); if (gas == NULL) { fprintf(stdout, "memory allocation error for gas in gascharge(),increase GASMAX in define.h exit\n"); exit(1); } build_dat_path((*minfo).gfilename, "GASPARM.DAT", sizeof (*minfo).gfilename, 0); rgasparm((*minfo).gfilename, &gasparmnum, gas); /*principle parameter file */ wac("ANTECHAMBER_GAS.AC", atomnum, atom, bondnum, bond, cinfo, (*minfo)); copied_size = build_exe_path(tmpchar1, "atomtype", sizeof tmpchar1, 1); strncat(tmpchar1, " -i ANTECHAMBER_GAS.AC -o ANTECHAMBER_GAS_AT.AC -d ", sizeof tmpchar1 - copied_size); build_dat_path(tmpchar2, "ATOMTYPE_GAS.DEF", sizeof tmpchar2, 1); strncat(tmpchar1, tmpchar2, sizeof tmpchar1 - strlen(tmpchar1) ); if (cinfo.intstatus == 2) fprintf(stdout, "Running: %s\n", tmpchar1); status = system(tmpchar1); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" of gascharge() in charge.c properly, exit\n", tmpchar1); exit(1); } cinfo.maxatom = atomnum + 10; cinfo.maxbond = bondnum + 10; atom_tmp = (ATOM *) malloc(sizeof(ATOM) * cinfo.maxatom); if (atom_tmp == NULL) { fprintf(stdout, "memory allocation error for *atom_tmp\n"); exit(1); } bond_tmp = (BOND *) malloc(sizeof(BOND) * cinfo.maxbond); if (bond_tmp == NULL) { fprintf(stdout, "memory allocation error for *bond_tmp\n"); exit(1); } for (i = 0; i < cinfo.maxbond; ++i) { bond_tmp[i].jflag = -1; /* bond type has not been assigned */ } minfo2 = *minfo; rac("ANTECHAMBER_GAS_AT.AC", &atomnum_tmp, atom_tmp, &bondnum_tmp, bond_tmp, &cinfo, &minfo2); // gasiter(atomnum_tmp, atom_tmp, gasparmnum, gas, (*minfo).usercharge); gasiter(atomnum_tmp, atom_tmp, gasparmnum, gas, (*minfo).icharge); for (i = 0; i < atomnum; i++) atom[i].charge = atom_tmp[i].charge; free(atom_tmp); free(bond_tmp); free(gas); } void write_sybyl_bat(char *str) { FILE *fpout; char tmpchar[MAXCHAR]; int status = 0; if ((fpout = fopen("antechamber_sybyl.bat", "w")) == NULL) { fprintf(stdout, "Cannot open antechamber_sybyl.bat , exit\n"); exit(1); } build_dat_path(tmpchar, "charge.spl", sizeof tmpchar, 0); fprintf(fpout, "%s", "#!/bin/csh"); fprintf(fpout, "\n%s", "sybyl << @"); fprintf(fpout, "\n%s", "take "); fprintf(fpout, "%s", tmpchar); if (strcmp(str, "gas1") == 0) fprintf(fpout, "\n%s", "CHARGE GASTEIGER"); if (strcmp(str, "gas2") == 0) fprintf(fpout, "\n%s", "CHARGE GAST_HUCK"); if (strcmp(str, "del") == 0) fprintf(fpout, "\n%s", "CHARGE DELRE"); if (strcmp(str, "pull") == 0) fprintf(fpout, "\n%s", "CHARGE PULLMAN "); if (strcmp(str, "huc") == 0) fprintf(fpout, "\n%s", "CHARGE HUCKEL"); if (strcmp(str, "mmff") == 0) fprintf(fpout, "\n%s", "CHARGE MMFF94"); fprintf(fpout, "\n%s", "QUIT YES"); fprintf(fpout, "\n%s\n\n", "@"); fclose(fpout); status = system("chmod +x antechamber_sybyl.bat"); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" of write_sybyl_bat() in charge.c properly, exit\n", "chmod +x antechamber_sybyl.bat"); exit(1); } status = system("antechamber_sybyl.bat"); if(status != 0) { fprintf(stdout, "Error: cannot run \"%s\" of write_sybyl_bat() in charge.c properly, exit\n", "antechamber_sybyl.bat"); exit(1); } } /* CHARGE METHOD : Gasteiger, using sybyl */ void gas1(int atomnum, ATOM atom[], int bondnum, BOND bond[], AROM arom[], CONTROLINFO cinfo, MOLINFO minfo) { wmol2("ANTECHAMBER_INPUT.mol2", atomnum, atom, bondnum, bond, arom, cinfo, minfo); write_sybyl_bat("gas1"); rmol2("ANTECHAMBER_INPUT.mol2", &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); } /* CHARGE METHOD : Del Re, using sybyl*/ void del(int atomnum, ATOM atom[], int bondnum, BOND bond[], AROM arom[], CONTROLINFO cinfo, MOLINFO minfo) { wmol2("ANTECHAMBER_INPUT.mol2", atomnum, atom, bondnum, bond, arom, cinfo, minfo); write_sybyl_bat("del"); rmol2("ANTECHAMBER_INPUT.mol2", &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); } /* CHARGE METHOD : Pullman, using sybyl */ void pull(int atomnum, ATOM atom[], int bondnum, BOND bond[], AROM arom[], CONTROLINFO cinfo, MOLINFO minfo) { wmol2("ANTECHAMBER_INPUT.mol2", atomnum, atom, bondnum, bond, arom, cinfo, minfo); write_sybyl_bat("pull"); rmol2("ANTECHAMBER_INPUT.mol2", &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); } /* CHARGE METHOD :Gasteiger-Huckel, using sybyl*/ void gas2(int atomnum, ATOM atom[], int bondnum, BOND bond[], AROM arom[], CONTROLINFO cinfo, MOLINFO minfo) { wmol2("ANTECHAMBER_INPUT.mol2", atomnum, atom, bondnum, bond, arom, cinfo, minfo); write_sybyl_bat("gas2"); rmol2("ANTECHAMBER_INPUT.mol2", &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); } /* CHARGE METHOD : Huckel, using sybyl */ void huc(int atomnum, ATOM atom[], int bondnum, BOND bond[], AROM arom[], CONTROLINFO cinfo, MOLINFO minfo) { wmol2("ANTECHAMBER_INPUT.mol2", atomnum, atom, bondnum, bond, arom, cinfo, minfo); write_sybyl_bat("huc"); rmol2("ANTECHAMBER_INPUT.mol2", &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); } /* CHARGE METHOD :MMFF94, using sybyl*/ void mmff(int atomnum, ATOM atom[], int bondnum, BOND bond[], AROM arom[], CONTROLINFO cinfo, MOLINFO minfo) { wmol2("ANTECHAMBER_INPUT.mol2", atomnum, atom, bondnum, bond, arom, cinfo, minfo); write_sybyl_bat("mmff"); rmol2("ANTECHAMBER_INPUT.mol2", &atomnum, atom, &bondnum, bond, &cinfo, &minfo, 0); }