Skip to main content

A Python package for analyzing the Hofstadter model.

Project description

docs pytests pypi conda-forge license

HofstadterTools (HT) is a set of Python programs and classes for analyzing the Hofstadter model, which describes the behavior of non-interacting quantum particles hopping on a lattice coupled to a gauge field. This package can be used to compute the band structure of a generalized Hofstadter model on any regular Euclidean lattice, as well as its key properties, such as quantum geometry and topology.

Quick Start

Installing HofstadterTools is quick and easy!

Using pip:

pip install HofstadterTools

Using conda:

conda install conda-forge::HofstadterTools

You can now access the band_structure and butterfly programs from any location. The band_structure program evaluates the Hofstadter band structure at fixed flux density \(n_\phi=p/q\) for a range of momenta \(\mathbf{k}=(k_x,k_y)\), whereas the butterfly program evaluates the energy spectrum at fixed momentum \(\mathbf{k}=\mathbf{0}\) for a range of \(n_\phi=p/q\), where \(p\) and \(q\) are coprime integers.

band_structure -lat square -nphi 1 4 --display both --wilson

3D Band Structure Wilson Loops 2D Band Structure

butterfly -lat square -q 97 --color point --wannier --plot_lattice

Butterfly Spectrum Wannier Diagram Lattice

Voilà! You have just plotted the Hofstadter band structure for nearest-neighbor hopping on the square lattice at flux density \(n_\phi=1/4\), together with the corresponding butterfly spectrum at \(q=97\). You can append --help to either of these programs to view the list of options. Alternatively, you can explore the gallery and code reference to see what HofstadterTools has to offer.

Installation

This package was developed using Ubuntu 20.04.6 (x86_64) with Python=3.10.13, however it is designed to be platform-independent and can work with any Python>=3.9.

Basic install

For basic usage of HofstadterTools, i.e. in cases where you do not plan on editing the source code, you can install the package from a distribution.

Using pip

  1. [Optional] Create and activate a new venv environment. In the example below, my_env is the name of the venv and its parent folder. If needed, you can replace python3 with python3.xx below to create a venv pinned to a particular Python version.

user@domain:any/path$ python3 -m venv my_env
user@domain:any/path$ source path/to/my_env/bin/activate
  1. Install HofstadterTools from PyPI.

(my_env) user@domain:any/path$ pip install HofstadterTools
  1. [Optional] Upgrade an existing HofstadterTools installation.

(my_env) user@domain:any/path$ pip install --upgrade HofstadterTools

You can verify the installation by typing pip list | grep HofstadterTools, you can uninstall by typing pip uninstall HofstadterTools, and you can deactivate the environment by typing deactivate. The entire environment can be removed by deleting the my_env folder.

Using conda

  1. [Optional] Create and activate a new conda environment. In the example below, my_env is the name of the conda environment. If needed, you can replace python=3 with python=3.xx below to create a conda environment with a particular Python version pre-installed.

user@domain:any/path$ conda create -n my_env python=3
user@domain:any/path$ conda activate my_env
  1. Install HofstadterTools from conda-forge.

(my_env) user@domain:any/path$ conda install conda-forge::HofstadterTools
  1. [Optional] Update an existing HofstadterTools installation.

(my_env) user@domain:any/path$ conda update HofstadterTools

You can verify the installation by typing conda list | grep hofstadtertools, you can uninstall by typing conda remove HofstadterTools, and you can deactivate the environment by typing conda deactivate. The entire environment can be removed by typing conda remove -n my_env --all.

Advanced install

For advanced usage of HofstadterTools, i.e. in cases where you do plan on editing the source code, you can install the package from source.

  1. Clone the HofstadterTools repository.

user@domain:any/path$ git clone git@github.com:HofstadterTools/HofstadterTools.git
  1. Using pip, install the HofstadterTools package. This step can also be done in a virtual environment. The optional -e flag below indicates an editable install.

user@domain:path/to/HofstadterTools$ pip install -e .

Alternatively, if you plan on building the documentation locally, the optional docs dependencies need to be installed.

user@domain:path/to/HofstadterTools$ pip install -e ".[docs]"
  1. [Optional] Build and view the documentation locally. The optional clean argument below removes files from the build directory, and firefox can be replaced with any web browser.

user@domain:path/to/HofstadterTools/docs$ make clean html
user@domain:path/to/HofstadterTools/docs$ firefox build/html/index.html &

Testing

You can confirm that HofstadterTools is correctly installed by running the pytests.

user@domain:any/path$ pytest --pyargs HT

Once the project HofstadterTools is installed, the package HT will be available in your Python environment. In addition, you can access the programs band_structure, butterfly, plot_band_structure, and plot_butterfly, from any location.

