Exemple #1
0
def test_orthorhombic_equil(crystal_params):
    """Ensure the equilibration is close to initialisation."""
    snap_min = init_from_crystal(crystal_params)
    snap_ortho = make_orthorhombic(snap_min)
    snap_equil = equilibrate(snap_ortho, crystal_params, equil_type="crystal")

    # Simulation box within 20% of initialisation
    for attribute in ["Lx", "Ly", "Lz", "xy", "xz", "yz"]:
        assert np.isclose(
            getattr(snap_ortho.box, attribute),
            getattr(snap_equil.box, attribute),
            rtol=0.2,
        )
Exemple #2
0
def test_orthorhombic_sims(cell_dimensions, crystal_params):
    """Test the initialisation from a crystal unit cell.

    This also ensures there is no unusual things going on with the calculation
    of the orthorhombic unit cell.
    """
    # Multiple of 6 works nicely with the p2 crystal
    cell_dimensions = cell_dimensions * 6
    with crystal_params.temp_context(cell_dimensions=cell_dimensions):
        snapshot = init_from_crystal(crystal_params)
        snapshot = equilibrate(snapshot, crystal_params, equil_type="crystal")
    snapshot = make_orthorhombic(snapshot)
    temp_context = hoomd.context.initialize(crystal_params.hoomd_args)
    production(snapshot, temp_context, crystal_params, dynamics=False)
Exemple #3
0
def test_minimize_snapshot(crystal_params, ensemble):
    snap = init_from_crystal(crystal_params,
                             equilibration=False,
                             minimize=False)
    min_snap = minimize_snapshot(snap, crystal_params, ensemble)
    if ensemble == "NPH":
        rtol = 0.2
    else:
        rtol = 0
    assert_allclose(snap.box.Lx, min_snap.box.Lx, rtol=rtol)
    assert_allclose(snap.box.Ly, min_snap.box.Ly, rtol=rtol)
    assert_allclose(snap.box.Lz, min_snap.box.Lz, rtol=rtol)
    assert_allclose(snap.box.xy, min_snap.box.xy, rtol=rtol)
    assert_allclose(snap.box.xz, min_snap.box.xz, rtol=rtol)
    assert_allclose(snap.box.yz, min_snap.box.yz, rtol=rtol)
Exemple #4
0
def test_orthorhombic_init(crystal_params, cell_dimensions):
    """Ensure orthorhombic cell initialises correctly."""
    snap = init_from_crystal(crystal_params)
    snap_ortho = make_orthorhombic(snap)
    assert np.all(snap_ortho.particles.position == snap.particles.position)
    assert np.all(
        snap_ortho.particles.position[:, 0] < snap_ortho.box.Lx / 2.0)
    assert np.all(
        snap_ortho.particles.position[:, 0] >= -snap_ortho.box.Lx / 2.0)
    assert np.all(
        snap_ortho.particles.position[:, 1] < snap_ortho.box.Ly / 2.0)
    assert np.all(
        snap_ortho.particles.position[:, 1] >= -snap_ortho.box.Ly / 2.0)
    assert snap_ortho.box.xy == 0
    assert snap_ortho.box.xz == 0
    assert snap_ortho.box.yz == 0
Exemple #5
0
def test_dump_mols(crystal_params, equil_type):
    """Ensure the equilibration is close to initialisation."""
    # Initialisation of snapshot
    snap_init = init_from_crystal(crystal_params)
    snap_init_mols = get_num_mols(snap_init)

    # Equilibration
    snap_equil = equilibrate(snap_init, crystal_params, equil_type)
    snap_equil_mols = get_num_mols(snap_equil)

    snap_out = init_from_file(crystal_params.outfile, crystal_params.molecule,
                              crystal_params.hoomd_args)
    snap_out_mols = get_num_mols(snap_out)

    assert snap_init_mols == snap_equil_mols
    assert snap_init_mols == snap_out_mols
