Pytorch based crystallographic refinement
Project description
TorchRef
A PyTorch-based crystallographic refinement library
TorchRef is a crystallographic refinement package built entirely on PyTorch. By leveraging PyTorch's automatic differentiation and GPU acceleration, TorchRef enables seamless integration with machine learning workflows and provides a flexible, extensible framework for crystallographic structure refinement.
Key Features
-
Native PyTorch Integration: Built on PyTorch's
nn.Modulearchitecture, TorchRef integrates naturally with the PyTorch ecosystem, including machine learning models, optimizers, and GPU acceleration. -
Automatic Differentiation: Dynamic computational graphs eliminate the need for manually implemented gradient calculations. Define new refinement targets directly—PyTorch handles the derivatives automatically.
-
Modular Architecture: Following PyTorch's module pattern, components are easily composable and extensible. Add custom targets, restraints, or optimizers without modifying core code.
-
GPU Acceleration: Leverage CUDA for structure factor calculations, scaling, and optimization—achieving significant speedups for large structures.
-
FFT-based Structure Factors: Efficient structure factor calculation using Fast Fourier Transform (FFT) methods, enabling rapid F_calc computation even for large unit cells.
-
State Management: Full
state_dictsupport enables saving and loading complete refinement states, including model parameters, scaler settings, and restraints.
Getting Started
Installation
pip install torchref
Local installation for development
clone the repository
git clone https://github.com/HatPdotS/TorchRef.git cd torchref
Install with pip
pip install -e .
Or install with development dependencies
pip install -e ".[dev]"
Dependencies
- Python ≥ 3.10
- PyTorch ≥ 2.40
- NumPy ≥ 2.0
- Gemmi ≥ 0.5
- reciprocalspaceship ≥ 0.9
- SciPy ≥ 1.7
Testing
# Run all tests
pytest tests/
# Run with coverage
pytest tests/ --cov=torchref
# Run specific test categories
pytest tests/unit/ # Fast unit tests
pytest tests/integration/ # Integration tests
pytest tests/functional/ # Full workflow tests
Contributing
Contributions are welcome! Please follow these guidelines:
- Follow the NumPy docstring style
- Add tests for new functionality
- Ensure all tests pass before submitting
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torchref-0.4.3.tar.gz.
File metadata
- Download URL: torchref-0.4.3.tar.gz
- Upload date:
- Size: 2.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60a6e59ab0211eac6c01fc5c1b25336fd42dac41a16238ed6562d76dfe757a44
|
|
| MD5 |
fd9141c090ec75d794497b70f17e6100
|
|
| BLAKE2b-256 |
cc11709f9abb6ad3da0752480f1a77de7d3c311393d6193f89d6ce18cc7d5099
|
Provenance
The following attestation bundles were made for torchref-0.4.3.tar.gz:
Publisher:
publish.yml on HatPdotS/TorchRef
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchref-0.4.3.tar.gz -
Subject digest:
60a6e59ab0211eac6c01fc5c1b25336fd42dac41a16238ed6562d76dfe757a44 - Sigstore transparency entry: 1080496114
- Sigstore integration time:
-
Permalink:
HatPdotS/TorchRef@061fe432a2ae30779355e06530fd2996712c2368 -
Branch / Tag:
refs/tags/0.4.3 - Owner: https://github.com/HatPdotS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@061fe432a2ae30779355e06530fd2996712c2368 -
Trigger Event:
release
-
Statement type:
File details
Details for the file torchref-0.4.3-py3-none-any.whl.
File metadata
- Download URL: torchref-0.4.3-py3-none-any.whl
- Upload date:
- Size: 3.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a24cd0d1859c7d39cb96edfa1a92cc34d129c30ffae718e0693c1814d679d1f
|
|
| MD5 |
882adbd40c55cd630dba52b16771bd18
|
|
| BLAKE2b-256 |
a73a847415e01c63f1d7d71316d541be7464628096ed37f5fc9020d147463263
|
Provenance
The following attestation bundles were made for torchref-0.4.3-py3-none-any.whl:
Publisher:
publish.yml on HatPdotS/TorchRef
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torchref-0.4.3-py3-none-any.whl -
Subject digest:
5a24cd0d1859c7d39cb96edfa1a92cc34d129c30ffae718e0693c1814d679d1f - Sigstore transparency entry: 1080496158
- Sigstore integration time:
-
Permalink:
HatPdotS/TorchRef@061fe432a2ae30779355e06530fd2996712c2368 -
Branch / Tag:
refs/tags/0.4.3 - Owner: https://github.com/HatPdotS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@061fe432a2ae30779355e06530fd2996712c2368 -
Trigger Event:
release
-
Statement type: