magnopy.io.load_tb2j#

magnopy.io.load_tb2j(filename, spin_values=None, spglib_types=None, g_factors=None, missing_bonds='restore', when_present='raise error', quiet=True) SpinHamiltonian[source]#

Reads spin Hamiltonian from the "exchange.out" file produced by TB2J.

Parameters:
filenamestr

Path to the "exchange.out" file produced by TB2J.

spin_values(M, ) iterable of floats, optional

Spin values for all magnetic atoms. Order is the same as in TB2J file. Magnetic atoms are defined as those that have at least one parameter associated with them. If none given, Magnopy sets spin value as \(|\boldsymbol{m} / g_{factor}|\) for each spin, where \(\boldsymbol{m}\) is the magnetic moment, read from the TB2J file.

spglib_types(M_prime, ) iterable of ints, optional

Spglib types for all atoms (not only for magnetic ones, but for all). Order is the same as in TB2J file. If none given, then there will be no "spglib_types" key in spinham.atoms.

g_factors(M, ) iterable of floats, optional

g-factors for all atoms. Order is the same as in TB2J file. If none given, then Magnopy sets \(g = 2\) for all atoms.

missing_bondsbool, default "restore"

Added in version 0.5.2.

What to do if some of the equivalent bonds are missing (see Equivalent parameters and Multiple counting for more details on equivalent bonds). Case-insensitive. Supported options are

  • "restore" (default) Magnopy adds missing equivalent bonds, by inserting additional parameters.

  • "ignore"

    Magnopy does nothing.

when_presentstr, default "raise error"

Added in version 0.5.2.

What to do if the exact same interaction is repeated twice in the file. See SpinHamiltonian.add() for supported values.

quietbool, default True

If False, warnings are printed when distances between atoms computed by Magnopy are different from the distances read from the TB2J file. This is a legacy feature, kept for the sake of backward compatibility. See Notes for details.

Returns:
spinhamSpinHamiltonian

Spin Hamiltonian, that is built from the TB2J file.

Raises:
ValueError

If spin_values is provided and its length does not match the number of magnetic atoms in the Hamiltonian.

ValueError

If spglib_types is provided and its length does not match the number of atoms in the Hamiltonian.

Notes

TB2J outputs distances between atoms for each exchange bond. Magnopy do not use those, but rather computes distances based on the unit cell and atom positions if necessary. At the moment of reading the file it can check if the distance read from the file is different from the computed one and print a warning if quiet=False. Computed and read distances tend to differ in the last digits, since the unit cell is provided with the same precision as the distance in the TB2J file.