Material from formula

Python script

 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/sample/MaterialFromFormula.py