Esempio n. 1
0
    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)
Esempio n. 2
0
def test_from_gsd_snapshot_populated(s, device):
    if s.exists:
        s.configuration.box = [10, 12, 7, 0.1, 0.4, 0.2]
        for section in ('particles', 'bonds', 'angles', 'dihedrals',
                        'impropers', 'pairs'):
            setattr(getattr(s, section), 'N', 5)
            setattr(getattr(s, section), 'types', ['A', 'B'])

        for prop in ('angmom', 'body', 'charge', 'diameter', 'image', 'mass',
                     'moment_inertia', 'orientation', 'position', 'typeid',
                     'velocity'):
            attr = getattr(s.particles, prop)
            if attr.dtype == numpy.float64:
                attr[:] = numpy.random.rand(*attr.shape)
            else:
                attr[:] = numpy.random.randint(3, size=attr.shape)

        for section in ('bonds', 'angles', 'dihedrals', 'impropers', 'pairs'):
            for prop in ('group', 'typeid'):
                attr = getattr(getattr(s, section), prop)
                attr[:] = numpy.random.randint(3, size=attr.shape)

        s.constraints.N = 3
        for prop in ('group', 'value'):
            attr = getattr(s.constraints, prop)
            if attr.dtype == numpy.float64:
                attr[:] = numpy.random.rand(*attr.shape)
            else:
                attr[:] = numpy.random.randint(3, size=attr.shape)

    gsd_snap = make_gsd_snapshot(s)
    hoomd_snap = Snapshot.from_gsd_snapshot(gsd_snap, device.communicator)
    assert_equivalent_snapshots(gsd_snap, hoomd_snap)
Esempio n. 3
0
    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)
Esempio n. 4
0
def test_from_gsd_snapshot_empty(s, device):
    gsd_snap = make_gsd_snapshot(s)
    hoomd_snap = Snapshot.from_gsd_snapshot(gsd_snap, device.communicator)
    assert_equivalent_snapshots(gsd_snap, hoomd_snap)