pyretis.inout package¶
The sub-package handles input and output for PyRETIS.
This package is intended for creating various forms of output from the PyRETIS program. It includes writers for simple text-based output and plotters for creating figures. Figures and the text results can be combined into reports, which are handled by the report module.
Package structure¶
Modules¶
- __init__.py
- Imports from the other modules.
- checker.py (
pyretis.inout.checker) - Functions to check the compatibility and consistency of various input values.
- common.py (
pyretis.inout.common) - Common functions and variables for the input/output. These functions are mainly intended for internal use and are not imported here.
- fileio.py (
pyretis.inout.fileio) - A module which defines a generic file class for PyRETIS output files.
- settings.py (
pyretis.inout.settings) - A module which handles the reading/writing of settings.
- simulationio.py (
pyretis.inout.simulationio) - A module which handles th reading/writing of the main simulations.
- restart.py (
pyretis.inout.restart) - A module which handles restart reading/writing.
Sub-packages¶
- analysisio (
pyretis.inout.analysisio) - Handles the input and output needed for analysis.
- formats (
pyretis.inout.formats) - Handles the input and output of different data formats. This includes the configurations and the internal data formats.
- plotting (
pyretis.inout.plotting) - Handles the plotting needed by the analysis by defining plotting tools, methods and styles.
- report (
pyretis.inout.report) - Generate reports with results from simulations.
Important classes defined in this package¶
Important methods defined in this package¶
- generate_report (
generate_report()) - A function to generate reports from analysis output(s).
- parse_settings_file (
parse_settings_file()) - Method for parsing settings from a given input file.
- write_settings_file (
write_settings_file()) - Method for writing settings from a simulation to a given file.
- write_restart_file (
write_restart_file()) - Method for writing restart information.
Subpackages¶
- pyretis.inout.analysisio package
- pyretis.inout.formats package
- Package structure
- List of submodules
- pyretis.inout.formats.formatter module
- pyretis.inout.formats.cp2k module
- pyretis.inout.formats.cross module
- pyretis.inout.formats.energy module
- pyretis.inout.formats.gromacs module
- Important methods defined here
_add_matrices_to_snapshot()_get_chunks()read_gromacs_file()read_gromacs_generic()read_gromacs_gro_file()read_gromos96_file()read_trr_data()read_trr_file()read_trr_header()read_xvg_file()skip_trr_data()trr_frame_to_g96()write_gromacs_gro_file()write_gromos96_file()write_trr_frame()
- pyretis.inout.formats.order module
- pyretis.inout.formats.pathensemble module
- pyretis.inout.formats.path module
- pyretis.inout.formats.snapshot module
- pyretis.inout.formats.txt_table module
- pyretis.inout.formats.xyz module
- pyretis.inout.plotting package
- Package structure
create_plotter()- List of submodules
- pyretis.inout.plotting.mpl_plotting module
- Important classes defined here
- Important methods defined here
MplPlotterMplPlotter.__init__()MplPlotter._print_figures_to_file()MplPlotter.output_energy()MplPlotter.output_flux()MplPlotter.output_matched_probability()MplPlotter.output_orderp()MplPlotter.output_path()MplPlotter.output_pp_global_cross()MplPlotter.output_pppath()MplPlotter.output_tau()MplPlotter.output_xi()
_mpl_plot_xy_chunk()_mpl_read_style_file()_mpl_shoots_histogram()
- pyretis.inout.plotting.plotting module
- pyretis.inout.plotting.txt_plotting module
- pyretis.inout.report package
List of submodules¶
pyretis.inout.archive module¶
Module defining the base classes for the PyRETIS output.
Important classes defined here¶
- PathStorage (
PathStorage) - A class for handling storage of external trajectories to an archive. In this case, it is simply a folder based structure.
- PathStorageTar (
PathStorageTar) - A class for handling storage of external trajectories to an archive format (tar in this case).
-
class
pyretis.inout.archive.PathStorage(link_cycle_zero=False, load_folder=None)[source]¶ Bases:
OutputBaseA class for handling storage of external trajectories.
Variables: - target (string) – Determines the target for this output class. Here it will be a file archive (i.e. a directory based collection of files).
- archive_acc (string) – Basename for the archive with accepted trajectories.
- archive_rej (string) – Basename for the archive with rejected trajectories.
- archive_traj (string) – Basename for a sub-folder containing the actual files for a trajectory.
- formatters (dict) – This dict contains the formatters for writing path data, with default filenames used for them.
- out_dir_fmt (string) – A format to use for creating directories within the archive. This one is applied to the step number for the output.
-
__init__(link_cycle_zero=False, load_folder=None)[source]¶ Set up the storage.
Note that we here do not pass any formatters to the parent class. This is because this class is less flexible and only intended to do one thing - write path data for external trajectories.
-
static
_place_file(file_src, target, symlink=False)[source]¶ Copy a file or, when
symlinkis true, create a relative symlink.Used to reference cycle-0 trajectory frames back to the original load folder without duplicating bytes on disk. The symlink target is resolved relative to the symlink’s own directory so that copying or moving the whole simulation tree preserves the link.
-
_resolve_load_source(file_src, ensemble_name)[source]¶ Find the original cycle-0 source under
load_folder.At cycle 0 the file referenced by
file_srclives in the ensemble’saccepted/directory, which will be overwritten on the first accepted move. The user’s load folder, however, is preserved. We probe the conventional layouts so that symlinks survive subsequent cycles.
-
archive_acc= 'traj-acc'¶
-
archive_rej= 'traj-rej'¶
-
archive_traj= 'traj'¶
-
formatters= {'energy': {'file': 'energy.txt', 'fmt': <pyretis.inout.formats.energy.EnergyPathFormatter object>}, 'order': {'file': 'order.txt', 'fmt': <pyretis.inout.formats.order.OrderPathFormatter object>}, 'traj': {'file': 'traj.txt', 'fmt': <pyretis.inout.formats.path.PathExtFormatter object>}}¶
-
out_dir_fmt= '{}'¶
-
output(step, data)[source]¶ Format the path data and store the path.
Parameters: - step (integer) – The current simulation step.
- data (list) – Here,
data[0]is assumed to be an object likePath,data[1]a string containing the status of this path anddata[2]the path ensemble for which the path was generated.
Returns: files (list of tuples of strings) – The files added to the archive.
-
output_path_files(step, data, target_dir)[source]¶ Write the output files for energy, path and order parameter.
Parameters: - step (integer) – The current simulation step.
- data (list) – Here,
data[0]is assumed to be an object likePathand data[1]` a string containing the status of this path. - target_dir (string) – The path to where we archive the files.
Returns: files (list of tuple of strings) – These are the files created. The tuple contains the files as a full path and a relative path (to the given target directory). The form is
files[i] = (full_path[i], relative_path[i]). The relative path is useful for organizing internally in archives.
-
target= 'file-archive'¶
-
class
pyretis.inout.archive.PathStorageTar(link_cycle_zero=False, load_folder=None)[source]¶ Bases:
PathStorageA class for handling storage of external trajectories.
Here, we collect the external trajectories into tar archives.
-
static
_add_links_to_archive(archive_file, files)[source]¶ Add symlink entries to a tar archive.
Each
(src, trg)is stored as a symlink whose target is a path relative to the symlink’s own location inside the tar (assuming the tar is extracted in place, i.e. next to thearchive_file). Used for cycle-0loadruns so the tar references the original files instead of duplicating bytes.
-
static
_add_to_archive(archive_file, files)[source]¶ Add some files to an archive file.
Parameters: - archive_file (string) – The path to the archive file to create.
- files (list of tuples) – The path(s) to the file(s) to add with names to
create internally in the archive. That is, the form is:
file[i] = (source[i], target[i])wheretarget[i]will be used as the archive name for filesource[i].
Returns: add (boolean) – True if we added files to the archive.
-
archive_acc= 'traj-acc.tar'¶
-
archive_rej= 'traj-rej.tar'¶
-
output(step, data)[source]¶ Format the path data and store the path.
Parameters: - step (integer) – The current simulation step.
- data (list) – Here,
data[0]is assumed to be an object likePath,data[1]a string containing the status of this path anddata[2]the path ensemble for which the path was generated.
Returns: files (list of tuples of strings) – The files added to the archive.
-
static
-
pyretis.inout.archive.add_to_tar_file(tar_file, files, file_mode='a')[source]¶ Open a tar file and add some files.
Parameters: - tar_file (string) – The path to the tar file to create.
- files (list of tuples) – The path(s) to the file(s) to add with names to
create internaly in the tar file. That is:
file[i] = (source[i], target[i])wheretarget[i]will be used as the archname forsource[i]. - file_mode (string) – Determines how we try to open the tar file.
Returns: out (boolean) – True if we managed to write to the file.
-
pyretis.inout.archive.generate_traj_names(path, target_dir)[source]¶ Generate new file names for moving copying paths.
Parameters: - path (object like
PathBase) – This is the path object we are going to store. - target_dir (string) – The location where we are moving the path to.
Returns: files (list of tuples of strings) – The files to add and the file names to use internally for storing. That is:
file[i] = (source[i], target[i])wheretarget[i]is the internal storage name.- path (object like
pyretis.inout.common module¶
This file contains common functions for the input/output.
It contains some slave functions that are used in the in/output function of PyRETIS.
Important classes defined here¶
- OutputBase (
OutputBase) - A base class for handling the output.
Important methods defined here¶
- check_python_version (
check_python_version()) - A method that will give warnings when we use older and possibly unsupported Python versions.
- create_backup (
create_backup()) - A function to handle the creation of backups of old files.
- make_dirs (
make_dirs()) - Create directories (for path simulation).
- atomic_write (
atomic_write()) - Write a file atomically and durably (crash-safe).
- durable_copy (
durable_copy()) - Copy a file and flush the copy to stable storage.
- fsync_dir (
fsync_dir()) - Flush a directory entry to disk.
- create_empty_ensembles (
create_ensembles()) - A method to prepare the ensembles inputs in settings
- simplify_ensemble_name (
simplify_ensemble_name()) - Simplify the name of ensembles for creating directories.
- generate_file_name (
generate_file_name()) - Generate file name for an output task, from settings.
-
class
pyretis.inout.common.OutputBase(formatter)[source]¶ Bases:
objectA generic class for handling output.
Variables: - formatter (object like py:class:.OutputFormatter) – The object responsible for formatting output.
- target (string) – Determines where the target for the output, for instance “screen” or “file”.
- first_write (boolean) – Determines if we have written something yet, or if this is the first write.
-
output(step, data)[source]¶ Use the formatter to write data to the file.
Parameters: - step (int) – The current step number.
- data (list) – The data we are going to output.
-
target= None¶
-
pyretis.inout.common.add_dirname(filename, dirname)[source]¶ Add a directory as a prefix to a filename, i.e. dirname/filename.
Parameters: - filename (string) – The filename.
- dirname (string) – The directory we want to prefix. It can be None, in which case we ignore it.
Returns: out (string) – The path to the resulting file.
-
pyretis.inout.common.atomic_write(path, write_fn, binary=True, keep_prev=False)[source]¶ Write a file atomically and durably.
The payload is first written to a temporary file in the same directory, flushed to disk with
os.fsyncand then moved into place withos.replace(an atomic operation on POSIX systems when both files reside on the same filesystem). Finally the parent directory entry is flushed so that the rename itself survives a crash.This guarantees that
pathis never observed in a half-written state: after a crash it is either the complete new content or the complete previous content.Parameters: - path (string) – The file we want to create.
- write_fn (callable) – A function that takes a single argument, the open file handle, and writes the payload to it.
- binary (boolean, optional) – If True, the temporary file is opened in binary mode, otherwise in (utf-8) text mode.
- keep_prev (boolean, optional) – If True, an existing
pathis copied topath + '.prev'before the replace. This keeps the previous version available even if a crash happens in the (tiny) window around the rename.
Returns: out (string) – The path that was written.
-
pyretis.inout.common.create_backup(outputfile)[source]¶ Check if a file exist and create backup if requested.
This function will check if the given file name exists and if it does, it will move that file to a new file name such that the given one can be used without overwriting.
Parameters: outputfile (string) – This is the name of the file we wish to create. Returns: out (string) – This string is None if no backup is made, otherwise, it will just say what file was moved (and to where). Note
No warning is issued here. This is just in case the msg returned here will be part of some more elaborate message.
-
pyretis.inout.common.create_empty_ensembles(settings)[source]¶ Create missing ensembles in the settings.
Checks the input and allocate it to the right ensemble. In theory inouts shall include all these info, but it is not practical.
Parameters: settings (dict) – The current input settings. Returns: None, but this method might add data to the input settings.
-
pyretis.inout.common.durable_copy(src, dst)[source]¶ Copy a file and flush the copy to stable storage.
Used for trajectory files (and other binary payloads) that must be on disk before we record them as part of an archived path. Both the copied file and its parent directory entry are flushed with
os.fsync.Parameters: - src (string) – The file to copy.
- dst (string) – The destination file name.
-
pyretis.inout.common.fsync_dir(dirname)[source]¶ Flush a directory entry to disk.
After an atomic rename, the directory entry itself must be flushed for the rename to be durable across a crash (e.g. a power loss). This is best-effort: some filesystems do not allow
fsyncon a directory handle, and that single situation is the only one we ignore here.Parameters: dirname (string) – The directory whose metadata we flush. An empty string is interpreted as the current working directory.
-
pyretis.inout.common.generate_file_name(basename, directory, settings)[source]¶ Generate file name for an output task, from settings.
Parameters: - basename (string) – The base file name to use.
- directory (string) – A directory to output to. Can be None to output to the current working directory.
- settings (dict) – The input settings
Returns: filename (string) – The file name to use.
-
pyretis.inout.common.make_dirs(dirname)[source]¶ Create directories for path simulations.
This function will create a folder using a specified path. If the path already exists and if it’s a directory, we will do nothing. If the path exists and is a file we will raise an OSError exception here.
Parameters: dirname (string) – This is the directory to create. Returns: out (string) – A string with some info on what this function did. Intended for output.
-
pyretis.inout.common.name_file(name, extension, path=None)[source]¶ Return a file name by joining a name and an file extension.
This function is used to create file names. It will use os.extsep to create the file names and os.path.join to add a path name if the path is given. The returned file name will be of form (example for posix):
path/name.extension.Parameters: - name (string) – This is the name, without extension, for the file.
- extension (string) – The extension to use for the file name.
- path (string, optional) – An optional path to add to the file name.
Returns: out (string) – The resulting file name.
-
pyretis.inout.common.simplify_ensemble_name(ensemble, fmt='{:03d}')[source]¶ Simplify path names for file/directory names.
Here, we are basically translating ensemble names to more friendly names for directories and files that is:
[0^-]returns000,[0^+]returns001,[1^+]returns002, etc.
Parameters: - ensemble (string) – This is the string to simplify.
- fmt (string. optional) – This is a format to use for the directories.
pyretis.inout.fileio module¶
Module defining the base classes for the PyRETIS output.
Important classes defined here¶
- FileIO (
FileIO) - A generic class for handling input & output with files.
Important methods defined here¶
- read_some_lines (
read_some_lines()) - Method to read lines from PyRETIS data files.
-
class
pyretis.inout.fileio.FileIO(filename, file_mode, formatter, backup=True)[source]¶ Bases:
OutputBaseA generic class for handling IO with files.
This class defines how PyRETIS stores and reads data. Formatting is handled by an object like
OutputFormatterVariables: - filename (string) – Name (e.g. path) to the file to read or write.
- file_mode (string) – Specifies the mode in which the file is opened.
- backup (boolean) – Determines the behavior if we want to write to a file that is already existing.
- fileh (object like
io.IOBase) – The file handle we are interacting with. - last_flush (object like
datetime.datetime) – The previous time for flushing to the file.
-
__init__(filename, file_mode, formatter, backup=True)[source]¶ Set up the file object.
Parameters: - filename (string) – The path to the file to open or read.
- file_mode (string) – Specifies the mode for opening the file.
- formatter (object like py:class:.OutputFormatter) – The object responsible for formatting output.
- backup (boolean, optional) – Defines how we handle cases where we write to a file which is already existing.
-
open_file_write()[source]¶ Open a file for writing.
In this method, we also handle the possible backup settings.
-
target= 'file'¶
-
write(towrite, end='\n')[source]¶ Write a string to the file.
Parameters: - towrite (string) – The string to output to the file.
- end (string, optional) – Appended to towrite when writing, can be used to print a new line after the input towrite.
Returns: status (boolean) – True if we managed to write, False otherwise.
-
pyretis.inout.fileio._read_line_data(ncol, stripline, line_parser)[source]¶ Read data for
read_some_lines.().Parameters: - ncol (integer) – The expected number of columns to read. If this is less than 1 it is not yet set. Note that we skip data which appear inconsistent. A warning will be issued about this.
- stripline (string) – The line to read. Note that we assume that leading and trailing spaces have been removed.
- line_parser (callable) – A method we use to parse a single line.
-
pyretis.inout.fileio.read_some_lines(filename, line_parser, block_label='#')[source]¶ Open a file and try to read as many lines as possible.
This method will read a file using the given line_parser. If the given line_parser fails at a line in the file, read_some_lines will stop here. Further, this method will read data in blocks and yield a block when a new block is found. A special string (block_label) is assumed to identify the start of blocks.
Parameters: - filename (string) – This is the name/path of the file to open and read.
- line_parser (function, optional) – This is a function which knows how to translate a given line to a desired internal format. If not given, a simple float will be used.
- block_label (string, optional) – This string is used to identify blocks.
Yields: data (list) – The data read from the file, arranged in dicts.
pyretis.inout.restart module¶
This module defines how we write and read restart files.
Important methods defined here¶
- read_restart_file (
read_restart_file()) - A method for reading restart information from a file.
- write_restart_file (
write_restart_file()) - A method for writing the restart file.
- write_ensemble_restart (
write_ensemble_restart()) - A method for writing restart files for path ensembles.
-
pyretis.inout.restart.load_system_restart(system, info)[source]¶ Restore System state from a restart-info dict.
Equivalent to the soon-to-go
System.load_restart_info(info)method on the harness System.Parameters: - system (object like
System) – The system to populate. - info (dict) – The restart info, as produced by
system_restart_info().
- system (object like
-
pyretis.inout.restart.read_restart_file(filename)[source]¶ Read restart info for a simulation.
Parameters: filename (string) – The file we are going to read from.
-
pyretis.inout.restart.system_restart_info(system)[source]¶ Collect restart info for a System (free-function form).
Equivalent to the soon-to-go
System.restart_info()method on the harness System. Returns the same dict shape; works on any System with the bridge surface (units,temperature,post_setup,order,box,particles).Parameters: system (object like System) – The system whose state to serialise.Returns: dict – Restart-info dictionary.
-
pyretis.inout.restart.write_ensemble_restart(ensemble, settings_ens)[source]¶ Write a restart file for a path ensemble.
Parameters: - ensemble (dict) – it contains:
- path_ensemble : object like
PathEnsembleThe path ensemble we are writing restart info for. - ` system` : object like
SystemSystem is used here since we need access to the temperature and to the particle list. - order_function : object like
OrderParameterThe class used for calculating the order parameter(s). - engine : object like
EngineBaseThe engine to use for propagating a path.
- path_ensemble : object like
- settings_ens (dict) – A dictionary with the ensemble settings.
- ensemble (dict) – it contains:
-
pyretis.inout.restart.write_restart_file(filename, simulation)[source]¶ Write restart info for a simulation.
Parameters: - filename (string) – The file we are going to write to.
- simulation (object like
Simulation) – A simulation object we will get information from.
pyretis.inout.screen module¶
Module defining the base classes for the PyRETIS output.
Important classes defined here¶
- ScreenOutput (
FileIO) - A generic class for handling output to the screen.
Important constants defined here¶
- PROGRESSint
- Custom log level (25) between INFO (20) and WARNING (30). Used for user-facing progress messages (green on console).
- BANNERint
- Custom log level (26) between PROGRESS (25) and WARNING (30). Used for decorative/banner text (cyan on console): logo, version info, references.
-
class
pyretis.inout.screen.ScreenOutput(formatter)[source]¶ Bases:
OutputBaseA class for handling output to the screen.
-
target= 'screen'¶
-
pyretis.inout.settings module¶
This module handles parsing of input settings.
This module defines the file format for PyRETIS input files.
Important methods defined here¶
- parse_settings_file (
parse_settings_file()) - Method for parsing settings from a given input file.
- write_settings_file (
write_settings_file()) - Method for writing settings from a simulation to a given file.
-
pyretis.inout.settings._apply_restart_overrides(new_set, settings)[source]¶ Apply allowed keyword overrides from a new input onto restart settings.
Topology-defining keywords (see
RESTART_FORBIDDEN_KEYWORDS) are first checked for equality; any disagreement aborts the restart. For every section and key listed inRESTART_OVERRIDE_KEYWORDS, if the value supplied in the new input file differs from the one stored in the restart, a WARNING is logged and the new value replaces the old one. Sections or keys absent from settings are silently skipped.Parameters: - new_set (dict) – Settings loaded from the restart file (modified in-place).
- settings (dict) – Settings parsed from the new input file.
-
pyretis.inout.settings._check_restart_forbidden(new_set, settings)[source]¶ Raise if topology-defining keywords disagree between input and restart.
Keywords listed in
RESTART_FORBIDDEN_KEYWORDSdescribe the state space of the simulation (interfaces, task, …). They must match the value stored in the restart, otherwise the already-saved paths would be reinterpreted against a different topology and the continuation would be silently wrong.Parameters: - new_set (dict) – Settings loaded from the restart file.
- settings (dict) – Settings parsed from the new input file.
Raises: ValueError – When the new input changes a forbidden keyword.
-
pyretis.inout.settings._clean_settings(settings)[source]¶ Clean up input settings.
Here, we attempt to remove unwanted stuff from the input settings.
Parameters: settings (dict) – The current input settings. Returns: settingsc (dict) – The cleaned input settings.
-
pyretis.inout.settings._drop_none(value)[source]¶ Return
valuewithNone-valued dict keys removed (recursively).Lists are walked element-wise; non-dict, non-list values pass through untouched. Used by
_settings_to_toml_dict()so the on-disk TOML never carries Python ``None``s (TOML has no null).
-
pyretis.inout.settings._finalise_settings(settings, add_default=True)[source]¶ Run the post-parse defaulting / checking pipeline.
Shared by
parse_settings_rst()andparse_settings_toml()so both frontends produce a dict that has gone through the same defaulting and validation.
-
pyretis.inout.settings._intify_parameter_keys(settings)[source]¶ Coerce digit-string keys back to
intunderparameterdicts.The rst parser turns
parameter 0 = {...}into{'parameter': {0: {...}}}(int atom-type index). On the TOML side those keys travel as"0"since TOML keys must be strings; this helper reverses the coercion so both readers produce the same shape. Scoped toparametersub-dicts only so non-numeric user keys ("Ar","H2") are untouched.
-
pyretis.inout.settings._merge_section_text(raw_section)[source]¶ Merge text for settings that are split across lines.
This method supports keyword settings that are split across several lines. Here we merge these lines by assuming that keywords separate different settings.
Parameters: raw_section (string) – The text we will merge.
-
pyretis.inout.settings._normalise_raw(settings)[source]¶ Make a raw settings dict comparable across rst and toml.
- Drops
None-valued keys (TOML has nonull; downstream treats absent andNoneidentically). - Coerces tuples to lists. The rst parser uses
ast.literal_eval()which preserves Python tuple syntax (index = (0, 1)), but TOML has no tuple type. Coercing on the rst side too keeps both readers shape-equal; shipped pyretis consumers index viav[0]/v[1], which works for either.
The decorative
headingsection is NOT dropped here — the rst parser needs to preserve user-provided headings._settings_to_toml_dict()drops it on the write side, and converter-level round-trip tests compare moduloheading.- Drops
-
pyretis.inout.settings._parse_all_raw_sections(raw_sections)[source]¶ Parse all raw sections.
This method is helpful for running tests etc.
Parameters: raw_sections (dict) – The dictionary with the raw data in sections. Returns: settings (dict) – The parsed settings, with one key for each section parsed.
-
pyretis.inout.settings._parse_raw_section(raw_section, section)[source]¶ Parse the raw data from a section.
Parameters: - raw_section (list of strings) – The text data for a given section which will be parsed.
- section (string) – A text identifying the section we are parsing for. This is used to get a list over valid keywords for the section.
Returns: out (dict) – A dict with keys corresponding to the settings.
-
pyretis.inout.settings._parse_section_default(raw_section)[source]¶ Parse a raw section.
This is the default parser for sections.
Parameters: raw_section (list of strings) – The text data for a given section which will be parsed. Returns: setting (dict) – A dict with keys corresponding to the settings.
-
pyretis.inout.settings._parse_section_heading(raw_section)[source]¶ Parse the heading section.
Parameters: raw_section (list of strings) – The text data for a given section which will be parsed. Returns: setting (dict) – A dict with keys corresponding to the settings.
-
pyretis.inout.settings._parse_sections(inputtxt)[source]¶ Find sections in the input file with raw data.
This method will find sections in the input file and collect the corresponding raw data.
Parameters: inputtxt (list of strings or iterable file object) – The raw data to parse. Returns: raw_data (dict) – A dictionary with keys corresponding to the sections found in the input file. raw_data[key] contains the raw data for the section corresponding to key.
-
pyretis.inout.settings._read_rst_raw(filename)[source]¶ Parse rst into the raw, pre-defaulting settings dict.
Used by the rst→toml converter so the on-disk TOML carries only keys the user actually wrote, with no ensemble-inheritance or default-filling artefacts. Strips
None-valued keys so the resulting dict round-trips through TOML (which has nonull).
-
pyretis.inout.settings._read_toml_raw(filename)[source]¶ Parse toml into the raw, pre-defaulting settings dict.
-
pyretis.inout.settings._remove_legacy_tis_settings(settings)[source]¶ Strip deprecated TIS keys after parsing and warn on conflicts.
-
pyretis.inout.settings._set_default_units_from_engine(settings)[source]¶ Set default system units from the selected engine.
Parameters: settings (dict) – The simulation settings. Raises: ValueError – If the engine-specific unit resolution fails.
-
pyretis.inout.settings._settings_to_toml_dict(settings)[source]¶ Project a settings dict onto a TOML-serialisable shape.
- drops the decorative
headingsection - drops
None-valued keys recursively - coerces integer dict keys to strings (TOML keys must be strings;
see
_stringify_int_keys()for why this is round-trip safe) - preserves
SPECIAL_MULTIPLEsections as lists of dicts sotomli_wemits them as arrays-of-tables ([[potential]]).
- drops the decorative
-
pyretis.inout.settings._stringify_int_keys(value)[source]¶ Recursively coerce
intdict keys tostr.TOML disallows non-string keys, but the rst parser produces integer keys for
parameter <int> = ...lines (atom-type indices in pair potentials)._intify_parameter_keys()reverses this on read, so the rst→toml→dict round-trip is exact.
-
pyretis.inout.settings._toml_to_settings(raw)[source]¶ Map a parsed TOML dict to the canonical PyRETIS settings dict.
Aliases (
md→simulation) are normalised; sections inSPECIAL_MULTIPLEare coerced to lists if the user wrote a single table instead of an array-of-tables.
-
pyretis.inout.settings._tuples_to_lists(value)[source]¶ Recursively coerce
tupletolist(TOML has no tuple).
-
pyretis.inout.settings._warn_and_pop_aimless(tis_dict, where)[source]¶ Remove the deprecated
aimlessflag, warning on conflict.The sign of
sigma_vnow selects the shooting style. When the legacyaimlesssetting disagrees with that choice, emit a WARNING so users know their input would silently flip behaviour; when it agrees, emit an INFO-level deprecation notice.
-
pyretis.inout.settings._warn_rst_deprecated(filename)[source]¶ Emit a single
DeprecationWarningfor rst input.Mirrors what users see when they pass
-i FOO.rsttopyretisrun/pyretisanalyse. The warning carries a concrete command (python -m pyretis.tools.convert_settings) so the migration path is in the message itself, not just the docs.
-
pyretis.inout.settings.add_default_settings(settings)[source]¶ Add default settings.
Parameters: settings (dict) – The current input settings. Returns: None, but this method might add data to the input settings.
-
pyretis.inout.settings.add_specific_default_settings(settings)[source]¶ Add specific default settings for each simulation task.
Parameters: settings (dict) – The current input settings. Returns: None, but this method might add data to the input settings.
-
pyretis.inout.settings.fill_up_tis_and_retis_settings(settings)[source]¶ Make the life of sloppy users easier.
The full input set-up will be here completed.
Parameters: settings (dict) – The current input settings. Returns: None, but this method might add data to the input settings.
-
pyretis.inout.settings.parse_settings_file(filename, add_default=True)[source]¶ Parse settings from a file name.
Dispatches on the file extension:
.tomluses the canonical TOML reader; anything else (typically.rst) falls back to the legacy rst parser.Parameters: - filename (string) – The file to parse.
- add_default (boolean) – If True, we will add default settings as well for keywords not found in the input.
Returns: settings (dict) – A dictionary with settings for PyRETIS.
-
pyretis.inout.settings.parse_settings_rst(filename, add_default=True)[source]¶ Parse settings from the legacy
.rstPyRETIS input format.Deprecated since version The: rst input format is deprecated in favour of TOML and will be removed in a future release. This reader still works so existing scripts keep running; to silence the warning, run
python -m pyretis.tools.convert_settings YOUR.rstand switch your workflow to the resulting.tomlfile.Parameters: - filename (string) – The file to parse.
- add_default (boolean) – If True, we will add default settings as well for keywords not found in the input.
Returns: settings (dict) – A dictionary with settings for PyRETIS.
-
pyretis.inout.settings.parse_settings_toml(filename, add_default=True)[source]¶ Parse settings from a pyretis-native
.tomlinput file.The TOML schema mirrors the rst section layout one-to-one: each rst section is a TOML table of the same name; sections that can repeat (
potential,collective-variable,ensemble) are TOML arrays-of-tables; hyphenated keys (order-file,trajectory-file…) are emitted with quoted keys.The returned dict has the same shape as
parse_settings_rst(), so downstream PyRETIS code does not need to know which frontend was used.Parameters: - filename (string) – The TOML file to parse.
- add_default (boolean) – If True, we will add default settings as well for keywords not found in the input.
Returns: settings (dict) – A dictionary with settings for PyRETIS.
-
pyretis.inout.settings.write_settings_file(settings, outfile, backup=True)[source]¶ Write simulation settings to an output file.
Dispatches on the output extension:
.tomlwrites the canonical TOML schema; anything else writes the legacy rst.Parameters: - settings (dict) – The dictionary to write.
- outfile (string) – The file to create.
- backup (boolean, optional) – If True, we will backup existing files with the same file name as the provided file name.
Note
This will currently fail if objects have made it into the supplied
settings.
pyretis.inout.simulationio module¶
Definition of a class for handling output related to simulations.
Important classes defined here¶
- Task (
Task) - Base class for tasks. This is used by
SimulationTaskandOutputTask. - OutputTask (
OutputTask) - A class representing a simulation output task.
Important methods defined here¶
- get_task_type (
get_task_type()) - Do additional handling for a path task.
- get_file_mode (
get_file_mode()) - Determine if we should append or backup existing files.
- task_from_settings (
task_from_settings()) - Create output task from simulation settings.
Important variables defined here¶
- OUTPUT_TASKS (
OUTPUT_TASKS) - A dictionary defining the different output tasks known to PyRETIS.
-
pyretis.inout.simulationio.OUTPUT_TASKS= {'cross': {'filename': 'cross.txt', 'formatter': <class 'pyretis.inout.formats.cross.CrossFormatter'>, 'result': ('cross',), 'target': 'file', 'when': 'cross-file'}, 'energy': {'filename': 'energy.txt', 'formatter': <class 'pyretis.inout.formats.energy.EnergyFormatter'>, 'result': ('thermo',), 'target': 'file', 'when': 'energy-file'}, 'order': {'filename': 'order.txt', 'formatter': <class 'pyretis.inout.formats.order.OrderFormatter'>, 'result': ('order',), 'target': 'file', 'when': 'order-file'}, 'path-energy': {'filename': 'energy.txt', 'formatter': <class 'pyretis.inout.formats.energy.EnergyPathFormatter'>, 'result': ('path', 'status'), 'target': 'file', 'when': 'energy-file'}, 'path-order': {'filename': 'order.txt', 'formatter': <class 'pyretis.inout.formats.order.OrderPathFormatter'>, 'result': ('path', 'status'), 'target': 'file', 'when': 'order-file'}, 'path-traj-ext': {'filename': 'traj.txt', 'result': ('path', 'status', 'pathensemble'), 'target': 'file-archive', 'when': 'trajectory-file', 'writer': <class 'pyretis.inout.archive.PathStorage'>}, 'path-traj-int': {'filename': 'traj.txt', 'formatter': <class 'pyretis.inout.formats.path.PathIntFormatter'>, 'result': ('path', 'status'), 'target': 'file', 'when': 'trajectory-file'}, 'pathensemble': {'filename': 'pathensemble.txt', 'formatter': <class 'pyretis.inout.formats.pathensemble.PathEnsembleFormatter'>, 'result': ('pathensemble',), 'target': 'file', 'when': 'pathensemble-file'}, 'pathensemble-retis-screen': {'formatter': <class 'pyretis.inout.formats.txt_table.RETISResultFormatter'>, 'result': ('pathensemble',), 'target': 'screen', 'when': 'screen'}, 'pathensemble-screen': {'formatter': <class 'pyretis.inout.formats.txt_table.PathTableFormatter'>, 'result': ('pathensemble',), 'target': 'screen', 'when': 'screen'}, 'thermo-file': {'filename': 'thermo.txt', 'formatter': <class 'pyretis.inout.formats.txt_table.ThermoTableFormatter'>, 'result': ('thermo',), 'target': 'file', 'when': 'energy-file'}, 'thermo-screen': {'formatter': <class 'pyretis.inout.formats.txt_table.ThermoTableFormatter'>, 'result': ('thermo',), 'target': 'screen', 'when': 'screen'}, 'traj-txt': {'filename': 'traj.txt', 'formatter': <class 'pyretis.inout.formats.snapshot.SnapshotFormatter'>, 'result': ('system',), 'target': 'file', 'when': 'trajectory-file'}, 'traj-xyz': {'filename': 'traj.xyz', 'formatter': <class 'pyretis.inout.formats.snapshot.SnapshotFormatter'>, 'result': ('system',), 'target': 'file', 'when': 'trajectory-file'}}¶ Define a set of known output tasks.
The output tasks are defined as dictionaries with the following keys:
- targetstring
“file” or “screen”, defines where the task writes to.
- filenamestring
A default file name for an output file if writing to a file.
- resulttuple of strings
Determines what item from the result dictionary we are outputting.
- whenstring
Determines what input setting from the “output” section is used to define the output frequency. Default values are defined by the output section, see: py:mod:pyretis.inout.settings.settings.
- formatterobject like
OutputFormatter Selects the formatter for the output.
- formatterobject like
- writerobject like
OutputBase Selects the writer for the output.
- writerobject like
- settingstuple of strings, optional
A dict with additional settings which can be passed to the formatter if needed. These settings can, for instance, be defined in the output section of the input file.
The writer can be defined explicitly, or via the formatter. If a formatter is given, then the generic
FileIOwill be used. If no formatter is given, then the writer is assumed to be given.
-
class
pyretis.inout.simulationio.OutputTask(name, result, writer, when)[source]¶ Bases:
TaskA base class for simulation output.
This class will handle an output task for a simulation. The output task consists of one object which is responsible for formatting the output data and one object which is responsible for writing that data, for instance to the screen or to a file.
Variables: - target (string) – This string identifies what kind of output we are dealing with. This will typically be either “screen” or “file”.
- name (string) – This string identifies the task, it can, for instance, be used to reference the dictionary used to create the writer.
- result (tuple of strings) – This string defines the result we are going to output.
- writer (object like
OutputBase) – This object will handle the actual outputting of the result. - when (dict) – Determines if the task should be executed.
-
__init__(name, result, writer, when)[source]¶ Initialise the generic output task.
Parameters: - name (string) – This string identifies the task, it can, for instance, be used to reference the dictionary used to create the writer.
- result (list of strings) – These strings define the results we are going to output.
- writer (object like
IOBase) – This object will handle formatting of the actual result and output to screen or to a file. - when (dict) – Determines when the output should be written. Example: {‘every’: 10} will be executed at every 10th step.
-
output(simulation_result)[source]¶ Output given results from simulation steps.
This will output the task using the result found in the simulation_result which should be the dictionary returned from a simulation object (e.g. object like
Simulation) after a step.Parameters: simulation_result (dict) – This is the result from a simulation step. Returns: out (boolean) – True if the writer wrote something, False otherwise.
-
class
pyretis.inout.simulationio.Task(when)[source]¶ Bases:
objectBase representation of a “task”.
A task is just something that is supposed to be executed at a certain point. This class will just set up functionality that is common for output tasks and for simulation tasks.
Variables: when (dict) – Determines when the task should be executed. -
__init__(when)[source]¶ Initialise the task.
Parameters: when (dict, optional) – Determines if the task should be executed.
-
execute_now(step)[source]¶ Determine if a task should be executed.
Parameters: step (dict of ints) – Keys are ‘step’ (current cycle number), ‘start’ cycle number at start ‘stepno’ the number of cycles we have performed so far. Returns: out (boolean) – True of the task should be executed.
-
property
when¶ Return the “when” property.
-
-
pyretis.inout.simulationio.get_file_mode(settings)[source]¶ Determine if we should append or backup existing files.
This method translates the backup settings into a file mode string. We assume here that the file is opened for writing.
Parameters: settings (dict) – The simulation settings. Returns: file_mode (string) – A string representing the file mode to use.
-
pyretis.inout.simulationio.get_task_type(task, engine)[source]¶ Do additional handling for a path task.
The path task is special since we do very different things for external paths. The set-up required to do this is handled here.
Parameters: - task (dict) – Settings related to the specific task.
- engine (object like
EngineBase) – This object is used to determine if we need to do something special for external engines. If no engine is given, we do not do anything special.
Returns: out (string) – The task type we are going to be creating for.
-
pyretis.inout.simulationio.task_from_settings(task, settings, directory, engine, progress=False)[source]¶ Create output task from simulation settings.
Parameters: - task (dict) – Settings for creating a task. This dict contains the type and
name of the task to create. It can also contain overrides to
the default settings in
OUTPUT_TASKS. - settings (dict) – Settings for the simulation.
- directory (string) – The directory to write output files to.
- engine (object like
EngineBase) – This object is used to determine if we need to do something special for external engines. If no engine is given, we do not do anything special. - progress (boolean, optional) – For some simulations, the user may select to display a progress bar. We will then just disable the other screen output.
Returns: out (object like
OutputTask) – An output task we can use in the simulation.- task (dict) – Settings for creating a task. This dict contains the type and
name of the task to create. It can also contain overrides to
the default settings in
pyretis.inout.checker module¶
This module checks that the inputs are meaningful.
Main methods defined here¶
- check_ensemble (
check_ensemble()) - Function to check the ensemble settings.
- check_interfaces (
check_interfaces()) - Function to check engine set-up.
- check_for_bullshitt (
check_for_bullshitt()) - Function to compare nested dicts and lists.
- check_engine (
check_engine()) - Function to check engine set-up.
-
pyretis.inout.checker._check_wire_fencing_zero_minus(settings)[source]¶ Warn if wire fencing is set for the [0^-] ensemble.
Wire fencing requires middle != right interface, but the [0^-] ensemble has middle == right == lambda_0, making it inapplicable. When detected, the shooting move for [0^-] is reset to ‘sh’.
Parameters: settings (dict) – The current input settings.
-
pyretis.inout.checker.check_engine(settings)[source]¶ Check the engine settings.
Checks that the input engine settings are correct, and automatically determine the ‘internal’ or ‘external’ engine setting.
Parameters: settings (dict) – The current input settings.
-
pyretis.inout.checker.check_ensemble(settings)[source]¶ Check that the ensemble input parameters are complete.
Parameters: settings (dict) – The settings needed to set up the simulation.