Analysis workflow

The Sample class coordinates post-processing of a trajectory. You can configure multiple of samplers to analyse different properties at once.

The easiest way to analyse a ReaxFF simulation is to run the ana.py script generated by Simulate.generate(). All you have to do is fill in the atoms, bonds, rdf pairs you want.

Creating a Sample instance

To start an analysis, create a Sample instance to read the trajectory and bond files.

from porereax import Sample

atom_lib = {"Si": 1, "O": 2, "H": 3}
masses = {"Si": 28.086, "O": 15.9994, "H": 2.016}

sampler = Sample(
    atom_lib=atom_lib,
    masses=masses,
    trajectory_file="run_0.lammpstrj",
    bond_file="run_0.bonds",
)
  • atom_lib maps every atom type name that appears in the trajectory to a numeric LAMMPS type ID. The defined names are later used to write down the bonding environments.

  • masses maps the same atom names to their mass; its keys must match atom_lib exactly.

  • trajectory_file is the .lammpstrj dump, and bond_file the matching ReaxFF .bonds file (both written by the LAMMPS).

  • system (optional) points to a pore.yml describing a pore, required for the "Pore"/"Reservoir"/"Wall" regions and for "Pore1D"/"Pore2D" density sampling.

  • start_end_nthframe=(start, end, nth) (optional, default (0, -1, 1)) restricts sampling to a frame range, end=-1 meaning the last frame, and samples every nth frame.

Note

Do not import ovito yourself before creating a Sample instance. If your platform only supports the fork multiprocessing start method (see Execution below), an already-imported ovito module in the main process will raise an error when sample() tries to start subprocesses.

Registering samplers

Calling any add_*_sampling(...) method adds the sampler to the list of samplers to run.

Each method takes a name_out (used for the output file, see Output files below) and, depending on the sampler, one or more atoms=[...] / bonds=[...] / pairs=[...] / reactions=[...] entries describing the bonding environments to sample (except for molecule_structure_sampling, which searches and counts all bonding environments). Optionaly a region can be specified to restrict the sampling to a certain area of the box.

sampler.add_molecule_structure_sampling(name_out="molecule_structure")
sampler.add_charge_sampling(
    name_out="charge", atoms=[{"atom": "O", "bonds": ["H", "H"]}]
)
sampler.add_rdf_sampling(
    name_out="rdf",
    pairs=[({"atom": "O", "bonds": ["Si", "H"]}, {"atom": "O", "bonds": ["H", "H"]})],
    region="Pore",
)

Execution

sampler.sample(is_parallel=True, num_cores=8)

sample() runs the analysis and samples with each registered sampler. The analysis can be run in parallel with is_parallel=True or serially with only one process.

sampler.sample(is_parallel=False)

Note

Parallel execution uses multiprocessing, preferring the forkserver or spawn, and only falling back to fork if neither is available. fork brings a risk of deadlocks if the ovito module is already imported or any pre defined object is not picklable.

Output files

Each registered sampler writes a single <name_out>.obj file once sample() finishes, e.g. the example above produces molecule_structure.obj, charge.obj, and rdf.obj. These are pickled dictionaries keyed by the identifiers of the atoms/bonds/pairs/reactions you registered, plus an input_params entry recording how the sampler was configured. See Visualisation for how to load and plot them.

Progress output

Sample reports progress through the standard logging module (logger porereax.sample). Enable it with logging.basicConfig(level=logging.INFO); the generated ana.py already does this.