コード例 #1
0
    def test_partial1(self):
        lx = 8
        ly = 11
        lz = 9
        N = 10
        dz = 1.1
        r0 = 1.0
        potential = 'Harmonic'
        partial_indices = [4, 3, 5]

        x = np.array([0.0] * N)
        y = np.array([0.0] * N)
        z = np.array([dz * i - lz / 2.0 for i in range(N)])
        t = [0] * N
        bonds = [[i, j] for i, j in zip(range(N - 1), range(1, N))]

        U0 = 0
        U0 += self.harmonic(dz, 1.0, r0) * (len(partial_indices) - 1
                                            )  #inner bonds
        U0 += self.harmonic(dz, 1.0, r0) * (2)  #outer bonds

        NBPT = PairTable(types=['P1'],
                         parms=['epsilon', 'rcut', 'sigma', 'potential'])
        NBPT.setUnsetValues('epsilon', 1.0)
        NBPT.setUnsetValues('sigma', 1.0)
        NBPT.setUnsetValues('rcut', 2.5)
        NBPT.setUnsetValues('potential', 'HardSphere')

        BPT = PairTable(types=['P1'], parms=['k', 'r0', 'potential'])
        BPT.setUnsetValues('k', 1.0)
        BPT.setUnsetValues('r0', r0)
        BPT.setUnsetValues('potential', potential)

        system = System()
        system.add_beads(x=x, y=y, z=z, types=t, bonds=bonds)
        system.box = Box(cell_grid=(3, 3, 3))
        system.box.lx = lx
        system.box.ly = ly
        system.box.lz = lz
        system.BondedTable = BPT
        system.NonBondedTable = NBPT

        (x, y, z), (imx, imy, imz) = system.box.wrap_positions(x=x, y=y, z=z)

        xarray = np.array(x, dtype=np.float)
        yarray = np.array(y, dtype=np.float)
        zarray = np.array(z, dtype=np.float)
        system.box.neighbor_list.build_nlist(xarray, yarray, zarray, True)

        PE = BondedPotentialEnergy(system)
        U1 = sum(PE.compute(partial_indices=partial_indices))

        self.assertAlmostEqual(U0, U1, delta=0.001)
コード例 #2
0
    def base_test(self, lx, ly, lz, N, dz, potential, r0):
        dx = 1.0
        dy = 0.5
        x = np.array([i * dx for i in range(N)])
        y = np.array([i * dy for i in range(N)])
        z = np.array([dz * i - lz / 2.0 for i in range(N)])
        t = [0] * N
        bonds = [[i, j] for i, j in zip(range(N - 1), range(1, N))]

        NBPT = PairTable(types=['P1'],
                         parms=['epsilon', 'rcut', 'sigma', 'potential'])
        NBPT.setUnsetValues('epsilon', 1.0)
        NBPT.setUnsetValues('sigma', 1.0)
        NBPT.setUnsetValues('rcut', 2.5)
        NBPT.setUnsetValues('potential', 'HardSphere')

        BPT = PairTable(types=['P1'], parms=['k', 'r0', 'potential'])
        BPT.setUnsetValues('k', 1.0)
        BPT.setUnsetValues('r0', r0)
        BPT.setUnsetValues('potential', potential)

        system = System()
        system.add_beads(x=x, y=y, z=z, types=t, bonds=bonds)
        system.box = Box(cell_grid=(3, 3, 3))
        system.box.lx = lx
        system.box.ly = ly
        system.box.lz = lz
        system.BondedTable = BPT
        system.NonBondedTable = NBPT

        (x, y, z), (imx, imy, imz) = system.box.wrap_positions(x=x, y=y, z=z)
        U0 = self.calc_all_potential(bonds, x, y, z, t, lx, ly, lz, BPT)

        xarray = np.array(x, dtype=np.float)
        yarray = np.array(y, dtype=np.float)
        zarray = np.array(z, dtype=np.float)
        system.box.neighbor_list.build_nlist(xarray, yarray, zarray, True)

        PE = BondedPotentialEnergy(system)
        U1 = sum(PE.compute())

        return U0, U1
コード例 #3
0
    def test_trial_move(self):
        lx = 8
        ly = 11
        lz = 9
        dz = 1.1
        r0 = 1.0
        potential = 'Harmonic'

        N = 10
        ref_x = np.array([0.0] * N)
        ref_y = np.array([0.0] * N)
        ref_z = np.array([dz * i - lz / 2.0 for i in range(N)])
        ref_t = [0] * N
        ref_bonds = [[i, j] for i, j in zip(range(N - 1), range(1, N))]

        N = 5
        x = [0.0] * N
        y = [0.0] * N
        z = [dz * i - lz / 2.0 for i in range(N)]
        t = [0] * N
        bonds = [[i, j] for i, j in zip(range(N - 1), range(1, N))]

        N_trial = 5
        trial_x = [0.0] * N_trial
        trial_y = [0.0] * N_trial
        trial_z = [dz * 5 + dz * i - lz / 2.0 for i in range(N_trial)]
        trial_t = [0] * N_trial
        trial_bonds = [[i + N, j + N]
                       for i, j in zip(range(N_trial - 1), range(1, N_trial))]
        trial_bonds += [[N, N + 1]]

        NBPT = PairTable(types=['P1'],
                         parms=['epsilon', 'rcut', 'sigma', 'potential'])
        NBPT.setUnsetValues('epsilon', 1.0)
        NBPT.setUnsetValues('sigma', 1.0)
        NBPT.setUnsetValues('rcut', 2.5)
        NBPT.setUnsetValues('potential', 'HardSphere')

        BPT = PairTable(types=['P1'], parms=['k', 'r0', 'potential'])
        BPT.setUnsetValues('k', 1.0)
        BPT.setUnsetValues('r0', r0)
        BPT.setUnsetValues('potential', potential)

        system = System()
        system.add_beads(x=x, y=y, z=z, types=t, bonds=bonds)
        system.box = Box(cell_grid=(3, 3, 3))
        system.box.lx = lx
        system.box.ly = ly
        system.box.lz = lz
        system.BondedTable = BPT
        system.NonBondedTable = NBPT

        system.trial_x = np.array([trial_x])
        system.trial_y = np.array([trial_y])
        system.trial_z = np.array([trial_z])
        system.trial_types = np.array([trial_t])
        system.trial_bond_pairlist = np.array(trial_bonds)

        (ref_x, ref_y, ref_z), (imx, imy,
                                imz) = system.box.wrap_positions(x=ref_x,
                                                                 y=ref_y,
                                                                 z=ref_z)
        U0 = self.calc_all_potential(ref_bonds, ref_x, ref_y, ref_z, ref_t, lx,
                                     ly, lz, BPT)

        PE = BondedPotentialEnergy(system)
        U1 = sum(PE.compute())
        U2 = sum(PE.compute(trial_move=True))

        self.assertAlmostEqual(U0, U1 + U2, delta=0.001)