schrodinger.ui.two_d_viewer module

Embeddable 2D Viewer widget. For main panel, see mmshare/python/scripts/two_d_viewer_gui.py

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.ui.two_d_viewer.get_icon(path)
schrodinger.ui.two_d_viewer.st_to_rdmol_without_hydrogens(st)

Create a sanitized RDMol from Structure. Used for MCS calculation only. Hydrogens are exlucded to make the calculation faster, and to prevent hangs.

NOTE: Atom indices will be different from the original structure, because explicit hydrogens will be stripped (and if any hydrogen has lower atom index than a heavy atom, heavy atoms will get renumbered).

Parameters

st (structure.Structure) – Structure to convert.

Returns

RDKit molecule.

Return type

Chem.Mol

schrodinger.ui.two_d_viewer.get_mcs_atoms(rdmol1, rdmol2)

Find the maximum common structure between the given structures, and return atom lists for each molecule that match the MCS. Lists are 0-indexed, because they are then passed on to rdkit. Input structures should not have explicit Hs, to make the calculation faster and avoid hangs on certen molecules

Parameters
  • rdmol1 (Chem.Mol) – First molecule

  • rdmol2 (Chem.Mol) – Second molecule

Returns

(list of MCS atoms in rdmol1, list of MCS atoms in rdmol2)

Return type

(list, list)

schrodinger.ui.two_d_viewer.kpls_color_from_value(value)

Calculate color corresponding to value for kpls annotations. Blue is minimum and red is maximum

schrodinger.ui.two_d_viewer.property_string(atom, property_name)
schrodinger.ui.two_d_viewer.generate_pic_with_text(text)

Create a QPicture with the text painted on it.

Parameters

text (str) – Text to draw in the picture.

Returns

The QPicture with the text.

Return type

QtGui.QPicture.

class schrodinger.ui.two_d_viewer.CtPropsDialog(viewer, all_props, selected_props, display_names, use_title_caps)

Bases: schrodinger.ui.qt.basewidgets.BaseDialog

Dialog for letting the user select which CT-level properties to show.

ctPropertiesChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

initSetOptions()

Suggested subclass use: set instance variables, excluding layouts and subwidgets. Also use here to (optionally) apply the legacy stylesheet spacing settings (PANEL-19101).

__init__(viewer, all_props, selected_props, display_names, use_title_caps)
accept(self)
class schrodinger.ui.two_d_viewer.AtomPropertyDialog(viewer, annotate_property)

Bases: schrodinger.ui.qt.basewidgets.BaseDialog

Dialog for letting the user select which atom-level property to show.

atomPropertyChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

initSetOptions()

Suggested subclass use: set instance variables, excluding layouts and subwidgets. Also use here to (optionally) apply the legacy stylesheet spacing settings (PANEL-19101).

__init__(viewer, annotate_property)
accept(self)
class schrodinger.ui.two_d_viewer.ZoomWidget(parent=None)

Bases: PyQt6.QtWidgets.QWidget

__init__(parent=None)
paintEvent(self, a0: QPaintEvent)
class schrodinger.ui.two_d_viewer.Cell(st, has_protein, entry_id)

Bases: object

The idea is to dynamically generate an instance whenever the model requests this data.

__init__(st, has_protein, entry_id)
Parameters
  • st (structure.Structure) – Structure to show in the cell (ligand only, no protein)

  • has_protein (bool) – Whether to show the “protein” icon in the cell.

  • entry_id (int) – Entry ID (when in Maestro) or Structure handle.

getProjectRow()

Return the ProjectRow instance for this entry. Returns None if the entry is no longer in the Project Table.

isIncluded()
getIncludedState()

Will return one of the following: NOT_IN_WORKSPACE, IN_WORKSPACE, LOCKED_IN_WORKSPACE

clearAlignment()
clearTransformations()
copyTransformations(cell)

Copies the transformations from the given cell to this cell

generateNeutralStateIfNeeded(uncharger)

Generate the neutral state of the structure, if one is still missing.

class schrodinger.ui.two_d_viewer.TwoDTableModel(parent, *args)

Bases: schrodinger.ui.qt.table.ViewerModel

