from hubbard import HubbardHamiltonian, sp2, ncsile import sisl import numpy as np # Build sisl Geometry object only for a subset of atoms molecule = sisl.get_sile('mol-ref/mol-ref.XV').read_geometry().sub([2,3,5]) molecule.sc.set_nsc([1, 1, 1]) # Build HubbardHamiltonian object Hsp2 = sp2(molecule) H = HubbardHamiltonian(Hsp2, U=3.5) # Generate simple density H.n = np.ones((2, H.sites))*0.5 print(f'1. Write and read densities under group {H.get_hash()} using the HubbardHamiltonian class\n') # Write density in file H.write_density('mol-ref/test.HU.nc', group=H.get_hash(), mode='w') # Read density using the HubbardHamiltonian class H.read_density('mol-ref/test.HU.nc', group=H.get_hash()) # Write another density in file under another group print(f'2. Write another densities under another group\n') H.n *= 2 H.write_density('mol-ref/test.HU.nc', group='group2', mode='a') print('3. Read density, U and kT using ncsile from all groups') fh = sisl.get_sile('mol-ref/test.HU.nc', mode='r') for g in fh.groups: print('group: ', g) print('n:', fh.read_density(group=g))
n_AFM = H.n f = open('FM-AFM.dat', 'w') mixer = sisl.mixing.PulayMixer(0.7, history=7) for u in np.arange(5, 0, -0.25): # We approach the solutions for different U values H.U = u mixer.clear() # AFM case first success = H.read_density( 'clar-goblet.nc') # Try reading, if we already have density on file if not success: H.n = n_AFM.copy() dn = H.converge(density.calc_n_insulator, tol=1e-10, mixer=mixer) eAFM = H.Etot H.write_density('clar-goblet.nc') n_AFM = H.n.copy() if u == 3.5: p = plot.SpinPolarization(H, colorbar=True, vmax=0.4, vmin=-0.4) p.savefig('spin_pol_U%i_AFM.pdf' % (H.U * 1000)) # Now FM case H.q[0] += 1 # change to two more up-electrons than down H.q[1] -= 1 success = H.read_density( 'clar-goblet.nc') # Try reading, if we already have density on file
# Map electrodes in the device region elec_indx = [range(len(H_elec)), range(len(HC.H) - len(H_elec), len(HC.H))] # MFH object of the device MFH_HC = HubbardHamiltonian(HC.H, U=U, kT=kT) # Initial densities success = MFH_HC.read_density('HC_density.nc') if not success: # Get initial spin-densities with PBC to speed up the following convergence with OBC n = MFH_elec.tile(16, axis=0).n a = np.delete(n[0], [67, 68, 69, 72, 73, 74, 77, 78, 79, 82, 83, 84, 87, 88, 89]) b = np.delete(n[1], [67, 68, 69, 72, 73, 74, 77, 78, 79, 82, 83, 84, 87, 88, 89]) n = np.array([a, b]) MFH_HC.n = n # First create NEGF object negf = NEGF(MFH_HC, [(MFH_elec, '-A'), (MFH_elec, '+A')], elec_indx, V=0.1) mixer.clear() dn = MFH_HC.converge(negf.calc_n_open, steps=1, tol=1e-5, mixer=mixer, func_args={'qtol': 1e-4}, print_info=True) print('Nup, Ndn: ', MFH_HC.n.sum(axis=1)) # Write also densities for future calculations MFH_HC.write_density('HC_density.nc') # Plot spin polarization of electrodes