CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-periodictable

Extensible periodic table of the elements with support for mass, density and X-ray/neutron scattering information

Pending
Overview
Eval results
Files

neutron-scattering.mddocs/

Neutron Scattering

Comprehensive neutron scattering calculations including scattering length densities, cross sections, penetration depths, and wavelength conversions for elements, isotopes, and compounds with energy-dependent and activation analysis support.

Capabilities

Scattering Length Density Calculations

Calculate neutron scattering length densities for materials, which are fundamental for neutron reflectometry, small-angle neutron scattering, and other neutron techniques.

def neutron_sld(compound, density: float = None, wavelength: float = None,
               energy: float = None) -> tuple:
    """
    Calculate neutron scattering length density for a compound.
    
    Args:
        compound: Formula string, Formula object, or list of (atom, count) pairs
        density: Mass density in g/cm³ (uses compound.density if available)
        wavelength: Neutron wavelength in Ångström (default 1.798 Å)
        energy: Neutron energy in meV (alternative to wavelength)
        
    Returns:
        tuple: (sld_real, sld_imag, sld_incoh) in units of 10⁻⁶ Ų⁻²
            sld_real: Real scattering length density (coherent)
            sld_imag: Imaginary scattering length density (absorption)
            sld_incoh: Incoherent scattering length density
    """

def neutron_sld_from_atoms(atoms: dict, density: float, wavelength: float = None,
                          energy: float = None) -> tuple:
    """
    Low-level SLD calculation from atomic composition.
    
    Args:
        atoms: Dictionary mapping atoms to counts
        density: Mass density in g/cm³
        wavelength: Neutron wavelength in Ångström
        energy: Neutron energy in meV
        
    Returns:
        tuple: (sld_real, sld_imag, sld_incoh) in 10⁻⁶ Ų⁻² units
    """

Usage examples:

import periodictable as pt

# Simple compounds
water = pt.formula("H2O", density=1.0)
sld_real, sld_imag, sld_incoh = pt.neutron_sld(water)
print(f"H2O SLD: {sld_real:.4f} + {sld_imag:.4f}i (10⁻⁶ Ų⁻²)")
print(f"H2O incoherent SLD: {sld_incoh:.4f} (10⁻⁶ Ų⁻²)")

# Heavy water comparison
heavy_water = pt.formula("D2O", density=1.107)
d2o_sld = pt.neutron_sld(heavy_water)
print(f"D2O SLD: {d2o_sld[0]:.4f} (10⁻⁶ Ų⁻²)")

# At different wavelengths
thermal_sld = pt.neutron_sld(water, wavelength=1.8)    # Thermal neutrons
cold_sld = pt.neutron_sld(water, wavelength=4.0)      # Cold neutrons
print(f"H2O SLD at 1.8 Å: {thermal_sld[0]:.4f}")
print(f"H2O SLD at 4.0 Å: {cold_sld[0]:.4f}")

# Using energy instead of wavelength
energy_sld = pt.neutron_sld(water, energy=25.3)  # 25.3 meV = 1.798 Å
print(f"H2O SLD at 25.3 meV: {energy_sld[0]:.4f}")

# Complex materials
steel = pt.mix_by_weight("Fe", 95, "C", 0.8, "Cr", 4.2, density=7.8)
steel_sld = pt.neutron_sld(steel)
print(f"Steel SLD: {steel_sld[0]:.4f} (10⁻⁶ Ų⁻²)")

Comprehensive Scattering Calculations

Calculate complete neutron scattering properties including cross sections, penetration depths, and transmission coefficients.

def neutron_scattering(compound, density: float = None, wavelength: float = None,
                      energy: float = None) -> dict:
    """
    Calculate comprehensive neutron scattering properties.
    
    Args:
        compound: Formula string, Formula object, or atomic composition
        density: Mass density in g/cm³
        wavelength: Neutron wavelength in Ångström (default 1.798 Å)
        energy: Neutron energy in meV
        
    Returns:
        dict: Complete scattering information containing:
            'sld': (real, imag, incoherent) scattering length densities
            'xs_coherent': Coherent scattering cross section (cm⁻¹)
            'xs_incoherent': Incoherent scattering cross section (cm⁻¹)  
            'xs_absorption': Absorption cross section (cm⁻¹)
            'xs_total': Total cross section (cm⁻¹)
            'penetration_depth': 1/e penetration depth (cm)
            'transmission': Transmission per cm thickness
    """

Usage examples:

import periodictable as pt

# Complete scattering analysis
water = pt.formula("H2O", density=1.0)
scattering = pt.neutron_scattering(water)

