Source code for schrodinger.application.desmond.depictor

from schrodinger.infra import canvas2d

from .image_generator import SchrodImageGenerator


[docs]def singleton(cls): instances = {} def getinstance(): if cls not in instances: instances[cls] = cls() return instances[cls] return getinstance
[docs]@singleton class Depictor(SchrodImageGenerator): def __init__(self): SchrodImageGenerator.__init__(self) self._model.setShowHydrogenPreference(-1) self._model.setFontSize(18)
[docs]def ct2chmmol(st): """ convert mmct to chmmol object """ adaptor = canvas2d.ChmMmctAdaptor() stereo = canvas2d.ChmMmctAdaptor.StereoFromGeometry_Safe mol = adaptor.create(st.handle, stereo) return mol
[docs]def get_aligned_chmmol_from_ct(ct0, ct1, ma0, ma1, attached_atom0, attached_atom1): """ generated aligned chmmol pair from ct and SMARTS :type ct0: Structure :param ct0: reference structure :type ct1: Structure :param ct1: structure to be aligned :type smarts0: string :param smarts0: SMARTS pattern for ct0 :type smarts1: string :param smarts1: SMARTS pattern for ct1 :return two ChmMol instances as a tuple """ # convert to 0-base index ma0 = [i - 1 for i in ma0] ma1 = [i - 1 for i in ma1] # convert ct to chmmol chmmol0 = ct2chmmol(ct0) chmmol1 = ct2chmmol(ct1) return align_chmmol(chmmol0, chmmol1, ma0, ma1, attached_atom0, attached_atom1)
[docs]def show_attached_hydrogen(chmmol, attached_atom): for atom in attached_atom: chmmol.getAtom(atom).setHydrogensHidden(False)
[docs]def align_chmmol(chmmol0, chmmol1, ma0, ma1, attached_atom0, attached_atom1): """ generated aligned chmmol pair from ct and SMARTS :type chmmol0: ChmMol :param chmmol0: reference structure :type chmmol1: ChmMol :param chmmol0: structure to be aligned :type smarts0: string :param smarts0: SMARTS pattern for ct0 :type smarts1: string :param smarts1: SMARTS pattern for ct1 :return two ChmMol instances as a tuple """ HYDROGEN = canvas2d.ChmAtomOption.H_Never RESCALE = canvas2d.ChmCoordGenOption.Physical # we try to minimize the number of hydrogen to be rendered, in order to # avoid the accidental flipping that can cause stereo center to be # shown incorrectly chmmol0.markHydrogens(canvas2d.ChmAtomOption.H_Never) chmmol1.markHydrogens(canvas2d.ChmAtomOption.H_Never) # we show the selected hydrogens show_attached_hydrogen(chmmol0, attached_atom0) show_attached_hydrogen(chmmol1, attached_atom1) for i in range(0, len(ma0)): atom0 = chmmol0.getAtom(ma0[i]) atom1 = chmmol1.getAtom(ma1[i]) # show hydrogen atoms in stereo center if atom0.isHydrogen(): atom0.setHidden(False) if atom1.isHydrogen(): atom1.setHidden(False) # generate 2D coordinates canvas2d.Chm2DCoordGen.generateAndApply(chmmol0, HYDROGEN, RESCALE) canvas2d.Chm2DCoordGen.generateAndApply(chmmol1, HYDROGEN, RESCALE) # allow adjustment of 2D coordinates after alignment FIXUP = False BYPASSCOORDGEN = False CopyOverOriginalTemplateCoords = False # align 2D coordinates canvas2d.Chm2DCoordGen.generateFromTemplateAndApply( chmmol1, chmmol0, ma1, ma0, HYDROGEN, RESCALE, FIXUP, BYPASSCOORDGEN, CopyOverOriginalTemplateCoords) return chmmol0, chmmol1