wepy.reporter.walker module

Provides a reporter for generating 3D molecular structure files for walkers.

This is useful for getting a snapshot of what is happening in the simulation as it progresses.

class wepy.reporter.walker.WalkerReporter(*, init_state=None, json_topology=None, main_rep_idxs=None, **kwargs)[source]

Bases: wepy.reporter.reporter.ProgressiveFileReporter

Reporter for generating 3D molecular structure files of the walkers produced by a cycle.

It generates two different files using the mdtraj library: a PDB format and a DCD file.

The PDB is used as a “topology” that is only generated once at the beginning of a simulation (in the call to the ‘init’ method). This defines the atom types and bonds for non-protein molecules. Most molecular viewers have special algorithms that automatically determine bond topologies from amino acid residue designations.

The DCD is a binary format that carries only information about the positions of atoms (essentially a (N_frames, N_atoms, 3) array) that is recognized by many different molecular viewer software. This is generated every cycle and the number of frames is the number of walkers.

Because this representation is meant to be amenable to visual inspection, there is functionality for subsetting atoms from the full simulation system (i.e. to remove solvent).

Constructor for the WalkerReporter.

Parameters
  • init_state (object implementing WalkerState) – An initial state, only used for writing the PDB topology.

  • json_topology (str) – A molecular topology in the common JSON format, that matches the main_rep_idxs.

  • main_rep_idxs (listlike of int) – The indices of the atoms to select from the full representation.

FILE_ORDER = ('init_state_path', 'walker_path')

Specify an ordering of file paths. Should be customized.

SUGGESTED_EXTENSIONS = ('init_top.pdb', 'walkers.dcd')

Suggested extensions for file paths for use with the automatic reparametrization feature. Should be customized.

init(**kwargs)[source]

Initialize the reporter at simulation time.

This will generate the initial state PDB file.

DEFAULT_MODE = 'x'

The default mode to set for opening files if none is specified (create if doesn’t exist, fail if it does.)

DEFAULT_SUGGESTED_EXTENSION = 'report'

The default file extension used for files during dynamic reparametrization, if none is specified

MODES = ('x', 'w', 'w-', 'r', 'r+')

Valid modes accepted for files.

SUGGESTED_FILENAME_TEMPLATE = '{config}{narration}{reporter_class}.{ext}'

Template to use for dynamic reparametrization of file path names.

The fields in the template are:

config : indicator of the runtime configuration used

narration : freeform description of the instance

reporter_classthe name of the class that produced the

output. When no specific name is given for a file report generated from a reporter this is used to disambiguate, along with the extension.

ext : The file extension, for multiple files produced from one reporter this should be sufficient to disambiguate the files.

The ‘config’ and ‘narration’ should be the same across all reporters in the same simulation manager, and the ‘narration’ is considered optional.

_validate_mode(mode)

Check if the mode spec is a valid one.

Parameters

mode (str) –

Returns

valid

Return type

bool

cleanup(**kwargs)

Teardown routines for the reporter at the end of the simulation.

Use to cleanly and safely close I/O connections or other cleanup I/O.

Use to close file descriptors, database connections etc.

Reporters can expect to have the following key word arguments passed to them during a simulation by the sim_manager.

Parameters
  • runner (Runner object) – The runner at the end of the simulation

  • work_mapper (WorkeMapper object) – The work mapper at the end of the simulation

  • resampler (Resampler object) – The resampler at the end of the simulation

  • boundary_conditions (BoundaryConditions object) – The boundary conditions at the end of the simulation

  • reporters (list of Reporter objects) – The list of reporters at the end of the simulation

property file_path

For single file path reporters the file path to that file spec.

property file_paths

The file paths for this reporter, in order.

property mode

For single file path reporters the mode of that file.

property modes

The modes for the files, in order.

reparametrize(file_paths, modes)

Set the file paths and modes for all files in the reporter.

Parameters
  • file_paths (list of str) – New file paths for each file, in order.

  • modes (list of str) – New modes for each file, in order.

report(cycle_idx=None, new_walkers=None, **kwargs)[source]

Report the current cycle’s walker states as 3D molecular structures.

Parameters
  • cycle_idx (int) –

  • new_walkers (list of Walker objects) –

set_mode(file_idx, mode)

Set the mode for a single indexed file.

Parameters
  • file_idx (int) – Index in the listing of files.

  • mode (str) – The new mode spec.

set_path(file_idx, path)

Set the path for a single indexed file.

Parameters
  • file_idx (int) – Index in the listing of files.

  • path (str) – The new path to set for this file