A GPU-Accelerated Open-Source Python Package for Calculating Powder Diffraction, Small-Angle-, and Total Scattering with the Debye Scattering Equation
A GPU-Accelerated Open-Source Python Package for Calculating Powder Diffraction, Small-Angle-, and Total Scattering with the Debye Scattering Equation - Published in JOSS (2024)
Science Score: 100.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 10 DOI reference(s) in README and JOSS metadata -
✓Academic publication links
Links to: joss.theoj.org -
✓Committers with academic emails
5 of 5 committers (100.0%) from academic institutions -
○Institutional organization owner
-
✓JOSS paper metadata
Published in Journal of Open Source Software
Scientific Fields
Repository
A vectorised implementation of the Debye Scattering Equation on CPU and GPU
Basic Info
Statistics
- Stars: 33
- Watchers: 2
- Forks: 7
- Open Issues: 4
- Releases: 8
Metadata Files
README.md

Welcome to DebyeCalculator! This is a simple tool for calculating the scattering intensity $I(Q)$ through the Debye scattering equation, the Total Scattering Structure Function $S(Q)$, the Reduced Total Scattering Function $F(Q)$, and the Reduced Atomic Pair Distribution Function $G(r)$ from an atomic structure.
The Debye scattering equation can be used to compute the scattering pattern of any atomic structure and is commonly used to study both crystalline and non-crystalline materials with a range of scattering techniques like powder diffraction, total scattering with pair distribution function and small-angle scattering. Although the Debye scattering equation is extremely versatile, the computation of the double sum, which scales O(N2), has limited the practical use of the equation.
Here, we provide an optimised code for the calculation of the Debye scattering equation on Graphics processing units (GPUs) which accelerate the calculations with orders of magnitudes.
Installation
Prerequisites
DebyeCalculator requires Python version >=3.7, <3.12. If needed, create an environment with any of these Python versions:
bash
conda create -n debyecalculator_env python=3.9
bash
conda activate debyecalculator_env
Before installing the DebyeCalculator package, ensure that you have PyTorch installed. Follow the instructions on the official PyTorch website to install the appropriate version for your system: PyTorch Installation Guide.
NOTE: Installing an earlier version of PyTorch (<=1.13.1) will be necessary if you're running Python 3.7, since the latest PyTorch version requires Python 3.8 or higher.
Install with pip
Run the following command to install the DebyeCalculator package. (Requires: Python >=3.7, <3.12)
pip install debyecalculator
Install locally
Clone the repo
git clone https://github.com/FrederikLizakJohansen/DebyeCalculator.git
Run the following command to install the DebyeCalculator package. (Requires: Python >=3.7, <3.12)
python -m pip install .
Testing the local installation
To ensure that the installation is set up correctly and your environment is ready to go, we recommend running the included unit tests.
First, make sure you have pytest installed. If not, you can install it using:
bash
pip install pytest
After installing the package, open a terminal or command prompt and navigate to the root directory of the package. Then run the following command to execute the tests:
bash
pytest
GPU Support
The DebyeCalculator package supports GPU acceleration using PyTorch with CUDA. Follow these steps to enable GPU support:
1. Verify GPU Availability
After installing PyTorch with CUDA, you can check if your GPU is available by running the following code snippet in a Python environment:
python
import torch
print("CUDA available:", torch.cuda.is_available())
2. Specify GPU Device in DebyeCalculator
When creating an instance of DebyeCalculator, you can specify the device as 'cuda' to utilize GPU acceleration:
```python from debyecalculator import DebyeCalculator
calc = DebyeCalculator(device='cuda') ```
Usage
Interactive mode
IMPORTANT: CHANGES TO INTERACTIVE MODE AS OF JANUARY 2024 (DebyeCalculator version >=1.0.5) In the lastest version of DebyeCalculator, we are unfortunately experiences some issues with Google Colab that does not allow the package to display the interact() widget. If you experience any related issues, please refer to this statement for further clarification and workarounds.
Example Usage
This section provides quick examples on how to use the DebyeCalculator class for generating both total and partial scattering intensities from particle structures defined in .xyz files, .cif files, or directly from structure tuples.
Generating Scattering
To calculate the scattering intensity $I(Q)$ for a particle, you can use different structure sources:
```python from debyecalculator import DebyeCalculator import torch
Initialize the DebyeCalculator object
calc = DebyeCalculator(qmin=1.0, qmax=8.0, qstep=0.01)
Define structure sources
xyzfile = "somepath/somefile.xyz" ciffile = "somepath/somefile.cif" structure_tuple = ( ["Fe", "Fe", "O", "O"], torch.tensor( [[0.5377, 0.7068, 0.8589], [0.1576, 0.1456, 0.8799], [0.5932, 0.0204, 0.6759], [0.6946, 0.4114, 0.4869]] ) )
Calculate I(Q) from different sources
q, iqxyz = calc.iq(xyzfile) q, iqcif = calc.iq(ciffile) q, iqtuple = calc.iq(structuretuple) ```
Generating Partial Scattering
DebyeCalculator also allows users to extract the partial scattering for specific pairs of atomic species within a structure: ```python
Create an instance of DebyeCalculator with appropriate parameters
calc = DebyeCalculator(qmin=1.0, qmax=20.0)
Load a single particle from a .xyz file and calculate partial I(Q) for specific atom pairs
Replace 'X' and 'Y' with the atomic symbols present in your structure
q, iqXX = calc.iq("path/to/nanoparticle.xyz", partial="X-X") q, iqYY = calc.iq("path/to/nanoparticle.xyz", partial="Y-Y") q, iq_XY = calc.iq("path/to/nanoparticle.xyz", partial="X-Y") ``` Note: When combining signals from partial scattering, be cautious to avoid double-counting interactions between atoms.
Demo
For a more detailed demonstration on how DebyeCalulator works, including additional examples, please refer to the Demo.ipynb notebook available in the repository, or visit Colab-Demo
Additional implementation details
See the docs folder.
Authors
Frederik L. Johansen1, 2
Andy S. Anker1
1 Department of Chemistry & Nano-Science Center, University of Copenhagen, Denmark
2 Department of Computer Science, University of Copenhagen, Denmark
Should there be any questions, desired improvements or bugs please contact us on GitHub or through email: frjo@di.ku.dk and ansoan@dtu.dk.
Cite
If you use our code or our results, please consider citing our paper. Thanks in advance!
@article{Johansen_anker2024debye,
title={A GPU-Accelerated Open-Source Python Package for Calculating Powder Diffraction, Small-Angle-, and Total Scattering with the Debye Scattering Equation},
author={Frederik L. Johansen, Andy S. Anker, Ulrik Friis-Jensen, Erik B. Dam, Kirsten M. Ø. Jensen, Raghavendra Selvan},
journal={Journal of Open Source Software},
year={2024},
issn={2475-9066},
issue={94},
url={"https://joss.theoj.org/papers/10.21105/joss.06024"},
doi={10.5281/zenodo.10659528}
Contributing to the software
We welcome contributions to our software! To contribute, please follow these steps:
- Fork the repository.
- Make your changes in a new branch.
- Submit a pull request.
We'll review your changes and merge them if they meet our quality standards, including passing all unit tests. To ensure that your changes pass the unit tests, please run the tests locally before submitting your pull request. You can also view the test results on our GitHub repository using GitHub Actions.
Reporting issues
If you encounter any issues or problems with our software, please report them by opening an issue on our GitHub repository. Please include as much detail as possible, including steps to reproduce the issue and any error messages you received.
Seeking support
If you need help using our software, please reach out to us on our GitHub repository. We'll do our best to assist you and answer any questions you have.
References
[1] Waasmaier, D., & Kirfel, A. (1995). New analytical scattering-factor functions for free atoms and ions. Acta Crystallographica Section A, 51(3), 416–431. https://doi.org/10.1107/S0108767394013292
Owner
- Name: Frederik Lizak Johansen
- Login: FrederikLizakJohansen
- Kind: user
- Location: Denmark
- Company: @NanostructureUCPH
- Twitter: fupperlidt
- Repositories: 1
- Profile: https://github.com/FrederikLizakJohansen
JOSS Publication
A GPU-Accelerated Open-Source Python Package for Calculating Powder Diffraction, Small-Angle-, and Total Scattering with the Debye Scattering Equation
Authors
Department of Chemistry & Nano-Science Center, University of Copenhagen, Denmark, Department of Computer Science, University of Copenhagen, Denmark
Department of Energy Conversation and Storage, Technical University of Denmark, Denmark, Department of Chemistry, University of Oxford, United Kingdom
Department of Chemistry & Nano-Science Center, University of Copenhagen, Denmark, Department of Computer Science, University of Copenhagen, Denmark
Tags
Scattering Debye Scattering Equation GPU-accelerated Nanoparticles Pair Distribution Function AnalysisCitation (CITATION.cff)
cff-version: "1.2.0"
authors:
- family-names: Johansen
given-names: Frederik L.
orcid: "https://orcid.org/0000-0002-8049-8624"
- family-names: Anker
given-names: Andy S.
orcid: "https://orcid.org/0000-0002-7403-6642"
- family-names: Friis-Jensen
given-names: Ulrik
orcid: "https://orcid.org/0000-0001-6154-1167"
- family-names: Dam
given-names: Erik B.
orcid: "https://orcid.org/0000-0002-8888-2524"
- family-names: Jensen
given-names: Kirsten M. Ø.
orcid: "https://orcid.org/0000-0003-0291-217X"
- family-names: Selvan
given-names: Raghavendra
orcid: "https://orcid.org/0000-0003-4302-0207"
contact:
- family-names: Johansen
given-names: Frederik L.
orcid: "https://orcid.org/0000-0002-8049-8624"
- family-names: Anker
given-names: Andy S.
orcid: "https://orcid.org/0000-0002-7403-6642"
- family-names: Jensen
given-names: Kirsten M. Ø.
orcid: "https://orcid.org/0000-0003-0291-217X"
- family-names: Selvan
given-names: Raghavendra
orcid: "https://orcid.org/0000-0003-4302-0207"
doi: 10.5281/zenodo.10659528
message: If you use this software, please cite our article in the
Journal of Open Source Software.
preferred-citation:
authors:
- family-names: Johansen
given-names: Frederik L.
orcid: "https://orcid.org/0000-0002-8049-8624"
- family-names: Anker
given-names: Andy S.
orcid: "https://orcid.org/0000-0002-7403-6642"
- family-names: Friis-Jensen
given-names: Ulrik
orcid: "https://orcid.org/0000-0001-6154-1167"
- family-names: Dam
given-names: Erik B.
orcid: "https://orcid.org/0000-0002-8888-2524"
- family-names: Jensen
given-names: Kirsten M. Ø.
orcid: "https://orcid.org/0000-0003-0291-217X"
- family-names: Selvan
given-names: Raghavendra
orcid: "https://orcid.org/0000-0003-4302-0207"
date-published: 2024-02-20
doi: 10.21105/joss.06024
issn: 2475-9066
issue: 94
journal: Journal of Open Source Software
publisher:
name: Open Journals
start: 6024
title: A GPU-Accelerated Open-Source Python Package for Calculating
Powder Diffraction, Small-Angle-, and Total Scattering with the
Debye Scattering Equation
type: article
url: "https://joss.theoj.org/papers/10.21105/joss.06024"
volume: 9
title: A GPU-Accelerated Open-Source Python Package for Calculating
Powder Diffraction, Small-Angle-, and Total Scattering with the Debye
Scattering Equation
GitHub Events
Total
- Create event: 3
- Issues event: 2
- Release event: 1
- Watch event: 10
- Issue comment event: 8
- Push event: 4
- Pull request event: 4
- Fork event: 2
Last Year
- Create event: 3
- Issues event: 2
- Release event: 1
- Watch event: 10
- Issue comment event: 8
- Push event: 4
- Pull request event: 4
- Fork event: 2
Committers
Last synced: 5 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Andy S. Anker | A****y@n****k | 392 |
| Frederik | f****o@d****k | 370 |
| UlrikFriis-Jensen | l****3@a****k | 25 |
| Andy Sode Anker | a****n@D****l | 12 |
| raghavian | r****v@d****k | 5 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 4 months ago
All Time
- Total issues: 22
- Total pull requests: 20
- Average time to close issues: 19 days
- Average time to close pull requests: 3 days
- Total issue authors: 9
- Total pull request authors: 3
- Average comments per issue: 1.64
- Average comments per pull request: 0.1
- Merged pull requests: 19
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 5
- Average time to close issues: 1 day
- Average time to close pull requests: 8 days
- Issue authors: 3
- Pull request authors: 1
- Average comments per issue: 3.0
- Average comments per pull request: 0.4
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- elena-pascal (6)
- AndySAnker (5)
- KedoKudo (4)
- nicoratel (1)
- maak-sdu (1)
- marcocamma (1)
- UlrikFriisJensen (1)
- miguelgondu (1)
- sara-mokhtari (1)
Pull Request Authors
- AndySAnker (18)
- UlrikFriisJensen (7)
- raghavian (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 126 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 15
- Total maintainers: 1
pypi.org: debyecalculator
A vectorised implementation of the Debye Equation on CPU and GPU
- Homepage: https://github.com/FrederikLizakJohansen/DebyeCalculator
- Documentation: https://debyecalculator.readthedocs.io/
- License: Apache-2.0
-
Latest release: 1.0.14
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/checkout v3 composite
- actions/upload-artifact v1 composite
- openjournals/openjournals-draft-action master composite
- stefanzweifel/git-auto-commit-action v4 composite
- ase *
- numpy *
- pyyaml *
- torch *
- torchaudio *
- torchvision *