1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
import pytest
@pytest.mark.calculator('gpaw')
@pytest.mark.filterwarnings('ignore:The keyword')
# Ignore calculator constructor keyword warning for now
def test_no_spin_and_spin(factory):
from ase.build import molecule
from ase import io
txt = 'out.txt'
calculator = factory.calc(h=0.3, txt=txt)
atoms = molecule('H2', calculator=calculator)
atoms.center(vacuum=3)
atoms.get_potential_energy()
atoms.set_initial_magnetic_moments([0.5, 0.5])
calculator.set(charge=1)
atoms.get_potential_energy()
# read again
t = io.read(txt, index=':')
assert isinstance(t, list)
M = t[1].get_magnetic_moments()
assert abs(M - 0.2).max() < 0.1
|