def make_supercell(self, sc_matrix=None, supercell_maker=None, sc_spin_model=None, sc_lattice_model=None): if supercell_maker is not None: smaker = supercell_maker else: smaker = SupercellMaker(sc_matrix) sc_natom = self.natom * smaker.ncell sc_ms = smaker.sc_trans_invariant(self.ms) sc_Sref = np.zeros((len(sc_ms), 3), dtype=float) sc_Sref[:, 2] = np.real(smaker.phase([0.5, 0.5, 0.5])) slc = SpinLatticeCoupling( spin_model=sc_spin_model, lattice_model=sc_lattice_model, ms=sc_ms, natom=sc_natom, Sref=sc_Sref) for key, val in self.terms.items(): slc.add_term(val.make_supercell(supercell_maker=smaker), name=key) print("supercell made") return slc
def setUpClass(self): self.Oiju = OijuTerm.read_netcdf(fname='./Oiju_scalarij.nc') self.ncellx = 4 self.ncell = self.ncellx**3 self.natom = 5 * self.ncell self.nspin = 1 * self.ncell self.scmaker = SupercellMaker(sc_matrix=np.eye(3) * self.ncellx) self.sc_Oiju = self.Oiju.make_supercell(supercell_maker=self.scmaker)
def make_supercell(self, sc_matrix=None, supercell_maker=None): if supercell_maker is None: spm = SupercellMaker(sc_matrix=sc_matrix) else: spm = supercell_maker sc_ref_atoms = spm.sc_atoms(self.ref_atoms) print("maker supercell for ifc") sc_ifc = self.total_ifc.make_supercell(scmaker=spm) return Lattice(ifc=sc_ifc, ref_atoms=sc_ref_atoms)
def make_supercell(self, sc_maker=None, sc_matrix=None): from minimulti.utils.supercell import SupercellMaker if sc_maker is None: sc_maker = SupercellMaker(sc_matrix) if self.atoms is not None: sc_atoms = sc_maker.sc_atoms(self.atoms) #print(self.HwannR.shape) sc_Rlist, sc_HR = sc_maker.sc_Rlist_HR(self.Rlist, self.HwannR, n_basis=self.nwann) return sc_atoms, sc_Rlist, sc_HR
class SLCSupercellTest(unittest.TestCase): @classmethod def setUpClass(self): self.Oiju = OijuTerm.read_netcdf(fname='./Oiju_scalarij.nc') self.ncellx = 4 self.ncell = self.ncellx**3 self.natom = 5 * self.ncell self.nspin = 1 * self.ncell self.scmaker = SupercellMaker(sc_matrix=np.eye(3) * self.ncellx) self.sc_Oiju = self.Oiju.make_supercell(supercell_maker=self.scmaker) def test_supercell_force(self): Sref = np.zeros((self.nspin, 3), dtype=float) Sref[:, 2] = np.real(self.scmaker.phase([0.5, 0.5, 0.5])) S = np.zeros((self.nspin, 3), dtype=float) #S[:,2]=1.0 #S=np.random.random((self.nspin, 3)) S = Sref.copy() #S[5,1]=-1.0 #S[5,2]=0.0 S[1, 2] *= -1 S[2, 2] *= -1 forces = self.sc_Oiju.get_forces(S, Sref) #print("forces:", forces) print("sum of forces", np.sum(forces, axis=0)) #print(sorted(forces.flatten())) def test_supercell_bfield(self): S = np.zeros((self.nspin, 3), dtype=float) displacement = np.zeros((self.natom * 3), dtype=float) displacement[3] = 0.01 bfield = np.zeros((self.nspin, 3), dtype=float) self.sc_Oiju.eff_field(S, displacement, bfield)
def make_supercell(self, supercell_matrix=None, scmaker=None): if scmaker is None: scmaker = SupercellMaker(sc_matrix=supercell_matrix) ret = ijR(nbasis=self.nbasis * scmaker.ncell) if self.positions is None: ret.positions = None else: ret.positions = scmaker.sc_pos(self.positions) ret.sparse = self.sparse ret.double_site_energy = self.double_site_energy for R, mat in self.data.items(): for i in range(self.nbasis): for j in range(self.nbasis): for sc_i, sc_j, sc_R in scmaker.sc_ijR_only( i, j, R, self.nbasis): ret.data[sc_R][sc_i, sc_j] = mat[i, j] return ret
def make_supercell(self, sc_matrix=None, smaker=None): """ make supercell sc_matrix: supercell matrix. """ if self.atoms is not None: natoms = len(self.atoms) else: natoms = set(e.site for e in self) if smaker is None: smaker = SupercellMaker(sc_matrix) if self.atoms is not None: sc_atoms = smaker.sc_atoms(self.atoms) sc_sites = smaker.sc_index(self.get_sites(), n_ind=natoms) sc_labels = smaker.sc_trans_invariant(self.get_labels()) sc_spins = smaker.sc_trans_invariant(self.get_spins()) sc_indices = smaker.sc_index(self.get_indices()) sc_bset = BasisSet() sc_bset.set_atoms(sc_atoms) for site, label, spin, ind in zip(sc_sites, sc_labels, sc_spins, sc_indices): sc_bset.append(Basis(site, label, spin, ind)) sc_bset.set_nspin(self.nspin) return sc_bset
def make_supercell(self, sc_matrix): smaker = SupercellMaker(sc_matrix) sc_spin_model = self._spin_model.make_supercell(supercell_maker=smaker) sc_lattice_model = self._lattice_model.make_supercell( supercell_maker=smaker) sc_slc = self._slc.make_supercell(supercell_maker=smaker, sc_spin_model=sc_spin_model, sc_lattice_model=sc_lattice_model) return SpinLatticeModel(sc_spin_model, sc_lattice_model, sc_slc)
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)
def make_supercell(self, sc_matrix=None, supercell_maker=None): if sc_matrix is None and supercell_maker is None: raise ValueError( "One of sc_matrix or supercell_maker should be inputed.") elif sc_matrix is not None: supercell_maker = SupercellMaker(sc_matrix) sc_nspin = self.nspin * supercell_maker.ncell sc_natom = self.natom * supercell_maker.ncell sc_ilist = supercell_maker.sc_index(self.ilist, self.nspin) sc_jlist, sc_Rjlist = supercell_maker.sc_jR(self.jlist, self.Rjlist, self.nspin) sc_ulist, sc_Rulist = supercell_maker.sc_jR(self.ulist, self.Rulist, self.natom * 3) sc_vallist = supercell_maker.sc_trans_invariant(self.vallist) sc_Oiju = OijuTerm( nspin=sc_nspin, natom=sc_natom, ndata=len(sc_ilist), ilist=sc_ilist, jlist=sc_jlist, ulist=sc_ulist, Rjlist=sc_Rjlist, Rulist=sc_Rulist, vallist=sc_vallist) return sc_Oiju
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
def test_make_supercell(self): scmaker = SupercellMaker(sc_matrix=np.eye(3) * 2) self.sc_Oiju = self.Oiju.make_supercell(supercell_maker=scmaker)
def make_supercell(self, sc_matrix=None, supercell_maker=None, pbc=[1, 1, 1]): if supercell_maker is None: smaker = SupercellMaker(sc_matrix) else: smaker = supercell_maker sc_cell = smaker.sc_cell(np.array(self.cell)) sc_pos = np.array(smaker.sc_pos(np.array(self.pos))) sc_zion = smaker.sc_trans_invariant(np.array(self.zion)) if self.index_spin is not None: sc_index_spin = smaker.sc_trans_invariant(self.index_spin) sc_Rlist = np.repeat(smaker.R_sc, self.nspin, axis=0) sc_iprim = smaker.sc_trans_invariant(list(range(self.nspin))) sc_spinat = np.array(smaker.sc_trans_invariant(self.spinat)) sc_ham = SpinHamiltonian(cell=sc_cell, pos=sc_pos, spinat=sc_spinat, zion=sc_zion, Rlist=sc_Rlist, iprim=sc_iprim) sc_gyro_ratio = np.array(smaker.sc_trans_invariant(self.gyro_ratio)) sc_ham.gyro_ratio = sc_gyro_ratio sc_gilbert_damping = np.array( smaker.sc_trans_invariant(self.gilbert_damping)) sc_ham.gilbert_damping = sc_gilbert_damping if self.has_external_hfield: sc_Hext = smaker.sc_trans_invariant(self.H_ext) sc_ham.set_external_hfield(sc_Hext) if self.has_uniaxial_anistropy: sc_k1 = smaker.sc_trans_invariant(self.k1) sc_k1dir = smaker.sc_trans_invariant(self.k1dir) sc_ham.set_uniaxial_mca(sc_k1, np.array(sc_k1dir)) if self.has_exchange: sc_Jdict = smaker.sc_ijR(self.exchange_Jdict, n_basis=len(self.pos)) sc_ham.set_exchange_ijR(exchange_Jdict=sc_Jdict, pbc=pbc) if self.has_dmi: sc_dmi_ddict = smaker.sc_ijR(self.dmi_ddict, n_basis=len(self.pos)) sc_ham.set_dmi_ijR(sc_dmi_ddict) return sc_ham