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