def test_pbc_homog_HS_sigma155_trial_move(self): lx = 10 ly = 11 lz = 10 partial_indices = [3,4,5] eps = 1.0 sig = 1.55 rcut = 2.5 PT = PairTable(types=['P1'],parms=['epsilon','rcut','sigma','potential']) PT.setUnsetValues('epsilon',eps) PT.setUnsetValues('sigma',sig) PT.setUnsetValues('rcut',rcut) PT.setUnsetValues('potential','HardSphere') N = 3 ref_x,ref_y,ref_z,ref_t = self.make_rubix(N=N,types=None) x1 = list(ref_x) y1 = list(ref_y) z1 = list(ref_z) t1 = list(ref_t) x2 = []; y2 = []; z2 = []; t2 = []; trial_indices = [3,3,8] #equivalent to 3,4,10 for idex in trial_indices: x2.append(x1.pop(idex)) y2.append(y1.pop(idex)) z2.append(z1.pop(idex)) t2.append(t1.pop(idex)) U0 = 0 dist = self.calc_dist(3,4,ref_x,ref_y,ref_z,lx,ly,lz) U0+=self.hard_sphere(dist,eps,sig,rcut) dist = self.calc_dist(4,10,ref_x,ref_y,ref_z,lx,ly,lz) U0+=self.hard_sphere(dist,eps,sig,rcut) dist = self.calc_dist(3,10,ref_x,ref_y,ref_z,lx,ly,lz) U0+=self.hard_sphere(dist,eps,sig,rcut) for bead_i in range(len(x2)): for bead_j in range(len(x1)): dx = abs(x2[bead_i] - x1[bead_j]) dy = abs(y2[bead_i] - y1[bead_j]) dz = abs(z2[bead_i] - z1[bead_j]) if dx>lx/2.0: dx-=lx if dy>ly/2.0: dy-=ly if dz>lz/2.0: dz-=lz dist = sqrt(dx*dx+dy*dy+dz*dz) U0+=self.hard_sphere(dist,eps,sig,rcut) system = System() system.add_beads(x=x1,y=y1,z=z1,types=t1) system.box = Box(cell_grid=(3,3,3)) system.box.lx = lx system.box.ly = ly system.box.lz = lz system.trial_x = np.array([x2],dtype=np.float) system.trial_y = np.array([y2],dtype=np.float) system.trial_z = np.array([z2],dtype=np.float) system.trial_types = np.array([t2]) system.trial_bonds = [] xarray = np.array(x1,dtype=np.float) yarray = np.array(y1,dtype=np.float) zarray = np.array(z1,dtype=np.float) system.box.neighbor_list.build_nlist(xarray,yarray,zarray,True) system.NonBondedTable = PT PE = NonBondedPotentialEnergy(system) U1 = sum(PE.compute(trial_move=True)) self.assertAlmostEqual(U0,U1,delta=0.001)
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)