Skip to main content

quantem.diffsim

An interactive electron diffraction simulator for web pages and Dash apps. It shows a crystal and its diffraction pattern side by side for any orientation: nanobeam, convergent beam (CBED) and Kikuchi patterns, with kinematical or Bloch wave intensities, thickness, convergence, precession and beam energy controls. Every calculation runs in the browser, so the server only sends the structure.

The structure factors use the Lobato and Van Dyck electron scattering factors (Acta Cryst. A 70, 636 (2014)), and the Bloch wave couplings use the absorptive Weickenmeier and Kohl scattering factors with a Debye-Waller factor (Acta Cryst. A 47, 590 (1991)), as computed in quantEM. The same simulator runs in Jupyter as quantem.widget.DiffractionSim.

The package has no dependencies. It ships the browser bundle (one ES module, about 1.2 MB) and a few Python helpers.

Standalone page

from pymatgen.core import Lattice, Structure
import quantem.diffsim as diffsim

si = Structure.from_spacegroup("Fd-3m", Lattice.cubic(5.431), ["Si"], [[0, 0, 0]])
diffsim.save_html("si.html", si, zone_axis=[1, 1, 0], mode="nanobeam", title="Si")

structure_to_cif accepts a pymatgen Structure, an ASE Atoms object, CIF text or a CIF path. A pymatgen structure is converted to its conventional standard cell first (conventional=False keeps the given cell), so zone axes refer to the conventional lattice.

Dash

from dash import Dash, Input, Output, dcc, html
from quantem.diffsim import dash as diffsim_dash
import quantem.diffsim as diffsim

app = Dash(__name__)
diffsim_dash.register(app)
app.layout = html.Div([dcc.Store(id="structure"), diffsim_dash.layout("tem")])

@app.callback(Output(diffsim_dash.settings_id("tem"), "data"), Input("structure", "data"))
def show(structure):
    return diffsim.settings(Structure.from_dict(structure), zone_axis=[0, 0, 1], mode="nanobeam")

register(app) serves the bundle from the app's Flask server and adds one clientside callback that draws every simulator in the layout. Each new settings dictionary redraws that simulator.

Settings

settings() checks the names below. Lengths are in Å, angles in mrad unless named _deg, and scattering vectors in 1/Å.

Name Default Meaning
zone_axis [110], or [0001] for hexagonal cells Initial beam direction [uvw] or [uvtw]
mode "cbed" "nanobeam", "cbed" or "kikuchi"
dynamical True Bloch wave intensities; False gives kinematical intensities
energy_keV 200 Beam energy
thickness_A 400 Specimen thickness
semiangle_mrad 3 Convergence semiangle
precession_deg 0 Precession angle
pattern_range_inv_A 3 Largest scattering vector shown
field_mrad 50 Field of view of the Kikuchi pattern
thermal_sigma_A 0.05 RMS thermal displacement
power, vmax 0.5, 0.5 Display brightness exponent and upper contrast limit
show_kikuchi, show_hkl, show_labels, show_ewald, polyhedra Overlays
n_cells [1, 1, 1] Unit cells drawn
panel_width_px 400 Panel size
title, structure_name Heading and structure name
show_logo True The "Powered by quantEM" link to the quantEM documentation

License

MIT. Source and issues: electronmicroscopy/quantem.widget.

Metadata

Release files for quantem.diffsim 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for quantem.diffsim 0.1.0
File Size Uploaded Provenance Actions
quantem_diffsim-0.1.0.tar.gz 335.3 kB With provenance Details for quantem_diffsim-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for quantem.diffsim 0.1.0
File Interpreter ABI Platform Actions
quantem_diffsim-0.1.0-py3-none-any.whl Python 3 none any Details for quantem_diffsim-0.1.0-py3-none-any.whl

Total release size: 671.6 kB

Release files / quantem_diffsim-0.1.0.tar.gz

Download URL quantem_diffsim-0.1.0.tar.gz
Size 335.3 kB
Tags Source
SHA-256 checksum
How to use checksums
1a480cd970f76c18227a539622d5bb04940b9c2ba555aded28cd5f75e1a62665
BLAKE2b-256 checksum
How to use checksums
0da88024e6d1a95a89dcd68e4cca97439c377c581680e4cc8f224314677fadf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Release files / quantem_diffsim-0.1.0-py3-none-any.whl

Download URL quantem_diffsim-0.1.0-py3-none-any.whl
Size 336.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11220bf186025dcd2ce316f4138e386d5667971fe7279e724cf5b409a70f5976
BLAKE2b-256 checksum
How to use checksums
28520eaac6b1a3b38878361d0aad42db236e92e35d6afe9bae31f5a931103c4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

Security for quantem.diffsim 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for quantem_diffsim-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 4, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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