pyGND
Geometrically Necessary Dislocation calculations for TriBeam 3D microstructures
PyGND is a Python package for calculating geometrically necessary dislocation (GND) densities from EBSD (Electron Backscatter Diffraction) data using Nye's dislocation theory. The code was originally developed in MATLAB by Wyatt Witzen and has been reimplemented in Python for improved performance and accessibility.
THIS CODE IS UNDER ACTIVE DEVELOPMENT AND IS PROVIDED AS_IS. Please submit an issue if any problems arise.
Features
- Multiple crystal structures: FCC, BCC, and HCP
- Flexible slip system selection: Choose specific slip systems or use all available
- Optimized calculations: Parallel processing with configurable CPU cores
- Multiple minimization methods: L1 and L2 minimization
- Multiple input formats: Support for ANG files and DREAM.3D formats
- Progress tracking: Built-in progress bars for long calculations
- Memory efficient: Configurable chunking for large datasets
- Desktop GUI and a command line interface, in addition to the Python API
Installation
From PyPI
pip install pygnd
From source
git clone https://github.com/lambjames18/pyGND.git
cd pyGND
pip install -e .
If you use uv (the toolchain this project develops with), uv sync will set up an editable install with all dependencies resolved from pyproject.toml. Using uv is the recommended route, especially if planning to contribute to the project.
Quick Start
Python API
import pygnd
# Calculate GND from an .ang file
pygnd.calculate_and_save_ang(
"path/to/data.ang",
cs=1, # 1=FCC, 2=BCC, 3=HCP
burgers=2.48e-10, # Burgers vector magnitude in meters
grain_ids_path="path/to/grain_data.txt",
minimization=["l2", "l1"],
slip_systems="all",
n_cpus=4,
progress_bar=True,
)
# Calculate GND from a DREAM.3D file and save the results back into it
pygnd.calculate_and_save_dream3d(
"path/to/data.dream3d",
ids_name="FeatureIds",
euler_name="EulerAngles",
cs=2, # BCC
burgers=2.48e-10,
minimization="l2",
slip_systems="screw+110",
n_cpus=8,
chunk_size=5000,
)
See examples/ for complete runnable scripts, and the API documentation for the full parameter reference (including pygnd.get_linear_operator, the pygnd.rotations/pygnd.quaternions conversion utilities, and lower-level functions in pygnd.core).
Command line
Installing the package also provides three console scripts:
# Print the version, logo, and a summary of the entry points below
pygnd
# Run the same calculation as above from the command line
pygnd_calculate ang path/to/data.ang --cs 1 --burgers 2.48e-10 --grain-ids-path path/to/grain_data.txt
pygnd_calculate dream3d path/to/data.dream3d --ids-name FeatureIds --euler-name EulerAngles --cs 2 --burgers 2.48e-10
# Validate a file's shape/spacing before queuing a large job, without running the calculation
pygnd_calculate ang path/to/data.ang --dry-run
# Launch the desktop GUI
pygnd_gui
Run pygnd_calculate --help, pygnd_calculate ang --help, or pygnd_calculate dream3d --help for the full list of options (minimization scheme, CPU/chunk-size controls, slip systems, etc.) — these mirror the Python API parameters below.
Crystal Structures and Slip Systems
FCC (cs=1)
- Slip systems: Always uses all slip systems
BCC (cs=2)
Available slip system options:
"screw+110"- Screw dislocations on {110} planes"screw+112"- Screw dislocations on {112} planes"screw+123"- Screw dislocations on {123} planes"screw+110+112"- Combined {110} and {112}"screw+110+123"- Combined {110} and {123}"screw+112+123"- Combined {112} and {123}"all"- All available slip systems
HCP (cs=3)
Available slip system options:
"basal"- Basal slip"prismatic"- Prismatic slip"pyramidal"- Pyramidal slip"basal+prismatic"- Combined basal and prismatic"basal+pyramidal"- Combined basal and pyramidal"prismatic+pyramidal"- Combined prismatic and pyramidal"all"- All available slip systems
For HCP with a mixed basal/prismatic + pyramidal slip-system combination, burgers must be a (basal/prismatic, pyramidal) tuple of the two Burgers vector magnitudes.
Main Functions
calculate_and_save_ang(ang_path, cs, burgers, grain_ids_path=None, ...)— calculate from an.angfile, saving results as.npyfiles and preview images next to it.calculate_and_save_dream3d(dream3d_path, ids_name, euler_name, cs, burgers, ...)— calculate from a DREAM.3D file, saving results back into it (falling back to.npyfiles if the DREAM.3D write fails).calculate_and_save(...)— a deprecated combined-argument entry point kept for backwards compatibility; prefer the two functions above.
Both functions share the following parameters:
cs(int): Crystal structure (1=FCC, 2=BCC, 3=HCP)burgers(float or tuple): Burgers vector magnitude(s) in meters (see above for HCP mixed slip systems)slip_systems(str): Slip system selection (see above)minimization(str or list):"l1","l2", or both["l1", "l2"]n_cpus(int): Number of CPU cores to use for L1 minimization (-1uses all available)chunk_size(int): Data points per processing chunkprogress_bar(bool): Show a progress bar during L1 minimization
See the API documentation for the complete, per-function parameter reference.
Output
The package saves results in .npy files by default. If a DREAM.3D file is used, it will attempt to add the output to the DREAM.3D file directly. In the case of an ANG file, images of the result are saved in addition to the .npy raw data. Raw data is saved in the following format:
gnd_l1.npyorgnd_l2.npy: shape (n_slip_systems, Z, Y, X), to get the full GND density, sum across the first (n_slip_systems) axis.fdm.npy: shape (3, Z, Y, X), to get the average finite difference misorientation, take the mean along the first axis.
Dependencies
Runtime dependencies (see pyproject.toml for the authoritative, unpinned list): numpy, scipy, h5py, matplotlib, tqdm, joblib.
Documentation
- API documentation (built with pdoc)
- Test coverage report
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. Before submitting:
- Ensure all tests pass:
uv run pytest - Add tests for new features
- Follow the existing code style
- Update documentation as needed
See CONTRIBUTING.md for more details.
Uses in the literature
A few papers that have used this code are provided below.
-
Lamb, J.D. et al. On the role of geometrically necessary dislocations in void formation and growth in response to shock loading conditions in wrought and additively manufactured Ta. DOI: 10.1016/j.jmrt.2024.07.003
-
Lamb, J.D. et al. Quantification of melt pool dynamics and microstructure during simulated additive manufacturing. DOI: 10.1016/j.scriptamat.2024.116036
-
Witzen, W.A. et al. Resolving crystallographic geometrically necessary dislocations in three dimensions in a hexagonal close packed titanium alloy. DOI: 10.1088/1361-651x/ad64f4
License
This project is licensed under the MIT License - see the LICENSE file for details.
Authors
- James Lamb - Python implementation
- Wyatt Witzen - Original MATLAB implementation and methodology
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 pygnd-1.1.3.tar.gz.
File metadata
- Download URL: pygnd-1.1.3.tar.gz
- Upload date:
- Size: 80.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb32d134834982682c78d86fd0ca70b7da336c80d13b003d5881c85a400b6e0d
|
|
| MD5 |
4fd9f40bae3ea526d573646bb0cd0db0
|
|
| BLAKE2b-256 |
47fda2afbef30f94bc38d093abf2d230a46e66b06df4bfc569e984b13a12d390
|
Provenance
The following attestation bundles were made for pygnd-1.1.3.tar.gz:
Publisher:
cicd.yml on lambjames18/pyGND
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygnd-1.1.3.tar.gz -
Subject digest:
eb32d134834982682c78d86fd0ca70b7da336c80d13b003d5881c85a400b6e0d - Sigstore transparency entry: 2307011834
- Sigstore integration time:
-
Permalink:
lambjames18/pyGND@f475a1a58a02660fb9dd5fdc535a3f50516dba89 -
Branch / Tag:
refs/tags/v1.1.3 - Owner: https://github.com/lambjames18
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cicd.yml@f475a1a58a02660fb9dd5fdc535a3f50516dba89 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pygnd-1.1.3-py3-none-any.whl.
File metadata
- Download URL: pygnd-1.1.3-py3-none-any.whl
- Upload date:
- Size: 43.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26806b326149ee54ed1ec85c7e98968bb7df4fb09decb16db6b78d57488cd062
|
|
| MD5 |
bdbc48a27f0ebaa06bdff97ef03dffc9
|
|
| BLAKE2b-256 |
397d205ba50cd6e68e5c3f2f758a462d4e38da69bfd2849463c1c1b2224d3fee
|
Provenance
The following attestation bundles were made for pygnd-1.1.3-py3-none-any.whl:
Publisher:
cicd.yml on lambjames18/pyGND
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygnd-1.1.3-py3-none-any.whl -
Subject digest:
26806b326149ee54ed1ec85c7e98968bb7df4fb09decb16db6b78d57488cd062 - Sigstore transparency entry: 2307011911
- Sigstore integration time:
-
Permalink:
lambjames18/pyGND@f475a1a58a02660fb9dd5fdc535a3f50516dba89 -
Branch / Tag:
refs/tags/v1.1.3 - Owner: https://github.com/lambjames18
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cicd.yml@f475a1a58a02660fb9dd5fdc535a3f50516dba89 -
Trigger Event:
push
-
Statement type: