def run_align_group(grouped_files, index, n, protein, target, start, raw_root): for i, conformer in enumerate(grouped_files[index]): pair = '{}-to-{}'.format(target, start) protein_path = os.path.join(raw_root, protein) pair_path = os.path.join(protein_path, pair) output_path = os.path.join(pair_path, 'conformers') if not os.path.exists(output_path): os.mkdir(output_path) num = str(n * index + i) os.chdir(output_path) screen_file = os.path.join(output_path, "screen_{}.mae".format(num)) with structure.StructureWriter(screen_file) as screen: screen.append(conformer) shape_file = os.path.join(pair_path, '{}_lig.mae'.format(start)) run_cmd( _ALIGN_CMD.format(shape=shape_file, screen=screen_file, job_name=num)) aligned_conformer_file = os.path.join(output_path, '{}_align.maegz'.format(num)) aligned_conformer = list( structure.StructureReader(aligned_conformer_file))[0] build.delete_hydrogens(aligned_conformer) no_hydrogen_file = os.path.join( output_path, "{}_align_without_hydrogen.mae".format(num)) with structure.StructureWriter(no_hydrogen_file) as no_h: no_h.append(aligned_conformer)
def main(argv=sys.argv): global purpose if len(argv) != 4: print "\n Description:" print purpose print "\n Usage: %s in.maegz out.maegz out.log\n" % argv[0] print " in.maegz : ligands prepared via `ligprep`" print " out.maegz: to save newly generated ligands" print " out.log : to save atom number of each ligand's reaction center\n" sys.exit(1) assert os.path.exists(argv[1]) assert not os.path.exists(argv[2]) inf = structure.StructureReader(argv[1]) outf = structure.StructureWriter(argv[2]) outf_log = open(argv[3], "w") print >> outf_log, "ligand_title reaction_center" count_in = 0 count_out = 0 for ligand in inf: count_in += 1 new_ligands = process_ligand(ligand) if len(new_ligands) == 0: print "ligand `%s` doesn't match either `C=CC=O` or `[CH]=O`" % ( ligand.title) continue for st, atom_index in new_ligands: count_out += 1 outf.append(st) print >> outf_log, st.title, atom_index outf.close() outf_log.close() print "Totally read %d ligands. After processing, generated %d ligands!" % ( count_in, count_out)
def run_align_combine(process, raw_root): counter = 0 for protein, target, start in process: if counter == 10: break pair = '{}-to-{}'.format(target, start) protein_path = os.path.join(raw_root, protein) pair_path = os.path.join(protein_path, pair) conformer_file = os.path.join(pair_path, "{}_lig0-out.maegz".format(target)) conformers = list(structure.StructureReader(conformer_file)) if len(conformers) == 1: continue else: counter += 1 output_path = os.path.join(pair_path, 'conformers') combined_file = os.path.join( pair_path, "aligned_to_start_without_hydrogen_conformers.mae") with structure.StructureWriter(combined_file) as combined: for i in range(len(conformers)): aligned_file = os.path.join( output_path, '{}_align_without_hydrogen.mae'.format(i)) s = list(structure.StructureReader(aligned_file))[0] combined.append(s) print(len(list(structure.StructureReader(combined_file))))
def main(argv=sys.argv): if len(argv) != 4 and len(argv) != 5: print "\n Usage: %s in.maegz out_protein out_ligands [N]" % argv[0] print " in.maegz : files generated by glide dock" print " out_protein: protein in `in.maegz`." print " can be pdb, maegz et al." print " out_ligands: top `N` ligands sorted by `docking score`." print " can be sdf, maegz et al." print " [N] : if not given, all ligands will be extracted!!\n" sys.exit(1) if len(argv) == 5: n = int(argv[4]) else: n = 0 inf = structure.StructureReader(argv[1]) pro = inf.next() pro.write(argv[2]) outf = structure.StructureWriter(argv[3]) names = set() for ligand in inf: ligand.title = ligand.property['s_sd_IDNUMBER'] if ligand.title not in names: names.add(ligand.title) outf.append(ligand) if n and (len(names) == n): break outf.close()
def create_decoys(lig_file): """ creates MAX_DECOYS number of translated/rotated decoys :param lig_file: (string) file of glide ligand pose that will be translated/rotated :return: """ code = lig_file.split('/')[-1].split('_')[-1] if code == 'lig0.mae': modify_file(lig_file, '_pro_ligand') else: modify_file(lig_file, '_ligand') for i in range(MAX_DECOYS): s = list(structure.StructureReader(lig_file))[0] #translation x, y, z = random_three_vector() dist = np.random.normal(MEAN_TRANSLATION, STDEV_TRANSLATION) transform.translate_structure(s, x * dist, y * dist, z * dist) #rotation x_angle = np.random.uniform(MIN_ANGLE, MAX_ANGLE) y_angle = np.random.uniform(MIN_ANGLE, MAX_ANGLE) z_angle = np.random.uniform(MIN_ANGLE, MAX_ANGLE) rot_center = list(get_centroid(s)) transform.rotate_structure(s, x_angle, y_angle, z_angle, rot_center) decoy_file = lig_file[:-4] + chr(ord('a') + i) + '.mae' with structure.StructureWriter(decoy_file) as decoy: decoy.append(s) if code == 'lig0.mae': modify_file(decoy_file, lig_file.split('/')[-1]) else: modify_file(decoy_file, lig_file.split('/')[-1])
def create_cartesian_decoys(lig_file): """ creates MAX_DECOYS number of translated/rotated decoys :param lig_file: (string) file of glide ligand pose that will be translated/rotated :return: """ code = lig_file.split('/')[-1].split('_')[-1] if code == 'lig0.mae': modify_file(lig_file, '_pro_ligand') else: modify_file(lig_file, '_ligand') for i in range(6): s = list(structure.StructureReader(lig_file))[0] #translation x, y, z = cartesian_vector(i) dist = np.random.normal(MEAN_TRANSLATION, STDEV_TRANSLATION) transform.translate_structure(s, x * dist, y * dist, z * dist) decoy_file = lig_file[:-4] + chr(ord('a') + i) + '.mae' with structure.StructureWriter(decoy_file) as decoy: decoy.append(s) if code == 'lig0.mae': modify_file(decoy_file, lig_file.split('/')[-1]) else: modify_file(decoy_file, lig_file.split('/')[-1])
def compute_mcss(self, ligands, init_file, mcss_types_file, small=False): """ Compute the MCSS file by calling Schrodinger canvasMCSS. Updates instance with MCSSs present in the file """ structure_file = '{}.ligands.mae'.format(init_file) mcss_file = '{}.mcss.csv'.format(init_file) stwr = structure.StructureWriter(structure_file) stwr.append(ligands[self.l1]) stwr.append(ligands[self.l2]) stwr.close() # set the sizes in atoms of each of the ligands self._set_ligand_sizes(structure_file) if os.system( self.mcss_cmd.format(structure_file, mcss_file, 5 if small else 10, mcss_types_file)): assert False, 'MCSS computation failed' self._set_mcss(mcss_file) self.tried_small = small with open(init_file, 'a+') as fp: fp.write(str(self) + '\n') os.system('rm {} {}'.format(structure_file, mcss_file))
def minimization(): for filename in os.listdir("."): if filename.startswith("propka"): st = structure.StructureReader(filename).next() writer = structure.StructureWriter("min"+filename) minimize.minimize_structure(st) st.append("min"+filename)
def main(argv=sys.argv): if len(argv) != 3: print "\n OBJ: to extract covalent binding ligands" print "\n Usage: %s infile out.maegz" % argv[0] print " infile:" print " .maegz: docked file" print " .txt : one .maegz file per line" sys.exit(1) assert os.path.exists(argv[1]) and (not os.path.exists(argv[2])) outf = structure.StructureWriter(argv[2]) basename, ext = os.path.splitext(argv[1]) count = 0 if ext == ".txt": inf = open(argv[1], "r") for line in inf: inf_structures = structure.StructureReader(line.strip()) for complex_st in inf_structures: ligand = get_ligand(complex_st) outf.append(ligand) count += 1 inf.close() else: inf = structure.StructureReader(argv[1]) for complex_st in inf: ligand = get_ligand(complex_st) outf.append(ligand) count += 1 outf.close() print "Totally extracted %d ligands" % count
def mutate(infile): uu = [] for line in infile: uu.append(line) sorted_score = [l.split(', ') for l in uu] sorted_sc = sorted(sorted_score, key=itemgetter(0)) print(sorted_sc[0]) i = 0 for i in range(len(sorted_score)): list_mutations = [] for j in range(1, 5): #4 changed to 5 # Get the input structure if j == 1: reference_st = structure.StructureReader( 'PELE_PaDaI.mae').next() if j > 1: reference_st = structure.StructureReader( 'mutated_structures.mae').next() # Create the writer for the output file and append the reference writer = structure.StructureWriter('mutated_structures.mae') # writer.append(reference_st) list_mutations.append(str(sorted_sc[i][j])) # Define the residues and mutations residues = ["'A:" + sorted_sc[i][j] + "'"] muts = ['HIS'] # Get a compatible list of mutations. The above turns into # [('A', 22, 'DENQ')] mutations = protein.Mutator.convert_residue_list(residues, muts) # Construct the mutator mutator = protein.Mutator(reference_st, mutations) # Loop over each mutation for mutation in mutator.generate(): # mutated_structure = mutation.struct residue_map = mutation.residue_map res_str = ", ".join(str(res) for res in residue_map.values()) print 'Residues affected by this mutation: %s' % res_str # Do something with the mutated structure (refine maybe) writer.append(mutated_structure) os.system( "/gpfs/projects/bsc72/Schrodinger_SMP2/utilities/structconvert -imae mutated_structures.mae -opdb merged_" + str(i) + "_" + list_mutations[0] + "_" + list_mutations[1] + "_" + list_mutations[2] + "_" + list_mutations[3].rstrip() + ".pdb") i = i + 1 if i > 5000: break
def main(verbose, pH): import os import commands from schrodinger import structure # Requires Schrodinger Suite # Write input for epik. if verbose: print "Converting input file to Maestro format..." reader = structure.StructureReader("epik-input.mol2") writer = structure.StructureWriter("epik-input.mae") for st in reader: writer.append(st) reader.close() writer.close() # Run epik to enumerate protomers/tautomers and get associated state penalties. if verbose: print "Running Epik..." cmd = '%s/epik -imae epik-input.mae -omae epik-output.mae -pht 10.0 -ms 100 -nt -pKa_atom -ph %f -WAIT' % ( os.environ['SCHRODINGER'], pH) output = commands.getoutput(cmd) if verbose: print output # Convert output from epik from .mae to .sdf. if verbose: print "Converting output file to SDF..." reader = structure.StructureReader("epik-output.mae") writer = structure.StructureWriter("epik-output.sdf") for st in reader: writer.append(st) reader.close() writer.close() # Also convert to .mol2. if verbose: print "Converting output file to MOL2..." reader = structure.StructureReader("epik-output.mae") writer = structure.StructureWriter("epik-output.mol2") for st in reader: writer.append(st) reader.close() writer.close()
def mini(structures, frozen_atoms=None, fix_torsions=None): """ Takes many structures, minimizes them and returns the minimized structures. It's faster to do multiple structures at once. Arguments --------- structure : list of Schrödinger structure Returns ------- list of Schrödinger structure """ import schrodinger.application.macromodel.utils as mmodutils import schrodinger.job.jobcontrol as jobcontrol from setup_com_from_mae import MyComUtil print(' - ATTEMPTING MINI') sch_writer = sch_struct.StructureWriter('TEMP.mae') sch_writer.extend(structures) sch_writer.close() # Setup the minimization. com_setup = MyComUtil() com_setup.my_mini( mae_file='TEMP.mae', com_file='TEMP.com', out_file='TEMP_OUT.mae', frozen_atoms=frozen_atoms, fix_torsions=fix_torsions) command = ['bmin', '-WAIT', 'TEMP'] # Run the minimization. job = jobcontrol.launch_job(command) job.wait() # Read the minimized structures. sch_reader = sch_struct.StructureReader('TEMP_OUT.mae') new_structures = [] for structure in sch_reader: new_structures.append(structure) sch_reader.close() if len(new_structures) > 0: print(' - MINI SUCCEEDED') structures = [new_structures[0]] else: print(' - MINI FAILED. CONTINUING W/O MINI') if DEBUG: raw_input('Press any button to continue.') # Remove temporary files. os.remove('TEMP.mae') os.remove('TEMP.com') os.remove('TEMP_OUT.mae') os.remove('TEMP.log') return structures
def main(opts): """ Main for merge. Returns ------- list of Schrodinger structures """ structures = merge_many_filenames(opts.group) print('-' * 80) print('END NUMBER STRUCTURES: {}'.format(len(structures))) if opts.mini: structures = mini(structures) new_structures = [] for structure in structures: new_structures.append(add_chirality(structure)) structures = new_structures # All output below. # Write structures to a single file. if opts.output: print('OUTPUT FILE: {}'.format(opts.output)) sch_writer = sch_struct.StructureWriter(opts.output) sch_writer.extend(structures) sch_writer.close() # Write structures to a directory. if opts.directory: print('OUTPUT DIRECTORY: {}'.format(opts.directory)) for structure in structures: path = make_unique_filename( os.path.join( opts.directory, structure.property['s_m_title'] + '.mae')) filename = os.path.basename(path) print(' * WRITING : {}'.format(filename)) sch_writer = sch_struct.StructureWriter(path) sch_writer.append(structure) sch_writer.close() return structures
def create_conformer_decoys(conformers, grid_size, start_lig_center, prot, pose_path, target, max_poses, min_angle, max_angle): num_iter_without_pose = 0 num_valid_poses = 1 grid = [] for dx in range(-grid_size, grid_size): for dy in range(-grid_size, grid_size): for dz in range(-grid_size, grid_size): grid.append([[dx, dy, dz], 0]) while num_valid_poses < max_poses: num_iter_without_pose += 1 conformer = random.choice(conformers) conformer_center = list(get_centroid(conformer)) # translation index = random.randint(0, len(grid) - 1) grid_loc = grid[index][0] transform.translate_structure( conformer, start_lig_center[0] - conformer_center[0] + grid_loc[0], start_lig_center[1] - conformer_center[1] + grid_loc[1], start_lig_center[2] - conformer_center[2] + grid_loc[2]) conformer_center = list(get_centroid(conformer)) # rotation x_angle = np.random.uniform(min_angle, max_angle) y_angle = np.random.uniform(min_angle, max_angle) z_angle = np.random.uniform(min_angle, max_angle) transform.rotate_structure(conformer, x_angle, y_angle, z_angle, conformer_center) if steric_clash.clash_volume(prot, struc2=conformer) < 200: decoy_file = os.path.join( pose_path, "{}_lig{}.mae".format(target, num_valid_poses)) with structure.StructureWriter(decoy_file) as decoy: decoy.append(conformer) modify_file(decoy_file, '_pro_ligand') modify_file(decoy_file, '{}_lig0.mae'.format(target)) num_valid_poses += 1 grid[index][1] = 0 num_iter_without_pose = 0 elif num_iter_without_pose == 5 and len(grid) > 1: max_val = max(grid, key=lambda x: x[1]) grid.remove(max_val) num_iter_without_pose = 0 else: grid[index][1] += 1
def create_muts(ligand, ligands): cutoff = 2 conflict_dict = {} conflict_dict[ligand] = {} for target in ligands: if ligand != target: start_ending = '{}/structures/aligned_files/{}/{}_out.mae'.format( protein, ligand, ligand) start_s = list( structure.StructureReader(combind_root + start_ending))[0] target_ending = '{}/structures/aligned_files/{}/{}_out.mae'.format( protein, target, target) target_s = list( structure.StructureReader(combind_root + target_ending))[0] mutate_list = [] mutate_info = [] for m in list(start_s.molecule): if len(m.residue) != 1: for r in list(m.residue): r_atoms = [a.index for a in list(r.atom)] target_lig = [ a.index for a in target_s.atom if a.chain == 'L' ] clash = steric_clash.clash_volume( start_s, r_atoms, target_s, target_lig) if clash > cutoff: mutate_info.append({ 'Name': r.pdbres, 'Number': r.resnum, 'Clash volume': clash }) mutate_list.append(list(r.atom)[0]) conflict_dict[ligand][target] = mutate_info for atom in mutate_list: build.mutate(start_s, atom, 'ALA') prot_st = start_s.extract( [a.index for a in start_s.atom if a.chain != 'L']) prot_wr = structure.StructureWriter('{}/{}_to_{}.mae'.format( save_location, target, ligand)) prot_wr.append(prot_st) prot_wr.close() with open( '/home/users/sidhikab/flexibility_project/mutations/Data/conflict/' + ligand, 'wb') as outfile: pickle.dump(conflict_dict, outfile)
def mcmm(structures, frozen_atoms=None): """ Takes many structures, and does a short MCMM search on them. Arguments --------- structure : list of Schrödinger structure Returns ------- list of Schrödinger structure """ import schrodinger.application.macromodel.utils as mmodutils import schrodinger.job.jobcontrol as jobcontrol from setup_com_from_mae import MyComUtil print(' - ATTEMPTING MCMM') sch_writer = sch_struct.StructureWriter('TEMP.mae') sch_writer.extend(structures) sch_writer.close() com_setup = MyComUtil() com_setup.my_mcmm( mae_file='TEMP.mae', com_file='TEMP.com', out_file='TEMP_OUT.mae', nsteps=50, frozen_atoms=frozen_atoms) command = ['bmin', '-WAIT', 'TEMP'] job = jobcontrol.launch_job(command) job.wait() sch_reader = sch_struct.StructureReader('TEMP_OUT.mae') new_structures = [] for structure in sch_reader: new_structures.append(structure) sch_reader.close() if len(new_structures) > 0: print(' - MCMM SUCCEEDED') structures = [new_structures[0]] else: print(' - MCMM FAILED. CONTINUING W/O MCMM') if DEBUG: raw_input('Press any button to continue.') # Remove temporary files. os.remove('TEMP.mae') os.remove('TEMP.com') os.remove('TEMP_OUT.mae') os.remove('TEMP.log') return structures
def pdb_to_mae(pdb_inputfile, schr_path, mae_output_file=None, remove=False): # Get output name from file file_info = pdb_inputfile.split("_") if not mae_output_file: dirpath = os.path.join(os.path.dirname(pdb_inputfile)) filename = "{}_{}.mae".format(file_info[-3], file_info[-2]) mae_output_file = os.path.join(dirpath, filename) # Get properties from name properties = { "BindingEnergy": float(file_info[-1].replace("BindingEnergy", "").replace(".pdb", "")), "epoch": int(file_info[-2].split(".")[0]), "trajectory": file_info[-2].split(".")[1] } # Convert to mae file pdb_convert = os.path.join(schr_path, "utilities/pdbconvert") os.system("{} -ipdb {} -omae {}".format(pdb_convert, pdb_inputfile, mae_output_file)) # Set properties to mae_file mae_file = MaeFile(mae_output_file) for Property, value in properties.items(): if type(value) == str: proper = mae_file.set_property(Property, value, typedata="s") if type(value) == int: proper = mae_file.set_property(Property, value, typedata="i") if type(value) == float: proper = mae_file.set_property(Property, value, typedata="r") # output maestro file with st.StructureWriter(mae_output_file) as writer: writer.append(mae_file._structure) if remove: os.remove(pdb_inputfile)
def main(argv=sys.argv): if len(argv) != 4: print "\n Usage: %s prepare.log docked.maegz out.maegz" % argv[0] print " prepare.log : from 2nd line on, each should be `title reactive_center`" print " docked.maegz: generated by glide docking" print " out.maegz : only those whose closest atom within (7.38, -12.05, 0.06) r=1A" print " was in `prepare.log` will be saved." sys.exit(1) assert not os.path.exists(argv[3]) inf_log = open(argv[1], "r") line = inf_log.readline() info = {} for line in inf_log: line = line.split() if not info.has_key(line[0]): info[line[0]] = set() info[line[0]].add(int(line[1])) inf_log.close() inf = structure.StructureReader(argv[2]) recp = inf.next() outf = structure.StructureWriter(argv[3]) outf.append(recp) count = 0 for lig in inf: atom_index_list = find_closest(lig) find = False for atom_index in atom_index_list: if atom_index in info[lig.title]: find = True break if find: count += 1 outf.append(lig) outf.close() print "totally found %d molecules satisfying the criterion `%s`" % ( count, argv[1])
def main(): """ Main body of the script. """ constraint_at_list = [] outfile_list = [] infile_list = [] comfile_list = [] logfile_list = [] cmd_args = parse_args() constraints_enabled = check_args(cmd_args) if len(cmd_args.constrain_by_index): constraint_at_list = cmd_args.constrain_by_index.split(",") # BEN basename, comfile, inmaefile, outmaefile, logfile = \ create_com_file(cmd_args.infile, cmd_args, constraint_at_list) outfile_list.append(outmaefile) infile_list.append(inmaefile) comfile_list.append(comfile) logfile_list.append(logfile) subprocess.call([BMIN, "-NOJOBID", "-LOCAL", basename]) writer = structure.StructureWriter(cmd_args.outfile) for out in outfile_list: for st in structure.StructureReader(out): writer.append(st) writer.close() file_list = comfile_list + outfile_list + infile_list + logfile_list
'i_m_formal_charge', 's_m_color_rgb', 's_m_atom_name', 's_m_atomic_number', 's_m_label_format', 'i_m_label_color', 's_m_label_user_text', 's_m_grow_name', 'i_m_sculpting_atom_index', 'i_m_sculpting_constraint', 'i_sd_original_parity' ] if __name__ == '__main__': structure_reader = structure.StructureReader(sys.argv[1]) structure_writer = structure.StructureWriter(sys.argv[2]) for structure in structure_reader: for prop in PROPERTIES_TO_REMOVE: try: del structure.property[prop] except KeyError: pass for atom in structure.atom: for prop in ATOM_PROPERTIES_TO_REMOVE: try: del atom.property[prop] except KeyError: pass except ValueError: pass
r.atom )[0].chain == "A" and r.pdbres == res_data[ 'name'] and r.resnum == res_data['num']: if res_data['rmsd'] > cutoff: mutate_info.append({ 'Name': res_data['name'], 'Number': res_data['num'], 'RMSD': res_data['rmsd'] }) mutate_list.append(list(r.atom)[0]) counter += 1 mut_dict[start][target] = mutate_info for atom in mutate_list: build.mutate(s, atom, 'ALA') prot_st = s.extract( [a.index for a in s.atom if a.chain != 'L']) prot_wr = structure.StructureWriter('{}/{}_to_{}.mae'.format( save_location, target, start)) prot_wr.append(prot_st) prot_wr.close() with open('/home/users/sidhikab/flexibility_project/mutations/Data/mut4', 'wb') as outfile: pickle.dump(mut_dict, outfile)
'r_cs_torc_a5', 'r_cs_torc_a6', 'i_cs_torc_b1', 'i_cs_torc_b4', 'r_cs_torc_b5', 'r_cs_torc_b6' ] # Updates for new format. CONV_DIC = { 'i_cs_torc_1': 'i_cs_torc_a1', 'i_cs_torc_2': 'i_cs_torc_a4', 'r_cs_torc_5': 'r_cs_torc_a5', 'r_cs_torc_6': 'r_cs_torc_a6' } if __name__ == "__main__": for filename in sys.argv[1:]: structure_reader = sch_struct.StructureReader(filename) structure_writer = sch_struct.StructureWriter('TEMP.mae') for structure in structure_reader: for prop in PROPERTIES_TO_REMOVE: try: del structure.property[prop] except KeyError: pass # Change the name too. Why not. structure.property['s_m_title'] = \ structure.property['s_m_entry_name'] = \ os.path.splitext( os.path.basename(filename))[0] for atom in structure.atom: for prop in ATOM_PROPERTIES_TO_REMOVE: try:
def create_com_file(inFilename, cmd_args, constraint_at_list): """ Create the MacroModel com file. @param inFilename: filename. @type inFilename: string @param cmd_args: All script arguments and options. @type cmd_args: class:`argparse.Namespace` @param constraint_at_list: List of atom indices to constrain of fix. @type constraint_at_list: list @return: Filenames @rtype: str, str, str, str, str """ line3 = None line4 = None line5 = None basename = fileutils.get_basename(cmd_args.outfile) comfile = basename + ".com" inmaefile = basename + "-in.mae" outmaefile = basename + "-out.mae" logfile = basename + ".log" writer = structure.StructureWriter(inmaefile) for i, st in enumerate(structure.StructureReader(inFilename)): writer.append(st) writer.close() line1 = (" MMOD 0 1 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") if cmd_args.forcefield != "MMFFs": line2 = (" FFLD" + str(FF_DICT[cmd_args.forcefield]).rjust(8) + " 1 0 0 1.0000 0.0000 0.0000 " "0.0000" + "\n") else: line2 = (" FFLD" + str(FF_DICT[cmd_args.forcefield]).rjust(8) + " 1 0 1 1.0000 0.0000 0.0000 " "0.0000" + "\n") if cmd_args.solvent == "None": line5 = ( " BDCO 0 0 0 0 41.5692 99999.0000 " "0.0000 0.0000" + "\n") elif cmd_args.solvent == "Water": line3 = ( " SOLV 3 1 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line4 = ( " EXNB 0 0 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line5 = ( " BDCO 0 0 0 0 89.4427 99999.0000 " "0.0000 0.0000" + "\n") elif cmd_args.solvent == "Octanol": line3 = ( " SOLV 3 9 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line4 = ( " EXNB 0 0 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line5 = ( " BDCO 0 0 0 0 89.4427 99999.0000 " "0.0000 0.0000" + "\n") elif cmd_args.solvent == "CHCL3": line3 = ( " SOLV 3 5 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line4 = ( " EXNB 0 0 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line5 = ( " BDCO 0 0 0 0 89.4427 99999.0000 " "0.0000 0.0000" + "\n") line5b = (" BGIN 0 0 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line6 = (" READ 0 0 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") line7 = (" CONV 2 0 0 0" + str("%.4f" % float(cmd_args.convergence)).rjust(11) + " 0.0000 0.0000 0.0000" + "\n") if cmd_args.mini_method != "TNCG": line8 = (" MINI" + str(MM_DICT[cmd_args.mini_method]).rjust(8) + " 0" + str(cmd_args.mini_steps).rjust(7) + " 0 0.0000 0.0000 0.0000 0.0000" + "\n") else: line8 = (" MINI 9 1" + str(cmd_args.mini_steps).rjust(7) + " 0 0.0000 0.0000 0.0000 0.0000" + "\n") line9 = (" END 0 0 0 0 0.0000 0.0000 " "0.0000 0.0000" + "\n") with open(comfile, "w") as com_file: com_file.write(inmaefile + "\n") com_file.write(outmaefile + "\n") com_file.write(line1) com_file.write(line2) if line3 is not None: com_file.write(line3) com_file.write(line4) com_file.write(line5) else: com_file.write(line5) com_file.write(line5b) com_file.write(line6) if len(constraint_at_list): for at in constraint_at_list: if (cmd_args.frozenHeavy is True or len(cmd_args.frozenSmarts) or len(cmd_args.constrain_by_coord)): line = (" FXAT " '{:>7}'.format(at) + " 0 0 0 -1.0000 0.0000 " "0.0000 0.0000" + "\n") com_file.write(line) elif cmd_args.fixedHeavy is True or len(cmd_args.fixedSmarts): line = ( " FXAT " '{:>7}'.format(at) + " 0 0 0" + '{:>11}'.format('%.4f' % cmd_args.constraintForce) + '{:>11}'.format('%.4f' % cmd_args.constraintWidth) + " 0.0000 0.0000" + "\n") com_file.write(line) # BEN if len(cmd_args.constrain_by_index): line = (" FXTA " '{:>7}'.format(constraint_at_list[0]) + '{:>7}'.format(constraint_at_list[1]) + '{:>7}'.format(constraint_at_list[2]) + '{:>7}'.format(constraint_at_list[3]) + " 5000.0000 999.0000 0.0000 0.0000\n") # " 99.0000 999.0000 0.0000 0.0000\n") com_file.write(line) com_file.write(line7) com_file.write(line8) com_file.write(line9) return basename, comfile, inmaefile, outmaefile, logfile
def add_to_mae(filename, output, comp, tors, rca4, chig, torc): """ Adds properties to atoms and bonds in a *.mae file. The properties it adds were extracted from MacroModel conformational search *.com files. Arguments --------- filename : string Name of input .mae file. output : string Name of output .mae file. comp : list of integers Atom numbers for COMP atoms. tors : list of tuples of length 2 Each tuple is atoms assigned to a TORS command. rca4 : list of tuples of length 4 Each tuple is the indices of 4 atoms used to describe a ring break required for MacroModel conformational searches. chig : list of integers Atom indices for chiral centers. torc : list of tuples of length 6 Each tuple is the indices of 4 atoms used to describe a torsion check and 2 real numbers used to describe the abs(min) and abs(max) value of a torsion. """ structure_reader = sch_struct.StructureReader(filename) structure_writer = sch_struct.StructureWriter('TEMP.mae') tors_set = [set(x) for x in tors] for structure in structure_reader: # Copy over which atoms should go with COMP. print('SETUP COMP:') for one_comp in comp: atom = structure.atom[one_comp] atom.property['b_cs_comp'] = 1 print(' * {:>4}/{:2}'.format(atom.index, atom.atom_type_name)) # Copy over which atoms should go with CHIG. print('SETUP CHIG:') for one_chig in chig: atom = structure.atom[one_chig] atom.property['b_cs_chig'] = 1 print(' * {:>4}/{:2}'.format(atom.index, atom.atom_type_name)) # Set all remaining b_cs_comp and b_cs_chig to 0. for atom in structure.atom: if not atom.index in comp: atom.property['b_cs_comp'] = 0 if not atom.index in chig: atom.property['b_cs_chig'] = 0 print('SETUP TORS:') for one_tors in tors: bond = structure.getBond(one_tors[0], one_tors[1]) bond.property['b_cs_tors'] = 1 print(' * {:>4}/{:2} {:>4}/{:2}'.format( bond.atom1.index, bond.atom1.atom_type_name, bond.atom2.index, bond.atom2.atom_type_name)) # Add RCA4 properties. print('SETUP RCA4:') for one_rca4 in rca4: bond = structure.getBond(one_rca4[1], one_rca4[2]) bond.property['i_cs_rca4_1'] = one_rca4[0] bond.property['i_cs_rca4_2'] = one_rca4[3] print(' * {:>4} {:>4}/{:2} {:>4}/{:2} {:>4}'.format( bond.property['i_cs_rca4_1'], bond.atom1.index, bond.atom1.atom_type_name, bond.atom2.index, bond.atom2.atom_type_name, bond.property['i_cs_rca4_2'])) print('SETUP TORC:') for one_torc in torc: bond = structure.getBond(one_torc[1], one_torc[2]) if 'i_cs_torc_a1' not in bond.property or \ not bond.property['i_cs_torc_a1']: bond.property['i_cs_torc_a1'] = one_torc[0] bond.property['i_cs_torc_a4'] = one_torc[3] bond.property['r_cs_torc_a5'] = one_torc[4] bond.property['r_cs_torc_a6'] = one_torc[5] # Might be nice to expand this to include the min and max torsion # values. print(' * {:>4} {:>4}/{:2} {:>4}/{:2} {:>4}'.format( bond.property['i_cs_torc_a1'], bond.atom1.index, bond.atom1.atom_type_name, bond.atom2.index, bond.atom2.atom_type_name, bond.property['i_cs_torc_a4'])) else: bond.property['i_cs_torc_b1'] = one_torc[0] bond.property['i_cs_torc_b4'] = one_torc[3] bond.property['r_cs_torc_b5'] = one_torc[4] bond.property['r_cs_torc_b6'] = one_torc[5] # Might be nice to expand this to include the min and max torsion # values. print(' * {:>4} {:>4}/{:2} {:>4}/{:2} {:>4}'.format( bond.property['i_cs_torc_b1'], bond.atom1.index, bond.atom1.atom_type_name, bond.atom2.index, bond.atom2.atom_type_name, bond.property['i_cs_torc_b4'])) # Set i_cs_rca4_1, i_cs_rca4_2 and b_cs_tors to 0 for all other bonds. for bond in structure.bond: if not 'i_cs_rca4_1' in bond.property: bond.property['i_cs_rca4_1'] = 0 if not 'i_cs_rca4_2' in bond.property: bond.property['i_cs_rca4_2'] = 0 if not 'b_cs_tors' in bond.property: bond.property['b_cs_tors'] = 0 if not 'i_cs_torc_a1' in bond.property: bond.property['i_cs_torc_a1'] = 0 if not 'i_cs_torc_a4' in bond.property: bond.property['i_cs_torc_a4'] = 0 if not 'r_cs_torc_a5' in bond.property: bond.property['r_cs_torc_a5'] = 0 if not 'r_cs_torc_a6' in bond.property: bond.property['r_cs_torc_a6'] = 0 if not 'i_cs_torc_b1' in bond.property: bond.property['i_cs_torc_b1'] = 0 if not 'i_cs_torc_b4' in bond.property: bond.property['i_cs_torc_b4'] = 0 if not 'r_cs_torc_b5' in bond.property: bond.property['r_cs_torc_b5'] = 0 if not 'r_cs_torc_b6' in bond.property: bond.property['r_cs_torc_b6'] = 0 structure_writer.append(structure) structure_writer.close() structure_reader.close() os.rename('TEMP.mae', output) print('WROTE: {}'.format(output))
def main(): parser = argparse.ArgumentParser() parser.add_argument('task', type=str, help='either all, group, check, or MAPK14') parser.add_argument('docked_prot_file', type=str, help='file listing proteins to process') parser.add_argument('run_path', type=str, help='directory where script and output files will be written') parser.add_argument('raw_root', type=str, help='directory where raw data will be placed') parser.add_argument('--index', type=int, default=-1, help='for group task, group number') args = parser.parse_args() if args.task == 'all': process = get_prots(args.docked_prot_file) grouped_files = group_files(N, process) if not os.path.exists(args.run_path): os.mkdir(args.run_path) for i, group in enumerate(grouped_files): cmd = 'sbatch -p owners -t 1:00:00 -o {} --wrap="$SCHRODINGER/run python3 lig_extractor.py group {} {} {} ' \ '--index {}"' os.system(cmd.format(os.path.join(args.run_path, 'lig{}.out'.format(i)), args.docked_prot_file, args.run_path, args.raw_root, i)) if args.task == 'group': process = get_prots(args.docked_prot_file) grouped_files = group_files(N, process) for protein, target, start in grouped_files[args.index]: protein_path = os.path.join(args.raw_root, protein) pair_path = os.path.join(protein_path, '{}-to-{}'.format(target, start)) pose_path = os.path.join(pair_path, 'cartesian_ligand_poses') pv_file = os.path.join(pair_path, '{}-to-{}_glide_pv.maegz'.format(target, start)) num_poses = len(list(structure.StructureReader(pv_file))) for i in range(1, num_poses): if i == MAX_POSES: break with structure.StructureWriter(os.path.join(pose_path, '{}_lig{}.mae'.format(target, i))) as all: all.append(list(structure.StructureReader(pv_file))[i]) break if args.task == 'check': process = [] num_pairs = 0 with open(args.docked_prot_file) as fp: for line in fp: if line[0] == '#': continue protein, target, start = line.strip().split() num_pairs += 1 protein_path = os.path.join(args.raw_root, protein) pair_path = os.path.join(protein_path, '{}-to-{}'.format(target, start)) pose_path = os.path.join(pair_path, 'ligand_poses') pv_file = os.path.join(pair_path, '{}-to-{}_pv.maegz'.format(target, start)) num_poses = min(MAX_POSES, len(list(structure.StructureReader(pv_file)))) if not os.path.join(pose_path, '{}_lig{}.mae'.format(target, num_poses)): process.append((protein, target, start)) print('Missing', len(process), '/', num_pairs) print(process) if args.task == 'MAPK14': protein = 'MAPK14' ligs = ['3D83', '4F9Y'] for target in ligs: for start in ligs: if target != start: file = os.path.join(args.save_root, '{}/{}-to-{}/{}-to-{}_pv.maegz'.format(protein, target, start, target, start)) num_poses = len(list(structure.StructureReader(file))) for i in range(1, num_poses): if i > MAX_POSES: break with structure.StructureWriter( '{}/{}/{}-to-{}/{}_lig{}.mae'.format(args.save_root, protein, target.lower(), start.lower(), target.lower(), str(i))) as all: all.append(list(structure.StructureReader(file))[i])
def generate_zeolite_cluster(silicon_atom_list, oxygen_atom_list, close_atom_list, all_atom_list, guest_atom_list, complex_st, cmd_args): """ Determine the capping atoms. Find the next shell of atoms around the close atoms, store them and delete all other atoms. Convert the last shell of atoms to proton and adjust their bond lengths. @param silicon_atom_list: List of all silicon atoms. @type silicon_atom_list: list @param oxygen_atom_list: List of all oxygen atoms. @type oxygen_atom_list: list @param close_atom_list: List of close atoms. @type close_atom_list: list @param all_atom_list: List of all atom in the structure. @type all_atom_list: list @param guest_atom_list: List of all guest atoms in the structure. @type guest_atom_list: list @param complex_st: Merged structure of the zeolite and guest molecules. @type complex_st: L{structure.Structure} @param cmd_args: All script arguments and options. @type cmd_args: class:`argparse.Namespace` @return: List of the final capping atoms based on the new st atom numbers. @rtype: list """ final_cap_at = [] si_cap_atoms = generate_capping_atoms(silicon_atom_list, close_atom_list, complex_st) ox_cap_atoms = generate_capping_atoms(oxygen_atom_list, close_atom_list, complex_st) extended_atoms = list(set(si_cap_atoms + ox_cap_atoms)) capping_atoms = list(set(extended_atoms) - set(close_atom_list)) for subset in itertools.combinations(capping_atoms, 2): if complex_st.areBound(subset[0], subset[1]) is True: complex_st.deleteBond(subset[0], subset[1]) delete_atom_list = list( set(all_atom_list) - set(extended_atoms) - set(guest_atom_list)) atom_map = complex_st.deleteAtoms(delete_atom_list, renumber_map=True) for cap_at in capping_atoms: if cap_at in atom_map: mod_at = complex_st.atom[atom_map[cap_at]] if mod_at.element == "O": bond_length = 1.4 else: bond_length = 0.9 final_cap_at.append(mod_at.index) mod_at.element = "H" mod_at.atom_type = 42 mod_at.color = "white" num_atoms = mm.mmct_ct_get_atom_total(complex_st) bs = mmbitset.Bitset(size=num_atoms) for bond_at in mod_at.bonded_atoms: mm.mmct_atom_set_distance(bond_length, complex_st, bond_at, complex_st, mod_at, bs) writer = structure.StructureWriter(cmd_args.outfile) writer.append(complex_st) writer.close() return complex_st, final_cap_at
def main(): parser = argparse.ArgumentParser() parser.add_argument('task', type=str, help='either align or search') parser.add_argument('docked_prot_file', type=str, help='file listing proteins to process') parser.add_argument( 'run_path', type=str, help='directory where script and output files will be written') parser.add_argument('raw_root', type=str, help='directory where raw data will be placed') parser.add_argument('--protein', type=str, default='', help='protein name') parser.add_argument('--target', type=str, default='', help='target ligand name') parser.add_argument('--start', type=str, default='', help='start ligand name') parser.add_argument('--align_n', type=int, default=10, help='number of alignments processed in each job') parser.add_argument('--rotation_search_step_size', type=int, default=1, help='step size between each angle ' 'checked, in degrees') parser.add_argument('--index', type=int, default=-1, help='grid point group index') parser.add_argument( '--rmsd_cutoff', type=int, default=2, help='rmsd accuracy cutoff between predicted ligand pose ' 'and true ligand pose') parser.add_argument('--num_conformers', type=int, default=300, help='maximum number of conformers considered') parser.add_argument('--grid_size', type=int, default=6, help='grid size in positive and negative x, y, z ' 'directions') parser.add_argument('--grid_n', type=int, default=30, help='number of grid_points processed in each job') parser.add_argument('--time', dest='get_time', action='store_true') parser.add_argument('--no_time', dest='get_time', action='store_false') parser.set_defaults(get_time=False) parser.add_argument('--remove_prot_h', dest='no_prot_h', action='store_true') parser.add_argument('--keep_prot_h', dest='no_prot_h', action='store_false') parser.set_defaults(no_prot_h=False) parser.add_argument('--prot_pocket_only', dest='pocket_only', action='store_true') parser.add_argument('--all_prot', dest='pocket_only', action='store_false') parser.set_defaults(pocket_only=False) args = parser.parse_args() random.seed(0) if not os.path.exists(args.run_path): os.mkdir(args.run_path) pair = '{}-to-{}'.format(args.target, args.start) protein_path = os.path.join(args.raw_root, args.protein) pair_path = os.path.join(protein_path, pair) if args.task == 'conformer_all': process = get_prots(args.docked_prot_file) random.shuffle(process) run_conformer_all(process, args.raw_root, args.run_path, args.docked_prot_file) elif args.task == 'conformer_group': target_lig_file = os.path.join(pair_path, 'ligand_poses', '{}_lig0.mae'.format(args.target)) gen_ligand_conformers(target_lig_file, pair_path, args.num_conformers) if os.path.exists( os.path.join(pair_path, '{}_lig0.log'.format(args.target))): os.remove( os.path.join(pair_path, '{}_lig0.log'.format(args.target))) if args.task == 'conformer_check': process = get_prots(args.docked_prot_file) random.shuffle(process) run_conformer_check(process, args.raw_root) if args.task == 'align_all': process = get_prots(args.docked_prot_file) random.shuffle(process) run_align_all(process, args.raw_root, args.run_path, args.docked_prot_file, args.align_n) elif args.task == 'align_group': grouped_files = get_conformer_groups(args.align_n, args.target, args.start, args.protein, args.raw_root) run_align_group(grouped_files, args.index, args.n, args.protein, args.target, args.start, args.raw_root) elif args.task == 'align_check': process = get_prots(args.docked_prot_file) random.shuffle(process) run_align_check(process, args.raw_root) elif args.task == 'align_combine': process = get_prots(args.docked_prot_file) random.shuffle(process) run_align_combine(process, args.raw_root) elif args.task == 'run_search': process = get_prots(args.docked_prot_file) random.shuffle(process) grouped_files = get_grid_groups(args.grid_size, args.grid_n) search_system_caller(process, args.raw_root, args.run_path, args.docked_prot_file, args.rotation_search_step_size, args.grid_size, grouped_files) elif args.task == 'search': grouped_files = get_grid_groups(args.grid_size, args.grid_n) run_search(args.protein, args.target, args.start, args.index, args.raw_root, args.get_time, args.rmsd_cutoff, args.rotation_search_step_size, grouped_files[args.index], args.no_prot_h, args.pocket_only) elif args.task == 'check_search': process = get_prots(args.docked_prot_file) random.shuffle(process) grouped_files = get_grid_groups(args.grid_size, args.grid_n) counter = 0 unfinished = [] for protein, target, start in process: if counter == 10: break pair = '{}-to-{}'.format(target, start) protein_path = os.path.join(args.raw_root, protein) pair_path = os.path.join(protein_path, pair) conformer_file = os.path.join(pair_path, "{}_lig0-out.maegz".format(target)) conformers = list(structure.StructureReader(conformer_file)) if len(conformers) == 1: continue else: counter += 1 save_folder = os.path.join( os.getcwd(), 'decoy_timing_data', '{}_{}-to-{}'.format(protein, target, start)) for i in range(len(grouped_files)): if not os.path.exists( os.path.join(save_folder, '{}.csv'.format(i))): unfinished.append((protein, target, start, i)) print("Missing:", len(unfinished)) print(unfinished) elif args.task == 'test_search': run_test_search(args.protein, args.target, args.start, args.raw_root, args.rmsd_cutoff, args.rotation_search_step_size, pair_path, args.no_prot_h, args.pocket_only, args.get_time) elif args.task == 'get_grid_data': process = get_prots(args.docked_prot_file) random.shuffle(process) grouped_files = get_grid_groups(args.grid_size, args.grid_n) get_data(process, grouped_files, args.raw_root, args.grid_size) elif args.task == 'combine_search_data': process = get_prots(args.docked_prot_file) random.shuffle(process) grouped_files = get_grid_groups(args.grid_size, args.grid_n) get_data(process, grouped_files, args.raw_root, args.grid_size, True) elif args.task == 'get_dist': process = get_prots(args.docked_prot_file) random.shuffle(process) counter = 0 for protein, target, start in process: if counter == 10: break pair = '{}-to-{}'.format(target, start) protein_path = os.path.join(args.raw_root, protein) pair_path = os.path.join(protein_path, pair) conformer_file = os.path.join(pair_path, "{}_lig0-out.maegz".format(target)) conformers = list(structure.StructureReader(conformer_file)) if len(conformers) == 1: continue else: counter += 1 start_lig_file = os.path.join(pair_path, '{}_lig.mae'.format(start)) start_lig = list(structure.StructureReader(start_lig_file))[0] start_lig_center = list(get_centroid(start_lig)) target_lig_file = os.path.join(pair_path, 'ligand_poses', '{}_lig0.mae'.format(target)) target_lig = list(structure.StructureReader(target_lig_file))[0] target_lig_center = list(get_centroid(target_lig)) dist = math.sqrt(( (start_lig_center[0] - target_lig_center[0])**2) + ( (start_lig_center[1] - target_lig_center[1])**2) + ((start_lig_center[2] - target_lig_center[2])**2)) print(protein, target, start, dist) elif args.task == 'test_rotate_translate': prot_file = os.path.join(pair_path, '{}_prot.mae'.format(args.start)) schrodinger_prot = list(structure.StructureReader(prot_file))[0] custom_prot = list(structure.StructureReader(prot_file))[0] translation_vector = np.random.uniform(low=-100, high=100, size=(3)) transform.translate_structure(schrodinger_prot, translation_vector[0], translation_vector[1], translation_vector[2]) translate_structure(custom_prot, translation_vector[0], translation_vector[1], translation_vector[2]) schrodinger_atoms = np.array(schrodinger_prot.getXYZ(copy=False)) custom_atoms = np.array(custom_prot.getXYZ(copy=False)) if np.array_equal(schrodinger_atoms, custom_atoms): print("Translate function works properly") else: print("Error in translate function") schrodinger_prot = list(structure.StructureReader(prot_file))[0] custom_prot = list(structure.StructureReader(prot_file))[0] rotation_vector = np.random.uniform(low=-2 * np.pi, high=2 * np.pi, size=(3)) rotation_center = np.random.uniform(low=-100, high=100, size=(3)) rotation_center = [ rotation_center[0], rotation_center[1], rotation_center[2] ] transform.rotate_structure(schrodinger_prot, rotation_vector[0], rotation_vector[1], rotation_vector[2], rotation_center) coords = rotate_structure(custom_prot.getXYZ(copy=False), rotation_vector[0], rotation_vector[1], rotation_vector[2], rotation_center) custom_prot.setXYZ(coords) schrodinger_atoms = np.array(schrodinger_prot.getXYZ(copy=False)) custom_atoms = np.array(custom_prot.getXYZ(copy=False)) if np.amax(np.absolute(schrodinger_atoms - custom_atoms)) < 10**-7: print("Rotate function works properly") else: print("Error in rotate function") elif args.task == 'get_rmsd': conformer_file = os.path.join( pair_path, "aligned_to_start_without_hydrogen_conformers.mae".format( args.target)) conformers = list(structure.StructureReader(conformer_file)) target_lig_file = os.path.join(pair_path, 'ligand_poses', '{}_lig0.mae'.format(args.target)) target_lig = list(structure.StructureReader(target_lig_file))[0] build.delete_hydrogens(target_lig) start_lig_file = os.path.join(pair_path, '{}_lig.mae'.format(args.start)) start_lig = list(structure.StructureReader(start_lig_file))[0] start_lig_center = list(get_centroid(start_lig)) rmsds = [] for i, conformer in tqdm(enumerate(conformers), desc='going through conformers'): conformer_center = list(get_centroid(conformer)) translate_structure(conformer, start_lig_center[0] - conformer_center[0], start_lig_center[1] - conformer_center[1], start_lig_center[2] - conformer_center[2]) rmsds.append( (conformer, rmsd.calculate_in_place_rmsd(conformer, conformer.getAtomIndices(), target_lig, target_lig.getAtomIndices()), i)) # best_match_conformer = min(rmsds, key=lambda x: x[1]) # print(best_match_conformer[1], best_match_conformer[2]) # file = os.path.join(pair_path, 'best_match_conformer.mae') # with structure.StructureWriter(file) as best_match: # best_match.append(best_match_conformer[0]) print(rmsds[248][1], rmsds[248][2]) file = os.path.join(pair_path, 'translated_conformer_248.mae') with structure.StructureWriter(file) as best_match: best_match.append(rmsds[248][0]) elif args.task == 'check_rotation': target_lig_file = os.path.join(pair_path, 'ligand_poses', '{}_lig0.mae'.format(args.target)) target_lig = list(structure.StructureReader(target_lig_file))[0] remove = [i for i in target_lig.getAtomIndices() if i != 1] target_lig.deleteAtoms(remove) center = list(get_centroid(target_lig)) print("ROTATE 5,5,5") rotate_structure(target_lig, math.radians(5), math.radians(5), math.radians(5), center) target_lig_2 = list(structure.StructureReader(target_lig_file))[0] target_lig_2.deleteAtoms(remove) center = list(get_centroid(target_lig_2)) print("ROTATE 5,0,0") rotate_structure(target_lig_2, math.radians(5), 0, 0, center) print("ROTATE 0,5,0") rotate_structure(target_lig_2, 0, math.radians(5), 0, center) print("ROTATE 0,0,5") rotate_structure(target_lig_2, 0, 0, math.radians(5), center) print( rmsd.calculate_in_place_rmsd(target_lig, target_lig.getAtomIndices(), target_lig_2, target_lig_2.getAtomIndices())) print(target_lig.getXYZ(copy=False)) print(target_lig_2.getXYZ(copy=False))
def mk_conformers_epik(options, molecule, maxconf=99, verbose=True, pH=7): """ Enumerate the list of conformers and associated properties for each protonation and tautomeric state using epik from the Schrodinger Suite. Parameters ---------- options molecule : openeye.oechem The molecule read from the PDB whose protomer and tautomer states are to be enumerated. maxconf : int, optional, default=128 Maximum number of protomers/tautomers to generate. pH : float, optional, default=7.0 pH to use for conformer enumeration Returns ------- conformers : list of Conformer The list of protomers/tautomers generated. """ from schrodinger import structure # Requires Schrodinger Suite # Write mol2 file. if verbose: print "Writing input file as mol2..." outmol = oechem.OEMol(molecule) ofs = oechem.oemolostream() ofs.open('epik-input.mol2') oechem.OEWriteMolecule(ofs, outmol) ofs.close() # Use low level writer to get atom names correct. ofs = oechem.oemolostream() ofs.open('epik-input.mol2') for (dest_atom, src_atom) in zip(outmol.GetAtoms(), molecule.GetAtoms()): dest_atom.SetName(src_atom.GetName()) oechem.OEWriteMol2File(ofs, outmol, True) ofs.close() # Write mol2 file. if verbose: print "Writing input file as sdf..." outmol = oechem.OEMol(molecule) ofs = oechem.oemolostream() ofs.open('epik-input.sdf') oechem.OEWriteMolecule(ofs, outmol) ofs.close() # Write pdb file. if verbose: print "Writing input file as pdb..." outmol = oechem.OEMol(molecule) ofs = oechem.oemolostream() ofs.open('epik-input.pdb') oechem.OEWriteMolecule(ofs, outmol) ofs.close() # Write input for epik. if verbose: print "Converting input file to Maestro format..." reader = structure.StructureReader("epik-input.mol2") writer = structure.StructureWriter("epik-input.mae") for st in reader: writer.append(st) reader.close() writer.close() # Run epik to enumerate protomers/tautomers and get associated state penalties. if verbose: print "Running Epik..." cmd = '%s/epik -imae epik-input.mae -omae epik-output.mae -pht 10.0 -ms 100 -nt -pKa_atom -ph %f -WAIT' % (os.environ['SCHRODINGER'], pH) output = commands.getoutput(cmd) if verbose: print output # Convert output from epik from .mae to .sdf. if verbose: print "Converting output file to SDF..." reader = structure.StructureReader("epik-output.mae") writer = structure.StructureWriter("epik-output.sdf") for st in reader: writer.append(st) reader.close() writer.close() # Also convert to .mol2. if verbose: print "Converting output file to MOL2..." reader = structure.StructureReader("epik-output.mae") writer = structure.StructureWriter("epik-output.mol2") for st in reader: writer.append(st) reader.close() writer.close() # Find minimum charge. ifs = oechem.oemolistream() ifs.open('epik-output.mol2') molecule = oechem.OEGraphMol() min_formal_charge = 1000 while oechem.OEReadMolecule(ifs, molecule): # Check aromaticity. oechem.OEAssignAromaticFlags(molecule) # Assign formal charge oechem.OEAssignFormalCharges(molecule) formal_charge = 0 for atom in molecule.GetAtoms(): formal_charge += atom.GetFormalCharge() # Keep most negative formal charge min_formal_charge = min(min_formal_charge, formal_charge) ifs.close() if verbose: print "Minimum formal charge = %d" % min_formal_charge # Read conformers from SDF and mol2 (converted from Epik). if verbose: print "Reading conformers from SDF..." ifs_sdf = oechem.oemolistream() ifs_sdf.SetFormat(oechem.OEFormat_SDF) ifs_sdf.open('epik-output.sdf') sdf_molecule = oechem.OEGraphMol() ifs_mol2 = oechem.oemolistream() ifs_mol2.open('epik-output.mol2') mol2_molecule = oechem.OEGraphMol() conformer_index = 1 conformers = list() while oechem.OEReadMolecule(ifs_sdf, sdf_molecule): if verbose: print "Conformer %d" % conformer_index # Read corresponding mol2 molecule. oechem.OEReadMolecule(ifs_mol2, mol2_molecule) oechem.OEAssignAromaticFlags(mol2_molecule) # check aromaticity # Make a copy of the mol2 molecule. molecule = oechem.OEMol(mol2_molecule) # Set name name = options.ligand+'%02d' % conformer_index molecule.SetTitle(name) # Assign formal charge oechem.OEAssignFormalCharges(molecule) formal_charge = 0.0 for atom in molecule.GetAtoms(): formal_charge += atom.GetFormalCharge() if verbose: print "formal charge: %d" % formal_charge # DEBUG: Write mol2 file before assigning charges. if verbose: print "Writing %s to mol2..." % name outmol = oechem.OEMol(molecule) ofs = oechem.oemolostream() ofs.open(name + '.mol2') oechem.OEWriteMolecule(ofs, outmol) ofs.close() # Assign canonical AM1BCC charges. try: if verbose: print "Assigning AM1-BCC charges..." #assign_canonical_am1bcc_charges(molecule) assign_simple_am1bcc_charges(molecule) except Exception as e: print str(e) continue # Get Epik data. epik_Ionization_Penalty = float(oechem.OEGetSDData(sdf_molecule, "r_epik_Ionization_Penalty")) epik_Ionization_Penalty_Charging = float(oechem.OEGetSDData(sdf_molecule, "r_epik_Ionization_Penalty_Charging")) epik_Ionization_Penalty_Neutral = float(oechem.OEGetSDData(sdf_molecule, "r_epik_Ionization_Penalty_Neutral")) epik_State_Penalty = float(oechem.OEGetSDData(sdf_molecule, "r_epik_State_Penalty")) epik_Tot_Q = int(oechem.OEGetSDData(sdf_molecule, "i_epik_Tot_Q")) # Compute number of protons. nprotons = epik_Tot_Q - min_formal_charge + 1 # Compute effective pKa. import numpy as np kT = 298 * 6.022e23 * 1.381e-23 / 4184 # kcal/mol for 298 K pKa = options.pH - epik_State_Penalty / (nprotons * kT * np.log(10)) print "effective pKa = %8.3f" % pKa # DEBUG print "%24s : pKa penalty %8.3f kcal/mol | tautomer penalty %8.3f kcal/mol | total state penalty %8.3f\n" % (name, epik_Ionization_Penalty, epik_State_Penalty - epik_Ionization_Penalty, epik_State_Penalty) # Create a conformer and append it to the list. conformer = Conformer(name, epik_Tot_Q, molecule, state_penalty=epik_State_Penalty) conformers.append(conformer) print epik_Tot_Q # DEBUG # Increment counter. conformer_index += 1 ifs_sdf.close() ifs_mol2.close() if verbose: print "%d protomer/tautomer states were enumerated" % len(conformers) return conformers
#!/usr/bin/python """ Uses Schrodinger to invert the chirality of a molecule. """ import argparse import sys import schrodinger.structure as sch_struct if __name__ == '__main__': parser = argparse.ArgumentParser( description="Inverts x-coords of a molecule.") parser.add_argument('--input', '-i', type=str, help='Input filename.') parser.add_argument('--output', '-o', type=str, help='Output filename.') opts = parser.parse_args(sys.argv[1:]) writer = sch_struct.StructureWriter(opts.output) reader = sch_struct.StructureReader(opts.input) for structure in reader: for coords in structure.getXYZ(copy=False): coords[0] = -coords[0] writer.append(structure) reader.close() writer.close()
def main(argv=sys.argv): if len(argv) != 2: print "\n OBJ: to make complex between given ligand and receptor" print "\n Usage: makeComplex.py config.txt" print " config.txt: where information about receptor and ligand locate" sys.exit(1) global receptor global ligands print "to parse `%s`" % argv[1] parse_config(argv[1]) try: receptor_file = receptor['receptor_file'] receptor_leaving_atom = int(receptor['receptor_leaving_atom']) receptor_staying_atom = int(receptor['receptor_staying_atom']) except KeyError: print "Error: missing keys for receptor!" sys.exit(1) receptor_st = structure.StructureReader(receptor_file).next() print "receptor: `%s`" % receptor_file print "receptor_leaving_atom: `%d`" % receptor_leaving_atom print "receptor_staying_atom: `%d`\n" % receptor_staying_atom for i, ligand in enumerate(ligands): print "%d. to process ligand(s) from file %s" % (i + 1, ligand['ligand_file']) try: ligand_file = ligand['ligand_file'] smarts = ligand['smarts'] complex_out = ligand['complex_out'] #base_name,ext = os.path.splitext(complex_out) except KeyError: print " Error: missing key(s)!" else: if os.path.exists(complex_out): print " Error: `%s` is already exists!" % complex_out print " The corresponding complexes will not be generated!!" continue total_success = 0 outf = structure.StructureWriter(complex_out) inf = structure.StructureReader(ligand_file) for j, ligand_st in enumerate(inf): if ligand_st.title == '': print " > process %dth ligand" % (j + 1) else: print " > process %dth ligand (%s)" % (j + 1, ligand_st.title) match_list = structureutil.evaluate_smarts(ligand_st, smarts) print " totally found %d matches" % len(match_list) for matched_atoms in match_list: ligand_reactive_atom = matched_atoms[0] print " - try to make bond between atom `%d`(ligand) and `%d`(receptor)" % ( ligand_reactive_atom, receptor_staying_atom) complexes_st = stageTools.makeComplex( receptor_st, receptor_leaving_atom, receptor_staying_atom, ligand_st, ligand_reactive_atom) if complexes_st is None: print " Fail" else: #modification. 2013-06-24 20:19 tmp_count = 0 for complex_st in complexes_st: outf.append(complex_st) total_success += 1 tmp_count += 1 print " Success (%d)" % tmp_count #out_name = "%s_%s_%d%s"%(base_name,title,ligand_reactive_atom,ext) #complex_st.write(out_name) #inp_name = "%s_%s_%d.inp"%(base_name,title,ligand_active_atom) #writeInpFile(inp_name,out_name) #print " Success, complex has been written to file" #print " `%s`"%out_name #print " And, corresponding inp file was generated" #print " `%s`"%inp_name print " => totally %d complexes have been written to file" % total_success print " `%s`" % complex_out base_name, ext = os.path.splitext(complex_out) inp_name = base_name + ".inp" writeInpFile(inp_name, complex_out) print " corresponding inp file is saved in" print " `%s`" % inp_name