Extending TB2J

In this section we show how to extend TB2J to interface with other first principles or similar codes and to write the output formats useful for codes such as spin dynamics.

Interface TB2J with other first principles or similar codes.

To interface a DFT code with TB2J, one has only to implement a tight-binding-like model which has certain methods and properties implemented. TB2J make use of the duck type feature of python, thus any class which has these things can be plugged in. Then the object can be inputted to the TB2J.Exchange class.

The methods and properties of AbstractTB class is listed as below.

class TB2J.myTB.AbstractTB(R2kfactor, nspin, norb)
HS_and_eigen(kpts)

get Hamiltonian, overlap matrices, eigenvalues, eigen vectors for all kpoints.

Param:
  • kpts: list of k points.
Returns:
  • H, S, eigenvalues, eigenvectors for all kpoints
  • H: complex array of shape (nkpts, nbasis, nbasis)
  • S: complex array of shape (nkpts, nbasis, nbasis). S=None if the basis set is orthonormal.
  • evals: complex array of shape (nkpts, nbands)
  • evecs: complex array of shape (nkpts, nbasis, nbands)
get_hamR(R)

get the Hamiltonian H(R), array of shape (nbasis, nbasis)

get_orbs()

returns the orbitals.

is_siesta = None

\(\alpha\) used in \(H(k)=\sum_R H(R) \exp( \alpha k \cdot R)\), Should be \(2\pi i\) or \(-2\pi i\)

nbasis = None

nbasis=nspin*norb

norb = None

number of orbitals. Each orbital can have two spins.

nspin = None

number of spin. 1 for collinear, 2 for spinor.

xcart = None

The array of cartesian coordinate of all basis. shape:nbasis,3

xred = None

The array of cartesian coordinate of all basis. shape:nbasis,3

To pass the tight-binding-like model to the Exchange class is quite simple, here I take the sisl interface as an example

# read hamiltonian using sisl
fdf = sisl.get_sile(fdf_fname)
H = fdf.read_hamiltonian()
# wrap the hamiltonian to SislWrapper
tbmodel = SislWrapper(H, spin=None)
# pass to ExchangeNCL
exchange = ExchangeNCL(
    tbmodels=tbmodel,
    atoms=atoms,
    efermi=0.0,
    magnetic_elements=magnetic_elements,
    kmesh=kmesh,
    emin=emin,
    emax=emax,
    nz=nz,
    exclude_orbs=exclude_orbs,
    Rcut=Rcut,
    ne=ne,
    description=description)
exchange.run()

In which the SislWrapper is a AbstractTB-like class which use sisl to read the Hamiltonian and overlap matrix from Siesta output.

Extend the output to other formats

The calculated magnetic interaction parameters, together with other informations, such as the atomic structure and some metadata, are saved in “SpinIO” object. By making use of it, it is easy to output the parameters to the file format needed. Some parameters, which cannot be calculated in TB2J can also be inputted so that they can be written to the files. The list of stored data is listed below, by using which it should be easy to write the output function as a member of the SpinIO class. A method write_some_format(path) can be implemented and called in the write_all method. Then the format is automatically written after the TB2J calculation.

class TB2J.io_exchange.SpinIO(atoms, spinat, charges, index_spin, orbital_names={}, colinear=True, distance_dict=None, exchange_Jdict=None, exchange_Jdict_orb=None, dJdx=None, dmi_ddict=None, Jani_dict=None, biquadratic_Jdict=None, debug_dict=None, k1=None, k1dir=None, NJT_Jdict=None, NJT_ddict=None, damping=None, gyro_ratio=None, write_experimental=True, description=None)
Jani_dict = None

The dictionary of anisotropic exchange. The vlaues are matrices of shape (3,3).

atoms = None

atomic structures, ase.Atoms object

colinear = None

If the calculation is collinear or not

distance_dict = None

A dictionary of distances, the keys are (i,j, R), where i and j are spin index and R is the cell index, a tuple of three integers.

dmi_ddict = None

The dictionary of DMI. the key is the same as exchange_Jdict, the values are 3-d vectors (Dx, Dy, Dz).

exchange_Jdict = None

The dictionary of \(J_{ij}(R)\), the keys are (i,j, R), where R is a tuple, and the value is the isotropic exchange

gyro_ratio = None

Gyromagnetic ratio for each atom

has_bilinear = None

Whether there is anisotropic exchange term

has_dmi = None

Whether there is DMI.

has_exchange = None

whether there is isotropic exchange

ind_atoms = None

The index of atom for each spin.

index_spin = None

index of spin linked to atoms. -1 if non-magnetic

classmethod load_pickle(path='TB2J_resutls', fname='TB2J.pickle')
plot_DvsR(ax=None, fname=None, show=False)
plot_JanivsR(ax=None, fname=None, show=False)
plot_JvsR(ax=None, color='blue', marker='o', fname=None, show=False)
plot_all(title=None, savefile=None, show=False)
spinat = None

spin for each atom. shape of (natom, 3)

write_Jq(kmesh, path, **kwargs)
write_all(path='TB2J_results')
write_multibinit(path)
write_pickle(path='TB2J_results', fname='TB2J.pickle')
write_tom_format(path)
write_txt(path)
write_uppasd(path)
write_vampire(path)