def aggregate_structures(data_path, save_location, scores_version): protein = 'MAPK14' print(protein) #try to load the score file scores_file = "{}/{}/scores/{}/pdb.sc".format(data_path, protein, scores_version) if os.path.isfile(scores_file): ligand_folder = '{}/{}/structures/aligned_files'.format( data_path, protein) ligands = os.listdir(ligand_folder) # write one mae files for all poses with StructureWriter('{}/all_{}_pv.mae'.format(save_location, protein)) as all: #iterate over each scored ligand for i, ligand in enumerate(ligands): pose_file = "{}/{}/structures/aligned_files/{}/{}_out.mae".format( data_path, protein, ligand, ligand) #load the structure file containing docking results pv = list(StructureReader(pose_file)) print(pv) #add the protein structure but only for the first file all.append(pv[0])
def main(): args = parse_args() print("args", args) if args.implementation == TORCHANI: from torchani_calculator import torchani_calculator calculator = torchani_calculator(args.network_type, args.numb_networks) elif args.implementation == AES_ANI: from ani_ase import ani_ase_calculator calculator = ani_ase_calculator(args.network_type) elif args.implementation == KHAN: from khan_calculator import khan_calculator calculator = khan_calculator(args.network_type, args.khan_network, args.numb_networks) strs = list(StructureReader(args.mae_file)) cvgd = optimize_structures(strs, calculator.committee, maxit=500, thresh=0.01) rd = rawdataset_from_st(strs) energy_data = calculator.committee.compute_data(rd) for st, data in zip(strs, energy_data): st.property["r_j_ANI_ENERGY"] = data.energy st.property["r_j_ANI_RHO"] = data.rho base, ext = os.path.splitext(args.mae_file) outfile = base + "_optimized" + ext print("final structure written to file: %s" % outfile) with StructureWriter(outfile) as writer: writer.extend(strs)
def mol_graph_to_maestro_file(molecule: MoleculeGraph, filename: Union[str, Path]): """ Write a pymatgen MoleculeGraph object to a Maestro file. Args; molecule (MoleculeGraph): MoleculeGraph to be written filename (str): Path to file where molecule will be written. Returns: None """ if isinstance(filename, Path): fn = filename.as_posix() else: fn = filename struct = mol_graph_to_schrodinger_struct(molecule) StructureWriter.write(struct, fn)
def save_merged_ligand_protein(self, raw_protein_file, raw_ligand_file): """ Merge structures from files and save to save directory :param raw_ligand_file: absolute paths :return: """ prot_st = next(StructureReader(raw_protein_file)) alpha = 'ABCDEFGHIJKMNOPQRST' alpha_count = 0 for c in prot_st.chain: if c.name.strip() == '': continue c.name = alpha[alpha_count] alpha_count += 1 if raw_ligand_file != '': lig_st = next(StructureReader(raw_ligand_file)) # standardize chain naming for c in lig_st.chain: c.name = 'L' merged_st = lig_st.merge(prot_st) else: merged_st = prot_st st_wr = StructureWriter(self.path + self.raw_complex) st_wr.append(merged_st) st_wr.close()
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 = 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 run_group(grouped_files, raw_root, index): for protein, target, start in grouped_files[index]: pair = '{}-to-{}'.format(target, start) protein_path = os.path.join(raw_root, protein) pair_path = os.path.join(protein_path, pair) pose_path = os.path.join(pair_path, 'ligand_poses') # comput mcss compute_protein_mcss([target, start], pair_path) # combine ligands with StructureWriter('{}/{}_merge_pv.mae'.format(pair_path, pair)) as all_file: for file in os.listdir(pose_path): if file[-3:] == 'mae': pv = list(StructureReader(os.path.join(pose_path, file))) all_file.append(pv[0]) # zip file os.system('gzip -f {}/{}_merge_pv.mae'.format(pair_path, pair, pair_path, pair))
def split(self): #look for the opt_complex, if it doesn't exist, just use the prepped complex usefile = '' if (os.path.isfile(self.path + self.align_file)): usefile = self.path + self.align_file else: usefile = self.path + self.prepped_complex st = next(StructureReader(usefile)) prot_st = st.extract([a.index for a in st.atom if a.chain != 'L']) prot_st.title = '{}_prot'.format(self.name) lig_st = st.extract([a.index for a in st.atom if a.chain == 'L']) lig_st.title = '{}_lig'.format(self.name) prot_wr = StructureWriter(self.path + self.split_protein) prot_wr.append(prot_st) prot_wr.close() lig_wr = StructureWriter(self.path + self.split_ligand) lig_wr.append(lig_st) lig_wr.close()
def main(): args = parse_args() print("args", args) if args.implementation == TORCHANI: from torchani_calculator import torchani_calculator calculator = torchani_calculator(args.network_type, args.numb_networks) elif args.implementation == AES_ANI: from ani_ase import ani_ase_calculator calculator = ani_ase_calculator(args.network_type) elif args.implementation == KHAN: from khan_calculator import khan_calculator calculator = khan_calculator(args.network_type, args.khan_network, args.numb_networks) #assert args.cif_file.endswith('.cif') or args.cif_file.endswith('.xyz') if args.cif_file.endswith('.mae'): st = next(StructureReader(args.cif_file)) if args.truncate_box: # reduced size box a = 12.0 deletions = [] for mol in st.molecule: rcom = center_of_mass(st, mol.getAtomIndices()) inbox = [abs(x) < a / 2 for x in rcom] if False in [abs(x) < a / 2 for x in rcom]: deletions.extend(mol.getAtomIndices()) st.deleteAtoms(deletions) rd = rawdataset_from_st([st]) ase_molecs = khan_molec_to_ase_atoms(rd.all_Xs) atoms = ase_molecs[0] if args.truncate_box: # hard coded box #a = 22.6868 vecs = [[a, 0.0, 0.0], [0.0, a, 0.0], [0.0, 0.0, a]] atoms.set_cell(vecs) atoms.set_pbc([True, True, True]) print("after set cell", atoms.get_pbc()) if args.cif_file.endswith('.cif'): atoms = ase_io.read(args.cif_file) if args.box_length is not None: atoms.set_cell([ [args.box_length, 0.0, 0.0], [0.0, args.box_length, 0.0], [0.0, 0.0, args.box_length], ]) atoms.set_pbc([True, True, True]) if args.supercell is not None: atoms = build_supercell(atoms, [args.supercell] * 3) periodic = False not in atoms.get_pbc() print("cell") print(atoms.get_cell()) if periodic: #atoms.wrap() space_group = spacegroup.get_spacegroup(atoms) print("Space group of crystal: %s" % space_group) print("initial unit cell") print(atoms.cell) # this shows how to get unique atoms and there equivalents #scaled_positions = atoms.get_scaled_positions() #unique_positions = space_group.unique_sites(scaled_positions) #all_positions, symmetry_map = space_group.equivalent_sites(unique_positions) #symmetry_groups = defaultdict(list) #for igroup, position in zip(symmetry_map, all_positions): # symmetry_groups[igroup].append(position) #print("unique positions") #for xyz in unique_positions: # print(xyz) #for igroup in sorted(symmetry_groups.keys()): # print("positions in symmetry group %d" % igroup) # for xyz in symmetry_groups[igroup]: # print(xyz) torsions = () if args.torsion is not None: torsions = [( float(args.torsion[0]), int(args.torsion[1]), int(args.torsion[2]), int(args.torsion[3]), )] if args.optimize: # cannot optimize cell until we implement a stress tensor energy = optimize_molecule( atoms, calculator, torsions=torsions, thresh=0.05, optimize_cell=args.relax_cell, ) else: start_time = time.time() energy = single_point_energy(atoms, calculator) print("--- %s seconds ---" % (time.time() - start_time)) if args.dynamics: traj = molecular_dynamics(atoms, calculator, total_time=args.total_time, time_step=args.time_step) if args.cif_file.endswith('.mae'): st = next(StructureReader(args.cif_file)) with StructureWriter("md_path.mae") as writer: for m in traj: st0 = st.copy() st0.setXYZ(m.get_positions()) writer.append(st0) else: with open("md_path.xyz", "w") as fout: xyz_lst = [] for atoms in traj: xyz_lst.append("%d\n" % len(atoms)) species = atoms.get_chemical_symbols() carts = atoms.get_positions() for ch, xyz in zip(species, carts): xyz_lst.append("%s %.8f %.8f %.8f" % (ch, xyz[0], xyz[1], xyz[2])) fout.write("\n".join(xyz_lst)) print("energy of cell (au):", energy) if periodic: space_group = spacegroup.get_spacegroup(atoms) print("Final Space group of crystal: %s" % space_group) print("energy of cell/volume (au):", energy / atoms.get_volume()) print("final unit cell") print(atoms.cell) print("Uncertainty %.4f (kcal/mol)" % (calculator.uncertainty(atoms) * 627.509)) if periodic: outfile = os.path.splitext(args.cif_file)[0] + "_optimized.cif" else: outfile = os.path.splitext(args.cif_file)[0] + "_optimized.xyz" ase_io.write(outfile, atoms) print("final structure written to file: %s" % outfile)
""" The purpose of this code is to remove the ligands from a list of structure (.mae) files It can be run on sherlock using $ ml load chemistry $ ml load schrodinger $ $SCHRODINGER/run python3 ligand_remover.py """ import os from schrodinger.structure import StructureReader, StructureWriter if __name__ == '__main__': root = '/home/users/sidhikab/flexibility_project/mutations/Data/MAPK14/' files = sorted(os.listdir(root)) for s_file in files: if len(s_file) == 16: print(s_file) prot_path = s_file[:12] + '_nolig.mae' if os.path.exists(root + prot_path): print("Exists") else: st = next(StructureReader(root + s_file)) prot_st = st.extract( [a.index for a in st.atom if a.chain != 'L']) prot_wr = StructureWriter(root + prot_path) prot_wr.append(prot_st) prot_wr.close() os.remove(root + s_file)