Exemple #1
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')
Exemple #2
0
def test_case():
    """Test formulaUnits
    """
    input_test = input
    del input_test['formulaUnits']
    structure = Material(input_test)
    del structure
Exemple #3
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))
def test_optimal_thickness():
    """Test optimal thickness calculation
    """
    structure = Material(input)
    assert (structure.calc_optimal_thickness() == 1.9552936422413782)
def test_plot(mock_show):
    """Test unitcell plot
    """
    structure = Material(input)
    structure.plot_unit_cell()
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)
from neutronpy import Material
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
h, k = np.meshgrid(np.linspace(0, 2, 81), np.linspace(0, 2, 81))
def_FeTe = {'name': 'Fe1.1Te',
            'composition': [{'ion': 'Fe', 'pos': [0.75, 0.25, 0.0]},
                            {'ion': 'Fe', 'pos': [0.25, 0.75, 0.0]},
                            {'ion': 'Te', 'pos': [0.25, 0.25, 0.2839]},
                            {'ion': 'Te', 'pos': [0.75, 0.75, -0.2839]},
                            {'ion': 'Fe', 'pos': [0.25, 0.25, 0.721], 'occupancy': 0.1},
                            {'ion': 'Fe', 'pos': [0.75, 0.75, -0.721], 'occupancy': 0.1}],
            'debye-waller': False,
            'massNorm': False,
            'lattice': {'abc': [3.81, 3.81, 6.25],
                        'abg': [90, 90, 90]}}
FeTe = Material(def_FeTe)
str_fac = 0.25 * (np.abs(FeTe.calc_nuc_str_fac((h, k, 0))) ** 2 +
                  np.abs(FeTe.calc_nuc_str_fac((-h, k, 0))) ** 2 +
                  np.abs(FeTe.calc_nuc_str_fac((h, -k, 0))) ** 2 +
                  np.abs(FeTe.calc_nuc_str_fac((-h, -k, 0))) ** 2)
plt.pcolormesh(h, k, str_fac, cmap=cm.jet)
plt.xlabel('h (r.l.u.)')
plt.ylabel('k (r.l.u.)')
plt.show()
from neutronpy import Material
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
h, k = np.meshgrid(np.linspace(0, 2, 81), np.linspace(0, 2, 81))
def_FeTe = {'name': 'Fe1.1Te',
            'composition': [{'ion': 'Fe', 'pos': [0.75, 0.25, 0.0]},
                            {'ion': 'Fe', 'pos': [0.25, 0.75, 0.0]},
                            {'ion': 'Te', 'pos': [0.25, 0.25, 0.2839]},
                            {'ion': 'Te', 'pos': [0.75, 0.75, -0.2839]},
                            {'ion': 'Fe', 'pos': [0.25, 0.25, 0.721], 'occupancy': 0.1},
                            {'ion': 'Fe', 'pos': [0.75, 0.75, -0.721], 'occupancy': 0.1}],
            'debye-waller': False,
            'massNorm': False,
            'lattice': {'abc': [3.81, 3.81, 6.25],
                        'abg': [90, 90, 90]},
            'space_group': 'P4/nmm'}
FeTe = Material(def_FeTe)
str_fac = np.abs(FeTe.calc_nuc_str_fac((h, k, 0))) ** 2
plt.pcolormesh(h, k, str_fac, cmap=cm.jet)
plt.xlabel('h (r.l.u.)')
plt.ylabel('k (r.l.u.)')
plt.show()
Exemple #9
0
def test_volume():
    """Tests volume of unitcell
    """
    structure = Material(input)
    assert (structure.volume == 90.725624999999965)
Exemple #10
0
def test_N_atoms():
    """Tests number of atoms in X g of material
    """
    structure = Material(input)
    assert (structure.N_atoms(22) == 36110850351331465494528)
Exemple #11
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)
Exemple #12
0
def test_optimal_thickness():
    """Test optimal thickness calculation
    """
    structure = Material(input)
    assert (structure.calc_optimal_thickness() == 1.9552936422413782)
Exemple #13
0
def test_plot(mock_show):
    """Test unitcell plot
    """
    structure = Material(input)
    structure.plot_unit_cell()
Exemple #14
0
def test_total_scattering_cross_section():
    """Tests scattering cross section
    """
    structure = Material(input)
    assert (structure.total_scattering_cross_section == 31.880000000000003)
Exemple #15
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()))