pyretis.pyvisa package

The sub-package with tools for visualizing simulation results for PyRETIS.

This package is intended for compiling data of a simulation into a compact file standard (hdf5), and displaying results from file in a custom GUI applet. Included are compiler of simulation data and a custom-built PyQt5 GUI applet that loads pre-compiled data (or compiles when loading raw simulation data). The applet allows for user-friendly and interactive plotting of combinations of order parameter data of different interfaces and cycles of the simulation.

Package structure

Modules

__init__.py
Imports from the other modules.
common.py (pyretis.pyvisa.common)
Common functions and variables for the visualization. These functions are mainly intended for internal use and are not imported here.
orderparam_density.py (pyretis.pyvisa.orderparam_density)
A module that handles the compiling of data to a single file.
plotting.py (pyretis.pyvisa.plotting)
A module which contains some functions that are used to plot regression lines and interface planes, and generate surface plots.
resources_rc.py (pyretis.pyvisa.resources_rc)
A module containing the resources, icons/logos for the PyVISA GUI.
visualize.py (pyretis.pyvisa.visualize)
A module that handles the loading and plotting of data from a compiled file or a simulation.

Sub-packages

None

Important classes defined in this package

CustomFigCanvas
(pyretis.pyvisa.visualize.CustomFigCanvas) A class for the custom figure shown in the VisualApp class PyQt5 applet.
DataObject
(pyretis.pyvisa.visualize.DataObject) A class that reads from simulation data, holds the data, and supplies the data to VisualApp for plotting.
DataSlave (pyretis.pyvisa.visualize.DataSlave)
QObject class definition that holds the PathDensity data.
PathDensity (pyretis.pyvisa.orderparam_density.PathDensity)
A class for reading, storing, and compiling simulation data.
PathVisualize
(pyretis.pyvisa.orderparam_density.PathVisualize) A class for loading data (compiled or not), and generating plots.
VisualApp (pyretis.pyvisa.visualize.VisualApp)
A QtWidget class that holds a user-defined figure.
VisualObject
(pyretis.pyvisa.visualize.VisualObject) A class that loads from hdf5, holds and, supplies VisualApp with data for plotting.

Important methods defined in this package

_grid_it_up (pyretis.pyvisa.plotting._grid_it_up())
Maps the x,y and z data to a numpy.meshgrid using scipy interpolation at a user defined resolution.
gen_surface(pyretis.pyvisa.plotting.gen_surface())
A function that generates a user-defined surface plot (2D/3D).
_grid_it_up(pyretis.pyvisa.plotting._grid_it_up())
A function that generates a [X,Y] numpy.meshgrid and [Z] grid-data for a given resolution.
plot_int_plane(pyretis.pyvisa.plotting.plot_int_plane())
A function that generates planes of the simulation interfaces for 3D plots.
plot_regline(pyretis.pyvisa.plotting.plot_regline())
A function that generates a linear regression line of x and y data on a given matplotlib.axes object.
shift_data(pyretis.pyvisa.common.shift_data())
A function that shifts data values of a list by the median value.
try_data_shift(pyretis.pyvisa.common.try_data_shift())
A function that attempts a shift of the data values to increase linear correlation.

pyretis.pyvisa.inf module

This module just contains some info for PyRETIS.

Here we define the name of the program and some other relevant info.

pyretis.pyvisa.common module

Common functions for the path density.

Functions used to compare and process data, such as matching similar lists or attempting periodic shifts of values.

Important methods defined here

find_rst_file (:py:func: .find_rst_file)
Search for a rst-file from a chosen subdirectory.
read_traj_txt_file (:py:func: .read_traj_txt_file)
Read the sequence of files in a trajectory from a traj.txt file.
recalculate_all (recalculate_all())
Recalculate order parameter and new collective variables by finding all trajectory files from a simulation.
shift_data (:py:func: .shift_data)
Finds the median value of a given list of floats, and shifts the lower half of the data by the median.
try_data_shift (:py:func: .try_data_shift)
Takes in two lists of values, x and y, and calculates a linear regression and R**2-correlation of the data set. Attempts a shift of each data set by their respective median to increase the correlation.
where_from_to (:py:func: .where_from_to)
Check the initial and final steps of a trajectory with respect to the provided interfaces.
get_cv_names (:py:func: .get_cv_names)
Outputs a list of the names of the descriptors in the simulation.
recalculate_all (:py:func: .recalculate_all)
Recompute all the order parameters according to the PyRETIS storage scheme or for individual files/folders.
find_data (:py:func: .find_data)
Find suitable frames/trajectories to recompute the order parameter on.
pyretis.pyvisa.common._get_trjs(runfolder='.')

Find the trajectory files.

Parameters:runfolder (string, optional) – the location of the main simulation folder.
Returns:full_name_trj (list) – The trajectory files contained in the folder.
pyretis.pyvisa.common._process_ensemble(functions, ens, runfolder)

Process one ensemble: recompute order parameters for every cycle.

Parameters:
  • functions (list) – Order-parameter functions returned by create_orderparameter.
  • ens (dict) – Ensemble entry from the trajectory dict.
  • runfolder (str) – Root path of the simulation run.
pyretis.pyvisa.common._write_cycle(functions, cycles, main_order)

Write order parameters for a single trajectory cycle.

Parameters:
  • functions (list) – Order-parameter functions returned by create_orderparameter.
  • cycles (dict) – Cycle entry from the trajectory dict (contains 'traj' key).
  • main_order (str or None) – Path to the ensemble-level order.txt to append to, or None if no aggregation file is needed.
pyretis.pyvisa.common.find_data(runfolder, ensemble_names=None, data=None)

Find the trajectory data used to do post-processing.

find_traj returns a dict with a structure resembling that of the simulation.

Parameters:
  • runfolder (string, optional) – The path of the execution directory.
  • ensemble_names (list, optional) – List of ensemble names in the simulation to work with.
  • data (string, optional) – If given, the function will check only the single file or look only in the given directory
Returns:

