def test_pbc(self): a = ase.Atoms('CC', positions=[[0.1, 0.5, 0.5], [0.9, 0.5, 0.5]], cell=[1, 1, 1], pbc=True) an = native.from_atoms(a) nl = native.Neighbors(100) nl.request_interaction_range(0.3) # with pbc i, j, abs_dr = nl.get_neighbors(an) self.assertEqual(len(i), 2) a.set_pbc(False) an = native.from_atoms(a) nl = native.Neighbors(100) nl.request_interaction_range(0.3) # no pbc i, j, abs_dr = nl.get_neighbors(an) self.assertEqual(len(i), 0) a.set_pbc([False,False,True]) an = native.from_atoms(a) nl = native.Neighbors(100) nl.request_interaction_range(0.3) # partial pbc i, j, abs_dr = nl.get_neighbors(an) self.assertEqual(len(i), 0) a.set_pbc([True,False,False]) an = native.from_atoms(a) nl = native.Neighbors(100) nl.request_interaction_range(0.3) # partial pbc i, j, abs_dr = nl.get_neighbors(an) self.assertEqual(len(i), 2)
def test_neighbor_list(self): a = io.read('aC.cfg') an = native.from_atoms(a) nl = native.Neighbors(100) nl.request_interaction_range(5.0) i, j, abs_dr_no_vec = nl.get_neighbors(an) i, j, dr, abs_dr = nl.get_neighbors(an, vec=True) self.assertTrue(np.all(np.abs(abs_dr_no_vec-abs_dr) < 1e-12)) r = a.get_positions() dr_direct = mic(r[i]-r[j], a.cell) abs_dr_from_dr = np.sqrt(np.sum(dr*dr, axis=1)) abs_dr_direct = np.sqrt(np.sum(dr_direct*dr_direct, axis=1)) self.assertTrue(np.all(np.abs(abs_dr-abs_dr_from_dr) < 1e-12)) self.assertTrue(np.all(np.abs(abs_dr-abs_dr_direct) < 1e-12)) self.assertTrue(np.all(np.abs(dr-dr_direct) < 1e-12))
def atomic_strain(atoms_now, atoms_old, cutoff=None, i_now=None, j_now=None): """ Calculate deformation gradient tensor and D^2_min measure for non-affine displacements. See: Falk, Langer, Phys. Rev. B 57, 7192 (1998) Parameters: ----------- atoms_now Current atomic configuration atoms_old Reference atomic configuration cutoff Neighbor list cutoff. i_now, j_now Neighbor list. Automatically computed if not provided. Returns: -------- delta_plus_epsilon Strain gradient tensor d_sq D^2_min norm """ if i_now is None or j_now is None: if cutoff is None: raise ValueError('Please provide either neighbor list or neighbor ' 'list cutoff.') # Create a particles object and set number of atoms and cell p = native.from_atoms(a_now) # create a neighbor list object and set it's cutoff nl = native.Neighbors(avgn) nl.request_interaction_range(cutoff) # get neighbours and distance i_now, j_now, abs_dr_now = nl.get_neighbors(p) elif cutoff is not None: raise ValueError('Please provide either neighbor list or neighbor ' 'list cutoff, not both.') ### get the D square values delta_plus_epsilon, d_sq = get_D_square_min(atoms_now, atoms_old, i_now, j_now) return delta_plus_epsilon, d_sq
cutoff = float(value) elif key == '--avgn': avgn = int(value) ### print '# fn = ', fn print '# nbins = ', nbins print '# cutoff = ', cutoff print '# avgn = ', avgn ### a = read(fn) print '{0} atoms.'.format(len(a)) p = native.from_atoms(a) nl = native.neighbor_list(p, cutoff, avgn=avgn) i, j, dr, abs_dr = nl.get_neighbors(p, vec=True) pavg, pvar = native.pair_distribution(i, abs_dr, nbins, cutoff) r = np.linspace(0.0, cutoff, nbins + 1) r = (r[1:] + r[:-1]) / 2 rho = len(a) / a.get_volume() np.savetxt('g2.out', np.transpose([r, pavg, pvar, pavg / rho])) rho = np.sum(a.get_masses()) / a.get_volume() print 'Density is {0} g/cm^3.'.format(rho * 1e24 / mol)
elif key == '--avgn': avgn = int(value) ### print '# fn = ', fn print '# nbins = ', nbins print '# cutoff = ', cutoff print '# avgn = ', avgn ### a = read(fn) print '{0} atoms.'.format(len(a)) p = native.from_atoms(a) nl = native.neighbor_list(p, cutoff, avgn=avgn) i, j, dr, abs_dr = nl.get_neighbors(p, vec=True) pavg, pvar = native.pair_distribution(i, abs_dr, nbins, cutoff) r = np.linspace(0.0, cutoff, nbins+1) r = (r[1:]+r[:-1])/2 rho = len(a)/a.get_volume() np.savetxt('g2.out', np.transpose([r, pavg, pvar, pavg/rho])) rho = np.sum(a.get_masses())/a.get_volume() print 'Density is {0} g/cm^3.'.format(rho * 1e24/mol)