Esempio n. 1
0
def test_prism_raises():
    with pytest.raises(ValueError) as e:
        SMatrix(.01, 80e3, .5)

    assert str(e.value) == 'Interpolation factor must be int'

    with pytest.raises(RuntimeError) as e:
        prism = SMatrix(10, 80e3, 1)
        prism.build()

    assert str(e.value) == 'Grid extent is not defined'
Esempio n. 2
0
def test_downsample_smatrix():
    S = SMatrix(expansion_cutoff=10,
                interpolation=2,
                energy=300e3,
                extent=10,
                sampling=.05)
    S = S.build().downsample()

    S2 = SMatrix(expansion_cutoff=10,
                 interpolation=2,
                 energy=300e3,
                 extent=10,
                 gpts=S.gpts)
    S2 = S2.build()

    assert np.allclose(S.array - S2.array, 0., atol=5e-6)
Esempio n. 3
0
def test_unequal_interpolation():
    from ase.build import nanotube

    def make_atoms(l):
        atoms = nanotube(6, 0, length=l)
        atoms.rotate(-90, 'x', rotate_cell=True)
        atoms.center(vacuum=5, axis=(0, 1))

        cell = atoms.cell.copy()
        cell[1] = np.abs(atoms.cell[2])
        cell[2] = np.abs(atoms.cell[1])

        atoms.set_cell(cell)
        return atoms

    detector = AnnularDetector(50, 150)

    atoms1 = make_atoms(8)
    S1 = SMatrix(energy=80e3,
                 expansion_cutoff=10,
                 semiangle_cutoff=10,
                 interpolation=(2, 4),
                 device='cpu',
                 gpts=(256, 512))
    S1.extent = np.diag(atoms1.cell)[:2]
    scan = GridScan((0, 0), (atoms1.cell[0, 0], atoms1.cell[1, 1] / 2),
                    sampling=S1.ctf.nyquist_sampling * .9)
    measurement1 = S1.scan(scan, detector, atoms1, pbar=False)

    atoms2 = make_atoms(4)
    S2 = SMatrix(energy=80e3,
                 expansion_cutoff=10,
                 semiangle_cutoff=10,
                 interpolation=(2, 2),
                 device='cpu',
                 gpts=(256, 256))
    S2.extent = np.diag(atoms2.cell)[:2]
    scan = GridScan((0, 0), (atoms2.cell[0, 0], atoms2.cell[1, 1]),
                    sampling=S2.ctf.nyquist_sampling * .9)
    measurement2 = S2.scan(scan, detector, atoms2, pbar=False)

    assert len(S1) == len(S2)
    assert np.allclose((S1.build().collapse().intensity() -
                        S2.build().collapse().intensity()).array, 0)
    assert np.allclose((measurement2 - measurement1).array, 0, atol=1e-5)
Esempio n. 4
0
def test_prism_translate():
    S = SMatrix(30, 60e3, 1, extent=5, gpts=50)
    probe = Probe(extent=5,
                  gpts=50,
                  energy=60e3,
                  semiangle_cutoff=30,
                  rolloff=0)
    assert np.allclose(probe.build(np.array([(2.5, 2.5)])).array,
                       S.build().collapse([(2.5, 2.5)]).array,
                       atol=1e-5)
Esempio n. 5
0
def test_prism_match_probe():
    S = SMatrix(30., 60e3, 1, extent=5, gpts=50)
    probe = Probe(extent=5,
                  gpts=50,
                  energy=60e3,
                  semiangle_cutoff=30.,
                  rolloff=0.)
    assert np.allclose(probe.build([(0., 0.)]).array,
                       S.build().collapse([(0., 0.)]).array,
                       atol=2e-5)
Esempio n. 6
0
def test_prism_interpolation():
    S_builder = SMatrix(30, 60e3, 2, extent=10, gpts=100)
    probe = Probe(extent=5,
                  gpts=50,
                  energy=60e3,
                  semiangle_cutoff=30,
                  rolloff=0)
    assert np.allclose(probe.build(np.array([(2.5, 2.5)])).array,
                       S_builder.build().collapse([(2.5, 2.5)]).array,
                       atol=1e-5)
Esempio n. 7
0
def test_prism_tilt():
    S = SMatrix(semiangle_cutoff=30.,
                energy=60e3,
                interpolation=1,
                extent=5,
                gpts=50,
                tilt=(1, 2))
    S_array = S.build()
    wave = S_array.collapse()
    assert S_array.tilt == S.tilt == wave.tilt
Esempio n. 8
0
def test_prism_interpolation():
    S = SMatrix(semiangle_cutoff=30.,
                energy=60e3,
                interpolation=2,
                extent=10,
                gpts=100,
                rolloff=0.)
    probe = Probe(extent=5,
                  gpts=50,
                  energy=60e3,
                  semiangle_cutoff=30,
                  rolloff=0)

    probe_array = probe.build(np.array([(2.5, 2.5)])).array
    S_array = S.build().collapse([(2.5, 2.5)]).array

    assert np.allclose(probe_array, S_array, atol=1e-5)
Esempio n. 9
0
def test_prism_tilt():
    S = SMatrix(30., 60e3, 1, extent=5, gpts=50, tilt=(1, 2))
    S_array = S.build()
    wave = S_array.collapse()
    assert S_array.tilt == S.tilt == wave.tilt