def create_state_from_snapshot(self, snapshot): """Create the simulations state from a `Snapshot`. Args: snapshot (Snapshot or gsd.hoomd.Snapshot): Snapshot to initialize the state from. A `gsd.hoomd.Snapshot` will first be converted to a `hoomd.Snapshot`. When `timestep` is `None` before calling, `create_state_from_snapshot` sets `timestep` to 0. """ if self.state is not None: raise RuntimeError("Cannot initialize more than once\n") if isinstance(snapshot, Snapshot): # snapshot is hoomd.Snapshot self._state = State(self, snapshot) elif _match_class_path(snapshot, 'gsd.hoomd.Snapshot'): # snapshot is gsd.hoomd.Snapshot snapshot = Snapshot.from_gsd_snapshot(snapshot, self._device.communicator) self._state = State(self, snapshot) else: raise TypeError( "Snapshot must be a hoomd.Snapshot or gsd.hoomd.Snapshot.") step = 0 if self.timestep is not None: step = self.timestep self._init_system(step)
def create_state_from_snapshot(self, snapshot, domain_decomposition=(None, None, None)): """Create the simulation state from a `Snapshot`. Args: snapshot (Snapshot or gsd.hoomd.Snapshot): Snapshot to initialize the state from. A `gsd.hoomd.Snapshot` will first be converted to a `hoomd.Snapshot`. domain_decomposition (tuple): Choose how to distribute the state across MPI ranks with domain decomposition. Provide a tuple of 3 integers indicating the number of evenly spaced domains in the x, y, and z directions (e.g. ``(8,4,2)``). Provide a tuple of 3 lists of floats to set the fraction of the simulation box to include in each domain. The sum of each list of floats must be 1.0 (e.g. ``([0.25, 0.75], [0.2, 0.8], [1.0])``). When `timestep` is `None` before calling, `create_state_from_snapshot` sets `timestep` to 0. Note: Set any or all of the ``domain_decomposition`` tuple elements to `None` and `create_state_from_gsd` will select a value that minimizes the surface area between the domains (e.g. ``(2,None,None)``). The domains are spaced evenly along each automatically selected direction. The default value of ``(None, None, None)`` will automatically select the number of domains in all directions. See Also: `State.get_snapshot` `State.set_snapshot` """ if self._state is not None: raise RuntimeError("Cannot initialize more than once\n") if isinstance(snapshot, Snapshot): # snapshot is hoomd.Snapshot self._state = State(self, snapshot, domain_decomposition) elif _match_class_path(snapshot, 'gsd.hoomd.Snapshot'): # snapshot is gsd.hoomd.Snapshot snapshot = Snapshot.from_gsd_snapshot(snapshot, self._device.communicator) self._state = State(self, snapshot, domain_decomposition) else: raise TypeError( "Snapshot must be a hoomd.Snapshot or gsd.hoomd.Snapshot.") step = 0 if self.timestep is not None: step = self.timestep self._init_system(step)
def create_state_from_gsd(self, filename, frame=-1): """Create the simulation state from a GSD file. Args: filename (str): GSD file to read frame (int): Index of the frame to read from the file. Negative values index back from the last frame in the file. """ if self.state is not None: raise RuntimeError("Cannot initialize more than once\n") filename = _hoomd.mpi_bcast_str(filename, self.device._cpp_exec_conf) # Grab snapshot and timestep reader = _hoomd.GSDReader(self.device._cpp_exec_conf, filename, abs(frame), frame < 0) snapshot = Snapshot._from_cpp_snapshot(reader.getSnapshot(), self.device.communicator) step = reader.getTimeStep() if self.timestep is None else self.timestep self._state = State(self, snapshot) reader.clearSnapshot() # Store System and Reader for Operations self._cpp_sys = _hoomd.System(self.state._cpp_sys_def, step) self._init_communicator() self.operations._store_reader(reader)
def create_state_from_snapshot(self, snapshot): """Create the simulations state from a `Snapshot`. Args: snapshot (Snapshot): Snapshot to initialize the state from. When `timestep` is `None` before calling, `create_state_from_snapshot` sets `timestep` to 0. Warning: *snapshot* must be a `hoomd.Snapshot`. Use `create_state_from_gsd` to read GSD files. `create_state_from_snapshot` does not support ``gsd.hoomd.Snapshot`` objects from the ``gsd`` Python package. """ if self.state is not None: raise RuntimeError("Cannot initialize more than once\n") self._state = State(self, snapshot) step = 0 if self.timestep is not None: step = self.timestep # Store System and Reader for Operations self._cpp_sys = _hoomd.System(self.state._cpp_sys_def, step) self._init_communicator()
def create_state_from_gsd(self, filename, frame=-1, domain_decomposition=(None, None, None)): """Create the simulation state from a GSD file. Args: filename (str): GSD file to read frame (int): Index of the frame to read from the file. Negative values index back from the last frame in the file. domain_decomposition (tuple): Choose how to distribute the state across MPI ranks with domain decomposition. Provide a tuple of 3 integers indicating the number of evenly spaced domains in the x, y, and z directions (e.g. ``(8,4,2)``). Provide a tuple of 3 lists of floats to set the fraction of the simulation box to include in each domain. The sum of each list of floats must be 1.0 (e.g. ``([0.25, 0.75], [0.2, 0.8], [1.0])``). When `timestep` is `None` before calling, `create_state_from_gsd` sets `timestep` to the value in the selected GSD frame in the file. Note: Set any or all of the ``domain_decomposition`` tuple elements to `None` and `create_state_from_gsd` will select a value that minimizes the surface area between the domains (e.g. ``(2,None,None)``). The domains are spaced evenly along each automatically selected direction. The default value of ``(None, None, None)`` will automatically select the number of domains in all directions. """ if self._state is not None: raise RuntimeError("Cannot initialize more than once\n") filename = _hoomd.mpi_bcast_str(filename, self.device._cpp_exec_conf) # Grab snapshot and timestep reader = _hoomd.GSDReader(self.device._cpp_exec_conf, filename, abs(frame), frame < 0) snapshot = Snapshot._from_cpp_snapshot(reader.getSnapshot(), self.device.communicator) step = reader.getTimeStep() if self.timestep is None else self.timestep self._state = State(self, snapshot, domain_decomposition) reader.clearSnapshot() self._init_system(step)