示例#1
0
 def test_lj_energy(self):
     model = build_examples.LJModel(32)
     tfcompute = htf.tfcompute(model)
     N = 3 * 3
     NN = N - 1
     T = 10
     rcut = 5.0
     system = hoomd.init.create_lattice(
         unitcell=hoomd.lattice.sq(a=4.0),
         n=[3, 3])
     nlist = hoomd.md.nlist.cell(check_period=1)
     hoomd.md.integrate.mode_standard(dt=0.001)
     hoomd.md.integrate.nve(group=hoomd.group.all(
     )).randomize_velocities(seed=1, kT=0.8)
     log = hoomd.analyze.log(filename=None,
                             quantities=['potential_energy',
                                         'kinetic_energy'], period=1)
     tfcompute.attach(nlist, r_cut=rcut)
     energy = []
     for i in range(T):
         hoomd.run(250)
         energy.append(log.query('potential_energy'
                                 ) + log.query('kinetic_energy'))
         if i > 1:
             np.testing.assert_allclose(energy[-1],
                                        energy[-2], atol=1e-3)
示例#2
0
 def test_force_output(self):
     Ne = 5
     c = hoomd.context.initialize('')
     model = build_examples.LJModel(32, output_forces=False)
     model.compile(loss='MeanSquaredError')
     tfcompute = htf.tfcompute(model)
     rcut = 3.0
     system = hoomd.init.create_lattice(
         unitcell=hoomd.lattice.sq(a=2.0),
         n=[Ne, Ne])
     c.sorter.disable()
     nlist = hoomd.md.nlist.cell(check_period=1)
     hoomd.md.integrate.mode_standard(dt=0.01)
     lj = hoomd.md.pair.lj(r_cut=rcut, nlist=nlist)
     lj.pair_coeff.set('A', 'A', epsilon=1.0, sigma=1.0)
     lj2 = hoomd.md.pair.lj(r_cut=rcut, nlist=nlist)
     lj2.pair_coeff.set('A', 'A', epsilon=4.0, sigma=0.8)
     hoomd.md.integrate.nve(group=hoomd.group.all(
     )).randomize_velocities(seed=1, kT=0.8)
     tfcompute.attach(nlist, train=True, r_cut=rcut, period=100)
     tfcompute.set_reference_forces(lj)
     hoomd.run(300)
     error = model.metrics[0].result().numpy()
     assert abs(error) < 1e-5
     # now check difference between particle forces and
     # forces from htf
     lj_forces = np.array([lj.forces[j].force for j in range(Ne**2)])
     lj_energy = np.array([lj.forces[j].energy for j in range(Ne**2)])
     np.testing.assert_allclose(tfcompute.get_forces_array(
     )[:, :3], lj_forces)
     np.testing.assert_allclose(tfcompute.get_forces_array(
     )[:, 3], lj_energy)
示例#3
0
 def test_lj_forces(self):
     model = build_examples.LJModel(32)
     tfcompute = htf.tfcompute(model)
     T = 10
     N = 5 * 5
     rcut = 5.0
     system = hoomd.init.create_lattice(
         unitcell=hoomd.lattice.sq(a=3.0),
         n=[5, 5])
     nlist = hoomd.md.nlist.cell(check_period=1)
     hoomd.md.integrate.mode_standard(dt=0.005)
     hoomd.md.integrate.nvt(group=hoomd.group.all(),
                            kT=1, tau=0.2
                            ).randomize_velocities(seed=1)
     tfcompute.attach(nlist, r_cut=rcut)
     hoomd.run(20)
     tf_forces = []
     for i in range(T):
         hoomd.run(1)
         snapshot = system.take_snapshot()
         tf_forces.append([system.particles[j].net_force
                           for j in range(N)])
     tf_forces = np.array(tf_forces)
     # now run with stock lj
     hoomd.context.initialize('')
     system = hoomd.init.create_lattice(
         unitcell=hoomd.lattice.sq(a=3.0),
         n=[5, 5])
     nlist = hoomd.md.nlist.cell(check_period=1)
     hoomd.md.integrate.mode_standard(dt=0.005)
     hoomd.md.integrate.nvt(group=hoomd.group.all(), kT=1, tau=0.2
                            ).randomize_velocities(seed=1)
     lj = hoomd.md.pair.lj(r_cut=5.0, nlist=nlist)
     lj.pair_coeff.set('A', 'A', epsilon=1.0, sigma=1.0)
     hoomd.run(20)
     lj_forces = []
     for i in range(T):
         hoomd.run(1)
         snapshot = system.take_snapshot()
         lj_forces.append([system.particles[j].net_force for j in range(N)])
     lj_forces = np.array(lj_forces)
     for i in range(T):
         for j in range(N):
             np.testing.assert_allclose(tf_forces[i, j],
                                        lj_forces[i, j], atol=1e-5)
             # make sure we wrote test to have non-zero forces
             assert np.sum(
                 lj_forces[i, j]**2) > 1e-4**2, 'Forces are too low to assess!'
