TB2J: A python package for computing magnetic interaction parameters

Xu He*, Nicole Helbig, Matthieu J. Verstraete, Eric Bousquet

*Corresponding author for this work

Research output: Contribution to journalArticleAcademicpeer-review


We present TB2J, a Python package for the automatic computation of magnetic interactions, including exchange and Dzyaloshinskii–Moriya, between atoms of magnetic crystals from the results of density functional calculations. The program is based on the Green's function method with the local rigid spin rotation treated as a perturbation. As input, the package uses the output of either Wannier90, which is interfaced with many density functional theory packages, or of codes based on localized orbitals. One of the main interests of the code is that it requires only one first-principles electronic structure calculation in the non-relativistic case (or three in the relativistic case) and from the primitive cell only to obtain the magnetic interactions up to long distances, instead of first-principles calculations of many different magnetic configurations and large supercells. The output of TB2J can be used directly for the adiabatic magnon band structure and spin dynamics calculations. A minimal user input is needed, which allows for easy integration into high-throughput workflows. Program summary: Program Title: TB2J CPC Library link to program files: https://doi.org/10.17632/dm45fcn69d.1 Developer's repository link: https://github.com/mailhexu/TB2J Code Ocean capsule: https://codeocean.com/capsule/6486145 Licensing provisions: BSD 2-clause Programming language: Python Nature of problem: TB2J is a package for the computing of parameters in the extended Heisenberg model of the magnetic interaction, including the isotropic exchange, anisotropic exchange and Dzyaloshinskii–Moriya interactions from first principles result. It can make use of the Wannier function Hamiltonian, which can be constructed from many first principles codes, or localized orbital based codes. Solution method: It uses the magnetic force theorem and takes the rigid spin rotation as a perturbation to the electronic structure. The energy variation is calculated from the Green's functions from tight-binding like Hamiltonian based on Wannier functions or localized orbitals. Additional comments including restrictions and unusual features: Isotropic exchange, anisotropic exchange, and Dzyaloshinskii–Moriya interactions can all be computed with the input of many DFT codes through the interface of Wannier90, or directly from localized orbital codes. The magnetic interaction parameters up to any distance can be computed from one DFT calculation. A minimum user-input is required which provides a black-box like experience. It generates output for several spin dynamics codes and thus bridges the first principles electronic structure simulation with the large scale spin dynamics simulation.

Original languageEnglish
Article number107938
JournalComputer Physics Communications
Publication statusPublished - Jul 2021
Externally publishedYes


  • Anisotropic exchange
  • Dzyaloshinskii–Moriya interaction
  • Exchange
  • Green's function
  • Heisenberg model


Dive into the research topics of 'TB2J: A python package for computing magnetic interaction parameters'. Together they form a unique fingerprint.

Cite this