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 write_sph(filename, mol): dt = mol2.convert_sybyl_to_dock(mol) # get dock atom types. dockbase = os.environ.get('DOCKBASE') vdw_dict = intialize_vdw_parm(dockbase + '/proteins/defaults/vdw.parms.amb.mindock') outsph = open(filename, 'w') print len(mol.atom_list) outsph.write("DOCK spheres generated from ligand heavy atoms\n") outsph.write("cluster 1 number of spheres in cluster %d\n" % len(mol.atom_list)) for i in range(len(mol.atom_list)): radius = vdw_dict[dt[i]] #outsph.write("%5d%10.5f%10.5f%10.5f%8.3f%5d \n" % outsph.write( "%5d%10.5f%10.5f%10.5f%8.3f%5d 0 0\n" % (i + 1, round(mol.atom_list[i].X, 3), round(mol.atom_list[i].Y, 3), round(mol.atom_list[i].Z, 3), radius, i + 1)) outsph.close() return
def calc_score(fileprefix, values, gridscale, xn, yn, zn, origin, mol, vdw_dict, fileh, return_vals, Hchoice): # file - log file # values gist values # gridscale - the grid spacing if Hchoice != 0 and Hchoice != 1 and Hchoice != 2: print "Hchoice must be 0(use standard radius), 1 (use 0.8 for nonpolar H, instead of 1.540), or 2 (ignore H)" exit() dt = mol2.convert_sybyl_to_dock(mol) # get dock atom types. # loop over each atom. dict_gridpoint = {} # for each grid point have a list of atoms it is in sum_per_atom = [] for atom_i, atom in enumerate(mol.atom_list): sum_per_atom.append(0.0) #if (Hchoice == 1 and dt[atom_i] == 6): if (Hchoice == 1 and dt[atom_i] == 7): radius = 0.8 elif (Hchoice == 2 and (dt[atom_i] == 6 or dt[atom_i] == 7)): continue # go to nexed atom else: radius = vdw_dict[dt[atom_i]] #print atom.type, atom.X, atom.Y, atom.Z, atom.type, dt[atom_i], radius grid_i = round((atom.X - origin[0]) / gridscale) grid_j = round((atom.Y - origin[1]) / gridscale) grid_k = round((atom.Z - origin[2]) / gridscale) if (grid_i < 0.0 or grid_j < 0.0 or grid_k < 0.0): print "ERROR. . . " exit() radius_gridpoint = math.ceil(radius / gridscale) + 1 #print radius, gridscale, radius_gridpoint #print grid_i,grid_j, grid_k start_i = max([(grid_i - radius_gridpoint), 0.0]) stop_i = min([(grid_i + radius_gridpoint), xn]) start_j = max([(grid_j - radius_gridpoint), 0.0]) stop_j = min([(grid_j + radius_gridpoint), yn]) start_k = max([(grid_k - radius_gridpoint), 0.0]) stop_k = min([(grid_k + radius_gridpoint), zn]) ''' print "centerpoint:",grid_i, grid_j, grid_k print "i", start_i, stop_i print "j", start_i, stop_i print "k", start_i, stop_i ''' ''' count = 0 for i in range(xn): x = (i * gridscale) + origin[0] for j in range(yn): y = (j * gridscale) + origin[1] for k in range(zn): z = (k * gridscale) + origin[2] dist = distance([x,y,z],[atom.X,atom.Y,atom.Z]) if (dist <= radius): if not (count in dict_gridpoint): dict_gridpoint[count] = [atom_i] else: dict_gridpoint[count].append(atom_i) count = count+1 ''' for i in range(int(start_i), int( stop_i)): # looping over the cube about the center of the atom x = (i * gridscale) + origin[0] for j in range(int(start_j), int(stop_j)): y = (j * gridscale) + origin[1] for k in range(int(start_k), int(stop_k)): z = (k * gridscale) + origin[2] dist = distance([x, y, z], [atom.X, atom.Y, atom.Z]) if (dist <= radius): #count = i*((xn)**2)+j*(xn) + k count = i * (yn * zn) + j * (zn) + k if not (count in dict_gridpoint): dict_gridpoint[count] = [atom_i] else: dict_gridpoint[count].append(atom_i) sum_val = 0 sum_val_positive = 0 sum_val_negative = 0 voxel_vol = gridscale**3.0 # loop over all displaced grid points. for key in dict_gridpoint.keys(): # sum up total value as well as positive, and negative contrabutions. sum_val = sum_val + values[key] if values[key] > 0: sum_val_positive = sum_val_positive + values[key] else: sum_val_negative = sum_val_negative + values[key] # also calculate the per-atom gist decomposition. # if a point is shared by multiple atoms, divied the value by the # number of atoms that share that point and asign that fractional # value to each atom N = len(dict_gridpoint[key]) for atom_i in dict_gridpoint[key]: #print atom_i sum_per_atom[atom_i] = sum_per_atom[atom_i] + (values[key] / N) molN = len(dict_gridpoint.keys()) boxN = len(values) boxV = xn * gridscale * yn * gridscale * zn * gridscale molV = float(molN) / float(boxN) * boxV print "gist_val:", sum_val * voxel_vol print "gist_val_positive:", sum_val_positive * voxel_vol print "gist_val_negative:", sum_val_negative * voxel_vol print "molN=", molN, " boxN=", boxN, " boxV=", boxV print "molV=", molV fileh.write('%s,%f\n' % ("gist_val", sum_val * voxel_vol)) fileh.write('%s,%f\n' % ("gist_val_positive", sum_val_positive * voxel_vol)) fileh.write('%s,%f\n' % ("gist_val_negative", sum_val_negative * voxel_vol)) fileh.write('%s,%f\n' % ("molN", molN)) fileh.write('%s,%f\n' % ("boxN", boxN)) fileh.write('%s,%f\n' % ("boxV", boxV)) fileh.write('%s,%f\n' % ("molV", molV)) for i, atom in enumerate(mol.atom_list): print i, ":", sum_per_atom[i] * voxel_vol fileh.write('atom%d,%f\n' % (i + 1, sum_per_atom[i] * voxel_vol)) new_values = [] # make a new grid with only the voxels in the ligand are non-zerro if (return_vals): new_values = [] for i, val in enumerate(values): #if i in dict_gridpoint.keys(): if i in dict_gridpoint: new_values.append(val) else: new_values.append(0.0) return new_values
def calc_score(fileprefix, values, gridscale, xn, yn, zn, origin, mol, vdw_dict, fileh, return_vals, Hchoice): # file - log file # values gist values # gridscale - the grid spacing mol_name = mol.name if Hchoice != 0 and Hchoice != 1 and Hchoice != 2: print "Hchoice must be 0(use standard radius), 1 (use 0.8 for nonpolar H, instead of 1.540), or 2 (ignore H)" exit() dt = mol2.convert_sybyl_to_dock(mol) # get dock atom types. # loop over each atom. dict_gridpoint = {} # for each grid point have a list of atoms it is in sum_per_atom = [] for atom_i, atom in enumerate(mol.atom_list): sum_per_atom.append(0.0) #if (Hchoice == 1 and dt[atom_i] == 6): if (Hchoice == 1 and dt[atom_i] == 7): radius = 0.8 elif (Hchoice == 2 and (dt[atom_i] == 6 or dt[atom_i] == 7)): continue # go to nexed atom else: radius = vdw_dict[dt[atom_i]] #print atom.type, atom.X, atom.Y, atom.Z, atom.type, dt[atom_i], radius grid_i = round((atom.X - origin[0]) / gridscale) grid_j = round((atom.Y - origin[1]) / gridscale) grid_k = round((atom.Z - origin[2]) / gridscale) if (grid_i < 0.0 or grid_j < 0.0 or grid_k < 0.0): print "ERROR. . . " exit() radius_gridpoint = math.ceil(radius / gridscale) + 1 #print radius, gridscale, radius_gridpoint #print grid_i,grid_j, grid_k start_i = max([(grid_i - radius_gridpoint), 0.0]) stop_i = min([(grid_i + radius_gridpoint), xn]) start_j = max([(grid_j - radius_gridpoint), 0.0]) stop_j = min([(grid_j + radius_gridpoint), yn]) start_k = max([(grid_k - radius_gridpoint), 0.0]) stop_k = min([(grid_k + radius_gridpoint), zn]) ''' print "centerpoint:",grid_i, grid_j, grid_k print "i", start_i, stop_i print "j", start_i, stop_i print "k", start_i, stop_i ''' ''' count = 0 for i in range(xn): x = (i * gridscale) + origin[0] for j in range(yn): y = (j * gridscale) + origin[1] for k in range(zn): z = (k * gridscale) + origin[2] dist = distance([x,y,z],[atom.X,atom.Y,atom.Z]) if (dist <= radius): if not (count in dict_gridpoint): dict_gridpoint[count] = [atom_i] else: dict_gridpoint[count].append(atom_i) count = count+1 ''' for i in range(int(start_i), int( stop_i)): # looping over the cube about the center of the atom x = (i * gridscale) + origin[0] for j in range(int(start_j), int(stop_j)): y = (j * gridscale) + origin[1] for k in range(int(start_k), int(stop_k)): z = (k * gridscale) + origin[2] dist = distance([x, y, z], [atom.X, atom.Y, atom.Z]) if (dist <= radius): #count = i*((xn)**2)+j*(xn) + k scale = cal_gausian(dist, radius / 2.0) count = i * (yn * zn) + j * (zn) + k if not (count in dict_gridpoint): dict_gridpoint[count] = [[atom_i, scale]] else: dict_gridpoint[count].append([atom_i, scale]) sum_val = 0 sum_val_positive = 0 sum_val_negative = 0 voxel_vol = gridscale**3.0 # loop over all displaced grid points. for key in dict_gridpoint.keys(): key_sum = 0 for atom_i, scale in dict_gridpoint[key]: key_sum += -voxel_vol * values[key] * scale sum_val = sum_val + -1. * values[key] * scale print "gist_val:", sum_val * voxel_vol fileh.write('%f\n' % (sum_val * voxel_vol)) new_values = [] # make a new grid with only the voxels in the ligand are non-zerro if (return_vals): new_values = [] for i, val in enumerate(values): #if i in dict_gridpoint.keys(): if i in dict_gridpoint: new_values.append(val) else: new_values.append(0.0) return new_values
def calc_score(fileprefix, values, gridscale, xn, yn, zn, origin, mol, vdw_dict, fileh): # file - log file # values gist values # gridscale - the grid spacing # here the vector of values is transformed to a multidemitional array (grid) grid_old = [] count = 0 for i in range(xn): ydim = [] for j in range(yn): zdem = [] for k in range(zn): zdem.append(values[count]) count = count + 1 ydim.append(zdem) grid_old.append(ydim) dt = mol2.convert_sybyl_to_dock(mol) # get dock atom types. # loop over each atom. dict_gridpoint = {} # for each grid point have a list of atoms it is in sum_per_atom = [] for atom_i, atom in enumerate(mol.atom_list): sum_per_atom.append(0.0) radius = vdw_dict[dt[atom_i]] #print atom.type, atom.X, atom.Y, atom.Z, atom.type, dt[atom_i], radius grid_i = (atom.X - origin[0]) / gridscale grid_j = (atom.Y - origin[0]) / gridscale grid_k = (atom.Z - origin[0]) / gridscale #print grid_i,grid_j, grid_k count = 0 for i in range(xn): x = (i * gridscale) + origin[0] for j in range(yn): y = (j * gridscale) + origin[1] for k in range(zn): z = (k * gridscale) + origin[2] dist = distance([x, y, z], [atom.X, atom.Y, atom.Z]) if (dist <= radius): if not (count in dict_gridpoint): dict_gridpoint[count] = [atom_i] else: dict_gridpoint[count].append(atom_i) count = count + 1 sum_val = 0 sum_val_positive = 0 sum_val_negative = 0 voxel_vol = gridscale**3.0 # loop over all displaced grid points. for key in dict_gridpoint.keys(): # sum up total value as well as positive, and negative contrabutions. sum_val = sum_val + values[key] if values[key] > 0: sum_val_positive = sum_val_positive + values[key] else: sum_val_negative = sum_val_negative + values[key] # also calculate the per-atom gist decomposition. # if a point is shared by multiple atoms, divied the value by the # number of atoms that share that point and asign that fractional # value to each atom N = len(dict_gridpoint[key]) for atom_i in dict_gridpoint[key]: #print atom_i sum_per_atom[atom_i] = sum_per_atom[atom_i] + (values[key] / N) molN = len(dict_gridpoint.keys()) boxN = len(values) boxV = xn * gridscale * yn * gridscale * zn * gridscale molV = float(molN) / float(boxN) * boxV print "gist_val:", sum_val * voxel_vol print "gist_val_positive:", sum_val_positive * voxel_vol print "gist_val_negative:", sum_val_negative * voxel_vol print "molN=", molN, " boxN=", boxN, " boxV=", boxV print "molV=", molV fileh.write('%s,%f\n' % ("gist_val", sum_val * voxel_vol)) fileh.write('%s,%f\n' % ("gist_val_positive", sum_val_positive * voxel_vol)) fileh.write('%s,%f\n' % ("gist_val_negative", sum_val_negative * voxel_vol)) fileh.write('%s,%f\n' % ("molN", molN)) fileh.write('%s,%f\n' % ("boxN", boxN)) fileh.write('%s,%f\n' % ("boxV", boxV)) fileh.write('%s,%f\n' % ("molV", molV)) for i, atom in enumerate(mol.atom_list): print i, ":", sum_per_atom[i] * voxel_vol fileh.write('atom%d,%f\n' % (i + 1, sum_per_atom[i] * voxel_vol)) # make a new grid with only the voxels in the ligand are non-zerro new_values = [] for i, val in enumerate(values): if i in dict_gridpoint.keys(): new_values.append(val) else: new_values.append(0.0) return new_values