Overview

BornAgain contains no material database or chemical formula parser. Scattering length densities can instead be calculated in Python and passed to SLDMaterial. The periodictable package supplies chemical formulas, isotope data, and neutron and X-ray SLD calculations.

periodictable is not a BornAgain dependency. Install it in the environment that runs the calculation:

pip install periodictable

Neutron SLD

periodictable.neutron_sld expects density in g/cm³ and wavelength in angstroms. It returns the real, absorption, and incoherent SLD components in units of $10^{-6},\mathrm{Å}^{-2}$. BornAgain has no separate incoherent SLD component.

import bornagain as ba
import periodictable

silica_density = 2.2  # g/cm^3
neutron_wavelength = 4.75*ba.angstrom

sld_real, sld_imag, _incoherent = periodictable.neutron_sld(
    "SiO2",
    density=silica_density,
    wavelength=neutron_wavelength/ba.angstrom)

material = ba.SLDMaterial(
    "SiO2 for neutrons", (0.65, 0.75, 0.85), sld_real*1e-6, sld_imag*1e-6)

The second returned component is the nonnegative absorption magnitude, which matches the sld_imag convention of SLDMaterial.

X-ray SLD

The X-ray calculation uses the same density and output units:

import bornagain as ba
import periodictable

silica_density = 2.2  # g/cm^3
xray_wavelength = 1.5498*ba.angstrom  # 8 keV

sld_real, sld_imag = periodictable.xray_sld(
    "SiO2",
    density=silica_density,
    wavelength=xray_wavelength/ba.angstrom)

material = ba.SLDMaterial(
    "SiO2 for X-rays", (0.65, 0.75, 0.85), sld_real*1e-6, sld_imag*1e-6)

For X-rays, wavelength and energy are related by $\lambda,[\mathrm{Å}] = 12.398/E,[\mathrm{keV}]$.

Physical inputs and limitations

Mass density is required because a chemical formula alone does not specify material phase, porosity, or density. Isotopic formulas follow periodictable’s formula syntax.

For most nuclei the neutron SLD is wavelength-independent, but strong or resonant absorbers can be energy-dependent. X-ray SLD is generally wavelength-dependent. SLDMaterial stores the calculated value; it does not recalculate SLD when the wavelength changes within a scan. Use a fixed value only when dispersion over the scan range is negligible.

For interactive exploration, the same calculations are available through online interfaces:

Both use the periodictable package, so matching values check the formula, density, wavelength, and unit conversion rather than independently validating the underlying atomic data. The first calculator returns inverse square angstroms, which are the input units of SLDMaterial.

Complete example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.10"
# dependencies = ["bornagain>=25,<26", "periodictable"]
# ///
"""
Creates neutron and X-ray materials from chemical formulas and mass densities.
"""

import bornagain as ba
ba.require_versions("bornagain>=25,<26")
import periodictable
from bornagain import angstrom

silica_color = (0.65, 0.75, 0.85)
silica_density = 2.2  # g/cm^3
neutron_wavelength = 4.75*angstrom
xray_wavelength = 1.5498*angstrom  # 8 keV

# periodictable returns SLD components in 10^-6 A^-2. BornAgain has no
# separate incoherent SLD component.
neutron_sld_real, neutron_sld_imag, _incoherent = periodictable.neutron_sld(
    "SiO2",
    density=silica_density,
    wavelength=neutron_wavelength/angstrom)
neutron_sld_real *= 1e-6
neutron_sld_imag *= 1e-6
neutron_material = ba.SLDMaterial("SiO2 for neutrons", silica_color,
                                  neutron_sld_real, neutron_sld_imag)

xray_sld_real, xray_sld_imag = periodictable.xray_sld(
    "SiO2", density=silica_density, wavelength=xray_wavelength/angstrom)
xray_sld_real *= 1e-6
xray_sld_imag *= 1e-6
xray_material = ba.SLDMaterial("SiO2 for X-rays", silica_color,
                               xray_sld_real, xray_sld_imag)

print(f"SiO2 neutron SLD: {neutron_sld_real:.8g} - i {neutron_sld_imag:.8g} A^-2")
print(f"SiO2 X-ray SLD:   {xray_sld_real:.8g} - i {xray_sld_imag:.8g} A^-2")
auto/Examples/varia/MaterialFromFormula.py