def make_supercell(self, sc_matrix=None, supercell_maker=None):
        if supercell_maker is None:
            smaker = SupercellMaker(sc_matrix)
            n_sc = int(round(np.linalg.det(sc_matrix)))
        else:
            smaker = supercell_maker
            n_sc = smaker.ncell
        sc_nspin = self.nspin * n_sc
        sc_natom = self.natom * n_sc

        T_sc = IFClike(
            genfunc=lambda: Rijv(shape=(sc_natom * 3, sc_natom * 3), sparse=False, dtype=float))

        natom3 = self.natom * 3
        for iRsc, Rsc in enumerate(smaker.R_sc):
            for key_ijR, val_ijR in self.T_ijR.items():
                i, j, Rj = key_ijR
                ip = smaker.sc_i_to_sci(i, iRsc, self.nspin)
                jp, Rjp = smaker.sc_jR_to_scjR(
                    j=j, R=tuple(Rj), Rv=tuple(Rsc), n_basis=self.nspin)

                for R, mat in val_ijR.items():
                    ind_R = np.array(R, dtype=int)
                    #sc_part, pair_ind = smaker._sc_R_to_pair_ind(
                    #    tuple(ind_R + Rsc))
                    #mat[np.abs(mat)<1e-3]=0
                    coomat = coo_matrix(mat)
                    for u, v, val in zip(coomat.row, coomat.col, coomat.data):
                        up = smaker.sc_i_to_sci(u, iRsc, natom3)
                        vp, Rvp = smaker.sc_jR_to_scjR(
                            j=v, R=tuple(R), Rv=tuple(Rsc), n_basis=natom3)
                        T_sc[(ip, jp, Rjp)][tuple(Rvp)][up, vp] += val
        return TijuvTerm(natom=sc_natom, nspin=sc_nspin, parameter=T_sc)
Beispiel #2
0
def lwf_to_atoms(mylwf: LWF, scmat, amplist):
    patoms = mylwf.atoms
    scmaker = SupercellMaker(scmat)
    scatoms = scmaker.sc_atoms(patoms)
    positions = scatoms.get_positions()
    nR, natom3, nlwf = mylwf.wannR.shape
    scnatom = len(scatoms)

    print(mylwf.wannR[mylwf.Rdict[(0, 0, 0)], :, 0].real)

    displacement = np.zeros_like(positions.flatten())
    for (R, iwann, ampwann) in amplist:
        for Rwann, iRwann in mylwf.Rdict.items():
            for j in range(natom3):
                sc_j, sc_R = scmaker.sc_jR_to_scjR(j, Rwann, R, natom3)
                #print(f"{mylwf.wannR[iRwann, iwann, j].real: .2f}")
                amp = ampwann * mylwf.wannR[iRwann, j, iwann]
                #print(f"{amp:.2f}")
                displacement[sc_j] += amp.real
    sc_pos = positions + displacement.reshape((scnatom, 3))
    #print(displacement.reshape((scnatom, 3))[:6])
    scatoms.set_positions(sc_pos)
    return scatoms