Custom model for 2D Viewer table The idea is for this model to dynamically change as the project table changes.

__init__(parent, *args)
removeReference()
clearReferenceHighlighting()

Clears reference ligand highlighting. Note: cells are still aligned to previous alignment, if any

setReferenceToIndex(ref_i)
alignCellsToReference(ref_i)

Set MCS/alignment reference to the given cell index, and align all cells to it.

rowCount(parent=None)

Returns number of rows needed to display the data

getRowColumnFromI(i)
getIndexFromI(i)
columnCount(self, parent: QModelIndex = QModelIndex()) int
flags(self, index: QModelIndex) Qt.ItemFlag
data(index, role=ItemDataRole.DisplayRole)

Use getCellFromIndex() instead

numCells()
getCellFromI(i)
getIFromCell(cell)
setCells(cells)

Set the internal data list to the specified list of Cell objects.

getEntryIds()

Return a list of entry IDs that are currently in the table.

getTitles()

Return a list of titles, for all structures. Each title is prepended with the row number of this entry (if in Maestro) or structure index (if outside of Maestro).

removeAllRows()
setColumns(new_num_cols)
removeIsFromTable(remove_is)

Remove cells with specified i’s (cell index ints) from the table.

moveCell(old_index, new_index)

Move the given cell from old index (x,y position) to new index.

handleInclusonToggled(index)

Called when inclusion toggle within a cell is clicked.

Parameters

index (QModelIndex) – Index of the clicked cell

handleShiftClick(index)
Parameters

index (QModelIndex) – Index of the clicked cell

class schrodinger.ui.two_d_viewer.TwoDTableView(model, parent)

Bases: schrodinger.ui.qt.table.DataViewerTable

__init__(model, parent)
Parameters
  • model (QAbstractTableModel) – The model for this table. The typical class to use with this table is the StructureDataViewerModel class

  • parent (QWidget) – The widget that owns this table widget

  • aspect_ratio (bool) – if True (default) keeps the cell height & width aspect ratio locked at the ratio indicated by cell_height and cell width. Note that True implies gang=”both”. If aspect_ratio is true, fill can be “rows” OR “columns”, but NOT “both”.

  • fill ("rows", "columns", "both" or "none") – The specified table feature will expand or contract to exactly fit within the table’s viewport.

  • “none”: means neither rows or columns will expand

  • “rows”: means rows will expand (default)

  • “columns”: means columns will expand

  • “both”: means both rows and columns will expand

fill cannot be “both” if aspect_ratio is True.

Setting a feature to fill will turn off the corresponding scrollbar.

Parameters

gang ("rows", "columns", "both" or "none") – Controls whether rows and/or columns can be independently resized.

  • “none” - rows and columns can be independently resized

  • “rows” - rows are ganged so that changing the size of one row will change all the rows

  • “columns” - columns are ganged so that changing the size of one column will change all the columns

  • “both” - both rows and columns are ganged (default)

Parameters
  • universal_row_gang_setting (bool) – If true, then the gang setting applies to ALL rows and a subset of rows may not be ganged. If False (the default), either a subset or all rows may be ganged. It is never necessary to set this option, however setting it does allow for a slight improvement in memory usage for very large tables. Note that this setting applies whether the rows are all ganged or all not ganged. Note that this setting in combination with ganging rows will prevent actions such as hiding the row that change the row size.

  • universal_column_gang_setting (bool) – If true, then the gang setting applies to ALL columns and a subset of columns may not be ganged. If False (the default), either a subset or all columns may be ganged. It is never necessary to set this option, however setting it does allow for a slight improvement in memory usage for very large tables. Note that this setting applies whether the columns are all ganged or all not ganged. Note that this setting in combination with ganging columns will prevent actions such as hiding the column that change the column size.

  • resizable ("rows", "columns", "both" or "none") – the table features that can be resized by the user.

  • “none” - neither rows nor columns can be resized by the user

  • “rows” - rows can be resized by the user

  • “columns” - columns can be resized by the user

  • “both” - both rows and columns can be resized by the user (default)

Note - a feature that has fill turned on cannot be resized by the user, and if fill is turned on and aspect_ratio is True, neither rows nor columns can be resized by the user.

