Coverage for ase / utils / ptable.py: 100.00%
24 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-04 10:20 +0000
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-04 10:20 +0000
1import numpy as np
3from ase import Atoms
6def ptable(spacing=2.5):
7 """Generates the periodic table as an Atoms oobject to help with visualizing
8 rendering and color palette settings."""
9 # generates column, row positions for each element
10 zmax = 118
11 z_values = np.arange(1, zmax + 1) # z is atomic number not, position
12 positions = np.zeros((len(z_values), 3))
13 x, y = 1, 1 # column, row , initial coordinates for Hydrogen
14 for z in z_values:
15 if z == 2: # right align He
16 x += 16
17 if z == 5 or z == 13: # right align B and Al
18 x += 10
19 if z == 57 or z == 89: # down shift lanthanides and actinides
20 y += 3
21 if z == 72 or z == 104: # up/left shift last two transistion metal rows
22 y -= 3
23 x -= 14
24 positions[z - 1] = (x, -y, 0)
25 x += 1
26 if x > 18:
27 x = 1
28 y += 1
29 atoms = Atoms(z_values, positions * spacing)
30 return atoms