示例#4
0
 def test_overflow(self):
     '''Use too small neighbor list and ensure error is thrown
     '''
     N = 8 * 8
     model = build_examples.LJModel(4, check_nlist=True)
     tfcompute = htf.tfcompute(model)
     T = 10
     rcut = 10.0
     system = hoomd.init.create_lattice(
         unitcell=hoomd.lattice.sq(a=4.0),
         n=[8, 8])
     nlist = hoomd.md.nlist.cell(check_period=1)
     hoomd.md.integrate.mode_standard(dt=0.005)
     hoomd.md.integrate.nvt(group=hoomd.group.all(),
                            kT=1, tau=0.2
                            ).randomize_velocities(seed=1)
     tfcompute.attach(nlist, r_cut=rcut)
     with self.assertRaises(tf.errors.InvalidArgumentError):
         hoomd.run(2)
示例#5
0
def run_tf_lj(N, T):
    model = build_examples.LJModel(256)
    tfcompute = hoomd.htf.tfcompute(model)
    rcut = 5.0
    system = init.create_lattice(unitcell=hoomd.lattice.sq(a=4.0),
                                 n=[np.sqrt(N).astype(np.int),
                                    np.sqrt(N).astype(np.int)])
    nlist = md.nlist.cell()
    md.integrate.mode_standard(dt=0.005)
    md.integrate.nvt(group=hoomd.group.all(),
                     kT=1, tau=0.2).randomize_velocities(seed=1)
    tfcompute.attach(nlist, r_cut=rcut)
    hoomd.run(2)
    tf_forces = []
    for i in range(T):
        hoomd.run(1)
        snapshot = system.take_snapshot()
        tf_forces.append([system.particles[j].net_force for j in range(N)])
    tf_forces = np.array(tf_forces)
    return tf_forces
示例#6
0
 def test_nlist_count(self):
     '''Make sure nlist is full, not half
     '''
     model = build_examples.LJModel(32)
     tfcompute = htf.tfcompute(model)
     N = 3 * 3
     NN = N - 1
     T = 10
     rcut = 5.0
     system = hoomd.init.create_lattice(
         unitcell=hoomd.lattice.sq(a=4.0),
         n=[3, 3])
     nlist = hoomd.md.nlist.cell()
     hoomd.md.integrate.mode_standard(dt=0.001)
     hoomd.md.integrate.nve(group=hoomd.group.all(
     )).randomize_velocities(seed=1, kT=0.8)
     tfcompute.attach(nlist, r_cut=rcut)
     hoomd.run(1)  # in lattice, should have 4 neighbors
     nl = tfcompute.get_nlist_array()
     ncount = np.sum(np.sum(nl**2, axis=2) > 0.1, axis=1)
     self.assertEqual(np.min(ncount), 4)
示例#7
0
 def test_compute_pairwise(self):
     model = build_examples.LJModel(4)
     r = np.linspace(0.5, 1.5, 5)
     output = hoomd.htf.compute_pairwise(model, r)
     np.testing.assert_equal(output[0].shape[0], len(r),
                             'Pairwise not calculated correctly')