pyretis.visualization 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 (pickle), 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

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



Important classes defined in this package

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

Important methods defined in this package

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

pyretis.visualization.common module

This file contains common functions for the path density.

It contains some functions that is used to compare and process data, like matching similar lists or attempt periodic shifts of values.

Important methods defined here

hello_pathdensity_world (:py:func: .hello_pathdensity_world)
Prints an ASCII message/image to screen.
diff_matching (:py:func: .diff_matching)
Takes in two lists and their lengths, returns two lists with the indeces of the respective lists that differ from eachother.
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.
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.
pyretis.visualization.common.diff_matching(l1, l2, lenp)[source]

Check two lists for differences, returns lists of indices for each list.

  • l1, l2 (Lists)
  • lenp (List with lengths of l1 and l2)

d1, d2 (Lists) – Indeces of lists l1 and l2, respectively, to be deleted

pyretis.visualization.common.get_min_max(mydata, min_max, mini, maxi, acc)[source]

Find minimum and maximum indeces.

  • mydata (list) – List of cycle numbers to be checked for index of given min/max
  • min_max (list) – List of min/max values to search for
  • mini (dict) – Dictionary of found min cycle number of lists acc/rej
  • maxi (dict) – Dictionary of found max cycle number of lists acc/rej
  • acc (string) – ‘a’ or ‘r’ for acc/rej lists, respectively
  • Returns/updates
  • —————
  • mini, maxi (dict) – Stores values for min/max in acc and rej lists to the correct dicts.
pyretis.visualization.common.get_startat(myfile, noprint=False)[source]

Find last occurence of a ‘Cycle: 0’ in a file, and returns that line.

Parameters:myfile (string) – Filename of file that is checked for restart line
Returns:startat (integer) – Index of file (line) with last restart line

Print the word art.


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.visualization.common.try_data_shift(x, y, op1)[source]

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 precoursion, no shift is performed on x values if they are of the first order parameter ‘op1’

  • x, y (list) – Floats, data values
  • op1 (string) – Label of x values in PathDensity dictionary

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

pyretis.visualization.orderparam_density module

orderparam_density - An application for compiling PyRETIS simulation data.

This module is part of the PyRETIS library and can be used both for compiling the simulation data into a *.pickle dump, and load the data for later visualization.

usage : [-h] -i INPUT [-s]


optional arguments:
-h, --help show this help message and exit.
-i INPUT, --input INPUT
 Location of PyRETIS input/output file and simulation directory with subfolders (ensembles).
class pyretis.visualization.orderparam_density.PathDensity(iofile=None)[source]

Bases: object

Perfrom the path density analysis.

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


and order.txt files and appends the values to dictionaries. Function is currently called by default during initialization of PathDensityVisual class.

Type:Function which searches through subfolders 00* for energy.txt

(ops, eops,infos) to a *.pickle file for later visualization.

Type:Function which dumps data of all three dictionaries

file (order.txt or energy.txt).

Type:Function that return the latest restart point of a ensemble
get_OP, get_EOP

respectively, within a given folder. Used by function walk_Dirs.

Type:Functions which scan order.txt and energy.txt,
Type:Function checking the lengths of all lists in dictionaries

cycle number and time step values does not match.

Type:Function that finds indeces of lists to delete when

Initialize the class.


Loop over dicts, check lengths and print energy/order lists.

Function that loops over dictionaries, checking the length of lists respective to the folders they were read from. Prints length of energy lists, shortened order parameter lists, and full length order parameter lists.

  • fol (string) – Name of folder currently reading files from.
  • Returns/Updates
  • —————
  • No returns. Checks and updates the content of orderP and energy,
  • timestep and cycle, in the dictionary self.eops[]. If any differences
  • are found, another function is called on all lists of that particular
  • folder and acc/rej flags, which cuts the unmatched lines.
compare_and_cut(fol, acc, lenp, target='cycle')[source]

Compare an cut unmatched lines from dict lists.

Function that compares step number of energy and order dictionaries, and deletes unmatched lines from either dictionary’s lists

  • fol (string) – Name of folder where difference occured.
  • acc (string) – ‘r’/’a’ for accepted/rejected paths.
  • lenp (list) – Length of energy time-step list in eops dictionary. [0] = length of E-list, [1] = length of OP-list.
  • target (string) – The target lists to compare for deletion of lines.

  • Updates/removes items from lists in EOP dict and returns the
  • equal length lists, with correctly matched values.

get_EOP(fol, files, file_starts)[source]