Exemple #6
0
def test_init_crystal(crystal_params):
    """Test the initialisation of all crystals."""
    snap = init_from_crystal(crystal_params)
    Nx, Ny, _ = crystal_params.cell_dimensions
    unitcell = crystal_params.crystal.cell_matrix
    logger.debug("Unitcell: %s", unitcell)
    Lx = np.linalg.norm(np.dot(unitcell, np.array([1, 0, 0])))
    Ly = np.linalg.norm(np.dot(unitcell, np.array([0, 1, 0])))

    assert Lx > 0
    assert Ly > 0
    assert Nx > 0
    assert Ny > 0

    # Simulation box within 20% of initialisation
    assert_allclose(snap.box.Lx, Lx * Nx, rtol=0.2)
    assert_allclose(snap.box.Ly, Ly * Ny, rtol=0.2)
Exemple #7
0
def test_trimerPg_init_position():
    sim_params = SimulationParams(crystal=TrimerPg(), cell_dimensions=1)
    snap = init_from_crystal(sim_params, equilibration=False, minimize=False)
    manual = np.array(
        [
            [-1.088_551_4, 1.025_773_4, -0.5],
            [1.088_551_4, -1.025_773_4, -0.5],
            [-1.3476, 0.816_000_04, -0.5],
            [-0.874_034_4, -0.746_311_66, -0.5],
            [-0.414_019_6, 0.457_632_04, -0.5],
            [1.3476, -0.815_999_9, -0.5],
            [0.874_034_64, 0.746_311_8, -0.5],
            [0.414_019_44, -0.457_632_24, -0.5],
        ],
        dtype=np.float32,
    )
    assert_allclose(snap.particles.position, manual)
def setup_thermo(request):
    """Test the initialisation of all crystals."""
    with TemporaryDirectory() as tmp_dir:
        output_dir = Path(tmp_dir) / "output"
        output_dir.mkdir(exist_ok=True)
        sim_params = SimulationParams(
            temperature=0.4,
            pressure=1.0,
            num_steps=100,
            crystal=request.param(),
            output=output_dir,
            cell_dimensions=(10, 12, 10),
            outfile=output_dir / "test.gsd",
            hoomd_args="--mode=cpu --notice-level=0",
        )
        context = hoomd.context.initialize(args=sim_params.hoomd_args)
        sys = initialise_snapshot(
            snapshot=init_from_crystal(sim_params),
            context=context,
            sim_params=sim_params,
            thermalisation=True,
        )
        with context:
            group = get_group(sys, sim_params)
            integrator = set_integrator(sim_params, group)
            thermo_log = hoomd.analyze.log(
                None,
                quantities=[
                    "translational_kinetic_energy",
                    "rotational_kinetic_energy",
                    "temperature",
                ],
                period=1,
            )

            hoomd.run(1)
            snap = sys.take_snapshot()
        yield SimStatus(
            sim_params=sim_params,
            snapshot=snap,
            context=context,
            logger=thermo_log,
            integrator=integrator,
            system=sys,
        )
Exemple #9
0
def test_equilibrate(crystal_params, equil_type):
    """Ensure the equilibration is close to initialisation."""
    # Initialisation of snapshot
    snap_min = init_from_crystal(crystal_params)

    # Equilibration
    snapshot = equilibrate(snap_min, crystal_params, equil_type)

    # Simulation box within 10% of initialisation
    for attribute in ["Lx", "Ly", "Lz", "xy", "xz", "yz"]:
        assert np.isclose(
            getattr(snap_min.box, attribute),
            getattr(snapshot.box, attribute),
            rtol=0.20,
        )
    if equil_type in ["liquid", "interface"]:
        assert snapshot.box.xy == 0
        assert snapshot.box.xz == 0
        assert snapshot.box.yz == 0
Exemple #10
0
def test_init_crystal_position(crystal_params):
    if isinstance(crystal_params.crystal, (TrimerP2)):
        return
    with crystal_params.temp_context(cell_dimensions=1):
        snap = init_from_crystal(crystal_params,
                                 equilibration=False,
                                 minimize=False)

        crys = crystal_params.crystal

        num_mols = get_num_mols(snap)
        mol_positions = crystal_params.molecule.get_relative_positions()
        positions = np.concatenate([
            pos + rowan.rotate(orient, mol_positions)
            for pos, orient in zip(crys.positions, crys.get_orientations())
        ])
        box = np.array([snap.box.Lx, snap.box.Ly, snap.box.Lz])
        if crys.molecule.rigid:
            sim_pos = snap.particles.position[num_mols:] % box
        else:
            sim_pos = snap.particles.position % box
        init_pos = positions % box
        assert_allclose(sim_pos, init_pos)