Skip to main content

ChemRxiv | [Paper]

DebyeCalculator

DebyeCalculator

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.

  1. Installation
    1. Prerequisites
    2. Install with pip
    3. Install locally
    4. Testing installation
    5. GPU support
  2. Usage
    1. Interactive mode
    2. Example usage
  3. Additional implementation details
  4. Authors
  5. Cite
  6. Contributing to the software
    1. Reporting issues
    2. Seeking support

Installation

Prerequisites

DebyeCalculator requires Python version >=3.7, <3.12. If needed, create an environment with any of these Python versions:

conda create -n debyecalculator_env python=3.9
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 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:

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:

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:

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:

from debyecalculator import DebyeCalculator

calc = DebyeCalculator(device='cuda')

Usage

Interactive mode at Google Colab

Follow the instructions in our Interactive Google Colab notebook and try to play around.

Example usage

from debyecalculator import DebyeCalculator
import torch

# Initialise calculator object
calc = DebyeCalculator(qmin=1.0, qmax=8.0, qstep=0.01)

# Define structure sources
xyz_file = "some_path/some_file.xyz"
cif_file = "some_path/some_file.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]]
))

# Print object to view all parameters
print(calc)
## [OUTPUT] DebyeCalculator{'qmin': 1.0, 'qmax': 8.0, 'qstep': 0.01, 'rmin': 0.0, 'rmax': 20.0, ...}

# Calculate Powder (X-ray) Diffraction from XYZ-file
Q, I = calc.iq(structure_source=xyz_file)

# Calculate Powder (X-ray) Diffraction from CIF
Q, I = calc.iq(structure_source=cif_file, radii=5) # radii is the radius of the particle in Å

# Calculate Powder (X-ray) Diffraction from Tuple
Q, I = calc.iq(structure_source=structure_tuple)

# Update parameters for Small Angle (Neutron) Scattering
calc.update_parameters(qmin=0.0, qmax=3.0, qstep=0.01, radiation_type="neutron")

# Calculate Small Angle (Neutron) Scattering
Q, I = calc.iq(structure_source=xyz_file)

# Update parameters for Total Scattering with Pair Distribution Function analysis
calc.update_parameters(qmin=1.0, qmax=30.0, qstep=0.1, radiation_type="xray")

# Calculate Pair Distribution Function
r, G = calc.gr(structure_source=xyz_file)
.....

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_anker2023debye,
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={ChemRxiv}
year={2023}}

Contributing to the software

We welcome contributions to our software! To contribute, please follow these steps:

  1. Fork the repository.
  2. Make your changes in a new branch.
  3. 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

Metadata

Release files for DebyeCalculator 1.0.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 DebyeCalculator 1.0.6
File Size Uploaded
debyecalculator-1.0.6.tar.gz 263.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for DebyeCalculator 1.0.6
File Interpreter ABI Platform
debyecalculator-1.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 538.5 kB

Release files / debyecalculator-1.0.6.tar.gz

Download URL debyecalculator-1.0.6.tar.gz
Size 263.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ebe46cb638168cdecedd2703d1fcd081c02e79893e22b940c7a0cbb958126d97
BLAKE2b-256 checksum
How to use checksums
79a07cd91c2b766ee178733c46c9e39b881bb8ddffd014497f2f1b367782742f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.5 Linux/5.15.133.1-microsoft-standard-WSL2

Release files / debyecalculator-1.0.6-py3-none-any.whl

Download URL debyecalculator-1.0.6-py3-none-any.whl
Size 274.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
897d50ff3512cb401af021e0fb554c96f4380a2cd66f2cc5311f2dee392acdeb
BLAKE2b-256 checksum
How to use checksums
09a2d18ae3106aee19adcbb4d475d4391101fba8ab306aff69218549c5735f1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.4.0 CPython/3.11.5 Linux/5.15.133.1-microsoft-standard-WSL2

Release history Release notifications | RSS feed

1.1.1

2 release files

1.1.0

2 release files

1.0.14

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

This release

1.0.6 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

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