Exemplo n.º 1
0
def gen_exchange_gpaw(gpw_fname,
                      magnetic_elements=[],
                      kmesh=[3, 3, 3],
                      emin=-12.0,
                      emax=0.0,
                      nz=50,
                      exclude_orbs=[],
                      Rcut=None,
                      description=''):
    print("Reading from GPAW data and calculate electronic structure.")
    model = GPAWWrapper(gpw_fname=gpw_fname)
    efermi = model.calc.get_fermi_level()
    print(f"Fermi Energy: {efermi}")
    poses = np.vstack([model.positions, model.positions])
    basis, _ = auto_assign_basis_name(poses, model.atoms)
    if model.calc.get_spin_polarized():
        print("Starting to calculate exchange.")
        exchange = ExchangeNCL(tbmodels=model,
                               atoms=model.atoms,
                               efermi=efermi,
                               basis=basis,
                               magnetic_elements=magnetic_elements,
                               kmesh=kmesh,
                               emin=emin,
                               emax=emax,
                               nz=nz,
                               exclude_orbs=exclude_orbs,
                               Rcut=Rcut,
                               description=description)
        exchange.run()
        print("\n")
        print(
            "All calculation finsihed. The results are in TB2J_results directory."
        )
Exemplo n.º 2
0
 def read_from_wannier_dir(path,
                           prefix,
                           posfile='POSCAR',
                           nls=True,
                           groupby='spin'):
     """
     read tight binding model from a wannier function directory. 
     :param path: path
     :param prefix: prefix to the wannier files, often wannier90, or wannier90_up, or wannier90_dn for vasp.
     """
     #tbmodel = Model.from_wannier_folder(
     #    folder=path, prefix=prefix)
     #m = MyTB.from_tbmodel(tbmodel)
     nbasis, data = parse_ham(fname=os.path.join(path, prefix + '_hr.dat'))
     xcart, _, _ = parse_xyz(fname=os.path.join(path, prefix +
                                                '_centres.xyz'))
     atoms = read(os.path.join(path, posfile))
     cell = atoms.get_cell()
     xred = cell.scaled_positions(xcart)
     if groupby == 'orbital':
         norb = nbasis // 2
         xtmp = np.copy(xred)
         xred[:norb] = xtmp[::2]
         xred[norb:] = xtmp[1::2]
         for key, val in data.items():
             dtmp = copy.deepcopy(val)
             data[key][:norb, :norb] = dtmp[::2, ::2]
             data[key][:norb, norb:] = dtmp[::2, 1::2]
             data[key][norb:, :norb] = dtmp[1::2, ::2]
             data[key][norb:, norb:] = dtmp[1::2, 1::2]
     ind, positions = auto_assign_basis_name(xred, atoms)
     m = MyTB(nbasis=nbasis, data=data, positions=xred)
     nm = m.shift_position(positions)
     nm.set_atoms(atoms)
     return nm
Exemplo n.º 3
0
 def read_from_wannier_dir(path, prefix, posfile='POSCAR', nls=True):
     """
     read tight binding model from a wannier function directory. 
     :param path: path
     :param prefix: prefix to the wannier files, often wannier90, or wannier90_up, or wannier90_dn for vasp.
     """
     #tbmodel = Model.from_wannier_folder(
     #    folder=path, prefix=prefix)
     #m = MyTB.from_tbmodel(tbmodel)
     nbasis, data = parse_ham(fname=os.path.join(path, prefix + '_hr.dat'))
     xcart, _, _ = parse_xyz(fname=os.path.join(path, prefix +
                                                '_centres.xyz'))
     atoms = read(os.path.join(path, posfile))
     cell = atoms.get_cell()
     xred = cell.scaled_positions(xcart)
     ind, positions = auto_assign_basis_name(xred, atoms)
     m = MyTB(nbasis=nbasis, data=data, positions=xred)
     nm = m.shift_position(positions)
     nm.set_atoms(atoms)
     return nm
