Repository navigation
Add DiffractionSim and quantem.diffsim, and remove the abTEM dependency - #245
Merged
Merged
Conversation
|
Collaborator
|
Either we can wait for architecture refactoring or merge now. up to you. probably I can do this during the weekend or so. |
Main removed PlanPtycho, so its abTEM replacement is dropped. DiffractionSim moves to main's module layout and HtmlExportMixin, and the ShowCIF potential preview takes its Lobato factors from quantem (0.1.10 has quantem PR #297). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port quantem's compute_WK_factor to TypeScript (wk.ts) so a CIF loaded in the web build gets the absorptive couplings and Debye-Waller factor the presets carry, instead of absorption fixed at 8 % of the elastic coupling. A CIF of the silicon preset reproduces the preset couplings to 1e-5 of the largest coupling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
npm run build:web now writes the browser bundle into packages/quantem.diffsim, a dependency-free PyPI package with settings() and save_html() for pymatgen, ASE or CIF structures, and quantem.diffsim.dash for Dash apps. A page can pass its structure as CIF text, which replaces the structure menu, and the simulator shows a Powered by quantEM link to the quantEM documentation. The theme follows the first opaque background behind the widget. diffsim-release.yml publishes the package to PyPI from a diffsim-v tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cophus
marked this pull request as ready for review
November 4, 2026 00:08
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does it solve?
This PR adds
DiffractionSim, an interactive electron diffraction simulator, packages its browser build asquantem.diffsimfor web pages and Dash apps, and removes abTEM from quantem.widget.DiffractionSimshows a crystal and its diffraction pattern side by side for any orientation, computed live in the browser with Bloch waves: nanobeam disks, CBED and Kikuchi patterns, with thickness, convergence, precession and energy controls. It uses theCrystalandblochmodules of quantEM, which are released in quantem 0.1.10 (electronmicroscopy/quantem#297), so this PR is no longer waiting on quantEM.The TEM diffraction tab of the Materials Project website has been broken since the site moved to NumPy 2, because no py4DSTEM release contains the NumPy 2 fixes (materialsproject/crystaltoolkit#547, py4dstem/py4DSTEM#750). We plan to replace it with this simulator. The tab is a Crystal Toolkit component in a Dash app, which cannot take on torch, so the replacement has to run without quantEM's Python stack:
npm run build:webwrites a framework-free ES module of the simulator (export default { render }) intopackages/quantem.diffsim, a separate PyPI package with no dependencies. A page passes its structure as CIF text, which replaces the structure menu and the CIF button, and the module computes the reflection list, structure factors and Bloch couplings in the browser.quantem.diffsim.settings()converts pymatgen or ASE structures to CIF (a pymatgen structure as its conventional standard cell with its space group, which is the cell the current tab uses),save_html()writes an offline page, andquantem.diffsim.dashserves the module from the app's Flask server and draws every simulator in the layout with one clientside callback. The simulator shows a "Powered by quantEM" link to the quantEM documentation in its lower right corner.js/diffractionsim-web/wk.tsports quantEM'scompute_WK_factor(core loss, phonon absorption and the Debye-Waller factor), so a CIF now gives the same couplings as the presets.abTEM was used only for the Lobato scattering factors of the ShowCIF potential preview, and it brings in a large dependency stack including dask. The preview now takes these factors from quantem, and its tables agree with abTEM 1.0.10 to 1e-4. Main removed PlanPtycho after this PR was opened, so the PR no longer touches it, and the
crystalextra is now empty (kept so that existing install lines work).What should reviewer(s) do?
DiffractionSim(src/quantem/widget/diffraction_sim.py,js/diffractionsim/): the merge with main moved it toHtmlExportMixinandquantem.widget.fallback. Its HTML export has no encoding options, since the page holds no image data.js/diffractionsim-web/):wk.ts, the coupling loop incif.ts, and the page options inindex.ts(cif,structure_name,title,thermal_sigma_A,show_logo).packages/quantem.diffsim,tests/diffsimand.github/workflows/diffsim-release.yml: please say whether a second package in this repository is acceptable, or whether it should move to its own repository. The first release needs a PyPI trusted publisher forquantem.diffsim(this repository,diffsim-release.yml, environmentpypi), set up by a maintainer before thediffsim-v0.1.0tag.Verification
pytest: 668 passed and 223 skipped, with quantem 0.1.10 from PyPI. Two failures come from the local environment:test_sync_writes_a_manifest_of_the_pinned_ref_and_every_filesyncs from a sibling quantem.gpu checkout at another commit, andtest_show2d_sibling_static_output_via_nbconvertpicks up an lxml withoutlxml_html_clean.tests/diffsim: 3 passed with Dash 3.4, pymatgen and ASE installed.vitest: 389 passed.wk.test.tschecks the WK factors against quantem'scompute_WK_factorfor O, Si, Cu, Au and Ba at 80 to 300 keV (agreement to 1e-8), and checks that a CIF of the silicon preset reproduces the preset couplings to 1e-5 of the largest coupling.python -m build packages/quantem.diffsim: a 1.2 MB wheel holding the two modules and the bundle, with noquantem/__init__.py. Installed alone in Python 3.10, it imports no other package and writes a working page.quantem.diffsim.dash) draws Si stored as its primitive cell (shown as the conventional cell along [001]), SrTiO3 and GaN, redraws on each selection, follows the light page theme, and shows the corner link to the quantEM documentation, with no console errors. Asave_htmlpage of GaN along [11-20] in CBED mode renders at 375 px width without horizontal scrolling, and aDiffractionSim.export_htmlpage renders the Jupyter frontend offline.Written by Colin Ophus and Claude (Claude Code).