polychrom.polymerutils module

Loading and saving individual conformations

The module polychrom.polymerutils provides tools for saving and loading individual conformations. Note that saving and loading trajectories should generally be done using polychrom.hdf5_format module. This module provides tools for loading/saving invividual conformations, or for working with projects that have both old-style and new-style trajectories.

For projects using both old-style and new-style trajectories(e.g. in a project that was switched to polychrom, and new files were added), a function polychrom.polymerutils.fetch_block() can be helpful as it provides the same interface for fetching a conformation from both old-style and new-style trajectory. Note however that it is not the fastest way to iterate over conformations in the new-style trajectory, and the polychrom.hdf5_format.list_URIs() is faster.

A typical workflow with the new-style trajectories should be:

URIs = polychrom.hdf5_format.list_URIs(folder)
for URI in URIs:
    data = polychrom.hdf5_format.load_URI(URI)
    xyz = data["pos"]
polychrom.polymerutils.fetch_block(folder, ind, full_output=False)[source]

A more generic function to fetch block number “ind” from a trajectory in a folder

This function is useful both if you want to load both “old style” trajectories (block1.dat), and “new style” trajectories (“blocks_1-50.h5”)

It will be used in files “show”

Parameters
  • folder (str, folder with a trajectory) –

  • ind (str or int, number of a block to fetch) –

  • full_output (bool (default=False)) – If set to true, outputs a dict with positions, eP, eK, time etc. if False, outputs just the conformation (relevant only for new-style URIs, so default is False)

Returns

  • data, Nx3 numpy array

  • if full_output==True, then dict with data and metadata; XYZ is under key “pos”

polychrom.polymerutils.load(filename)[source]

Universal load function for any type of data file It always returns just XYZ positions - use fetch_block or hdf5_format.load_URI for loading the whole metadata

Accepted file types

New-style URIs (HDF5 based storage)

Text files in openmm-polymer format joblib files in openmm-polymer format

param filename

filename to load or a URI

type filename

str

polychrom.polymerutils.rotation_matrix(rotate)[source]

Calculates rotation matrix based on three rotation angles

polychrom.polymerutils.save(data, filename, mode='txt', pdbGroups=None)[source]

Basically unchanged polymerutils.save function from openmm-polymer

It can save into txt or joblib formats used by old openmm-polymer

It is also very useful for saving files to PDB format to make them compatible with nglview, pymol_show and others