Exemplo n.º 4
0
def gen_exchange(path,
                 colinear=True,
                 groupby='spin',
                 posfile='POSCAR',
                 prefix_up='wannier90.up',
                 prefix_dn='wannier90.dn',
                 prefix_SOC='wannier90',
                 min_hopping_norm=1e-4,
                 max_distance=None,
                 efermi=0,
                 magnetic_elements=[],
                 kmesh=[4, 4, 4],
                 emin=-12.0,
                 emax=0.0,
                 nz=100,
                 height=0.2,
                 nz1=50,
                 nz2=200,
                 nz3=50,
                 exclude_orbs=[],
                 Rcut=None,
                 ne=None,
                 use_cache=False,
                 np=1,
                 output_path='TB2J_results',
                 wannier_type="wannier90",
                 qspace=False,
                 description=''):
    atoms = read(os.path.join(path, posfile))
    basis_fname = os.path.join(path, 'basis.txt')
    if colinear:
        if wannier_type.lower() == "wannier90":
            print("Reading Wannier90 hamiltonian: spin up.")
            tbmodel_up = MyTB.read_from_wannier_dir(path=path,
                                                    prefix=prefix_up,
                                                    posfile=posfile,
                                                    nls=False)
            print("Reading Wannier90 hamiltonian: spin down.")
            tbmodel_dn = MyTB.read_from_wannier_dir(path=path,
                                                    prefix=prefix_dn,
                                                    posfile=posfile,
                                                    nls=False)
            if os.path.exists(basis_fname):
                basis = read_basis(basis_fname)
            else:
                basis, _ = auto_assign_basis_name(tbmodel_up.xred, atoms)
        elif wannier_type.lower() == "banddownfolder":
            print("Reading Banddownfolder hamiltonian: spin up.")
            tbmodel_up = MyTB.load_banddownfolder(path=path,
                                                  prefix=prefix_up,
                                                  posfile=posfile,
                                                  nls=False)
            print("Reading Banddownfolder hamiltonian: spin down.")
            tbmodel_dn = MyTB.load_banddownfolder(path=path,
                                                  prefix=prefix_dn,
                                                  posfile=posfile,
                                                  nls=False)

            basis, _ = auto_assign_basis_name(tbmodel_up.xred, atoms)
        else:
            raise ValueError(
                "wannier_type should be Wannier90 or banddownfolder.")

        print("Starting to calculate exchange.")
        description = f""" Input from collinear Wannier90 data.
 Tight binding data from {path}. 
 Prefix of wannier function files:{prefix_up} and {prefix_dn}.
Warning: Please check if the noise level of Wannier function Hamiltonian to make sure it is much smaller than the exchange values.
\n"""
        if not qspace:
            exchange = ExchangeCL2(tbmodels=(tbmodel_up, tbmodel_dn),
                                   atoms=atoms,
                                   basis=basis,
                                   efermi=efermi,
                                   magnetic_elements=magnetic_elements,
                                   kmesh=kmesh,
                                   emin=emin,
                                   emax=emax,
                                   nz=nz,
                                   height=height,
                                   nz1=nz1,
                                   nz2=nz2,
                                   nz3=nz3,
                                   exclude_orbs=exclude_orbs,
                                   Rcut=Rcut,
                                   ne=ne,
                                   np=np,
                                   use_cache=use_cache,
                                   description=description)
        else:
            exchange = ExchangeCLQspace(tbmodels=(tbmodel_up, tbmodel_dn),
                                        atoms=atoms,
                                        basis=basis,
                                        efermi=efermi,
                                        magnetic_elements=magnetic_elements,
                                        kmesh=kmesh,
                                        emin=emin,
                                        emax=emax,
                                        nz=nz,
                                        height=height,
                                        nz1=nz1,
                                        nz2=nz2,
                                        nz3=nz3,
                                        exclude_orbs=exclude_orbs,
                                        Rcut=Rcut,
                                        ne=ne,
                                        np=np,
                                        use_cache=use_cache,
                                        description=description)

        exchange.run(path=output_path)
        print(
            "All calculation finsihed. The results are in TB2J_results directory."
        )

    elif colinear and wannier_type.lower() == "banddownfolder":
        print("Reading Wannier90 hamiltonian: spin up.")
        tbmodel_up = MyTB.read_from_wannier_dir(path=path,
                                                prefix=prefix_up,
                                                posfile=posfile,
                                                nls=False)
        print("Reading Wannier90 hamiltonian: spin down.")
        tbmodel_dn = MyTB.read_from_wannier_dir(path=path,
                                                prefix=prefix_dn,
                                                posfile=posfile,
                                                nls=False)
        tbmodel = merge_tbmodels_spin(tbmodel_up, tbmodel_dn)
        basis, _ = auto_assign_basis_name(tbmodel.xred, atoms)
        description = f""" Input from collinear BandDownfolder data.
 Tight binding data from {path}. 
 Prefix of wannier function files:{prefix_up} and {prefix_dn}.
Warning: Please check if the noise level of Wannier function Hamiltonian to make sure it is much smaller than the exchange values.
\n"""
        print("Starting to calculate exchange.")
        exchange = ExchangeCL2(tbmodels=tbmodel,
                               atoms=atoms,
                               basis=basis,
                               efermi=efermi,
                               magnetic_elements=magnetic_elements,
                               kmesh=kmesh,
                               emin=emin,
                               emax=emax,
                               nz=nz,
                               height=height,
                               nz1=nz1,
                               nz2=nz2,
                               nz3=nz3,
                               exclude_orbs=exclude_orbs,
                               Rcut=Rcut,
                               ne=ne,
                               np=np,
                               use_cache=use_cache,
                               description=description)
        exchange.run(path=output_path)
        print(
            "All calculation finsihed. The results are in TB2J_results directory."
        )
    else:
        print("Reading Wannier90 hamiltonian: non-colinear spin.")
        groupby = groupby.lower().strip()
        if groupby not in ['spin', 'orbital']:
            raise ValueError("groupby can only be spin or orbital.")
        tbmodel = MyTB.read_from_wannier_dir(path=path,
                                             prefix=prefix_SOC,
                                             posfile=posfile,
                                             groupby=groupby,
                                             nls=True)
        if os.path.exists(basis_fname):
            print("The use of basis file is deprecated. It will be ignored.")
            #basis = read_basis(basis_fname)
        else:
            basis, _ = auto_assign_basis_name(tbmodel.xred, atoms)
        description = f""" Input from non-collinear Wannier90 data.
 Tight binding data from {path}. 
 Prefix of wannier function files:{prefix_SOC}.
Warning: Please check if the noise level of Wannier function Hamiltonian to make sure it is much smaller than the exchange values.
 The DMI component parallel to the spin orientation, the Jani which has the component of that orientation should be disregarded
 e.g. if the spins are along z, the xz, yz, zz, zx, zy components and the z component of DMI.
 If you need these component, try to do three calculations with spin along x, y, z,  or use structure with z rotated to x, y and z. And then use TB2J_merge.py to get the full set of parameters.

\n"""
        print("Starting to calculate exchange.")
        exchange = ExchangeNCL(tbmodels=tbmodel,
                               atoms=atoms,
                               basis=basis,
                               efermi=efermi,
                               magnetic_elements=magnetic_elements,
                               kmesh=kmesh,
                               emin=emin,
                               emax=emax,
                               nz=nz,
                               height=height,
                               nz1=nz1,
                               nz2=nz2,
                               nz3=nz3,
                               exclude_orbs=exclude_orbs,
                               Rcut=Rcut,
                               ne=ne,
                               np=np,
                               use_cache=use_cache,
                               description=description)
        print("\n")
        exchange.run(path=output_path)
        print(
            f"All calculation finsihed. The results are in {output_path} directory."
        )
