Skip to content

Instantly share code, notes, and snippets.

@agagniere
Last active May 29, 2020 15:59
Show Gist options
  • Save agagniere/1e88b3fd14dd3b938bf606880290f1c9 to your computer and use it in GitHub Desktop.
Save agagniere/1e88b3fd14dd3b938bf606880290f1c9 to your computer and use it in GitHub Desktop.
Generate the electronic configuration of neutral atoms
# Possible names of this ordering rule :
# * Madelung rule (after Erwin Madelung)
# * Janet rule (after Charles Janet)
# * Klechkowsky rule (after Vsevolod Klechkovsky)
# * aufbau approximation
# * Uncle Wiggly path or
# * diagonal rule
def aufbau():
i = 0
while True:
subshell = i // 2
shell = i - subshell
while (subshell >= 0):
yield (subshell,shell)
subshell -= 1
shell += 1
i += 1
# Returns the size of the subshell of index i
# It is the sequence 2, 6, 10, 14, ...
subshell_size = lambda i: 4 * i + 2
# Returns the theorical electronic configuration of the neutral atom
# with _atomic_number_ protons in its neucleus
def electronic_configuration(atomic_number):
result = []
electrons = atomic_number
for subshell, shell in aufbau():
current = min(electrons, subshell_size(subshell))
while len(result) <= shell:
result += [list()]
result[shell] += [current]
electrons -= current
if not electrons:
break
return result
for n in range(1, 119):
print("{:3}: {}".format(n, electronic_configuration(n)))
@agagniere
Copy link
Author

Sample output:

  1: [[1]]
  2: [[2]]
  3: [[2], [1]]
  4: [[2], [2]]
  5: [[2], [2, 1]]
  6: [[2], [2, 2]]
  7: [[2], [2, 3]]
  8: [[2], [2, 4]]
  9: [[2], [2, 5]]
 10: [[2], [2, 6]]
 11: [[2], [2, 6], [1]]
 12: [[2], [2, 6], [2]]
 13: [[2], [2, 6], [2, 1]]
 14: [[2], [2, 6], [2, 2]]
 15: [[2], [2, 6], [2, 3]]
 16: [[2], [2, 6], [2, 4]]
 17: [[2], [2, 6], [2, 5]]
 18: [[2], [2, 6], [2, 6]]
 19: [[2], [2, 6], [2, 6], [1]]
 20: [[2], [2, 6], [2, 6], [2]]
 21: [[2], [2, 6], [2, 6, 1], [2]]
 22: [[2], [2, 6], [2, 6, 2], [2]]

@agagniere
Copy link
Author

agagniere commented May 29, 2020

by replacing the break with

offset = (0 if len(result[shell]) == 1 else 34 - 2 * len(result[shell]) ** 2)
return (offset + current, len(result))

one can have the position (starting from (1,1) to (32,7)) of the element on the Mendeliev table

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment