schrodinger.ui.qt.input_selector module

This module provides the InputSelector class, which allows the user to specify the source of structures (Workspace, Project Table, File).

schrodinger.ui.qt.input_selector.get_workspace_structure()

Returns the Workspace structure. If only one entry is in workspace, then the properties are included as well.

schrodinger.ui.qt.input_selector.format_list_to_filter_string(filetypes)

Converts Tkinter-style file types list to Qt-style filter string. Deprecated. Use Qt style filter strings directly instead.

class schrodinger.ui.qt.input_selector.InputSelector(parent, **kwargs)

Bases: PyQt6.QtWidgets.QFrame

An application input source selection widget.

Allows the user to choose the source of the job input: Project Table, files, or Workspace (which is not included entries, just the Workspace ct).

Configuration options set via constructor keywords.

Parameters
  • filetypes – If file input allowed, the file filters used in the browse dialog. Either a QFileDialog filter string, or a Tk-type list of tuples, in format: [('Maestro Files', '*.mae'), ...]

  • initialdir – If file input allowed, the default initial directory in the file dialog. Default is ‘.’.

  • file – Allow an external file as an input source. Default is True.

  • selected_entries – Allow the selected Project Table entries to be used as an input source. Maestro only. Default is True.

  • included_entries – Allow the included Project Table entries to be used as an input source. Maestro only. Default is False.

  • included_entry – Allow the single included Project Table entry to be used as an input source. An error is presented if more than one entry is included. Properties are preserved. Maestro only. Default is False.

  • workspace – Allow the Workspace structure as an input source. If more than one entry is included, they are merged and CT-level properties are dropped. Maestro only. Default is True. Consider using the ‘included_entries’ or ‘included_entry’ instead.

  • default_source – What the default source should be. Must be one of: “file”, “selected_entries”, “included_entries”, “included_entry”, or “workspace”. Default is “selected_entries”, if enabled; if not, then “file” (if enabled)

  • writefile – Automatically generate the ‘<jobname>.<ext>’ file from WS/PT/FILE source. Default is True. If True: The written file name is stored as ‘inputstrucfile’ in the _InputParameters object. If False: For FILE source, store file path to “inputstrucfile”. For other sources, nothing is stored. It is user’s job then use this information as desired.

  • label_text – Default is: ‘Use structures from:’

  • file_text – Default is: “File name:” / “File names:”

  • tracking – Track whether structures selected for input have changed. Type of changes tracked: ( User changes input type (File/Workspace/Etc.), User selects a new file (via Browse or typing), PT inclusion/selection changes when those are the selected input, Workspace changes when Workspace is the selected input). When one of these changes occur, the InputSelector object emits an input_changed signal. Workspace changes are not tracked for PT selection source, unless extra_ws_tracking is set to True. Tracking will only occur if the panel is currently shown. The default is tracking=False because this adds overhead to every workspace change and project update.

  • extra_ws_tracking – Typically input_changed signal is not emitted on Workspace changes if source is PT Selection. If this option is set, and one of selected entries if included in the Workspace, emit input_changed if the Workspce changes with one of these events: WORKSPACE_CHANGED_EVERYTHING, WORKSPACE_CHANGED_APPEND, or WORKSPACE_CHANGED_CONNECTIVITY. This will result in multiple input_changed signal emissions for a single change in inclusion - one for the project update and multiple emits because Maestro calls the callback multiple times for each (un)inclusion. No signal will be emitted for workspace changes if none of the selected entries are currently included in the Workspace. The default is extra_ws_tracking=False due to the extra overhead of this signal.

These are not _InputParameters attributes, and the input structure file is not written by this class. InputSelector does that work.

Variables

source_changed (QtCore.pyqtSignal) – signal emitted when the input source has changed; emitted with the new input source string

input_changed

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.

source_changed

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.

FILE = 'file'
SELECTED_ENTRIES = 'selected_entries'
PROJECT_TABLE = 'selected_entries'
INCLUDED_ENTRIES = 'included_entries'
INCLUDED_ENTRY = 'included_entry'
WORKSPACE = 'workspace'
__init__(parent, **kwargs)

See class docstring. Raises an Exception if no input source is allowed.

current_file

The currently chosen file path if tracking is on

setInputSourceComboVisible(set_visible)

Show or hide input source combo.

Parameters

set_visible (bool) – True - show input combo, False - hide it.

addFileWidgets()

Add widgets associated with a file input source to the input frame.

addRangeWidgets()

Add from/to range widgets under the file entry field.

inputState()

Return the input type as class constant FILE, SELECTED_ENTRIES, INCLUDED_ENTRIES, INCLUDED_ENTRY, or WORKSPACE. Returns the current state of the menu. For the state at the time of call to setup(), use InputSelector.sourceType() method.

setInputState(input_state)

Set the input type.

Parameters

input_state (str) – The input state to change to. It must one of FILE, SELECTED_ENTRIES, INCLUDED_ENTRIES, INCLUDED_ENTRY, or WORKSPACE.

Raises

ValueError – If the specified input type is not present

getFile()

Private method; use structFile() method instead.

Returns the contents of the filename entry field. If self.original_dir is defined, relative paths will be converted to absolute paths based on that (This is expected by AF2).

Returns ‘’ if this is called while file input is not allowed.

getFiles()

Private method; use structFiles() method instead.

Return the list of file names from the file entry field. This is a true list, not a comma-separated list.

setFile(filename)

Private method; do not use directly.

Select the specified filename in the input selector. To specify multiple files, separate them using commas. “File” or “Files” will be selected as the input source as appropriate.

Parameters