Exemplo n.º 5
0
def gen_exchange(path,
                 colinear=True,
                 orb_order=1,
                 posfile='POSCAR',
                 prefix_up='wannier90.up',
                 prefix_dn='wannier90.dn',
                 prefix_SOC='wannier90',
                 min_hopping_norm=1e-4,
                 max_distance=None,
                 efermi=0,
                 magnetic_elements=[],
                 kmesh=[4, 4, 4],
                 emin=-12.0,
                 emax=0.0,
                 nz=100,
                 height=0.2,
                 nz1=50,
                 nz2=200,
                 nz3=50,
                 exclude_orbs=[],
                 Rcut=None,
                 ne=None,
                 description=''):
    atoms = read(os.path.join(path, posfile))
    basis_fname = os.path.join(path, 'basis.txt')
    if colinear:
        print("Reading Wannier90 hamiltonian: spin up.")
        tbmodel_up = MyTB.read_from_wannier_dir(path=path,
                                                prefix=prefix_up,
                                                posfile=posfile,
                                                nls=False)
        print("Reading Wannier90 hamiltonian: spin down.")
        tbmodel_dn = MyTB.read_from_wannier_dir(path=path,
                                                prefix=prefix_dn,
                                                posfile=posfile,
                                                nls=False)
        if os.path.exists(basis_fname):
            basis = read_basis(basis_fname)
        else:
            basis, _ = auto_assign_basis_name(tbmodel_up.xred, atoms)
        print("Starting to calculate exchange.")
        exchange = ExchangeCL2(tbmodels=(tbmodel_up, tbmodel_dn),
                               atoms=atoms,
                               basis=basis,
                               efermi=efermi,
                               magnetic_elements=magnetic_elements,
                               kmesh=kmesh,
                               emin=emin,
                               emax=emax,
                               nz=nz,
                               height=height,
                               nz1=nz1,
                               nz2=nz2,
                               nz3=nz3,
                               exclude_orbs=exclude_orbs,
                               Rcut=Rcut,
                               ne=ne,
                               description=description)
        exchange.run()
        print(
            "All calculation finsihed. The results are in TB2J_results directory."
        )

    elif colinear and 0:
        print("Reading Wannier90 hamiltonian: spin up.")
        tbmodel_up = MyTB.read_from_wannier_dir(path=path,
                                                prefix=prefix_up,
                                                posfile=posfile,
                                                nls=False)
        print("Reading Wannier90 hamiltonian: spin down.")
        tbmodel_dn = MyTB.read_from_wannier_dir(path=path,
                                                prefix=prefix_dn,
                                                posfile=posfile,
                                                nls=False)
        tbmodel = merge_tbmodels_spin(tbmodel_up, tbmodel_dn)
        if os.path.exists(basis_fname):
            basis = read_basis(basis_fname)
        else:
            basis, _ = auto_assign_basis_name(tbmodel.xred, atoms)
        print("Starting to calculate exchange.")
        exchange = ExchangeCL(tbmodels=tbmodel,
                              atoms=atoms,
                              basis=basis,
                              efermi=efermi,
                              magnetic_elements=magnetic_elements,
                              kmesh=kmesh,
                              emin=emin,
                              emax=emax,
                              nz=nz,
                              height=height,
                              nz1=nz1,
                              nz2=nz2,
                              nz3=nz3,
                              exclude_orbs=exclude_orbs,
                              Rcut=Rcut,
                              ne=ne,
                              description=description)
        exchange.run()
        print(
            "All calculation finsihed. The results are in TB2J_results directory."
        )
    else:
        print("Reading Wannier90 hamiltonian: non-colinear spin.")
        tbmodel = MyTB.read_from_wannier_dir(path=path,
                                             prefix=prefix_SOC,
                                             posfile=posfile,
                                             nls=True)
        if orb_order == 1:
            pass
        if orb_order == 2:
            tbmodel = tbmodel.reorder()
        if os.path.exists(basis_fname):
            print("The use of basis file is deprecated. It will be ignored.")
            #basis = read_basis(basis_fname)
        else:
            basis, _ = auto_assign_basis_name(tbmodel.xred, atoms)
        print("Starting to calculate exchange.")
        exchange = ExchangeNCL(tbmodels=tbmodel,
                               atoms=atoms,
                               basis=basis,
                               efermi=efermi,
                               magnetic_elements=magnetic_elements,
                               kmesh=kmesh,
                               emin=emin,
                               emax=emax,
                               nz=nz,
                               height=height,
                               nz1=nz1,
                               nz2=nz2,
                               nz3=nz3,
                               exclude_orbs=exclude_orbs,
                               Rcut=Rcut,
                               ne=ne,
                               description=description)
        print("\n")
        exchange.run()
        print(
            "All calculation finsihed. The results are in TB2J_results directory."
        )
