schrodinger.application.matsci.gutils module

Module for gui utility classes and functions

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.application.matsci.gutils.validate_child_widgets(child_widgets)

Runs each widget’s validators while respecting the validation_order across all other widgets.

Rather than running validators one widget at a time, ensures that the validator with smallest validation_order across widgets is run first, and so on.

Validation methods that call this function and return its value should be decorated with @validation.multi_validator()

Parameters

child_widgets (list) – The widgets to run validations for

Return type

validation.ValidationResults

Returns

The results of validations, or the results up to and including the first failed validation.

schrodinger.application.matsci.gutils.format_tooltip(tip, min_width=None)

Return a formatted tooltip.

Parameters
  • tip (str) – the tip text

  • min_width (int or None) – the minimum tip width, if None a default is used

Return type

str

Returns

the formatted tool tip

schrodinger.application.matsci.gutils.load_job_into_panel(entry_id, panel, load_func)

Load the entry’s job into the panel

Parameters
  • entry_id (int) – The entry to get source path from

  • panel (af2.App) – The panel to load the job into

  • load_func (callable) – The panel method to call to load the job

Return bool

Whether loading was successful

schrodinger.application.matsci.gutils.load_entries_for_panel(*entry_ids, panel=None, load_func=None, included_entry=False, selected_entries=False, load_job=False)
Parameters
  • entry_ids (tuple) – Entry ids to load into the panel

  • panel (af2.App) – The panel to populate

  • load_func (callable) – The panel method to call to load the entries

  • included_entry (bool) – Whether the group’s entries should be included for the panel

  • selected_entries (bool) – Whether the group’s entries should be selected for the panel

  • load_job (bool) – Whether the entry’s job should be loaded into the panel

Raises

RuntimeError – If neither included nor selected entries is being used

Add a Desmond D. E. Shaw logo on the left and a MatSci logo on the right

Parameters

layout (QBoxLayout) – The layout to add the logos to

schrodinger.application.matsci.gutils.sub_formula(formula)

Add <sub></sub> tags around numbers. Can be used to prettify unit cell formula.

Parameters

formula (str) – Formula to add tags around numbers

Return type

str

Returns

Formula with tags added

schrodinger.application.matsci.gutils.color_text(value, color)

Return a string that colors the given value when placed in a widget (for widgets that support rich text).

Parameters
  • value – The value to color. Will be converted with standard f-string conversion for its type.

  • color (str) – The color. Can be either a simple color name like “red” or a hexadecimal RGB value like #007732.

Return type

str

Returns

The rich text with the indicated color

schrodinger.application.matsci.gutils.get_row_from_pt(maestro, entry_id)

Get row from the PT from entry_id

Parameters
  • entry_id (str) – Entry ID

  • maestro (maestro) – Maestro instance

Return type

ProjectRow or None

Returns

Row or None, if not found

class schrodinger.application.matsci.gutils.WheelEventFilterer

Bases: PyQt6.QtCore.QObject

An event filter that turns off wheel events for the affected widget

eventFilter(unused, event)

Filter out mouse wheel events

Parameters
  • unused (unused) – unused

  • event (QEvent) – The event object for the current event

Return type

bool

Returns

True if the event should be ignored (a Mouse Wheel event) or False if it should be passed to the widget

schrodinger.application.matsci.gutils.turn_off_unwanted_wheel_events(widget, combobox=True, spinbox=True, others=None)

Turns off the mouse wheel event for any of the specified widget types that are a child of widget

Note: The mouse wheel will still scroll an open pop-up options list for a combobox if the list opens too large for the screen. Only mouse wheel events when the combobox is closed are ignored.

Parameters
  • widget (QtWidgets.QWidget) – The widget to search for child widgets

  • combobox (bool) – True if comboboxes should be affected

  • spinbox (bool) – True if spinboxes (int and double) should be affected

  • others (list) – A list of other widget classes that should be affected

schrodinger.application.matsci.gutils.run_parent_method(obj, method, *args)

Try to call a function of a parent widget. If not found, parent of the parent will be used and so on, until there are no more parents. *args will be passed to the found function (if any).

Parameters
  • obj (QWidget) – QWidget to use

  • method (str) – Method name to be called

Locate the the requested file from the given project row property. If it isn’t at the linked location, check the source directory for this row. If it still can’t be found, a file dialog will be posted for the user to locate it.

Parameters
  • row (schrodinger.structure.Structure or schrodinger.project.ProjectRow) – The project row or structure with the info

  • linkprop (str) – The property that gives the file link

  • fix_link (bool) – If True, the linkprop will be fixed with any new file location found

  • parent (QWidget) – Any file dialog will be centered over this widget. If not given, no file dialog will be posted.

  • ext (str) – The extension (including ‘.’) of the file. Used only by the file dialog.

  • idtag (str) – The id for the file dialog

  • caption (str) – The caption for the file dialog

  • source_subdir (str) – If given and the source directory property is used to locate the file, look in this subdirectory of the source directory. If source_subdir is simply True, then if file doesn’t exists in the current directory, the subdir name is taken from the final directory in the path obtained from linkprop. For instance, if source_subdir=True and the path obtained from linkprop is /a/b/c/d, d will be the file name and c will be the source_subdir. If the source path is used and found to be /e/f/g, the file looked for will be /e/f/g/c/d.