trj_dict (dict) – To each key, ensemble_name (e.g. 000, 001, etc) the values are: the last accepted trajectories given by the accepted-key; the generation trajectory or conf files given by the generation-key, and lastly the dictionary stored_traj that is given by the traj-key. stored_traj is split up into the dictionaries`traj-acc` and traj-rej which have keys for all the accepted and rejected cycles respectively, where the trajectory files for that cycle is stored.

pyretis.pyvisa.common.find_rst_file(search_dir)

Search for rst-files.

Parameters:search_dir (string) – Path to the .rst file.
Returns:out[0] (string) – Path and name of the .rst file.
pyretis.pyvisa.common.get_cv_names(input_settings, num_columns=None)

Return labels for the order parameter and collective variables.

The labels follow the same convention for the main order parameter and any extra collective variable: each [orderparameter] / [collective-variable] block may declare name either as a single string or as a list of strings.

  • A list of strings is used as-is for that block (one label per value returned by the corresponding calculate()).
  • A single string is expanded with an index suffix ("<name>_1", "<name>_2", ...) to match the number of values the block produces. If the block produces a single value the bare string is used.
  • When name is missing the labels fall back to "op_<i>" for the main order parameter and "cv_<i>" for each collective variable (using the bare prefix if the block produces a single value).
Parameters:
  • input_settings (dict) – Dictionary with the settings from the simulations.
  • num_columns (int, optional) – Total number of order-parameter columns observed (e.g. read from order.txt). When supplied, this is used to allocate unspecified blocks: if there is exactly one section configured and num_columns is greater than one, the single name is expanded with indices to cover all columns. When num_columns is given and cannot be reconciled with the configured names, a ValueError is raised.
Returns:

names (list of str) – Flat list of column labels, in the same order as the concatenated calculate() outputs.

Raises:

ValueError – If a name list does not match the number of values produced by its block, or if num_columns cannot be reconciled with the configured names.

pyretis.pyvisa.common.read_traj_txt_file(path)

Read a traj.txt file.

Function which reads a traj.txt file and returns a dict containing the name of each file in the trajectory and the sign of their velocity.

Parameters:path (string) – Path to the traj.txt file.
Returns:files (dict) – Dictionary containing each file in the trajectory and the sign of their velocity.
pyretis.pyvisa.common.recalculate_all(runfolder, iofile, ensemble_names=None, data=None)

Recalculate order parameter and collective variables.

Performs post-processing by analyzing trajectories of old simulations to extract data, do new calculations, and write to a new order.txt file.

Parameters:
  • runfolder (string) – The path of the execution directory.
  • iofile (string) – The input file where the settings are collected.
  • ensemble_names (list, optional) – List of ensemble names in the simulation to work with.
  • data (string, optional) – If given, the function will check only the single file or look only in the given directory
Returns:

out (boolean) – True if the recomputation was successful, False otherwise.

pyretis.pyvisa.common.shift_data(x)

Shifts the data under the median.

Function that takes in a list of data, and shifts all values below the median value of the data by the max difference, effectively shifting parts of the data periodically in order to give clusters for visualization.

Parameters:x (list) – Floats, data values
Returns:xnorm (list) – Floats where some values are shifted values of x, and some are left unchanged.
pyretis.pyvisa.common.try_data_shift(x, y, fixedx)

Check if shifting increases correlation.

Function that checks if correlation of data increases by shifting either sets of values, x or y, or both. Correlation is checked by doing a simple linear regression on the different sets of data: - x and y , x and yshift, xshift and y, xshift and yshift. If linear correlation increases (r-squared value), data sets are updated.

As a precaution, no shift is performed on x values if they are of the first order parameter ‘op1’.

Parameters:
  • x, y (list) – Floats, data values
  • fixedx (bool) – If True, x is main OP and should not be shifted.
Returns:

x, y (list) – Floats, updated (or unchanged) data values (If changed, returns x_temp or y_temp or both)

pyretis.pyvisa.common.where_from_to(trj, int_a, int_b=-inf)

Detect L∕R starts and L / R / * ends.

Given a list of order parameters (a trj), the function will try to establish where the path started (L or R or *) and where it ended. Note: for the ‘REJ’ paths, this function results might differ from PyRETIS.

Parameters:
  • trj (numpy array) – The order parameters of the trj.
  • int_a (float) – The interface that defines state A.
  • int_b (float, optional) – The interface that defines state B. If not given, it is assumed that the 0^- ensemble is in use without the 0^- L interface.
Returns:

  • start (string*1) – The initial position of the trajectory in respect to the interfaces given (L eft, R ight or * for nothing).
  • end (string*1) – The final position of the trajectory in respect to the interfaces given (L eft, R ight or * for nothing).

pyretis.pyvisa.orderparam_density module

Compiler of PyRETIS simulation data.

This module is part of the PyRETIS library and can be used both for compiling the simulation data into a compressed file and/or load the data for later visualization.

Important classes defined here

Trajectory (PathBase)
A base class to store trajectories composed by only orderp, collective variables and energies.
PathDensity (PathBase)
A base class to assemble the data.
PathVisualize (PathVisualize)
A base class to prepare for the visualization.

Important methods defined here

pyvisa_zip (:py:func: .pyvisa_zip)
Compress the PyVisA output file in a .zip format.
pyvisa_unzip (:py:func: .pyvisa_unzip)
Decompress the zip into PyVisA output.
remove_nan (:py:func: .remove_nan)
Checks for the presence of nan values and replace them with a local, if available.
pyvisa_compress (:py:func: .pyvisa_compress)
Compress PyRETIS outputs to a .hdf5 file.
class pyretis.pyvisa.orderparam_density.PathDensity(basepath='.', iofile=None)

Bases: object

Perform the path density analysis.

This class defines the path density analysis for completed simulations with several order parameters.

__init__(basepath='.', iofile=None)

Initialize the class.

Parameters:
  • basepath (string, optional) – The path to the input file.
  • iofile (string, optional) – The input file.
traj_dict

Values of order params and energy in all ensembles and info about trajectories. To each key, ensemble_name (e.g. 000, 001, etc.) the value is the list of respective Trajectory objects.

