def replace(self, probe_smiles: str, probe_resn: str, probe_name: str) -> str: """ The target probe needs a un-taken PDB 3 letter residue name if the flag ``load_PDB_components`` is left. Else the PDB component library version will win! :param probe_smiles: Valid Smiles, protons optional. :param probe_resn: untaken 3 letter residue name :param probe_name: file friend! :return: """ probe = self.make_probe(probe_smiles) cid = self.align_probe_to_target(probe) aligned_file = f'{probe_name}.aligned.mol' #Chem.MolToMolFile(probe, aligned_file, confId=cid) writer = rdmolfiles.SDWriter(aligned_file) writer.write(probe, confId=cid) for i in range(probe.GetNumConformers()): if i == cid: continue writer.write(probe, confId=i) writer.close() molfile_to_params.run(aligned_file, conformers_in_one_file=True, name=probe_resn, amino_acid=None, chain='X', pdb=probe_name, clobber=True) pdbblocks = self.combine(probe_name, probe_resn) return pdbblocks.all
def save_confs(self, out, file) -> True: # Chem.MolToMolFile(out,'test.mol') writer = rdmolfiles.SDWriter(file) writer.SetKekulize(False) for i in range(out.GetNumConformers()): writer.write(out, confId=i) writer.close() return True
def sdf_file(test_mols): # Create directory for test file(s) tmp_dir = maybe_create_dir('data/tmp/') fname = os.path.join(tmp_dir, 'test.sdf') # Store molecules writer = rdmolfiles.SDWriter(fname) for mol in test_mols: writer.write(mol) writer.close() return fname
def write_probe(self, cid): aligned_file = f'{self.work_path}/{self.name}/{self.name}.aligned.mol' # Chem.MolToMolFile(probe, aligned_file, confId=cid) writer = rdmolfiles.SDWriter(aligned_file) writer.SetKekulize(False) writer.write(self.dethio_mol, confId=cid) for i in range(self.dethio_mol.GetNumConformers()): if i == cid: continue writer.write(self.dethio_mol, confId=i) writer.close() return aligned_file
def save_output(output_list, file_name): """ Write the output to an SD file :param output_list: list of pairs :param file_name: output file name :return: None """ writer = rdmolfiles.SDWriter(file_name) for mol, name, val in output_list: mol.SetProp("_Name", name) mol.SetProp("Value", str(val)) writer.write(mol)
mols = {cid: Chem.MolFromSmiles(smi) for cid, smi in smiles.items()} print("Computing 3D coordinates...") s = SaltRemover.SaltRemover() for i, (cid, mol) in enumerate(mols.items()): if i > 0 and i % 100 == 0: print("Finished %d" % i) try: mol.SetProp("_Name","%d: %s" % (cid, smiles[cid])) mol = s.StripMol(mol,dontRemoveEverything=True) mol = Chem.AddHs(mol) AllChem.Compute2DCoords(mol) AllChem.EmbedMolecule(mol) AllChem.UFFOptimizeMolecule(mol) # Is this deterministic? except Exception as e: print('Exception for %d' % cid) mols[cid] = None else: mols[cid] = mol mols = {cid: mol for cid, mol in mols.items() if mol} writer = rdmolfiles.SDWriter('data/cids-smiles.sdf') for smile, mol in mols.items(): writer.write(mol) writer.close() suppl = rdmolfiles.SDMolSupplier('data/cids-smiles.sdf') for mol in suppl: print(mol.GetNumAtoms())