def test_magmom(): from ase import Atoms from ase.io import read, write atoms = Atoms('HH', [[.0, .0, .0], [.0, .0, .74]], pbc=True, cell=[5, 5, 5]) atoms.set_initial_magnetic_moments([1, -1]) moms = atoms.get_initial_magnetic_moments() write('test.traj', atoms) atoms = read('test.traj') assert (atoms.get_initial_magnetic_moments() == moms).all()
def test_noncollinear(): a = Atoms('H2') a[0].magmom = 1 m = a.get_initial_magnetic_moments() assert m.shape == (2, ) and (m == [1, 0]).all() a[1].magmom = -1 m = a.get_initial_magnetic_moments() assert m.shape == (2, ) and (m == [1, -1]).all() assert a[1].magmom == -1 a.set_initial_magnetic_moments() a[0].magmom = (0, 1, 0) m = a.get_initial_magnetic_moments() assert m.shape == (2, 3) and (m == [(0, 1, 0), (0, 0, 0)]).all() a[1].magmom = (1, 0, 0) m = a.get_initial_magnetic_moments() assert m.shape == (2, 3) and (m == [(0, 1, 0), (1, 0, 0)]).all() assert (a[1].magmom == (1, 0, 0)).all()
def test_build(): import numpy as np from ase import Atoms, Atom a = Atoms([Atom('Cu')]) a.positions[:] += 1.0 print(a.get_positions(), a.positions) a = a + a a += a a.append(Atom('C')) a += Atoms([]) a += Atom('H', magmom=1) print(a.get_initial_magnetic_moments()) print(a[0].number) print(a[[0, 1]].get_atomic_numbers()) print(a[np.array([1, 1, 0, 0, 1, 0], bool)].get_atomic_numbers()) print(a[::2].get_atomic_numbers()) print(a.get_chemical_symbols()) del a[2] print(a.get_chemical_symbols()) del a[-2:] print(a.get_chemical_symbols())
import numpy as np from ase import Atoms, Atom a = Atoms([Atom('Cu')]) a.positions[:] += 1.0 print(a.get_positions(), a.positions) a = a + a a += a a.append(Atom('C')) a += Atoms([]) a += Atom('H', magmom=1) print(a.get_initial_magnetic_moments()) print(a[0].number) print(a[[0, 1]].get_atomic_numbers()) print(a[np.array([1, 1, 0, 0, 1, 0], bool)].get_atomic_numbers()) print(a[::2].get_atomic_numbers()) print(a.get_chemical_symbols()) del a[2] print(a.get_chemical_symbols()) del a[-2:] print(a.get_chemical_symbols())
import numpy as np from ase import Atoms, Atom a = Atoms([Atom('Cu')]) a.positions[:] += 1.0 print(a.get_positions(), a.positions) a=a+a a+=a a.append(Atom('C')) a += Atoms([]) a += Atom('H', magmom=1) print(a.get_initial_magnetic_moments()) print(a[0].number) print(a[[0,1]].get_atomic_numbers()) print(a[np.array([1,1,0,0,1], bool)].get_atomic_numbers()) print(a[::2].get_atomic_numbers()) print(a.get_chemical_symbols()) del a[2] print(a.get_chemical_symbols()) del a[-2:] print(a.get_chemical_symbols())
from ase import Atom, Atoms a = Atoms('H2') a[0].magmom = 1 m = a.get_initial_magnetic_moments() assert m.shape == (2,) and (m == [1, 0]).all() a[1].magmom = -1 m = a.get_initial_magnetic_moments() assert m.shape == (2,) and (m == [1, -1]).all() assert a[1].magmom == -1 a.set_initial_magnetic_moments() a[0].magmom = (0, 1, 0) m = a.get_initial_magnetic_moments() assert m.shape == (2, 3) and (m == [(0, 1, 0), (0, 0, 0)]).all() a[1].magmom = (1, 0, 0) m = a.get_initial_magnetic_moments() assert m.shape == (2, 3) and (m == [(0, 1, 0), (1, 0, 0)]).all() assert (a[1].magmom == (1, 0, 0)).all()
from ase import Atoms from gpaw import GPAW, FermiDirac from gpaw.eigensolvers.rmm_diis_old import RMM_DIIS from gpaw.mixer import MixerSum from gpaw.test import equal a = 2.87 bulk = Atoms('Fe2', scaled_positions=[(0, 0, 0), (0.5, 0.5, 0.5)], magmoms=[2.20, 2.20], cell=(a, a, a), pbc=True) mom0 = sum(bulk.get_initial_magnetic_moments()) h = 0.2 conv = {'eigenstates': 0.1, 'density': 0.1, 'energy': 0.01} calc = GPAW(h=h, eigensolver=RMM_DIIS(), mixer=MixerSum(0.1, 3), nbands=11, kpts=(3, 3, 3), convergence=conv, occupations=FermiDirac(0.1, fixmagmom=True)) bulk.set_calculator(calc) e = bulk.get_potential_energy() niter = calc.get_number_of_iterations() mom = calc.get_magnetic_moment() equal(mom, mom0, 1e-5) energy_tolerance = 0.0002 niter_tolerance = 0 equal(e, -20.3251, energy_tolerance)
from ase import Atoms a = Atoms('H2') a[0].magmom = 1 m = a.get_initial_magnetic_moments() assert m.shape == (2, ) and (m == [1, 0]).all() a[1].magmom = -1 m = a.get_initial_magnetic_moments() assert m.shape == (2, ) and (m == [1, -1]).all() assert a[1].magmom == -1 a.set_initial_magnetic_moments() a[0].magmom = (0, 1, 0) m = a.get_initial_magnetic_moments() assert m.shape == (2, 3) and (m == [(0, 1, 0), (0, 0, 0)]).all() a[1].magmom = (1, 0, 0) m = a.get_initial_magnetic_moments() assert m.shape == (2, 3) and (m == [(0, 1, 0), (1, 0, 0)]).all() assert (a[1].magmom == (1, 0, 0)).all()
from ase import Atoms from ase.io import read, write atoms = Atoms('HH', [[.0, .0, .0], [.0, .0, .74]], pbc=True, cell=[5, 5, 5]) atoms.set_initial_magnetic_moments([1, -1]) moms = atoms.get_initial_magnetic_moments() write('test.traj', atoms) atoms = read('test.traj') assert (atoms.get_initial_magnetic_moments() == moms).all()
from ase import Atoms from ase.io import read, write atoms = Atoms('HH', [[.0,.0,.0], [.0,.0,.74]], pbc=True, cell=[5, 5, 5]) atoms.set_initial_magnetic_moments([1, -1]) moms = atoms.get_initial_magnetic_moments() write('test.traj',atoms) atoms = read('test.traj') assert (atoms.get_initial_magnetic_moments() == moms).all()
from ase import Atoms from gpaw import GPAW, FermiDirac from gpaw.eigensolvers.rmm_diis_old import RMM_DIIS from gpaw.mixer import MixerSum from gpaw.test import equal a = 2.87 bulk = Atoms('Fe2', scaled_positions=[(0, 0, 0), (0.5, 0.5, 0.5)], magmoms=[2.20, 2.20], cell=(a, a, a), pbc=True) mom0 = sum(bulk.get_initial_magnetic_moments()) h = 0.2 conv = {'eigenstates': 0.1, 'density':0.1, 'energy':0.01} calc = GPAW(h=h, eigensolver=RMM_DIIS(), mixer=MixerSum(0.1,3), nbands=11, kpts=(3, 3, 3), convergence=conv, occupations=FermiDirac(0.1, fixmagmom=True)) bulk.set_calculator(calc) e = bulk.get_potential_energy() niter = calc.get_number_of_iterations() mom = calc.get_magnetic_moment() equal(mom, mom0, 1e-5) energy_tolerance = 0.0002 niter_tolerance = 0 equal(e, -20.3251, energy_tolerance)