def main(): assert installed() # simple test calculation of CO molecule 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., istart=0, lwave=False, lcharg=False, ldipol=True) co.set_calculator(calc) energy = co.get_potential_energy() forces = co.get_forces() dipole_moment = co.get_dipole_moment() # check that parsing of vasprun.xml file works conf = read('vasprun.xml') assert conf.calc.parameters['kpoints_generation'] assert conf.calc.parameters['sigma'] == 1.0 assert conf.calc.parameters['ialgo'] == 68 assert energy - conf.get_potential_energy() == 0.0 assert np.allclose(conf.get_forces(), forces) assert np.allclose(conf.get_dipole_moment(), dipole_moment, atol=1e-6) # Cleanup calc.clean()
def main(): if sys.version_info < (2, 7): raise NotAvailable('read_xml requires Python version 2.7 or greater') assert installed() # simple test calculation of CO molecule d = 1.14 co = Atoms('CO', positions=[(0, 0, 0), (0, 0, d)], pbc=True) co.center(vacuum=5.) calc = Vasp(xc='LDA', prec='Low', algo='Fast', ismear=0, sigma=1., nbands=12, istart=0, nelm=3, lwave=False, lcharg=False, ldipol=True) co.set_calculator(calc) energy = co.get_potential_energy() forces = co.get_forces() dipole_moment = co.get_dipole_moment() # check that parsing of vasprun.xml file works conf = read('vasprun.xml') assert conf.calc.parameters['kpoints_generation'] assert conf.calc.parameters['sigma'] == 1.0 assert conf.calc.parameters['ialgo'] == 68 assert energy - conf.get_potential_energy() == 0.0 # Check some arrays assert np.allclose(conf.get_forces(), forces) assert np.allclose(conf.get_dipole_moment(), dipole_moment, atol=1e-6) # Check k-point-dependent properties assert len(conf.calc.get_eigenvalues(spin=0)) >= 12 assert conf.calc.get_occupation_numbers()[2] == 2 assert conf.calc.get_eigenvalues(spin=1) is None kpt = conf.calc.get_kpt(0) assert kpt.weight == 1. # Perform a spin-polarised calculation co.calc.set(ispin=2, ibrion=-1) co.get_potential_energy() conf = read('vasprun.xml') assert len(conf.calc.get_eigenvalues(spin=1)) >= 12 assert conf.calc.get_occupation_numbers(spin=1)[0] == 1. # Cleanup calc.clean()
def test_h2o(): import ase.calculators.demon as demon from ase import Atoms from ase.optimize import BFGS import numpy as np tol = 1.0e-6 # d = 0.9575 d = 0.9775 # t = np.pi / 180 * 104.51 t = np.pi / 180 * 110.51 atoms = Atoms('H2O', positions=[(d, 0, 0), (d * np.cos(t), d * np.sin(t), 0), (0, 0, 0)]) # set up deMon calculator basis = {'all': 'aug-cc-pvdz', 'O': 'RECP6|SD'} auxis = {'all': 'GEN-A2*'} input_arguments = {'GRID': 'FINE'} calc = demon.Demon(basis=basis, auxis=auxis, scftype='RKS TOL=1.0E-6 CDF=1.0E-5', guess='TB', xc=['BLYP', 'BASIS'], input_arguments=input_arguments) atoms.calc = calc # energy energy = atoms.get_potential_energy() ref = -469.604737006 print('energy') print(energy) error = np.sqrt(np.sum((energy - ref)**2)) print('diff from reference:') print(error) tol = 1.0e-6 assert (error < tol) # dipole dipole = atoms.get_dipole_moment() ref = np.array([0.19228183, 0.27726241, 0.0]) error = np.sqrt(np.sum((dipole - ref)**2)) print('dipole') print(dipole) print('diff from reference:') print(error) tol = 1.0e-4 assert (error < tol) # numerical forces forces_num = calc.calculate_numerical_forces(atoms, d=0.001) ref = np.array([[-1.26056746e-01, 4.10007559e-01, 2.85719551e-04], [4.28062314e-01, 2.56059142e-02, 2.17691110e-04], [-3.02019173e-01, -4.35613473e-01, -5.03410632e-04]]) error = np.sqrt(np.sum((forces_num - ref)**2)) print('forces_num') print(forces_num) print('diff from reference:') print(error) tol = 1.0e-4 assert (error < tol) # analytical forces forces_an = atoms.get_forces() ref = np.array([[-1.26446863e-01, 4.09628186e-01, -0.00000000e+00], [4.27934442e-01, 2.50425467e-02, -5.14220671e-05], [-2.99225008e-01, -4.31533987e-01, -5.14220671e-05]]) error = np.sqrt(np.sum((forces_an - ref)**2)) print('forces_an') print(forces_an) print('diff from reference:') print(error) tol = 1.0e-3 assert (error < tol) # optimize geometry dyn = BFGS(atoms) dyn.run(fmax=0.01) positions = atoms.get_positions() ref = np.array([[9.61364579e-01, 2.81689367e-02, -1.58730770e-06], [-3.10444398e-01, 9.10289261e-01, -5.66399075e-06], [-1.56957763e-02, -2.26044053e-02, -2.34155615e-06]]) error = np.sqrt(np.sum((positions - ref)**2)) print('positions') print(positions) print('diff from reference:') print(error) tol = 1.0e-3 assert (error < tol) print('tests passed')
atoms.set_calculator(calc) # energy energy = atoms.get_potential_energy() ref = -469.604737006 print('energy') print(energy) error = np.sqrt(np.sum((energy - ref)**2)) print('diff from reference:') print(error) assert(error < tol) # dipole dipole = atoms.get_dipole_moment() ref = np.array([0.19228183, 0.27726241, 0.0]) error = np.sqrt(np.sum((dipole - ref)**2)) print('dipole') print(dipole) print('diff from reference:') print(error) assert(error < tol) # numerical forces forces_num = calc.calculate_numerical_forces(atoms, d=0.001) ref = np.array([[-1.26056746e-01, 4.10007559e-01, 2.85719551e-04],
atoms.set_calculator(calc) # energy energy = atoms.get_potential_energy() ref = -469.604737006 print('energy') print(energy) error = np.sqrt(np.sum((energy - ref)**2)) print('diff from reference:') print(error) assert (error < tol) # dipole dipole = atoms.get_dipole_moment() ref = np.array([0.19228183, 0.27726241, 0.0]) error = np.sqrt(np.sum((dipole - ref)**2)) print('dipole') print(dipole) print('diff from reference:') print(error) assert (error < tol) # numerical forces forces_num = calc.calculate_numerical_forces(atoms, d=0.001) ref = np.array([[-1.26056746e-01, 4.10007559e-01, 2.85719551e-04], [4.28062314e-01, 2.56059142e-02, 2.17691110e-04],
# Initial structural parameters d = 0.974 theta = 104.4 * np.pi/180. # Positions of the H2O atoms (in that order) pos = [[d*np.cos(theta/2.), d*np.sin(theta/2.), 0.], [d*np.cos(theta/2.), -d*np.sin(theta/2.), 0.], [0., 0., 0.]] # Let us instantiate an Atoms object and add some vacuum around the molecule atoms = Atoms("H2O", positions=pos, pbc=False) atoms.center(vacuum=4.) # Let's view the molecule view(atoms) # We create a GPAW calculator object and assign it to atoms if print_to_screen: calc = GPAW(xc="PBE") else: calc = GPAW(xc="PBE", txt="gpaw.out") atoms.set_calculator(calc) # Let us run a GPAW calculation to get the cohesive energy of this configuration e_water = atoms.get_potential_energy() dip_water = atoms.get_dipole_moment() print("Dipole of a H2O monomer: (%f, %f, %f) electrons/Angstrom" % \ (dip_water[0], dip_water[1], dip_water[2]))
bond_lengths = [1.1, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18] energies = [] dipoles = [] for d in bond_lengths: # possible bond lengths co = Atoms('CO', [(0, 0, 0), (0, 0, d)]) calc = Aims(label='molecules/co-{0}'.format(d), # output dir xc='PBE', output=['dipole', 'mulliken'], sc_accuracy_etot=1e-5, sc_accuracy_eev=1e-3, sc_accuracy_rho=1e-4, sc_accuracy_forces=1e-3) co.set_calculator(calc) try: e = co.get_potential_energy() dip = co.get_dipole_moment() print(dip) energies.append(e) dipoles.append(dip[2]) # only in z direction print('d = {0:1.2f} ang'.format(d)) print('energy = {0:1.3f} eV'.format(e)) print('dipole = {0:1.3f} eV'.format(dip[2])) print('forces = (eV/ang)\n {0}'.format(co.get_forces())) print('') # blank line except: energies.append(None) dipoles.append(None) print('bond lengths {0:1.3f} fhi-aims fails'.format(d)) pass if None not in energies: import matplotlib.pyplot as plt