def get_lib_dict(parms): amberhome = os.getenv('AMBERHOME') add = amberhome + '/AmberTools/src/pymsmt/pymsmtlib/' 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 >> lp, 'source oldff/leaprc.%s' %ff_choice elif ff_choice in ['ff03.r1', 'ff12SB', 'ff14SB']: print >> lp, 'source leaprc.%s' %ff_choice print >> lp, 'source leaprc.gaff' #Add atom types, for bonded model if model in [1, 2]: if atomdefs.keys() != []: print >> lp, 'addAtomTypes {' for i in atomdefs.keys(): print >> lp, ' { "%s" "%s" "sp3" }' %(i, atomdefs[i]) print >> lp, '}' #load lib and frcmod files for monovalent ions (for salt) if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff03.r1']: print >> lp, 'loadoff atomic_ions.lib' print >> lp, 'loadamberparams frcmod.ions1lsm_hfe_%s' %watermodel #Load mol2 file for the refitting charge residues if model in [1, 2]: for i in resns: print >> lp, '%s = loadmol2 %s.mol2' %(i, i) elif model == 3: for i in naamol2fs: print >> lp, '%s = loadmol2 %s.mol2' %(i, i) #Load frcmod files for non-standard residues and metal site for i in frcmodfs: print >> lp, 'loadamberparams %s' %i if model == 1: print >> lp, 'loadamberparams %s' %finfcdf elif model == 2: for frcmodf in frcmodfs: print >> lp, 'loadamberparams %s' %frcmodf elif model == 3: for metresn in metresns: print >> lp, 'loadoff %s.lib' %metresn for frcmodf in frcmodfs: print >> lp, 'loadamberparams %s' %frcmodf #load pdb file print >> lp, 'mol = loadpdb %s' %fipdbf ##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 >> lp, 'bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2 ##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 >> lp, 'bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2 ##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 >> lp, j #Save dry structure print >> lp, 'savepdb mol %s_dry.pdb' %gname print >> lp, 'saveamberparm mol %s_dry.prmtop %s_dry.inpcrd' \ %(gname, gname) #Solvatebox if watermodel == 'tip3p': print >> lp, 'solvatebox mol TIP3PBOX 10.0' elif watermodel == 'spce': print >> lp, 'solvatebox mol SPCBOX 10.0' print >> lp, 'loadamberparams frcmod.spce' elif watermodel == 'tip4pew': print >> lp, 'solvatebox mol TIP4PEWBOX 10.0' print >> lp, 'loadamberparams frcmod.tip4pew' #Add counter ions print >> lp, 'addions mol Na+ 0' print >> lp, 'addions mol Cl- 0' #Save solvated structure print >> lp, 'savepdb mol %s_solv.pdb' %gname print >> lp, 'saveamberparm mol %s_solv.prmtop %s_solv.inpcrd' \ %(gname, gname) print >> lp, 'quit' print >> 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 >> lp, 'source oldff/leaprc.%s' % ff_choice elif ff_choice in ['ff03.r1', 'ff12SB', 'ff14SB']: print >> lp, 'source leaprc.%s' % ff_choice print >> lp, 'source leaprc.gaff' #Add atom types, for bonded model if model in [1, 2]: if atomdefs.keys() != []: print >> lp, 'addAtomTypes {' for i in atomdefs.keys(): print >> lp, ' { "%s" "%s" "sp3" }' % (i, atomdefs[i]) print >> lp, '}' #load lib and frcmod files for monovalent ions (for salt) if ff_choice in ['ff94', 'ff99', 'ff99SB', 'ff03', 'ff03.r1']: print >> lp, 'loadoff atomic_ions.lib' print >> lp, 'loadamberparams frcmod.ions1lsm_hfe_%s' % watermodel #Load mol2 file for the refitting charge residues if model in [1, 2]: for i in resns: print >> lp, '%s = loadmol2 %s.mol2' % (i, i) elif model == 3: for i in naamol2fs: print >> lp, '%s = loadmol2 %s.mol2' % (i, i) #Load frcmod files for non-standard residues and metal site for i in frcmodfs: print >> lp, 'loadamberparams %s' % i if model == 1: print >> lp, 'loadamberparams %s' % finfcdf elif model == 2: for frcmodf in frcmodfs: print >> lp, 'loadamberparams %s' % frcmodf elif model == 3: for metresn in metresns: print >> lp, 'loadoff %s.lib' % metresn for frcmodf in frcmodfs: print >> lp, 'loadamberparams %s' % frcmodf #load pdb file print >> lp, 'mol = loadpdb %s' % fipdbf ##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 >> lp, 'bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2 ##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 >> lp, 'bond', 'mol.' + str(resid1) + '.' + atname1, 'mol.' + \ str(resid2) + '.' + atname2 ##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 >> lp, j #Save dry structure print >> lp, 'savepdb mol %s_dry.pdb' % gname print >> lp, 'saveamberparm mol %s_dry.prmtop %s_dry.inpcrd' \ %(gname, gname) #Solvatebox if watermodel == 'tip3p': print >> lp, 'solvatebox mol TIP3PBOX 10.0' elif watermodel == 'spce': print >> lp, 'solvatebox mol SPCBOX 10.0' print >> lp, 'loadamberparams frcmod.spce' elif watermodel == 'tip4pew': print >> lp, 'solvatebox mol TIP4PEWBOX 10.0' print >> lp, 'loadamberparams frcmod.tip4pew' #Add counter ions print >> lp, 'addions mol Na+ 0' print >> lp, 'addions mol Cl- 0' #Save solvated structure print >> lp, 'savepdb mol %s_solv.pdb' % gname print >> lp, 'saveamberparm mol %s_solv.prmtop %s_solv.inpcrd' \ %(gname, gname) print >> lp, 'quit' print >> lp, ' ' lp.close() print 'Finish generating the leap input file.'