Type:dict
infos

Information about the simulation, it contains:

  • ensemble_names: list List of ensemble names.
  • interfaces: list List of interface positions.
  • num_op: integer Number of order parameters.
  • op_labels: list List of order parameter names.
  • energy_labels: list List of energy entry labels.
Type:dict
fill_energy(traj, eframes, ensemble_name, cycle)

Fill in energy-data to a trajectory.

Parameters:
  • traj (Trajectory object) – Trajectory object to be filled in energy-data.
  • eframes (dict) – Dictionary containing energy-data for the trajectory.
  • ensemble_name (string) – The name of the ensemble.
  • cycle (integer) – Cycle number.
  • Updates
  • ——-
  • traj_dict (Trajectory object) – Trajectory object with filled in energy-data.
fill_op(frames, info, ensemble_name, cycle)

Fill in OP-data to a trajectory.

Function that fills the dictionary traj_dict containing Trajectory objects with data from the order parameter and the collective variables from the simulation.

Parameters:
  • frames (dict) – Dictionary containing energy-data for the trajectory.
  • info (dict) – Information about the trajectory.
  • ensemble_name (string) – The name of the ensemble.
  • cycle (integer) – Cycle number.
  • Updates
  • ——-
  • traj_dict (Trajectory object) – Trajectory object with filled in OP-data.
get_traj_energy(ensemble_name)

Read energy.txt files and collects energy-data.

Function that fills the dictionary traj_dict containing Trajectory objects with energy data from the simulation.

Parameters:
  • ensemble_name (string) – The name of the ensemble.
  • Updates
  • ——-
  • traj_dict (dict) – Dictionary containing Trajectory objects from simulation with filled in energy-data.
get_traj_op(ensemble_name)

Read order.txt files and collects data OP data.

Parameters:
  • ensemble_name (string)
  • Updates
  • ——-
  • traj_dict (dict) – Dictionary containing Trajectory objects from simulation with filled in OP-data.
hdf5_data()

Compress the data to a .hdf5 file.

initialize_compressed(input_file)

Load PathDensity from a compressed file.

Parameters:input_file (string) – The input file.
walk_dirs(only_ops=False)

Create a lists in acc or rej dictionary for all order parameters.

First generate list of folders/ensembles to iterate through. Then search for number of order parameters(columns) in file in one of the folders of path, and create lists in acc/rej dictionaries for all order parameters.

Lastly iterate through all folders and files, filling in correct data to the lists and dictionaries.

Parameters:only_ops (boolean, optional) – If true, PathDensity will not collect data from energy files.
class pyretis.pyvisa.orderparam_density.PathVisualize(basepath='.', pfile=None)

Bases: object

Class to define the visualization of data with PathDensity.

Class definition of the visualization of data gathered from simulation directory using the PathDensity class.

__init__(basepath='.', pfile=None)

Initialize the PathVisualize class.

If a supported compressed input file is present, loads the pre-compiled data from it. Else, must use specific functions explicitly.

Parameters:
  • basepath (string, optional) – The path of the input file.
  • pfile (string, optional) – The input file.
load_hdf5()

Load precompiled data from a hdf5 file.

Function that loads precompiled data from a .hdf5 file made using pandas.

load_traj(criteria)

Load relevant data from Trajectories.

Parameters:

criteria (dict) – Dictionary of the selection criteria for which data to load. It contains:

  • x: string Name of parameter to plot.
  • y: string Name of parameter to plot.
  • z: string Name of parameter to plot.
  • ensemble_name: string Name of ensemble to loop through.
  • cycles: tuple Cycles to loop over.
  • status: string Status of the path: accepted/rejected.
  • MC-move: string, optional Generation move of the trajectory.
  • stored: bool, optional True if the trajectory has available trajectory files.
  • weights: bool, optional Option to apply statistical weights to the trajectories, used in the weighted density plot.
Returns:

  • x_list (list) – List of data from chosen parameter.
  • y_list (list) – List of data from chosen parameter.
  • z_list (list) – List of data from chosen parameter, if required.
  • data_origin (list) – List of ensemble_name and cycle for each point, if required.

load_whatever()

Load all possible supported files.

This functions directs traffic towards the real loaders. Essentially, it does almost nothing.

class pyretis.pyvisa.orderparam_density.Trajectory(frames, info)

Bases: object

Class representing a simulation trajectory.

This class defines the trajectories from the completed simulations, with all information available. The labels of the order parameter and collective variables will either be labeled in the fashion of opx, or from the names in the input file if the number of names given and number of descriptors in the system are equal.

__init__(frames, info)

Initialize the class.

Parameters:
  • frames (pandas Dataframe or dict) – Dataframe/dict containing order parameter and energy-data for the trajectory. It contains:
    • OP1: string Order parameter.
    • OP2: string Collective variables, all other CV’s will be named in increasing fashion, OP3, OP4 etc.
    • PotE: string Potential energy.
    • KinE: string Kinetic energy.
    • TotE: string Total energy.
  • info (dict) – Dictionary containing information about the trajectory. It contains:
    • ensemble_name: string The name of the ensemble.
    • cycle: integer The cycle number.
    • status: string Status of accepted/rejected etc.
    • MC-move: string Generation move of the trajectory.
    • MC-start: string Generation starting point of the trajectory.
    • ordermax: float Max value of OP.
    • ordermin: float Min value of OP.
    • stored: boolean True if the trajectory has existing trajectory files.
pyretis.pyvisa.orderparam_density.pyvisa_compress(runpath, input_file, pyvisa_dict)

Compress simulation data.

Parameters:
  • runpath (string) – The execution folder where the input files are.
  • input_file (string) – The input file for compression.
  • pyvisa_dict (dict) – It determines the section of pyvisa to use.
pyretis.pyvisa.orderparam_density.pyvisa_unzip(origin, destination=None)

Unzip compressed file before load in visualizer.

Parameters:
  • origin (string) – Zipped file to unzip.
  • destination (string, optional) – Unzipped file name.
pyretis.pyvisa.orderparam_density.pyvisa_zip(input_file)