user@domain:any/path$ band_structure --help
user@domain:any/path$ butterfly --help
user@domain:any/path$ plot_band_structure --help
user@domain:any/path$ plot_butterfly --help

The plot_* programs are used to replot band_structures / butterflies that have been saved to file.

Directory Structure

  • src – sources root with the HT package, along with its configuration settings, subpackages, and programs. A detailed description of the available programs and namespace packages is in the documentation.

    • HTHT package.

      • configuration – user-defined configuration files for the programs.

      • functions – helper functions for the programs.

      • models – model classes for the programs.

      • plot – location of the plot scripts.

      • tests – unit tests for the programs.

  • data – output destination for raw data files (if programs are run explicitly from their file location, otherwise the output destination is the current working directory).

    • band_structure – data generated by the band_structure program.

    • butterfly – data generated by the butterfly program.

  • docs – location of the sphinx documentation. To view the documentation locally, compile by running make html or make clean html and then open build/html/index.html in a web browser. This assumes that the optional docs dependencies are installed.

    • build – compiled documentation (once built).

    • source – documentation source.

  • figs – output destination for the figures (if programs are run explicitly from their file location, otherwise the output destination is the current working directory).

    • band_structure – figures generated by the band_structure program.

    • butterfly – figures generated by the butterfly program.

  • logs – output destination for the log files (if programs are run explicitly from their file location, otherwise the output destination is the current working directory).

    • band_structure – logs generated by the band_structure program.

    • butterfly – logs generated by the butterfly program.

  • paper – summary paper introducing HofstadterTools. The formatted pdf can be downloaded as an artifact of the production-pdf workflow under the GitHub actions tab.

How to Cite

If you have found HofstadterTools useful, it would be greatly appreciated if you could cite us in your work. Please find the bibtex reference below.

@article{HofstadterTools,
doi = {10.21105/joss.06356},
url = {https://doi.org/10.21105/joss.06356},
year = {2024},
publisher = {The Open Journal},
volume = {9},
number = {95},
pages = {6356},
author = {Bartholomew Andrews},
title = {HofstadterTools: A Python package for analyzing the Hofstadter model},
journal = {Journal of Open Source Software}
}

Acknowledgments

We thank Gunnar Möller, Titus Neupert, Rahul Roy, Alexey Soluyanov, Michael Zaletel, Daniel Parker, Stefan Divic, Johannes Mitscherling, and Mathi Raja, for useful discussions. This project was funded by the Swiss National Science Foundation under Grant No. P500PT_203168, and supported by the U.S. Department of Energy, Office of Science, Basic Energy Sciences, under Early Career Award No. DE-SC0022716.

Contributing

The Hofstadter model is an active field of research and therefore HofstadterTools will never be complete. Here is a list of some features that we have on the pipeline to be implemented (in no particular order):

  • support for hyperbolic lattices [Stegmaier22]

  • support for fractal lattices [Chen20]

  • support for higher-dimensional lattices [DiColandrea22]

  • support for quasicrystals [Ghadimi22]

  • support for open boundary conditions [Pena23]

  • interface to quantum chemistry codes [Bodesheim23]

  • capability to compute the non-Abelian Hofstadter moth [Osterloh05], [Yang20]

  • capability to compute Chern numbers using bulk-edge correspondence [Agazzi14]

  • capability to generate the potential function corresponding to hopping amplitudes [Yilmaz17]

  • implementation of other topological flat-band models for benchmarking (e.g. chiral pi-flux model) [Neupert11]

Contributions are always welcome! The HofstadterTools repository is maintained using GitHub. If you would like to contribute, please submit a pull request; if you would like to report an issue or problem, please open an issue; and if you need to seek support, please start a discussion. For all other enquires, please contact Bart Andrews.

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

HofstadterTools-1.0.4.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

HofstadterTools-1.0.4-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file HofstadterTools-1.0.4.tar.gz.

File metadata

  • Download URL: HofstadterTools-1.0.4.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for HofstadterTools-1.0.4.tar.gz
Algorithm Hash digest
SHA256 c14a80164c72cb905cac9a58739aa985caa44443a042b803e3a2efab4d28a42f
MD5 1193f5f33a3a40ada5de11da00055380
BLAKE2b-256 07911f5bf823c0f3f029fd4e9e16712c533ac62c9549bf6bb8ce1af80e08027f

See more details on using hashes here.

File details

Details for the file HofstadterTools-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for HofstadterTools-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4491ccad9d136d0142e5ff2cb9b02f05da89f0f6b24e7beefec1e80b103ce6d1
MD5 d649e39bf5808d18995d7c9215fa482c
BLAKE2b-256 6e09c949c95da69bc0d6fcd6434e2bfbd79a72f645bf4190a36dadfea18be982

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page