示例#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=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)
示例#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=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)
示例#3
0
def test_preallocated_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)
    scan = GridScan(start=[0, 0], end=potential.extent, gpts=4)

    detector1 = AnnularDetector(inner=70, outer=100)
    probe = Probe(semiangle_cutoff=15,
                  energy=300e3,
                  extent=potential.extent,
                  gpts=512)

    measurement = detector1.allocate_measurement(probe, scan)
    probe.scan(scan, detector1, potential, measurement, pbar=False)

    assert np.any(measurement.array > 0)

    detector2 = PixelatedDetector()

    measurement1 = detector1.allocate_measurement(probe, scan)
    measurement2 = detector2.allocate_measurement(probe, scan)

    with pytest.raises(ValueError) as e:
        probe.scan(scan, [detector1, detector2],
                   potential,
                   measurement1,
                   pbar=False)

    probe.scan(scan, [detector1, detector2],
               potential, {
                   detector1: measurement1,
                   detector2: measurement2
               },
               pbar=False)
示例#4
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)