schrodinger.ui.qt.structure2d module¶
2D structures drawing
- schrodinger.ui.qt.structure2d.get_qpicture_protected(renderer, chmmol, gen_coord=True)¶
Generate a QPicture for the given molecule. If the picture couldn’t be generated (e.g. the molecule is too large), then a QPicture will contain the failure message text.
- Parameters:
renderer (Chm2DRenderer intance) – The renderer to use for generating the QPicture
chmmol (ChmMol instance.) – Structure to generate the picture for.
gen_coord (bool) – if True (default) generate new coordinates; if False, use existing 2D coordinates.
- Return type:
QPicture
- Returns:
The generated picture.
- schrodinger.ui.qt.structure2d.get_qpicture_highlight(renderer, chmmol, atoms, bonds, color, gen_coord=False)¶
Generate a QPicture for the given molecule and highlight given atoms and bonds. If the picture couldn’t be generated (e.g. the molecule is too large), then a QPicture will contain the failure message text.
- Parameters:
renderer (Chm2DRenderer intance) – The renderer to use for generating the QPicture
chmmol (ChmMol instance.) – Structure to generate the picture for.
atoms (list) – list of atoms that should be highlighted
bonds (list) – list of bonds that should be highlighted
color (
QtGui.QColor) – color that is used to highlight atoms and bondsgen_coord (bool) – if True generate coordinates.
- Return type:
QPicture
- Returns:
The generated picture.
- schrodinger.ui.qt.structure2d.get_chmmol_bonds_from_atoms(chmmol, atoms)¶
This function returns a list of bonds that connect atoms in a given list.
- Parameters:
chmmol (
canvas2d.ChmMol) – molecule structureatoms (list) – list of atom indices
- schrodinger.ui.qt.structure2d.get_ligand(st)¶
Return a substructure that can be rendered in a 2D image (the first ligand in
st, unless it’s also has too many atoms).
- class schrodinger.ui.qt.structure2d.StructurePicture(parent=None, layout=None, height=200, width=200, background='white', annotators=None)¶
Bases:
QLabelThis is the label that normally stores the picture of the molecule. It can also store a text message.
We make sure that this stays the same size, no matter what data (if any) is stored in it.
NOTE: PANEL-24077 will remove this class’s Canvas rendering and annotator support in favor of RDKit and Renderer APIs.
- __init__(parent=None, layout=None, height=200, width=200, background='white', annotators=None)¶
- Parameters:
parent (QWidget) – the widget that owns this widget
layout (QLayout) – The layout that this widget should be placed in
height (int) – the height of this label in pixels
width (int) – the width of this label in pixels
annotators (list) – Each item of the list should be a
canvas2d.ChemViewAnnotatorobject that will be applied to thecanvas2d.ChmRender2DModelwhen generating the image
- sizeHint(self) QSize¶
- drawStructure(structure, StereoType=StereoType.StereoFromAnnotationAndGeometry_Safe, hydrogenTreatment=H.H_ExplicitOnly, wantProperties=True, wantMMStereoProps=True, readAtomBondProperties=True, allowRadicals=False)¶
Makes a 2-D rendering of the structure
- Parameters:
structure (schrodinger.structure.Structure class object) – structure to be drawn on the canvas
StereoType (canvas2d.ChmMmctAdaptor.StereoType) – Stereochemistry option to use. Available options: # Does not include stereochemistry info: canvas2d.ChmMmctAdaptor.NoStereo # Ignores mmstereo annotations: canvas2d.ChmMmctAdaptor.StereoFromGeometry # Silently ignores stereo information that Canvas doesn’t agree with: canvas2d.ChmMmctAdaptor.StereoFromGeometry_Safe # Ignores 3d geometry: canvas2d.ChmMmctAdaptor.StereoFromAnnotation # Silently ignores stereo information that Canvas doesn’t agree with: canvas2d.ChmMmctAdaptor.StereoFromAnnotation_Safe # Uses mmstereo annotaions with 3D geometry as a backup: canvas2d.ChmMmctAdaptor.StereoFromAnnotationAndGeometry # Silently ignores stereo information that Canvas doesn’t agree with: canvas2d.ChmMmctAdaptor.StereoFromAnnotationAndGeometry_Safe
hydrogenTreatment (canvas2d.ChmAtomOption.H) – Hydrogen treatment method. Available options: canvas2d.ChmAtomOption.H_Never canvas2d.ChmAtomOption.H_ExplicitOnly canvas2d.ChmAtomOption.H_Polar canvas2d.ChmAtomOption.H_ExplicitPolar canvas2d.ChmAtomOption.H_Chiral canvas2d.ChmAtomOption.H_ExplicitChiral canvas2d.ChmAtomOption.H_ExplicitPolarAndChiral canvas2d.ChmAtomOption.H_All
wantProperties (bool) – Whether properties should be copied.
wantMMStereoProps (bool) – Whether to copy mmstereo properties.
readAtomBondProperties (bool) – Whether to copy atom and bond-level properties.
allowRadicals (bool) – Whether to assume that valence deficiencies represent unpaired electrons.
- drawChmmol(chmmol, atoms=[], bonds=[], color=<PyQt6.QtGui.QColor object>, gen_coord=False)¶
Makes a 2-D rendering of the chmmol object with optional atoms and bonds highlighting.
- Parameters:
chmmol (ChmMol instance.) – Structure to generate the picture for.
atoms (list) – list of atoms that should be highlighted
bonds (list) – list of bonds that should be highlighted
color (
QtGui.QColor) – color that is used to highlight atoms and bondsgen_coord (bool) – if True generate coordinates.
- drawRDMol(mol)¶
Draws the given RDKit molecule.
- Parameters:
mol (Chem.rdchem.Mol) – structure to be drawn
- class schrodinger.ui.qt.structure2d.StructureToolTip(structure=None, offset=(10, 10), global_position=None, height=200, width=200, **kwargs)¶
Bases:
StructurePictureA tooltip that shows a chemical structure
NOTE: PANEL-24077 will update this class to use the Renderer-based
StructurePictureimplementation.- __init__(structure=None, offset=(10, 10), global_position=None, height=200, width=200, **kwargs)¶
- Parameters:
structure (structure object that canvas2d.ChmMmctAdaptor.create() accepts.) – the structure to draw in the cell. This can be given at instantiation time if the structure will always be the same, or it can be given a show time if the structure will change dynamically.
offset (tuple(int, int)) – x and y pixel offset from the mouse pointer position to draw the upper left corner of the tooltip window
global_position (tuple(int, int)) – global position relative to the screen to to draw the upper left corner of the tooltip window. This parameter overrides the offset parameter.
height (int) – the height of this tooltip in pixels
width (int) – the width of this tooltip in pixels
This class is designed to be created once and shown/hidden as often as needed. However, there seems to be an issue with PyQt that eventually (in an unreproducible fashion) the tooltip window may simply showing up. It will claim to be visible with self.isVisible() and return the full window size using self.visibleRegion(), but it won’t be visible. Therefore it is probably best to create a new instance each time. Instances of this class are lightweight, quick to create, and garbage collect without any apparent memory leaks.
- protein_present_image = None¶
- paintEvent(event)¶
Reimplement the paint event to scale pictures larger than the tooltip.
- show(structure=None, pic=None)¶
Show the tooltip
- Parameters:
structure (structure object that canvas2d.ChmMmctAdaptor.create() accepts.) – the structure to draw in the cell. This can be given at instantiation time if the structure will always be the same, or it can be given a show time if the structure will change dynamically.
- finish()¶
Hide ourselves. This slot should be connected to a signal that is emitted when the parent widget receives a leaveEvent, or called directly from the widget’s leaveEvent routine.
Don’t destroy ourselves here even if we are being used in one-time use mode, because bus errors can result if we are created/destroyed in too short a timeframe - as can happen with tooltips.
- class schrodinger.ui.qt.structure2d.LabeledStructureToolTip(structure=None, offset=(2, 16), global_position=None, height=200, width=200, **kwargs)¶
Bases:
QFrameClass that creates a tooltip with a 2d structure picture. An arbitrary number of labels can be added that will be displayed beneath the picture.
NOTE: PANEL-24077 will remove this class’s Canvas and ChmMol rendering paths in favor of RDKit and Renderer APIs.
- __init__(structure=None, offset=(2, 16), global_position=None, height=200, width=200, **kwargs)¶
- Parameters:
structure (
structure.Structure,Chem.rdchem.Mol, orcanvas2d.ChmMol) – the structure to draw in the cell. This can be given at instantiation time if the structure will always be the same, or it can be given a show time if the structure will change dynamically.offset (tuple of 2 ints) – x and y pixel offset from the mouse pointer position to draw the upper left corner of the tooltip window
global_position (tuple of 2 ints) – global position relative to the screen to to draw the upper left corner of the tooltip window. This parameter overrides the offset parameter.
height (int) – the height of this tooltip in pixels
width (int) – the width of this tooltip in pixels
- draw2DPicture(structure)¶
Draws 2D picture of the structure.
- Parameters:
structure (
structure.Structure,Chem.rdchem.Mol, orcanvas2d.ChmMol) – Structure to draw
- show(structure=None)¶
Show the tooltip
- Parameters:
structure (
structure.Structure,Chem.rdchem.Mol, orcanvas2d.ChmMol) – the structure to draw in the cell. This can be given at instantiation time if the structure will always be the same, or it can be given a show time if the structure will change dynamically.
- addLabel(text)¶
Add a label containing the specified text underneath the structure picture.
- Parameters:
text (str) – Text to be included in the label
- setText(text: str)¶
Set the text of the label if it exists, otherwise add a new label containing the specified text.
- Parameters:
text – Text to be included in the label
- text() str¶
Return the text of the label.
- class schrodinger.ui.qt.structure2d.structure_scene¶
Bases:
QGraphicsSceneScene which holds the structure_view object
- class schrodinger.ui.qt.structure2d.structure_view(scene)¶
Bases:
QGraphicsViewView which holds a structure_item object
NOTE: PANEL-24077 will remove or update the Canvas-specific interaction support after the remaining
structure_itemconsumers are ported.- atom_clicked¶
A
pyqtSignalemitted by instances of the class.
- __init__(scene)¶
- wheelEvent(self, event: QWheelEvent | None)¶
- resizeEvent(self, event: QResizeEvent | None)¶
- class schrodinger.ui.qt.structure2d.structure_item(rect=None)¶
Bases:
QGraphicsItemA Canvas-rendered structure graphics item.
NOTE: PANEL-24077 will remove this class after its remaining consumers are ported to RDKit and Renderer APIs.
- __init__(rect=None)¶
- Parameters:
rect (QRectF) – Size of the rect of the bounding box.
- boundingRect(self) QRectF¶
- clear()¶
Clear picture from item.
- generate_picture(gen_coord=True)¶
Generates a QPicture of the structure. This should be called after setting the structure and the accompaning annotators.
- Parameters:
gen_coord (bool) – if True generate coordinates.
- paint(painter, option, widget=0)¶
Overrides the paint function to draw the picture that has already been generated. This should never be called manually.
- set_colormap(colormap)¶
Sets the colormap for the atom and bond coloring. Otherwise, the coloring used will be that coming from the ct and/or chmmol.
- set_structure(struct, StereoType=StereoType.StereoFromAnnotationAndGeometry_Safe, hydrogenTreatment=H.H_ExplicitOnly, wantProperties=True, wantMMStereoProps=True, readAtomBondProperties=True, allowRadicals=False)¶
Set the structure to the given Structure object.
- Parameters:
struct (schrodinger.structure.Structure class object) – structure to be drawn on the canvas
StereoType (ChmMmctAdaptor.StereoType) – Stereochemistry option to use. Avialable options: # Does not include stereochemistry info: canvas2d.ChmMmctAdaptor.NoStereo # Ignores mmstereo annotations: canvas2d.ChmMmctAdaptor.StereoFromGeometry # Silently ignores stereo information that Canvas doesn’t agree with: canvas2d.ChmMmctAdaptor.StereoFromGeometry_Safe # Ignores 3d geometry: canvas2d.ChmMmctAdaptor.StereoFromAnnotation # Silently ignores stereo information that Canvas doesn’t agree with: canvas2d.ChmMmctAdaptor.StereoFromAnnotation_Safe # Uses mmstereo annotaions with 3D geometry as a backup: canvas2d.ChmMmctAdaptor.StereoFromAnnotationAndGeometry # Silently ignores stereo information that Canvas doesn’t agree with: canvas2d.ChmMmctAdaptor.StereoFromAnnotationAndGeometry_Safe
hydrogenTreatment (canvas2d.ChmAtomOption.H) – Hydrogen treatment method. canvas2d.ChmAtomOption.H_Never canvas2d.ChmAtomOption.H_ExplicitOnly canvas2d.ChmAtomOption.H_Polar canvas2d.ChmAtomOption.H_ExplicitPolar canvas2d.ChmAtomOption.H_Chiral canvas2d.ChmAtomOption.H_ExplicitChiral canvas2d.ChmAtomOption.H_ExplicitPolarAndChiral canvas2d.ChmAtomOption.H_All
wantProperties (bool) – Whether properties should be copied.
wantMMStereoProps (bool) – Whether to copy mmstereo properties.
readAtomBondProperties (bool) – Whether to copy atom and bond-level properties.
allowRadicals (bool) – Whether to assume that valence deficiencies represent unpaired electrons.
- set_rect(rect)¶
- Parameters:
rect (QRect) – size of bounding box
- set_text(text, alignment=None)¶
Sets text in the view. This is useful if you display text in place of a structure, in places where no structure is available.
- Parameters:
text (string) – text to be displayed
alignment (Qt.AlignmentFlags) – alignment flags of text, defaults to QtCore.Qt.AlignVCenter|QtCore.Qt.AlignCenter
- add_annotator(annotator)¶
Adds annotator to stack. The order that these functions get added is the order that they will be applied to the picture.
- Parameters:
annotator (schrodinger.infra.canvas2d.ChemViewAnnotator) – Annotator which draws on top an image
- add_annotator_function_return(function)¶
Add functions that need to get returned after the structure is rendered on the screen. An example of this would be a function that returns drawmol coordinates.
- clear_annotators()¶
Clears all annotators
- mousePressEvent(event)¶
Emit a signal if the user left-clicked on an atom or a bond
- getBondAtLocation(pos)¶
Return the bond at the specified coordinates
- Parameters:
pos (
PyQt5.QtCore.QPoint) – The specified coordinates- Returns:
If there is a bond at the specified coordinates, return a list of the chmmol atom indices for the two bound atoms. (Note that the chmmol atom indices are zero-indexed, so you should add one to each index if you want the
schrodinger.structure.Structureatom indices). If there is no bond at the specified coordinates, return an empty list.- Return type:
list
- class schrodinger.ui.qt.structure2d.ColoredArrowAnnotator(mol, bond_info=None, draw_arrowhead=True)¶
Bases:
ChemViewAnnotatorThis annotator allows you to add colored arrows to bonds in 2d renderings.
This is a slightly less terrible port from C++. Most of the logic still keeps C++-style syntax, simply because rewriting it is not worth the effort. The interface is now more pythonic, at least.
NOTE: This annotator is used by the FEP Edge Report and Event Analysis panels. Remove it once those panels use the new Renderer APIs.
- __init__(mol, bond_info=None, draw_arrowhead=True)¶
- Parameters:
mol – is a chmmol
bond_info – is a list containing individual lists of: (atom1, atom2, outlined, QColor)
These lists are composed of:
atom1 is a ct-atom index
atom2 is a ct-atom index
outlined (0/1) is whether you want the arrow to have a black outline
qc is a qcolor for the bond
- add_bond_arrow(atom1, atom2, outlined, qc)¶
atom1 is a ct-atom index atom2 is a ct-atom index outlined (0/1) is whether you want the arrow to have a black outline qc is the qcolor of the bond
- clear_bond_arrows()¶
Clear all bond markers in this annotator
- annotate(view, dm)¶
This function annotates the specified arrows.
- class schrodinger.ui.qt.structure2d.CgCoreAnnotator(bond_info, colors, atoms, atomColors, mol)¶
Bases:
ColoredArrowAnnotatorThis is the original ColoredArrowAnnotator class name. When that class had the format of its input changed, it became incompatible with the original class.
This class will remain to preserve backwards compatability.
NOTE: This annotator is used by the R-Group Analysis and Combinatorial Synthesis Analyzer panels. Remove it once those panels use the new Renderer APIs.
- __init__(bond_info, colors, atoms, atomColors, mol)¶
bond_info is a list of size 3N, (atom1 idx, a2 idx, outline) colors is a list of size 3N (R, G, B) atoms/atomColors are deprecated mol is a chmmol
- class schrodinger.ui.qt.structure2d.BaseSquareAnnotator¶
Bases:
ChemViewAnnotatorBase class for annotators that draw a square around atoms
NOTE: This base class supports annotators used by the Reorder Atoms, P450 Site of Metabolism, and Event Analysis panels. Remove it once those panels use the new Renderer APIs.
- annotate(view, dm)¶
Add this sphere to the list of things in the picture
- Parameters:
view (Chemview) – the View this item goes in
dm (ChmDrawMol) – object that contains the list of atom and bond graphics
- class schrodinger.ui.qt.structure2d.RedSquareAnnotator(atom=None, size=100, color=GlobalColor.red)¶
Bases:
BaseSquareAnnotatorCreate a square around the specified atom.
NOTE: This annotator is used by the Reorder Atoms and P450 Site of Metabolism panels. Remove it once those panels use the new Renderer APIs.
- __init__(atom=None, size=100, color=GlobalColor.red)¶
Instantiate a RedSquareAnnotator instance.
- Parameters:
atom (int) – the atom number to which square applies. Note that this expects the first atom to be atom 1, not 0.
size (float) – the size of one side of the square in pixels.
color (QColor) – the color used to draw annotator. Default is red.
- setAtom(atom, color=None)¶
Set the atom number to which the square applies
- Parameters:
atom (int) – the atom number to which square applies. Note that this expects the first atom to be atom 1, not 0. If 0 is passed in, no atom will be annotated.
color (QColor) – the color used to draw annotator. If not given, the previously set color for this annotator will be used.
- clearAtom()¶
Remove the current atom so no atoms are annotated
- getAtom()¶
Return the atom index current annotated
- Return type:
int or None
- Returns:
The index (1-based) of the atom annotated, or None if no atoms are annotated
- setColor(color)¶
Set the color of the square
- Parameters:
color (QColor) – the color used to draw annotator.
- class schrodinger.ui.qt.structure2d.MultiSquareAnnotator(atom_dict, size=100)¶
Bases:
BaseSquareAnnotatorCreate a square around each specified atom.
NOTE: This annotator is used by the Event Analysis panel. Remove it once that panel uses the new Renderer APIs.
- __init__(atom_dict, size=100)¶
Instantiate a MultiSquareAnnotator instance.
- Parameters:
atom_dict (dict) – A dictionary of {atom number: QColor} specifying the appropriate color for each atom
size (float) – The size of one side of the square in pixels. Defaults to 100 pixels.
- class schrodinger.ui.qt.structure2d.AtomNumberAnnotator¶
Bases:
ChemViewAnnotatorShow the atom number of each atom rather than a vertex or atomic symbol
NOTE: This annotator is used by the Reorder Atoms panel. Remove it once that panel uses the new Renderer APIs.
- annotate(view, dm)¶
Add atom number to each atom
- Parameters:
view (Chemview) – the View this item goes in
dm (ChmDrawMol) – object that contains the list of atom and bond graphics
- class schrodinger.ui.qt.structure2d.AtomLabelAnnotator(atom_labels)¶
Bases:
ChemViewAnnotatorChanges the label displayed for an atom. The label can have subscripts.
NOTE: This annotator is used by the Materials Science Builder panel. Remove it once that panel uses the new Renderer APIs.
- __init__(atom_labels)¶
Instantiate a AtomLabelAnnotator instance.
- Parameters:
atom_labels (dict) – A dictionary of {atom number: label} specifying the label for each atom to be custom labeled. Each label may either be a string or a (str, str) tuple. In the latter case, the first string is the main label and the second string is the subscript. Note the atom numbers used here should be 1-based (first atom number = 1)
- annotate(view, drawmol)¶
Add a label to each atom specified in the atom_labels property
- Parameters:
view (Chemview) – the View this item goes in
drawmol (ChmDrawMol) – object that contains the list of atom and bond graphics
- class schrodinger.ui.qt.structure2d.CircleAnnotator(atom=None, radius=75.0, color=GlobalColor.green, gradient=False, fill=False, width=4)¶
Bases:
ChemViewAnnotatorCreates a circle behind one or more atoms.
NOTE: This annotator is used by the Reorder Atoms and FEP Edge Report panels. Remove it once those panels use the new Renderer APIs.
- __init__(atom=None, radius=75.0, color=GlobalColor.green, gradient=False, fill=False, width=4)¶
Instantiate a ColorCircleAnnotator instance.
- Parameters:
atom (int) – the atom number to which radius applies. Note that this expects the first atom to be atom 1, not 0.
radius (float) – the radius of the sphere in pixels. Default is 75.
color (QColor) – The color of the circle fill
gradient (bool) – If True, the circle is filled with a gradient that goes from white at the center to the defined color. gradient is exclusive with fill.
fill (bool) – If True, the circle is given a constant fill. fill is exclusive with gradient.
width (int) – The width of the pen if fill and gradient are both False. Default is 4.
- addAtom(atom_num, radius=None, color=None)¶
Add another sphere to this annotator
- Parameters:
atom_num (int) – the atom number to which radius applies. Note that this expects the first atom to be atom 1, not 0.
radius (float) – the radius of the sphere in pixels. If not given, the radius given at the time of instance creation is used.
color (QColor) – The color of the circle fill. If not given, the color given at the time of instance creation is used.
- removeAtom(atom_num)¶
Remove an atom from the annotator
- Parameters:
atom_num (int) – the atom number to which radius applies. Note that this expects the first atom to be atom 1, not 0.
- clearAtoms()¶
Remove all atoms from the annotator
- setColor(color, reset_colors=False)¶
Set the default color for this annotator
- Parameters:
color (QColor) – The color of the circle fill.
reset_colors (bool) – If True, all existing circles will have their color reset to this value
- setRadius(radius, reset_radii=False)¶
Set the default radius for this annotator
- Parameters:
radius (float) – The radius of the circle
reset_radii (bool) – If True, all existing circles will have their radius reset to this value
- annotate(view, dm)¶
Add this sphere to the list of things in the picture
- Parameters:
view (Chemview) – the View this item goes in
dm (ChmDrawMol) – object that contains the list of atom and bond graphics