Exemplo n.º 6
0
 def test_assign_basis(self):
     basis_dict, shifted_pos = auto_assign_basis_name(
         positions=self.tbmodel.xred, atoms=self.atoms)
     # Note that it starts from 1.
     self.assertEqual(basis_dict['Ru1|orb_1'], 1)
     self.assertEqual(basis_dict['Ru1|orb_6'], 29)
Exemplo n.º 7
0
Arquivo: Oiju.py Projeto: wangvei/TB2J
def gen_exchange_Oiju(path,
                      amp,
                      colinear=True,
                      poscar='POSCAR',
                      prefix_up='wannier90.up',
                      prefix_dn='wannier90.dn',
                      prefix_SOC='wannier90',
                      d0_up_ncfile='m0_up.nc',
                      d0_dn_ncfile='m0_dn.nc',
                      dHdx_up_ncfile='m1_up.nc',
                      dHdx_dn_ncfile='m1_dn.nc',
                      d2_up_ncfile='m2_up.nc',
                      d2_dn_ncfile='m2_dn.nc',
                      min_hopping_norm=1e-6,
                      max_distance=None,
                      efermi=3.,
                      magnetic_elements=[],
                      kmesh=[5, 5, 5],
                      emin=-12.0,
                      emax=0.0,
                      height=0.2,
                      nz1=50,
                      nz2=200,
                      nz3=50,
                      exclude_orbs=[],
                      Rmesh=[1, 1, 1],
                      description=''):
    atoms = read(os.path.join(path, poscar))
    basis_fname = os.path.join(path, 'basisb.txt')
    if colinear:
        tbmodel_up = MyTB.read_from_wannier_dir(
            path=path, prefix=prefix_up, poscar=poscar, nls=False)
        tbmodel_dn = MyTB.read_from_wannier_dir(
            path=path, prefix=prefix_dn, poscar=poscar, nls=False)
        tbmodel = merge_tbmodels_spin(tbmodel_up, tbmodel_dn)

        dHdx_up = MyTB.load_MyTB(dHdx_up_ncfile)
        dHdx_dn = MyTB.load_MyTB(dHdx_dn_ncfile)
        dHdx = merge_tbmodels_spin(dHdx_up, dHdx_dn)

        d0_up = MyTB.load_MyTB(d0_up_ncfile)
        d0_dn = MyTB.load_MyTB(d0_dn_ncfile)
        d0 = merge_tbmodels_spin(d0_up, d0_dn)

        d2_up = MyTB.load_MyTB(d2_up_ncfile)
        d2_dn = MyTB.load_MyTB(d2_dn_ncfile)
        d2 = merge_tbmodels_spin(d2_up, d2_dn)

        tb = PolyTB(ref_model=tbmodel, m0=d0, m1=dHdx, m2=d2)

        tbmodel = tb.gen_model(amp)

        if os.path.exists(basis_fname):
            basis = read_basis(basis_fname)
        else:
            basis, _ = auto_assign_basis_name(tbmodel.xred, atoms)
        exchange = ExchangePert(
            tbmodels=tbmodel,
            atoms=atoms,
            basis=basis,
            efermi=efermi,
            magnetic_elements=magnetic_elements,
            kmesh=kmesh,
            emin=emin,
            emax=emax,
            height=height,
            nz1=nz1,
            nz2=nz2,
            nz3=nz3,
            exclude_orbs=exclude_orbs,
            Rmesh=Rmesh,
            description=description)
        exchange.set_dHdx(dHdx)
        exchange.run('DJ_amp%.3f'%amp)