pyretis.tools package

Tools which can help with setting up simulations.

This package defines some simple tools which may be useful for creating simulations.

Package structure

Modules

lattice.py (pyretis.tools.lattice)
Defines tools for setting up and generating lattice points.
recalculate_order.py (pyretis.tools.recalculate_order)
Methods for recalculating order parameters on external paths.

Important methods defined in this package

generate_lattice (generate_lattice())
Generates points on a lattice.
recalculate_order (recalculate_order())
Recalculate order parameter(s).

pyretis.tools.lattice module

Some methods for generating initial lattice structures.

Important methods defined here

generate_lattice (generate_lattice())
Generate points on a simple lattice.

Examples

>>> from pyretis.tools.lattice import generate_lattice
>>> xyz, size = generate_lattice('diamond', [1, 1, 1], lcon=1)
pyretis.tools.lattice.generate_lattice(lattice, repeat=None, lcon=None, density=None)[source]

Generate points on a simple lattice.

The lattice is one of the defined keys in the global variable UNIT_CELL. This lattice will be repeated a number of times. The lattice spacing can be given explicitly, or it can be given implicitly by the number density.

Parameters:
  • lattice (string) – Select the kind of lattice. The following options are currently defined in UNIT_CELL:

    • 1d : 1D lattice
    • sc : Simple cubic lattice.
    • sq : Square lattice (2D) with one atom in the unit cell.
    • sq2 : Square lattice with two atoms in the unit cell.
    • bcc : Body-centred cubic lattice.
    • fcc : Face-centred cubic lattice.
    • hcp : Hexagonal close-packed lattice.
    • diamond : Diamond structure.
  • repeat (list of integers, optional.) – How many time the cell is replicated.

  • lcon (float, optional) – The lattice constant.

  • density (float, optional) – The desired density. If this is given, lcon is calculated. Note that density will be interpreted as given in internal units.

Returns:

  • positions (numpy.array) – The lattice positions.
  • size (list of floats) – The corresponding size(s), can be used to define a simulation box.

pyretis.tools.recalculate_order module

Method to re-calculate order parameters for external trajectories.

Important methods defined here

recalculate_order (recalculate_order())
Generic method for recalculating order parameters.
recalculate_from_trj (recalculate_from_trj())
Recalculate order parameters using a GROMACS .trr file.
recalculate_from_xyz (recalculate_from_xyz())
Recalculate order parameters using a .xyz file.
recalculate_from_frame (recalculate_from_frame())
Recalculate order parameters using a .gro or .g96 file.
pyretis.tools.recalculate_order.recalculate_from_frame(order_parameter, frame_file, options)[source]

Re-calculate order parameters from a .g96/.gro file.

Here we assume that there is ONE frame in the frame_file.

Parameters:
  • order_parameter (object like OrderParameter) – The order parameter to use.
  • frame_file (string) – The path to the frame file we should read.
  • options (dict) – It contains:
    • ext: string File extension for the frame_file.
    • reverse: boolean, optional If True, we reverse the velocities.
Returns:

out (list of lists of floats) – The order parameters for the current frame.

pyretis.tools.recalculate_order.recalculate_from_trj(order_parameter, trr_file, options)[source]

Re-calculate order parameters from a .trr file.

Parameters:
  • order_parameter (object like OrderParameter) – The order parameter to use.
  • trr_file (string) – The path to the trr file we should read.
  • options (dict) – It contains:
    • reverse: boolean, optional If True, we reverse the velocities.
    • maxidx: integer, optional This is the maximum frame we will read. Can be used in case the .trr file contains extra frames not needed by us.
    • minidx: integer, optional This is the first frame we will read. Can be used in case we want to skip some frames from the .trr file.
    • idx: integer, optional This allows the selection of a single frame to recompute.
Yields:

out (list of lists of floats) – The order parameters, calculated per frame.

pyretis.tools.recalculate_order.recalculate_from_xyz(order_parameter, traj_file, options)[source]

Re-calculate order parameters from a .xyz file.

Parameters:
  • order_parameter (object like OrderParameter) – The order parameter to use.
  • traj_file (string) – The path to the trajectory file we should read.
  • options (dict) – It contains:
    • reverse: boolean, optional If True, we reverse the velocities.
    • maxidx: integer, optional This is the maximum frame we will read. Can be used in case the .trr file contains extra frames not needed by us.
    • minidx: integer, optional This is the first frame we will read. Can be used in case we want to skip some frames from the .trr file.
    • box: list of floats It contains the box vector lenght. It is required in the case that .xyz do not normally contains the simulation box dimension.
Yields:

out (list of lists of floats) – The order parameters as a list.

pyretis.tools.recalculate_order.recalculate_order(order_parameter, traj_file, options)[source]

Re-calculate order parameters.

Parameters:
  • order_parameter (object like OrderParameter) – The order parameter to use.
  • traj_file (string) – Path to the trajectory file to recalculate for.
  • options (dict) – It contains:
    • reverse: boolean, optional If True, we reverse the velocities.
    • maxidx: integer, optional This is the maximum frame we will read. Can be used in case the .trr file contains extra frames not needed by us.
    • minidx: integer, optional This is the first frame we will read. Can be used in case we want to skip some frames from the .trr file.

pyretis.tools.convert_settings module

Convert a legacy PyRETIS .rst settings file to TOML.

Usage:
python -m pyretis.tools.convert_settings path/to/retis.rst python -m pyretis.tools.convert_settings path/to/retis.rst out.toml

If the output path is omitted, the converter writes alongside the input with the extension swapped to .toml (retis.rstretis.toml). The original .rst is left in place.

The converter validates each conversion by re-reading the produced TOML and comparing the resulting raw settings dict to the rst one; any mismatch aborts with an error.

pyretis.tools.convert_settings._strip_heading(value)[source]

Drop heading keys recursively for converter equality checks.

The TOML schema intentionally omits the decorative heading text, so any nested copy (created by ensemble-inheritance during defaulting) is ignored when comparing raw dicts.

pyretis.tools.convert_settings.convert(rst_path, toml_path=None, *, force=False, validate=True)[source]

Convert one rst file to TOML and (optionally) verify the round-trip.

Returns the path of the written TOML file.

pyretis.tools.convert_settings.main(argv=None)[source]

Run the settings converter command line interface.