Skip to main content

Crystal Tortuosity Analysis with Fortran Extensions

Project description

status DOI PyPI version build-and-test Coverage Status Documentation Status Python 3.10+ License: MIT

crystal_torture:

crystal_torture is a Python, Fortran and OpenMP crystal structure analysis module. The module contains a set of classes that enable:

  • a crystal structure to be converted into a graph for network analysis.
  • connected clusters of crystal sites (nodes) to be retrieved and output.
  • periodicity of connected clusters of crystal sites to be determined.
  • relative path tortuosity to traverse a crystal within a connected cluster to be calculated for each site.

Ionic diffusion through crystalline solids depends not only on the dynamics of ions within the crystal, but also the connectivity of the transport network. Understanding how the connectivity of diffusion pathways in crystal structures is affected by changes in chemistry is necessary for understanding how chemical modifications change ionic conductivities, for example the doping of solid electrolytes.

crystal-torture provides a Python API for interrogating network connectivity and diffusion pathways in partially blocked crystal structures. It can be used as a tool for materials scientists to quickly build up network connectivity statistics in order to determine the viability of potential ionic conductors, and how chemical modification affects network connectivity, before the use of more computationally expensive approaches modelling the full dynamics.

Features

  • Fast Performance: Fortran extensions with OpenMP parallelisation for computationally intensive operations
  • Fallback Support: Pure Python implementations available when Fortran extensions unavailable
  • Modern Build System: Uses meson-python for reliable cross-platform builds
  • Comprehensive Testing: Extensive test suite covering both Fortran and Python code paths
  • Type Hints: Modern Python with type annotations for better development experience

Installation

crystal_torture requires Python 3.10 or above.

From PyPI (Recommended)

For most users, installation from PyPI will provide pre-compiled packages:

pip install crystal-torture

From Source

Building from source enables Fortran extensions for optimal performance. This requires a Fortran compiler and build tools:

System Dependencies

Ubuntu/Debian:

sudo apt-get update
sudo apt-get install gfortran build-essential

macOS (with Homebrew):

brew install gfortran

Windows: Install a Fortran compiler such as MinGW-w64 or use Windows Subsystem for Linux.

Installation

git clone https://github.com/connorourke/crystal_torture
cd crystal_torture
pip install . --use-pep517

Development Installation

git clone https://github.com/connorourke/crystal_torture
cd crystal_torture  
pip install ."[dev]" --use-pep517

Fortran Extensions

Performance Note: The Fortran extensions provide significant performance improvements for large systems. If Fortran compilation fails, some functions will fall back to Python implementations, while others (like torture_fort()) will require using the Python equivalent (torture_py()).

To verify Fortran extensions loaded successfully:

from crystal_torture import tort, dist
print(f"Fortran tort available: {tort.tort_mod is not None}")
print(f"Fortran dist available: {dist._DIST_AVAILABLE}")

Quick Start

from crystal_torture.pymatgen_interface import graph_from_file

# Load structure and create graph
graph = graph_from_file("my_structure.cif", rcut=4.0, elements={"Li"})

# Analyse tortuosity (uses Fortran if available)
graph.torture()  # or graph.torture_py() for pure Python

# Get results
percolating_fraction = graph.return_frac_percolating()
for cluster in graph.minimal_clusters:
    print(f"Cluster size: {cluster.size}, Tortuosity: {cluster.tortuosity}")

Tests

crystal_torture is automatically tested on each commit via GitHub Actions across Python 3.10-3.13, but tests can be run manually:

# Run all tests
pytest

# Run with coverage
pytest --cov=crystal_torture

# Run specific test file
pytest tests/test_node.py -v

Examples

Examples on how to use crystal_torture can be found in a Jupyter notebook in the examples directory crystal_torture_examples.ipynb

Documentation

Documentation can be found here

Dependencies

Runtime Dependencies

  • numpy>=1.19.0
  • pymatgen>=2022.0.0

Build Dependencies (for source installation)

  • meson-python>=0.12.0
  • gfortran (Fortran compiler)
  • ninja (build tool)
  • OpenMP (optional, for parallelisation)

Development Dependencies

  • pytest>=6.0
  • pytest-cov
  • coverage
  • ddt

Performance

The Fortran extensions with OpenMP provide substantial performance improvements over pure Python implementations, particularly for large crystal structures with many atoms.

Contributing

Bug Reports and Feature Requests

If you think you have found a bug, please report it on the Issue Tracker. This is also the place to propose ideas for new features or ask questions about the design of crystal_torture. Poor documentation is considered a bug, but please be as specific as possible when asking for improvements.

Code Contributions

We welcome your help in improving and extending the package with your own contributions. This is managed through GitHub pull requests; for external contributions we prefer the "fork and pull" workflow, while core developers use branches in the main repository:

  1. First open an Issue to discuss the proposed contribution. This discussion might include how the changes fit crystal_torture's scope and a general technical approach.
  2. Make your own project fork and implement the changes there. Please keep your code style compliant with PEP8.
  3. Add or update tests for your changes.
  4. Open a pull request to merge the changes into the main project. A more detailed discussion can take place there before the changes are accepted.

Development Setup

git clone https://github.com/connorourke/crystal_torture
cd crystal_torture
pip install ."[dev]" --use-pep517
pytest  # Run tests to verify installation

Citation

If you use crystal_torture in your research, please cite:

@article{ORourke2019,
  title = {crystal-torture: A crystal tortuosity module},
  volume = {4},
  ISSN = {2475-9066},
  url = {http://dx.doi.org/10.21105/joss.01306},
  DOI = {10.21105/joss.01306},
  number = {38},
  journal = {Journal of Open Source Software},
  publisher = {The Open Journal},
  author = {O'Rourke,  Conn and Morgan,  Benjamin},
  year = {2019},
  month = jun,
  pages = {1306}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

Version

Current version: 1.2.0

Changelog

  • v1.2.0: Modern meson-python build system, improved Fortran integration, Python 3.10+ support
  • v1.1.x: Previous stable releases with setuptools build system

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

crystal_torture-1.2.0.tar.gz (7.4 MB view details)

Uploaded Source

Built Distributions

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

crystal_torture-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.28+ x86-64

crystal_torture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl (947.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

crystal_torture-1.2.0-cp312-cp312-macosx_10_9_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.12macOS 10.9+ x86-64

crystal_torture-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.28+ x86-64

crystal_torture-1.2.0-cp311-cp311-macosx_11_0_arm64.whl (947.0 kB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

crystal_torture-1.2.0-cp311-cp311-macosx_10_9_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

crystal_torture-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

crystal_torture-1.2.0-cp310-cp310-macosx_11_0_arm64.whl (947.0 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

crystal_torture-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

File details

Details for the file crystal_torture-1.2.0.tar.gz.

File metadata

  • Download URL: crystal_torture-1.2.0.tar.gz
  • Upload date:
  • Size: 7.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for crystal_torture-1.2.0.tar.gz
Algorithm Hash digest
SHA256 8469e53ba2f610a4a95a4c0e6ec711012d2801972db3af8d283fe7595a8a7382
MD5 4bdb2410bf0976142435c1da5f2a1b75
BLAKE2b-256 5493f6a5566fc4321736ca470aba170f09bae1c82f036f0e0e682a81df9a28d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0.tar.gz:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75f9d0680ec4f7e21eff54c3c67ac7b03f0a515cd2a16a3389bdac5315a0c8f2
MD5 c507944dd9d342cb11338a6a9b283132
BLAKE2b-256 b3eb9f1a1965dffc0da058319a627ff9e6a422fa84cbd29d76e22adc8baaa46b

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp312-cp312-manylinux_2_28_x86_64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3fe8b3773c7603f7415571f630de994ab363e5934f0367c34a40712cfacd76f9
MD5 fbf0a78e727e01cf74c5caedb6e8daa3
BLAKE2b-256 81bdd9236338643089558e68681b1e397ca7a30033585aa32ca989e5f7d98f4d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp312-cp312-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp312-cp312-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 9b24bba8ea630fe0eff00caf43f5927647e96ec379d39c760508652675719d26
MD5 1c24df4461b5ed6db2c97f721c1526c8
BLAKE2b-256 73fb3b28acc1f9a1848cceec61b38490aad2468aa91fbf8c6b9b588c5da1ae4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp312-cp312-macosx_10_9_x86_64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 724148a425cf03a211c9772144aa3b5a776fcf1e6c1cd9360d08ea6c1dc6a0d8
MD5 d4500250393d1306f76d02bb1d020689
BLAKE2b-256 08b2fd865a54134130732da04ee520d45f92df6c94d08b60bbb3343f75e3d927

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp311-cp311-manylinux_2_28_x86_64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f811133ab8ebaa1e12527b22496de6466415c4732cdd1fb568fea325fecf1090
MD5 25c6302ca00a97d2fc5a3f5ed84f2cb8
BLAKE2b-256 26f6acf21ca97ebdb274c1722e8f5bb31d0be8b261d639584e68e7eece37f3a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1a7cfe8935e3b2a34c933a1208ec7dfcbdeab21cb85447a50cbc3d7942e2c921
MD5 2828e3fc2a3845905ffbcf8a55f1686c
BLAKE2b-256 cd85172193c504e8eda099e669e96bf1db144a5790d9b7e41726d99a133cad5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp311-cp311-macosx_10_9_x86_64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6757fea38836645714e8626d0fecb8ea7e7d28284674ce21cc8f073c583f26a3
MD5 c306b7c2980ec88c0bda0b3a2345bd4e
BLAKE2b-256 b4824ed3630f7fe8b6afb324b7d1fe2edbc78ff32251bad8fd50c3130dd6e5d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp310-cp310-manylinux_2_28_x86_64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3524b72e9a4a44fb347e5535256bfece01a79c494d487aa9e3d992fb2ae3a811
MD5 4f1fbfb123a0c10f1b2036d6dfbe097d
BLAKE2b-256 989c5feefb65ab514e66b9cb14c04e5a3acecca8ce1d1cfd5c78be4ae7f7869d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file crystal_torture-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for crystal_torture-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 5a4122a838a67fc1f1433e84d95ef994133ef0fa8c087f43d98bb563fc86c9df
MD5 089196bd7d68652a14ebc12a146e6cc8
BLAKE2b-256 9af4b26c5c62e7ef94ad418d3ebf8cc3b31ca4fd23b1f811902ab9cae3b39506

See more details on using hashes here.

Provenance

The following attestation bundles were made for crystal_torture-1.2.0-cp310-cp310-macosx_10_9_x86_64.whl:

Publisher: upload_release.yml on connorourke/crystal_torture

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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