def __init__(self, fname=None, sc_matrix=None, ham=None):
        self.params = SpinParams()
        if ham is not None:
            self._ham=ham
        elif fname is not None:
            self.read_from_file(fname)
        else:
            self._ham = SpinHamiltonian()

        if sc_matrix is not None:
            self.make_supercell(sc_matrix)

        self.mover = SpinMover(self._ham)
예제 #2
0
def plot_M_vs_T(ham, supercell_matrix=np.eye(3), Tlist=np.arange(0.0, 110,
                                                                 20)):
    Mlist = []
    for temperature in Tlist:
        sc_ham = ham.make_supercell(supercell_matrix)
        mover = SpinMover(hamiltonian=sc_ham)
        mover.set(
            time_step=2e-4,
            #damping_factor=0.1,
            temperature=temperature,
            total_time=1,
            save_all_spin=True)

        mover.run(write_step=10)

        hist = mover.get_hist()
        hspin = np.array(hist['spin'])
        time = np.array(hist['time'])
        tspin = np.array(hist['total_spin'])

        Ms = np.linalg.det(supercell_matrix)
        avg_total_m = np.average((np.linalg.norm(tspin, axis=1) / Ms)[300:])
        print("T: %s   M: %s" % (temperature, avg_total_m))
        Mlist.append(avg_total_m)

    plt.plot(Tlist, Mlist)
    plt.ylim(-0.01, 1.01)
    plt.xlabel('Temperature (K)')
    plt.ylabel('Average magnetization (Ms)')
    plt.show()
예제 #3
0
def plot_M_vs_time(ham, supercell_matrix=np.eye(3), temperature=0):
    sc_ham = ham.make_supercell(supercell_matrix)
    mover = SpinMover(hamiltonian=sc_ham)
    mover.set(
        time_step=1e-5,
        temperature=temperature,
        total_time=1,
        save_all_spin=True)

    mover.run(write_step=10)

    hist = mover.get_hist()
    hspin = np.array(hist['spin'])
    time = np.array(hist['time'])
    tspin = np.array(hist['total_spin'])

    Ms = np.linalg.det(supercell_matrix)
    plt.figure()
    plt.plot(
        time, np.linalg.norm(tspin, axis=1) / Ms, label='total', color='black')
    plt.plot(time, tspin[:, 0] / Ms, label='x')
    plt.plot(time, tspin[:, 1] / Ms, label='y')
    plt.plot(time, tspin[:, 2] / Ms, label='z')
    plt.xlabel('time (s)')
    plt.ylabel('magnetic moment ($\mu_B$)')
    plt.legend()
    #plt.show()
    #avg_total_m = np.average((np.linalg.norm(tspin, axis=1)/Ms)[:])
    plt.show()
 def test_cubic(self):
     ham = cubic_3d_hamiltonian(Jx=3e-21, Jy=3e-21, Jz=3e-21)
     sc_ham = ham.make_supercell(np.eye(3) * self.N)
     mover = SpinMover(hamiltonian=sc_ham,
                       hist_fname='Spinhist.nc',
                       write_hist=True)
     mover.set(time_step=0.005,
               temperature=200.0,
               total_time=1,
               save_all_spin=False)
     mover.run(write_step=10)
예제 #5
0
def plot_supercell(ham,
                   supercell_matrix=np.diag([30, 1, 1]),
                   plot_type='2d',
                   length=0.1,
                   ylimit=None):
    sc_ham = ham.make_supercell(supercell_matrix)
    sc_ham.s = np.random.rand(*sc_ham.s.shape) - 0.5
    mover = SpinMover(hamiltonian=sc_ham)
    mover.set(time_step=3e-4, temperature=0, total_time=6, save_all_spin=False)

    mover.run(write_step=20)
    pos = np.dot(sc_ham.pos, sc_ham.cell)
    if plot_type == '2d':
        plot_2d_vector(
            pos, mover.s, show_z=False, length=length, ylimit=ylimit)
    elif plot_type == '3d':
        plot_3d_vector(pos, mover.s, length=length)
 def make_supercell(self, sc_matrix=None, supercell_maker=None):
     self._ham = self._ham.make_supercell(
         sc_matrix=sc_matrix, supercell_maker=supercell_maker)
     self.mover = SpinMover(self._ham)
     return self
class SpinModel():
    def __init__(self, fname=None, sc_matrix=None, ham=None):
        self.params = SpinParams()
        if ham is not None:
            self._ham=ham
        elif fname is not None:
            self.read_from_file(fname)
        else:
            self._ham = SpinHamiltonian()

        if sc_matrix is not None:
            self.make_supercell(sc_matrix)

        self.mover = SpinMover(self._ham)

    @property
    def ham(self):
        return self._ham

    def add_term(self, term, name=None):
        self._ham.add_Hamiltonian_term(term, name=name)

    @ham.setter
    def ham(self, ham):
        self._ham = ham

    @property
    def S(self):
        return self.mover.s

    @property
    def nspin(self):
        return self._ham.nspin

    def read_from_file(self, fname):
        self._ham = read_spin_ham_from_file(fname)

    def set(self, **kwargs):
        self.params.set(**kwargs)
        self.mover.set(
            time_step=self.params.time_step,
            temperature=self.params.temperature,
            total_time=self.params.total_time,
        )

    def make_supercell(self, sc_matrix=None, supercell_maker=None):
        self._ham = self._ham.make_supercell(
            sc_matrix=sc_matrix, supercell_maker=supercell_maker)
        self.mover = SpinMover(self._ham)
        return self

    def run_one_step(self):
        self.mover.run_one_step()

    def run_time(self):
        self.mover.run()

    def plot_magnon_band(
            self,
            kvectors=np.array([[0, 0, 0], [0.5, 0, 0], [0.5, 0.5, 0],
                               [0, 0, 0], [.5, .5, .5]]),
            knames=['$\Gamma$', 'X', 'M', '$\Gamma$', 'R'],
            supercell_matrix=None,
            npoints=100,
            color='red',
            ax=None,
            kpath_fname=None,
    ):
        self._ham.plot_magnon_band(
            kvectors=kvectors,
            knames=knames,
            supercell_matrix=supercell_matrix,
            npoints=npoints,
            color=color,
            ax=ax,
            kpath_fname=kpath_fname)