mythos.simulators.io ==================== .. py:module:: mythos.simulators.io .. autoapi-nested-parse:: Common data structures for simulator I/O. Classes ------- .. autoapisummary:: mythos.simulators.io.SimulatorTrajectory Functions --------- .. autoapisummary:: mythos.simulators.io._merge_metadata Module Contents --------------- .. py:class:: SimulatorTrajectory Bases: :py:obj:`jax_md.rigid_body.RigidBody` A trajectory of a simulation run. This class extends jax_md.rigid_body.RigidBody to include optional metadata associated with each state in the trajectory. This object can also store data associated with a single state, but in such a case certain methods do not make sense (e.g. filtering or slicing). Such single-state usage is primarily intended for use within mapping functions. :param center: The center of mass positions for each rigid body at each state in the trajectory. :param orientation: The orientations (as quaternions) for each rigid body at each state in the trajectory. :param box_size: Optional box size associated with each state in the trajectory. :param metadata: Optional metadata associated with each state in the trajectory. This must be a dictionary where each value is a numerical array whose first axis has length corresponding to number of states. .. py:attribute:: box_size :type: mythos.utils.types.Arr_Box | None :value: None .. py:attribute:: metadata :type: dict[str, jax.numpy.ndarray] | None :value: None .. py:method:: from_rigid_body(rigid_body: jax_md.rigid_body.RigidBody, **kwargs: Any) -> SimulatorTrajectory :classmethod: Create a SimulatorTrajectory from a RigidBody instance. :param rigid_body: The RigidBody instance to create the SimulatorTrajectory from. :param \*\*kwargs: Additional keyword arguments to pass to the :param SimulatorTrajectory constructor.: :returns: A SimulatorTrajectory instance. .. py:method:: with_state_metadata(**metadata: dict[str, mythos.utils.types.ARR_OR_SCALAR]) -> SimulatorTrajectory Set the same metadata for all states in the trajectory. .. py:method:: filter(filter_fn: collections.abc.Callable[[Any], bool]) -> SimulatorTrajectory Filter the trajectory based on metadata. :param filter_fn: A function that takes in metadata tree and returns a boolean array of length equal to the number of states, indicating which states to keep. :returns: A new SimulatorTrajectory with only the states that pass the filter. .. py:method:: slice(key: int | slice | jax.numpy.ndarray | list) -> SimulatorTrajectory Slice the trajectory. .. py:method:: length() -> int Return the length of the trajectory. Note, that this may have been more natural to implement as the built-in __len__ method. However, the chex.dataclass decorator overrides that method to be compatabile with the abc.Mapping interface See here: https://github.com/google-deepmind/chex/blob/8af2c9e8a19f3a57d9bd283c2a34148aef952f60/chex/_src/dataclass.py#L50 .. py:method:: __add__(other: SimulatorTrajectory) -> SimulatorTrajectory Concatenate two trajectories. .. py:method:: to_file(filepath: pathlib.Path, box_size: mythos.utils.types.Vector3D = (0, 0, 0)) -> None Write the trajectory to an oxDNA file. Note that the SimulatorTrajectory does not store several of the fields necessary to fully reconstruct an oxDNA trajectory file (e.g. times, box size, velocities, angular momenta, and energies). Thus, times are filled with a monotonic sequence, while the rest of these fields are filled with 0's. The resultant file can be used for inspection and visualization of non-time-dependent state-by-state spatial information only. :param filepath: The path to write the trajectory file to. :param box_size: The box size in 3 dimensions to write to the file. defaults to (0,0,0). .. py:function:: _merge_metadata(left: dict[str, jax.numpy.ndarray] | None, len_left: int, right: dict[str, jax.numpy.ndarray] | None, len_right: int) -> dict[str, jax.numpy.ndarray] | None Merge two metadata dictionaries for SimulatorTrajectory concatenation. If a key is missing in one of the dictionaries, it is filled with NaNs of the same shape (excluding leading axis which is num_states) as the corresponding array in the other dictionary. If a key is present in both dictionaries the shapes must be consistent beyond the leading axis.