Parameters

fit_view ("rows", "columns", "both" or "none") – the table features that determine the size of the table’s viewport (the part visible to the user).

When this is turned on for a feature, the visible part of the table resizes dynamically to exactly fit that feature. For instance, if fit_view=’rows’, the visible part of the table will resize to exactly fit all the rows any time the size of a row changes.

  • “none” - neither rows nor columns determine the viewport size

  • “rows” - rows determine the viewport height

  • “columns” - columns determine the viewport width

  • “both” - both rows and columns determine the viewport size

Note - a feature that has fill turned on cannot have viewport_fit turned on. fill uses the size of the viewport to determine the size of the cells, while fit_view uses the sie of the cells to determine the size of the viewport.

Note 2 - Setting a feature to fit_view will turn off the corresponding scrollbar.

Note 3 - User resizing of rows with both gang and fit_view=’rows’ or ‘both’ tends to be a bit wonky because the amount the row resizes depends on the placement of the mouse relative to the table, and the table moves as it resizes to the rows, so you tend to get very large changes rapidly.

Parameters

vscrollbar ("on", "off" or "default") – Vertical scrollbar setting - “on” - always on - “off” - always off - “default” - (default) on as needed

If either fit_view or fill = “rows” or “both”, the vertical scrollbar is turned off

Parameters

hscrollbar ("on", "off" or "default") – Horizontal scrollbar setting - “on” - always on - “off” - always off - “default” - (default) on as needed

If either fit_view for fill =”columns” or “both”, the horizontal scrollbar is turned off

Parameters
  • cell_width (int) – default width of cells in pixels

  • cell_height (int) – default height of cells in pixels

  • enable_copy (bool) – True if data in the table can be copied to the clipboard. Cells with structures copy the title of the structure to the clipboard, else the string conversion of the structure to the clipboard.

columnWidth(self, column: int) int
rowHeight(rownum)

Returns the height of the specified row (same for all rows). This method is used by the view.

keyPressEvent(event)

Will get called when a key is pressed

resizeEvent(event)

Called when the viewport changes size. Resizes the rows to keep images square. Uses view’s rowHeight() method.

dragEnterEvent(self, e: QDragEnterEvent)
dropEvent(event)

Don’t allow drops to the right of the right-most column. See Qt documentation for additional method documentation.

class schrodinger.ui.two_d_viewer.CellContextualMenu(viewer, cell, row)

Bases: PyQt6.QtWidgets.QMenu

__init__(viewer, cell, row)
show(pos)

Show contextual menu for the given 2D cell, at the current position of the mouse cursor.

updateView()
includeEntries()

Include selected cells in the Workspace.

excludeEntries()

Exclude all selected cells from the Workspace.

excludeOtherEntries()

Exclude all entries from the Workspace, except those for selected 2D viewer cells.

selectEntries()

Select in PT those entries that are selected in 2D viewer.

deselectOtherEntries()

Deselect everything from PT except cells that are selected in 2D Viewer

deselectEntries()

Deselect in PT those cells that are selected in 2D Viewer.

copyToClipboard()
setAsReference()
removeAlignments()

Remove alignments to reference for selected cells.

class schrodinger.ui.two_d_viewer.TwoDTableDelegate(viewer, tableview, tablemodel)

Bases: schrodinger.ui.qt.table.GenericViewerDelegate

__init__(viewer, tableview, tablemodel)
Parameters
  • tableview (ViewerTable) – Table this delegate paints to

  • tablemodel (StructureDataViewerModel) – DEPRECATED Model containing the data this delegate paints This parameter should not be used, because a delegate should only get information from a QModelIndex, not a model directly

paint(painter, option, index)

This handles the logic behind painting/not-painting when the scrollbar is being dragged.

hideStructureTooltip()
class schrodinger.ui.two_d_viewer.TwoDViewer(parent=None)

Bases: PyQt6.QtWidgets.QFrame

Embeddable 2D Viewer, that contains:

  1. Main table, with a vertical scroll bar

  2. “Change view” pull-down menu

  3. Text “Drag cells to reorder. Right-click for more options.”

  4. Reference pull-down menu with “Align All” button

  5. Transformation options

  6. Generate report options

