def create_input_multislice():
    """
    Create the input multislice parameters

    """

    # Initialise the input and system configuration
    input_multislice = multem.Input()

    # Set simulation experiment
    input_multislice.simulation_type = "EWRS"

    # Electron-Specimen interaction model
    input_multislice.interaction_model = "Multislice"
    # input_multislice.potential_type = "Lobato_0_12"
    input_multislice.potential_type = "Peng_0_12"

    # Potential slicing
    input_multislice.potential_slicing = "dz_Proj"

    # Electron-Phonon interaction model
    input_multislice.pn_model = "Still_Atom"

    # Specimen thickness
    input_multislice.thick_type = "Whole_Spec"

    # Illumination model
    input_multislice.illumination_model = "Partial_Coherent"
    input_multislice.temporal_spatial_incoh = "Temporal_Spatial"

    # Set the energy
    input_multislice.E_0 = 300

    return input_multislice
Exemplo n.º 2
0
def create_input_multislice(n_phonons, single_phonon_conf=False):

    # Initialise the input and system configuration
    input_multislice = multem.Input()

    # Set simulation experiment
    input_multislice.simulation_type = "EWRS"

    # Electron-Specimen interaction model
    input_multislice.interaction_model = "Multislice"
    input_multislice.potential_type = "Lobato_0_12"

    # Potential slicing
    input_multislice.potential_slicing = "dz_Proj"

    # Electron-Phonon interaction model
    input_multislice.pn_model = "Still_Atom"
    input_multislice.pn_coh_contrib = 0
    input_multislice.pn_single_conf = False
    input_multislice.pn_nconf = 10
    input_multislice.pn_dim = 110
    input_multislice.pn_seed = 300_183

    # Specimen thickness
    input_multislice.thick_type = "Whole_Spec"

    # Illumination model
    input_multislice.illumination_model = "Partial_Coherent"
    input_multislice.temporal_spatial_incoh = "Temporal_Spatial"

    input_multislice.nx = 1024
    input_multislice.ny = 1024

    input_multislice.obj_lens_m = 0
    input_multislice.obj_lens_c_10 = 15.836
    input_multislice.obj_lens_c_30 = 1e-03
    input_multislice.obj_lens_c_50 = 0.00
    input_multislice.obj_lens_c_12 = 0.0
    input_multislice.obj_lens_phi_12 = 0.0
    input_multislice.obj_lens_c_23 = 0.0
    input_multislice.obj_lens_phi_23 = 0.0
    input_multislice.obj_lens_inner_aper_ang = 0.0
    input_multislice.obj_lens_outer_aper_ang = 24.0
    input_multislice.obj_lens_zero_defocus_type = "Last"
    input_multislice.obj_lens_zero_defocus_plane = 0

    return input_multislice
Exemplo n.º 3
0
import multem
import numpy
import pickle
from cu001_crystal import cu001_crystal

input_multislice = multem.Input()
system_conf = multem.SystemConfiguration()

system_conf.precision = "float"
system_conf.device = "host"

# Set simulation experiment
input_multislice.simulation_type = "HRTEM"

# Electron-Specimen interaction model
input_multislice.interaction_model = "Multislice"

# Potential slicing
input_multislice.potential_slicing = "Planes"

# Electron-Phonon interaction model
input_multislice.pn_model = "Frozen_Phonon"
input_multislice.pn_coh_contrib = 0
input_multislice.pn_single_conf = False
input_multislice.pn_nconf = 10
input_multislice.pn_dim = 110
input_multislice.pn_seed = 300183

