Example #1
0
def test_partition_measurement():
    atoms = read(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     'data/amorphous_carbon.cif'))
    potential = Potential(atoms,
                          gpts=512,
                          slice_thickness=1,
                          projection='infinite',
                          parametrization='kirkland').build(pbar=False)

    detector = AnnularDetector(inner=70, outer=100)
    gridscan = GridScan(start=[0, 0], end=potential.extent, gpts=16)

    S = SMatrix(expansion_cutoff=15, interpolation=1, energy=300e3)
    S = S.multislice(potential, pbar=False)

    measurements = S.scan(gridscan, [detector], pbar=False)

    scans = gridscan.partition_scan((2, 2))
    partitioned_measurements = {
        detector: detector.allocate_measurement(S.collapse((0, 0)), gridscan)
    }

    for scan in scans:
        partitioned_measurements = S.scan(scan, measurements, pbar=False)

    assert np.allclose(partitioned_measurements[detector].array,
                       measurements[detector].array)
Example #2
0
def test_partition_measurement():
    atoms = read(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     'data/amorphous_carbon.cif'))
    potential = Potential(atoms,
                          gpts=256,
                          slice_thickness=1,
                          projection='infinite',
                          parametrization='kirkland').build(pbar=False)

    detector = AnnularDetector(inner=70, outer=100)
    gridscan = GridScan(start=[0, 0], end=potential.extent, gpts=4)

    probe = Probe(semiangle_cutoff=15, energy=300e3)

    measurements = probe.scan(gridscan, detector, potential, pbar=False)

    scans = gridscan.partition_scan((2, 2))
    partitioned_measurements = detector.allocate_measurement(probe, gridscan)

    for scan in scans:
        probe.scan(scan,
                   detector,
                   potential,
                   measurements=partitioned_measurements,
                   pbar=False)

    assert np.allclose(partitioned_measurements.array, measurements.array)
Example #3
0
def test_partition():
    gridscan = GridScan(start=(0, 0), end=(2, 2), sampling=.5, endpoint=False)
    scans = gridscan.partition_scan((2, 2))
    positions = []
    for scan in scans:
        positions.append(scan.get_positions())

    assert np.allclose(((np.vstack(positions)[None] - gridscan.get_positions()[:, None]) ** 2).min(0), 0)
    assert np.allclose(((np.vstack(positions)[None] - gridscan.get_positions()[:, None]) ** 2).min(1), 0)

    gridscan = GridScan(start=(0, 0), end=(2, 2), sampling=.5, endpoint=True)
    scans = gridscan.partition_scan((2, 2))
    positions = []
    for scan in scans:
        positions.append(scan.get_positions())

    assert np.allclose(((np.vstack(positions)[None] - gridscan.get_positions()[:, None]) ** 2).min(0), 0)
    assert np.allclose(((np.vstack(positions)[None] - gridscan.get_positions()[:, None]) ** 2).min(1), 0)
Example #4
0
def test_crop():
    S = SMatrix(expansion_cutoff=30,
                interpolation=3,
                energy=300e3,
                extent=10,
                sampling=.02).build()
    gridscan = GridScan(start=[0, 0], end=S.extent, gpts=64)

    scans = gridscan.partition_scan((2, 2))
    cropped = S.crop_to_scan(scans[0])

    assert cropped.gpts != S.gpts

    position = (4.9, 0.)
    assert np.allclose(
        S.collapse(position).array - cropped.collapse(position).array, 0.)
Example #5
0
def test_cropped_scan():
    atoms = read(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     'data/amorphous_carbon.cif'))
    potential = Potential(atoms,
                          gpts=512,
                          slice_thickness=1,
                          device='gpu',
                          projection='infinite',
                          parametrization='kirkland',
                          storage='gpu').build(pbar=True)
    detector = AnnularDetector(inner=40, outer=60)
    gridscan = GridScan(start=[0, 0], end=potential.extent, gpts=16)

    S = SMatrix(expansion_cutoff=20,
                interpolation=4,
                energy=300e3,
                device='gpu',
                storage='cpu')  # .build()

    S = S.multislice(potential, pbar=True)
    S = S.downsample('limit')

    measurements = S.scan(gridscan, [detector], max_batch_probes=64)

    scans = gridscan.partition_scan((2, 2))
    cropped_measurements = {
        detector: detector.allocate_measurement(S.collapse((0, 0)), gridscan)
    }

    for scan in scans:
        cropped = S.crop_to_scan(scan)
        cropped = cropped.transfer('gpu')
        cropped_measurements = cropped.scan(scan,
                                            cropped_measurements,
                                            pbar=False)

    assert np.allclose(cropped_measurements[detector].array,
                       measurements[detector].array)