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#
make_universe(), a universe of a LAMMPS data file and dump in the convention of the studies.write_stamps(), the stamps CSV of one probed artifact.UNIVERSE_KWARGS, the fixed arguments ofmake_universe().
Dependencies#
Python standard library: copy, multiprocessing, os, pathlib, types, typing.
MDAnalysis 2.8 or later, through the
mdaextra.
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
a LAMMPS data file as the topology, a LAMMPS dump as the trajectory with its coordinates read as the wrapped, unscaled |
Functions
|
Open a LAMMPS data file and dump as one MDAnalysis universe, as the studies read them. |
|
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 zcolumns, and theAtomslines of the data file read asid resid type x y z, thebond,angle, andmolecularatom 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, whoseAtomslines areatom-ID molecule-ID atom-type x y zand whoseMassessection 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 theatomstyle with unscaled, wrapped coordinates (ITEM: ATOMS id type x y z). MDAnalysis sorts the atoms of each frame byid, sopositionsare in atom-ID order, the order along the chain.**kwargs (
typing.Any) – Further arguments ofUniverse, such asdt, the time between frames, orin_memory. The keys ofUNIVERSE_KWARGSare 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 thesegmentorwholelineage, 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.csvin it, with the parser’s name and group.
- Returns:
The file written.
- Return type:
- Raises:
ValueError – If n_frames is not a non-negative integer.
Notes
The columns are, in order, the lineage names of
lineage_genealogy, thegroup, every name inattributes, andn_frames; the row holds the parser’s values. The research code’sstamps_reportwrote the same columns withoutgroup, whichchildren_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)