Exemple #1
0
    def test_single_atom_batched(self):
        N = 3 * 3
        NN = N - 1
        rcut = 5.0
        system = hoomd.init.create_lattice(unitcell=hoomd.lattice.sq(a=4.0),
                                           n=[3, 3])

        mol_indices = htf.find_molecules(system)
        model = build_examples.LJMolModel(
            MN=1, mol_indices=mol_indices, nneighbor_cutoff=NN)
        tfcompute = htf.tfcompute(model)
        nlist = hoomd.md.nlist.cell()
        hoomd.md.integrate.mode_standard(dt=0.005)
        hoomd.md.integrate.nvt(group=hoomd.group.all(), kT=1, tau=0.2)
        with self.assertRaises(ValueError):
            tfcompute.attach(nlist, r_cut=rcut, batch_size=3)
Exemple #2
0
    def test_single_atom(self):
        N = 3 * 3
        NN = N - 1
        rcut = 5.0
        system = hoomd.init.create_lattice(unitcell=hoomd.lattice.sq(a=4.0),
                                           n=[3, 3])

        mol_indices = htf.find_molecules(system)
        model = build_examples.LJMolModel(
            MN=1, mol_indices=mol_indices, nneighbor_cutoff=NN)
        tfcompute = htf.tfcompute(model)
        nlist = hoomd.md.nlist.cell()
        hoomd.md.integrate.mode_standard(dt=0.005)
        hoomd.md.integrate.nvt(group=hoomd.group.all(), kT=1, tau=0.2)
        assert self.c.sorter.enabled
        tfcompute.attach(nlist, r_cut=rcut)
        # make sure tfcompute disabled the sorting
        assert not self.c.sorter.enabled
        hoomd.run(8)
Exemple #3
0
 def test_com(self):
     # I write this as an N x M
     # However, we need to have them as M x N, hence the
     # transpose
     mapping_matrix = np.array([[1, 0, 0], [1, 0, 0], [0, 1, 0], [0, 1, 0],
                                [1, 0, 0], [0, 0, 1], [0, 0, 1], [0, 0, 1],
                                [0, 0, 0], [0, 1, 0]]).transpose()
     mapping = htf.find_molecules(self.system)
     s = htf.sparse_mapping([mapping_matrix for _ in mapping], mapping,
                            self.system)
     # see if we can build it
     N = len(self.system.particles)
     p = tf.placeholder(tf.float32, shape=[N, 3])
     com = htf.center_of_mass(p, s, self.system)
     non_pbc_com = tf.sparse.matmul(s, p)
     with tf.Session() as sess:
         positions = self.system.take_snapshot().particles.position
         com, non_pbc_com = sess.run([com, non_pbc_com],
                                     feed_dict={p: positions})
     # TODO: Come up with a real test of this.
     assert True
Exemple #4
0
 def test_sparse_mapping(self):
     '''Checks the sparse mapping when used for
     summing forces, not center of mass
     '''
     # I write this as an N x M
     # However, we need to have them as M x N, hence the
     # transpose
     mapping_matrix = np.array([[1, 0, 0], [1, 0, 0], [0, 1, 0], [0, 1, 0],
                                [1, 0, 0], [0, 0, 1], [0, 0, 1], [0, 0, 1],
                                [1, 0, 0], [0, 1, 0]]).transpose()
     mapping = htf.find_molecules(self.system)
     s = htf.sparse_mapping([mapping_matrix for _ in mapping], mapping)
     # see if we can build it
     N = len(self.system.particles)
     p = tf.ones(shape=[N, 1])
     m = tf.sparse.matmul(s, p)
     dense_mapping = tf.sparse.to_dense(s)
     msum = tf.reduce_sum(m)
     with tf.Session() as sess:
         msum = sess.run(msum)
         # here we are doing sum, not center of mass.
         # So this is like com forces
         # number of nonzero mappeds = number of molecules
         # * number of particles in each molecule
         assert int(msum) == len(mapping) * mapping_matrix.shape[1]
         # now make sure we see the mapping matrix in first set
         dense_mapping = sess.run(dense_mapping)
     map_slice = dense_mapping[:mapping_matrix.shape[0], :mapping_matrix.
                               shape[1]]
     # make mapping_matrix sum to 1
     ref_slice = mapping_matrix
     np.testing.assert_array_almost_equal(map_slice, ref_slice)
     # check off-diagnoal slice, which should be 0
     map_slice = dense_mapping[:mapping_matrix.shape[0],
                               -mapping_matrix.shape[1]:]
     assert np.sum(map_slice) < 1e-10
     # make sure the rows sum to N
     assert (np.sum(np.abs(np.sum(dense_mapping, axis=1))) -
             dense_mapping.shape[1]) < 10e-10
Exemple #5
0
 def test_find_molecules(self):
     # test out mapping
     mapping = htf.find_molecules(self.system)
     assert len(mapping) == 9
     assert len(mapping[0]) == 10