Skip to main content

NR-SCFT-ML: Neutron Reflectivity SCFT Machine Learning

A Python package for Neutron Reflectivity data analysis using Machine Learning.
Including Chi parameter prediction from SLD profile data and SLD profile prediction from NR curves.


Overview

NR-SCFT-ML (implemented as the pyreflect package) is a Python toolkit for efficient processing and analysis of Neutron Reflectivity (NR) data. It provides a streamlined pipeline for:

  • Preprocessing NR datasets
  • Predicting SLD profiles using CNN-based models
  • Predicting Chi parameters using a combined Autoencoder and MLP architecture

Prerequisites

  • Python >= 3.10
  • Strongly recommended: Conda (local machines and HPC clusters)
  • Optional: GPU with CUDA-capable PyTorch build for faster training and inference

Large-scale synthetic data generation and model training are memory intensive. HPC resources or a workstation with large RAM and optionally a GPU are recommended.


Installation

pyreflect depends on scientific Python libraries with native extensions (NumPy, SciPy, refnx, refl1d, etc.).
For reliability across platforms, Conda is the recommended installation method, especially on Windows and HPC systems.


Option 1. ✅ Recommended: Conda (Local or HPC)

1. Create and activate a Conda environment

conda create -n pyreflect python=3.10
conda activate pyreflect

2. Install scientific dependencies via conda-forge

conda install -c conda-forge \
    numpy scipy refnx refl1d numba llvmlite

3. Install pyreflect

pip install pyreflect-nr

After installation, you can access the CLI via:

python -m pyreflect --help

GPU support (optional)

For GPU-accelerated training and inference, install a CUDA-enabled PyTorch build inside the same environment, following the official PyTorch instructions for your system or cluster.


Option 2. 🛠 Automated setup (using setup.sh)

This repository provides a helper script setup.sh that:

  • Detects your Conda installation
  • Creates a Conda environment named pyreflect (Python 3.10)
  • Installs core scientific dependencies
  • Registers a Jupyter kernel called Python (pyreflect)

You can fetch and run it as follows:

curl -fsSLo setup.sh https://raw.githubusercontent.com/williamQyq/pyreflect/main/setup.sh
bash setup.sh

After it completes:

  • In Jupyter, select the Python (pyreflect) kernel
  • The environment is ready for use

⚠️ pip-only installation (not recommended on Windows)

A pure pip installation may work on Linux or macOS systems with a full build toolchain.
On Windows, this may require Microsoft C++ Build Tools and is not recommended.

python -m venv .venv
source .venv/bin/activate  # Windows: .venv\Scripts\activate
pip install --upgrade pip
pip install pyreflect-nr

If installation fails due to native extensions, switch to the Conda workflow above.


👩‍💻 Development setup (for contributors)

Poetry is used for development and maintenance, not for end-user installation.

git clone https://github.com/williamQyq/pyreflect.git
cd pyreflect

poetry install
poetry shell

You can then run:

python -m pyreflect --help

Example Notebooks

Example notebooks are available in the examples directory:

Tutorial video:

For detailed CLI usage, configuration, and typical research workflows, see docs/usage.md.


Credits

This project builds on work by:

  • Brian Qu (NR-SLD-CNN)
  • Dr. Rajeev Kumar
  • Prof. Miguel Fuentes-Cabrera (NR-SCFT-ML)
  • Shanshou Li
  • Hudson Kass
  • Francisco Jimenez

Author

Yuqing Qiao (William) – Maintainer and developer
Shanshou Li - Developer
Hudson Kass - Developer Francisco Jimenez - Validator

Metadata

Release files for pyreflect-nr 1.4.6

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

Source distribution (sdist)

Source distribution for pyreflect-nr 1.4.6
File Size Uploaded Provenance Actions
pyreflect_nr-1.4.6.tar.gz 28.6 kB Without provenance Details for pyreflect_nr-1.4.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pyreflect-nr 1.4.6
File Interpreter ABI Platform Actions
pyreflect_nr-1.4.6-py3-none-any.whl Python 3 none any Details for pyreflect_nr-1.4.6-py3-none-any.whl

Total release size: 64.6 kB

Release files / pyreflect_nr-1.4.6.tar.gz

Download URL pyreflect_nr-1.4.6.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8c86fd4fa30aa168712880ab0d452cbe9358e16ebc47b34e715d58ea1d11bba7
BLAKE2b-256 checksum
How to use checksums
a2cc7fcf5afa1f04ef31a8d2a6f651552f0552eb2993c87097f37dd5ce3799d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Release files / pyreflect_nr-1.4.6-py3-none-any.whl

Download URL pyreflect_nr-1.4.6-py3-none-any.whl
Size 36.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
02d0e876dbf4b13ec266f37f88df27ce9978b4b231225b27bb435fdfa6697dc8
BLAKE2b-256 checksum
How to use checksums
71374923855169e86661655b2829bc2f77bd650594d0272e9c34f192ed9cedb5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.9

Security for pyreflect-nr 1.4.6

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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