def main(): if len(sys.argv) != 3: # if no input print "ERORR" return namemol2 = sys.argv[1] namedocktype = sys.argv[2] fh = open(namedocktype, 'w') fh1 = open(namedocktype + '.amb.crg.oxt', 'w') fh2 = open(namedocktype + '.prot.table.ambcrg.ambH', 'w') mol = mol2.read_Mol2_file(namemol2)[0] dt = mol2.convert_sybyl_to_dock(mol) for i in range(len(mol.atom_list)): print i + 1, mol.atom_list[i].type, dt[i] fh.write('%2d %4s %4s %4s %-6s %2s\n' % (i + 1, mol.atom_list[i].name, mol.atom_list[i].resname, upper_to_lower( mol.atom_list[i].resname), mol.atom_list[i].type, dt[i])) fh1.write( '%-4s %4s %6.3f\n' % (mol.atom_list[i].name, upper_to_lower( mol.atom_list[i].resname), mol.atom_list[i].Q)) fh2.write('%4s %4s %6.3f %2s\n' % (pad_string(mol.atom_list[i].name), mol.atom_list[i].resname, mol.atom_list[i].Q, dt[i])) fh.close() fh1.close() fh2.close()
def main(): if len(sys.argv) != 3: # if no input print "ERORR" return namemol2in = sys.argv[1] namemol2outprefix = sys.argv[2] mol = mol2.read_Mol2_file(namemol2in)[0] shift_mol2(namemol2outprefix, mol)
def main(): if len(sys.argv) != 3: # if no input print "ERORR" return namemol2 = sys.argv[1] namesph = sys.argv[2] mol = mol2.remove_hydrogens(mol2.read_Mol2_file(namemol2)[0]) write_sph(namesph, mol)
def main(): if len(sys.argv) != 3: # if no input print "ERORR" print "this script reads in a mol2 file and writes out a sph file." print "this script takes 2 arguments: name.mol2 name.sph" return namemol2 = sys.argv[1] namesph = sys.argv[2] mol = mol2.remove_hydrogens(mol2.read_Mol2_file(namemol2)[0]) write_sph(namesph, mol)
def main(): if len(sys.argv) != 2: # if no input print "ERORR" return namemol2in = sys.argv[1] mols = mol2.read_Mol2_file(namemol2in) count = 0 for mol in mols: print "mol%d" % (count) dist_mol2(mol, 1.70) count = count + 1
def main(): if len(sys.argv) != 6: # if no input print "ERORR." print "syntax: namemol2in namemol2outprefix xtran ytran ztran" return namemol2in = sys.argv[1] namemol2outprefix = sys.argv[2] xtran = float(sys.argv[3]) ytran = float(sys.argv[4]) ztran = float(sys.argv[5]) mol = mol2.read_Mol2_file(namemol2in)[0] shift_mol2(namemol2outprefix, mol, xtran, ytran, ztran)
def main(): if len(sys.argv) != 6: # if no input print(" This script needs the following:") print(" (1) input mol2 file") print(" (2) output mol2 file") print(" (3-5) x, y, z rotation angles") print(" rotation order: x, y, then z with be rotated in that order. ") return mol2file = sys.argv[1] outputfile = sys.argv[2] xangle = float(sys.argv[3]) yangle = float(sys.argv[4]) zangle = float(sys.argv[5]) cos_x = math.cos(xangle) xsign = 1.0 if xangle < 0.0: xsign = -1.0 cos_y = math.cos(yangle) ysign = 1.0 if yangle < 0.0: ysign = -1.0 cos_z = math.cos(zangle) zsign = 1.0 if zangle < 0.0: zsign = -1.0 mols = mol2.read_Mol2_file(mol2file) first = True for m in mols: center = mol2.centre_of_mass(m) translate(m, -center[0], -center[1], -center[2]) rotate_x(m.atom_list, cos_x, xsign) rotate_y(m.atom_list, cos_y, ysign) rotate_z(m.atom_list, cos_z, zsign) translate(m, center[0], center[1], center[2]) if first: mol2.write_mol2(m, outputfile) first = False else: mol2.append_mol2(m, outputfile) return
def main(): if len(sys.argv) != 6: # if no input print ("ERORR:") print ("syntex: distance_cal_no_precomput.py mol2_file(docked poses) mol2_file(find poses close to) threshold hname output ") return infilemol2_poses = sys.argv[1] infilemol2_ref = sys.argv[2] dist_threshold = float(sys.argv[3]) hname = sys.argv[4] outfile = sys.argv[5] print ("input file (poses) = ", infilemol2_poses) print ("input file (reference) = ", infilemol2_ref) print ("threshold =", dist_threshold) print ("head_name =", hname) print ("outputprefix =", outfile) #mol2_vector = mol2.read_Mol2_file(infilemol2_poses) mol2_vector = mol2.read_Mol2_file_head(infilemol2_poses) mol2_ref = mol2.read_Mol2_file(infilemol2_ref)[0] count = 0 for mol in mol2_vector: min_dist = 100000 count_atom_lt_thes = 0 for atom in mol.atom_list: if (atom.type == 'H'): continue #dist = cal_dist_closest_grid_point(grid_dist,gridscale,xn,yn,zn,origin,atom) #dist = cal_dist_tri_linear(grid_dist,gridscale,xn,yn,zn,origin,atom) dist = cal_min_dist_atom_mol(atom,mol2_ref) if dist < min_dist: min_dist = dist if dist < dist_threshold: count_atom_lt_thes = count_atom_lt_thes + 1 if min_dist < dist_threshold: print("mol %d,dist=%f,num_atom_lt_threshold=%d"%(count,min_dist,count_atom_lt_thes)) #close_mol2.append(mol) mol.header = mol.header+"########## %s_dist: %f\n"%(hname,min_dist) mol.header = mol.header+"########## %s_num_atom_lt_threshold: %d\n"%(hname,count_atom_lt_thes) mol2.append_mol2(mol, outfile+'.mol2') count = count + 1
def main(): if len(sys.argv) != 5: # if no input print "ERORR:" print "syntex: dx-gist_rescore.py dx-file mol2" print "dx-input-file input file in dx formate produed by gist, may be disities or energies" print "mol2 containing docked poses. " print "Hchoice [0(use standard radius), 1 (use 0.8 for nonpolar H, instead of 1.540), or 2 (ignore H)]" print "radius_pad : if a value of 8.0 is given then 8 angstroms is added to all atom radii" return infiledx = sys.argv[1] infilemol2 = sys.argv[2] Hchoice = int(sys.argv[3]) pad = float(sys.argv[4]) outfile = "out" print infiledx print infilemol2 DOCKpath = os.getenv('DOCKBASE') print(DOCKpath) vdwdict = intialize_vdw_parm(DOCKpath + '/proteins/defaults/vdw.parms.amb.mindock') #vdwdict = intialize_vdw_parm('/nfs/home/tbalius/zzz.github/DOCK/proteins/defaults/vdw.parms.amb.mindock') xn, yn, zn, dx, dy, dz, origin, values = dxlib.read_in_dx_file(infiledx) gridscale = dx # assumes that they are all the same spaceing mols = mol2.read_Mol2_file(infilemol2) file1 = open(outfile + 'gist_values.txt', 'w') N = len(mols) count = 0 for mol in mols: new_values = calc_score(outfile, values, gridscale, xn, yn, zn, origin, mol, vdwdict, file1, (N < 3), Hchoice, pad) if N < 3: # only print gist grids if there are a few poses in the mol2 file print "writting gist grid for overlap with ligand . . ." dxlib.write_out_dx_file(outfile + str(count) + "new_gist.dx", xn, yn, zn, dx, dy, dz, origin, new_values) count = count + 1 #exit() file1.close()
def modify_charges_mol2_file(mol2file, atom_list_hex, outputprefix): ## read in mol2 file mol = mol2.read_Mol2_file(mol2file)[0] n = len(atom_list_hex) if n != len(mol.atom_list): print "Error: n != len(mol.atom_list) : " + str(n) + " !=" + str( len(mol.atom_list)) exit() for i in range(n): charge = atom_list_hex[i][2] print mol.atom_list[i].Q, charge mol.atom_list[i].Q = float(charge) filename = outputprefix + '.mol2' mol2.write_mol2(mol, filename) return
def main(): if len(sys.argv) != 3: # if no input print "ERORR:" print "syntex: dx-gist_rescore.py dx-file mol2" print "dx-input-file input file in dx formate produed by gist, may be disities or energies" print "mol2 containing docked poses. " return infiledx = sys.argv[1] infilemol2 = sys.argv[2] outfile = "out" print infiledx print infilemol2 vdwdict = intialize_vdw_parm( '/nfs/home/tbalius/zzz.github/DOCK/proteins/defaults/vdw.parms.amb.mindock' ) xn, yn, zn, dx, dy, dz, origin, values = read_in_dx_file(infiledx) gridscale = dx # assumes that they are all the same spaceing mols = mol2.read_Mol2_file(infilemol2) file1 = open(outfile + 'gist_values.txt', 'w') N = len(mols) count = 0 for mol in mols: new_values = calc_score(outfile, values, gridscale, xn, yn, zn, origin, mol, vdwdict, file1, (N < 3)) if N < 3: # only print gist grids if there are a few poses in the mol2 file print "writting gist grid for overlap with ligand . . ." write_out_dx_file(outfile + str(count) + "new_gist.dx", xn, yn, zn, dx, dy, dz, origin, new_values) count = count + 1 #exit() file1.close()
def modify_mol2_file(mol2file, outputprefix): ## read in mol2 file frist = True mollist = mol2.read_Mol2_file(mol2file) for mol in mollist: ori_formal_charge = mol2.formal_charge(mol) n = len(mol.atom_list) Si_atoms_index = [] for i in range(n): if mol.atom_list[i].name == 'CB' or mol.atom_list[i].name == 'SG': print(mol.atom_list[i].type, mol.atom_list[i].name) Si_atoms_index.append(i) if len(Si_atoms_index) != 2: print("error") exit() count_h = [0, 0] # remember how meny atoms are connected to the both Si Hlist = [ ] # remember which the atom index that are the connected bonds. Si1 = Si_atoms_index[0] Si2 = Si_atoms_index[1] for bond in mol.bond_list: if bond.a1_num - 1 == Si1: if (mol.atom_list[bond.a2_num - 1].type == 'H'): count_h[0] = count_h[0] + 1 Hlist.append(bond.a2_num) if bond.a2_num - 1 == Si1: if (mol.atom_list[bond.a1_num - 1].type == 'H'): count_h[0] = count_h[0] + 1 Hlist.append(bond.a1_num) if bond.a1_num - 1 == Si2: if (mol.atom_list[bond.a2_num - 1].type == 'H'): count_h[1] = count_h[1] + 1 Hlist.append(bond.a2_num) if bond.a2_num - 1 == Si2: if (mol.atom_list[bond.a1_num - 1].type == 'H'): count_h[1] = count_h[1] + 1 Hlist.append(bond.a1_num) print(Hlist) print(count_h) # (1) remove 5 hydrogen atoms, # (2) change Si to Du and the atom name, new_atomlist = [] for i, atom in enumerate(mol.atom_list): print(i, atom.num) #exit() if atom.num in Hlist: continue if atom.num - 1 == Si1: atom.type = 'Du' atom.Q = 0.0 print("Hcount ==", count_h[0]) if count_h[0] == 3: atom.name = 'D2' elif count_h[0] == 0: # SG will just have no H #elif count_h[0] == 2: atom.name = 'D1' if atom.num - 1 == Si2: atom.type = 'Du' atom.Q = 0.0 print("Hcount ==", count_h[1]) if count_h[1] == 3: atom.name = 'D2' #elif count_h[1] == 2: # elif count_h[1] == 0: # SG will just have no H atom.name = 'D1' new_atomlist.append(copy.copy(atom)) # (3) generate mapping from old to new atom numbering to be used in the bond modification. atom_num_map = {} for i, atom in enumerate(new_atomlist): atom_num_map[atom.num] = i + 1 atom.num = i + 1 # (4) remove bonds that contain any of the removed hydrogens. new_bondlist = [] for i, bond in enumerate(mol.bond_list): if bond.a1_num in Hlist or bond.a2_num in Hlist: continue new_bondlist.append(copy.copy(bond)) # (5) renumber the bonds, map old atom numbering to new atom number for bonds i = 1 for bond in new_bondlist: bond.num = i bond.a1_num = atom_num_map[bond.a1_num] bond.a2_num = atom_num_map[bond.a2_num] i = i + 1 mol.atom_list = new_atomlist mol.bond_list = new_bondlist # ajust Si-Si-C bond angle. Looks like it is 90 deg. #ajust_angle(mol,ang) # ajust the partial charge to make it an integer. make_integer_charge(mol, ori_formal_charge) #exit() filename = outputprefix + '.mol2' if frist: mol2.write_mol2(mol, filename) frist = False else: mol2.append_mol2(mol, filename) return
print "This file requiers the mol2 libary writen by trent balius and sudipto mukherjee" print "syntex: mol2_shuffle.py input_file1 input_file2 input_file3 output_file" print "this file takes in 3 mol2 input files 2 of the files are the same but a different order. " print "The 3 input is a file that you want to suffle for the order of 1 to 2" print "(1) origenal order." print "(2) the new order." print "(3) mol2 to file to change the order (can be multi mol2)" print "(4) name to which to write newly reordered mol2." infile1 = sys.argv[1] infile2 = sys.argv[2] infile3 = sys.argv[3] outfile = sys.argv[4] mol_1 = mol2.read_Mol2_file(infile1)[0] # ori order mol_2 = mol2.read_Mol2_file(infile2)[0] # new order mol_3list = mol2.read_Mol2_file_head(infile3) maping = maping_by_cord(mol_1, mol_2) for j, mol_3 in enumerate(mol_3list): print "molecule %d" % (j) #mol_3_new = copy.deepcopy(mol_3) atomlist = [] for i, move in enumerate(maping): #print i,move,maping[i] atom = mol_3.atom_list[move] atom.num = i + 1 atomlist.append(atom)
def zernike_moments(mol2_file, nmax=20, np=50, uniform=True, fix_dx=False, np_on_grid=20, shift=False, buildmap=False, coef_out=True, calc_intensity=True, external_rmax=-1): base = mol2_file.split('.')[0] splat_range = 0 fraction = 0.9 default_dx = 0.5 models = mol2.read_Mol2_file( mol2_file ) if(len( models )== 0): return None,None,None ## for testing purpose, here only the first model in the mol2 file is converted ## this_molecule = models[0] ## models should be a list of molecules, same ligand at different conformations ## all_atoms = this_molecule.atom_list if(len( all_atoms )== 0): return None,None,None # predefine some arrays we will need xyz = flex.vec3_double() charges = flex.double() # keep track of the atom types we have encountered for atom in all_atoms: xyz.append( ( atom.X, atom.Y, atom.Z ) ) charges.append( atom.Q ) if(xyz.size() == 0): return None,None,None if (uniform): density=flex.double(xyz.size(),1.0) else: # use charges density=charges voxel_obj = math.sphere_voxel(np,splat_range,uniform,fix_dx,external_rmax, default_dx, fraction,xyz,density) np = voxel_obj.np() rmax=voxel_obj.rmax()/fraction #print base, "RMAX: ", voxel_obj.rmax() #print time.time() grid_obj = math.sphere_grid(np, nmax) pdb_out = False grid_obj.clean_space(voxel_obj, pdb_out) #print time.time(), "END GRID CONST" grid_obj.construct_space_sum() #print time.time(), "SS CALC" mom_obj = math.zernike_moments(grid_obj, nmax) #print time.time(), "END MOM CALC" moments = mom_obj.moments() if(coef_out): nn = mom_obj.fnn() easy_pickle.dump(base+'.nlm.pickle', moments.coefs() ) easy_pickle.dump(base+'.nn.pickle', nn.coefs() ) # ####### The following will be optional ### if(shift): shift = [rmax, rmax, rmax] centered_xyz = voxel_obj.xyz() + shift out_mol2_filename =base+'_centered.mol2' for a,xyz in zip( all_atoms, centered_xyz): a.X = xyz[0] a.Y = xyz[1] a.Z = xyz[2] mol2.write_mol2( this_molecule, out_mol2_filename ) original_map = voxel_obj.map() xplor_map_type( original_map, np, rmax, file_name=base+'_pdb.xplor') ######## Calculate Intnesity Profile ############ if(calc_intensity): q_array = flex.double( range(51) )/100.0 z_model = zm.zernike_model( moments, q_array, rmax, nmax) nn = mom_obj.fnn() intensity = z_model.calc_intensity(nn) #iq_file = open(base+"_"+str(nmax)+"_"+str(int(rmax*fraction))+".zi", 'w') iq_file = open(base+"_"+str(nmax)+".zi", 'w') for qq, ii in zip(q_array, intensity): print>>iq_file, qq,ii iq_file.close() ####### END of Intensity Calculation ########### if(buildmap): print "grid setting up..." zga = math.zernike_grid(np_on_grid, nmax, False) print "grid setting up...Done" zga.load_coefs(moments.nlm(), moments.coefs() ) print "start reconstruction" map=flex.abs(zga.f() ) print "finished reconstruction" xplor_map_type( map, np_on_grid, rmax, file_name=base+'.xplor') ccp4_map_type( map, np_on_grid, rmax, file_name=base+'.ccp4' ) return mom_obj, voxel_obj, models
import mol2 import sys print "this file requiers the mol2 libary writen by trent balius and sudipto mukherjee" print "syntex: mol2_removeH.py input_file output_file" infile = sys.argv[1] outfile = sys.argv[2] mol_list = mol2.read_Mol2_file(infile) print len(mol_list) for mol_withH in mol_list: mol = mol2.remove_hydrogens(mol_withH) mol2.append_mol2(mol, outfile)
def main(): pwd = os.getcwd() + "/" ori_dir = sys.argv[1] tbGIST_dir = sys.argv[2] #ori_mol2 = "/mnt/nfs/work/tbalius/Water_Project_DUDE/"+pdb+"/ligands-decoys/ligands/allChunksCombined/poses.mol2" #ori_mol2 = "/mnt/nfs/export/rstein/Ligand_Generation/"+pdb+"_testing/"+pdb+"_std_min/ligands-decoys/ligands/allChunksCombined/poses.mol2" #ori_mol2 = "/mnt/nfs/work/rstein/DUDE_MIN/"+pdb+"_min/ligands-decoys/ligands/allChunksCombined/poses.mol2" #ori_mol2 = "/mnt/nfs/work/rstein/ampc_preparation/11-16_2017_for_bGIST/1L2S_dist0pt5_size0pt6/ligands-decoys/ligands/allChunksCombined/poses.mol2" ori_mol2 = pwd + ori_dir + "/ligands-decoys/ligands/allChunksCombined/poses.mol2" tbGIST_mol2 = pwd + tbGIST_dir + "/ligands-decoys/ligands/allChunksCombined/poses.mol2" #ori_mol2 = pwd+"1L2S_tart1_thin_spheres_5000_min/ligands-decoys/ligands/allChunksCombined/poses.mol2" #ori_mol2 = pwd+"1L2S_tart1_thin_spheres_min_top_10/ligands-decoys/ligands/allChunksCombined/poses.mol2" #tbGIST_mol2 = pwd+"1L2S_tart1_thin_spheres_tbGIST_min_top_10/ligands-decoys/ligands/allChunksCombined/poses.mol2" #tbGIST_mol2 = pwd+"1L2S_tart1_thin_spheres_tbGIST_5000_min/ligands-decoys/ligands/allChunksCombined/poses.mol2" #tbGIST_mol2 = "/mnt/nfs/work/rstein/Big_Blurry/"+pdb+"_truncate_blurry_spheres/"+pdb+"_sig_2_gist_rad_1pt8_1pt0_min/ligands-decoys/ligands/allChunksCombined/poses.mol2" #tbGIST_mol2 = "/mnt/nfs/work/rstein/ampc_preparation/11-16_2017_for_bGIST/1L2S_dist0pt5_size0pt6_tbGIST/ligands-decoys/ligands/allChunksCombined/poses.mol2" #tbGIST_mol2 = "/mnt/nfs/export/rstein/DUDE_Z/"+pdb+"_testing/"+pdb+"_tbGIST_std/ligands-decoys/ligands/allChunksCombined/poses.mol2" hydrogen_truncated_gist_grid = "/mnt/nfs/work/rstein/ampc_preparation/11-16_2017_for_bGIST/1L2S_dist0pt5_size0pt6_tbGIST/dockfiles/Sig_2_GIST_1pt0_gaussian.dx" heavy_truncated_gist_grid = "/mnt/nfs/work/rstein/ampc_preparation/11-16_2017_for_bGIST/1L2S_dist0pt5_size0pt6_tbGIST/dockfiles/Sig_2_GIST_1pt8_gaussian.dx" #hydrogen_truncated_gist_grid = "/mnt/nfs/export/rstein/Ligand_Generation/"+pdb+"_testing/"+pdb+"_tbGIST_std/dockfiles/Sig_2_GIST_1pt0_gaussian.dx" #heavy_truncated_gist_grid = "/mnt/nfs/export/rstein/Ligand_Generation/"+pdb+"_testing/"+pdb+"_tbGIST_std/dockfiles/Sig_2_GIST_1pt8_gaussian.dx" xn1, yn1, zn1, dx1, dy1, dz1, origin1, values1 = read_in_dx_file( hydrogen_truncated_gist_grid) xn2, yn2, zn2, dx2, dy2, dz2, origin2, values2 = read_in_dx_file( heavy_truncated_gist_grid) grid_hydrogen_precomp = precompute_grids(xn1, yn1, zn1, values1) grid_heavy_precomp = precompute_grids(xn2, yn2, zn2, values2) gridscale = dx1 energy_dict1 = collect_energies(ori_mol2) energy_dict2 = collect_energies(tbGIST_mol2) mols = mol2.read_Mol2_file(ori_mol2) #mols = mol2.read_Mol2_file(tbGIST_mol2) count = 0 diff_energy = [] for mol in mols: mol_name = mol.name if (mol_name in energy_dict1) and (mol_name in energy_dict2): print(mol_name) gist_val = calc_score(mol, origin1, gridscale, xn1, yn1, zn1, grid_hydrogen_precomp, grid_heavy_precomp) ori_std_pose_energy = sum_vals(energy_dict1[mol_name]) std_pose_energy = ori_std_pose_energy + gist_val gist_pose_energy = sum_vals(energy_dict2[mol_name]) diff = gist_pose_energy - std_pose_energy if diff > 0.001: print(mol_name, ori_std_pose_energy, gist_val, std_pose_energy, gist_pose_energy, diff) count += 1 diff_energy.append(diff) #elif diff < -0.001: # print("NEGATIVE DIFF") # print(mol_name, ori_std_pose_energy, gist_val, std_pose_energy, gist_pose_energy, diff) print(np.mean(diff_energy), np.std(diff_energy)) print(count)