def get_lib_dict(ff_choice): if ff_choice in list(FF_DICT.keys()): mol, atids, resids = get_atominfo(FF_DICT[ff_choice].mol2f) else: mol, atids, resids = get_atominfo(ff_choice) libdict = {} #resname + atname : atom type, atom charge chargedict = {} #resname : charge for i in resids: charge = 0.0 for j in mol.residues[i].resconter: #key is residue name and atom name key = mol.residues[i].resname + '-' + mol.atoms[j].atname if len(mol.atoms[j].atomtype) == 1: mol.atoms[j].atomtype = mol.atoms[j].atomtype + ' ' #value is atom type and atom charge val = (mol.atoms[j].atomtype, mol.atoms[j].charge) libdict[key] = val #cummulative charge of the residue charge = charge + mol.atoms[j].charge chargedict[mol.residues[i].resname] = charge #Alias HN as H #atnames = [mol.atoms[k].atname for k in mol.residues[i].resconter] #if set(['H', 'N', 'C', 'O']) < set(atnames): # libdict[mol.residues[i].resname + '-HN'] = \ # libdict[mol.residues[i].resname + '-H'] return libdict, chargedict
def get_lib_dict(parms): global add if parms in ['ff94', 'ff99', 'ff99SB']: mol, atids, resids = get_atominfo(add + 'parm94.mol2') elif (parms == 'ff03'): mol, atids, resids = get_atominfo(add + 'parm03.mol2') elif (parms == 'ff03.r1'): mol, atids, resids = get_atominfo(add + 'parm03_r1.mol2') elif (parms == 'ff10'): mol, atids, resids = get_atominfo(add + 'parm10.mol2') elif parms in ['ff12SB', 'ff14SB']: mol, atids, resids = get_atominfo(add + 'parm12.mol2') else: mol, atids, resids = get_atominfo(parms) libdict = {} #resname + atname : atom type, atom charge chargedict = {} #resname : charge for i in resids: charge = 0.0 for j in mol.residues[i].resconter: #key is residue name and atom name key = mol.residues[i].resname + '-' + mol.atoms[j].atname if len(mol.atoms[j].atomtype) == 1: mol.atoms[j].atomtype = mol.atoms[j].atomtype + ' ' #value is atom type and atom charge val = (mol.atoms[j].atomtype, mol.atoms[j].charge) libdict[key] = val #cummulative charge of the residue charge = charge + mol.atoms[j].charge chargedict[mol.residues[i].resname] = charge #Alias HN as H #atnames = [mol.atoms[k].atname for k in mol.residues[i].resconter] #if set(['H', 'N', 'C', 'O']) < set(atnames): # libdict[mol.residues[i].resname + '-HN'] = \ # libdict[mol.residues[i].resname + '-H'] return libdict, chargedict
def gene_leaprc(gname, orpdbf, fipdbf, stpdbf, stfpf, ionids,\ ionmol2fs, ioninf, mcresname, naamol2fs, ff_choice, frcmodfs, finfcdf, ileapf, model, watermodel='tip3p', paraset='cm'): print("******************************************************************") print("* *") print("*=================Generating input file for leap=================*") print("* *") print("******************************************************************") #---------------------Generate the new pdb file-------------------------- #mol0 is the old mol while mol is new mol file with new names mol0, atids0, resids0 = get_atominfo_fpdb(orpdbf) reslist0 = get_reslist(mol0, resids0) mol, atids, resids = get_atominfo_fpdb(orpdbf) #rename the residue names into AMBER style, e.g. HIS --> HID, HIP, HIE mol = rename_res(mol, atids) #get the disulfur bond information disul = get_diS_bond(mol, atids) #resname the old residue names to new ones if it is not metal ion if model in [1, 2]: metcenres1 = [] #Old residue ids fp = open(stfpf, 'r') for line in fp: if line[0:4] != "LINK": line = line.split('-') if int(line[0]) not in metcenres1: metcenres1.append(int(line[0])) fp.close() metcenres2 = mcresname #New residue names resndict = {} resns = [] for i in range(0, len(metcenres1)): resndict[metcenres1[i]] = metcenres2[i] resns.append(metcenres2[i]) for i in resndict.keys(): mol.residues[i].resname = resndict[i] writepdb(mol, atids, fipdbf) #----------------------------get the atom names which changed atom type if model in [1, 2]: atomdefs = {} fp0 = open(stfpf, 'r') for line in fp0: if line[0:4] != "LINK": line = line.strip('\n') line = line.split() if line[2] != line[4]: atnewtype = line[4] element = mol.atoms[int(line[1])].element if atnewtype not in atomdefs.keys(): atomdefs[atnewtype] = element else: if element != atomdefs[atnewtype]: raise pymsmtError('There are atoms in fingerprint file ' 'of standard model with same atom type ' 'but different element.') fp0.close() #---------------------Get the bond information, mol2 is the standard model if model == 1: mol2, atids2, resids2 = get_atominfo_fpdb(stpdbf) blist = get_mc_blist(mol2, atids2, ionids, stfpf) blist1 = [(i[0], i[1]) for i in blist] #----------------------Generate the lib file and get the frcmod file name if model == 2: frcmodfs = [] for ionmol2f in ionmol2fs: ionmol, ionatids, ionresids = get_atominfo(ionmol2f) for i in ionatids: element = ionmol.atoms[i].element chg = int(ionmol.atoms[i].charge) frcmodf = get_frcmod_fname(element, chg, watermodel, paraset) if frcmodf not in frcmodfs: frcmodfs.append(frcmodf) elif model == 3 and ioninf != []: #get the metal information metresns = ioninf[0::4] metatns = ioninf[1::4] metelmts = ioninf[2::4] metelmts = [i[0] + i[1:].lower() for i in metelmts] metchgs = ioninf[3::4] metchgs = [int(i) for i in metchgs] #check the charge of the metal ions for metchg in metchgs: if metchg < -1 or metchg > 4: raise pymsmtError('Could not deal with atomic ion which has charge ' 'less than -1 or bigger than +4.') frcmodfs = [] for i in range(0, len(metresns)): if metchgs[i] > 1: #if it is -1 or +1 ions, no need to create the lib file gene_ion_libfile(metresns[i], metatns[i], metelmts[i], metchgs[i]) frcmodf = get_frcmod_fname(metelmts[i], metchgs[i], watermodel, paraset) if frcmodf not in frcmodfs: frcmodfs.append(frcmodf) #-----------------------Generate the leap input file----------------------- print('Generating the leap input file...') ##Generate the tleap.in file lp = open(ileapf, 'w') if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff10']: print('source oldff/leaprc.%s' %ff_choice, file=lp) elif ff_choice in ['ff03.r1', 'ff12SB', 'ff14SB']: print('source leaprc.%s' %ff_choice, file=lp) print('source leaprc.gaff', file=lp) #Add atom types, for bonded model if model in [1, 2]: if atomdefs.keys() != []: print('addAtomTypes {', file=lp) for i in sorted(list(atomdefs.keys())): print(' { "%s" "%s" "sp3" }' %(i, atomdefs[i]), file=lp) print('}', file=lp) #load lib and frcmod files for monovalent ions (for salt) if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff03.r1']: print('loadoff atomic_ions.lib', file=lp) print('loadamberparams frcmod.ions1lsm_hfe_%s' %watermodel, file=lp) #Load mol2 file for the refitting charge residues if model in [1, 2]: for i in resns: print('%s = loadmol2 %s.mol2' %(i, i), file=lp) elif model == 3: for i in naamol2fs: print('%s = loadmol2 %s.mol2' %(i, i), file=lp) #Load frcmod files for non-standard residues and metal site for i in frcmodfs: print('loadamberparams %s' %i, file=lp) if model == 1: print('loadamberparams %s' %finfcdf, file=lp) elif model == 2: for frcmodf in frcmodfs: print('loadamberparams %s' %frcmodf, file=lp) elif model == 3: for metresn in metresns: print('loadoff %s.lib' %metresn, file=lp) for frcmodf in frcmodfs: print('loadamberparams %s' %frcmodf, file=lp) #load pdb file print('mol = loadpdb %s' %fipdbf, file=lp) ##The Disulfur Bond information if disul != []: for i in disul: at1 = i[0] at2 = i[1] resid1 = mol.atoms[at1].resid resid2 = mol.atoms[at2].resid atname1 = mol.atoms[at1].atname atname2 = mol.atoms[at2].atname print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2, file=lp) ##Bond including the metal ions if model == 1: for bond in blist1: if list(set(bond) & set(ionids)) != []: at1 = bond[0] at2 = bond[1] resid1 = mol.atoms[at1].resid resid2 = mol.atoms[at2].resid atname1 = mol.atoms[at1].atname atname2 = mol.atoms[at2].atname print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2, file=lp) ##Nonstandard residues with nearby residues if model in [1, 2]: bondcmds = [] for i in metcenres1: resname = mol0.residues[i].resname print('Renamed residues includes: ' + str(i) + '-' + resname) if i in reslist0.nterm: cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i+i) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) elif i in reslist0.cterm: cmdi = 'bond mol.' + str(i-1) + '.C' + ' mol.' + str(i) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) elif i in reslist0.std: cmdi = 'bond mol.' + str(i-1) + '.C' + ' mol.' + str(i) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i+1) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) for j in bondcmds: print(j, file=lp) #Save dry structure print('savepdb mol %s_dry.pdb' %gname, file=lp) print('saveamberparm mol %s_dry.prmtop %s_dry.inpcrd' \ %(gname, gname), file=lp) #Solvatebox if watermodel == 'tip3p': print('solvatebox mol TIP3PBOX 10.0', file=lp) elif watermodel == 'spce': print('solvatebox mol SPCBOX 10.0', file=lp) print('loadamberparams frcmod.spce', file=lp) elif watermodel == 'tip4pew': print('solvatebox mol TIP4PEWBOX 10.0', file=lp) print('loadamberparams frcmod.tip4pew', file=lp) #Add counter ions print('addions mol Na+ 0', file=lp) print('addions mol Cl- 0', file=lp) #Save solvated structure print('savepdb mol %s_solv.pdb' %gname, file=lp) print('saveamberparm mol %s_solv.prmtop %s_solv.inpcrd' \ %(gname, gname), file=lp) print('quit', file=lp) print(' ', file=lp) lp.close() print('Finish generating the leap input file.')
def gene_leaprc(gname, orpdbf, fipdbf, stpdbf, stfpf, ionids,\ ionmol2fs, ioninf, mcresname, naamol2fs, ff_choice, frcmodfs, finfcdf, ileapf, model, watermodel='tip3p', paraset='cm'): print("******************************************************************") print("* *") print("*=================Generating input file for leap=================*") print("* *") print("******************************************************************") #---------------------Generate the new pdb file-------------------------- #mol0 is the old mol while mol is new mol file with new names mol0, atids0, resids0 = get_atominfo_fpdb(orpdbf) reslist0 = get_reslist(mol0, resids0) mol, atids, resids = get_atominfo_fpdb(orpdbf) #rename the residue names into AMBER style, e.g. HIS --> HID, HIP, HIE mol = rename_res(mol, atids) #get the disulfur bond information disul = get_diS_bond(mol, atids) #resname the old residue names to new ones if it is not metal ion if model in [1, 2]: metcenres1 = [] #Old residue ids fp = open(stfpf, 'r') for line in fp: if line[0:4] != "LINK": line = line.split('-') if int(line[0]) not in metcenres1: metcenres1.append(int(line[0])) fp.close() metcenres2 = mcresname #New residue names resndict = {} resns = [] for i in range(0, len(metcenres1)): resndict[metcenres1[i]] = metcenres2[i] resns.append(metcenres2[i]) for i in resndict.keys(): mol.residues[i].resname = resndict[i] writepdb(mol, atids, fipdbf) #----------------------------get the atom names which changed atom type if model in [1, 2]: atomdefs = {} fp0 = open(stfpf, 'r') for line in fp0: if line[0:4] != "LINK": line = line.strip('\n') line = line.split() if line[2] != line[4]: atnewtype = line[4] element = mol.atoms[int(line[1])].element if atnewtype not in atomdefs.keys(): atomdefs[atnewtype] = element else: if element != atomdefs[atnewtype]: raise pymsmtError( 'There are atoms in fingerprint file ' 'of standard model with same atom type ' 'but different element.') fp0.close() #---------------------Get the bond information, mol2 is the standard model if model == 1: mol2, atids2, resids2 = get_atominfo_fpdb(stpdbf) blist = get_mc_blist(mol2, atids2, ionids, stfpf) blist1 = [(i[0], i[1]) for i in blist] #----------------------Generate the lib file and get the frcmod file name if model == 2: frcmodfs = [] for ionmol2f in ionmol2fs: ionmol, ionatids, ionresids = get_atominfo(ionmol2f) for i in ionatids: element = ionmol.atoms[i].element chg = int(ionmol.atoms[i].charge) frcmodf = get_frcmod_fname(element, chg, watermodel, paraset) if frcmodf not in frcmodfs: frcmodfs.append(frcmodf) elif model == 3 and ioninf != []: #get the metal information metresns = ioninf[0::4] metatns = ioninf[1::4] metelmts = ioninf[2::4] metelmts = [i[0] + i[1:].lower() for i in metelmts] metchgs = ioninf[3::4] metchgs = [int(i) for i in metchgs] #check the charge of the metal ions for metchg in metchgs: if metchg < -1 or metchg > 4: raise pymsmtError( 'Could not deal with atomic ion which has charge ' 'less than -1 or bigger than +4.') frcmodfs = [] for i in range(0, len(metresns)): if metchgs[ i] > 1: #if it is -1 or +1 ions, no need to create the lib file gene_ion_libfile(metresns[i], metatns[i], metelmts[i], metchgs[i]) frcmodf = get_frcmod_fname(metelmts[i], metchgs[i], watermodel, paraset) if frcmodf not in frcmodfs: frcmodfs.append(frcmodf) #-----------------------Generate the leap input file----------------------- print('Generating the leap input file...') ##Generate the tleap.in file lp = open(ileapf, 'w') if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff10']: print('source oldff/leaprc.%s' % ff_choice, file=lp) elif ff_choice in ['ff03.r1', 'ff12SB', 'ff14SB']: print('source leaprc.%s' % ff_choice, file=lp) print('source leaprc.gaff', file=lp) #Add atom types, for bonded model if model in [1, 2]: if atomdefs.keys() != []: print('addAtomTypes {', file=lp) for i in sorted(list(atomdefs.keys())): print(' { "%s" "%s" "sp3" }' % (i, atomdefs[i]), file=lp) print('}', file=lp) #load lib and frcmod files for monovalent ions (for salt) if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff03.r1']: print('loadoff atomic_ions.lib', file=lp) print('loadamberparams frcmod.ions1lsm_hfe_%s' % watermodel, file=lp) #Load mol2 file for the refitting charge residues if model in [1, 2]: for i in resns: print('%s = loadmol2 %s.mol2' % (i, i), file=lp) elif model == 3: for i in naamol2fs: print('%s = loadmol2 %s.mol2' % (i, i), file=lp) #Load frcmod files for non-standard residues and metal site for i in frcmodfs: print('loadamberparams %s' % i, file=lp) if model == 1: print('loadamberparams %s' % finfcdf, file=lp) elif model == 2: for frcmodf in frcmodfs: print('loadamberparams %s' % frcmodf, file=lp) elif model == 3: for metresn in metresns: print('loadoff %s.lib' % metresn, file=lp) for frcmodf in frcmodfs: print('loadamberparams %s' % frcmodf, file=lp) #load pdb file print('mol = loadpdb %s' % fipdbf, file=lp) ##The Disulfur Bond information if disul != []: for i in disul: at1 = i[0] at2 = i[1] resid1 = mol.atoms[at1].resid resid2 = mol.atoms[at2].resid atname1 = mol.atoms[at1].atname atname2 = mol.atoms[at2].atname print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2, file=lp) ##Bond including the metal ions if model == 1: for bond in blist1: if list(set(bond) & set(ionids)) != []: at1 = bond[0] at2 = bond[1] resid1 = mol.atoms[at1].resid resid2 = mol.atoms[at2].resid atname1 = mol.atoms[at1].atname atname2 = mol.atoms[at2].atname print('bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2, file=lp) ##Nonstandard residues with nearby residues if model in [1, 2]: bondcmds = [] for i in metcenres1: resname = mol0.residues[i].resname print('Renamed residues includes: ' + str(i) + '-' + resname) if i in reslist0.nterm: cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i + i) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) elif i in reslist0.cterm: cmdi = 'bond mol.' + str(i - 1) + '.C' + ' mol.' + str(i) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) elif i in reslist0.std: cmdi = 'bond mol.' + str(i - 1) + '.C' + ' mol.' + str(i) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) cmdi = 'bond mol.' + str(i) + '.C' + ' mol.' + str(i + 1) + '.N' if cmdi not in bondcmds: bondcmds.append(cmdi) for j in bondcmds: print(j, file=lp) #Save dry structure print('savepdb mol %s_dry.pdb' % gname, file=lp) print('saveamberparm mol %s_dry.prmtop %s_dry.inpcrd' \ %(gname, gname), file=lp) #Solvatebox if watermodel == 'tip3p': print('solvatebox mol TIP3PBOX 10.0', file=lp) elif watermodel == 'spce': print('solvatebox mol SPCBOX 10.0', file=lp) print('loadamberparams frcmod.spce', file=lp) elif watermodel == 'tip4pew': print('solvatebox mol TIP4PEWBOX 10.0', file=lp) print('loadamberparams frcmod.tip4pew', file=lp) #Add counter ions print('addions mol Na+ 0', file=lp) print('addions mol Cl- 0', file=lp) #Save solvated structure print('savepdb mol %s_solv.pdb' % gname, file=lp) print('saveamberparm mol %s_solv.prmtop %s_solv.inpcrd' \ %(gname, gname), file=lp) print('quit', file=lp) print(' ', file=lp) lp.close() print('Finish generating the leap input file.')