Esempio n. 1
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
Esempio n. 2
0
def test_thermalise(snapshot_from_none):
    sim_params = snapshot_from_none["sim_params"]
    snapshot = snapshot_from_none["snapshot"]
    thermal_snap = thermalise(snapshot, sim_params)

    num_mols = get_num_mols(thermal_snap)
    mass = sim_params.molecule.mass
    computed_trans_ke = (0.5 * mass * np.sum(
        np.square(thermal_snap.particles.velocity[:num_mols]))) / num_mols
    thermodynamic_ke = sim_params.molecule.dimensions * 0.5 * sim_params.temperature
    assert np.isclose(computed_trans_ke, thermodynamic_ke, rtol=0.2)
Esempio n. 3
0
def test_randomise_seed_different(snapshot_params):
    num_mols = get_num_mols(snapshot_params["snapshot"])
    snap1 = randomise_momenta(**snapshot_params, random_seed=0)
    snap2 = randomise_momenta(**snapshot_params, random_seed=1)
    angmom_similarity = np.sum(
        np.square(snap1.particles.angmom[:num_mols] -
                  snap2.particles.angmom[:num_mols]),
        axis=1,
    )
    velocity_similarity = np.sum(
        np.square(snap1.particles.velocity[:num_mols] -
                  snap2.particles.velocity[:num_mols]),
        axis=1,
    )
    if np.any(snapshot_params["sim_params"].molecule.moment_inertia != 0):
        assert np.all(angmom_similarity > 0)
    assert np.all(velocity_similarity > 0)
Esempio n. 4
0
def test_moment_inertia(mol_params, scaling_factor):
    """Ensure moment of inertia is set correctly in setup."""
    init_mol = np.array(mol_params.molecule.moment_inertia)
    logger.debug("Moment Inertia before scaling: %s", init_mol)
    init_mol *= scaling_factor
    logger.debug("Moment Inertia after scaling: %s", init_mol)
    with mol_params.temp_context(moment_inertia_scale=scaling_factor):
        snapshot = init_from_none(mol_params)
        context = hoomd.context.initialize(mol_params.hoomd_args)
        snapshot = initialise_snapshot(snapshot, context,
                                       mol_params).take_snapshot()
        num_mols = get_num_mols(snapshot)
        logger.debug("Simulation Moment Inertia: %s",
                     snapshot.particles.moment_inertia[0])
        logger.debug("Intended Moment Inertia: %s", init_mol)
        diff = snapshot.particles.moment_inertia[:num_mols] - init_mol
        assert_allclose(diff, 0, atol=1e-1)
Esempio n. 5
0
def test_randomise_iteration_id(snapshot_params, seed):
    snap1 = randomise_momenta(**snapshot_params)
    with snapshot_params["sim_params"].temp_context(iteration_id=seed):
        snap2 = randomise_momenta(**snapshot_params)
    num_mols = get_num_mols(snapshot_params["snapshot"])
    angmom_similarity = np.sum(
        np.square(snap1.particles.angmom[:num_mols] -
                  snap2.particles.angmom[:num_mols]),
        axis=1,
    )
    velocity_similarity = np.sum(
        np.square(snap1.particles.velocity[:num_mols] -
                  snap2.particles.velocity[:num_mols]),
        axis=1,
    )
    if np.any(snapshot_params["sim_params"].molecule.moment_inertia != 0):
        print("Molecule: ", snapshot_params["sim_params"].molecule)
        assert np.all(angmom_similarity > 0)
    assert np.all(velocity_similarity > 0)
Esempio n. 6
0
def test_initialise_randomise(mol_params):
    snapshot = hoomd.data.gsd_snapshot("test/data/Trimer-13.50-3.00.gsd")
    context = hoomd.context.initialize(mol_params.hoomd_args)
    num_mols = get_num_mols(snapshot)
    with mol_params.temp_context(iteration_id=1):
        sys = initialise_snapshot(snapshot, context, mol_params)
        assert isinstance(sys, hoomd.data.system_data)
        snap = sys.take_snapshot()
    angmom_similarity = np.sum(
        np.square(snap.particles.angmom[:num_mols] -
                  snapshot.particles.angmom[:num_mols]),
        axis=1,
    )
    velocity_similarity = np.sum(
        np.square(snap.particles.velocity[:num_mols] -
                  snapshot.particles.velocity[:num_mols]),
        axis=1,
    )
    if np.any(mol_params.molecule.moment_inertia != 0):
        assert np.all(angmom_similarity > 0)
    assert np.all(velocity_similarity > 0)
Esempio n. 7
0
def test_init_from_file(snapshot_params):
    sim_params = snapshot_params["sim_params"]
    snapshot = snapshot_params["snapshot"]
    filename = sim_params.output / "testfile.gsd"
    num_mols = get_num_mols(snapshot)

    context = hoomd.context.initialize(args=sim_params.hoomd_args)
    initialise_snapshot(snapshot, context, sim_params)
    with context:
        if sim_params.molecule.rigid:
            group = hoomd.group.rigid_center()
        else:
            group = hoomd.group.all()
        dump_frame(group, filename)

    snap_file = init_from_file(filename, sim_params.molecule,
                               sim_params.hoomd_args)
    assert snap_file.particles.types == sim_params.molecule.get_types()
    assert snap_file.particles.N == snapshot.particles.N
    assert np.all(
        snap_file.particles.mass[:num_mols] == sim_params.molecule.mass)
    assert_allclose(snap_file.particles.position[:num_mols],
                    snapshot.particles.position[:num_mols])
Esempio n. 8
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)
Esempio n. 9
0
def test_molecule_masses(snapshot_from_none):
    snap = snapshot_from_none["snapshot"]
    molecule = snapshot_from_none["sim_params"].molecule
    num_mols = get_num_mols(snap)
    assert np.all(snap.particles.mass[:num_mols] == molecule.mass)
 def num_mols(self):
     return get_num_mols(self.snapshot)