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.

  • Report bugs or request features via issues
  • Submit pull requests for improvements
  • Add examples, tutorials, or benchmarks

A detailed contributing guide will be added soon.


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.17.tar.gz (1.6 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.17-cp311-abi3-win_amd64.whl (333.6 kB view details)

Uploaded CPython 3.11+Windows x86-64

moirepy-0.0.17-cp311-abi3-manylinux_2_34_x86_64.whl (493.5 kB view details)

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

moirepy-0.0.17-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (465.9 kB view details)

Uploaded CPython 3.11+manylinux: glibc 2.17+ ARM64

moirepy-0.0.17-cp311-abi3-macosx_10_12_x86_64.whl (456.6 kB view details)

Uploaded CPython 3.11+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for moirepy-0.0.17.tar.gz
Algorithm Hash digest
SHA256 c96405e77f44fcc79cbab00fcb2050b115d1c0489f0bfeaadb08d28ca3a8e027
MD5 131157fc88af802695052e40c7b0112d
BLAKE2b-256 9c502a3288067e89f3b4aae0d1bcfb16e0952cb3d211dae2e902bd8e7a916c8e

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for moirepy-0.0.17-cp311-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 28f6932a1b840fa2498ef0ec71efe2fbf407be3810bfa067aef16ff94412ec48
MD5 4e4bed5965bb7dbed706f36ed5c83c2b
BLAKE2b-256 e6feded6bff7d288a4e5ff554609419d3fc23fcdb04c4148a3705358ad7602cb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for moirepy-0.0.17-cp311-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f649caae46cc56a4b973ad464fc4af58bd7f666d18d088ea5b31b300efeae609
MD5 b1d3185e75a84dec8a4b8eb044096789
BLAKE2b-256 255d35f9bca5eb5846f90627457b51b8e724997f88087b3d3bc67be2a5088349

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for moirepy-0.0.17-cp311-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 adf2bc1397cd3d3821095c5c26b67b821bc3f100f98947f991c38f4efc1d0856
MD5 038e5f689290ba676de5e477c937801f
BLAKE2b-256 4f4e3f19dd61092c0c09436c5201e90a3e581251da8d2b47e0f1c00c54031142

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for moirepy-0.0.17-cp311-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f60a5b3f1128bc11251f8cdf7fcf1a2a7f7861a496c2b5c262ab76c7f0671131
MD5 cbf5fbbfb0d23776c49ce4f9e21560bc
BLAKE2b-256 03226863bf5f5527171f87ad686e11d09555d88f460f08dcd82e3fb42bc40bb6

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