Return type

str or None

Returns

The path to the file if found, otherwise None

schrodinger.application.matsci.gutils.fill_table_with_data_frame(table, data_frame)

Fill the passed QTableWidget with data from the passed pandas data frame

Parameters
  • table (QTableWidget) – The table to fill

  • data_frame (pandas.DataFrame) – The data frame to read values from

schrodinger.application.matsci.gutils.disable_table_sort(table)

CM to disable sorting on a table.

Parameters

table (QTableWidget) – the table

schrodinger.application.matsci.gutils.shrink_panel(panel)

Shrinks the panel when removing widgets so that blank space is removed. Doesn’t not work on Mac.

Parameters

panel (af2.BasePanel) – The panel to shrink

schrodinger.application.matsci.gutils.remove_spacers(layout, orientation=None)

Remove all spacer items from the given layout and any layout it contains

Parameters
  • layout (QtWidgets.QLayout) –

  • orientation (str or Qt.Orientation) – The orientation of the spacer to remove. Should be either swidgets.VERTICAL or swidgets.HORIZONTAL, or a Qt.Orientation enum

schrodinger.application.matsci.gutils.expected_text_width(widget, text=None, chars=None)

Get the expected width of some text given the widget’s font settings

Parameters
  • widget (QWidget) – The widget the text will display on

  • text (str) – The exact text to display

  • chars (int) – The number of characters that will be displayed. An average width for this many characters will be return.

Return type

int

Returns

The expected width of the given text when displayed on widget

schrodinger.application.matsci.gutils.add_maestro_banner(text, text2='', action='', command='', action2='', command2='', action_in_new_line=False)

Add a temporary Maestro banner at the top of the Workspace. Supports adding clickable hyperlinks with actions

Parameters

text (str) – The banner text

See Prototype::addPythonBanner() in mmshare/maestro/src/main/prototype.h for other arguments

schrodinger.application.matsci.gutils.get_matplotlib_toolbar_message(event)

Get the toolbar message based on the mouse event

Parameters

event (matplotlib.backend_bases.MouseEvent) – Contains information about the location of the cursor and above which matplotlib.axes.Axes object the cursor was at the time of the event, if any.

Return str

The toolbar message

schrodinger.application.matsci.gutils.subscript_chemical_formula(formula)

Subscript all numbers in a string. Used to make chemical formulas look prettier.

Parameters

formula (str) – The chemical formula you want to format, e.g., ‘H2O’

Return str

The subscripted chemical formula, e.g., ‘H<sub>2</sub>O’

schrodinger.application.matsci.gutils.subscript_cg_formula(formula)

Subscript numbers in a string that follow closing parentheses. Used to make chemical formulas for coarse-grain structures look prettier.

Parameters

formula (str) – The chemical formula you want to format, e.g., ‘(W)80(BENZ)20)’

Return str

The subscripted chemical formula, e.g., ‘(W)<sub>80</sub>(BENZ)<sub>20</sub>)’

schrodinger.application.matsci.gutils.error(widget, msg)

Display an error dialog with a message

Parameters
  • widget (QWidget) – Widget

  • msg (str) – The message to display in the error dialog

schrodinger.application.matsci.gutils.info(widget, msg)

Display an information dialog with a message

Parameters
  • widget (QWidget) – Widget

  • msg (str) – The message to display in the information dialog

schrodinger.application.matsci.gutils.set_min_dimensions(panel, width=800, height=700)

Set the minimum dimensions of the panel.

Parameters
  • panel (af2.App) – the panel for which the minimum dimensions will be set

  • width (int) – the minimum width

  • height (int) – the minimum height

schrodinger.application.matsci.gutils.ignore_maestro_callbacks(attribute=None)

A decorator which accepts class attribute which is has ignoreMaestroCallbacks context manager

Parameters

attribute (str) – attribute which has ignoreMaestroCallbacks context manager

schrodinger.application.matsci.gutils.safe_data_export(fname, parent=None, text=None, data_frame=None, **kwargs)

Call this method instead of numpy.savetxt or pandas.DataFrame.to_csv for exporting the data to a text file. Raises the error dialog if fails to write the data. Either text or data_frame should be passed and not both. Additional kwargs get passed to numpy.savetxt or pandas.DataFrame.to_csv methods.

Parameters
  • fname (str) – File name with complete path

  • parent (QWidget) – Parent widget to raise the error dialog from

  • text (numpy.ndarray) – Data to be saved in the text file format.

  • data_frame (pandas.DataFrame) – DataFrame to be exported in CSV format.