Skip to main content

Simulate moire systems, generate hamiltonian in both real and momentum space and calculate various related observables.

Project description

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}
}

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

moirepy-0.0.19.tar.gz (2.1 MB view details)

Uploaded Source

Built Distributions

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

moirepy-0.0.19-cp311-abi3-win_amd64.whl (334.6 kB view details)

Uploaded CPython 3.11+Windows x86-64

moirepy-0.0.19-cp311-abi3-manylinux_2_34_x86_64.whl (494.7 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.34+ x86-64

moirepy-0.0.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (467.6 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

moirepy-0.0.19-cp311-abi3-macosx_10_12_x86_64.whl (455.4 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

Details for the file moirepy-0.0.19.tar.gz.

File metadata

  • Download URL: moirepy-0.0.19.tar.gz
  • Upload date:
  • Size: 2.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moirepy-0.0.19.tar.gz
Algorithm Hash digest
SHA256 66f9cd15fa7693292b1c00bd931c9a05c53cb85cfb92bc8a0f89d17cf012a5f1
MD5 1afa13d6b1ea865b987bbe1587d1c85a
BLAKE2b-256 17c1a87b2146928b638f25d966c971c79fd62a8ba366830e33f4fe15ace4e8ca

See more details on using hashes here.

File details

Details for the file moirepy-0.0.19-cp311-abi3-win_amd64.whl.

File metadata

  • Download URL: moirepy-0.0.19-cp311-abi3-win_amd64.whl
  • Upload date:
  • Size: 334.6 kB
  • Tags: CPython 3.11+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for moirepy-0.0.19-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8d97eac73ea03c14a2519c9511658ca39f3a43fc21eb052e1ff531531416cd6e
MD5 6491b71581ac820d9e4a916cfc02347f
BLAKE2b-256 f5b21e6df7ebb3a3b01781661d5c030624929198ec17045b3e8707b7b5af48fb

See more details on using hashes here.

File details

Details for the file moirepy-0.0.19-cp311-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for moirepy-0.0.19-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 48992c5f8c3515a099471a2cc4761ccbeab6f21a34ca65e1a6d4edfd7ddf61a3
MD5 b5698de0eb315b7e93daf924a5855af6
BLAKE2b-256 fc5c2e43a24e5018d9a92eeebd6dc4818db7d3f5ab5282148a4a24f15cbff965

See more details on using hashes here.

File details

Details for the file moirepy-0.0.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for moirepy-0.0.19-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1a03c32565f6bc396939fdc28970f6f7480947e32b70dc8c346095deba431195
MD5 61dd18559bee87e6f2752c86c2d8a206
BLAKE2b-256 d0395a23fcac21d09c42b8b4b18c74497017e19a64823f9400e54e580580002c

See more details on using hashes here.

File details

Details for the file moirepy-0.0.19-cp311-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for moirepy-0.0.19-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 551c5fda371c29669d9d43077914bc8854d14570d30d029aff009984dcdad730
MD5 bb5c995a3c107640b33ba4b097608513
BLAKE2b-256 3c5a3e8341fdab68b17945dd1c2acdcfcb66740213f53b40974c3d01db0420bb

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