File: test_magres.py

package info (click to toggle)
python-ase 3.21.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,936 kB
  • sloc: python: 122,428; xml: 946; makefile: 111; javascript: 47
file content (28 lines) | stat: -rw-r--r-- 899 bytes parent folder | download | duplicates (2)
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
26
27
28
def test_magres():
    import numpy as np
    from ase.io import read, write
    from ase.build import bulk
    from ase.calculators.singlepoint import SinglePointDFTCalculator

    # Test with fictional data
    si2 = bulk('Si')

    ms = np.ones((2, 3, 3))
    si2.set_array('ms', ms)
    efg = np.repeat([[[1, 0, 0], [0, 1, 0], [0, 0, -2]]], 2, axis=0)
    si2.set_array('efg', efg)

    calc = SinglePointDFTCalculator(si2)
    calc.results['sus'] = np.eye(3) * 2
    si2.calc = calc

    si2.info['magres_units'] = {'ms': 'ppm',
                                'efg': 'au',
                                'sus': '10^-6.cm^3.mol^-1'}

    write('si2_test.magres', si2)
    si2 = read('si2_test.magres')

    assert (np.trace(si2.get_array('ms')[0]) == 3)
    assert (np.all(np.isclose(si2.get_array('efg')[:, 2, 2], -2)))
    assert (np.all(np.isclose(si2.calc.results['sus'], np.eye(3) * 2)))