Skip to main content

Physical simulation of powder X-ray diffraction patterns

Project description

Pysimxrd

Physical simulation of powder X-ray diffraction patterns.

Pysimxrd provides high-level utilities for generating simulated powder XRD profiles from crystal structures stored in ASE database files. It includes a pymatgen-backed simulation path and a WPEM path for diffraction conditions, systematic extinction, multiplicity, structure factors, peak broadening, background, and noise.

Bin Cao, PhD of HKUST(Guangzhou), https://bin-cao.github.io
URL: https://github.com/Bin-Cao/SimXRD

Features

  • Simulate powder XRD patterns from ASE database entries.
  • Support 2-theta output and d-spacing output.
  • Include peak broadening from crystallite size and instrumental effects.
  • Add preferred-orientation variation, thermal vibration, background, and noise.
  • Provide a WPEM path with symmetry-based extinction and multiplicity handling.
  • Support optional random lattice deformation for data augmentation.

Installation

Install from PyPI:

pip install Pysimxrd

Install from the project root:

pip install .

For editable development:

pip install -e .

Quick Start

from ase.db import connect
from Pysimxrd import generator

database = connect("sim/demo_mp.db")
x, y = generator.parser(database, entry_id=1)

print(len(x), len(y))
print(x[:5], y[:5])

Use the WPEM simulation path:

from ase.db import connect
from Pysimxrd import generator

database = connect("sim/demo_mp.db")
x, y = generator.parser(database, entry_id=1, sim_model="WPEM")

Use d-spacing output instead of 2-theta:

x_d, intensity = generator.parser(
    database,
    entry_id=1,
    sim_model="WPEM",
    xrd="real",
)

Main API

Pysimxrd.generator.parser

parser(
    database,
    entry_id,
    grainsize=20,
    prefect_orientation=[0.1, 0.1],
    thermo_vibration=0.1,
    zero_shift=0.1,
    dis_detector2sample=500,
    half_height_slit_detector=5,
    half_height_sample=2.5,
    deformation=False,
    sim_model=None,
    xrd="reciprocal",
    background_order=6,
    background_ratio=0.05,
    mixture_noise_ratio=0.02,
    lattice_extinction_ratio=0.01,
    lattice_torsion_ratio=0.01,
    verbose=False,
)

Important arguments:

  • database: an open ASE database connection.
  • entry_id: row id in the ASE database.
  • sim_model: set to "WPEM" for the WPEM simulation path; use None for the pymatgen-backed default path.
  • xrd: "reciprocal" returns 2-theta; "real" returns d-spacing.
  • deformation: applies random lattice deformation for peak-position augmentation.
  • lattice_extinction_ratio: random stretching/compression ratio used when deformation=True.
  • lattice_torsion_ratio: random shear ratio used when deformation=True.
  • verbose: prints package and run metadata before simulation.

Returns:

x, y

where x is the simulated x-axis and y is the normalized intensity profile.

WPEM Deformation Behavior

For sim_model="WPEM" with deformation=True, symmetry information is taken from the undeformed conventional cell:

  • space group
  • centering symbol
  • crystal system
  • atom coordinates

The deformed lattice constants are then used for peak position and d-spacing calculation. This keeps the symmetry/extinction logic tied to the original crystal while allowing peak shifts from lattice perturbation.

Package Layout

src/Pysimxrd/
  __init__.py
  generator.py
  CGCNN_atom_emb.json
  utils/
    MatgenKit.py
    WPEMsim.py
    funs.py

Development Checks

Run a simple import and smoke test from the repository root:

python -c "from ase.db import connect; from Pysimxrd import generator; db=connect('sim/demo_mp.db'); x,y=generator.parser(db,1); print(len(x), len(y))"

Build a source distribution and wheel:

python setup.py sdist bdist_wheel

Citation

If this package or the associated SimXRD dataset is useful in your work, please cite the related project and repository:

SimXRD / Pysimxrd
Cao Bin
https://github.com/Bin-Cao/SimXRD

License

This project is released under the MIT License. See LICENSE for details.

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

pysimxrd-1.0.0.tar.gz (33.1 kB view details)

Uploaded Source

Built Distribution

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

pysimxrd-1.0.0-py3-none-any.whl (33.3 kB view details)

Uploaded Python 3

File details

Details for the file pysimxrd-1.0.0.tar.gz.

File metadata

  • Download URL: pysimxrd-1.0.0.tar.gz
  • Upload date:
  • Size: 33.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.19

File hashes

Hashes for pysimxrd-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91579ac359e59ea72dbea47976c1f99c5658ee6119b7d0ce898aa24aa65d755e
MD5 f8cb814b8c2f8151f84cb2960f3bc667
BLAKE2b-256 e9eaeb7ea72e631478ee2447c043e666531a026eefa777b5bf1024de124dfd47

See more details on using hashes here.

File details

Details for the file pysimxrd-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pysimxrd-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 33.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.19

File hashes

Hashes for pysimxrd-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 236687f33bb250a57ee74f6bd93c0874ede2da4136045e40cd8bf9f2f43567c2
MD5 c374b5d359fad2275e36f54eabe16fed
BLAKE2b-256 6d84d2f55e32ccb96e060f4d848ec4ab30476ec1fab6f80ec6a067366295b55a

See more details on using hashes here.

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