filename (str) – The name of the file or files to select

Raises
  • RuntimeError – If the file entry input state is not avaiable.

  • ValueError – If multiple files were provided, but the multiple files input state is not available.

validate()

Validate that the InputSelector is in a consistent and complete state. Returns an error string if the input is empty or invalid, or None if input is valid.

Return type

None or str

Returns

None on success, or an error string if no structures are specified (i.e. the source is set to FILE but there is no specified file name, source is selected entries and no entries are selected, etc.) or otherwise invalid.

validateEntries(rows)

Ensure that the passed entry rows are valid

Parameters

rows (iterable) – Project rows

Return type

str or None

Returns

Error message

writePTEntries(filename, source)

Write selected Project Table entries to ‘filename’.

Raises a RuntimeError on error. Returns False if the user cancelled. Returns True on success.

reset()

Clear the file path (if any) and range (if enabled), and set the source to the default source.

setup(jobname)

This method serializes the input structure(s) to disk and stores the name of the file in the self.params instance. Returns False (i.e., aborts the setup cascade) if no input structure file is written. Otherwise, returns True.

Parameters

jobname (str) – Determines what base name to use for the structure file that gets written.

Job parameters set by this method are…

inputstrucsource - The input source type that was used (FILE,

SELECTED_ENTRIES, INCLUDED_ENTIRES, INCLUDED_ENTRY, or WORKSPACE).

inputstrucfile - If “writefile”, the name of the written

structure file (<jobname>.<ext>); otherwise the path to the user-specified structure file. (not set when “multiplefiles” is True)

inputstrucfiles - If “writefile” is True, this is a list with

one file (same as inputstrucfile); if False a list of selected file paths. (only set if “multiplefiles” is True)

inputstrucorigfile - Original path to the user-specified input file,
(only set if source is FILE, “writefile” is

True, and “multiplefiles” is False).

Unused parameters are set to None.

browseFiles()

Callback method of the file browse button. Pops up a file selector and places the selected file name into the file text field

addCallback(callback_adder, method)

Add a callback for a method - quietly do nothing if such callback already exists. Example: self.addCallback(maestro.workspace_changed_function_add, self.wsChanged)

This method tracks callbacks that are added for easy removal later. This tracking is done because Maestro prints an uncatchable WARNING to the terminal if we try to remove a callback that has not been added.

Parameters
  • callback_adder (callable) – A callable function that adds a callback, such as maestro.workspace_changed_function_add

  • method (callable) – The method to use as the callback function.

removeCallback(callback_adder, method)

Remove a callback that may have been registered previously - silently do nothing if the callback isn’t registered. We need to track callbacks in this manner because Maestro prints a WARNING message to the terminal if a non-registered callback is attempted to be removed.

Parameters
  • callback_adder (callable) – A callable function that adds a callback, such as maestro.workspace_changed_function_add. This adder and its remover must be entered into the callback_removers dictionary.

  • method (callable) – The method to use as the callback function.

addAllCallbacks()

Add callbacks.

removeAllCallbacks()

Remove any previously added callbacks. We need to track callbacks in this manner because Maestro prints a WARNING message to the terminal if a non-registered callback is attempted to be removed.

getFileInputInfo()

Emit input_changed if the new file picked by the user is different from the old file

getSelectedEntryInfo()

Set self._previous_selection to the entries that are selected by the user, depending on the source. Trigger input_changed if the selection has changed.

For INCLUDED_ENTRY and INCLUDED_ENTRIES, this is the IDs of the entries included in the Workspace. For SELECTED_ENTRIES, it’s the IDs of the entries selected in the PT.

workspaceChanged(what_changed)

If tracking is enabled, emit input_changed if the Workspace change merits it.

Parameters

what_changed (maestro module constant (str)) – Description of what changed

projectUpdated()

If tracking is enabled, emit input_changed when PT source is included or selected entries, and user’s entry selection changes.

showEvent(event)

Make sure the proper signals are emitted and proper callbacks are registered when the panel shows itself

Parameters

event (QShowEvent) – The QEvent object generated by this event

Returns

The return value of the QFrame showEvent method

hideEvent(event)

Deregister callbacks when the panel hides itself so that we are not monitoring changes when the panel is inactive.

Parameters

event (QHideEvent) – The QEvent object generated by this event

Returns

The return value of the QFrame hideEvent method

structures(validate=True)

A generator that returns the user-specified input structures one at a time.

API Example:

# appframework1
for struct in self._if.structures():
    do something
# appframework2
for struct in self.input_selector.structures():
    do something
Parameters

validate (bool) – Validate that the InputSelector is in a consistent and complete state (rows are actually selected or file is specified, etc.) Return an empty iterator if input is empty or invalid. Default is True. This option is obsolete.

cmsModels(allow_mae=False)

A generator that returns the user-specified Cms model structures one at a time.

Parameters

do_raise (bool) – Whether to raise if entry is not a Cms. If False, None is yielded if entry is not a Cms model

Return type

generator of cms.Cms

Returns

Each item yielded is a Cms model

Raises

TypeError – If any of the selected input is not a valid Cms model

countStructures()

Return the number of structures specified. If input is invalid, zero will be returned. NOTE: If input source is file, this call can take some time for larger structures files.

Returns

Number of input structrues

Return type

int

structFile()
structFiles()
originalStructFile()
sourceType()
af2SettingsGetValue()

This function adds support for the settings mixin.

Returns

(Input source string, file path)

Return type

(str, str)

af2SettingsSetValue(value)

This function adds support for the settings mixin.

Parameters

value ((str, str)) – (Input source string, file path).