Advertisement
Mark2020H

Python script for calculating Electron Configuration ,Energy for Dirac ,Azimuthal Quantum Number

Aug 28th, 2023
3,712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.13 KB | Science | 0 0
  1. import openpyxl
  2. from openpyxl.styles import Alignment
  3.  
  4. class ElectronConfigurationCalculator:
  5.     def __init__(self):
  6.         self.periodic_table = {
  7.             'H': {'atomic_number': 1, 'atomic_mass': 1.008},
  8.             'He': {'atomic_number': 2, 'atomic_mass': 4.0026},
  9.             'Li': {'atomic_number': 3, 'atomic_mass': 6.94},
  10.             'Be': {'atomic_number': 4, 'atomic_mass': 9.0122},
  11.             # ... continue with the rest of the elements
  12.         }
  13.         self.output_filename = "electron_configurations.xlsx"
  14.  
  15.     def calculate_quantum_numbers(self, n, electron_count):
  16.         # Here, you would perform more complex calculations to determine the quantum numbers
  17.         l = 0  # Placeholder for demonstration purposes
  18.         return n, l, electron_count
  19.  
  20.     def calculate_electron_configuration(self, atomic_number):
  21.         electron_config = f"{atomic_number}s{atomic_number}"
  22.         energy_dirac = -atomic_number * 2
  23.         energy_analytical = -atomic_number * 1.5
  24.         diff = energy_dirac - energy_analytical
  25.  
  26.         return electron_config, energy_dirac, energy_analytical, diff
  27.  
  28.     def write_to_excel(self):
  29.         workbook = openpyxl.Workbook()
  30.         sheet = workbook.active
  31.         sheet.title = "Electron Configurations"
  32.  
  33.         headers = ["Element", "Atomic Number", "Atomic Mass", "Electron Configuration",
  34.                    "Energy for Dirac", "NR (Analytical)", "Diff",
  35.                    "Principal Quantum Number (n)", "Azimuthal Quantum Number (l)",
  36.                    "Magnetic Quantum Number (m_l)", "Spin Quantum Number (s)"]
  37.  
  38.         for col_num, header in enumerate(headers, 1):
  39.             col_letter = openpyxl.utils.get_column_letter(col_num)
  40.             sheet[f"{col_letter}1"] = header
  41.  
  42.         for row_num, (element_symbol, data) in enumerate(self.periodic_table.items(), 2):
  43.             atomic_number = data['atomic_number']
  44.             atomic_mass = data['atomic_mass']
  45.  
  46.             electron_config, energy_dirac, energy_analytical, diff = self.calculate_electron_configuration(atomic_number)
  47.             quantum_numbers = [self.calculate_quantum_numbers(1, 2)]
  48.  
  49.             row_data = [element_symbol, atomic_number, atomic_mass, electron_config,
  50.                         energy_dirac, energy_analytical, diff]
  51.  
  52.             for n, l, electrons in quantum_numbers:
  53.                 azimuthal_str = f"s, p, d, f within an energy level"
  54.                 magnetic_str = ", ".join([str(-l + i) for i in range(2 * l + 1)])
  55.                 spin_str = "±1/2"
  56.  
  57.                 row_data.extend([n, l, azimuthal_str, magnetic_str, spin_str])
  58.  
  59.             for col_num, cell_value in enumerate(row_data, 1):
  60.                 col_letter = openpyxl.utils.get_column_letter(col_num)
  61.                 cell = sheet[f"{col_letter}{row_num}"]
  62.                 cell.value = cell_value
  63.                 cell.alignment = Alignment(horizontal="center")
  64.  
  65.         workbook.save(self.output_filename)
  66.         print(f"Data written to {self.output_filename}")
  67.  
  68.     def main(self):
  69.         self.write_to_excel()
  70.  
  71.  
  72. if __name__ == "__main__":
  73.     calculator = ElectronConfigurationCalculator()
  74.     calculator.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement