def main(): if len(sys.argv) != 3: # if no input print "This function takes as input two pdb files" print "calculates distances and writes out a report" print len(sys.argv) return pdb_file1 = sys.argv[1] pdb_file2 = sys.argv[2] #pdb_out = sys.argv[3] print "center of voxal, file 1: " + pdb_file1 print "list of waters, file 2: " + pdb_file2 pdb1 = pdb_lib.read_pdb(pdb_file1) pdb2 = pdb_lib.read_pdb(pdb_file2) atomcount = [] # count how meny atoms are in each voxel # intialize for i in range(len(pdb1)): atomcount.append(0) i = 0 for voxelatom in pdb1: for atom in pdb2: #print atom.atomname if atom.atomname.replace(" ","") != "O": continue if (in_voxel(voxelatom,atom,0.25)): atomcount[i] = atomcount[i] + 1 i = i + 1 for i in range(len(pdb1)): print "voxel%d, %d"%(i, atomcount[i]) print len(pdb2)/3
def readin_all_atoms_center_of_mass(fileinputpdb): pdblist = pdb.read_pdb(fileinputpdb) atoms =[] for pdbatoms in pdblist: for atom in pdbatoms: atoms.append(atom) return centre_of_mass(atoms)
def main(): if (len(sys.argv) != 4): # if no input print " (1) pdb file name," print " (1) crd file name," print " (2) output file " return pdbfilename = sys.argv[1] crdfilename = sys.argv[2] output = sys.argv[3] #cl = pdb_lib.read_pdb(pdb_file) pdb = pdb_lib.read_pdb(pdbfilename)[0] size = len(pdb) frames = coord_reader(crdfilename, size) j = 0 for f in frames: i = 0 for c in f.cords: print "j=", j, "i=", i pdb[i].X = c.x pdb[i].Y = c.y pdb[i].Z = c.z i = i + 1 pdb_lib.output_pdb(pdb, output + "." + str(j) + ".pdb") j = j + 1 return
def readin_all_atoms_return_chains(fileinputpdb): pdblist = pdb.read_pdb(fileinputpdb) if (len(pdblist) > 1): print("len(pdblist) = %d" % len(pdblist)) #print(pdblist[0]) print("pdblist is greater than 1. there is more than one model...") pdblist_combined = [] for atoms in pdblist: print(len(atoms)) for atom in atoms: pdblist_combined.append(atom) # exit() atoms_list = [] chains = [] chains_dict = {} #current_chain = pdblist_combined[0].chainid for atom in pdblist_combined: #for atom in pdbatoms: if not (atom.chainid in chains_dict): chains_dict[atom.chainid] = [] chains_dict[atom.chainid].append(atom) for key in chains_dict: chains.append(chains_dict[key]) return chains
def main(): if (len(sys.argv) != 4): # if no input print(" (1) pdb file name,") print(" (1) crd file name,") print(" (2) output file ") return pdbfilename = sys.argv[1] crdfilename = sys.argv[2] output = sys.argv[3] #cl = pdb_lib.read_pdb(pdb_file) pdb = pdb_lib.read_pdb(pdbfilename)[0] size = len(pdb) j = 0 crds = [] for i in range(size): #print( "j=",j,"i=",i x = pdb[i].X y = pdb[i].Y z = pdb[i].Z crd = cord(x, y, z) crds.append(crd) mdcrd_writer(crdfilename, crds, "from " + pdbfilename) return
def main(): if len(sys.argv) != 3: # if no input print "This function takes as input two pdb files" print "read in the xtal waters (pdb1) and the water positions predicted by GIST (pdb2)." print len(sys.argv) return pdb_file1 = sys.argv[1] pdb_file2 = sys.argv[2] #pdb_out = sys.argv[3] print "file 1: " + pdb_file1 print "file 2: " + pdb_file2 pdb1 = pdb.read_pdb(pdb_file1) pdb2 = pdb.read_pdb(pdb_file2) pdb.cal_dists_TP_FP_FN(pdb1, pdb2)
def main(): if len(sys.argv) != 4: # if no input print "This function takes as input two pdb files" print "read in the low dielectric spheres (pdb1) and the water positions (pdb2)." print "calculates distances and writes out a the overlaping atoms from the second file (water positions)" print len(sys.argv) return pdb_file1 = sys.argv[1] pdb_file2 = sys.argv[2] pdb_out = sys.argv[3] print "file 1: " + pdb_file1 print "file 2: " + pdb_file2 pdb1 = pdb.read_pdb(pdb_file1) pdb2 = pdb.read_pdb(pdb_file2) pdb2_close = pdb.cal_dists_close(pdb1, pdb2) pdb.output_pdb(pdb2_close, pdb_out)
def main(): if len(sys.argv) != 5: # if no input print "ERORR: there need to be 4 inputs: pdb inputfilename, bfactorfilename(2 colomn:resname,value) residuelist, outputfileprefix." return fileinputpdb = sys.argv[1] filebfactor = sys.argv[2] res_string = sys.argv[3] fileoutput = sys.argv[4] splitname = fileinputpdb.split('/')[-1].split('.') if len(splitname) != 2: print "error pdb file is weird. " exit() prefix = splitname[0] print 'input_pdb =' + fileinputpdb print 'sph prefix =' + prefix print 'residue string =' + res_string print 'output =' + fileoutput residlist = [] res_string_split = res_string.split(',') print res_string_split # if len(res_string_split) == 1: # residlist.append(int(res_string_split[0])) # else: #print res_string_split for s in res_string_split: if ('-' in s): s_split = s.split('-') if (len(s_split) != 2): print "something is wrong with residue string." else: start = int(s_split[0]) stop = int(s_split[1]) + 1 for i in range(start, stop): residlist.append(i) else: residlist.append(int(s)) for i in range(1, len(residlist)): if residlist[i - 1] > residlist[i]: print "uhoh. list is not monotonic" exit() print residlist #exit() pdblist_chains = pdb.read_pdb(fileinputpdb) pdblist = [] for chain in pdblist_chains: pdblist = pdblist + chain pdblist_mod = add_bfactors(pdblist, residlist, filebfactor) pdb.output_pdb(pdblist_mod, fileoutput + '.pdb')
def main(): filename = sys.argv[1] intval = int(sys.argv[2]) fileprefix = sys.argv[3] pdbchains = pdb_lib.read_pdb(filename) count = 1 for pdbmol in pdbchains: renumber_residue_continuous(pdbmol, intval) pdb_lib.output_pdb(pdbmol, '%s_%i.pdb' % (fileprefix, count)) count = count + 1
def main(): if len(sys.argv) != 5: # if no input print "This function takes as input two pdb files, output file name and the value" print "read in the ligand (pdb1) and the water positions (pdb2)." print "calculates distances and writes out a the overlaping atoms from the second file (water positions)" print len(sys.argv) return pdb_file1 = sys.argv[1] pdb_file2 = sys.argv[2] pdb_out = sys.argv[3] val = float(sys.argv[4]) print "file 1: " + pdb_file1 print "file 2: " + pdb_file2 print "file out: " + pdb_out print "value: " + str(val) pdb1 = pdb.read_pdb(pdb_file1)[0] pdb2 = pdb.read_pdb(pdb_file2)[0] pdb2_close = pdb.cal_dists_close_val(pdb1,pdb2,val**2) pdb.output_pdb( pdb2_close, pdb_out)
def main(): if len(sys.argv) != 4: # if no input print "ERORR: there need to be 3 inputs: sph inputfilename, pdb inputfilename, outputfilename." return fileinputsph = sys.argv[1] fileinputpdb = sys.argv[2] fileoutput = sys.argv[3] print 'input_sph =' + fileinputsph print 'input_pdb =' + fileinputpdb print 'output =' + fileoutput list = sph.read_sph(fileinputsph, "A", "A") pdblist = pdb.read_pdb(fileinputpdb)[0] list2 = distance_sph_pdb(list, pdblist, 5) sph.write_sph(fileoutput, list2)
def main(): if len(sys.argv) != 4: # if no input print( "ERORR: there need to be 3 inputs: pdb inputfilename, residue:atom_list, outputfileprefix." ) print( "list is resnum1:atomname1,...,resnum1:atomnamei,...,resnumk,atomnamej,..." ) return fileinputpdb = sys.argv[1] res_string = sys.argv[2] fileoutput = sys.argv[3] splitname = fileinputpdb.split('\\')[-1].split('.') if len(splitname) != 2: print("error pdb file is weird. ") exit() prefix = splitname[0] print('input_pdb =' + fileinputpdb) print('sph prefix =' + prefix) print('residue string =' + res_string) print('output =' + fileoutput) residlist = [] res_string_split = res_string.split(',') residlist = res_string_split print res_string_split pdblist = pdb.read_pdb(fileinputpdb)[0] center = centre_of_mass(pdblist, residlist) #print ("%6.4f %6.4f %6.4f"%(center[0],center[1],center[2])) print( "HETATM 1 ZN ZN A 1 %8.3f%8.3f%8.3f 1.00 0.00 ZN" % (center[0], center[1], center[2])) fh = open(fileoutput + '_zinc.pdb', 'w') fh.write( "HETATM 1 ZN ZN A 1 %8.3f%8.3f%8.3f 1.00 0.00 ZN\n" % (center[0], center[1], center[2])) fh.close() change_name(pdblist, residlist) pdb.output_pdb(pdblist, fileoutput + '.pdb')
def main(): if len(sys.argv) != 6: # if no input print "ERORR: there need to be 4 inputs: sph inputfilename, pdb inputfilename, res list outputfilename, distance." return fileinputsph = sys.argv[1] fileinputpdb = sys.argv[2] fileinputlist = sys.argv[3] fileoutput = sys.argv[4] distance = float(sys.argv[5]) print 'input_sph =' + fileinputsph print 'input_pdb =' + fileinputpdb print 'input_list =' + fileinputlist print 'output =' + fileoutput print 'distance = %6.3f'%distance reslist = read_list(fileinputlist) #exit(0) sphlist = sph.read_sph(fileinputsph,"A","A") pdblist = pdb.read_pdb(fileinputpdb)[0] # make dictionary dict_pdblist = make_dict_pdb_res(pdblist) fhout = open(fileoutput,'w') # for each residue find the spheres within a certian distance for res in reslist: print res if not res in dict_pdblist: print str(res) + " not in dict" continue list2 = distance_sph_pdb(sphlist, dict_pdblist[res], distance) sphere_cluster = {} for sphere in list2: sphere_cluster[sphere.cluster] = '' # sorted clusters contain all the sphere clusters that are close to the residue. note that the sphere cluster define a pocket. sorted_clusters = sorted(sphere_cluster.keys()) print "sphere clusters close to residue %d:"%(res), sorted_clusters if len(sorted_clusters) != 0: fhout.write("sphere clusters close to residue %d: %s\n"%(res,int_list_to_string(sorted_clusters))) print "I AM HERE"
def main(): if len(sys.argv) != 5: # if no input print "ERORR: there need to be 4 inputs: sph inputfilename, pdb inputfilename, outputfilename, distance." return fileinputsph = sys.argv[1] fileinputpdb = sys.argv[2] fileoutput = sys.argv[3] distance = float(sys.argv[4]) print 'input_sph =' + fileinputsph print 'input_pdb =' + fileinputpdb print 'output =' + fileoutput print 'distance = %6.3f'%distance list = sph.read_sph(fileinputsph,"A","A") pdblist = pdb.read_pdb(fileinputpdb)[0] list2 = distance_sph_pdb(list, pdblist,distance) sph.write_sph(fileoutput,list2)
def main(): #if len(sys.argv) != 5: # if no input # print "ERORR: there need to be 4 inputs: sph inputfilename, pdb inputfilename, outputfilename, distance." # return if len(sys.argv) != 4: # if no input print "ERORR: there need to be 3 inputs: sph inputfilename, pdb inputfilename, outputfilename" return fileinputsph = sys.argv[1] fileinputpdb = sys.argv[2] fileoutput = sys.argv[3] #distance = float(sys.argv[4]) print 'input_sph =' + fileinputsph print 'input_pdb =' + fileinputpdb print 'output =' + fileoutput #print 'distance = %6.3f'%distance sph_cluster_list = sph.read_sph_cluster_list(fileinputsph) pdblist = pdb.read_pdb(fileinputpdb)[0] #list2 = distance_sph_pdb(sph_cluster_list, pdblist, distance) list2 = distance_sph_pdb(sph_cluster_list, pdblist) sph.write_sph(fileoutput, list2)
def cluster_water_pdb(inputfilename, cutoff, outputfilename, denominator): bonds = [] bond_dic = {} duplicate = {} pdb_ori = pdb_lib.read_pdb(inputfilename)[0] pdb_water = [] pdb_other = [] #print inputfilename for atom in pdb_ori: #print atom.resname if atom.resname == "HOH": pdb_water.append(atom) else: pdb_other.append(atom) numwat = len(pdb_water) print "%s contains %d waters" % (inputfilename, numwat) if numwat == 0: print "There are zero waters in the file. If this is not right make sure that there are no TER in the file and re-run. " for i in range(numwat): for j in range(i + 1, numwat): dist = dist_wat(pdb_water[i], pdb_water[j]) #print i, j, pdb_water[i].resnum, pdb_water[j].resnum, dist if (dist == 0.0): # discard duplicates duplicate[j] = i elif (dist < cutoff): #bonds.append([i,j, dist]) bonds.append([i, j]) print "bond: %d %d %f" % (i, j, dist) bond_dic[i] = 1 bond_dic[j] = 1 clusters = {} # what cluster belongs to each atom count = 0 # for bond in bonds: if bond[0] in clusters: # if the starting point is in a cluster then put the ending point in that same cluster clusters[bond[1]] = clusters[bond[0]] elif bond[ 1] in clusters: # if the ending point is in a cluster then put the starting point in that same cluster clusters[bond[0]] = clusters[bond[1]] else: # nether point is in a cluster clusters[bond[0]] = count clusters[bond[1]] = count count = count + 1 for i in range(numwat): if not i in bond_dic and not i in duplicate: # then singlton. clusters[i] = count count = count + 1 cluster_lists = {} # list of atoms in each cluster print clusters for key in clusters.keys(): # key is atom print key, clusters[key] cluster_lists[clusters[key]] = [] # intialize for key in clusters.keys(): cluster_lists[clusters[key]].append(key) cluster_centers = [] cluster_median = [] for cluster in cluster_lists: X = 0.0 Y = 0.0 Z = 0.0 count = 0 for atom in cluster_lists[cluster]: X = X + pdb_water[atom].X Y = Y + pdb_water[atom].Y Z = Z + pdb_water[atom].Z count = count + 1 X = X / count Y = Y / count Z = Z / count #alpha = float(count)/float(numwat) alpha = float(count) / denominator temp_atom_info = pdb_lib.PDB_atom_info('', "A", "HOH", cluster, " O ", cluster, X, Y, Z, 0.0, alpha, False) # find median water min_val = [-1, 1000] for i in range(len(cluster_lists[cluster])): dist = dist_wat(temp_atom_info, pdb_water[cluster_lists[cluster][i]]) if dist < min_val[1]: #min_val[0] = i # this index of the cluster member min_val[0] = cluster_lists[cluster][ i] # index of the water, simplifies call min_val[1] = dist pdb_water[cluster_lists[cluster][ i]].bfact = temp_atom_info.bfact # make both report the number of waters/ dem in b column cluster_centers.append(temp_atom_info) #cluster_median.append(pdb_water[cluster_lists[cluster][min_val[0]]]) # when we saved the index of the cluster instead of index of water cluster_median.append(pdb_water[min_val[0]]) # pdb_lib.output_pdb(cluster_centers, outputfilename + "_center.pdb") pdb_lib.output_pdb(cluster_median, outputfilename + "_median.pdb")
def main(): if len(sys.argv) != 4: # if no input print "ERORR: there need to be 3 inputs: pdb inputfilename, residuelist, outputfileprefix." return fileinputpdb = sys.argv[1] #fileinputsph = sys.argv[2] #res_string = sys.argv[3] #fileoutput = sys.argv[4] res_string = sys.argv[2] fileoutput = sys.argv[3] splitname = fileinputpdb.split('\\')[-1].split('.') if len(splitname) != 2: print "error pdb file is weird. " exit() prefix = splitname[0] print 'input_pdb =' + fileinputpdb print 'sph prefix =' + prefix print 'residue string =' + res_string print 'output =' + fileoutput residlist = [] res_string_split = res_string.split(',') print res_string_split # if len(res_string_split) == 1: # residlist.append(int(res_string_split[0])) # else: #print res_string_split for s in res_string_split: if ('-' in s): s_split = s.split('-') if (len(s_split) != 2): print "something is wrong with residue string." else: start = int(s_split[0]) stop = int(s_split[1]) + 1 for i in range(start, stop): residlist.append(i) else: residlist.append(int(s)) for i in range(1, len(residlist)): if residlist[i - 1] > residlist[i]: print "uhoh. list is not monotonic" exit() print residlist #exit() run_dms_sph(fileinputpdb, prefix) list1 = sph.read_sph(prefix + ".sph", "A", "A") pdblist = pdb.read_pdb(fileinputpdb) center = centre_of_mass(pdblist, residlist) print center list2 = closest_sphs_to_center(list1, center, 4) sph.write_sph(fileoutput + ".sph", list2) # add center to list and write agian to new file #tmp_sphere = sphere(index,x,y,z,r,atomnum,clust,col) tmp_sphere = sph.sphere(2, center[0], center[1], center[2], 0.7, 2, 0, 0) list2.append(tmp_sphere) sph.write_sph(fileoutput + "_and_center.sph", list2) convert_sph_to_pdb(fileoutput + ".sph", fileoutput)
def main(): if len(sys.argv) != 5: # if no input print( "ERORR: there need to be 4 inputs: pdb file_pdb_list lig_resid dcutoff (center of ligand to center of model)" ) return fileinputpdb1 = sys.argv[1] file_pdb_list = sys.argv[2] ligand_name = sys.argv[3] ligand_dist = float(sys.argv[4]) prefix = check_filename(fileinputpdb1) print('input_pdb1 =' + fileinputpdb1) print('sph prefix =' + prefix) print('pdb list file =' + file_pdb_list) print('lig_name =' + ligand_name) print('lig_dist = %d' % ligand_dist) #center = centre_of_mass(pdblist) # calculate the center of mass of the full file that contains all molecles center1 = readin_all_atoms_center_of_mass(fileinputpdb1) fh = open(file_pdb_list, 'r') dist_list = [] pdb_f_list = [] center_list = [] # loop over the list of pdb files. one file contains one model for line in fh: fileinputpdb2 = line.split()[0] print('input_pdb2 =' + fileinputpdb2) check_filename(fileinputpdb2) center2 = readin_all_atoms_center_of_mass(fileinputpdb2) d = distance(center1, center2) dist_list.append(d) pdb_f_list.append(fileinputpdb2) center_list.append(center2) distmin_id = 0 distmin = dist_list[distmin_id] for i in range(0, len(dist_list)): if (dist_list[i] < distmin): #if dist_list[i] < dist_list[distmin_id]: distmin_id = i distmin = dist_list[distmin_id] print("The model closest (dist = %f) to center is %s" % (dist_list[distmin_id], pdb_f_list[distmin_id])) # lets get the ligand pdblist = pdb.read_pdb( pdb_f_list[distmin_id] ) # read in the model that is closest to the center (this one should be completely suronded by neibors). # get the subset of atoms of just the ligand atom_lig_list = [] for pdbatoms in pdblist: for atom in pdbatoms: #print(atom.resname) if (atom.resname == ligand_name): atom_lig_list.append(atom) lig_center = centre_of_mass(atom_lig_list) filelist = [] # remember wich models are close by center of position. for i, center in enumerate(center_list): d = distance(center, lig_center) if d < ligand_dist: print( "The model within cutoff (dist = %f) to center of ligand is %s" % (d, pdb_f_list[i])) filelist.append(pdb_f_list[i]) cat_string = " files to cat " cat_cmd = " cat " for filename in filelist: print(filename) pdblist = pdb.read_pdb( filename ) # read in the model that is closest to the center (this one should be completely suronded by neibors). atom_list = [] for pdbatoms in pdblist: for atom in pdbatoms: #print(atom.resname) atom_list.append(atom) flag_write = min_dist_between_two_sets_of_atoms( atom_lig_list, atom_list, filename, 5) if flag_write: cat_string = cat_string + " " + filename cat_cmd = cat_cmd + " " + filename print(cat_string) os.system(cat_cmd + " > complex.pdb")
def run_energy_cal(): # this function will run amber. # cluster. we start with the frist water. find everything close, then go to the next water not alreay assigned. find everything close, repeat until all are assigned. wats = pdb_lib.read_pdb("waters.pdb") wat_clus = [] for i in range(len(wats)): wat_clus.append(0) clusterheads = [] cluster = 1 for i, wat1 in enumerate(wats): if wat_clus[ i] != 0: # if cluster is already asigned then continue to next water continue print "water" + str(i) + " is a clusterhead. " clusterheads.append(wat1) for j, wat2 in enumerate(wats): if wat_clus[ j] != 0: # if cluster is already asigned then continue to next water continue dist = dist_wat(wat1, wat2) #if dist < 3.0: if dist < 2.8: wat_clus[j] = cluster cluster = cluster + 1 pdb_lib.output_pdb(clusterheads, "waterclusters.pdb") # check if there is a tleap input file: # if there is not then write a defualt file, if one already exist then use that one. # This way someone can perpare the receptor the way they want. if not (os.path.isfile("./tleap.in")): #os.system('cp rec.pdb rec_ori.pdb' file1 = open("tleap.in", 'w') file1.write( " set default PBradii mbondi2 \n source leaprc.ff14SB \n \n REC = loadpdb rec_ori.pdb \n WAT = loadpdb water1.pdb \n COM = combine {REC WAT} \n saveamberparm REC rec.leap.prm7 rec.leap.rst7 \n saveamberparm COM rec.1wat.leap.prm7 rec.1wat.leap.rst7 \n charge REC \n quit \n" ) file1.close() else: print "using pre-existing tleap.in" # cut -c 24-28 rec_ori.pdb | sort -u | wc -l numres = 290 if not (os.path.isfile("./min.in")): file2 = open("min.in", 'w') #file2.write(" 01mi.in: equil minimization with Cartesian restraints /n &cntrl /n imin=1, maxcyc=3000, ncyc = 1500, /n ntpr=100, /n ntwr=100000000, /n ntr=1, /n restraint_wt=100.0, /n restraintmask= ':1-%d & !@H' /n / /n "%(numres)) file2.write( " min.in: minimization with GB \n &cntrl \n imin = 1, maxcyc = 100, ncyc = 50, ntmin = 1, \n igb=1, \n ntx = 1, ntc = 1, ntf = 1, \n ntb = 0, ntp = 0, \n ntwx = 1000, ntwe = 0, ntpr = 1000, \n cut = 999.9, \n ntr = 1, \n restraintmask = '!@H=', \n restraint_wt = 0.1, \n / \n " ) file2.close() #fh = open('waters.pdb','r') fh = open('waterclusters.pdb', 'r') lines = fh.readlines() fh.close() fh = open('water1.pdb', 'w') fh.write(lines[0]) fh.close() os.system("setenv AMBERHOME = /nfs/soft/amber/amber14") os.system("$AMBERHOME/bin/tleap -s -f tleap.in > ! tleap.out") # minimize the receptor alone. os.system( "$AMBERHOME/bin/sander -O -i min.in -o min.out -p rec.leap.prm7 -c rec.leap.rst7 -ref min.rst7 -x min.mdcrd -inf min.info -r min.rst7" ) # loop over all waters, run a minimization on each water in the context of the receptor. count = 1 for line in lines: name = "water_" + str(count) print "we are minimzing " + name fh = open(name + ".pdb", 'w') fh.write(line) fh.close() os.system("python /nfs/home/tbalius/zzz.scripts/add_h_to_wat.py " + name + ".pdb") #print "cat rec.leap.rst7 "+name+".pdb.rst7 > "+name+".rst7" #os.system("cat rec.leap.rst7 "+name+".pdb.rst7 > "+name+".rst7") fh = open('rec.leap.rst7', 'r') fh2 = open(name + '.rst7', 'w') linecount = 0 for line in fh: if linecount == 1: num = int(line.split()[0]) num = num + 3 fh2.write('%d\n' % num) else: fh2.write(line) linecount = linecount + 1 fh.close() fh = open(name + ".pdb.rst7", 'r') for line in fh: fh2.write(line) fh.close() fh2.close() #exit() os.system("$AMBERHOME/bin/ambpdb -p rec.1wat.leap.prm7 < " + name + ".rst7 > before_min_" + name + ".pdb") os.system("$AMBERHOME/bin/sander -O -i min.in -o min." + name + ".out -p rec.1wat.leap.prm7 -c " + name + ".rst7 -ref " + name + ".rst7 -x min." + name + ".mdcrd -inf min." + name + ".info -r min." + name + ".rst7") os.system("$AMBERHOME/bin/ambpdb -p rec.1wat.leap.prm7 < min." + name + ".rst7 > min." + name + ".pdb") count = count + 1
import pdb_lib import sys, copy # Written by Trent E. Balius, B. Shoichet Lab O = [28.781, 50.284, 29.051] H1 = [29.738, 50.284, 29.051] H2 = [28.541, 51.210, 29.051] pdb_file = sys.argv[1] wat_o = pdb_lib.read_pdb(pdb_file) print len(wat_o) fh = open(pdb_file + ".rst7", 'w') new_wat = [] count = 0 for c in wat_o: print c.X print c.Y print c.Z new_wat.append(c) #count = count+1 c1 = copy.copy(c) new_wat.append(c1) count = count + 1 new_wat[count].atomname = " H1 " #= line[12:16 new_wat[count].X = new_wat[count].X + H1[0] - O[0] # new_wat[count].Y = new_wat[count].Y + H1[1] - O[1] #
def cluster_water_pdb(inputfilename, cutoff, outputfilename, denominator): bonds = [] bond_dic = {} duplicate = {} pdb_ori = pdb_lib.read_pdb(inputfilename) pdb_water = [] pdb_other = [] for atom in pdb_ori: #print atom.resname if atom.resname == "HOH": pdb_water.append(atom) else: pdb_other.append(atom) numwat = len(pdb_water) for i in range(numwat): for j in range(i + 1, numwat): dist = dist_wat(pdb_water[i], pdb_water[j]) #print i, j, pdb_water[i].resnum, pdb_water[j].resnum, dist if (dist == 0.0): # discard duplicates duplicate[j] = i elif (dist < cutoff): #bonds.append([i,j, dist]) bonds.append([i, j]) print "bond: %d %d %f" % (i, j, dist) bond_dic[i] = 1 bond_dic[j] = 1 clusters = {} # what cluster belongs to each atom count = 0 # for bond in bonds: if bond[0] in clusters: # if the starting point is in a cluster then put the ending point in that same cluster clusters[bond[1]] = clusters[bond[0]] elif bond[ 1] in clusters: # if the ending point is in a cluster then put the starting point in that same cluster clusters[bond[0]] = clusters[bond[1]] else: # nether point is in a cluster clusters[bond[0]] = count clusters[bond[1]] = count count = count + 1 for i in range(numwat): if not i in bond_dic and not i in duplicate: # then singlton. clusters[i] = count count = count + 1 cluster_lists = {} # list of atoms in each cluster print clusters for key in clusters.keys(): # key is atom print key, clusters[key] cluster_lists[clusters[key]] = [] # intialize for key in clusters.keys(): cluster_lists[clusters[key]].append(key) cluster_centers = [] cluster_median = [] for cluster in cluster_lists: X = 0.0 Y = 0.0 Z = 0.0 count = 0 for atom in cluster_lists[cluster]: X = X + pdb_water[atom].X Y = Y + pdb_water[atom].Y Z = Z + pdb_water[atom].Z count = count + 1 X = X / count Y = Y / count Z = Z / count #alpha = float(count)/float(numwat) alpha = float(count) / denominator temp_atom_info = pdb_lib.PDB_atom_info('', "A", "HOH", cluster, " O ", cluster, X, Y, Z, alpha, False) # find median water min_val = [-1, 1000] for i in range(len(cluster_lists[cluster])): dist = dist_wat(temp_atom_info, pdb_water[cluster_lists[cluster][i]]) if dist < min_val[1]: min_val[0] = i min_val[1] = dist cluster_centers.append(temp_atom_info) cluster_median.append( pdb_water[cluster_lists[cluster][min_val[0]]]) # g pdb_lib.output_pdb(cluster_centers, outputfilename + "_center.pdb") pdb_lib.output_pdb(cluster_median, outputfilename + "_median.pdb")