import fpdb pdb = fpdb.fPDB('waterDimer.pdb') residues = pdb.topology.residues minDist = 10e8 keeper = None for i, resi in enumerate(residues): for resj in residues[:i]: for atomi in resi.atoms: for atomj in resj.atoms: d_2 = fpdb.dist_2(atomi, atomj) if d_2 < minDist: minDist = d_2 keeper = (resi, atomi, resj, atomj) resi, atomi, resj, atomj = keeper print(("\nmin distance atom pair are atom %s%d:%s%d and %s%d:%s%d\n" % ( resi.name, resi.index, atomi.name, atomi.index, resj.name, resj.index, atomj.name, atomj.index, )))
#!/usr/bin/env python import sys,os import fpdb after = 'shift_in_box.pdb' init = 'tleap_out.pdb' lig = 'lig.pdb' pdb1 = fpdb.fPDB(init) pdb2 = fpdb.fPDB(after) coord1 = pdb1.topology.residues[0].atoms[0].posi coord2 = pdb2.topology.residues[0].atoms[0].posi print coord1 print coord2 dx = coord2[0] - coord1[0] dy = coord2[1] - coord1[1] dz = coord2[2] - coord1[2] with open('lig_shift.pdb','w') as ofp: for line in open(lig): if len(line) >= 6 and line[:6] in ("ATOM ","HETATM"): x = float(line[30:38]) y = float(line[38:46]) z = float(line[46:54]) nx = x + dx ny = y + dy nz = z + dz newline = "%s%8.3f%8.3f%8.3f%s"%(line[:30],nx,ny,nz,line[54:]) else:
def prepare_md(dirpath, output=sys.stdout): dirpath = "%s/%s" % ("/home/fuqy/work/SPA_database/www/submit_jobs", dirpath) assert os.path.isdir(dirpath) assert os.path.isfile("%s/rec.pdb" % dirpath) assert os.path.isfile("%s/lig.pdb" % dirpath) os.chdir(dirpath) if True: ## receptor # assert(1==0) # load receptor rec = fpdb.fPDB("%s/rec.pdb" % dirpath) # fix his name if os.path.isfile("%s/his.list" % dirpath): # if his.list exist # load his.list histype = dict() for line in open("%s/his.list" % dirpath): histype[int(line.split()[0])] = line.split()[1] for resi in rec.topology.residues: if resi.index in list(histype.keys()): resi.name = histype[resi.index] else: # else for resi in rec.topology.residues: if resi.name in ("HIS", "HID", "HIP", "HIE"): #use HID by default resi.name = "HID" for resi in rec.topology.residues: if resi.name in ("CYS", "CYZ"): #use HID by default resi.name = "CYX" print(">>>>> OUTPUT of fSPA.prepare_md(): ") rec.write_pdb("ftmp.pdb") cgi_system("addter.py ftmp.pdb ftmp_ter.pdb", output) #cgi_system("addter.py ftmp.pdb ftmp_ter.pdb").read() with open("leap.in", 'w') as ofp: ofp.write(""" source leaprc.ff14SB rec = loadpdb ftmp_ter.pdb savepdb rec tleap_out.pdb quit """) cgi_system("tleap -f leap.in", output) cgi_system("sed -i s/CYX/CYS/g tleap_out.pdb", output) cgi_system("atomtypeconvert.py a2g tleap_out.pdb tleap_out_trans.pdb", output) # cgi_system("gmx pdb2gmx -f tleap_out_trans.pdb -o rec.gro -merge all -water tip3p -ff amber99sb",output) # add box # cgi_system("gmx editconf -f rec.gro -o box.gro -d 1.0",output) ## ligand if False: # fix atom coordinate, nothing to do # compute shift line_o = open('rec.gro').readlines()[2] line_f = open('box.gro').readlines()[2] xo = float(line_o[20:28]) * 10 yo = float(line_o[28:36]) * 10 zo = float(line_o[36:44]) * 10 xf = float(line_f[20:28]) * 10 yf = float(line_f[28:36]) * 10 zf = float(line_f[36:44]) * 10 xs, ys, zs = xf - xo, yf - yo, zf - zo # adjust ligand coordinate with open("lig_shift.pdb", 'w') as ofp: for line in open("lig.pdb"): if len(line) >= 6 and line[:6] in ("ATOM ", "HETATM"): x = float(line[30:38]) + xs y = float(line[38:46]) + ys z = float(line[46:54]) + zs ofp.write("%s%8.3f%8.3f%8.3f%s" % (line[:30], x, y, z, line[54:])) else: ofp.write(line) ## cp mdp files # cgi_system("cp -r %s/mdp ./"%fpdb.__path__[0][:-4],output) ## minimize receptor # cgi_system("gmx grompp -f mdp/em.mdp -o em.tpr -c box.gro -p topol.top -maxwarn 10",output) # cgi_system("gmx mdrun -deffnm em",output) ## add solvent # cgi_system("gmx solvate -cp em.gro -cs spc216 -o sys.gro -p topol.top",output) ## minimize solvent # cgi_system("gmx grompp -f mdp/em.mdp -o em_sys.tpr -c sys.gro -p topol.top -r box.gro -maxwarn 10",output) #cgi_system("gmx mdrun -deffnm em_sys",output) ## check rmsd ## if too large of some atoms, warning ## generate sge files ## return to cgi, wait for submit return 0
#!/usr/bin/python import fpdb import sys, os traj = 'prod/traj.pdb' os.system("shift_lig.py") frame = next(fpdb.next_frame(traj)) with open("prod/a1.pdb", 'w') as ofp: for line in frame: ofp.write(line) with open("prod/rec.pdb", 'w') as ofp: for resi in fpdb.fPDB(frame).topology.get_protein_residues(): resi.write_pdb(ofp) n = 0 with open("runspa.bash", 'w') as ofp: ofp.write("#!/bin/bash\n") ofp.write("source ~/.bashrc\n") while True: if os.path.isdir("spa_%d" % n): os.system("cp prod/a1.pdb spa_%d" % n) os.system("cp prod/rec.pdb spa_%d" % n) os.system("cp lig_shift.pdb spa_%d/a1_lig.pdb" % n) os.system("cp %s/para/SPA.amoeba.para spa_%d/SPA.para" % (os.environ['SPAHOME'], n)) ofp.write("cd spa_%d\n" % n) ofp.write("%s/bin/SPA_main SPA.para\n" % os.environ['SPAHOME'])
## pbsa if True: origin_lig = '%s.acpype/%s_GMX.pdb'%(ligname,ligname) origin_rec = 'rec.gro' box = 'box.gro' ## lig.pdb origin_line = open(origin_rec).readlines()[2] box_line = open(box).readlines()[2] ox = float(origin_line[20:28]) oy = float(origin_line[28:36]) oz = float(origin_line[36:44]) bx = float(box_line[20:28]) by = float(box_line[28:36]) bz = float(box_line[36:44]) lig_o = fpdb.fPDB(origin_lig).topology.residues[0] for atom in lig_o.atoms: x,y,z = atom.posi[:3] x += 10*(bx-ox) y += 10*(by-oy) z += 10*(bz-oz) atom.posi = (x,y,z) lig_o.write_pdb(open('lig.pdb','w')) ## restr_rec.itp with open("pbsa.restr.itp",'w') as ofp: ofp.write("[ position_restraints ]\n") ofp.write("; atom type fx fy fz \n") pdb = fpdb.fPDB("com.pdb") for resi in pdb.topology.residues:
#!/usr/bin/python import sys,os import fpdb ligfile = sys.argv[1] flexfile = sys.argv[2] recfile = sys.argv[3] outfile = sys.argv[4] # load residues flex_resi = dict() for resi in fpdb.fPDB(flexfile).topology.residues: flex_resi[resi.index] = resi rec_resi = fpdb.fPDB(recfile).topology.residues lig_resi = fpdb.fPDB(ligfile).topology.residues[0] # forge flex resides, add "N", "HN", "C", "O" for template_resi in rec_resi: index = template_resi.index if flex_resi.has_key(index): target_resi = flex_resi[index] for atom in template_resi.atoms: if target_resi.atoms_d.has_key(atom.name): atom.posi = target_resi.atoms_d[atom.name].posi # output residues ofp = open(outfile,'w') for resi in rec_resi: resi.write_pdb(ofp)
default=(0, 0, 0)) parser.add_argument('-box', nargs=3, help='Box size', type=float, default=(0, 0, 0)) args = parser.parse_args() infile = args.i outfile = args.o box = args.box center = args.center print ">>>>> Centering traj.." n = 0 center_coord = None pdb = fpdb.fPDB(infile) if center == (0, 0, 0): center_coord = pdb.find_protein_center() else: center_coord = center print "----- Center Coordination :", center_coord n = 0 ofp = open(outfile, 'w') pdb = fpdb.fPDB(infile) pdb.center(center_posi=center_coord, box=box) pdb.write_pdb(ofp) print "----- All done."
#!/usr/bin/python import sys, os import fpdb import gmx_top nonbonded = 'amber99sb.ffnonbonded.itp' rtp = 'amber99sb.aminoacids.rtp' waterfile = 'tip3p.itp' gmxtop = gmx_top.gmxtop(nonbonded, rtp, waterfile) pdb = fpdb.fPDB(sys.argv[1]) r1 = fpdb.topology.residues[0] r2 = fpdb.topology.residues[1] atom1 = r1.atoms['CA'] vs = cs = 0 for atom2 in r2.atoms: v, c = fpdb.potential_atom_atom(atom1, atom2) vs += v cs += c vdw, chg = fpdb.potential_resi(r1, r2) vdw, chg = fpdb.potential_atom_atom(atom1, atom2) print(">>>>> vDW:", vdw) print(">>>>> Charge:", chg)
import fpdb infile = sys.argv[1] a1_file = 'a1.pdb' lig_file = 'a1_lig.pdb' rec_file = 'rec.pdb' para_source = '/home/fuqiuyu/work/nmr_druggability/md/finished/1dhm/spa/SPA.para' para_file = 'SPA.para' print ">>>>> preparing SPA input files" for model in fpdb.next_frame(infile): pdb = fpdb.fPDB(model) pdb.write_pdb(a1_file) print "----- sys pdb done." ofp_rec = open(rec_file, 'w') for residue in pdb.topology.residues: if residue.name in fpdb.standard_protein_residues: residue.write_pdb(ofp_rec) print "----- rec pdb done." ofp_lig = open(lig_file, 'w') for line in open(rec_file): if len(line) >= 6 and line[:6] in ('ATOM ', 'HETATM'): if line[12:16].strip() not in ('C', 'O', 'N', 'CA'): if line[13] != 'H': ofp_lig.write(line)
import fpdb import sys, os dir1 = 'part1' dir2 = 'part2' dirs = sys.argv[1:-1] outfile = sys.argv[-1] graphics = list() for DIR in dirs: graphics.append('%s/%s' % (DIR, 'graphic.pdb')) pdbs = list() for graphic in graphics: pdbs.append(fpdb.fPDB(graphic)) waters = list() for pdb in pdbs: waters.append(pdb.topology.get_water_residues()) all_waters = list() for tmp in waters: all_waters.extend(tmp) cutoff = 1.0 nr_waters = list() for test_water in all_waters: dist = 9999 neighbor_water = None for water in nr_waters: