schrodinger.application.matsci.ml_formulations_gui_utils module¶
Utilities for Machine Learning Formulations GUI
Copyright Schrodinger, LLC. All rights reserved.
- schrodinger.application.matsci.ml_formulations_gui_utils.validate_smiles(smiles)¶
A cached function that wraps the adapter.validate_smarts function to validate the smiles string
- Parameters
smiles (str) – The smiles string to validate
- Returns
True if the smiles is valid, False otherwise
- Return type
bool
- class schrodinger.application.matsci.ml_formulations_gui_utils.FormulationData(formulation_info)¶
Bases:
PyQt6.QtCore.QObject
Class to hold data for a formulation, the data is passed to widgets as references so that it can be edited by the user.
properties: A dictionary of the properties of the formulation
- compositions: A dictionary with the component name as the key and
composition as the value
- info: A dictionary of the formulation information where key is the
column name and value is the value of the column of the formulation in the formulation CSV. This used to write the formulation data back to the CSV
property_updated is emitted when the user updates the value of a property in the formulation
- property_updated¶
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.
- __init__(formulation_info)¶
Initialize the FormulationData
- Parameters
formulation_info (dict) – A dictionary of the formulation information where key is the column name and value is the value of the column of the formulation in the formulation CSV
- fixSmiles(smiles, index)¶
Helper function for the constructor to fix the smiles string and validate it. There can be 3 cases: 1. User provided a valid smiles string, return the smiles and True 2. User provided a compound name (invalid smiles), return the name and False 3. User used predefined missing smiles as a placeholder, return the component name and False
- Parameters
smiles (str) – The smiles string to fix
index (str) – The index of the component
- Returns
The fixed smiles string and whether the smiles is valid
- Return type
tuple(str, bool)
- getComponentKey(component)¶
Get the key for the given component from the name of the component
- Parameters
component (str) – The component to get the key for
- Returns
The key for the component
- Return type
str
- getComposition()¶
Get the composition of the formulation
- Returns
The composition of the formulation where the keys are the COMPONENT and the values are the composition
- Return type
dict
- getProperties()¶
Get the properties of the formulation
- Returns
The properties of the formulation where the keys are the property names and the values are the property values
- Return type
dict
- addProperty(prop, value)¶
Add a property to the formulation
- Parameters
prop (str) – The name of the property to add
value (float) – The value of the property
- updateComposition(name, composition)¶
Update the composition of the formulation
- Parameters
name (str) – The name of the component to update
composition (float) – The new composition of the component
- updateComponent(old_name, new_name)¶
Update the name of the component in the formulation
- Parameters
old_name (str) – The old name of the component
new_name (str) – The new name of the component
- Raises
ValueError – If the new name already exists, due to duplicate
- updateProperties(prop, value)¶
Update the property value of the formulation
- Parameters
prop (str) – The name of the property to update
value (float) – The new value of the property
- removeProperty(prop)¶
Remove the property from the formulation
- Parameters
prop (str) – The name of the property to remove
- getCSVData()¶
Get the data for the formulation in the format to write to the CSV file
- Returns
The data with the keys as SMILES, COMPOSITION, and Properties as keys and the values as the values of the formulation. The values are empty strings if the value in SMILES is not a valid smiles.
- Return type
dict
- class schrodinger.application.matsci.ml_formulations_gui_utils.FormulationCSVReader¶
Bases:
object
Helper class to read the formulation CSV file
- validateHeader(header, required_props=None)¶
Validate the header of the csv file
- Parameters
header (list) – The list of header values in the csv file
required_props (list) – The list of required properties that must be present in the csv file
- Raises
ValueError – If the headers in the csv file are not valid
- getFormulationsFromCSV(csv_reader, required_props=None, skip_props=None)¶
Get the formulations from the CSV reader
- Parameters
csv_reader (csv.DictReader) – The csv reader object
required_props (list) – The list of required properties that must be
skip_props (list) – The list of properties to skip
- Returns
The list of formulations
- Return type
list(FormulationData)
- readCSVData(filename, required_props=None)¶
Read the data from the CSV file
- Parameters
filename (str) – The filename of the CSV file
required_props (list) – The list of required properties that must be present in the csv file. If None, there will be no requirement of properties
- Returns
The list of formulations
- Return type
list(FormulationData)
- readCSVIOData(csv_io, skip_props=None)¶
Read the data from the CSV StringIO object
- Parameters
csv_io (io.StringIO) – The StringIO object of the CSV file
skip_props (list) – The list of properties to skip
- Returns
The list of formulations
- Return type
list(FormulationData)
- class schrodinger.application.matsci.ml_formulations_gui_utils.ScrollableAreaWidget(v_scroll_bar=False)¶
Bases:
PyQt6.QtWidgets.QWidget
Scrollable data area that holds the formulation data
bottom_reached: signal is emitted when the bottom of the scroll area is reached
- bottom_reached¶
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.
- __init__(v_scroll_bar=False)¶
Initialize the ScrollableAreaWidget
- Parameters
v_scroll_bar (bool) – Whether to show the vertical scroll bar
- setupInternalWidget()¶
Setup the internal widget that holds the data in the scroll area
- connectVScrollSync(other_scroll_area)¶
Connect the scroll current scroll area to another scroll area to allow for synchronized vertical scrolling
- Parameters
other_scroll_area (ScrollableAreaWidget) – The other scroll area to connect to
- connectHScrollSync(other_scroll_area)¶
Connect the scroll current scroll area to another scroll area to allow for synchronized horizontal scrolling
- Parameters
other_scroll_area (ScrollableAreaWidget) – The other scroll area to connect to
- class schrodinger.application.matsci.ml_formulations_gui_utils.DataRowWidget(layout)¶
Bases:
PyQt6.QtWidgets.QWidget
Widget to hold the widgets for a row in the formulation table view. The widget has three sections:
Top section is the frame to display the warnings. Middle section is the frame to display the data. Bottom section is the frame to display the widgets to edit the data. The top and bottom sections are hidden by default.
- __init__(layout)¶
Initialize the DataRowWidget
- Parameters
layout (QtWidgets.QLayout) – The layout to add the widget to
- setRowMessage(message)¶
Set the message to display in the top section of the widget
- Parameters
message (str) – The message to display
- addDataColumnWidget(widget, fixed_width)¶
Add a widget to the middle section of the widget
- Parameters
widget (QtWidgets.QWidget) – The widget to add in the horizontal layout
fixed_width (int) – The width of the widget
- addEditColumnWidget(widget)¶
Add a widget to the bottom section of the widget
- Parameters
widget (QtWidgets.QWidget) – The widget to add in the horizontal layout
- finalizeRowLayout()¶
Hide the top and bottom sections of the widget and add stretch to the sections once all the widgets have been added
- toggleMessageVisibility(state)¶
Toggle the visibility of the top section of the widget
- Parameters
state (bool) – The state to set the visibility to
- toggleEditVisibility()¶
Toggle the visibility of the bottom section of the widget
- class schrodinger.application.matsci.ml_formulations_gui_utils.SketcherSMILESDialog(title: str, parent=None)¶
Bases:
schrodinger.ui.sketcher_smarts_dialog.SketcherSMARTSDialog
Dialog to show SMILES in sketcher and get the updated SMILES from sketcher
smiles_accepted is emitted when the user accepts the dialog and the new SMILES value is passed as an argument
- smiles_accepted¶
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.
- accept()¶
Accept the dialog
- class schrodinger.application.matsci.ml_formulations_gui_utils.CustomTooltip(text)¶
Bases:
PyQt6.QtWidgets.QWidget
A custom tooltip that can be used to display a message
- __init__(text)¶
Initialize the tooltip
- Parameters
text (str) – The text to display in the tooltip
- class schrodinger.application.matsci.ml_formulations_gui_utils.ValueLabel(text, parent_width, layout=None, fixed_width=None, **kwargs)¶
Bases:
PyQt6.QtWidgets.QLabel
A label that is used to display a formulation property values
- __init__(text, parent_width, layout=None, fixed_width=None, **kwargs)¶
Initialize the label
- Parameters
text (str) – The text to display in the label
parent_width (int) – The width of the parent widget
layout (QtWidgets.QLayout) – The layout to add the label to
fixed_width (int) – The fixed width of the label
- setElidedText(text)¶
Set the text of the label and elide it if it is too long. Keep the original text as the tooltip
- Parameters
text (str) – The text to display in the label
- class schrodinger.application.matsci.ml_formulations_gui_utils.ClickableLabel(text, command, parent_width, layout=None, fixed_width=None)¶
Bases:
schrodinger.application.matsci.ml_formulations_gui_utils.ValueLabel
A label that behaves like a link and can be clicked
- clicked¶
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.
- __init__(text, command, parent_width, layout=None, fixed_width=None)¶
- Parameters
text (str) – The text to display in the label
command (function) – The command to run when the label is clicked
parent_width (int) – The width of the parent widget
layout (QtWidgets.QLayout) – The layout to add the label to
fixed_width (int) – The fixed width of the label
- setToolTip(text)¶
Set the tooltip text for the label
- Parameters
text (str) – The text to display in the tooltip
- updateStyle(color, font_weight='normal')¶
Update the style of the label
- Parameters
color (str) – The color of the label
font_weight (str) – The font weight of the label
- hideCustomTooltip()¶
Hide the custom tooltip
- enterEvent(event)¶
Update the style of the label when the mouse enters the label to behave like hover in a link
- Parameters
event (QtCore.QEvent) – The enter event
- leaveEvent(event)¶
Update the style of the label when the mouse leaves the label
- Parameters
event (QtCore.QEvent) – The leave event
- mousePressEvent(event)¶
Emit the clicked signal when the label is clicked
- Parameters
event (QtCore.QEvent) – The mouse press event
- class schrodinger.application.matsci.ml_formulations_gui_utils.ValueEdit(text, command, fixed_width, validator, read_only=False)¶
Bases:
schrodinger.ui.qt.swidgets.SLineEdit
Line edit widget that is used to edit the formulation values
_editing_finished is emitted when the user finishes editing the value and the new value is passed as an argument
- __init__(text, command, fixed_width, validator, read_only=False)¶
- Parameters
text (str) – The text to display
command (function) – The command to run when the text is changed
fixed_width (int) – The width of the line edit widget
validator (QtGui.QValidator) – The validator to use for the line edit
read_only (bool) – Whether the line edit is read only
- class schrodinger.application.matsci.ml_formulations_gui_utils.ClickableProgressBar(value, layout)¶
Bases:
PyQt6.QtWidgets.QProgressBar
Progress bar that emits a signal when clicked on clicked
- clicked¶
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.
- __init__(value, layout)¶
Initialize the progress bar
- Parameters
value (int) – The value to set the progress bar to
layout (QtWidgets.QLayout) – The layout to add the progress bar to
- setValue(value)¶
Override the setValue method to set the tooltip to the value
- mousePressEvent(event)¶
Override the mousePressEvent to emit a signal when clicked
- class schrodinger.application.matsci.ml_formulations_gui_utils.ComponentsWidget(name, composition, command)¶
Bases:
PyQt6.QtWidgets.QWidget
,schrodinger.ui.qt.widgetmixins.basicmixins.MessageBoxMixin
Widget to hold the component name (can be SMILES) string and the progress bar to display the composition of the component
- name_changed is emitted when the user changes the name string using
the sketcher and old and new names are passed as arguments
- name_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.
- __init__(name, composition, command)¶
- Parameters
name (str) – The name string to display
composition (float) – The composition of the component in the formulation
command (function) – The command to run when the progress bar is clicked
- updateComposition(composition)¶
Update the composition of the component
- Parameters
composition (float) – The new composition
- updateName(name)¶
Update the component name
- Parameters
name (str) – The new name of the component
- showSketcher()¶
Show the sketcher dialog to edit the SMILES string
- class schrodinger.application.matsci.ml_formulations_gui_utils.FormulationRowManager(formulation, composition_layout, properties_layout)¶
Bases:
object
Class to manage the widgets in a row of the formulation table view
- __init__(formulation, composition_layout, properties_layout)¶
Initialize the FormulationRowManager
- Parameters
formulation (ml_formulations_gui_utils.FormulationData) – The formulation data to display in the row
composition_layout (QtWidgets.QLayout) – The layout to add the composition widgets to
properties_layout (QtWidgets.QLayout) – The layout to add the properties widgets to
- getTotalComposition()¶
Get the total composition of the formulation
- Returns
The total composition of the formulation
- Return type
float
- addCompositionRow()¶
Add the composition widgets to the composition row
- addPropertiesRow()¶
Add the properties values to the properties row
- toggleMessageVisibility(state=None)¶
Toggle the visibility of the message in the row
- toggleEditVisibility()¶
Toggle the visibility of the edit widgets in the row
- compositionUpdated(composition_widget, value)¶
Update the composition of the component in the formulation
- Parameters
composition_widget (ComponentsWidget) – The widget that was updated
value (str) – The new value of the composition
- nameUpdated(old_name, new_name)¶
Update the name of the component in the formulation
- Parameters
old_name (str) – The old name of the component
new_name (str) – The new name of the component
- deleteLater()¶
Delete the widgets in the row
- class schrodinger.application.matsci.ml_formulations_gui_utils.ScrollableAreaManager(grid_layout, scroll_update)¶
Bases:
object
Manager for the scrollable area that holds the formulation data that are separated into two different areas: composition and properties
- __init__(grid_layout, scroll_update)¶
Initialize the scrollable area manager
- Parameters
grid_layout (QtWidgets.QGridLayout) – layout of the parent widget
- syncPropertyTitlesHScroll(property_titles)¶
Connect the property titles to the scrollable areas to allow for synchronized horizontal scrolling
- Parameters
property_titles (PropertyTitlesArea) – The property titles widget
- addRow(formulation)¶
Add the formulation data to the respective areas
- Parameters
formulation (ml_formulations_gui_utils.FormulationData) – The formulation data to add to the widgets
- reset()¶
Reset the scrollable areas
- class schrodinger.application.matsci.ml_formulations_gui_utils.PropertyTitlesArea(properties)¶
Bases:
schrodinger.application.matsci.ml_formulations_gui_utils.ScrollableAreaWidget
Widget to hold the property titles for the formulation table
- property_clicked is emitted when the user clicks on a property title and
the property name is passed as an argument
- property_clicked¶
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.
- __init__(properties)¶
Initialize the PropertyTitles widget
- Parameters
properties (list) – A list of property names
- setupInternalWidget()¶
Override the setupInternalWidget to set the internal widget that holds the property titles
- class schrodinger.application.matsci.ml_formulations_gui_utils.FormulationTableWidget¶
Bases:
PyQt6.QtWidgets.QWidget
Widget that displays the formulation data in a table format
- properties_row_clicked: signal emitted when the properties label is clicked
and the property clicked is passed as an argument
- property_labels_clicked¶
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.
- __init__()¶
Initialize the formulation table widget
- displayData(formulations)¶
Display the formulation data in the table
- Parameters
formulations (list(ml_formulations_gui_utils.FormulationData)) – list of formulations
- loadNextFormulations()¶
Batch load the formulations to the table to avoid freezing the UI
- reset()¶
Reset the widgets
- class schrodinger.application.matsci.ml_formulations_gui_utils.FormulationPlotFrame¶
Bases:
schrodinger.ui.qt.swidgets.SFrame
,schrodinger.ui.qt.widgetmixins.basicmixins.MessageBoxMixin
Widget that displays the distribution of a property in the formulations
- NONE = '(none)'¶
- R_2 = 'R$^2$'¶
- RMSE = 'RMSE'¶
- PEARSON_R = "Pearson's $r$"¶
- __init__()¶
Initialize the widget
- statsEnabled(state)¶
Enable/disable the statistics checkboxes
- Parameters
state (bool) – The state to set the checkboxes to
- statsChecked(state)¶
Set the checked state of the statistics checkboxes
- Parameters
state (bool) – The state to set the checkboxes to
- setProperty(property_name)¶
Set the property to display distribution for
- Parameters
property_name (str) – name of the property
- loadData(formulations)¶
Load the formulations data
- Parameters
formulations (list(ml_formulations_gui_utils.FormulationData)) – list of formulations
- getData(property_name)¶
Get the data for the given property
- Parameters
property_name (str) – name of the property
- Returns
list of property values
- Return type
list
- Raises
ValueError – if the property name is not a number
- getStats(prop_data)¶
Get the statistics for the given property data if the statistics are requested
- Parameters
prop_data (list(list)) – list of property values where the first list is the x values and the second list is the y values
- Returns
dictionary of statistics where the key is the name of the statistic and the value is the value of the statistic
- Return type
dict
- addStatsToPlot(plot_data)¶
Add the statistics to the plot as a legend if the statistics are requested
- Parameters
plot_data (list(list)) – list of property values where the first list is the
- plotScatter()¶
Plot scatter plot of two selected properties.
- plotHistogram()¶
Plot the frequency distribution of the selected property
- replot()¶
Plot the distribution of the selected property
- resetScatter()¶
Reset the scatter plot
- reset()¶
Reset the widget
- class schrodinger.application.matsci.ml_formulations_gui_utils.FormulationsDataTab(program_name)¶
Bases:
schrodinger.ui.qt.swidgets.SFrame
Widget that displays the formulations CSV data in a table format along with the plot
- MIN_PLOT_WIDTH = 500¶
- INITIAL_SPLIT_SIZE = (100, 100)¶
- __init__(program_name)¶
Initialize the widget
- Parameters
program_name (str) – The name of the program
- showPropertyPlot(property_name)¶
Show the distribution plot frame for the selected property
- loadData(formulations)¶
Load the formulations data in the table
- Parameters
formulations (list(ml_formulations_gui_utils.FormulationData)) – list of formulations
- exportData(filename=None)¶
Export the formulations data to a CSV file
- Parameters
filename (str) – The name of the file to export the data to
- validateFormulations()¶
Validate the formulations data
- Returns
Whether the formulations data is valid. If not valid, the error message is also returned
- Return type
bool or bool, str
- reset()¶
Reset the widget