Skip to main content

nbragg

nbragg logo

CI Documentation Status PyPI version Python versions License: MIT

nbragg is a package designed for fitting neutron Bragg edge data using NCrystal cross-sections. This tool provides a straightforward way to analyze neutron transmission through polycrystalline materials, leveraging Bragg edges to extract information on material structure and composition.

Quick Example

Fit a measured iron-powder transmission spectrum in a few lines:

import nbragg

data = nbragg.Data.from_transmission("iron_powder.csv") # read data
xs = nbragg.CrossSection(iron="Fe_sg229_Iron-alpha.ncmat") # define sample
model = nbragg.TransmissionModel(xs, vary_background=True, vary_response=True) # define model
result = model.fit(data) # perform fit
result.plot() # plot results

Fit Results

Features

  • Flexible Cross-Section Calculations: Interfaces with NCrystal to fetch cross-sections for crystalline materials.
  • Multi-Phase and Oriented Materials: Combine phases with simple arithmetic (xs = 0.5*alpha + 0.5*gamma), and model textured or single-crystal samples with full orientation control.
  • Grouped/Gridded Data Fitting: Analyze spatially-resolved or multi-sample data with support for 1D arrays, 2D grids, and named groups. Includes parallel fitting with automatic result visualization via parameter maps.
  • Rietveld-Type Analysis: Iterative, staged refinement of Bragg edge data, accumulating parameters across stages for robust fitting.
  • MTEX Integration: Import phase weights and orientation distributions exported from MTEX for texture analysis.
  • SANS Modeling: Built-in support for Small Angle Neutron Scattering (SANS) using hard-sphere models for samples with nanoscale features.
  • Extinction Effects: Support for primary and secondary extinction modeling for large crystallites and thick samples.
  • Built-In Response and Background Functions: Includes predefined models for instrument response (e.g., Jorgensen, square) and background components (polynomial functions).
  • LMFit Integration: Flexible, nonlinear fitting of experimental data using the powerful lmfit library.
  • Save and Load: JSON-based persistence of models and fit results for reproducible analysis sessions.
  • Pythonic API: Simple to use, yet flexible enough for custom modeling.
  • Plotting Utilities: Ready-to-use plotting functions for easy visualization of data, cross-sections, and fit results.

Installation

nbragg requires Python 3.9 or later.

Basic Installation

To install the base package from PyPI:

pip install nbragg

Installation with Extinction Effects

To include extinction effects in your analysis, you'll need to install the extinction plugin separately:

pip install nbragg
pip install git+https://github.com/XuShuqi7/ncplugin-CrysExtn

The ncrystal-plugin-crysextn plugin provides extinction corrections for crystallographic calculations.

Note: The extinction plugin is only required if you plan to use extinction effects. For standard Bragg edge fitting without extinction corrections, the base installation is sufficient.

Tutorials and Documentation

Full documentation is available at nbragg.readthedocs.io.

Three Jupyter notebook tutorials cover the main workflows:

  1. Getting started with nbragg — data loading, cross-sections, model definition, fitting, oriented materials, and MTEX integration.
  2. Rietveld-type refinement — staged, parametric refinement of Bragg edge data.
  3. Grouped/gridded data fitting — spatially-resolved and multi-sample analysis with parallel fitting.

Citing nbragg

If you use nbragg in your research, please cite the accompanying paper:

T. Y. Hirsh, A. F. T. Leong, A. M. Long, D. D. DiJulio, S. Xu, G. Muhrer, T. H. Kittelmann, J. I. Marquez Damian, D. J. Savage and S. C. Vogel, nbragg: A Versatile Python Tool for Bragg-Edge Transmission Analysis Using NCrystal, Journal of Applied Crystallography (submitted, 2026).

BibTeX:

@article{nbragg2026,
  title   = {nbragg: A Versatile Python Tool for Bragg-Edge Transmission Analysis Using NCrystal},
  author  = {Hirsh, Tsviki Y. and Leong, Andrew F. T. and Long, Alexander M. and
             DiJulio, Douglas D. and Xu, Shuqi and Muhrer, G{\"u}nter and
             Kittelmann, Thomas H. and Marquez Damian, Jos{\'e} I. and
             Savage, Daniel J. and Vogel, Sven C.},
  journal = {Journal of Applied Crystallography},
  year    = {2026},
  note    = {Submitted}
}

Citation metadata is also provided in CITATION.cff, and GitHub's "Cite this repository" button generates BibTeX/APA entries automatically.

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines, and use the issue tracker to report bugs or request features.

License

nbragg is licensed under the MIT License.

Third-Party Dependencies

This project depends on several open-source packages with permissive licenses compatible with MIT:

  • scipy, pandas, numpy, lmfit: BSD/BSD 3-Clause
  • setuptools, tqdm: MIT License
  • matplotlib: PSF License
  • ncrystal: Apache 2.0 (license)

All dependencies allow free use, modification, and distribution.

Metadata

Release files for nbragg 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nbragg 1.0.0
File Size Uploaded Provenance Actions
nbragg-1.0.0.tar.gz 145.2 kB With provenance Details for nbragg-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nbragg 1.0.0
File Interpreter ABI Platform Actions
nbragg-1.0.0-py3-none-any.whl Python 3 none any Details for nbragg-1.0.0-py3-none-any.whl

Total release size: 254.2 kB

Release files / nbragg-1.0.0.tar.gz

Download URL nbragg-1.0.0.tar.gz
Size 145.2 kB
Tags Source
SHA-256 checksum
How to use checksums
470475b28255dcae1d9a14af4f55a5ec5984549a17b2494789e92bf074c39282
BLAKE2b-256 checksum
How to use checksums
710e3fa9afdb650a267e5bb4f2e4da39043c7ed4bd334d89a893db39f8f42aec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.

Transparency log

Release files / nbragg-1.0.0-py3-none-any.whl

Download URL nbragg-1.0.0-py3-none-any.whl
Size 109.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b26475249ba7a739ed3ccbe9c9147d8634dbcb256d1bbbe30805c88523049f1e
BLAKE2b-256 checksum
How to use checksums
51ba9861c5ecacbce2a77ccc02c76c2ba94b9e55f16e948d8ef91ee5f9433d11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.

Transparency log

Security for nbragg 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nbragg-1.0.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page