# Specimen information
na = 16
nb = 16
Exemplo n.º 4
0
def test_input():

    stem_detector = multem.STEMDetector()
    stem_detector.type = "Test"
    stem_detector.cir = [(0, 1), (2, 3)]
    stem_detector.radial = [(0, [1, 2, 3, 4]), (2, [5, 6, 8, 9])]
    stem_detector.matrix = [(3, [1, 2, 3, 4]), (4, [5, 6, 7, 8])]

    input = multem.Input()
    input.interaction_model = "Interaction Model"
    input.potential_type = "Potential Type"
    input.operation_mode = "Operation Mode"
    input.memory_size = 10
    input.reverse_multislice = False

    input.pn_model = "Phonon Interaction Model"
    input.pn_coh_contrib = True
    input.pn_single_conf = False
    input.pn_nconf = 20
    input.pn_dim = 30
    input.pn_seed = 40

    input.spec_atoms = multem.AtomList([(1, 2, 3, 4, 5, 6, 7, 8),
                                        (2, 3, 4, 5, 6, 7, 8, 9)])

    input.spec_dz = 50.1
    input.spec_lx = 60.1
    input.spec_ly = 70.1
    input.spec_lz = 80.1
    input.spec_cryst_na = 90
    input.spec_cryst_nb = 100
    input.spec_cryst_nc = 110
    input.spec_cryst_a = 120.1
    input.spec_cryst_b = 130.1
    input.spec_cryst_c = 140.1
    input.spec_cryst_x0 = 150.1
    input.spec_cryst_y0 = 160.1
    input.spec_amorp = [(0.1, 0.2, 0.3), (0.4, 0.5, 0.6)]

    input.spec_rot_theta = 0
    input.spec_rot_u0 = (1, 2, 3)
    input.spec_rot_center_type = "Spec Rot Center Type"
    input.spec_rot_center_p = (4, 5, 6)

    input.thick_type = "Thick Type"
    input.thick = [1.1, 2.2, 3.3, 4.4]

    input.potential_slicing = "Potential Slicing"

    input.nx = 1
    input.ny = 2
    input.bwl = True

    input.simulation_type = "Simulation Type"

    input.iw_type = "IW Type"
    input.iw_psi = [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j]
    input.iw_x = [1.1, 2.2, 3.3, 4.4, 5.5]
    input.iw_y = [6.6, 7.7, 8.8, 9.9, 0.0]

    input.E_0 = 3.1
    input.theta = 4.1
    input.phi = 5.9

    input.illumination_model = "Illumination Model"
    input.temporal_spatial_incoh = "Temporal Spatial Incoherence"

    input.cond_lens_m = 1
    input.cond_lens_c_10 = 0.1
    input.cond_lens_c_12 = 0.2
    input.cond_lens_phi_12 = 0.3
    input.cond_lens_c_21 = 0.4
    input.cond_lens_phi_21 = 0.5
    input.cond_lens_c_23 = 0.6
    input.cond_lens_phi_23 = 0.7
    input.cond_lens_c_30 = 0.8
    input.cond_lens_c_32 = 0.9
    input.cond_lens_phi_32 = 1.0
    input.cond_lens_c_34 = 1.1
    input.cond_lens_phi_34 = 1.2
    input.cond_lens_c_41 = 1.3
    input.cond_lens_phi_41 = 1.4
    input.cond_lens_c_43 = 1.5
    input.cond_lens_phi_43 = 1.6
    input.cond_lens_c_45 = 1.7
    input.cond_lens_phi_45 = 1.8
    input.cond_lens_c_50 = 1.9
    input.cond_lens_c_52 = 2.0
    input.cond_lens_phi_52 = 2.1
    input.cond_lens_c_54 = 2.2
    input.cond_lens_phi_54 = 2.3
    input.cond_lens_c_56 = 2.4
    input.cond_lens_phi_56 = 2.5
    input.cond_lens_inner_aper_ang = 2.6
    input.cond_lens_outer_aper_ang = 2.7

    input.cond_lens_ssf_sigma = 0.1
    input.cond_lens_ssf_npoints = 2

    input.cond_lens_dsf_sigma = 0.3
    input.cond_lens_dsf_npoints = 4

    input.cond_lens_zero_defocus_type = "Cond Lens Zero Defocus Type"
    input.cond_lens_zero_defocus_plane = 0.123

    input.obj_lens_m = 12
    input.obj_lens_c_10 = 0.1
    input.obj_lens_c_12 = 0.2
    input.obj_lens_phi_12 = 0.3
    input.obj_lens_c_21 = 0.4
    input.obj_lens_phi_21 = 0.5
    input.obj_lens_c_23 = 0.6
    input.obj_lens_phi_23 = 0.7
    input.obj_lens_c_30 = 0.8
    input.obj_lens_c_32 = 0.9
    input.obj_lens_phi_32 = 0.10
    input.obj_lens_c_34 = 0.11
    input.obj_lens_phi_34 = 0.12
    input.obj_lens_c_41 = 0.13
    input.obj_lens_phi_41 = 0.14
    input.obj_lens_c_43 = 0.15
    input.obj_lens_phi_43 = 0.16
    input.obj_lens_c_45 = 0.17
    input.obj_lens_phi_45 = 0.18
    input.obj_lens_c_50 = 0.19
    input.obj_lens_c_52 = 0.20
    input.obj_lens_phi_52 = 0.21
    input.obj_lens_c_54 = 0.22
    input.obj_lens_phi_54 = 0.23
    input.obj_lens_c_56 = 0.24
    input.obj_lens_phi_56 = 0.25
    input.obj_lens_inner_aper_ang = 0.26
    input.obj_lens_outer_aper_ang = 0.27

    input.obj_lens_dsf_sigma = 0.1
    input.obj_lens_dsf_npoints = 20

    input.obj_lens_zero_defocus_type = "Obj Lens Zero Defocus Type"
    input.obj_lens_zero_defocus_plane = 1.1

    input.detector = stem_detector

    input.scanning_type = "Scanning Type"
    input.scanning_periodic = True
    input.scanning_ns = 20
    input.scanning_x0 = 0.1
    input.scanning_y0 = 0.2
    input.scanning_xe = 0.3
    input.scanning_ye = 0.4

    input.ped_nrot = 0.5
    input.ped_theta = 0.6

    input.hci_nrot = 0.7
    input.hci_theta = 0.8

    input.eels_Z = 20
    input.eels_E_loss = 0.9
    input.eels_collection_angle = 10.1
    input.eels_m_selection = 30
    input.eels_channelling_type = "EELS Channelling Type"

    input.eftem_Z = 50
    input.eftem_E_loss = 0.1
    input.eftem_collection_angle = 0.2
    input.eftem_m_selection = 60
    input.eftem_channelling_type = "EFTEM Channelling Type"

    input.output_area_ix_0 = 10
    input.output_area_iy_0 = 20
    input.output_area_ix_e = 30
    input.output_area_iy_e = 40

    def check():
        assert input.interaction_model == "Interaction Model"
        assert input.potential_type == "Potential Type"
        assert input.operation_mode == "Operation Mode"
        assert input.memory_size == 10
        assert input.reverse_multislice == False

        assert input.pn_model == "Phonon Interaction Model"
        assert input.pn_coh_contrib == True
        assert input.pn_single_conf == False
        assert input.pn_nconf == 20
        assert input.pn_dim == 30
        assert input.pn_seed == 40

        assert input.spec_atoms == pytest.approx(
            numpy.array([(1, 2, 3, 4, 5, 6, 7, 8), (2, 3, 4, 5, 6, 7, 8, 9)]))

        assert input.spec_dz == 50.1
        assert input.spec_lx == 60.1
        assert input.spec_ly == 70.1
        assert input.spec_lz == 80.1
        assert input.spec_cryst_na == 90
        assert input.spec_cryst_nb == 100
        assert input.spec_cryst_nc == 110
        assert input.spec_cryst_a == 120.1
        assert input.spec_cryst_b == 130.1
        assert input.spec_cryst_c == 140.1
        assert input.spec_cryst_x0 == 150.1
        assert input.spec_cryst_y0 == 160.1
        assert input.spec_amorp == pytest.approx(
            numpy.array([(0.1, 0.2, 0.3), (0.4, 0.5, 0.6)]))

        assert input.spec_rot_theta == 0
        assert input.spec_rot_u0 == pytest.approx((1, 2, 3))
        assert input.spec_rot_center_type == "Spec Rot Center Type"
        assert input.spec_rot_center_p == pytest.approx((4, 5, 6))

        assert input.thick_type == "Thick Type"
        assert tuple(input.thick) == pytest.approx([1.1, 2.2, 3.3, 4.4])

        assert input.potential_slicing == "Potential Slicing"

        assert input.nx == 1
        assert input.ny == 2
        assert input.bwl == True

        assert input.simulation_type == "Simulation Type"

        assert input.iw_type == "IW Type"
        assert input.iw_psi == [1 + 1j, 2 + 2j, 3 + 3j, 4 + 4j]
        assert input.iw_x == [1.1, 2.2, 3.3, 4.4, 5.5]
        assert input.iw_y == [6.6, 7.7, 8.8, 9.9, 0.0]

        assert input.E_0 == 3.1
        assert input.theta == 4.1
        assert input.phi == 5.9

        assert input.illumination_model == "Illumination Model"
        assert input.temporal_spatial_incoh == "Temporal Spatial Incoherence"

        assert input.cond_lens_m == 1
        assert input.cond_lens_c_10 == 0.1
        assert input.cond_lens_c_12 == 0.2
        assert input.cond_lens_phi_12 == 0.3
        assert input.cond_lens_c_21 == 0.4
        assert input.cond_lens_phi_21 == 0.5
        assert input.cond_lens_c_23 == 0.6
        assert input.cond_lens_phi_23 == 0.7
        assert input.cond_lens_c_30 == 0.8
        assert input.cond_lens_c_32 == 0.9
        assert input.cond_lens_phi_32 == 1.0
        assert input.cond_lens_c_34 == 1.1
        assert input.cond_lens_phi_34 == 1.2
        assert input.cond_lens_c_41 == 1.3
        assert input.cond_lens_phi_41 == 1.4
        assert input.cond_lens_c_43 == 1.5
        assert input.cond_lens_phi_43 == 1.6
        assert input.cond_lens_c_45 == 1.7
        assert input.cond_lens_phi_45 == 1.8
        assert input.cond_lens_c_50 == 1.9
        assert input.cond_lens_c_52 == 2.0
        assert input.cond_lens_phi_52 == 2.1
        assert input.cond_lens_c_54 == 2.2
        assert input.cond_lens_phi_54 == 2.3
        assert input.cond_lens_c_56 == 2.4
        assert input.cond_lens_phi_56 == 2.5
        assert input.cond_lens_inner_aper_ang == 2.6
        assert input.cond_lens_outer_aper_ang == 2.7

        assert input.cond_lens_ssf_sigma == 0.1
        assert input.cond_lens_ssf_npoints == 2

        assert input.cond_lens_dsf_sigma == 0.3
        assert input.cond_lens_dsf_npoints == 4

        assert input.cond_lens_zero_defocus_type == "Cond Lens Zero Defocus Type"
        assert input.cond_lens_zero_defocus_plane == 0.123

        assert input.obj_lens_m == 12
        assert input.obj_lens_c_10 == 0.1
        assert input.obj_lens_c_12 == 0.2
        assert input.obj_lens_phi_12 == 0.3
        assert input.obj_lens_c_21 == 0.4
        assert input.obj_lens_phi_21 == 0.5
        assert input.obj_lens_c_23 == 0.6
        assert input.obj_lens_phi_23 == 0.7
        assert input.obj_lens_c_30 == 0.8
        assert input.obj_lens_c_32 == 0.9
        assert input.obj_lens_phi_32 == 0.10
        assert input.obj_lens_c_34 == 0.11
        assert input.obj_lens_phi_34 == 0.12
        assert input.obj_lens_c_41 == 0.13
        assert input.obj_lens_phi_41 == 0.14
        assert input.obj_lens_c_43 == 0.15
        assert input.obj_lens_phi_43 == 0.16
        assert input.obj_lens_c_45 == 0.17
        assert input.obj_lens_phi_45 == 0.18
        assert input.obj_lens_c_50 == 0.19
        assert input.obj_lens_c_52 == 0.20
        assert input.obj_lens_phi_52 == 0.21
        assert input.obj_lens_c_54 == 0.22
        assert input.obj_lens_phi_54 == 0.23
        assert input.obj_lens_c_56 == 0.24
        assert input.obj_lens_phi_56 == 0.25
        assert input.obj_lens_inner_aper_ang == 0.26
        assert input.obj_lens_outer_aper_ang == 0.27

        assert input.obj_lens_dsf_sigma == 0.1
        assert input.obj_lens_dsf_npoints == 20

        assert input.obj_lens_zero_defocus_type == "Obj Lens Zero Defocus Type"
        assert input.obj_lens_zero_defocus_plane == 1.1

        assert input.detector.type == "Test"
        assert input.detector.cir == [(0, 1), (2, 3)]
        assert input.detector.radial == [(0, [1, 2, 3, 4]), (2, [5, 6, 8, 9])]
        assert input.detector.matrix == [(3, [1, 2, 3, 4]), (4, [5, 6, 7, 8])]

        assert input.scanning_type == "Scanning Type"
        assert input.scanning_periodic == True
        assert input.scanning_ns == 20
        assert input.scanning_x0 == 0.1
        assert input.scanning_y0 == 0.2
        assert input.scanning_xe == 0.3
        assert input.scanning_ye == 0.4

        assert input.ped_nrot == 0.5
        assert input.ped_theta == 0.6

        assert input.hci_nrot == 0.7
        assert input.hci_theta == 0.8

        assert input.eels_Z == 20
        assert input.eels_E_loss == 0.9
        assert input.eels_collection_angle == 10.1
        assert input.eels_m_selection == 30
        assert input.eels_channelling_type == "EELS Channelling Type"

        assert input.eftem_Z == 50
        assert input.eftem_E_loss == 0.1
        assert input.eftem_collection_angle == 0.2
        assert input.eftem_m_selection == 60
        assert input.eftem_channelling_type == "EFTEM Channelling Type"

        assert input.output_area_ix_0 == 10
        assert input.output_area_iy_0 == 20
        assert input.output_area_ix_e == 30
        assert input.output_area_iy_e == 40

    check()

    input = pickle.loads(pickle.dumps(input))

    check()
