Esempio n. 1
0
def test_case():
    """Test formulaUnits
    """
    input_test = input
    del input_test['formulaUnits']
    structure = Material(input_test)
    del structure
Esempio n. 2
0
def calc_NDreflWeights(npy_materialDef, hkls):

    if isinstance(npy_materialDef, dict):

        mat = Material(npy_materialDef)

        str_fac = {}

        for fi, fam in enumerate(hkls):

            str_fac[fi] = []

            for h in fam:

                str_fac[fi].append(_np.abs(mat.calc_nuc_str_fac(h))**2)

            str_fac[fi] = _np.average(str_fac[fi])

        #normalize
        norm = 1 / _np.max(list(str_fac.values()))

        for fi, fam in enumerate(hkls):

            str_fac[fi] *= norm

            if abs(str_fac[fi] - 1) < 1E-3: str_fac[fi] = 1

        return str_fac

    else:
        raise ValueError('supplied mat def not valid')
Esempio n. 3
0
def test_str_fac():
    """Tests various positions for structure factor
    """
    structure = Material(input)
    assert (np.abs(structure.calc_nuc_str_fac(
        (2., 0., 0.)))**2 - 1702170.4663405998 < 1e-6)
    assert (np.abs(structure.calc_nuc_str_fac(
        (2, 0, 0)))**2 - 1702170.4663405998 < 1e-6)
    assert (np.abs(structure.calc_nuc_str_fac(
        (0, 2., 0)))**2 - 1702170.4663405998 < 1e-6)
    assert (np.abs(structure.calc_nuc_str_fac(
        (0, 2, 0)))**2 - 1702170.4663405998 < 1e-6)

    ndarray_example = np.linspace(0.5, 1.5, 21)
    assert (
        np.sum(abs(structure.calc_nuc_str_fac(
            (ndarray_example, 0, 0)))**2) - 7058726.6759794801 < 1e-6)
    assert (
        np.sum(abs(structure.calc_nuc_str_fac(
            (0, ndarray_example, 0)))**2) - 7058726.6759794801 < 1e-6)
    assert (
        np.sum(abs(structure.calc_nuc_str_fac(
            (0, 0, ndarray_example)))**2) - 16831011.814390473 < 1e-6)
    assert (np.sum(
        abs(structure.calc_nuc_str_fac(
            (ndarray_example, ndarray_example, 0)))**2) - 10616602.544519115 <
            1e-6)

    list_example = list(ndarray_example)
    assert (np.sum(abs(structure.calc_nuc_str_fac(
        (list_example, 0, 0)))**2) - 7058726.6759794801 < 1e-6)
    assert (np.sum(abs(structure.calc_nuc_str_fac(
        (0, list_example, 0)))**2) - 7058726.6759794801 < 1e-6)
    assert (np.sum(abs(structure.calc_nuc_str_fac(
        (0, 0, list_example)))**2) - 16831011.814390473 < 1e-6)

    tuple_example = tuple(ndarray_example)
    assert (np.sum(abs(structure.calc_nuc_str_fac(
        (tuple_example, 0, 0)))**2) - 7058726.6759794801 < 1e-6)
    assert (np.sum(abs(structure.calc_nuc_str_fac(
        (0, tuple_example, 0)))**2) - 7058726.6759794801 < 1e-6)
    assert (np.sum(abs(structure.calc_nuc_str_fac(
        (0, 0, tuple_example)))**2) - 16831011.814390473 < 1e-6)
Esempio n. 4
0
def test_dynamic_susceptibility():
    """Test dynamic susceptibility
    """
    from neutronpy import Material
    input_mat = {'name': 'FeTe',
                 'composition': [{'ion': 'Fe', 'pos': [0.75, 0.25, 0.]},
                                 {'ion': 'Fe', 'pos': [1. - 0.75, 1. - 0.25, 0.0]},
                                 {'ion': 'Te', 'pos': [0.25, 0.25, 1. - 0.2839]},
                                 {'ion': 'Te', 'pos': [1. - 0.25, 1. - 0.25, 1. - (1. - 0.2839)]}],
                 'debye-waller': True,
                 'massNorm': True,
                 'formulaUnits': 1.,
                 'lattice': dict(abc=[3.81, 3.81, 6.25], abg=[90, 90, 90])}

    data = build_data()
    material = Material(input_mat)

    ki = Energy(energy=14.7).wavevector
    kf = Energy(energy=14.7 - data.e).wavevector

    assert (np.all(data.dynamic_susceptibility(material, 14.7) == 4 * np.pi / (
        material.total_scattering_cross_section) * ki / kf * data.detector * data.detailed_balance_factor))
Esempio n. 5
0
def test_volume():
    """Tests volume of unitcell
    """
    structure = Material(input)
    assert (structure.volume == 90.725624999999965)
Esempio n. 6
0
def test_N_atoms():
    """Tests number of atoms in X g of material
    """
    structure = Material(input)
    assert (structure.N_atoms(22) == 36110850351331465494528)
Esempio n. 7
0
def test_optimal_thickness():
    """Test optimal thickness calculation
    """
    structure = Material(input)
    assert (structure.calc_optimal_thickness() == 1.9552936422413782)
Esempio n. 8
0
def test_plot(mock_show):
    """Test unitcell plot
    """
    structure = Material(input)
    structure.plot_unit_cell()
Esempio n. 9
0
def test_total_scattering_cross_section():
    """Tests scattering cross section
    """
    structure = Material(input)
    assert (structure.total_scattering_cross_section == 31.880000000000003)
Esempio n. 10
0
    'Al',
    'composition': [
        dict(ion='Al', pos=[0, 0, 0]),
        dict(ion='Al', pos=[0.5, 0, 0.5]),
        dict(ion='Al', pos=[0.5, 0.5, 0]),
        dict(ion='Al', pos=[0, 0.5, 0.5])
    ],
    'lattice':
    dict(abc=[4.0495, 4.0495, 4.0495], abg=[90, 90, 90]),
    'debye-waller':
    False,
    'massNorm':
    False
}

al = Material(def_al)

str_fac = {}

for fi, fam in enumerate(symHKL):

    str_fac[hkls[fi]] = []

    for h in fam:

        str_fac[hkls[fi]].append(np.abs(al.calc_nuc_str_fac(h))**2)

    str_fac[hkls[fi]] = np.average(str_fac[hkls[fi]])

#normalize
norm = 1 / np.max(list(str_fac.values()))