Variables

enable_maestro_features (bool) – Enables maestro connected features, inclusion in project table and import functionality

enable_maestro_features: bool = False
PROGRESS_STRUCT_COUNT = 1000
__init__(parent=None)
onShowHideActionsToggled(checked)

Show or hide the actions section.

populateSaveExportMenu()
populateViewMenu()
neutralizeToggled(on)

Called when the “Show Neutral Form” menu item is toggled.

generateNeutralizedStates()

For each loaded structure, generate the neuralized form, if not already present.

linkSelectionAndInclusionToggled(on)
displayPropsDialog()

Open CT properties dialog box.

showPropNames(selected_props, show_names, title_caps)
getPropertiesToShow()

Return a list of (property data name, whether to include property name) for each property that should be rendered below the 2D image.

atomPropDialog()

Open atom annotation dialog box.

atomPropChanged(prop)
openDisplayPreferences()

Open the Maestro’s preference dialog, to the image display tab.

columnActionSelected(item_action)
synchronizePreferencesFromMaestro()

Update the 2D Viewer’s preferences to the Maestro’s preferences.

info(text, preferences=None, key='')
warning(text, preferences=None, key='')
setWaitCursor()
restoreCursor()
status(text='')

Set the status label to the specified text.

commandCallback(command)

Called by Maestro when a command is issued, and is used to update the 2D Viewer preferences when Maestro’s preferences change.

workspaceChanged(what_changed)
copyToClipboard(cell)
setupPanel()

Setup the GUI

eventFilter(self, a0: QObject, a1: QEvent) bool
updatePreviousAndNextButtons()

Enable or disable “<” and “>” buttons as needed.

getIncludeToggleOffset()
paintOneCell(painter, cell, pic, cell_rect, exporting)

Paint the given QPicture of the 2D structure, plus properties and inclusion icon to the specified painter.

NOTE: For large structures, pic will contain rendering of text “Too many atoms to display: X” instead of the 2D image. If the structure failed to render, the pic will contain only white background (as of 9/11/19).

getPropsToShowForCell(cell)

Return a list of (property name, value) for properties to be reported for the given cell.

calculatePropertiesCoordinates(cell, rect)

Returns a list of (propname, value, top_y, bottom_y) for all properties that are to be displayed to the cell. This information is then used for drawing properties and for displaying tool tips. # Ev:91560

keyPressEvent(event)

Will get called when a key is pressed

mark(ignored=None)
setNumColumns(new_num_cols)
cellDoubleClicked(item)
toggleZoomView()
previousStructure()
nextStructure()
rotateLeft()
rotateRight()
flipHorizontal()
flipVertical()
selectOnlyCellIndex(index)

Select only the cell with the given index

selectOnlyCellI(i)
showZoomCellStatus()

Show the group info in the status field.

enterZoomView()
exitZoomView()
zoomContextMenuRequested(pos)
inZoomMode()

Return True if currently in zoom (single structure) mode.

getZoomCell()

Return the Cell object for the currently zoomed cell.

gridContextMenuRequested(pos)

Handle the display of contextual menu when the user right-clicks on a row in the table.

showContextMenu(cell)

Show contextual menu for the given 2D cell, at the current position of the mouse cursor.

tableSelectionChanged(selected, deselected)

Called by Qt when table selection is changed

includeSelectedCellsEntries()

Include all selected cell’s entries in the Workspace, and exclude any other entries.

updateReferenceMenu()
updateInfoLabel()

Update the label that shows how many structure are loaded, and how many are selected.

showEntryIds(entry_ids_to_show)

Populate the table with the given entry IDs.

populateTableWithProgress(st_iter, count, dialog_text, disable_auto=False)

Populate the table with the structure iterator and launch a progress if there is a certain amount of structures.

Parameters
  • st_iter (Iterator[Structure, int]) – generator of structures and entry id

  • count (int) – total count of structures

  • dialog_text (str) – progress text displayed in dialog

  • disable_auto (bool) – whether to disable the auto update checkbox when user cancels import

