Esempio n. 1
0
def from_formula(formula):
    # Parse chemical formula
    formulaData = CHEMICAL_FORMULA_PARSER.parseString(formula)

    zs = []
    atomicfractions = []
    for symbol, atomicfraction in formulaData:
        zs.append(pyxray.element_atomic_number(symbol))
        atomicfractions.append(float(atomicfraction))

    # Calculate total atomic mass
    totalatomicmass = 0.0
    for z, atomicfraction in zip(zs, atomicfractions):
        atomicmass = pyxray.element_atomic_weight(z)
        totalatomicmass += atomicfraction * atomicmass

    # Create composition
    composition = defaultdict(float)

    for z, atomicfraction in zip(zs, atomicfractions):
        atomicmass = pyxray.element_atomic_weight(z)
        weightfraction = atomicfraction * atomicmass / totalatomicmass
        composition[z] += weightfraction

    return composition
Esempio n. 2
0
def convert_atomic_to_mass_fractions(atomic_fractions):
    """
    Converts an atomic fraction :class:`dict` to a mass fraction :class:`dict`.

    Args:
        atomic_fractions (dict): atomic fraction :class:`dict`.
            The composition is specified by a dictionary.
            The keys are atomic numbers and the values atomic fractions.
            No wildcard are accepted.
    """
    # Calculate total atomic mass
    atomic_masses = {}
    total_atomic_mass = 0.0
    for z, atomic_fraction in atomic_fractions.items():
        atomic_mass = pyxray.element_atomic_weight(z)
        atomic_masses[z] = atomic_mass
        total_atomic_mass += atomic_fraction * atomic_mass

    # Create mass fraction
    mass_fractions = {}
    for z, atomic_fraction in atomic_fractions.items():
        mass_fractions[
            z] = atomic_fraction * atomic_masses[z] / total_atomic_mass

    return mass_fractions
Esempio n. 3
0
    def read_material(cls, fileobj):
        """
        Reads a PENELOPE generated material file (.mat).
        
        :arg fileobj: file object opened with read access
        """
        first_line = fileobj.readline().strip()
        assert first_line[:8] == 'PENELOPE'

        line = fileobj.readline()
        _label, value = line.split()
        name = value.strip()

        line = fileobj.readline()
        _label, value = line.split('=')
        value, _unit = value.split()
        density_g_per_cm3 = float(value)

        line = fileobj.readline()
        _label, value = line.split('=')
        element_count = int(value)

        composition = {}
        totalatomicmass = 0.0
        for _ in range(element_count):
            line = fileobj.readline()
            part_z, part_af = line.split(',')

            _label, value = part_z.split('=')
            z = int(value)

            _label, value = part_af.split('=')
            atomicfraction = float(value)
            atomicmass = atomicfraction * pyxray.element_atomic_weight(z)

            composition[z] = atomicmass
            totalatomicmass += atomicmass

        for z, atomicmass in composition.items():
            composition[z] = atomicmass / totalatomicmass

        line = fileobj.readline()
        _label, value = line.split('=')
        value, _unit = value.split()
        mean_excitation_energy_eV = float(value)

        line = fileobj.readline()
        label, _value = line.split('=')
        assert label.strip() == 'Number of oscillators'

        line = fileobj.readline()
        _, value1, _, value2, _, _ = line.split()
        oscillator_strength_fcb = float(value1)
        oscillator_energy_wcb_eV = float(value2)

        return cls(name, composition, density_g_per_cm3,
                   mean_excitation_energy_eV, oscillator_strength_fcb,
                   oscillator_energy_wcb_eV)
Esempio n. 4
0
def kanaya_okayama(composition, energy):
    """
    Returns the electron range (in meters).

    :arg composition: composition in weight fraction.
        The composition is specified by a dictionary.
        The keys are the atomic numbers and the values are the weight fractions
        between ]0.0, 1.0].
    :type composition: :class:`dict`

    :arg energy: beam energy in eV
    """
    r = 0.0

    for z, fraction in composition.items():
        dr = (0.0276 * pyxray.element_atomic_weight(z) * (energy / 1000.0) ** 1.67) / \
            (z ** 0.89 * pyxray.element_mass_density_g_per_cm3(z))
        r += fraction / (dr * 1e-6)

    return 1.0 / r
Esempio n. 5
0
def to_atomic(composition):
    """
    Returns a composition :class:`dict` where the values are atomic fractions.

    :arg composition: composition in weight fraction.
        The composition is specified by a dictionary.
        The key are atomic numbers and the values weight fractions.
        No wildcard are accepted.
    :type composition: :class:`dict`
    """
    composition2 = {}

    for z, weightfraction in composition.items():
        composition2[z] = weightfraction / pyxray.element_atomic_weight(z)

    totalfraction = sum(composition2.values())

    for z, fraction in composition2.items():
        try:
            composition2[z] = fraction / totalfraction
        except ZeroDivisionError:
            composition2[z] = 0.0

    return defaultdict(float, composition2)
Esempio n. 6
0
def convert_atomic_to_mass_fractions(atomic_fractions):
    """
    Converts an atomic fraction :class:`dict` to a mass fraction :class:`dict`.

    Args:
        atomic_fractions (dict): atomic fraction :class:`dict`.
            The composition is specified by a dictionary.
            The keys are atomic numbers and the values atomic fractions.
            No wildcard are accepted.
    """
    # Calculate total atomic mass
    atomic_masses = {}
    total_atomic_mass = 0.0
    for z, atomic_fraction in atomic_fractions.items():
        atomic_mass = pyxray.element_atomic_weight(z)
        atomic_masses[z] = atomic_mass
        total_atomic_mass += atomic_fraction * atomic_mass

    # Create mass fraction
    mass_fractions = {}
    for z, atomic_fraction in atomic_fractions.items():
        mass_fractions[z] = atomic_fraction * atomic_masses[z] / total_atomic_mass

    return mass_fractions
Esempio n. 7
0
def convert_mass_to_atomic_fractions(mass_fractions):
    """
    Converts a mass fraction :class:`dict` to an atomic fraction :class:`dict`.

    Args:
        mass_fractions (dict): mass fraction :class:`dict`.
            The composition is specified by a dictionary.
            The keys are atomic numbers and the values weight fractions.
            No wildcard are accepted.
    """
    atomic_fractions = {}

    for z, mass_fraction in mass_fractions.items():
        atomic_fractions[z] = mass_fraction / pyxray.element_atomic_weight(z)

    total_fraction = sum(atomic_fractions.values())

    for z, fraction in atomic_fractions.items():
        try:
            atomic_fractions[z] = fraction / total_fraction
        except ZeroDivisionError:
            atomic_fractions[z] = 0.0

    return atomic_fractions
Esempio n. 8
0
def convert_mass_to_atomic_fractions(mass_fractions):
    """
    Converts a mass fraction :class:`dict` to an atomic fraction :class:`dict`.

    Args:
        mass_fractions (dict): mass fraction :class:`dict`.
            The composition is specified by a dictionary.
            The keys are atomic numbers and the values weight fractions.
            No wildcard are accepted.
    """
    atomic_fractions = {}

    for z, mass_fraction in mass_fractions.items():
        atomic_fractions[z] = mass_fraction / pyxray.element_atomic_weight(z)

    total_fraction = sum(atomic_fractions.values())

    for z, fraction in atomic_fractions.items():
        try:
            atomic_fractions[z] = fraction / total_fraction
        except ZeroDivisionError:
            atomic_fractions[z] = 0.0

    return atomic_fractions