def __call__(self, *args): if os.path.exists(self.fn): print 'Reading configuration from checkpoint file %s...' % self.fn a = io.read(self.fn) else: a = self.func(*args) io.write(self.fn, a) return a
def test_no_pbc_small_cell(self): a = io.read('aC.cfg') a.set_calculator(Tersoff()) a.set_pbc(False) e1 = a.get_potential_energy() i1, j1, r1 = a.calc.nl.get_neighbors(a.calc.particles) a.set_cell(a.cell*0.9, scale_atoms=False) e2 = a.get_potential_energy() self.assertAlmostEqual(e1, e2) i2, j2, r2 = a.calc.nl.get_neighbors(a.calc.particles) for k in range(len(a)): neigh1 = np.array(sorted(j1[i1==k])) neigh2 = np.array(sorted(j2[i2==k])) self.assertTrue(np.all(neigh1 == neigh2))
def test_pbc_shift_by_multiple_cells(self): a = io.read('aC.cfg') a.set_calculator(Tersoff()) e1 = a.get_potential_energy() i1, j1, r1 = a.calc.nl.get_neighbors(a.calc.particles) a[100].position += 3*a.cell[0] e2 = a.get_potential_energy() i2, j2, r2 = a.calc.nl.get_neighbors(a.calc.particles) for i in range(len(a)): n1 = np.array(sorted(j1[i1==i])) n2 = np.array(sorted(j2[i2==i])) if np.any(n1 != n2): print(i, n1, n2) a[100].position += a.cell.T.dot([1,3,-4]) e3 = a.get_potential_energy() self.assertAlmostEqual(e1, e2) self.assertAlmostEqual(e1, e3)
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))
nbins = int(value) elif key == '--cutoff': 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()
(opt, args) = parser.parse_args() ### convlen = None if opt.toA: convlen = ase.units.Bohr elif opt.toBohr: convlen = 1.0 / ase.units.Bohr infn = args[0] outfn = args[1] a = io.read(infn) if 'shear_dx' in a.info: cx, cy, cz = a.cell assert abs(cx[1]) < 1e-12 assert abs(cx[2]) < 1e-12 assert abs(cy[0]) < 1e-12 assert abs(cy[2]) < 1e-12 assert abs(cz[0]) < 1e-12 assert abs(cz[1]) < 1e-12 dx, dy, dz = a.info['shear_dx'] sx, sy, sz = a.cell.diagonal() a.set_cell([[sx, 0, 0], [0, sy, 0], [dx, dy, sz]], scale_atoms=False) if opt.cell is not None: cell = map(float, opt.cell.split(','))
nbins = int(value) elif key == '--cutoff': 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()
assert len(args) == 1 infn = args[0] for key, value in optlist: if key == '--pot': potstr = value elif key == '--fmax': fmax = float(value) elif key == '--outfn': outfn = value ### print '# infn = ', infn print '# outfn = ', outfn print '# pot = ', potstr print '# fmax = ', fmax ### a = read(infn) print '{0} atoms.'.format(len(a)) potclass = getattr(atomistica, potstr) a.set_calculator(potclass()) FIRE(a).run(fmax=fmax) write(outfn, a)
(opt, args) = parser.parse_args() ### convlen = None if opt.toA: convlen = ase.units.Bohr elif opt.toBohr: convlen = 1.0/ase.units.Bohr infn = args[0] outfn = args[1] a = io.read(infn) if 'shear_dx' in a.info: cx, cy, cz = a.cell assert abs(cx[1]) < 1e-12 assert abs(cx[2]) < 1e-12 assert abs(cy[0]) < 1e-12 assert abs(cy[2]) < 1e-12 assert abs(cz[0]) < 1e-12 assert abs(cz[1]) < 1e-12 dx, dy, dz = a.info['shear_dx'] sx, sy, sz = a.cell.diagonal() a.set_cell([[sx,0,0],[0,sy,0],[dx,dy,sz]], scale_atoms=False) if opt.cell is not None: cell = map(float, opt.cell.split(','))