Skip to main content

The package tool for neutron reflectivity analysis

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyreflect_nr-1.4.5.tar.gz (28.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyreflect_nr-1.4.5-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file pyreflect_nr-1.4.5.tar.gz.

File metadata

  • Download URL: pyreflect_nr-1.4.5.tar.gz
  • Upload date:
  • Size: 28.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for pyreflect_nr-1.4.5.tar.gz
Algorithm Hash digest
SHA256 a915970d5e6b3c6ac82075e6f90082ecf7e63ad0d1390ce97fbc2a051b0204d4
MD5 2e6f819a3135c458c710c6909c36bc74
BLAKE2b-256 fe722f30ecc7cb9dacdd4c7c8e0aa80508b93c3cf969e96822553e4ed7965244

See more details on using hashes here.

File details

Details for the file pyreflect_nr-1.4.5-py3-none-any.whl.

File metadata

  • Download URL: pyreflect_nr-1.4.5-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for pyreflect_nr-1.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7534484e53f21b4f9495290b8c029c096282c1d2b02b89c2371d603dffc71a40
MD5 6b96764b1e520e0e15c03320373f910c
BLAKE2b-256 0344dcec6aa1d59a6f9fb36eb2dc404110d6c39c4ee40d7e7f016f6dece53da0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page