def gene_by_QM_fitting_zmatrix(smpdbf, ionids, stfpf, pref, finf, logfname, scalef): print("=============Using the Z-matrix method to generate the parameters.") sturefs, vals, fcs = get_fc_from_log(logfname) #pdb file mol, atids, resids = get_atominfo_fpdb(smpdbf) blist = get_mc_blist(mol, atids, ionids, stfpf) alist = get_alist(mol, blist) #reverse new id dict rvnatids = {} for i in range(0, len(atids)): rvnatids[i + 1] = atids[i] attypdict = get_attypdict(stfpf, atids) missbondtyps, missangtyps = get_misstyps(pref) #final parameter dicts finalparmdict = {} #for bond print("=======================Generate the bond parameters===============") for misbond in missbondtyps: bondlen = [] bfconst = [] for i in range(0, len(sturefs)): if len(sturefs[i]) == 2: at1 = sturefs[i][0] at2 = sturefs[i][1] bondtyp = (attypdict[rvnatids[at1]], attypdict[rvnatids[at2]]) "The unit in log file is Angs." if bondtyp == misbond or bondtyp[::-1] == misbond: dis = vals[i] fcfinal = fcs[i] * HB2_TO_KCAL_MOL_A2 * 0.5 fcfinal = fcfinal * scalef * scalef #Hatree/(Bohr^2) to kcal/(mol*angstrom^2) #Times 0.5 factor since AMBER use k(r-r0)^2 but not 1/2*k*(r-r0)^2 bondlen.append(dis) bfconst.append(fcfinal) #Get average bond parameters misbondat12 = misbond[0] + '-' + misbond[1] bond_para = avg_bond_para(misbondat12, bondlen, bfconst) #get the force constant finalparmdict[misbondat12] = bond_para #for angle print("=======================Generate the angle parameters==============") for misang in missangtyps: angvals = [] afconst = [] for i in range(0, len(sturefs)): if len(sturefs[i]) == 3: at1 = sturefs[i][0] at2 = sturefs[i][1] at3 = sturefs[i][2] angtyp = (attypdict[rvnatids[at1]], attypdict[rvnatids[at2]], attypdict[rvnatids[at3]]) if angtyp == misang or angtyp[::-1] == misang: angval = vals[i] fcfinal = fcs[i] * H_TO_KCAL_MOL * 0.5 fcfinal = fcfinal * scalef * scalef #Hatree to kcal/mol #Times 0.5 factor since AMBER use k(r-r0)^2 but not 1/2*k*(r-r0)^2 angvals.append(angval) afconst.append(fcfinal) #Get average angle parameters misangat123 = misang[0] + '-' + misang[1] + '-' + misang[2] ang_para = avg_angle_para(misangat123, angvals, afconst) finalparmdict[misangat123] = ang_para #Print out the final frcmod file print_frcmod_file(pref, finf, finalparmdict, 'Z-matrix')
def gene_by_QM_fitting_sem(smpdbf, ionids, stfpf, pref, finf, chkfname, logfile, g0x, scalef, bondavg, angavg): print("==================Using the Seminario method to solve the problem.") mol, atids, resids = get_atominfo_fpdb(smpdbf) blist = get_mc_blist(mol, atids, ionids, stfpf) alist = get_alist(mol, blist) #crds after optimization if g0x in ['g03', 'g09']: crds = get_crds_from_fchk(chkfname, len(atids)) elif g0x == 'gms': crds = get_crds_from_gms(logfile) #Whole Hessian Matrix if g0x in ['g03', 'g09']: fcmatrix = get_matrix_from_fchk(chkfname, 3 * len(atids)) elif g0x == 'gms': fcmatrix = get_matrix_from_gms(logfile, 3 * len(atids)) natids = {} for i in range(0, len(atids)): natids[atids[i]] = i + 1 attypdict = get_attypdict(stfpf, atids) missbondtyps, missangtyps = get_misstyps(pref) finalparmdict = {} #for bond print("=======================Generate the bond parameters===============") for misbond in missbondtyps: bondlen = [] bfconst = [] for bond in blist: at1 = bond[0] at2 = bond[1] bondtyp = (attypdict[at1], attypdict[at2]) "The unit in fchk file is a.u. so the distance is in Bohr." if bondtyp == misbond or bondtyp[::-1] == misbond: nat1 = natids[at1] nat2 = natids[at2] if bondavg == 1: dis, fcfinal, stdv = get_bond_fc_with_sem( crds, fcmatrix, nat1, nat2, scalef, bondavg) print('### Bond force constant between ' + \ mol.atoms[at1].resname + str(mol.atoms[at1].resid) + '@' + mol.atoms[at1].atname + ' and ' + \ mol.atoms[at2].resname + str(mol.atoms[at2].resid) + '@' + mol.atoms[at2].atname + ' : ' + \ str(round(fcfinal, 1)) + ' with StdDev ' + str(round(stdv, 1))) elif bondavg == 0: dis, fcfinal = get_bond_fc_with_sem( crds, fcmatrix, nat1, nat2, scalef, bondavg) bondlen.append(dis) bfconst.append(fcfinal) #Get average bond parameters misbondat12 = misbond[0] + '-' + misbond[1] bond_para = avg_bond_para(misbondat12, bondlen, bfconst) #get the force constant finalparmdict[misbondat12] = bond_para #for angle print("=======================Generate the angle parameters==============") for misang in missangtyps: angvals = [] afconst = [] for ang in alist: at1 = ang[0] at2 = ang[1] at3 = ang[2] angtyp = (attypdict[at1], attypdict[at2], attypdict[at3]) if angtyp == misang or angtyp[::-1] == misang: nat1 = natids[at1] nat2 = natids[at2] nat3 = natids[at3] if angavg == 1: angval, fcfinal, stdv = get_ang_fc_with_sem( crds, fcmatrix, nat1, nat2, nat3, scalef, angavg) print('### Angle force constant between ' + \ mol.atoms[at1].resname + str(mol.atoms[at1].resid) + '@' + mol.atoms[at1].atname + ', ' + \ mol.atoms[at2].resname + str(mol.atoms[at2].resid) + '@' + mol.atoms[at2].atname + ' and ' + \ mol.atoms[at3].resname + str(mol.atoms[at3].resid) + '@' + mol.atoms[at3].atname + ' : ' + \ str(round(fcfinal, 2)) + ' with StdDev ' + str(round(stdv, 2))) elif angavg == 0: angval, fcfinal = get_ang_fc_with_sem( crds, fcmatrix, nat1, nat2, nat3, scalef, angavg) angvals.append(angval) afconst.append(fcfinal) #Get average angle parameters misangat123 = misang[0] + '-' + misang[1] + '-' + misang[2] ang_para = avg_angle_para(misangat123, angvals, afconst) finalparmdict[misangat123] = ang_para #Print out the final frcmod file print_frcmod_file(pref, finf, finalparmdict, 'Seminario')
def gene_by_empirical_way(smpdbf, ionids, stfpf, pref, finf): print("******************************************************************") print("* *") print("*===========Using the empirical way to solve the problem=========*") print("* *") print("******************************************************************") #Read from small pdb mol, atids, resids = get_atominfo_fpdb(smpdbf) blist = get_mc_blist(mol, atids, ionids, stfpf) alist = get_alist(mol, blist) attypdict = get_attypdict(stfpf, atids) missbondtyps, missangtyps = get_misstyps(pref) finalparmdict = {} #for bond print("=======================Generate the bond parameters===============") for misbond in missbondtyps: bondlen = [] bfconst = [] for bond in blist: at1 = bond[0] at2 = bond[1] bondtyp = (attypdict[at1], attypdict[at2]) if bondtyp == misbond or bondtyp[::-1] == misbond: crd1 = mol.atoms[at1].crd crd2 = mol.atoms[at2].crd dis = calc_bond(crd1, crd2) dis = round(dis, 4) bondlen.append(dis) #get the atom number elmt1 = mol.atoms[at1].element elmt2 = mol.atoms[at2].element elmts = [elmt1, elmt2] elmts = sorted(elmts) fcfinal = fcfit_ep_bond(dis, elmts) bfconst.append(fcfinal) #Get average bond parameters misbondat12 = misbond[0] + '-' + misbond[1] bond_para = avg_bond_para(misbondat12, bondlen, bfconst) #get the force constant finalparmdict[misbondat12] = bond_para #for angle print("=======================Generate the angle parameters==============") for misang in missangtyps: angvals = [] afconst = [] for ang in alist: at1 = ang[0] at2 = ang[1] at3 = ang[2] angtyp = (attypdict[at1], attypdict[at2], attypdict[at3]) if angtyp == misang or angtyp[::-1] == misang: crd1 = mol.atoms[at1].crd crd2 = mol.atoms[at2].crd crd3 = mol.atoms[at3].crd angval = calc_angle(crd1, crd2, crd3) angvals.append(angval) elmt1 = mol.atoms[at1].element elmt2 = mol.atoms[at2].element elmt3 = mol.atoms[at3].element elmts = [elmt1, elmt2, elmt3] fcfinal = fcfit_ep_angle(elmts) afconst.append(fcfinal) #Get average angle parameters misangat123 = misang[0] + '-' + misang[1] + '-' + misang[2] ang_para = avg_angle_para(misangat123, angvals, afconst) finalparmdict[misangat123] = ang_para #Print out the final frcmod file print_frcmod_file(pref, finf, finalparmdict, 'empirical')
def gene_by_QM_fitting_zmatrix(smpdbf, ionids, stfpf, pref, finf, logfname, scalef): print("=============Using the Z-matrix method to generate the parameters.") sturefs, vals, fcs = get_fc_from_log(logfname) #pdb file mol, atids, resids = get_atominfo_fpdb(smpdbf) blist = get_mc_blist(mol, atids, ionids, stfpf) alist = get_alist(mol, blist) #reverse new id dict rvnatids = {} for i in range(0, len(atids)): rvnatids[i+1] = atids[i] attypdict = get_attypdict(stfpf, atids) missbondtyps, missangtyps = get_misstyps(pref) #final parameter dicts finalparmdict = {} #for bond print("=======================Generate the bond parameters===============") for misbond in missbondtyps: bondlen = [] bfconst = [] for i in range(0, len(sturefs)): if len(sturefs[i]) == 2: at1 = sturefs[i][0] at2 = sturefs[i][1] bondtyp = (attypdict[rvnatids[at1]], attypdict[rvnatids[at2]]) "The unit in log file is Angs." if bondtyp == misbond or bondtyp[::-1] == misbond: dis = vals[i] fcfinal = fcs[i] * HB2_TO_KCAL_MOL_A2 * 0.5 fcfinal = fcfinal * scalef * scalef #Hatree/(Bohr^2) to kcal/(mol*angstrom^2) #Times 0.5 factor since AMBER use k(r-r0)^2 but not 1/2*k*(r-r0)^2 bondlen.append(dis) bfconst.append(fcfinal) #Get average bond parameters misbondat12 = misbond[0] + '-' + misbond[1] bond_para = avg_bond_para(misbondat12, bondlen, bfconst) #get the force constant finalparmdict[misbondat12] = bond_para #for angle print("=======================Generate the angle parameters==============") for misang in missangtyps: angvals = [] afconst = [] for i in range(0, len(sturefs)): if len(sturefs[i]) == 3: at1 = sturefs[i][0] at2 = sturefs[i][1] at3 = sturefs[i][2] angtyp = (attypdict[rvnatids[at1]], attypdict[rvnatids[at2]], attypdict[rvnatids[at3]]) if angtyp == misang or angtyp[::-1] == misang: angval = vals[i] fcfinal = fcs[i] * H_TO_KCAL_MOL * 0.5 fcfinal = fcfinal * scalef * scalef #Hatree to kcal/mol #Times 0.5 factor since AMBER use k(r-r0)^2 but not 1/2*k*(r-r0)^2 angvals.append(angval) afconst.append(fcfinal) #Get average angle parameters misangat123 = misang[0] + '-' + misang[1] + '-' + misang[2] ang_para = avg_angle_para(misangat123, angvals, afconst) finalparmdict[misangat123] = ang_para #Print out the final frcmod file print_frcmod_file(pref, finf, finalparmdict, 'Z-matrix')
def gene_by_QM_fitting_sem(smpdbf, ionids, stfpf, pref, finf, chkfname, logfile, g0x, scalef, bondavg, angavg): print("==================Using the Seminario method to solve the problem.") mol, atids, resids = get_atominfo_fpdb(smpdbf) blist = get_mc_blist(mol, atids, ionids, stfpf) alist = get_alist(mol, blist) #crds after optimization if g0x in ['g03', 'g09']: crds = get_crds_from_fchk(chkfname, len(atids)) elif g0x == 'gms': crds = get_crds_from_gms(logfile) #Whole Hessian Matrix if g0x in ['g03', 'g09']: fcmatrix = get_matrix_from_fchk(chkfname, 3*len(atids)) elif g0x == 'gms': fcmatrix = get_matrix_from_gms(logfile, 3*len(atids)) natids = {} for i in range(0, len(atids)): natids[atids[i]] = i + 1 attypdict = get_attypdict(stfpf, atids) missbondtyps, missangtyps = get_misstyps(pref) finalparmdict = {} #for bond print("=======================Generate the bond parameters===============") for misbond in missbondtyps: bondlen = [] bfconst = [] for bond in blist: at1 = bond[0] at2 = bond[1] bondtyp = (attypdict[at1], attypdict[at2]) "The unit in fchk file is a.u. so the distance is in Bohr." if bondtyp == misbond or bondtyp[::-1] == misbond: nat1 = natids[at1] nat2 = natids[at2] if bondavg == 1: dis, fcfinal, stdv = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, scalef, bondavg) print('### Bond force constant between ' + \ mol.atoms[at1].resname + str(mol.atoms[at1].resid) + '@' + mol.atoms[at1].atname + ' and ' + \ mol.atoms[at2].resname + str(mol.atoms[at2].resid) + '@' + mol.atoms[at2].atname + ' : ' + \ str(round(fcfinal, 1)) + ' with StdDev ' + str(round(stdv, 1))) elif bondavg == 0: dis, fcfinal = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, scalef, bondavg) bondlen.append(dis) bfconst.append(fcfinal) #Get average bond parameters misbondat12 = misbond[0] + '-' + misbond[1] bond_para = avg_bond_para(misbondat12, bondlen, bfconst) #get the force constant finalparmdict[misbondat12] = bond_para #for angle print("=======================Generate the angle parameters==============") for misang in missangtyps: angvals = [] afconst = [] for ang in alist: at1 = ang[0] at2 = ang[1] at3 = ang[2] angtyp = (attypdict[at1], attypdict[at2], attypdict[at3]) if angtyp == misang or angtyp[::-1] == misang: nat1 = natids[at1] nat2 = natids[at2] nat3 = natids[at3] if angavg == 1: angval, fcfinal, stdv = get_ang_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, scalef, angavg) print('### Angle force constant between ' + \ mol.atoms[at1].resname + str(mol.atoms[at1].resid) + '@' + mol.atoms[at1].atname + ', ' + \ mol.atoms[at2].resname + str(mol.atoms[at2].resid) + '@' + mol.atoms[at2].atname + ' and ' + \ mol.atoms[at3].resname + str(mol.atoms[at3].resid) + '@' + mol.atoms[at3].atname + ' : ' + \ str(round(fcfinal, 2)) + ' with StdDev ' + str(round(stdv, 2))) elif angavg == 0: angval, fcfinal = get_ang_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, scalef, angavg) angvals.append(angval) afconst.append(fcfinal) #Get average angle parameters misangat123 = misang[0] + '-' + misang[1] + '-' + misang[2] ang_para = avg_angle_para(misangat123, angvals, afconst) finalparmdict[misangat123] = ang_para #Print out the final frcmod file print_frcmod_file(pref, finf, finalparmdict, 'Seminario')