print("Water neutron scattering properties:")
print(f"  SLD: {scattering['sld'][0]:.4f} × 10⁻⁶ Ų⁻²")
print(f"  Coherent XS: {scattering['xs_coherent']:.4f} cm⁻¹")
print(f"  Incoherent XS: {scattering['xs_incoherent']:.4f} cm⁻¹")
print(f"  Absorption XS: {scattering['xs_absorption']:.4f} cm⁻¹")
print(f"  Total XS: {scattering['xs_total']:.4f} cm⁻¹")
print(f"  Penetration depth: {scattering['penetration_depth']:.2f} cm")
print(f"  Transmission/cm: {scattering['transmission']:.4f}")

# Compare different materials
materials = [
    ("H2O", pt.formula("H2O", density=1.0)),
    ("D2O", pt.formula("D2O", density=1.107)),
    ("Al", pt.formula("Al", density=2.70)),
    ("Pb", pt.formula("Pb", density=11.34))
]

for name, material in materials:
    props = pt.neutron_scattering(material)
    print(f"{name}: SLD={props['sld'][0]:.2f}, μ={props['xs_total']:.3f} cm⁻¹")

Wavelength and Energy Conversions

Convert between neutron wavelength, energy, and velocity for different neutron sources and experimental conditions.

def neutron_wavelength(energy: float) -> float:
    """
    Convert neutron energy to wavelength.
    
    Args:
        energy: Neutron energy in meV
        
    Returns:
        Wavelength in Ångström
    """

def neutron_energy(wavelength: float) -> float:
    """
    Convert neutron wavelength to energy.
    
    Args:
        wavelength: Neutron wavelength in Ångström
        
    Returns:
        Energy in meV
    """

def neutron_wavelength_from_velocity(velocity: float) -> float:
    """
    Convert neutron velocity to wavelength.
    
    Args:
        velocity: Neutron velocity in m/s
        
    Returns:
        Wavelength in Ångström
    """

Usage examples:

import periodictable.nsf as nsf

# Thermal neutrons (room temperature ~25 meV)
thermal_energy = 25.3  # meV
thermal_wavelength = nsf.neutron_wavelength(thermal_energy)
print(f"Thermal neutrons: {thermal_energy} meV = {thermal_wavelength:.3f} Å")

# Cold neutrons  
cold_wavelength = 4.0  # Å
cold_energy = nsf.neutron_energy(cold_wavelength)
print(f"Cold neutrons: {cold_wavelength} Å = {cold_energy:.2f} meV")

# Hot neutrons
hot_energy = 100  # meV  
hot_wavelength = nsf.neutron_wavelength(hot_energy)
print(f"Hot neutrons: {hot_energy} meV = {hot_wavelength:.3f} Å")

# From velocity (e.g., neutron velocity selector)
velocity = 2200  # m/s (typical thermal neutron velocity)
wavelength = nsf.neutron_wavelength_from_velocity(velocity)
energy = nsf.neutron_energy(wavelength)
print(f"Velocity {velocity} m/s = {wavelength:.3f} Å = {energy:.2f} meV")

# Common neutron sources
sources = [
    ("Thermal (reactor)", 1.8, nsf.neutron_energy(1.8)),
    ("Cold (guide)", 4.0, nsf.neutron_energy(4.0)),
    ("Epithermal", 1.0, nsf.neutron_energy(1.0)),
    ("Hot", 0.5, nsf.neutron_energy(0.5))
]

for name, wl, energy in sources:
    print(f"{name}: {wl} Å = {energy:.1f} meV")

Composite Material SLD

Calculate scattering length densities for composite materials and multi-phase systems with volume-weighted averaging.

def neutron_composite_sld(parts: list, density: float = None, 
                         wavelength: float = None) -> tuple:
    """
    Calculate SLD for composite materials with multiple phases.
    
    Args:
        parts: List of (formula, volume_fraction) pairs
        density: Overall density if known (otherwise calculated)
        wavelength: Neutron wavelength in Ångström
        
    Returns:
        tuple: (sld_real, sld_imag, sld_incoh) for composite
    """

Usage examples:

import periodictable as pt
from periodictable.nsf import neutron_composite_sld

# Polymer composite: 70% polymer + 30% filler by volume
polymer = pt.formula("C8H8", density=1.05, name="Polystyrene")  
filler = pt.formula("SiO2", density=2.20, name="Silica")

composite_parts = [
    (polymer, 0.70),    # 70% polymer by volume
    (filler, 0.30)      # 30% silica by volume
]

composite_sld = neutron_composite_sld(composite_parts)
print(f"Composite SLD: {composite_sld[0]:.4f} × 10⁻⁶ Ų⁻²")

# Porous material: solid + voids
solid = pt.formula("Al2O3", density=3.95)
air = pt.formula("N2+3.76Ar", density=0.001225)  # Approximation for air

porous_parts = [
    (solid, 0.80),      # 80% solid
    (air, 0.20)         # 20% porosity
]

porous_sld = neutron_composite_sld(porous_parts)
print(f"Porous Al2O3 SLD: {porous_sld[0]:.4f} × 10⁻⁶ Ų⁻²")

Data Tables and Comparisons

