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 an 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.
List of submodules¶
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¶
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¶
- 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 trj in respect to the 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 orderp parameter on.
-
pyretis.pyvisa.common.
_get_trjs
(runfolder='.')[source]¶ 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.
find_data
(runfolder, ensemble_names=None, data=None)[source]¶ 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)[source]¶ 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)[source]¶ Return names of op and cv’s.
Parameters: input_settings (dict) – Dictionary with the settings from the simulations. Returns: names = list – List of the names.
-
pyretis.pyvisa.common.
read_traj_txt_file
(path)[source]¶ 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)[source]¶ Recalculate order parameter and collective variables.
This function performs post-processing by analyzing trajectories of old simulations in order to extract data and 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)[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.pyvisa.common.
try_data_shift
(x, y, fixedx)[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 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)[source]¶ 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)[source]¶ 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)[source]¶ 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: int 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)[source]¶ 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)[source]¶ 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 (int) – Cycle number.
- Updates
- ——-
- traj_dict (Trajectory object) – Trajectory object with filled in OP-data.
-
get_traj_energy
(ensemble_name)[source]¶ 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)[source]¶ 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.
-
initialize_compressed
(input_file)[source]¶ Load PathDensity from a compressed file.
Parameters: input_file (string) – The input 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 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)[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__
(basepath='.', pfile=None)[source]¶ 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
()[source]¶ Load precompiled data from a hdf5 file.
Function that loads precompiled data from a .hdf5 file made using pandas.
-
load_traj
(criteria)[source]¶ 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.
-
-
class
pyretis.pyvisa.orderparam_density.
Trajectory
(frames, info)[source]¶ 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)[source]¶ 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: int Max value of OP.
- ordermin: int Min value of OP.
- stored: boolean True if the trajectory has existing trajectory files.
- frames (pandas Dataframe or dict) – Dataframe/dict containing order parameter and energy-data
for the trajectory. It contains:
-
-
pyretis.pyvisa.orderparam_density.
pyvisa_compress
(runpath, input_file, pyvisa_dict)[source]¶ 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)[source]¶ 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)[source]¶ Zip compress file of simulation data.
Parameters: input_file (string) – The file to compress.
-
pyretis.pyvisa.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 occurrence.
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.
_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, 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.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.