def test_hoomdsimulation_restart(self): import gsd.hoomd import hoomd from foyer.forcefield import Forcefield from mbuild.formats.hoomd_simulation import create_hoomd_simulation box = mb.Compound() box.add(mb.Compound(name="Ar", pos=[1, 1, 1])) box.add(mb.Compound(name="Ar", pos=[1, 1, 1])) ff = Forcefield(forcefield_files=get_fn("lj.xml")) structure = ff.apply(box) structure.box = [10, 10, 10, 90, 90, 90] sim = hoomd.context.SimulationContext() with sim: hoomd_obj, ref_vals = create_hoomd_simulation( structure, 2.5, restart=get_fn("restart.gsd")) sim_forces = hoomd.context.current.forces pair_force = import_("hoomd.md.pair") assert isinstance(sim_forces[0], pair_force.lj) snap = hoomd_obj[0] with gsd.hoomd.open(get_fn("restart.gsd")) as f: rsnap = f[0] assert np.array_equal(snap.particles.position, rsnap.particles.position)
def test_structure_to_hoomdsimulation(self, ethane): import hoomd from foyer.forcefield import Forcefield from mbuild.formats.hoomd_simulation import create_hoomd_simulation ff = Forcefield(name="oplsaa") structure = ff.apply(ethane) sim = hoomd.context.SimulationContext() with sim: create_hoomd_simulation(structure, 2.5) sim_forces = hoomd.context.current.forces pair_force = import_("hoomd.md.pair") charge_force = import_("hoomd.md.charge") special_pair_force = import_("hoomd.md.special_pair") bond_force = import_("hoomd.md.bond") angle_force = import_("hoomd.md.angle") dihedral_force = import_("hoomd.md.dihedral") assert isinstance(sim_forces[0], pair_force.lj) assert isinstance(sim_forces[1], charge_force.pppm) assert isinstance(sim_forces[2], pair_force.ewald) assert isinstance(sim_forces[3], special_pair_force.lj) assert isinstance(sim_forces[4], special_pair_force.coulomb) assert isinstance(sim_forces[5], bond_force.harmonic) assert isinstance(sim_forces[6], angle_force.harmonic) assert isinstance(sim_forces[7], dihedral_force.opls)
def test_param_structure_to_snapshot(self, ethane): from foyer.forcefield import Forcefield from mbuild.formats.hoomd_snapshot import to_hoomdsnapshot ff = Forcefield(name="oplsaa") structure = ff.apply(ethane) snap, _ = to_hoomdsnapshot(structure) assert snap.particles.N == 8 assert snap.bonds.N == 7 assert snap.angles.N == 12 assert snap.dihedrals.N == 9 assert snap.pairs.N == 9
def test_lj_to_hoomd_forcefield(self): import hoomd from foyer.forcefield import Forcefield from mbuild.formats.hoomd_forcefield import create_hoomd_forcefield box = mb.Compound() box.add(mb.Compound(name="Ar", pos=[1, 1, 1])) box.add(mb.Compound(name="Ar", pos=[1, 1, 1])) ff = Forcefield(forcefield_files=get_fn("lj.xml")) structure = ff.apply(box) structure.box = [10, 10, 10, 90, 90, 90] snapshot, forces, ref_values = create_hoomd_forcefield(structure, 2.5) assert isinstance(forces[0], hoomd.md.pair.LJ)
def test_hexa_coordinated(): ff = Forcefield(forcefield_files=get_fn('pf6.xml')) mol2 = pmd.load_file(get_fn('pf6.mol2'), structure=True) pf6 = ff.apply(mol2) types = [a.type for a in pf6.atoms] assert types.count('P') == 1 assert types.count('F1') == 2 assert types.count('F2') == 2 assert types.count('F3') == 2 assert len(pf6.bonds) == 6 assert all(bond.type for bond in pf6.bonds) assert len(pf6.angles) == 15 assert all(angle.type for angle in pf6.angles)
def test_hexa_coordinated(self): ff = Forcefield(forcefield_files=get_fn("pf6.xml")) mol2 = pmd.load_file(get_fn("pf6.mol2"), structure=True) pf6 = ff.apply(mol2) types = [a.type for a in pf6.atoms] assert types.count("P") == 1 assert types.count("F1") == 2 assert types.count("F2") == 2 assert types.count("F3") == 2 assert len(pf6.bonds) == 6 assert all(bond.type for bond in pf6.bonds) assert len(pf6.angles) == 15 assert all(angle.type for angle in pf6.angles)
def test_structure_to_hoomd_forcefield(self, ethane): import hoomd from foyer.forcefield import Forcefield from mbuild.formats.hoomd_forcefield import create_hoomd_forcefield ff = Forcefield(name="oplsaa") structure = ff.apply(ethane) snapshot, forces, ref_values = create_hoomd_forcefield(structure, 2.5) assert isinstance(forces[0], hoomd.md.pair.LJ) assert isinstance(forces[1], hoomd.md.pair.Ewald) assert isinstance(forces[2], hoomd.md.long_range.pppm.Coulomb) assert isinstance(forces[3], hoomd.md.special_pair.LJ) assert isinstance(forces[4], hoomd.md.special_pair.Coulomb) assert isinstance(forces[5], hoomd.md.bond.Harmonic) assert isinstance(forces[6], hoomd.md.angle.Harmonic) assert isinstance(forces[7], hoomd.md.dihedral.OPLS)
def test_lj_to_hoomdsimulation(self): import hoomd from foyer.forcefield import Forcefield from mbuild.formats.hoomd_simulation import create_hoomd_simulation box = mb.Compound() box.add(mb.Compound(name="Ar", pos=[1, 1, 1])) box.add(mb.Compound(name="Ar", pos=[1, 1, 1])) ff = Forcefield(forcefield_files=get_fn("lj.xml")) structure = ff.apply(box) structure.box = [10, 10, 10, 90, 90, 90] sim = hoomd.context.SimulationContext() with sim: create_hoomd_simulation(structure, 2.5) sim_forces = hoomd.context.current.forces pair_force = import_("hoomd.md.pair") assert isinstance(sim_forces[0], pair_force.lj)