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_orthogonal
\(\alpha\) used in \(H(k)=\sum_R H(R) \exp( \alpha k \cdot R)\), Should be \(2\pi i\) or \(-2\pi i\)
- nbasis
nbasis=nspin*norb
- norb
number of orbitals. Each orbital can have two spins.
- nspin
number of spin. 1 for collinear, 2 for spinor.
- xcart
The array of cartesian coordinate of all basis. shape:nbasis,3
- xred
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, Jiso_orb=None, DMI_orb=None, Jani_orb=None, dJdx=None, dJdx2=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
The dictionary of anisotropic exchange. The vlaues are matrices of shape (3,3).
- atoms
atomic structures, ase.Atoms object
- colinear
If the calculation is collinear or not
- dmi_ddict
The dictionary of DMI. the key is the same as exchange_Jdict, the values are 3-d vectors (Dx, Dy, Dz).
- get_DMI(i, j, R, default=None)
- get_J(i, j, R, default=None)
- get_J_tensor(i, j, R, iso_only=False)
Return the full exchange tensor for atom i and j, and cell R. param i : spin index i param j: spin index j param R (tuple of integers): cell index R
- get_Jani(i, j, R, default=None)
Return the anisotropic exchange tensor for atom i and j, and cell R. param i : spin index i param j: spin index j param R (tuple of integers): cell index R
- get_Jiso(i, j, R, default=None)
- get_charge_iatom(iatom)
- get_charge_ispin(i)
- get_full_Jtensor_for_Rlist(asr=False, iso_only=False)
- get_full_Jtensor_for_one_R(R)
Return the full exchange tensor of all i and j for cell R. param R (tuple of integers): cell index R returns:
Jmat: (3*nspin,3*nspin) matrix.
- get_spin_iatom(iatom)
- get_spin_ispin(i)
- get_symbol_number_ispin(symnum)
Return the spin index for a given symbol number.
- gyro_ratio
Gyromagnetic ratio for each atom
- has_bilinear
Whether there is anisotropic exchange term
- has_dmi
Whether there is DMI.
- has_exchange
whether there is isotropic exchange
- i_spin(i)
- iatom(i)
- property ind_atoms
- classmethod load_pickle(path='TB2J_results', fname='TB2J.pickle')
- model(path)
- 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, **kwargs)
- plot_all(title=None, savefile=None, show=False)
- spinat
spin for each atom. shape of (natom, 3)
- write_Jq(kmesh, path, gamma=True, output_fname='EigenJq.txt', **kwargs)
- write_all(path='TB2J_results')
- write_multibinit(path)
- write_pickle(path='TB2J_results', fname='TB2J.pickle')
- write_tom_format(path)
- write_txt(*args, **kwargs)
- write_uppasd(path)
- write_vampire(path)