Zip compress file of simulation data.

Parameters:input_file (string) – The file to compress.
pyretis.pyvisa.orderparam_density.remove_nan(data)

Remove nan from data.

The function shall remove initial nan, assuming that they are originated by incomplete initial conditions (e.g. no energy file). In the case that nan appears as last cycle, it will not be fixed and an error shall rise up later in the code.

Parameters:data (list, dict, object like pandas.DataFrame or pandas.Series) – Input data structure. If np.nan are present, they are replaced by the following entry. The method accounts for multiple consecutive np.nan occurrences.

pyretis.pyvisa.plotting module

This file contains common functions for the visualization.

It contains some functions that are used to plot regression lines and interface planes, and generate surface plots.

Important methods defined here

gen_surface (gen_surface())
Generates a user-defined surface/contour/etc plot with colorbar in given matplotlib.figure and -.axes objects.
plot_int_plane(plot_regline())
Generates interface planes for the current span of x-values, in a given matplotlib.axes-object.
plot_regline (plot_regline())
Calculates the linear regression and correlation, plots a line for the regression in the given matplotlib.axes-object, with info in legend.
_grid_it_up (_grid_it_up())
Maps the x,y and z data to a numpy.meshgrid using scipy interpolation at a user defined resolution.
pyretis.pyvisa.plotting._add_colorbar(fig, mappable, ax, cbar_ax=None)[source]

Add a colorbar with Matplotlib’s current explicit axes API.

pyretis.pyvisa.plotting._grid_it_up(xyz, res_x=200, res_y=200, fill='max')[source]

Map x, y and z data values to a numpy meshgrid by interpolation.

Parameters:
  • xyz (list of list) – Lists of data values.
  • res_x, res_y (integer, optional) – Resolution (number of points in a axis range).
  • fill (string, optional) – Criteria to color the un-explored regions.
Returns:

g_x, g_y, g_z (list) – Numpy.arrays of mapped data.

pyretis.pyvisa.plotting.gen_surface(x, y, z, fig, ax, cbar_ax=None, dim=3, method='contour', res_x=400, res_y=400, colormap='viridis')[source]

Generate the chosen surface/contour/scatter plot.

Parameters:
  • x, y, z (list) – Coordinates of data points. (x,y) the chosen orderP pairs, and z is the chosen energy value of the two combinations.
  • fig (Matplotlib object) – main canvas.
  • ax (Matplotlib object) – axes of the plot.
  • cbar_ax (Matplotlib object, optional) – plot color-bar.
  • dim (int) – dimension of the plot surface.
  • method (string, optional) – Method used for plotting data, default is contour lines.
  • res_x, res_y (integer, optional) – Resolution of plot, either as N*N bins in 2D histogram (Density plot) or as grid-points for interpolation of data (Surface and contour plots).
  • colormap (string, optional) – Name of the colormap/color scheme to use when plotting.
Returns:

  • surf (Matplotlib object) – The chosen surface/contour/plot object.
  • cbar (Matplotlib object) – The chosen color-bar.

pyretis.pyvisa.plotting.plot_int_plane(ax, pos, yminmax, zminmax, visible=False)[source]

Generate the interface planes for 3D visualization.

Parameters:
  • ax (The matplotlib.axes object where the planes will be plotted.)
  • pos (float) – The x-axis position of the interface plane.
  • yminmax, zminmax (list of float) – The limits of the plane in the 3D canvas.
  • visible (boolean, optional) – If True, shows interface planes.
Returns:

plane (A 3D surface at x=pos, perpendicular to the x-axis.)

pyretis.pyvisa.plotting.plot_regline(ax, x, y)[source]

Plot a regression line calculated from input data in the input subplot.

Parameters:
  • ax (Matplotlib subplot, where reg.line is to be plotted.)
  • x, y (list) – Floats, coordinates of data regression lines are calculated from.
  • Updates
  • ——-
  • Regression line with values.

pyretis.pyvisa.resources_rc module

Fix string for pydocstyle.

pyretis.pyvisa.resources_rc.qCleanupResources()

Fix pydoc-error.

pyretis.pyvisa.resources_rc.qInitResources()

Fix pydoc-error.

pyretis.pyvisa.visualize module

GUI application for visualizing simulation data.

This is a PyQt5 file, using a custom made ui layout, with a window which displays different plots created by the path density tool. Window can either display data of a pre-compiled compressed file generated with the orderparam_density.py module, or compile on in/out files by importing orderparam_density and executing before displaying the results.

Important methods defined here

visualize_main (:py:func: .visualize_main)
Method to load the GUI.

Important classes defined here

VisualApp (VisualApp)
The PyQt5 GUI class that handles all the functionalities.
CustomFigCanvas (VisualApp)
Class to handle the MatPlotLiv canvas.
DataSlave (VisualApp)
The class to handle the data for the plots.
VisualObject (VisualApp)
The class that handles the load from files.
DataObject (VisualApp)
The class that loads the PyRETIS files.
class pyretis.pyvisa.visualize.CustomFigCanvas

Bases: FigureCanvasQTAgg

Class definition of the custom figure canvas used in VisualApp.

surf
Type:Placeholder for object shown in main subplot of figure.
ax
Type:Main subplot (Axes object) of CustomFigCanvas.
cbar_ax
Type:Subplot (Axes object) of colorbar in CustomFigCanvas.
intf
Type:Placeholder for a list of interface lines/planes in the figure.
regl
Type:Placeholder for 2D regression line in figure.
legend
Type:Placeholder for legend in figure.
title
Type:Placeholder for the figure title.
{x/y/z} axis
Type:Placeholder for the x/y/z-axis labels.
__init__()

Initialize the FigureCanvas class.

set_up(dim=2, cbar=True)

Define subplot projection (2D/3D).

Function that defines the main subplot’s projection (2D/3D) depending on chosen method from VisualApp GUI.

Parameters:
  • dim (integer, optional) – Dimension/projection of main subplot.
  • cbar (boolean, optional) – If True, the space for the colorbar is considered in the setting.
