blist = get_blist(mol, atids) all_list = get_all_list(mol, blist, atids, 8.0) natids = {} for i in range(0, len(atids)): natids[atids[i]] = i + 1 #crds after optimization if options.softversion in ['g03', 'g09']: crds = get_crds_from_fchk(options.hessfile, len(atids)) elif options.softversion == 'gms': crds = get_crds_from_gms(options.hessfile) #Whole Hessian Matrix if options.softversion in ['g03', 'g09']: fcmatrix = get_matrix_from_fchk(options.hessfile, 3*len(atids)) elif options.softversion == 'gms': fcmatrix = get_matrix_from_gms(options.hessfile, 3*len(atids)) for i in all_list.bondlist: at1 = i[0] at2 = i[1] nat1 = natids[at1] nat2 = natids[at2] if options.bondavg is True: dis, fcfinal, stdv = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, options.scalef, 1) else: dis, fcfinal = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, options.scalef, 0) print('### Bond force constant between ' + \
blist = get_blist(mol, atids) all_list = get_all_list(mol, blist, atids, 8.0) natids = {} for i in range(0, len(atids)): natids[atids[i]] = i + 1 #crds after optimization if options.softversion in ['g03', 'g09']: crds = get_crds_from_fchk(options.hessfile, len(atids)) elif options.softversion == 'gms': crds = get_crds_from_gms(options.hessfile) #Whole Hessian Matrix if options.softversion in ['g03', 'g09']: fcmatrix = get_matrix_from_fchk(options.hessfile, 3 * len(atids)) elif options.softversion == 'gms': fcmatrix = get_matrix_from_gms(options.hessfile, 3 * len(atids)) for i in all_list.bondlist: at1 = i[0] at2 = i[1] nat1 = natids[at1] nat2 = natids[at2] if options.bondavg is True: dis, fcfinal, stdv = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, options.scalef, 1) else: dis, fcfinal = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, options.scalef, 0)
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_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 get_all_fc_with_sem(mol, atids, hessf, prog, scalef, bondavg, avg13, angavg): """Generate all the force constants with Z-matrix method""" print_method_title('S') # Get the new atom ids natids = {} for i in xrange(0, len(atids)): natids[atids[i]] = i + 1 # Get the connection list blist = get_blist(mol, atids) all_list = get_all_list(mol, blist, atids, 8.0) # Crds after optimization if prog in ['g03', 'g09']: crds = get_crds_from_fchk(hessf, len(atids)) elif prog == 'gms': crds = get_crds_from_gms(hessf) # Whole Hessian Matrix if prog in ['g03', 'g09']: fcmatrix = get_matrix_from_fchk(hessf, 3 * len(atids)) elif prog == 'gms': fcmatrix = get_matrix_from_gms(hessf, 3 * len(atids)) # Print the bond part if bondavg is True: print_bond_title_wsd() else: print_bond_title() for i in all_list.bondlist: at1 = i[0] at2 = i[1] nat1 = natids[at1] nat2 = natids[at2] at1_rep = atom_rep(mol, at1) at2_rep = atom_rep(mol, at2) if bondavg is True: dis, fcfinal, stdv = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, scalef, 1) print_bond_inf_wsd(at1_rep, at2_rep, fcfinal, stdv, dis) else: dis, fcfinal = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat2, scalef, 0) print_bond_inf(at1_rep, at2_rep, fcfinal, dis) # Print the 1-3 part if avg13 is True: print_13_title_wsd() else: print_13_title() for i in all_list.anglist: at1 = i[0] at3 = i[2] nat1 = natids[at1] nat3 = natids[at3] at1_rep = atom_rep(mol, at1) at3_rep = atom_rep(mol, at3) if avg13 is True: dis, fcfinal, stdv = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat3, scalef, 1) print_13_inf_wsd(at1_rep, at3_rep, fcfinal, stdv, dis) else: dis, fcfinal = get_bond_fc_with_sem(crds, fcmatrix, nat1, nat3, scalef, 0) print_13_inf(at1_rep, at3_rep, fcfinal, dis) # Print the Angle part if angavg is True: print_angle_title_wsd() else: print_angle_title() for i in all_list.anglist: at1 = i[0] at2 = i[1] at3 = i[2] nat1 = natids[at1] nat2 = natids[at2] nat3 = natids[at3] at1_rep = atom_rep(mol, at1) at2_rep = atom_rep(mol, at2) at3_rep = atom_rep(mol, at3) if angavg is True: angval, fcfinal, stdv = get_ang_fc_with_sem( crds, fcmatrix, nat1, nat2, nat3, scalef, 1) print_angle_inf_wsd(at1_rep, at2_rep, at3_rep, fcfinal, stdv, angval) else: angval, fcfinal = get_ang_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, scalef, 0) print_angle_inf(at1_rep, at2_rep, at3_rep, fcfinal, angval) # Print the Dihedral part print_dih_title() for i in all_list.dihlist: at1 = i[0] at2 = i[1] at3 = i[2] at4 = i[3] nat1 = natids[at1] nat2 = natids[at2] nat3 = natids[at3] nat4 = natids[at4] at1_rep = atom_rep(mol, at1) at2_rep = atom_rep(mol, at2) at3_rep = atom_rep(mol, at3) at4_rep = atom_rep(mol, at4) dihval, fcfinal = get_dih_fc_with_sem(crds, fcmatrix, nat1, nat2, nat3, nat4, scalef) print_dih_inf(at1_rep, at2_rep, at3_rep, at4_rep, fcfinal, dihval) # Print the Improper part print_imp_title() for i in all_list.implist: at1 = i[0] at2 = i[1] at3 = i[2] #Central atom at4 = i[3] nat1 = natids[at1] nat2 = natids[at2] nat3 = natids[at3] nat4 = natids[at4] at1_rep = atom_rep(mol, at1) at2_rep = atom_rep(mol, at2) at3_rep = atom_rep(mol, at3) at4_rep = atom_rep(mol, at4) if mol.atoms[at1].element == mol.atoms[at2].element: fcfinal, dis = get_imp_fc_with_sem( crds, fcmatrix, nat3, nat1, nat2, nat4, scalef) #Treat the central atom first print_imp_inf(at1_rep, at2_rep, at3_rep, at4_rep, fcfinal, dis) elif mol.atoms[at1].element == mol.atoms[at4].element: fcfinal, dis = get_imp_fc_with_sem( crds, fcmatrix, nat3, nat1, nat4, nat2, scalef) #Treat the central atom first print_imp_inf(at1_rep, at4_rep, at3_rep, at2_rep, fcfinal, dis) elif mol.atoms[at2].element == mol.atoms[at4].element: fcfinal, dis = get_imp_fc_with_sem( crds, fcmatrix, nat3, nat2, nat4, nat1, scalef) #Treat the central atom first print_imp_inf(at4_rep, at2_rep, at3_rep, at1_rep, fcfinal, dis) else: fcfinal, dis = get_imp_fc_with_sem( crds, fcmatrix, nat3, nat1, nat2, nat4, scalef) #Treat the central atom first print_imp_inf(at1_rep, at2_rep, at3_rep, at4_rep, fcfinal, dis)