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

Modules

__init__.py
Imports from the other modules.
common.py (pyretis.visualization.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.visualization.orderparam_density)
A module that handles the compiling of data to a single file.
plotting.py (pyretis.visualization.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.visualization.resources_rc)
A module containing the resources, icons/logos for the PyRETIS GUI.
visualize.py (pyretis.visualization.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.visualization.visualize.CustomFigCanvas) A class for the custom figure shown in the VisualApp class PyQt5 applet.
DataObject
(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.
PathVisualize
(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.
VisualObject
(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.
diff_matching(pyretis.visualization.common.diff_matching())
A function to get the indeces where to similar lists differ.
gen_surface(pyretis.visualization.plotting.gen_surface())
A function that generates a user-defined surface plot (2D/3D).
_grid_it_up(pyretis.visualization.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.visualization.plotting.plot_int_plane())
A function that generates planes of the simulation interfaces for 3D plots.
plot_regline(pyretis.visualization.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.visualization.common.shift_data())
A function that shifts data values of a list by the median value.
try_data_shift(pyretis.visualization.common.try_data_shift())
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.

Parameters:
  • l1, l2 (Lists)
  • lenp (list) – lengths of l1 and l2
Returns:

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.

Parameters:
  • 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
pyretis.visualization.common.hello_pyvisa(noprint=False)[source]

Pyvisa logo printing to screen.

pyretis.visualization.common.shift_data(x)[source]

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’

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

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

pyretis.visualization.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.

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.

__init__(iofile=None)[source]

Initialize the class.

check_Steps(fol)[source]

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.

Parameters:
  • 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

Parameters:
  • 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.
Returns:

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

deepdish_data()[source]

Compresses the data to a .hdf5 file.

get_EOP(fol, files, file_starts)[source]

Read order and energy files, save frames only if present in both.

Parameters:
  • 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
  • —————
  • eops ([atime, rtime, apotE, rpotE, akinE, rkinE, atotE, rtotE,) – atimo, rtimo, aop{x}, rop{x}] for x in range(0, #orderP) Lists of floats, it contains accepted/rejected steps and energy from files efile and ofile in folder fol and the 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.

Parameters:
  • 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
  • —————
  • ops (a/r[timo, aop{x}, cycl] for 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.
pickle_data()[source]

Pickles the data to a .pickle file.

walk_dirs(only_ops=False)[source]

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 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.

Parameters:
  • only_ops (boolean, optional) – 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.
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.

__init__(pfile=None)[source]

Initialize the PathVisualize class.

If an input fil .pickle or .hdf5 is present, loads the pre-compiled data from it. Else, must use specific functions 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.

Parameters:
  • 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.
Returns:

  • 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).

Parameters:
  • 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, optional) – If True, trajectories are statistically weighted when read from dict.
  • min_max (list) – Minimum and maximum cycle number of simulation data.
Returns:

  • 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_dd()[source]

Load precompiled data from a hdf5 file.

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

load_pickle()[source]

Load precompiled data from pickle file.

Function that loads precompiled data from .pickle file. Depending on file name, will define data as being created using fast or slow post-processing.

pyretis.visualization.orderparam_density.remove_nan(data)[source]

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) – Input list. If nan are present, they are replaced by the following entry. The method accounts for multiple consecutive nan occourence.

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

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

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

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

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.

Parameters:
  • 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, optional) – If True, shows interface planes.
Returns:

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.

Parameters:
  • 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