def cal_total_DOS(self): """ Calculate the total DOS and return as a DOS instance. """ total_DOS = [ ] for entry in self.DOS: total_DOS.append([entry[0], sum(entry[1:])]) return DOS(total_DOS)
def cal_spin_polarized_DOS(self): """ Calculate the total spin up and spin down DOS separately and return them as a tuple of two DOS instances. """ spin_polarized_DOS = [ ] for entry in self.DOS: spin_polarized_DOS.append([entry[0], sum(entry[1::2]), sum(entry[2::2])]) return DOS(spin_polarized_DOS)
def subtract_DOS(self, other): """ subtract other's DOS from the DOS that must have the same data structure and format. """ assert isinstance(other, self.__class__), "Cannot combine the two DOS files of different formats" if len(self.DOS) != len(other.DOS) or len(self.DOS[0]) != len(other.DOS[0]): print("Cannot combine <--- The two DOS files have different data structures.") subtracted_DOS = [ ] for i, j in zip(self.DOS, other.DOS): subtracted_DOS.append([i[0]] + list([m - n for m, n in zip(i[1:], j[1:])])) return DOS(subtracted_DOS)
def test(): """This is a testing""" import sys from Process_Partial_Dos import DOS from Read_File import read_DOS_file, parse_setting_file dos1 = DOS(read_DOS_file("DOS123")) dos2 = DOS(read_DOS_file("DOS052")) print("total_dos_cal_test ---> write into total_dos_cal_test") dos1.cal_total_DOS().write("total_dos_cal_test") print("spoin_polarized_DOS_cal_test --> write into cal_spin_polarized_dos_test") dos1.cal_spin_polarized_DOS().write("cal_spin_polarized_dos_test") print("dos_combination_test --> write into dos_combination_test") (dos1 + dos2).write("dos_combination_test_test") print("dos_subtraction_test --> write into dos_subtraction_test") (dos1 - dos2).write("dos_subtraction_test") print("fermi_energy_correction_test (suppose Ef=100) --> write into fermi_energy_correction_test") dos1.reset_fermi_energy("100") dos1.write("fermi_energy_correction_test")
def test(): """This is a testing""" dos1 = DOS(read_DOS_file("DOS123")) dos2 = DOS(read_DOS_file("DOS052")) print("total_dos_cal_test ---> write into total_dos_cal_test") dos1.cal_total_DOS().write("total_dos_cal_test") print( "spoin_polarized_DOS_cal_test --> write into cal_spin_polarized_dos_test" ) dos1.cal_spin_polarized_DOS().write("cal_spin_polarized_dos_test") print("dos_combination_test --> write into dos_combination_test") (dos1 + dos2).write("dos_combination_test_test") print("dos_subtraction_test --> write into dos_subtraction_test") (dos1 - dos2).write("dos_subtraction_test") print( "fermi_energy_correction_test (suppose Ef=100) --> write into fermi_energy_correction_test" ) dos1.reset_fermi_energy("100") dos1.write("fermi_energy_correction_test")
(dos1 + dos2).write("dos_combination_test_test") print("dos_subtraction_test --> write into dos_subtraction_test") (dos1 - dos2).write("dos_subtraction_test") print( "fermi_energy_correction_test (suppose Ef=100) --> write into fermi_energy_correction_test" ) dos1.reset_fermi_energy("100") dos1.write("fermi_energy_correction_test") if __name__ == '__main__': # test() for setting in parse_setting_file(sys.argv[1]): dos = DOS(read_DOS_file(setting["dos_filenames"][0])) if "c" in setting["operation"]: for file_name in setting["dos_filenames"][1:]: dos = dos + DOS(read_DOS_file(file_name)) elif setting["operation"] == "sub": for file_name in setting["dos_filenames"][1:]: dos = dos - DOS(read_DOS_file(file_name)) if "t" in setting["sum_dos"]: if setting["ispin"] == '2': dos = dos.cal_spin_polarized_DOS() if setting["ispin"] == '1': dos = dos.cal_total_DOS() dos.reset_fermi_energy(setting["fermi_energy"])