Skip to main content

MoirePy: Twist It, Solve It, Own It!

MoirePy is a FOSS Python library for simulating moire lattices with a clean, highly Pythonic API. The performance-critical backend is written in Rust, which keeps large lattice generation and Hamiltonian assembly fast while preserving a Python-first workflow.

It is designed to be easy to use while remaining fully flexible. You can define custom lattice geometries, program arbitrary hopping functions, and build tight-binding Hamiltonians in both real space and k-space, with support for open (OBC) and periodic (PBC) boundary conditions. Generate your lattice and Hamiltonian in MoirePy, then export to the tools you already use (like Kwant, NumPy, SciPy, and related ecosystems) and keep your workflow.


Why MoirePy

  • Plug and play: Build in MoirePy, continue in your current stack: Kwant, NumPy, SciPy etc.
  • Fast by default: Rust backend + optimized core algorithms.
  • Flexible models: Custom geometry, orbitals, and hoppings.
  • Multiple modes: Real-space/k-space and OBC/PBC supported.
  • Easy onboarding: Pythonic API and web tools for quick tinkering.

Philosophy

  • Not a workflow replacement: Use MoirePy where it shines, then export to Kwant, NumPy, SciPy, and more.
  • Do one thing and do it well: Focus on robust and fast moire lattice simulation and Hamiltonian generation.
  • Power to you: If it is mathematically possible, you can build it. No questions asked.
  • Learn by doing: Explore fast, and reproduce well-known paper systems.

Installation

pip install moirepy

Quick Example: Twisted Bilayer Graphene

import numpy as np
import matplotlib.pyplot as plt
from moirepy import BilayerMoireLattice, HexagonalLayer

# Define a twisted bilayer moiré lattice
lattice = BilayerMoireLattice(
    latticetype=HexagonalLayer,
    # you choose the next 4 values based on the twist angle using this tool:
    # Angle-Value Calculator: https://jabed-umar.github.io/MoirePy/theory/avc/
    ll1=3, ll2=4, ul1=4, ul2=3,
    n1=1, n2=1,
)

# Visualize the lattice
lattice.plot_lattice()
plt.show()

ham = lattice.generate_hamiltonian(
    tll=1, tuu=1,
    tlu=1, tul=1,
    tlself=0, tuself=0
)  # returns scipy sparse matrix

print(ham.shape)

Benchmark: Why This Is Fast

Basic benchmark snapshots using Twisted Bilayer Graphene (TBG) as a test case, benchmarked on a laptop with a 12th Gen Intel Core i5 (performance cores).

Experiment 1: Full Pipeline

Experiment 1: Full pipeline benchmark

This includes lattice generation plus Hamiltonian assembly. Even at around 160k lattice points, the full pipeline is about 620 ms. For context, configurations near the magic angle ($\sim 1.1^\circ$) typically have just around 5-6k lattice points.

Experiment 2: Subsequent Hamiltonian Generation

Experiment 2: Hamiltonian-only benchmark

After setup, Hamiltonian generation is much faster. At around 160k lattice points, it is about 15 ms. This is the speed profile we optimize for: heavy setup once, then fast repeated builds. Memory usage in these runs is negligible relative to typical laptop RAM.

For more comprehensive performance benchmarks, visit this: BENCHMARK


Contributing

Contributions are welcome.

Please read the full contribution guide at contributing.md.

Highlights:

  • Join our Discord server to coordinate and discuss ideas.
  • Choose your path: Docs Contributor (examples, blogs, docs) or Developer Contributor (Rust core, Python API, tests/CI).
  • Start from issues and submit focused pull requests.
  • Follow project philosophy: keep implementations simple, benchmark in practice, and optimize for user experience.

Citation

If you use this work in research:

@software{MoirePy2025,
  author = {Mukhopadhyay, Aritra and Umar, Jabed},
  license = {MIT},
  title = {{MoirePy: Python package for efficient atomistic simulation of moiré lattices}},
  url = {https://github.com/jabed-umar/MoirePy}
}

Metadata

Release files for moirepy 0.0.19

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

Source distribution (sdist)

Source distribution for moirepy 0.0.19
File Size Uploaded Provenance
moirepy-0.0.19.tar.gz 2.1 MB Without provenance Details

Built distributions (wheels)

Table of built distributions (wheels) for moirepy 0.0.19
File
moirepy-0.0.19-cp311-abi3-win_amd64.whl CPython 3.11 abi3 Windows x86-64 Details
moirepy-0.0.19-cp311-abi3-manylinux_2_34_x86_64.whl CPython 3.11 abi3 Linux glibc 2.34+ x86-64 Details
moirepy-0.0.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details
moirepy-0.0.19-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details

Total release size: 3.8 MB

Release files / moirepy-0.0.19.tar.gz

Download URL moirepy-0.0.19.tar.gz
Size 2.1 MB
Tags Source
SHA-256 checksum
How to use checksums
66f9cd15fa7693292b1c00bd931c9a05c53cb85cfb92bc8a0f89d17cf012a5f1
BLAKE2b-256 checksum
How to use checksums
17c1a87b2146928b638f25d966c971c79fd62a8ba366830e33f4fe15ace4e8ca
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / moirepy-0.0.19-cp311-abi3-win_amd64.whl

Download URL moirepy-0.0.19-cp311-abi3-win_amd64.whl
Size 334.6 kB
Tags CPython 3.11 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
8d97eac73ea03c14a2519c9511658ca39f3a43fc21eb052e1ff531531416cd6e
BLAKE2b-256 checksum
How to use checksums
f5b21e6df7ebb3a3b01781661d5c030624929198ec17045b3e8707b7b5af48fb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / moirepy-0.0.19-cp311-abi3-manylinux_2_34_x86_64.whl

Download URL moirepy-0.0.19-cp311-abi3-manylinux_2_34_x86_64.whl
Size 494.7 kB
Tags CPython 3.11 Linux glibc 2.34+ x86-64 abi3
SHA-256 checksum
How to use checksums
48992c5f8c3515a099471a2cc4761ccbeab6f21a34ca65e1a6d4edfd7ddf61a3
BLAKE2b-256 checksum
How to use checksums
fc5c2e43a24e5018d9a92eeebd6dc4818db7d3f5ab5282148a4a24f15cbff965
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / moirepy-0.0.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL moirepy-0.0.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 467.6 kB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
1a03c32565f6bc396939fdc28970f6f7480947e32b70dc8c346095deba431195
BLAKE2b-256 checksum
How to use checksums
d0395a23fcac21d09c42b8b4b18c74497017e19a64823f9400e54e580580002c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / moirepy-0.0.19-cp311-abi3-macosx_10_12_x86_64.whl

Download URL moirepy-0.0.19-cp311-abi3-macosx_10_12_x86_64.whl
Size 455.4 kB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
551c5fda371c29669d9d43077914bc8854d14570d30d029aff009984dcdad730
BLAKE2b-256 checksum
How to use checksums
3c5a3e8341fdab68b17945dd1c2acdcfcb66740213f53b40974c3d01db0420bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for moirepy 0.0.19

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

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