Generate formatted tables comparing neutron properties across elements and isotopes for data analysis and reference.

def sld_table(table: PeriodicTable = None) -> None:
    """Print neutron SLD table for all elements."""

def energy_dependent_table(table: PeriodicTable = None) -> None:
    """List isotopes with energy-dependent scattering."""

def absorption_comparison_table(table: PeriodicTable = None) -> None:
    """Compare neutron absorption cross sections."""

def coherent_comparison_table(table: PeriodicTable = None) -> None:
    """Compare coherent scattering cross sections."""

def incoherent_comparison_table(table: PeriodicTable = None) -> None:
    """Compare incoherent scattering cross sections."""

def total_comparison_table(table: PeriodicTable = None) -> None:
    """Compare total scattering cross sections."""

Usage examples:

import periodictable.nsf as nsf

# Print SLD table for all elements
nsf.sld_table()

# Show elements with energy-dependent scattering
nsf.energy_dependent_table()

# Compare absorption properties
nsf.absorption_comparison_table()

# Compare scattering properties
nsf.coherent_comparison_table()
nsf.incoherent_comparison_table()
nsf.total_comparison_table()

Element Neutron Properties

Access detailed neutron scattering properties for individual elements and isotopes through the Neutron class attached to atomic objects.

class Neutron:
    """Neutron scattering properties for elements and isotopes."""
    
    # Scattering lengths (fm)
    b_c: complex        # Coherent scattering length  
    b_inc: float        # Incoherent scattering length
    
    # Cross sections (barns)
    sigma_coh: float    # Coherent cross section
    sigma_inc: float    # Incoherent cross section  
    sigma_abs: float    # Absorption cross section
    sigma_tot: float    # Total cross section
    
    # Nuclear properties
    abundance: float    # Natural abundance (%)
    nuclear_spin: float # Nuclear spin quantum number
    
    def sld(self, density: float = None) -> tuple:
        """Calculate SLD for this isotope at given density."""
    
    def has_sld(self) -> bool:
        """Check if SLD calculation is possible."""

Usage examples:

import periodictable as pt

# Element neutron properties
hydrogen = pt.H
if hasattr(hydrogen, 'neutron') and hydrogen.neutron:
    print(f"H coherent length: {hydrogen.neutron.b_c:.3f} fm")
    print(f"H incoherent XS: {hydrogen.neutron.sigma_inc:.1f} barns")
    print(f"H absorption XS: {hydrogen.neutron.sigma_abs:.3f} barns")

# Isotope properties
isotopes = [pt.H[1], pt.H[2], pt.H[3]]  # H, D, T
for iso in isotopes:
    if hasattr(iso, 'neutron') and iso.neutron:
        print(f"{iso} b_c: {iso.neutron.b_c:.3f} fm")

# Check all nickel isotopes
print("Nickel isotope SLDs:")
for iso in pt.Ni:
    if hasattr(iso, 'neutron') and iso.neutron and iso.neutron.has_sld():
        sld = iso.neutron.sld(density=8.9)  # Ni density
        print(f"{iso}: {sld[0]:.4f} × 10⁻⁶ Ų⁻²")

# Compare different elements
elements = [pt.H, pt.D, pt.C, pt.N, pt.O, pt.Si, pt.Fe]
print("Element neutron properties:")
for el in elements:
    if hasattr(el, 'neutron') and el.neutron:
        print(f"{el.symbol:2s}: b_c={el.neutron.b_c:.2f} fm, "
              f"σ_abs={el.neutron.sigma_abs:.2f} barns")

Constants and Reference Values

Standard reference values and wavelengths used in neutron scattering calculations.

ABSORPTION_WAVELENGTH: float = 1.798  # Reference wavelength in Ångström for absorption XS

Usage examples:

import periodictable.nsf as nsf

# Reference wavelength for absorption cross sections
print(f"Standard wavelength: {nsf.ABSORPTION_WAVELENGTH} Å")

# Convert absorption XS to other wavelengths
# σ_abs(λ) = σ_abs(λ_ref) × (λ/λ_ref)
lambda_new = 4.0  # Å
scaling_factor = lambda_new / nsf.ABSORPTION_WAVELENGTH
print(f"Absorption XS scaling for {lambda_new} Å: {scaling_factor:.3f}×")

Types

class Neutron:
    """Neutron scattering properties for elements and isotopes."""
    b_c: complex
    b_inc: float
    sigma_coh: float
    sigma_inc: float
    sigma_abs: float
    sigma_tot: float
    abundance: float
    nuclear_spin: float
    def sld(self, density: float = None) -> tuple: ...
    def has_sld(self) -> bool: ...

ABSORPTION_WAVELENGTH: float = 1.798

Install with Tessl CLI

npx tessl i tessl/pypi-periodictable

docs

constants-utilities.md

elements.md

formulas.md

index.md

neutron-scattering.md

xray-scattering.md

tile.json