polyphys.probe.core#

polyphys.probe.core#

The polyphys.probe.core module holds what every probe shares: how a study’s LAMMPS data file and dump are opened as one MDAnalysis Universe, and the stamps file, the one-row table of a probed artifact’s lineage names, parser attributes, and frame count that the organizer later combines across a space.

The research code opened every universe with the same four arguments and wrote the stamps with the same columns in each of its probe functions; make_universe() and write_stamps() are those two pieces, written once.

Contents#

Dependencies#

Every probe analysis computes each part of a split run on its own shallow copy of itself (_compute_part), so that the serial backend, which hands every part the same analysis object, keeps each part’s results, frames, and times apart, as the multiprocessing and dask backends do by pickling.

Every probe analysis also takes its run from _ProbeAnalysis, which closes and joins the pool of the multiprocessing backend instead of terminating it, so the workers exit normally and release the semaphores they made.

Examples

>>> import tempfile
>>> from polyphys.tests.synthetic import ChainCyl
>>> parser = ChainCyl('N4r2.5lz10ac1nc0dt0.005bdump1adump1ens1',
...                     'whole', 'bug')
>>> with tempfile.TemporaryDirectory() as tmp:
...     path = write_stamps(parser, n_frames=5, save_to=tmp)
...     path.name
'N4r2.5lz10ac1nc0dt0.005bdump1adump1ens1-bug-stamps.csv'

Added in version 0.7.0.

Module Attributes

UNIVERSE_KWARGS

a LAMMPS data file as the topology, a LAMMPS dump as the trajectory with its coordinates read as the wrapped, unscaled x y z columns, and the Atoms lines of the data file read as id resid type x y z, the bond, angle, and molecular atom styles whose molecule ID becomes the residue ID that a selection such as 'resid 1' picks.

Functions

make_universe(topology, trajectory, **kwargs)

Open a LAMMPS data file and dump as one MDAnalysis universe, as the studies read them.

write_stamps(parser, n_frames, save_to)

Write the stamps of one probed artifact: a one-row CSV of its lineage names, its parser attributes, and its number of frames.

polyphys.probe.core.UNIVERSE_KWARGS: Mapping[str, str] = mappingproxy({'topology_format': 'DATA', 'format': 'LAMMPSDUMP', 'lammps_coordinate_convention': 'unscaled', 'atom_style': 'id resid type x y z'})#

a LAMMPS data file as the topology, a LAMMPS dump as the trajectory with its coordinates read as the wrapped, unscaled x y z columns, and the Atoms lines of the data file read as id resid type x y z, the bond, angle, and molecular atom styles whose molecule ID becomes the residue ID that a selection such as 'resid 1' picks.

Added in version 0.7.0.

Type:

The fixed arguments of make_universe()

polyphys.probe.core.make_universe(topology, trajectory, **kwargs)[source]#

Open a LAMMPS data file and dump as one MDAnalysis universe, as the studies read them.

Added in version 0.7.0.

Parameters:
  • topology (str | os.PathLike[str]) – The LAMMPS data file, whose Atoms lines are atom-ID molecule-ID atom-type x y z and whose Masses section gives every atom type a mass. The masses weight the radius of gyration and the gyration tensor; without them MDAnalysis cannot form the tensor.

  • trajectory (str | os.PathLike[str]) – The LAMMPS dump, in the atom style with unscaled, wrapped coordinates (ITEM: ATOMS id type x y z). MDAnalysis sorts the atoms of each frame by id, so positions are in atom-ID order, the order along the chain.

  • **kwargs (typing.Any) – Further arguments of Universe, such as dt, the time between frames, or in_memory. The keys of UNIVERSE_KWARGS are fixed and may not be given.

Returns:

The universe, with the trajectory at its first frame.

Return type:

MDAnalysis.Universe

Raises:

ValueError – If kwargs names a key of UNIVERSE_KWARGS.

Warns:

UserWarning – From the dump reader, Reader has no dt information, when dt is not given: the frame times are then the dump’s time steps.

Notes

The dump’s box is read per frame; the data file’s box is not used after the topology is built. Opening a universe reads the whole data file and indexes the dump, \(O(N + F)\) time for \(N\) atoms and \(F\) frames, and holds the topology, \(O(N)\) space; frames are read one at a time unless in_memory is set.

Examples

A two-bead chain in a one-frame dump:

>>> import tempfile
>>> import numpy as np
>>> from polyphys.simulate.core import Box
>>> from polyphys.simulate.data import DataFile, write_data
>>> pair = DataFile(
...     atom_style='bond', box=Box(lo=np.zeros(3), hi=np.full(3, 5.0)),
...     ids=np.array([1, 2]), types=np.array([1, 1]),
...     positions=np.array([[2.0, 2.5, 2.5], [3.0, 2.5, 2.5]]),
...     n_atom_types=1, masses=np.array([1.0]), mol_ids=np.array([1, 1]),
...     bonds=np.array([[1, 1, 2]]), n_bond_types=1)
>>> dump = '''ITEM: TIMESTEP
... 0
... ITEM: NUMBER OF ATOMS
... 2
... ITEM: BOX BOUNDS pp pp pp
... 0 5
... 0 5
... 0 5
... ITEM: ATOMS id type x y z
... 2 1 3.0 2.5 2.5
... 1 1 2.0 2.5 2.5
... '''
>>> with tempfile.TemporaryDirectory() as tmp:
...     data = write_data(pair, Path(tmp) / 'pair.data')
...     _ = (Path(tmp) / 'pair.lammpstrj').write_text(dump)
...     universe = make_universe(data, Path(tmp) / 'pair.lammpstrj',
...                              dt=1.0)
...     chain = universe.select_atoms('resid 1')
...     chain.n_atoms, universe.trajectory.n_frames, chain.ids.tolist()
(2, 1, [1, 2])
polyphys.probe.core.write_stamps(parser, n_frames, save_to)[source]#

Write the stamps of one probed artifact: a one-row CSV of its lineage names, its parser attributes, and its number of frames.

Added in version 0.7.0.

Parameters:
  • parser (polyphys.manage.parser.ParserBase) – The artifact’s parser, at the segment or whole lineage, built from the trajectory’s name or path.

  • n_frames (int) – The number of frames probed, zero or more.

  • save_to (str | os.PathLike[str]) – An existing directory; the file is <name>-<group>-stamps.csv in it, with the parser’s name and group.

Returns:

The file written.

Return type:

pathlib.Path

Raises:

ValueError – If n_frames is not a non-negative integer.

Notes

The columns are, in order, the lineage names of lineage_genealogy, the group, every name in attributes, and n_frames; the row holds the parser’s values. The research code’s stamps_report wrote the same columns without group, which children_stamps() then takes from the file name. Time and space are \(O(a)\) for \(a\) attributes.

Examples

>>> import tempfile
>>> from polyphys.tests.synthetic import ChainCyl
>>> parser = ChainCyl(
...     'N4r2.5lz10ac1nc0dt0.005bdump1adump1ens1.j01', 'segment',
...     'bug')
>>> with tempfile.TemporaryDirectory() as tmp:
...     stamps = pd.read_csv(write_stamps(parser, 3, tmp))
>>> stamps.columns[:3].tolist(), stamps.columns[-2:].tolist()
(['segment', 'whole', 'ensemble_long'], ['rho_bulk_c', 'n_frames'])
>>> int(stamps.loc[0, 'nmon']), int(stamps.loc[0, 'n_frames'])
(4, 3)