Funcion that reads two files, and saves frames only if in both.

  • fol (string) – Name of folder - e.g. “000”. Used in dictionaries for allocating values from read to correct list.
  • files (list of strings) – Name of files in subfolder path.
  • file_starts (list of integers) – Index of files with latest restart of simulation
  • Returns/Updates
  • —————
  • In
  • eops ([atime, rtime, apotE, rpotE,) – akinE, rkinE, atotE, rtotE] Lists of floats. Contains accepted/rejected steps and energy from files efile and ofile in folder fol.
  • eops ([atimo, rtimo, aop{x}, rop{x}] - x in range(0,#orderP)) – Lists of floats. Contains accepted/rejected steps and order param from file ofile in folder fol. aop{x}/rop{x} loops through the total number of order parameters found in the order param file.
get_OP(ofile, fol, ostart)[source]

Read order params from file and append to the lists in dict.

Function that reads order params from orderfile, and appends values to relevant lists in dictionary.

  • ofile (string) – Name of orderP file in subfolder path - e.g. “000/order.txt”.
  • fol (string) – Name of folder - e.g. “000”. Used in dictionaries for allocating values from read to correct list.
  • ostart (integer) – Index of ofile with latest restart of simulation
  • Returns/Updates
  • —————
  • In
  • ops (a/r[timo, aop{x}, cycl] - x in range(0,#orderP)) – Lists of floats. Contains accepted/rejected steps and order param from file ofile in folder fol. aop{x}/rop{x} loops through the total number of order parameters found in the order param file.

Pickles the data to a *.pickle file.


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

First generate list of folders/ensembles to iterate through. Then search for number of orderparameters(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.

  • only_ops (boolean, default=False) – If true, PathDensity will not collect data from energy files.
  • Returns/Updates
  • —————
  • ops (dict) – Values of order params in all ensembles.
  • eops (dict) – Values of order params and energies in all ensembles.

Write the lengths of the ops and eops dict to a txt file.

Function that writes lengths of some of the data lists in dictionaries ops and eops to a *.txt file.

Parameters:fast (Boolean, default=True) – Speed of data compile, if True is fast, else is slow.
class pyretis.visualization.orderparam_density.PathVisualize(pfile=None)[source]

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.


a *.pickle file.

Type:Function that loads pre-compiled simulation results from
Type:Plots the 1D and 2D density of order parameter combinations
Type:Load data (3) from eops dictionary using current settings.
Type:Load data (1) from eops dictonary using curent settings
Type:Load data (2) from ops dictionary using current settings.

(histogram) of just one order parameter.

Type:Function that generates plot of the distribution

order parameters.

Type:Function that generates plot of the density of two

of three order parameters/energies/other.

Type:Function that generates different plots for combinations

Initialize the PathVisualize class.

If an input file (*.pickle) is present, loads the pre-compiled data from it. Else, must use func load_pickle explicitly.

get_Edata(fol, XYZ, ACC, min_max=None)[source]

Load relevant data from the dictionaries.

Function that loads the relevant data from the dictionaries, depending on choice of order param and energy, whether paths acc/rej/both, and folder.

  • XYZ (list) – Names of order parameter and energy labels, for x/y/z-axis.
  • ACC (boolean OR string) – True/False for acc/rej paths, “BOTH” for both.
  • fol (string) – Name of folder, 000,001,etc.
  • min_max (list) – Minimum and maximum cycle of simulation data.

  • x (list) – Floats with values of op2, from dict eops[op2,fol].
  • y (list) – Floats with values of op1, from dict eops[op1,fol].
  • z (list) – Floats with values of E from eops[E,fol].

get_Odata(fol, XYACC, weight=True, min_max=(0, 0))[source]

Load relevant data from dictionaries.

Function that loads the relevant data from the dictionaries. (Depending on choice of order param, folder, and whether paths are acc/rej/both).

  • fol (string) – Name of folder, 000,001,etc.
  • XYACC (list) – [0:1] : strings, names of x/y order parameter. [2] : bool, True/False for acc/rej paths.
  • weight (boolean, default=True) – If True, trajectories are statistically weighted when read from dict.
  • min_max (list) – Minimum and maximum cycle number of simulation data.

  • x (list) – Floats with values of op2, from dict ops[op2,fol].
  • y (list) – Floats with values of op1, from dict ops[op1,fol].


Load pre-compiled data from *.pickle file.

Function that loads pre-compiled data from *.pickle file. Depending on file name, will define data as being created using fast or slow post-processing. Defaults to ‘fast’.


Run the Compressor application.

pyretis.visualization.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.
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.visualization.plotting._grid_it_up(x, y, z, resX=200, resY=200)[source]

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

  • x,y,z (list) – Lists of data values.
  • resX, resY (integer) – Resolution (number of points in a axis range).

X, Y, Z (list) – Numpy.arrays of mapped data.

pyretis.visualization.plotting.gen_surface(x, y, z, fig, ax, cbar_ax=None, dim=3, method='contour', resX=400, resY=400, scat_size=3, colormap='viridis')[source]

Generate the chosen surface/contour/scatter plot.

  • 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, ax, cbar_ax (Matplotlib objects; figure, main canvas axes and axes) – for plotting colorbar.
  • dim (interger, default=3) – Dimension of plot.
  • method (string, default=’contour’) – Method used for plotting data, default is contour lines.
  • resX, resY (integer, integer) – Resolution of plot, either as N*N bins in 2D histogram (Density plot) or as gridpoints for interpolation of data (Surface and contour plots).
  • scat_size (integer, default=3) – Size/diameter(?) of scatter points (in pixels).
  • colormap (string, default=’viridis’) – Name of the colormap/color scheme to use when plotting.

surf, cbar (The chosen surface/contour/plot object, and the colorbar.)

pyretis.visualization.plotting.plot_int_plane(ax, pos, ymin, ymax, zmin, zmax, visible=False)[source]

Generate the interface planes for 3D visualization.

  • ax (The matplotlib.axes object where the planes will be plotted.)
  • pos (float) – The x-axis position of the interface plane.
  • ymin, ymax, zmin, zmax (float) – The limits of the plane in the 3D canvas.
  • visible (boolean, default=False) – If True, shows interface planes.

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

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

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

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

pyretis.visualization.resources_rc module

pyretis.visualization.visualize module