def gene_pre_frcmod_file(ionids, naamol2f, stpdbf, stfpf, scresf, prefcdf, ffchoice, gaff, frcmodfs, watermodel): print "******************************************************************" print "* *" print "*===================Generate the Initial frcmod file=============*" print "* *" print "******************************************************************" libdict = {} chargedict = {} for mol2f in naamol2f: libdict1, chargedict1 = get_lib_dict(mol2f) libdict.update(libdict1) chargedict.update(chargedict1) #get the parameter dicts Params = get_parm_dict(ffchoice, gaff, frcmodfs) massparms = Params.mass bondparms = Params.bond angparms = Params.ang dihparms = Params.dih impparms = Params.imp nbparms = Params.nb #-------------------------------------------------------------------------- #############Get the metal center information#################### #-------------------------------------------------------------------------- mol, atids, resids = get_atominfo_fpdb(stpdbf) #get the blist blist = get_mc_blist(mol, atids, ionids, stfpf) #get_all_the_lists from standard model all_list = get_all_list(mol, blist, atids, 10.0) #atom type dictionary, key is the atom id, value is atom type attypdict = {} #atom ids which has been transfered to another atom type atidtrans = [] #get the information for the three from finger print fp = open(stfpf, 'r') for line in fp: if line[0:4] != "LINK": atinfo, atid, attyp1st, symbol, attyp2nd = line.split() atid = int(atid) attyp1st = addspace(attyp1st) attyp2nd = addspace(attyp2nd) attypdict[atid] = (attyp1st, attyp2nd) if attyp1st != attyp2nd: atidtrans.append(atid) fp.close() print "Atoms which has changed the atom types:", atidtrans for atid in atidtrans: resid = mol.atoms[atid].resid resname = mol.residues[resid].resname attyp1 = attypdict[atid][0] attyp2 = attypdict[atid][1] print str(resid) + '-' + resname + '@' + str(atid) + '-' + \ mol.atoms[atid].atname + ' : ' + attyp1, '-->', attyp2 #------------------------------------------------------------------------- ########Print the pre-generated frcmod files############## #------------------------------------------------------------------------- fmf = open(prefcdf, 'w') #for atoms which changed atom types print >> fmf, 'REMARK GOES HERE, THIS FILE IS GENERATED BY MCPB.PY' print >> fmf, 'MASS' for atid in atidtrans: if atid not in ionids: #not include metal ion atyp1 = attypdict[atid][0] atyp2 = attypdict[atid][1] print >> fmf, 'YES', atyp2 + massparms[atyp1] #for metal ions for i in ionids: attyp = attypdict[i][1] atname = mol.atoms[i].atname if len(atname) > 1: atname = atname[0] + atname[1:].lower() massi = Mass[atname] print >> fmf, 'YES', attyp + ' ' + str(round(massi, 2)) + \ ' ' + atname + ' ion' #-------------------------------------------------------------------------- bondparamsdict1 = {} #For metal ions bondparamsdict2 = {} #For the others print >> fmf, ' ' print >> fmf, 'BOND' #for bond for bonds in all_list.bondlist: i = bonds[0] j = bonds[1] if list(set(ionids) & set(bonds)) != []: #The bonds which related to the ions bondtyp2 = (attypdict[i][1], attypdict[j][1]) if (bondtyp2 not in bondparamsdict1.keys()) and (bondtyp2[::-1] \ not in bondparamsdict1.keys()): bondparamsdict1[bondtyp2] = ' ' elif list(set(atidtrans) & set(bonds)) != []: #The bonds related to the atoms which changed their atom types bondtyp1 = (attypdict[i][0], attypdict[j][0]) bondtyp2 = (attypdict[i][1], attypdict[j][1]) if (bondtyp2 not in bondparamsdict2.keys()) and (bondtyp2[::-1] \ not in bondparamsdict2.keys()): if bondtyp1 in bondparms.keys(): bondparamsdict2[bondtyp2] = bondparms[bondtyp1] elif bondtyp1[::-1] in bondparms.keys(): bondparamsdict2[bondtyp2] = bondparms[bondtyp1[::-1]] for i in bondparamsdict1.keys(): print >> fmf, 'NON', i[0] + '-' + i[1] + bondparamsdict1[i] for i in bondparamsdict2.keys(): print >> fmf, 'YES', i[0] + '-' + i[1] + bondparamsdict2[i] #-------------------------------------------------------------------------- coparas = [] r_scresf = open(scresf, 'r') for line in r_scresf: line = line.strip('\n') line = line.split('-') resid = int(line[1]) if ('GLY' in line) or ('KCO' in line) or ('ACE' in line): if resid + 1 not in resids: coparas.append(resid) r_scresf.close() angparamsdict1 = {} #For metal ions angparamsdict2 = {} #For the others print >> fmf, ' ' print >> fmf, 'ANGL' #for angle for angs in all_list.anglist: i = angs[0] j = angs[1] k = angs[2] if list(set(ionids) & set(angs)) != []: #The angles which related to the ions angtyp2 = (attypdict[i][1], attypdict[j][1], attypdict[k][1]) if (angtyp2 not in angparamsdict1.keys()) and (angtyp2[::-1] \ not in angparamsdict1.keys()): angparamsdict1[angtyp2] = ' ' #print >> fmf, 'NON', attypdict[i][1] + '-' + attypdict[j][1] + \ #'-' + attypdict[k][1] elif list(set(atidtrans) & set(angs)) != []: #The angles related to the atoms #which changed their atom types angtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0]) angtyp2 = (attypdict[i][1], attypdict[j][1], attypdict[k][1]) if (angtyp2 not in angparamsdict2.keys()) and (angtyp2[::-1] \ not in angparamsdict2.keys()): if angtyp1 in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1] elif angtyp1[::-1] in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1[::-1]] #Add for a specific situation for i in coparas: for atid in atidtrans: if mol.atoms[atid].atname == 'O' and mol.atoms[atid].resid == i: angtyp1 = (attypdict[atid][0], 'C ', 'N ') angtyp2 = (attypdict[atid][1], 'C ', 'N ') if (angtyp2 not in angparamsdict2.keys()) and (angtyp2[::-1] \ not in angparamsdict2.keys()): if angtyp1 in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1] elif angtyp1[::-1] in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1[::-1]] for i in angparamsdict1.keys(): print >> fmf, 'NON', i[0] + '-' + i[1] + '-' + i[2] + angparamsdict1[i] for i in angparamsdict2.keys(): print >> fmf, 'YES', i[0] + '-' + i[1] + '-' + i[2] + angparamsdict2[i] #-------------------------------------------------------------------------- dihparamsdict = {} #for dihedral for dihs in all_list.dihlist: i = dihs[0] j = dihs[1] k = dihs[2] l = dihs[3] if list(set(ionids) & set(dihs)) != []: #The dihedral related to the metal ions dihtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) dihtyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) if (dihtyp1 not in dihparamsdict.keys()) and (dihtyp1[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] elif list(set(atidtrans) & set(dihs)) != []: if list(set(atidtrans) & set(dihs[0::3])) == []: #Neither the 1st and 4th atom change atom types #There is 2nd or 3rd or both changed atom type(s) dihtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) dihtyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) dihtyp2 = ('X ', attypdict[j][0], attypdict[k][0], 'X ') dihtyp2n = ('X ', attypdict[j][1], attypdict[k][1], 'X ') if dihtyp1 in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1] elif dihtyp1[::-1] in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1[::-1]] elif dihtyp2 in dihparms.keys(): if (dihtyp2n not in dihparamsdict.keys()) and (dihtyp2n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp2n] = dihparms[dihtyp2] elif dihtyp2[::-1] in dihparms.keys(): if (dihtyp2n not in dihparamsdict.keys()) and (dihtyp2n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp2n] = dihparms[dihtyp2[::-1]] else: if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] else: #There is 1st or 4th atoms or both changed the atom type(s) dihtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) dihtyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) dihtyp2 = ('X ', attypdict[j][1], attypdict[k][1], 'X ') if dihtyp1 in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1] elif dihtyp1[::-1] in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1[::-1]] else: if (dihtyp2 in dihparms.keys()) or (dihtyp2[::-1] \ in dihparms.keys()): continue elif (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] #Add for a specfic situation for i in coparas: for atid in atidtrans: if mol.atoms[atid].atname == 'O' and mol.atoms[atid].resid == i: for ionid in ionids: if ((atid, ionid, 1) in all_list.bondlist) or \ ((ionid, atid, 1) in all_list.bondlist): dihtyp1 = (attypdict[ionid][0], attypdict[atid][0], 'C ', 'N ') dihtyp2 = (attypdict[ionid][1], attypdict[atid][1], 'C ', 'N ') if (dihtyp2 not in dihparamsdict) and ( dihtyp2[::-1] not in dihparamsdict): if dihtyp1 in dihparms.keys(): dihparamsdict[dihtyp2] = dihparms[dihtyp1] elif dihtyp1[::-1] in dihparms.keys(): dihparamsdict[dihtyp2] = dihparms[ dihtyp1[::-1]] else: dihparamsdict[dihtyp2] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] print >> fmf, ' ' print >> fmf, 'DIHE' for keyv in dihparamsdict.keys(): if 'X ' not in keyv: #For types don't contain X valv = dihparamsdict[keyv] keyv = keyv[0] + '-' + keyv[1] + '-' + keyv[2] + '-' + keyv[3] temp = len(valv) / 3 for i in range(0, temp): temp1 = i * 3 print >> fmf, 'YES', keyv, valv[temp1] + valv[temp1+1] + \ valv[temp1+2] for keyv in dihparamsdict.keys(): if 'X ' in keyv: #For types contain X valv = dihparamsdict[keyv] keyv = keyv[0] + '-' + keyv[1] + '-' + keyv[2] + '-' + keyv[3] temp = len(valv) / 3 for i in range(0, temp): temp1 = i * 3 print >> fmf, 'YES', keyv, valv[temp1] + valv[temp1+1] + \ valv[temp1+2] #-------------------------------------------------------------------------- impparamsdict = {} #For improper torsion for imps in all_list.implist: i = imps[0] j = imps[1] k = imps[2] l = imps[3] if list(set(ionids) & set(imps)) != []: continue elif list(set(atidtrans) & set(imps)) != []: imptyps = {} #1 situation imptyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) imptyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) #3 situations imptyp2 = ('X ', 'X ', attypdict[k][0], attypdict[i][0]) imptyp2n = ('X ', 'X ', attypdict[k][1], attypdict[i][1]) imptyp3 = ('X ', 'X ', attypdict[k][0], attypdict[j][0]) imptyp3n = ('X ', 'X ', attypdict[k][1], attypdict[j][1]) imptyp4 = ('X ', 'X ', attypdict[k][0], attypdict[l][0]) imptyp4n = ('X ', 'X ', attypdict[k][1], attypdict[l][1]) #6 situations imptyp5 = ('X ', attypdict[i][0], attypdict[k][0], attypdict[j][0]) imptyp5n = ('X ', attypdict[i][1], attypdict[k][1], attypdict[j][1]) imptyp6 = ('X ', attypdict[j][0], attypdict[k][0], attypdict[i][0]) imptyp6n = ('X ', attypdict[j][1], attypdict[k][1], attypdict[i][1]) imptyp7 = ('X ', attypdict[i][0], attypdict[k][0], attypdict[l][0]) imptyp7n = ('X ', attypdict[i][0], attypdict[k][1], attypdict[l][1]) imptyp8 = ('X ', attypdict[l][0], attypdict[k][0], attypdict[i][0]) imptyp8n = ('X ', attypdict[l][1], attypdict[k][1], attypdict[i][1]) imptyp9 = ('X ', attypdict[j][0], attypdict[k][0], attypdict[l][0]) imptyp9n = ('X ', attypdict[j][1], attypdict[k][1], attypdict[l][1]) imptyp10 = ('X ', attypdict[l][0], attypdict[k][0], attypdict[j][0]) imptyp10n = ('X ', attypdict[l][1], attypdict[k][1], attypdict[j][1]) imptyps[imptyp1] = imptyp1n imptyps[imptyp2] = imptyp2n imptyps[imptyp3] = imptyp3n imptyps[imptyp4] = imptyp4n imptyps[imptyp5] = imptyp5n imptyps[imptyp6] = imptyp6n imptyps[imptyp7] = imptyp7n imptyps[imptyp8] = imptyp8n imptyps[imptyp9] = imptyp9n imptyps[imptyp10] = imptyp10n for imptypkey in imptyps.keys(): if imptypkey in impparms.keys(): impparamsdict[imptyps[imptypkey]] = impparms[imptypkey] print >> fmf, ' ' print >> fmf, 'IMPR' #for improper torsion for i in impparamsdict.keys(): if i not in impparms.keys(): imptypkey = i[0] + '-' + i[1] + '-' + i[2] + '-' + i[3] print >> fmf, 'YES', imptypkey, impparamsdict[i] #-------------------------------------------------------------------------- #for nb print >> fmf, ' ' print >> fmf, 'NONB' for atid in atidtrans: #For the others if atid not in ionids: attyp1 = attypdict[atid][0] attyp2 = attypdict[atid][1] print >> fmf, 'YES ', attyp2 + nbparms[attyp1] IonLJParaDict = get_ionljparadict(watermodel) for i in ionids: #For metal ions element = mol.atoms[i].element chg = str(int(chargedict[mol.atoms[i].resname])) attyp2 = attypdict[i][1] rmin = IonLJParaDict[element + chg][0] ep = IonLJParaDict[element + chg][1] annot = IonLJParaDict[element + chg][2] print >> fmf, 'YES %s %11.3f %13.10f %-s' %(attyp2, rmin, \ ep, annot) print >> fmf, ' ' print >> fmf, ' ' fmf.close() #-------------------------------------------------------------------------- #Move the file, delete the repeat parts os.system("mv %s temp" % prefcdf) os.system("uniq temp > %s" % prefcdf) os.system("rm temp")
def resp_fitting(stpdbf, lgpdbf, stfpf, lgfpf, mklogf, ionids,\ ffchoice, mol2fs, metcenres2, chgmod, fixchg_resids, g0x, lgchg): print "******************************************************************" print "* *" print "*======================RESP Charge fitting=======================*" print "* *" print "******************************************************************" gene_resp_input_file(lgpdbf, ionids, stfpf, ffchoice, mol2fs, chgmod, fixchg_resids, lgchg) #------------------------------------------------------------------------- ####################RESP charge fitting################################### #------------------------------------------------------------------------- print '***Doing the RESP charge fiting...' espf = mklogf.strip('.log') + '.esp' if g0x in ['g03', 'g09']: get_esp_from_gau(mklogf, espf) elif g0x == 'gms': get_esp_from_gms(mklogf, espf) os.system("resp -O -i resp1.in -o resp1.out -p resp1.pch -t resp1.chg \ -e %s -s resp1_calc.esp" %espf) os.system("resp -O -i resp2.in -o resp2.out -p resp2.pch -q resp1.chg \ -t resp2.chg -e %s -s resp2_calc.esp" %espf) #------------------------------------------------------------------------- ####################Collecting the atom type and charge data############## #------------------------------------------------------------------------- #------------Atom type---------- sddict = {} #get the atom type information from standard model scf = open(stfpf, 'r') for line in scf: if line[0:4] != "LINK": line = line.strip('\n') line = line.split(' ') line = [i for i in line if i != ''] if len(line[-1]) == 1: line[-1] = line[-1] + ' ' sddict[line[0]] = line[-1] scf.close() #------------Charge------------- chgs = read_resp_file('resp2.chg') metcenres1 = [] #original name of the metal center residue stlist = [] #get the atom name list from the standard model stf = open(stfpf, 'r') for line in stf: if line[0:4] != "LINK": line = line.strip('\n') line = line.split() stlist.append(line[0]) line = line[0].split('-') lresname = line[0] + '-' + line[1] if lresname not in metcenres1: metcenres1.append(lresname) stf.close() llist = [] #get the atom name list from the large model lf = open(lgfpf, 'r') for line in lf: line = line.strip('\n') llist.append(line) lf.close() ldict = {} #get charge of the large model, one-to-one relationship for i in range(0, len(llist)): ldict[llist[i]] = chgs[i] stdict = {} #get the charge of the standard model for i in ldict.keys(): if i in stlist: stdict[i] = ldict[i] #------------------------------------------------------------------------- ####################Checking Models######################### #------------------------------------------------------------------------- print "=========================Checking models==========================" print '***Check the large model...' if len(chgs) != len(llist): raise pymsmtError('Error: the charges and atom numbers are mismatch ' 'for the large model!') else: print 'Good. The charges and atom numbers are match for the ' + \ 'large model.' print 'Good. There are ' + str(len(llist)) + ' atoms in the ' + \ 'large model.' print '***Check the standard model...' if len(stlist) != len(stdict): raise pymsmtError('Error: the charges and atom numbers are mismatch ' 'for the standard model!') else: print 'Good. The charges and atom numbers are match for the ' + \ 'standard model.' print 'Good. There are ' + str(len(stlist)) + ' atoms in the ' + \ 'standard model.' print '***Check the residue names provided...' if len(metcenres1) != len(metcenres2): print 'You gave the residue names: ', str(metcenres2) print 'Database had them: ', str(metcenres1) raise pymsmtError('Error: The number of the residue names given is ' 'mismatch the database!') else: print 'Good. The number of the residue names given matches ' + \ 'the database.' #------------------------------------------------------------------------- ####################Building mol2 files for modeling###################### #------------------------------------------------------------------------- #Load the force field libdict, chargedict = get_lib_dict(ffchoice) for mol2f in mol2fs: libdict1, chargedict1 = get_lib_dict(mol2f) libdict.update(libdict1) chargedict.update(chargedict1) ##get the bondlist mol, atids, resids = get_atominfo_fpdb(stpdbf) #from standard pdb blist = get_mc_blist(mol, atids, ionids, stfpf) blist2 = [(i[0], i[1]) for i in blist] print "=======================Building mol2 files========================" #for each residue, print out the mol2 file for i in range(0, len(resids)): resconter = mol.residues[resids[i]].resconter #atom ids in the residue resname1 = mol.residues[resids[i]].resname #load residue name resname2 = metcenres2[i] #new residue name #Backbone atoms use AMBER backbone atom types #if resname1 in resnamel: # for bbatm in ['N', 'H', 'CA', 'HA','C', 'O']: # key1 = str(resids[i]) + '-' + resname1 + '-' + bbatm # key2 = resname1 + '-' + bbatm # sddict[key1] = libdict[key2][0] #New id dict iddict1 = {} for j in range(0, len(resconter)): iddict1[resconter[j]] = j + 1 #Bond list for each residue with new atom ids blist_each = [] for k in blist2: if set(resconter) & set(k) == set(k): blist_each.append((iddict1[k[0]], iddict1[k[1]])) print_mol2f(resids[i], resname1, resname2, resconter, mol, iddict1, \ sddict, stdict, blist_each)
def gene_pre_frcmod_file(ionids, naamol2f, stpdbf, stfpf, scresf, prefcdf, ffchoice, gaff, frcmodfs, watermodel): print "******************************************************************" print "* *" print "*===================Generate the Initial frcmod file=============*" print "* *" print "******************************************************************" libdict = {} chargedict = {} for mol2f in naamol2f: libdict1, chargedict1 = get_lib_dict(mol2f) libdict.update(libdict1) chargedict.update(chargedict1) #get the parameter dicts Params = get_parm_dict(ffchoice, gaff, frcmodfs) massparms = Params.mass bondparms = Params.bond angparms = Params.ang dihparms = Params.dih impparms = Params.imp nbparms = Params.nb #-------------------------------------------------------------------------- #############Get the metal center information#################### #-------------------------------------------------------------------------- mol, atids, resids = get_atominfo_fpdb(stpdbf) #get the blist blist = get_mc_blist(mol, atids, ionids, stfpf) #get_all_the_lists from standard model all_list = get_all_list(mol, blist, atids, 10.0) #atom type dictionary, key is the atom id, value is atom type attypdict = {} #atom ids which has been transfered to another atom type atidtrans = [] #get the information for the three from finger print fp = open(stfpf, 'r') for line in fp: if line[0:4] != "LINK": atinfo, atid, attyp1st, symbol, attyp2nd = line.split() atid = int(atid) attyp1st = addspace(attyp1st) attyp2nd = addspace(attyp2nd) attypdict[atid] = (attyp1st, attyp2nd) if attyp1st != attyp2nd: atidtrans.append(atid) fp.close() print "Atoms which has changed the atom types:", atidtrans for atid in atidtrans: resid = mol.atoms[atid].resid resname = mol.residues[resid].resname attyp1 = attypdict[atid][0] attyp2 = attypdict[atid][1] print str(resid) + '-' + resname + '@' + str(atid) + '-' + \ mol.atoms[atid].atname + ' : ' + attyp1, '-->', attyp2 #------------------------------------------------------------------------- ########Print the pre-generated frcmod files############## #------------------------------------------------------------------------- fmf = open(prefcdf, 'w') #for atoms which changed atom types print >> fmf, 'REMARK GOES HERE, THIS FILE IS GENERATED BY MCPB.PY' print >> fmf, 'MASS' for atid in atidtrans: if atid not in ionids: #not include metal ion atyp1 = attypdict[atid][0] atyp2 = attypdict[atid][1] print >> fmf, 'YES', atyp2 + massparms[atyp1] #for metal ions for i in ionids: attyp = attypdict[i][1] atname = mol.atoms[i].atname if len(atname) > 1: atname = atname[0] + atname[1:].lower() massi = Mass[atname] print >> fmf, 'YES', attyp + ' ' + str(round(massi, 2)) + \ ' ' + atname + ' ion' #-------------------------------------------------------------------------- bondparamsdict1 = {} #For metal ions bondparamsdict2 = {} #For the others print >> fmf, ' ' print >> fmf, 'BOND' #for bond for bonds in all_list.bondlist: i = bonds[0] j = bonds[1] if list(set(ionids) & set(bonds)) != []: #The bonds which related to the ions bondtyp2 = (attypdict[i][1], attypdict[j][1]) if (bondtyp2 not in bondparamsdict1.keys()) and (bondtyp2[::-1] \ not in bondparamsdict1.keys()): bondparamsdict1[bondtyp2] = ' ' elif list(set(atidtrans) & set(bonds)) != []: #The bonds related to the atoms which changed their atom types bondtyp1 = (attypdict[i][0], attypdict[j][0]) bondtyp2 = (attypdict[i][1], attypdict[j][1]) if (bondtyp2 not in bondparamsdict2.keys()) and (bondtyp2[::-1] \ not in bondparamsdict2.keys()): if bondtyp1 in bondparms.keys(): bondparamsdict2[bondtyp2] = bondparms[bondtyp1] elif bondtyp1[::-1] in bondparms.keys(): bondparamsdict2[bondtyp2] = bondparms[bondtyp1[::-1]] for i in bondparamsdict1.keys(): print >> fmf, 'NON', i[0] + '-' + i[1] + bondparamsdict1[i] for i in bondparamsdict2.keys(): print >> fmf, 'YES', i[0] + '-' + i[1] + bondparamsdict2[i] #-------------------------------------------------------------------------- coparas = [] r_scresf = open(scresf, 'r') for line in r_scresf: line = line.strip('\n') line = line.split('-') resid = int(line[1]) if ('GLY' in line) or ('KCO' in line) or ('ACE' in line): if resid+1 not in resids: coparas.append(resid) r_scresf.close() angparamsdict1 = {} #For metal ions angparamsdict2 = {} #For the others print >> fmf, ' ' print >> fmf, 'ANGL' #for angle for angs in all_list.anglist: i = angs[0] j = angs[1] k = angs[2] if list(set(ionids) & set(angs)) != []: #The angles which related to the ions angtyp2 = (attypdict[i][1], attypdict[j][1], attypdict[k][1]) if (angtyp2 not in angparamsdict1.keys()) and (angtyp2[::-1] \ not in angparamsdict1.keys()): angparamsdict1[angtyp2] = ' ' #print >> fmf, 'NON', attypdict[i][1] + '-' + attypdict[j][1] + \ #'-' + attypdict[k][1] elif list(set(atidtrans) & set(angs)) != []: #The angles related to the atoms #which changed their atom types angtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0]) angtyp2 = (attypdict[i][1], attypdict[j][1], attypdict[k][1]) if (angtyp2 not in angparamsdict2.keys()) and (angtyp2[::-1] \ not in angparamsdict2.keys()): if angtyp1 in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1] elif angtyp1[::-1] in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1[::-1]] #Add for a specific situation for i in coparas: for atid in atidtrans: if mol.atoms[atid].atname == 'O' and mol.atoms[atid].resid == i: angtyp1 = (attypdict[atid][0], 'C ', 'N ') angtyp2 = (attypdict[atid][1], 'C ', 'N ') if (angtyp2 not in angparamsdict2.keys()) and (angtyp2[::-1] \ not in angparamsdict2.keys()): if angtyp1 in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1] elif angtyp1[::-1] in angparms.keys(): angparamsdict2[angtyp2] = angparms[angtyp1[::-1]] for i in angparamsdict1.keys(): print >> fmf, 'NON', i[0] + '-' + i[1] + '-' + i[2] + angparamsdict1[i] for i in angparamsdict2.keys(): print >> fmf, 'YES', i[0] + '-' + i[1] + '-' + i[2] + angparamsdict2[i] #-------------------------------------------------------------------------- dihparamsdict = {} #for dihedral for dihs in all_list.dihlist: i = dihs[0] j = dihs[1] k = dihs[2] l = dihs[3] if list(set(ionids) & set(dihs)) != []: #The dihedral related to the metal ions dihtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) dihtyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) if (dihtyp1 not in dihparamsdict.keys()) and (dihtyp1[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] elif list(set(atidtrans) & set(dihs)) != []: if list(set(atidtrans) & set(dihs[0::3])) == []: #Neither the 1st and 4th atom change atom types #There is 2nd or 3rd or both changed atom type(s) dihtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) dihtyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) dihtyp2 = ('X ', attypdict[j][0], attypdict[k][0], 'X ') dihtyp2n = ('X ', attypdict[j][1], attypdict[k][1], 'X ') if dihtyp1 in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1] elif dihtyp1[::-1] in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1[::-1]] elif dihtyp2 in dihparms.keys(): if (dihtyp2n not in dihparamsdict.keys()) and (dihtyp2n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp2n] = dihparms[dihtyp2] elif dihtyp2[::-1] in dihparms.keys(): if (dihtyp2n not in dihparamsdict.keys()) and (dihtyp2n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp2n] = dihparms[dihtyp2[::-1]] else: if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] else: #There is 1st or 4th atoms or both changed the atom type(s) dihtyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) dihtyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) dihtyp2 = ('X ', attypdict[j][1], attypdict[k][1], 'X ') if dihtyp1 in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1] elif dihtyp1[::-1] in dihparms.keys(): if (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = dihparms[dihtyp1[::-1]] else: if (dihtyp2 in dihparms.keys()) or (dihtyp2[::-1] \ in dihparms.keys()): continue elif (dihtyp1n not in dihparamsdict.keys()) and (dihtyp1n[::-1] \ not in dihparamsdict.keys()): dihparamsdict[dihtyp1n] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] #Add for a specfic situation for i in coparas: for atid in atidtrans: if mol.atoms[atid].atname == 'O' and mol.atoms[atid].resid == i: for ionid in ionids: if ((atid, ionid, 1) in all_list.bondlist) or \ ((ionid, atid, 1) in all_list.bondlist): dihtyp1 = (attypdict[ionid][0], attypdict[atid][0], 'C ', 'N ') dihtyp2 = (attypdict[ionid][1], attypdict[atid][1], 'C ', 'N ') if (dihtyp2 not in dihparamsdict) and (dihtyp2[::-1] not in dihparamsdict): if dihtyp1 in dihparms.keys(): dihparamsdict[dihtyp2] = dihparms[dihtyp1] elif dihtyp1[::-1] in dihparms.keys(): dihparamsdict[dihtyp2] = dihparms[dihtyp1[::-1]] else: dihparamsdict[dihtyp2] = [' 3 0.00 0.0 ', \ ' 3. ', ' '] print >> fmf, ' ' print >> fmf, 'DIHE' for keyv in dihparamsdict.keys(): if 'X ' not in keyv: #For types don't contain X valv = dihparamsdict[keyv] keyv = keyv[0] + '-' + keyv[1] + '-' + keyv[2] + '-' + keyv[3] temp = len(valv)/3 for i in range(0, temp): temp1 = i * 3 print >> fmf, 'YES', keyv, valv[temp1] + valv[temp1+1] + \ valv[temp1+2] for keyv in dihparamsdict.keys(): if 'X ' in keyv: #For types contain X valv = dihparamsdict[keyv] keyv = keyv[0] + '-' + keyv[1] + '-' + keyv[2] + '-' + keyv[3] temp = len(valv)/3 for i in range(0, temp): temp1 = i * 3 print >> fmf, 'YES', keyv, valv[temp1] + valv[temp1+1] + \ valv[temp1+2] #-------------------------------------------------------------------------- impparamsdict = {} #For improper torsion for imps in all_list.implist: i = imps[0] j = imps[1] k = imps[2] l = imps[3] if list(set(ionids) & set(imps)) != []: continue elif list(set(atidtrans) & set(imps)) != []: imptyps = {} #1 situation imptyp1 = (attypdict[i][0], attypdict[j][0], attypdict[k][0], \ attypdict[l][0]) imptyp1n = (attypdict[i][1], attypdict[j][1], attypdict[k][1], \ attypdict[l][1]) #3 situations imptyp2 = ('X ', 'X ', attypdict[k][0], attypdict[i][0]) imptyp2n = ('X ', 'X ', attypdict[k][1], attypdict[i][1]) imptyp3 = ('X ', 'X ', attypdict[k][0], attypdict[j][0]) imptyp3n = ('X ', 'X ', attypdict[k][1], attypdict[j][1]) imptyp4 = ('X ', 'X ', attypdict[k][0], attypdict[l][0]) imptyp4n = ('X ', 'X ', attypdict[k][1], attypdict[l][1]) #6 situations imptyp5 = ('X ', attypdict[i][0], attypdict[k][0], attypdict[j][0]) imptyp5n = ('X ', attypdict[i][1], attypdict[k][1], attypdict[j][1]) imptyp6 = ('X ', attypdict[j][0], attypdict[k][0], attypdict[i][0]) imptyp6n = ('X ', attypdict[j][1], attypdict[k][1], attypdict[i][1]) imptyp7 = ('X ', attypdict[i][0], attypdict[k][0], attypdict[l][0]) imptyp7n = ('X ', attypdict[i][0], attypdict[k][1], attypdict[l][1]) imptyp8 = ('X ', attypdict[l][0], attypdict[k][0], attypdict[i][0]) imptyp8n = ('X ', attypdict[l][1], attypdict[k][1], attypdict[i][1]) imptyp9 = ('X ', attypdict[j][0], attypdict[k][0], attypdict[l][0]) imptyp9n = ('X ', attypdict[j][1], attypdict[k][1], attypdict[l][1]) imptyp10 = ('X ', attypdict[l][0], attypdict[k][0], attypdict[j][0]) imptyp10n = ('X ', attypdict[l][1], attypdict[k][1], attypdict[j][1]) imptyps[imptyp1] = imptyp1n imptyps[imptyp2] = imptyp2n imptyps[imptyp3] = imptyp3n imptyps[imptyp4] = imptyp4n imptyps[imptyp5] = imptyp5n imptyps[imptyp6] = imptyp6n imptyps[imptyp7] = imptyp7n imptyps[imptyp8] = imptyp8n imptyps[imptyp9] = imptyp9n imptyps[imptyp10] = imptyp10n for imptypkey in imptyps.keys(): if imptypkey in impparms.keys(): impparamsdict[imptyps[imptypkey]] = impparms[imptypkey] print >> fmf, ' ' print >> fmf, 'IMPR' #for improper torsion for i in impparamsdict.keys(): if i not in impparms.keys(): imptypkey = i[0] + '-' + i[1] + '-' + i[2] + '-' + i[3] print >> fmf, 'YES', imptypkey, impparamsdict[i] #-------------------------------------------------------------------------- #for nb print >> fmf, ' ' print >> fmf, 'NONB' for atid in atidtrans: #For the others if atid not in ionids: attyp1 = attypdict[atid][0] attyp2 = attypdict[atid][1] print >> fmf, 'YES ', attyp2 + nbparms[attyp1] IonLJParaDict = get_ionljparadict(watermodel) for i in ionids: #For metal ions element = mol.atoms[i].element chg = str(int(chargedict[mol.atoms[i].resname])) attyp2 = attypdict[i][1] rmin = IonLJParaDict[element + chg][0] ep = IonLJParaDict[element + chg][1] annot = IonLJParaDict[element + chg][2] print >> fmf, 'YES %s %11.3f %13.10f %-s' %(attyp2, rmin, \ ep, annot) print >> fmf, ' ' print >> fmf, ' ' fmf.close() #-------------------------------------------------------------------------- #Move the file, delete the repeat parts os.system("mv %s temp" %prefcdf) os.system("uniq temp > %s" %prefcdf) os.system("rm temp")
def gene_resp_input_file(lgpdbf, ionids, stfpf, ffchoice, mol2fs, chgmod, fixchg_resids, lgchg): libdict, chargedict = get_lib_dict(ffchoice) for mol2f in mol2fs: libdict1, chargedict1 = get_lib_dict(mol2f) libdict.update(libdict1) chargedict.update(chargedict1) mol, atids, resids = get_atominfo_fpdb(lgpdbf) reslist = get_reslist(mol, resids) blist = get_mc_blist(mol, atids, ionids, stfpf) bnoatids = [] #Binding backbone N and C Atom IDs mcresids = [] #Metal site residues stfpff = open(stfpf, 'r') for line in stfpff: if line[0:4] != 'LINK': line = line.split() line = line[0].split('-') mcresids.append(int(line[0])) else: line = line.strip('\n') line = line.split() if (line[-1][-1] in ['N3', 'N', 'O', 'OXT']): atid, atom = line[-1].split('-') bnoatids.append(int(atid)) stfpff.close() bnoresids = [] #Binding Backbone N and C Residue IDs, which are not fitted #with backbone restriction in the charge fitting for i in bnoatids: resid = mol.atoms[i].resid if resid not in bnoresids: bnoresids.append(resid) angresids = [] #ACE, NME, GLY residues for i in resids: if i not in mcresids: angresids.append(i) #Get the total charge of the system------------------------------------- totchg = 0.0 for i in resids: resname = mol.residues[i].resname if i in reslist.nterm: reschg = chargedict['N' + resname] elif i in reslist.cterm: reschg = chargedict['C' + resname] else: reschg = chargedict[resname] totchg = totchg + reschg totchg = int(round(totchg, 0)) if lgchg == -99: lgchg = totchg #------------------------------------------------------------------------- ##############RESP1.IN file############################################### #------------------------------------------------------------------------- print "***Generating the 1st stage resp charge fitting input file..." #print the 1st part, the title fresp1 = open('resp1.in', 'w') print >> fresp1, "Resp charges for organic molecule" print >> fresp1, " " print >> fresp1, " &cntrl" print >> fresp1, " " print >> fresp1, " nmol = 1," print >> fresp1, " ihfree = 1," print >> fresp1, " ioutopt = 1," print >> fresp1, " " print >> fresp1, " &end" print >> fresp1, " 1.0" print >> fresp1, "Resp charges for organic molecule" print >> fresp1, "%5d" %lgchg, print >> fresp1, "%4d" %len(atids) #2. print the 2nd part, the free and fozen atoms--------------------------- natids = [i for i in range(1, len(atids)+1)] #new atids iddict = {} #First number in iddict is new atom id, second is atomic number for i in range(0, len(atids)): iddict[atids[i]] = natids[i] for i in atids: element = mol.atoms[i].element elenum = Atnum[element] iddict[i] = (iddict[i], elenum) for i in resids: get_equal_atoms(mol, i, blist, iddict) #other atoms (except the CH2 and CH3 groups) are frozen for i in atids: if (len(iddict[i]) == 2): iddict[i] = (iddict[i][0], iddict[i][1], -99) for i in atids: #if iddict[i][2] == -99: print >> fresp1, "%5d" %iddict[i][1], print >> fresp1, "%4s" %'0' #else: # print >> fresp1, "%5d" %iddict[i][1], # print >> fresp1, "%4s" %iddict[i][2] fresp1.close() add_restriction('resp1.in', libdict, mol, resids, reslist, mcresids, bnoresids, angresids, iddict, chgmod, fixchg_resids) #------------------------------------------------------------------------- ####################RESP2.IN file######################################### #------------------------------------------------------------------------- print "***Generating the 2nd stage resp charge fitting input file..." #1. print the 1st part, the title------------------------------------------ fresp2 = open('resp2.in', 'w') print >> fresp2, "Resp charges for organic molecule" print >> fresp2, " " print >> fresp2, " &cntrl" print >> fresp2, " " print >> fresp2, " nmol = 1," print >> fresp2, " ihfree = 1," print >> fresp2, " ioutopt = 1," print >> fresp2, " iqopt = 2," print >> fresp2, " qwt = 0.001," print >> fresp2, " " print >> fresp2, " &end" print >> fresp2, " 1.0" print >> fresp2, "Resp charges for organic molecule" print >> fresp2, "%5d" %lgchg, print >> fresp2, "%4d" %len(atids) #2. print the 2nd part, the free or frozen information--------------------- for i in atids: print >> fresp2, "%5d" %iddict[i][1], print >> fresp2, "%4s" %iddict[i][2] fresp2.close() add_restriction('resp2.in', libdict, mol, resids, reslist, mcresids, bnoresids, angresids, iddict, chgmod, fixchg_resids)