class pyretis.pyvisa.visualize.DataObject(iofile=None)

Bases: DataSlave, PathDensity

DataSlave class used by VisualApp to load data from PyRETIS input.

__init__(iofile=None)

Initialize the class and classes inherited.

Parameters:iofile (string, optional) – The input file name.
cycle_printed

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.

Type:pyqtSignal(*types, name
Type:str = …, revision
walk()

Signal emission to begin ‘walk’ in the simulation directory.

class pyretis.pyvisa.visualize.DataSlave(iofile=None)

Bases: QObject, PathVisualize

QObject class definition that holds the PathDensity data.

By pyqtSignals this object can be called upon to either do a directory “walk” to collect data, or get specific data into lists by specific settings.

Contains the same attributes as the PathDensity() class of
orderparam_density.py in source.
Functions
---------
load_all

Load x,y and z data from all trajectories selected by the settings of PyVisA. Also stored the coordinates, ensemble name and cycle of each point for use in interactivity in the plot.

Type:function
find_cycle_ensemble

Accept a MouseClick event on the plot and return the x, y coordinate, cycle and ensemble name of the closest point to wherever the user clicks on the plot.

Type:function
load_to_df

Loads trajectory data into a pandas dataframe for analysis.

Type:function
Signals
-------
cycle_printed

Send a list of min and max cycle number to the VisualApp to update the dropwidget with correct values.

Type:PyQt Signal
returns_coords

Send three lists of coords (or empty) to the VisualApp to update the figure.

Type:PyQt Signal
Slots
-----
walk

When activated with a string, initializes the walk_Dirs() function of DataObject/PathDensity class. At end of function, emits list of cycles to signal cycle_printed.

Type:PyQt Slot connected to VisualApp
get

When activated with a dictionary with relevant plotting settings, preforms a data fetch of either get_Edata or get_Odata on DataObject/PathDensity class. At end of function, emits lists of coords to signal return_coords.

Type:PyQt Slot connected to VisualApp
__init__(iofile=None)

Initialize the QObject class and classes inherited.

Parameters:iofile (string, optional) – The input file name.
find_cycle_ensemble(event)

Return x, y, cycle and ensemble name at the closest point.

Parameters:event (Matplotlib mouse event) – The users mouse click on the plot.
Returns:
  • closest (list) – List of the x and y coordinate of the closest point to the users click on the plot.
  • cycle (int) – Corresponding cycle of the closest point.
  • ensemble_name (string) – Corresponding ensemble name of the closest point.
get_xyz_data(new_settings)

Signal emission to get xyz data from settings in VisualApp.

Parameters:new_settings (dict) – The settings provided by an user to select the data to extract.
load_all()

Load chosen data from all trajectories.

Function that uses the load_traj function from orderparam_density() to load all the x, y, and z data corresponding to the chosen settings for plotting. The criteria for plotting is collected from the settings and sent to load_traj. It also stores the coordinates, and data_origin of each points which is used for the interactivity in other functions like on_pick.

Returns:
  • x (list) – List of data from chosen parameter.
  • y (list) – List of data from chosen parameter.
  • z (list) – List of data from chosen parameter.
load_reactive_unreactive(sim_settings)

Assign a boolean for reactive (True) and unreactive (False) path.

Parameters:sim_settings (dict) – Dict containing settings from GUI.
Returns:reactive_data (Pandas Dataframe) – Dataframe containing True/False for each frame in the simulation. True if the frame is reactive, False if unreactive.
load_to_df(sim_settings)

Create a pandas dataframe for analysis.

Parameters:sim_settings (dict) – Dict containing settings from GUI.
Returns:df (Pandas Dataframe) – Dataframe containing all OP, CV and energy data from selected ensembled.
remove_values(sim_settings, min_op, max_op)

Remove values below and above chosen values in a dataframe.

Parameters:
  • sim_settings (dict) – Dict containing the simulation settings.
  • min_op (float) – Lowest chosen value of the order parameter.
  • max_op (float) – highest chosen value of the order parameter.
Returns:

  • sim_reduced (Dataframe) – Dataframe containing data from the simulation with removed frames where the op is above or below a predetermined value.
  • reactive_reduced (Dataframe) – Dataframe containing the reactive/unreactive flag for each frame in the simulation with removed frames where the op is above or below a predetermined value.

return_coords

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.

Type:pyqtSignal(*types, name
Type:str = …, revision
class pyretis.pyvisa.visualize.VisualApp(folder, iofile, sub_files)

Bases: QMainWindow, Ui_MainWindow

Class definition of the path visualization window GUI for PyRETIS.

Application opens a QMainWindow object with a QFrame for inserting a matplotlib figure canvas into, and a QDropWidget with the relevant settings for plotting.

mainworker

data back-end, initialized by the VisualApp window. When called will update the data lists and return to VisualApp for plotting.

Type:A QThread object that stores (and executes) the path density
Functions
---------
close_event, action_reload, center_on_screen, toggle_buttons

Functions that relate to closing of window, reloading data, centering the window on screen and disable key buttons while pdating data/figure.

_update_canvas_{title/text}

Functions that update the title and label text of plot settings and in the figure.

_get_settings
Type:Gets plot settings from VisualApp dropwidget.
_get_savename
Type:Generate generic savename based on current settings.
save_png

window as a .png image, with name generated from data settings.

Type:Function that store the current figure shown in VisualApp
save_hdf5

window a hdf5 save, with name generated from data settings.

Type:Function that store the current figure shown in VisualApp
save_json

window a json save, with name generated from data settings.

Type:Function that store the current figure shown in VisualApp
save_script

plot from the compressed file.

Type:Function that generates a script to reconstruct the current
_load_file
Type:Opens QFileDialog for choosing file to load in VisualApp.
_load_data
Type:Loads data from hdf5 save.
_load_data_output

displaying results.

Type:Executes a PathDensity on input/output file before
_reload
Type:Clears old data and initializes loading new data from file.
_change_{cmap/zoom}

Updates figure with different colormap, and with xlims+ylims

toggle_{intf/regl/cbar/titles}

Functions that shows/hides interfaces, regression line, colorbar, and titles/labes, respectively.

emit_settings

‘Update’ after choosing desired settings for plot. Sends settings to mainworker, which updates the data of x, y (and z) lists before sending back to VisualApp for plotting.

Type:Function that is called when pressing a QPushButton labeled
on_pick

Writes the x, y coordinate, cycle, ensemble name, status and mc move of the closest corresponding point to wherever the user clicks on the plot and fills in the slots in the Analysis tab in PyVisA and plots the closest point.

Type:Function that is called when clicking on the plot.
draw_trajectory

When pressing the button labeled “show trj” in the “Analysis” tab in PyVisA. The function plots all points in the trajectory corresponding to the closest point defined by the users pick on the plot.

Type:Function that is called when pressing a QPushButton.
play_cycle

Pressing the QPushButton labeled “play” button in the “Analysis” tab in PyVisA causes the function to check if the corresponding trajectory files exists, and reverses them through rev_trj if necessary before merging them to a pdb file, and loading them to PyMOL. NB: Requires the user to have PyMOL installed in order to work.

Type:Function that is called when pressing a QPushButton.
create_full_traj
Type:Function that creates a pdb-file for a trajectory.
display_message_box

Function displays a message box in use for error handling and messaging the user about operations and choices that are not availeable.

Type:Function that displays a QMessageBox.
toggle_only_stored_trjs

Function that loops over all trajectories in the chosen ensembles and cycles and only plots those trajectories which have existing trajectory files.

Type:Only plot data with trajectory files.
recalculate

Function activating from the QAction labeled “Recalculate data” in the file menu of PyVisA. Uses the tools available in the recalculate_order.py file to load the trajectory files of the simulation, and calculate new collective variables which need to be declared in the input files “retis.rst” and “orderp.py”. The new data will be stored in the full order.txt in the ensemble folders, and also the order.txt in the cycle folders of each ensemble enabling PyVisA to load and visualize the new descriptors. The previous data files are renamed as order_old.

Type:Recalculate OP and CV’s in new order.txt files.
statistic_analysis

A function that is connected to the statistical function in the statistical_methods file, and that takes the users choice of analysis and run the said choice.

Type:Perform statistical analysis on plotted data.
show_correlation

Shows the Pearson correlation in a matrix form for all the variables from the simulation.

Type:Show the correlation between simulation variables.
refresh_data

Performs a new walk of the data, to use during a running simulation to visualise its development.

Type:Signal a walk of the data.
Signals
-------
start_cmd

It tells worker to start using string, cmd.

Type:PyQt Signal
send_settings

It sends settings for data_get to worker thread.

Type:PyQt Signal
Slots
-----
update_cycle

thread. Signal sets upper and lower bounds for max/min cycles used in plotting.

Type:function bound to a pyqtSignal sent by the mainworker
update_fig

Pyqt slot, worker thread calls function by sending 3 lists of floats for plotting in this function.

Type:PyQt Slot
__init__(folder, iofile, sub_files)

Initialize the VisualApp QMainWindow.

Sets up ui from file, centers on screen and sets up mainworker QThread for data loading.

Parameters:
  • folder (string) – The path of the target folder.
  • iofile (string) – The name of the main input file.
  • sub_files (dict) – Contains the name of multiple input files.
_change_cmap()

Set colormap of surface.

Function that tries to set the colormap of object myfig.surf (plot) Bound to detection of returnPress in colormap combo box.

_change_zoom()

Set the zoom/x-&y-limits of the plot.

_get_limits()

Update x/y/z limits from GUI.

Function that updates the min/max limits of data for plotting in the GUI. If invalid inputs, will return default values.

_get_op_range()

Display the range of the order parameter to the GUI.

_get_savename()

Generate generic save-name.

Function that generates a generic save-name for the current figure displayed in VisualApp based on settings.

_get_settings()

Update self.settings{} with the current option from the GUI.

Function that updates the settings of dictionary self.settings{} with current options from GUI window.

_get_titles()

Generate tiles and labels and update QLineEdits of VisualApp.

Function that generates generic titles and labels for the figure axes, colorbar, etc. and updates QLineEdits of VisualApp with those titles/labels.

static _iffloat(value, default_v)

Check if value is a float, and returns it.

_init_widget()

Initialize QDropWidget.

Function initializing the settings of the QDropWidget of VisualApp window. Adds correct items to the ComboBoxes of op1,op2 and E, and add the CustomFigCanvas object to the QFrame. If no folder or file is given when initializing VisualApp, a QFileDialog is opened to get file/folder.

_load_data(pfile)

Load saved data.

Function that loads simulation data from a pre-compiled file and initializes the VisualApp window for plotting said data.

_load_data_output()

Load simulation data.

Function that loads simulation data using in/out file of simulation and initializes PathDensity on the directory, before showing the results in the VisualApp window.

_load_file()

Load data file.

Function that sets up QObject, moves to QThread, and begins the data extract. Or, loads pre-processed data from file and moves to a QThread.

_reload()

Reload the data of VisualApp.

Function that clears the old data of VisualApp and initializes the load of new.

_save_sim_data_hdf5()

Save the data to hdf5 file.

_save_sim_data_hdf5_z()

Save the data to hdf5 zipped file.

_set_cur_limits()

Update x/y/z limits in GUI with current values.

_set_def_limits(x, y, z)

Update x/y/z limits in GUI with default values.

Parameters:x, y, z (list) – Floats, the coordinates used in plotting.
_update_canvas_font()

Change the fontsize of title/labels of figure.

Bound to event only.

_update_canvas_text()

Create the titles and labels of figure.

This is in VisualApp from QLineEdits current text. Called by update_fig() and bound to event.

action_reload()

Display a QMessagebox to confirm reload action.

Function that displays a QMessagebox for user, double confirming the reload data action.

center_on_screen()

Centers widget/window on screen.

closeEvent(event)

Event function, activated when attempting to close VisualApp.

Will create a QMessage prompt asking for confirmation of exit by user. If confirmed, will stop Qthread of DataObject and attempt to clear dataobject from memory.

Parameters:event (QtWidget event) – It activates the closing of the VisualApp.
close_event()

Event function interpreter to make the event to a boolean.

create_full_traj(cycle=None, ensemble_name=None, rst_file=None)

Create trajectory file.

Parameters:
  • cycle (string, optional) – Cycle number of trajectory.
  • ensemble_name (string, optional) – Ensemble name of trajectory.
  • rst_file (string, optional) – Path to the input/output file of the simulation.
decision_tree()

Create a decision tree from simulation results.

disable_reglinecheck()

Disabling regression line checkbox if 3D method.

disable_zcombox()

Disabling combobox with z-values if plotting density.

display_message_box(line1, line2)

Display a message box with chosen text.

Parameters:
  • line1 (string) – Title of message box.
  • line2 (string) – Main message for the box.
draw_trajectory()

Draw chosen trajectory on plot.

Show a full chosen trajectory on the plot in a selected color with choices of marker size and line thickness.

emit_settings()

Update settings before sending to the data object.

Function calls for an update of data/plot settings before sending dictionary to data object in main worker to update the data lists x, y, (z).

initiate_pca()

Perform PCA.

on_pick(event)

Write all information about the closest point to slots in PyVisA.

Parameters:event (Matplotlib mouse event) – It activates the interactive function on the plot.
play_cycle()

Collect traj-files in order to animate the trajectory.

random_forest()

Create a random forest from simulation results.

recalculate()

Recalculate OP and new CV’s.

Using the functions from recalculate_order.py this function will calculate new collective variables to the simulation while keeping the original OP in order to explore new descriptors of the system. The new files will replace the order files so PyVisA can load and visualize the new descriptors. The old files will be renamed as order_old.

refresh_data()

Signal a walk of the data.

static rev_trj(frames)

Reverse a list of trajectory frames, excluding the first.

Parameters:frames (list of numpy.ndarray) – Ordered list of coordinate frames.
Returns:list of numpy.ndarray – Frames in reverse order, with the original first frame dropped.
save_hdf5()

Save in hdf5 format the current figure.

Function that saves the current pyplot.figure object of VisualApp and CustomFigCanvas to a .hdf5 file. Function creates title and name for file by the current settings for the plot.

save_json()

Save in json format the current figure.

Function that saves the current pyplot.figure object of VisualApp and CustomFigCanvas to a .json file. Function creates title and name for file by the current settings for the plot.

save_png()

Save current figure as png.

Function that saves the current plotted figure of VisualApp and CustomFigCanvas as a .png file. Function creates title and name for file by the current settings for the plot.

save_script()

Make makefigure.py script.

Function that generate and store the current plot from the GUI to a separate script file, that can re-generate a fairly similar figure to the GUI using stored settings.

save_textdata()

Save x, y, z data to file.

Function that saves the current x, y, z data of the visualizer to a text file for use in other operations, plotting, etc.

send_settings

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.

Type:pyqtSignal(*types, name
Type:str = …, revision
show_correlation()

Show the correlation between simulation data.

Function which plots a correlation matrix from the simulation data.

start_cmd

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.

Type:pyqtSignal(*types, name
Type:str = …, revision
statistic_analysis()

Perform statistical analysis on plotted data.

Function which performs a range of different clustering techniques like K-mean, Hierarchical, Gaussian Mixture, Spectral and PCA by choice of the user. The user specifies the type of analysis as well as the amount of cluster/components.

toggle_buttons(onoff)

Toggles enable-state of key buttons of VisualApp.

It avoids user-created conflicts while busy updating data and drawing figure.

Parameters:onoff (boolean) – Determines the status of the button.
toggle_cbar()

Toggle colorbar visibility.

toggle_intf()

Toggle interface visibility.

toggle_only_stored_trjs()

Toggle to show only data with trajectory files.

toggle_regl()

Toggle regression line and legend visibility.

toggle_titles()

Toggle labels and titles visibility.

update_cycle(cycles)

Set upper and lower bound of cycles for data loading.

Function bound to pyqtSignal from DataObject in QThread, sets upper and lower bound of cycles for data loading, and enables ‘Update’ QPushButton when finished.

Parameters:cycles (list) – Integers defining the initial en final cycle number to plot.
update_fig(x, y, z)

Update figure by pyqtSignal.

Function that updates figure canvas of CustomFigCanvas and the colorbar. Initiated by pyqtSignal from running QThread. Function checks method chosen in GUI and calls on built-in functions of orderparam_density module to generate a surface/contour/scatter/etc. If checked, function also plots interfaces and regression line.

Parameters:
  • x, y, z (list) – Floats, the coordinates used in plotting.
  • Updates/Draws
  • ————-
  • myfig.fig (Re-draws canvas with method, data, and possible) – interfaces, reg.line and legend.
  • myfig.ax (As above. (Axes containing plot, legend, lines, etc))
  • myfig.cbar_ax (Axes with colorbar of plot.)
update_preview()

Update the visual of the plot.

Button function, updates visual of plot based on all settings of ‘Plot’-tab in VisualApp.

class pyretis.pyvisa.visualize.VisualObject(pfile=None, trajfile=None)

Bases: DataSlave

DataSlave class used by VisualApp to load data from compressed file.

__init__(pfile=None, trajfile=None)

Initialize the class and classes inherited.

Parameters:
  • pfile (string, optional) – The input file name.
  • trajfile (string, optional) – The input trajectory file name.
cycle_printed

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.

Type:pyqtSignal(*types, name
Type:str = …, revision
get_data(pfile)

Signal emission for loading data from file.

Parameters:pfile (string) – The input file name.
load_data_from_single(iofile)

Load a single trajectory file.

Parameters:iofile (string) – The input file name.
pyretis.pyvisa.visualize._redraw_colorbar(colorbar)

Refresh a Matplotlib colorbar across Matplotlib versions.

pyretis.pyvisa.visualize._remove_last_line(ax)

Remove the latest line from an axes across Matplotlib versions.

pyretis.pyvisa.visualize._set_tick_fontsize(axis, fontsize)

Set major tick label font sizes across Matplotlib versions.

pyretis.pyvisa.visualize._write_pdb(filename, frames, topology)

Write trajectory frames to a PDB file.

Parameters:
  • filename (str) – Output PDB path.
  • frames (list of numpy.ndarray, shape (N, 3)) – Positions in nm for each frame.
  • topology (dict) – Snapshot dict from read_gromacs_gro_file() supplying atom/residue names and numbers.
pyretis.pyvisa.visualize.visualize_main(basepath, infile=None, rst_file=None, trajfile=None)

Run the VisualApp application.

Parameters:
  • basepath (string) – The execution folder where the input files are.
  • infile (string, optional) – Path to the data that PyVisA is initialized with. Can be a PathDensity object, or a hdf5 file.
  • rst_file (string, optional) – Path to the rst file if PyVisA has been loaded through the input/output rst files of the simulation.
  • trajfile (string, optional) – Path to the trajectory file is PyVisA has been loaded with the -data command.

pyretis.pyvisa.statistical_methods module

Collection of statistical methods for PyVisA.

Important methods defined here

correlation_matrix (correlation_matrix())
Method for displaying the correlations from the simulation variables.
gaussian_mixture (gaussian_mixture())
Generic method for performing gaussian mixture clustering on simulation data.
hierarchical (hierarchical())
Generic method for performing hierarchical clustering on simulation data.
k_means (k_means())
Generic method for performing K-means clustering on simulation data.
pyvis_pca (pyvisa_pca())
Generic method for performing pca on simulation data.
spectral (spectral())
Generic method for performing spectral clustering on simulation data.
pyretis.pyvisa.statistical_methods._plot_pca_results(n_pca, principal_df, loadings, pca_info, cmap)

Plot the results of a PCA analysis.

Parameters:
  • n_pca (integer) – Number of principal components.
  • principal_df (object like pandas.DataFrame) – Principal components data.
  • loadings (object like pandas.DataFrame) – PCA loadings.
  • pca_info (dict) – Dict with keys ‘model’ (fitted PCA), ‘cols’ (column labels), ‘features’ (feature labels).
  • cmap (string) – Matplotlib colormap.
pyretis.pyvisa.statistical_methods.correlation_matrix(dataframe)

Show correlation matrix of simulation variables.

Function which computes the Pearson correlations between parameters and shows it in a correlation plot.

Parameters:dataframe (object like pandas.DataFrame) – Dataframe containing simulation data.
pyretis.pyvisa.statistical_methods.decision_tree(xdata, ydata, depth)

Create a decision tree.

Parameters:
  • xdata (object like pandas.DataFrame) – Pandas dataframe containing the op and cv data from selected frames i the simulation.
  • ydata (object like pandas.DataFrame) – Pandas dataframe containing True/False for each frame in the selected ensembles. True if the frame is reactive, else False.
  • depth (integer) – Depth of the decision tree.
pyretis.pyvisa.statistical_methods.gaussian_mixture(n_clusters, data, settings, cmap)

Perform gaussian mixture clustering.

This function performs gaussian mixture clustering on simulation data with a chosen amount of clusters, and plots the results.

Parameters:
  • n_clusters (integer) – Number of clusters.
  • data (object like numpy.ndarray) – Simulation data from chosen ensembles.
  • settings (dict) – Settings from GUI.
  • cmap (string) – Matplotlib colormap.
pyretis.pyvisa.statistical_methods.hierarchical(n_clusters, data, settings, cmap)

Perform hierarchical clustering.

This function performs hierarchical clustering on simulation data with a chosen amount of clusters, and plots the results.

Parameters:
  • n_clusters (integer) – Number of clusters.
  • data (object like numpy.ndarray) – Simulation data from chosen ensembles.
  • settings (dict) – Settings from GUI.
  • cmap (string) – Matplotlib colormap.
pyretis.pyvisa.statistical_methods.k_means(n_clusters, data, settings, cmap)

Perform K-means clustering.

This function performs K-means clustering on simulation data with a chosen amount of clusters, and plots the results.

Parameters:
  • n_clusters (integer) – Number of clusters.
  • data (object like numpy.ndarray) – Simulation data from chosen ensembles.
  • settings (dict) – Settings from GUI.
  • cmap (string) – Matplotlib colormap.
pyretis.pyvisa.statistical_methods.pyvisa_pca(n_pca, settings, data, cmap)

Perform PCA on ensemble data.

This function performs PCA on data from the selected ensembles and stores the data to a hdf-file for further analysis, plots the first two principal components against each other, the cumulative explained variance and the loadings. The hdf5 file contains the keywords:

  • sim_data: pandas Dataframe containing the simulation data.
  • PC: Dataframe containing the data from the principal components.
  • loadings: pandas Dataframe containing the loadings.
  • explained: pandas Series containing the simulation data.
  • correlation_matrix: Dataframe containing the correlation matrix.
Parameters:
  • n_pca (integer) – Number of clusters.
  • settings (dict) – Settings from GUI.
  • data (object like pandas.DataFrame) – Simulation data from chosen ensembles.
  • cmap (string) – Matplotlib colormap.
pyretis.pyvisa.statistical_methods.random_forest(xdata, ydata, depth)

Create random forest classification.

Parameters:
  • xdata (object like pandas.DataFrame) – Pandas dataframe containing the op and cv data from selected frames in the simulation.
  • ydata (object like pandas.DataFrame) – Pandas dataframe containing True/False for each frame in the selected ensembles. True if the frame is reactive, else False.
  • depth (integer) – Depth of random forest model.
pyretis.pyvisa.statistical_methods.spectral(n_clusters, data, settings, cmap)

Perform spectral clustering.

This function performs spectral clustering on simulation data with a chosen amount of clusters, and plots the results.

Parameters:
  • n_clusters (integer) – Number of clusters.
  • data (object like numpy.ndarray) – Simulation data from chosen ensembles.
  • settings (dict) – Settings from GUI.
  • cmap (string) – Matplotlib colormap.