Source code for schrodinger.application.phase.packages.mmp3dscreener

"""
This module contains the MMP3DScreener class, which performs flexible
shape-based screens of a 3D matched molecular pairs database with queries
supplied as SMILES strings.
"""

import os

from schrodinger import structure
from schrodinger.infra import phase


[docs]class MMP3DScreener: """ Performs flexible shape-based screens of a 3D matched molecular pairs database with queries supplied as SMILES strings. """
[docs] def __init__(self, mmp3d_db_path, conf_options=None): """ Constructor that takes a Maestro file containing a 3D MMP database and conformer generation options. Default conformer generation options are used if conf_options is omitted. :param mmp3d_db_path: Path to 3D MMP database file :type mmp3d_db_path: str :param conf_options: Conformer generation options :type conf_options: phase.PhpConfOptions """ self._validateDb(mmp3d_db_path) self._mmp3d_db_path = mmp3d_db_path self._conf_options = conf_options or phase.PhpConfOptions()
[docs] def screen(self, smiles, title=None): """ Generator that performs a flexible 3D screen against each pair of structures in the MMP database. Each call to this function returns a 3D shape-based alignment of the query to the next MMP, with the shape similarity stored in the property phase.PHASE_DUAL_SHAPE_SIM. :param smiles: SMILES string of the query :type smiles: str :param title: Title for all returned structures :type title: str :return: The best alignment to each MMP in the database :rtype: structure.Structure """ st = structure.SmilesStructure(smiles).get3dStructure( require_stereo=False) if title: st.title = title aligner = phase.PhpShapeTripletAligner(st.handle, self._conf_options) with structure.StructureReader(self._mmp3d_db_path) as reader: for st1 in reader: st2 = next(reader) try: st_aligned = structure.Structure( aligner.alignToPair(st1.handle, st2.handle)) yield st_aligned except (RuntimeError, phase.PhpException) as e: triplet = f'{smiles} to MMP {st1.title}, {st2.title}' print("Skipping alignment of %s: %s" % (triplet, e))
def _validateDb(self, mmp3d_db_path): """ Ensures that the provided MMP 3D database is a Maestro file and that it exists. :param mmp3d_db_path: Path to 3D MMP database file :type mmp3d_db_path: str :raise OSError: If mmp3d_db_path is not a Maestro file or is not found """ file_format = phase.get_phase_file_format(mmp3d_db_path) if file_format != phase.PhpFileFormat_PHP_FORMAT_MAE: raise OSError("Illegal MMP 3D database file name: \"%s\"" % mmp3d_db_path) if not os.path.isfile(mmp3d_db_path): raise OSError("MMP 3D database file \"%s\" not found" % mmp3d_db_path)