calculatePropertyPrecisions()
populateTableFromStructures(st_iterator)
generateCellForEntry(eid, st)

Update the cell for the specified entry (if loaded) to the latest structure present in the PT.

alignAllToReference()
referenceChanged(i)
setCellAsReference(cell)

Called when “Set Structure as Reference” is selected from contextual menu.

refreshTable()

Redraw the table (if in grid view) or the zoom widget (if in single structure view).

propsChanged()
synchFromFile(infile)

Initializes the 2D viewer from the input file.

readStructsFromFile(infile)

Generate structures from the input file.

Parameters

infile – input file

quitPanel()

It gets called when panel quits (not just gets hidden)

clearTable()
setDefaults()

Reset the GUI

getSelectedCell()

Returns the selected cell. Should only be used when only one is selected Raises an ValueError if no cells are selected.

iterateOverSelectedIs()

One by one, return index (to the model) of selected cells.

iterateOverSelectedCells()

Iterator for all selected cells (sorted)

getSelectedEntryIds()

Return a list of entry IDs for selected cells.

getNumCells()

Return the number of cells that is currently loaded into the panel.

getAllCells()

Return the list of Cell objects stored in the model.

getStructToRender(cell)

Return the Structure object for this cell. Protein atoms will be excluded.

removeSelectedFromTable()

Remove selected cells from the 2D Viewer table.

cellClicked(index, x, y)

Called for mouse clicks in the cell

exportImages()
exportStructures()
exportToPdfFile(outfile)
exportToHtml(outfile)
exportToPngFile(outfile)

Export all structures to one or several PNG files. Derive base name from given file name.

exportTo2dSdFile(outfile)

Export all structures to a 2D SD file.

exportTo3dSdWithSmilesFile(outfile)

Export all structures to the given 3D SD file, with SMILES string set as a property.

numSelectedCells()

Returns number of selected cells. This method is optimized for speed.

getKplsData(st)

Calculate list of color for KPLS annotations, atomic factors, and predicted value. Returns empty lists if 2D Viewer was not opened via AutoQSAR panel.

Parameters

st (structure.Structure) – Structure to process

Returns

List of atom colors, List of factors, predicted activity

Return type

(list, list, float or None)

getPropertyLabels(st)

Calculate list of strings for property annotations. Returns empty list if there’s nothing to display

loadRendererForCell(cell)

Return sketcher.Renderer class, populated with structure from the given cell. Returns None if structure has too many atoms.

generatePicFromCell(cell)

Generate QPicture of the 2D structure of the cell. If structure has too many atoms, “Too many atoms to display: X” will be drawn.

getPictureForCell(cell)

Return a QPicture object for the given cell. Cached picture is used if present - if not, new QPicture is generated and cached in the delegate.

generate2dCoords(cell, st, include_hs)

Generate 2D coordinates for the given cell. If it’s a reference, or no alignment to reference is done, coordinates are based on the cell entry’s 3D coordinates. If there is a reference present, and cell is aligned to it, the reference 3D structure is used as template.

Parameters

include_hs (bool) – Whether to include explicit hydrogens

getImageFromPic(pic, dimensions=None, transparent=False)

Generates a QImage from the given QPicture.

Parameters
  • pic (QtGui.QPicture) – QPicture to render

  • dimensions ((int, int)) – Width and height of the image to produce. if None, QPicture’s bounding rect will be used for sizing, and image size will depend on size of the structure - larger structures will take up more pixels. Also aspect ratio will NOT be the same for all images.

  • transparent (bool) – Whether to use transparent background instead of white.

generateHtml(outfile)

Generates the HTML file from the saved images

generatePdf(outfile)

Generates the PDF file from the saved images.

Parameters

outfile (str) – Path to the PDF file to generate.

clearAutQsarModel()

Clear AutQSAR model.

setAutoQsarModel(kpls_file, model_id, fit_prop)

Set the KPLS model to be used for visualization. If set to (None, None) clear the KPLS visualization model. :param kpls_file: filename for kpls.tar.gz file from model :type kpls_file: str :param model_id: current model name or factor index :type model_id: str or int :param fit_prop: The name of the predicted (y) property. :type fit_prop: str