1def test_emt_stress():
2    import numpy as np
3    from ase.build import bulk
4    from ase.calculators.emt import EMT
5
6    a = bulk('Cu', 'fcc')
7    a.calc = EMT()
8    a.set_cell(np.dot(a.cell,
9                      [[1.02, 0, 0.03],
10                       [0, 0.99, -0.02],
11                       [0.1, -0.01, 1.03]]),
12               scale_atoms=True)
13    a *= (1, 2, 3)
14    a.rattle()
15    # Verify analytical stress tensor against numerical value
16    s_analytical = a.get_stress()
17    s_numerical = a.calc.calculate_numerical_stress(a, 1e-5)
18    s_p_err = 100 * (s_numerical - s_analytical) / s_numerical
19    print('Analytical stress:\n', s_analytical)
20    print('Numerical stress:\n', s_numerical)
21    print('Percent error in stress:\n', s_p_err)
22    assert np.all(abs(s_p_err) < 1e-5)
23