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()
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)
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)
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