d = 1.14 co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)], pbc=True) co.center(vacuum=5.) calc = Vasp( xc = 'PBE', prec = 'Low', algo = 'Fast', ismear= 0, sigma = 1., lwave = False, lcharg = False) co.set_calculator(calc) en = co.get_potential_energy() assert abs(en + 14.918933) < 1e-4 # Secondly, check that restart from the previously created VASP output works calc2 = Vasp(restart=True) co2 = calc2.get_atoms() # Need tolerance of 1e-14 because VASP itself changes coordinates # slightly between reading POSCAR and writing CONTCAR even if no ionic # steps are made. assert array_almost_equal(co.positions, co2.positions, 1e-14) assert en - co2.get_potential_energy() == 0. assert array_almost_equal(calc.get_stress(co), calc2.get_stress(co2)) assert array_almost_equal(calc.get_forces(co), calc2.get_forces(co2))
from ase_ext import Atoms from ase_ext.calculators.emt import EMT from ase_ext.constraints import FixBondLength from ase_ext.io import PickleTrajectory from ase_ext.optimize import BFGS a = 3.6 b = a / 2 cu = Atoms('Cu2Ag', positions=[(0, 0, 0), (b, b, 0), (a, a, b)], calculator=EMT()) e0 = cu.get_potential_energy() print(e0) d0 = cu.get_distance(0, 1) cu.set_constraint(FixBondLength(0, 1)) t = PickleTrajectory('cu2ag.traj', 'w', cu) qn = BFGS(cu) qn.attach(t.write) def f(): print(cu.get_distance(0, 1)) qn.attach(f) qn.run(fmax=0.01) assert abs(cu.get_distance(0, 1) - d0) < 1e-14
print("No Scientific python found. Check your PYTHONPATH") raise NotAvailable('ScientificPython version 2.8 or greater is required') if not (os.system('which dacapo.run') == 0): print( "No Dacapo Fortran executable (dacapo.run) found. Check your path settings." ) raise NotAvailable( 'dacapo.run is not installed on this machine or not in the path') # Now Scientific 2.8 and dacapo.run should both be available from ase_ext import Atoms, Atom from ase_ext.calculators.jacapo import Jacapo atoms = Atoms([Atom('H', [0, 0, 0])], cell=(2, 2, 2)) calc = Jacapo('Jacapo-test.nc', pw=200, nbands=2, kpts=(1, 1, 1), spinpol=False, dipole=False, symmetry=False, ft=0.01) atoms.set_calculator(calc) print(atoms.get_potential_energy()) os.system('rm -f Jacapo-test.nc Jacapo-test.txt')
from ase_ext import Atom, Atoms from gpaw import GPAW a = 4.0 b = a / 2**.5 L = 7.0 al = Atoms([Atom('Al')], cell=(b, b, L), pbc=True) calc = GPAW(kpts=(4, 4, 1)) al.set_calculator(calc) al.get_potential_energy() calc.write('Al100.gpw', 'all')
from ase_ext import Atoms from ase_ext.calculators.emt import EMT from ase_ext.optimize import QuasiNewton n2 = Atoms('N2', positions=[(0, 0, 0), (0, 0, 1.1)], calculator=EMT()) QuasiNewton(n2).run(0.01) print(n2.get_distance(0, 1), n2.get_potential_energy())
H H H H H H HH HHH""" d = 0.8 atoms = Atoms() for y, line in enumerate(logo.split('\n')): for x, c in enumerate(line): if c == 'H': atoms.append(Atom('H', [d * x, -d * y, 0])) atoms.center(vacuum=2.0) view(atoms) if 0: calc = GPAW(nbands=30) atoms.set_calculator(calc) atoms.get_potential_energy() calc.write('ase-logo.gpw') else: calc = GPAW('ase-logo.gpw', txt=None) density = calc.get_pseudo_density() image = density[..., density.shape[2] // 2] if 1: # scale colors to wiki background / foreground import numpy as np background = np.array([[[19., 63., 82.]]]).T / 255 # 1c4e63 blueish foreground = np.array([[[1., 1., 1.]]]).T # white image = background + image / image.max() * (foreground - background) image = image.T else: # Use a standard color scheme image = pl.cm.hot(image.T)
import numpy as np from ase_ext import Atoms from ase_ext.units import fs from ase_ext.calculators.test import TestPotential from ase_ext.calculators.emt import EMT from ase_ext.md import VelocityVerlet from ase_ext.io import PickleTrajectory, read from ase_ext.optimize import QuasiNewton np.seterr(all='raise') a = Atoms('4X', masses=[1, 2, 3, 4], positions=[(0, 0, 0), (1, 0, 0), (0, 1, 0), (0.1, 0.2, 0.7)], calculator=TestPotential()) print(a.get_forces()) md = VelocityVerlet(a, dt=0.5 * fs, logfile='-', loginterval=500) traj = PickleTrajectory('4N.traj', 'w', a) md.attach(traj.write, 100) e0 = a.get_total_energy() md.run(steps=10000) del traj assert abs(read('4N.traj').get_total_energy() - e0) < 0.0001 qn = QuasiNewton(a) qn.run(0.001) assert abs(a.get_potential_energy() - 1.0) < 0.000002
import numpy as np from ase_ext.calculators.emt import EMT from ase_ext import Atoms a = 3.60 b = a / 2 cu = Atoms('Cu', positions=[(0, 0, 0)], cell=[(0, b, b), (b, 0, b), (b, b, 0)], pbc=1, calculator=EMT()) e0 = cu.get_potential_energy() print(e0) cu.set_cell(cu.get_cell() * 1.001, scale_atoms=True) e1 = cu.get_potential_energy() V = a**3 / 4 B = 2 * (e1 - e0) / 0.003**2 / V * 160.2 print(B) for i in range(4): x = 0.001 * i A = np.array([(x, b, b + x), (b, 0, b), (b, b, 0)]) cu.set_cell(A, scale_atoms=True) e = cu.get_potential_energy() - e0 if i == 0: print(i, e) else: print(i, e, e / x**2) A = np.array([(0, b, b), (b, 0, b), (6 * b, 6 * b, 0)])