def create_input_multislice(
    microscope, slice_thickness, margin, simulation_type, centre=None
):
    """
    Create the input multislice object

    Args:
        microscope (object): The microscope object
        slice_thickness (float): The slice thickness
        margin (int): The pixel margin

    Returns:
        object: The input multislice object

    """

    # Initialise the input and system configuration
    input_multislice = multem.Input()

    # Set simulation experiment
    input_multislice.simulation_type = simulation_type

    # Electron-Specimen interaction model
    input_multislice.interaction_model = "Multislice"
    input_multislice.potential_type = "Lobato_0_12"

    # Potential slicing
    # XXX If this is set to "Planes" then for the ribosome example I found that
    # the simulation would not work well (e.g. The image may have nothing or a
    # single point of intensity and nothing else). Best to keep this set to
    # dz_Proj.
    input_multislice.potential_slicing = "dz_Proj"

    # Electron-Phonon interaction model
    input_multislice.pn_model = "Still_Atom"  # "Frozen_Phonon"
    # input_multislice.pn_model = "Frozen_Phonon"
    input_multislice.pn_coh_contrib = 0
    input_multislice.pn_single_conf = False
    input_multislice.pn_nconf = 50
    input_multislice.pn_dim = 110
    input_multislice.pn_seed = 300_183

    # Set the slice thickness
    input_multislice.spec_dz = slice_thickness

    # Specimen thickness
    input_multislice.thick_type = "Whole_Spec"

    # x-y sampling
    input_multislice.nx = microscope.detector.nx + margin * 2
    input_multislice.ny = microscope.detector.ny + margin * 2
    input_multislice.bwl = False

    # Microscope parameters
    input_multislice.E_0 = microscope.beam.energy
    input_multislice.theta = 0.0
    input_multislice.phi = 0.0

    # Illumination model
    input_multislice.illumination_model = "Partial_Coherent"
    input_multislice.temporal_spatial_incoh = "Temporal_Spatial"

    # Condenser lens
    # source spread function
    ssf_sigma = multem.mrad_to_sigma(
        input_multislice.E_0, microscope.beam.source_spread
    )
    input_multislice.cond_lens_ssf_sigma = ssf_sigma

    # Objective lens
    input_multislice.obj_lens_m = microscope.lens.m
    input_multislice.obj_lens_c_10 = microscope.lens.c_10
    input_multislice.obj_lens_c_12 = microscope.lens.c_12
    input_multislice.obj_lens_phi_12 = microscope.lens.phi_12
    input_multislice.obj_lens_c_21 = microscope.lens.c_21
    input_multislice.obj_lens_phi_21 = microscope.lens.phi_21
    input_multislice.obj_lens_c_23 = microscope.lens.c_23
    input_multislice.obj_lens_phi_23 = microscope.lens.phi_23
    input_multislice.obj_lens_c_30 = microscope.lens.c_30
    input_multislice.obj_lens_c_32 = microscope.lens.c_32
    input_multislice.obj_lens_phi_32 = microscope.lens.phi_32
    input_multislice.obj_lens_c_34 = microscope.lens.c_34
    input_multislice.obj_lens_phi_34 = microscope.lens.phi_34
    input_multislice.obj_lens_c_41 = microscope.lens.c_41
    input_multislice.obj_lens_phi_41 = microscope.lens.phi_41
    input_multislice.obj_lens_c_43 = microscope.lens.c_43
    input_multislice.obj_lens_phi_43 = microscope.lens.phi_43
    input_multislice.obj_lens_c_45 = microscope.lens.c_45
    input_multislice.obj_lens_phi_45 = microscope.lens.phi_45
    input_multislice.obj_lens_c_50 = microscope.lens.c_50
    input_multislice.obj_lens_c_52 = microscope.lens.c_52
    input_multislice.obj_lens_phi_52 = microscope.lens.phi_52
    input_multislice.obj_lens_c_54 = microscope.lens.c_54
    input_multislice.obj_lens_phi_54 = microscope.lens.phi_54
    input_multislice.obj_lens_c_56 = microscope.lens.c_56
    input_multislice.obj_lens_phi_56 = microscope.lens.phi_56
    input_multislice.obj_lens_inner_aper_ang = microscope.lens.inner_aper_ang
    input_multislice.obj_lens_outer_aper_ang = microscope.lens.outer_aper_ang

    # Do we have a phase plate
    if microscope.phase_plate:
        input_multislice.phase_shift = pi / 2.0

    # defocus spread function
    input_multislice.obj_lens_dsf_sigma = multem.iehwgd_to_sigma(
        defocus_spread(
            microscope.lens.c_c * 1e-3 / 1e-10,  # Convert from mm to A
            microscope.beam.energy_spread,
            microscope.lens.current_spread,
            microscope.beam.acceleration_voltage_spread,
        )
    )

    # zero defocus reference
    if centre is not None:
        input_multislice.cond_lens_zero_defocus_type = "User_Define"
        input_multislice.obj_lens_zero_defocus_type = "User_Define"
        input_multislice.cond_lens_zero_defocus_plane = centre
        input_multislice.obj_lens_zero_defocus_plane = centre
    else:
        input_multislice.cond_lens_zero_defocus_type = "Last"
        input_multislice.obj_lens_zero_defocus_type = "Last"

    # Return the input multislice object
    return input_multislice