Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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)