def compute_2d(self, manager: DepictionManager, remove_hs: bool = True) -> DepictionResult: """Compute 2d depiction of the component using DepictionManager instance. Args: manager (DepictionManager): Instance of the ligand depiction class. remove_hs (bool, optional): Defaults to True. Remove hydrogens prior to depiction. Returns: DepictionResult: Object with the details about depiction process. """ mol_copy = rdkit.Chem.RWMol(self.mol) if remove_hs: mol_copy = rdkit.Chem.RemoveHs(mol_copy, updateExplicitCount=True, sanitize=False) rdkit.Chem.SanitizeMol(mol_copy, catchErrors=True) result_log = manager.depict_molecule(self.id, mol_copy) self.mol2D = result_log.mol return result_log
def __init__( self, pubchem_templates="", general_templates=config.general_templates, library_path=config.fragment_library, ): """Initialize manager Args: pubchem_templates (str): Path to the pubchem templates general_templates (str, optional): Path to the general templates. Defaults to config.general_templates. library_path (str, optional): Path to the fragments library: Defaults to config.fragment_library. """ # helper class to download templates if needed self.pubchem = (PubChemDownloader(pubchem_templates) if pubchem_templates else None) # helper class to get nice depictions self.depictions = DepictionManager(pubchem_templates, general_templates) # Fragments library to get substructure matches self.fragment_library = FragmentLibrary(library_path)
def test_collision_template_picked(expected_template, names): """Test if expected templates are picked for certain compounds Args: expected_template (str): template name. names (list of str): list of ids matching this template. """ d = DepictionManager() for ccd_id in names: mol = load_molecule(ccd_id) response = mol.compute_2d(d) assert response.source == DepictionSource.Template assert response.score > 0 assert response.template_name == expected_template
def _init(self, args): """Initialize PDBeChem pipeline and necessary objects. Args: args (argparse.Namespace): Verified application arguments """ self.logger.debug('Initializing calculation...') self.output_dir = args.output_dir self.depictions = DepictionManager(args.pubchem_templates, args.general_templates) self.pubchem = PubChemDownloader( args.pubchem_templates) if os.path.isdir( args.pubchem_templates) else None self.fragment_library = FragmentLibrary(args.library) self.logger.debug(f'Reading in {args.components_cif} file...') self.compounds = ccd_reader.read_pdb_components_file( args.components_cif) self.ligands_to_process = len( self.compounds) if args.test_first is None else args.test_first self.logger.debug('Initialization finished.')
import pytest from pdbeccdutils.core import ccd_reader from pdbeccdutils.core.component import Component from pdbeccdutils.core.depictions import DepictionManager, DepictionSource from pdbeccdutils.tests.tst_utilities import cif_filename collision_free_templates = [ ('hem', ['HEM', 'HEA', 'HEB', 'HEC', 'HDD', 'HEG']), ('porphycene', ['HNN', 'HME']), ('ru_complex', ['11R']), ] collision_templates = [('cube', ['SF4', '0KA', '1CL']), ('adamantane', ['ADM'])] depictions = DepictionManager() def load_molecule(id_): c = ccd_reader.read_pdb_cif_file(cif_filename(id_)).component c.compute_2d(depictions) return c class TestWriteImg: @staticmethod def test_file_generated( tmpdir): # tmpdir is a fixture with temporary directory mol = load_molecule('ATP') path = str(tmpdir.join('atp_test.svg'))