Esempio n. 1
0
def test_volume(base_box):
    assert isclose(base_box.volume, np.product(base_box.L))
    for L in np.linspace(1, 10, 10):
        box = Box.cube(L)
        assert isclose(box.volume, L**3)
        box = Box(L, L + 1, L + 2)
        assert isclose(box.volume, L * (L + 1) * (L + 2))
Esempio n. 2
0
    def box(self):
        """hoomd.Box: The current simulation box.

        Editing the box directly is not allowed. For example
        ``state.box.scale(1.1)`` would not scale the state's box. To set the
        state's box to a new box ``state.box = new_box`` must be used.
        """
        b = Box._from_cpp(self._cpp_sys_def.getParticleData().getGlobalBox())
        return Box.from_box(b)
Esempio n. 3
0
    def box(self):
        """hoomd.Box: A copy of the current simulation box.

        Note:
            The `box` property cannot be set. Call `set_box` to set a new
            simulation box.
        """
        b = Box._from_cpp(self._cpp_sys_def.getParticleData().getGlobalBox())
        return Box.from_box(b)
Esempio n. 4
0
def test_lattice_vectors(base_box):
    expected_vectors = np.array([[1, 0, 0], [2, 2, 0], [6, 9, 3]],
                                dtype=np.float64)
    assert np.allclose(base_box.lattice_vectors, expected_vectors)
    box = Box.cube(4)
    lattice_vectors = np.array([[4, 0, 0], [0, 4, 0], [0, 0, 4]])
    assert np.allclose(box.lattice_vectors, lattice_vectors)
Esempio n. 5
0
    def set_box(self, box):
        """Set a new simulation box.

        Args:
            box (Box): New simulation box.

        Note:
            All particles must be inside the new box. `set_box` does not change
            any particle properties.

        See Also:
            `hoomd.update.BoxResize.update`
        """
        if self._in_context_manager:
            raise RuntimeError(
                "Cannot set system box within local snapshot context manager.")
        try:
            box = Box.from_box(box)
        except Exception:
            raise ValueError('{} is not convertable to hoomd.Box using '
                             'hoomd.Box.from_box'.format(box))

        if box.dimensions != self._cpp_sys_def.getNDimensions():
            self._simulation.device._cpp_msg.warning(
                "Box changing dimensions from {} to {}."
                "".format(self._cpp_sys_def.getNDimensions(), box.dimensions))
            self._cpp_sys_def.setNDimensions(box.dimensions)
        self._cpp_sys_def.getParticleData().setGlobalBox(box._cpp_obj)
Esempio n. 6
0
def test_from_matrix(new_box_matrix_dict):
    box = Box.from_matrix(new_box_matrix_dict['matrix'])
    assert np.allclose(new_box_matrix_dict['matrix'], box.matrix)
    assert np.allclose(box.L, [new_box_matrix_dict['Lx'],
                               new_box_matrix_dict['Ly'],
                               new_box_matrix_dict['Lz']])
    assert np.allclose(box.tilts, [new_box_matrix_dict['xy'],
                                   new_box_matrix_dict['xz'],
                                   new_box_matrix_dict['yz']])
Esempio n. 7
0
    def box(self, value):
        if self._in_context_manager:
            raise RuntimeError(
                "Cannot set system box within local snapshot context manager.")
        try:
            value = Box.from_box(value)
        except Exception:
            raise ValueError('{} is not convertable to hoomd.Box using '
                             'hoomd.Box.from_box'.format(value))

        if value.dimensions != self._cpp_sys_def.getNDimensions():
            self._simulation.device._cpp_msg.warning(
                "Box changing dimensions from {} to {}."
                "".format(self._cpp_sys_def.getNDimensions(),
                          value.dimensions))
            self._cpp_sys_def.setNDimensions(value.dimensions)
        self._cpp_sys_def.getParticleData().setGlobalBox(value._cpp_obj)
Esempio n. 8
0
    def get_box(self, timestep):
        """Get the box for a given timestep.

        Args:
            timestep (int): The timestep to use for determining the resized
                box.

        Returns:
            Box: The box used at the given timestep.
        """
        if self._attached:
            timestep = int(timestep)
            if timestep < 0:
                raise ValueError("Timestep must be a non-negative integer.")
            return Box._from_cpp(self._cpp_obj.get_current_box(timestep))
        else:
            return None
Esempio n. 9
0
def base_box(box_dict):
    return Box(**box_dict)
Esempio n. 10
0
def test_neq(base_box, box_dict):
    box2 = Box(**box_dict)
    assert not base_box != box2
    box2.Lx = 2
    assert base_box != box2
Esempio n. 11
0
def test_square():
    for L in np.linspace(1, 100, 10):
        box = Box.square(L)
        assert all(box.L == [L, L, 0])
        assert box.Lx == box.Ly == L and box.Lz == 0
Esempio n. 12
0
def test_base_constructor(box_dict):
    box = Box(**box_dict)
    for key in box_dict:
        assert getattr(box, key) == box_dict[key]
Esempio n. 13
0
def test_cube():
    for L in np.linspace(1, 100, 10):
        box = Box.cube(L)
        assert all(box.L == L)
        assert box.Lx == box.Ly == box.Lz == L