def test_writestate_ncl(self): print("TEST WRITE NCL") sys.stdout.flush() from pymatgen.io.vasp.outputs import Chgcar wf = NCLWavefunction.from_directory("noncollinear") fileprefix = "" b, k, s = 10, 1, 0 state1, state2 = wf.write_state_realspace(b, k, s, fileprefix="") state1, state2 = wf.write_state_realspace(b, k, s, fileprefix="", dim=np.array([30, 30, 30])) assert state1.shape[0] == 30 assert state1.shape[1] == 30 assert state1.shape[2] == 30 assert state1.dtype == np.complex128 filename_base = "%sB%dK%dS%d" % (fileprefix, b, k, s) filename1 = "%s_UP_REAL.vasp" % filename_base filename2 = "%s_UP_IMAG.vasp" % filename_base filename3 = "%s_DOWN_REAL.vasp" % filename_base filename4 = "%s_DOWN_IMAG.vasp" % filename_base chg1 = Chgcar.from_file(filename1) chg2 = Chgcar.from_file(filename2) chg3 = Chgcar.from_file(filename3) chg4 = Chgcar.from_file(filename4) upart = chg1.data["total"]**2 + chg2.data["total"]**2 dpart = chg3.data["total"]**2 + chg4.data["total"]**2 vol = chg1.poscar.structure.volume assert_almost_equal(np.sum((upart + dpart) * vol / 30**3), 1, 2) os.remove(filename1) os.remove(filename2) os.remove(filename3) os.remove(filename4)
def initialize_wf_and_mm(self): SIZE = 60 self.wf = Wavefunction.from_directory(".") vol = self.wf.structure.volume self.realspace_wf = self.wf.get_state_realspace(0, 0, 0, dim=(SIZE, SIZE, SIZE), remove_phase=True) # self.realspace_chg = np.abs(self.realspace_wf)**2 self.realspace_chg = self.wf.get_state_realspace_density(0, 0, 0, dim=(SIZE, SIZE, SIZE)) self.recipspace_wf = np.fft.fftn( self.realspace_wf) / SIZE**3 * np.sqrt(vol) self.recipspace_chg = np.fft.fftn(self.realspace_chg) / SIZE**3 * vol self.mm_real = MomentumMatrix(self.wf, encut=3000) self.mm_direct = MomentumMatrix(self.wf) self.mm_direct2 = MomentumMatrix(self.wf, encut=self.wf.encut) self.ncl_wf = NCLWavefunction.from_directory("noncollinear") self.ncl_realspace_wf = self.ncl_wf.get_state_realspace( 0, 0, 0, dim=(SIZE, SIZE, SIZE), remove_phase=True) self.ncl_recipspace_wf = ( np.fft.fftn(self.ncl_realspace_wf[0]) / SIZE**3 * np.sqrt(vol), np.fft.fftn(self.ncl_realspace_wf[1]) / SIZE**3 * np.sqrt(vol), )
def test_density_ncl(self): print("TEST DENSITY NCL") sys.stdout.flush() print("LOAD WAVEFUNCTION") sys.stdout.flush() wf = NCLWavefunction.from_directory('noncollinear') print("FINISHED LOAD WAVEFUNCTION") sys.stdout.flush() #wf = wf.desymmetrized_copy() wf.write_density_realspace(scale = wf.structure.lattice.volume) wf.write_density_realspace(dim=np.array([40,40,40]), scale = wf.structure.lattice.volume) tstchg = Chgcar.from_file("AECCAR2").data['total']# / wf.structure.volume chg = Chgcar.from_file("PYAECCAR").data['total'] reldiff = np.sqrt(np.mean(((chg-tstchg)/tstchg)**2)) newchg = chg-tstchg Chgcar(Poscar(wf.structure), {'total': newchg}).write_file('DIFFCHGCAR.vasp') print(np.sum(chg)/40**3, np.sum(tstchg)/40**3) assert_almost_equal(reldiff, 0, decimal=3)
def test_writestate_ncl(self): print("TEST WRITE NCL") sys.stdout.flush() wf = NCLWavefunction.from_directory('noncollinear') fileprefix = '' b, k, s = 10, 1, 0 state1, state2 = wf.write_state_realspace(b, k, s, fileprefix="", dim=np.array([30, 30, 30])) assert state1.shape[0] == 30 assert state1.shape[1] == 30 assert state1.shape[2] == 30 assert state1.dtype == np.complex128 filename_base = "%sB%dK%dS%d" % (fileprefix, b, k, s) filename1 = "%s_UP_REAL" % filename_base filename2 = "%s_UP_IMAG" % filename_base filename3 = "%s_DOWN_REAL" % filename_base filename4 = "%s_DOWN_IMAG" % filename_base os.remove(filename1) os.remove(filename2) os.remove(filename3) os.remove(filename4)