Coverage for ase/cluster/decahedron.py: 93.75%
32 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1import numpy as np
3from ase import Atoms
4from ase.cluster.util import get_element_info
7def Decahedron(symbol, p, q, r, latticeconstant=None):
8 """
9 Return a decahedral cluster.
11 Parameters
12 ----------
13 symbol: Chemical symbol (or atomic number) of the element.
15 p: Number of atoms on the (100) facets perpendicular to the five
16 fold axis.
18 q: Number of atoms on the (100) facets parallel to the five fold
19 axis. q = 1 corresponds to no visible (100) facets.
21 r: Depth of the Marks re-entrence at the pentagon corners. r = 0
22 corresponds to no re-entrence.
24 latticeconstant (optional): The lattice constant. If not given,
25 then it is extracted form ase.data.
26 """
28 symbol, atomic_number, latticeconstant = get_element_info(
29 symbol, latticeconstant
30 )
32 # Check values of p, q, r
33 if p < 1 or q < 1:
34 raise ValueError('p and q must be greater than 0.')
36 if r < 0:
37 raise ValueError('r must be greater than or equal to 0.')
39 # Defining constants
40 t = 2.0 * np.pi / 5.0
41 b = latticeconstant / np.sqrt(2.0)
42 a = b * np.sqrt(3.0) / 2.0
44 verticies = a * np.array(
45 [
46 [np.cos(np.pi / 2.0), np.sin(np.pi / 2.0), 0.0],
47 [np.cos(t * 1.0 + np.pi / 2.0), np.sin(t * 1.0 + np.pi / 2.0), 0.0],
48 [np.cos(t * 2.0 + np.pi / 2.0), np.sin(t * 2.0 + np.pi / 2.0), 0.0],
49 [np.cos(t * 3.0 + np.pi / 2.0), np.sin(t * 3.0 + np.pi / 2.0), 0.0],
50 [np.cos(t * 4.0 + np.pi / 2.0), np.sin(t * 4.0 + np.pi / 2.0), 0.0],
51 ]
52 )
54 # Number of atoms on the five fold axis and a nice constant
55 h = p + q + 2 * r - 1
56 g = h - q + 1 # p + 2*r
58 positions = []
59 # Make the five fold axis
60 for j in range(h):
61 pos = np.array([0.0, 0.0, j * b - (h - 1) * b / 2.0])
62 positions.append(pos)
64 # Make pentagon rings around the five fold axis
65 for n in range(1, h):
66 # Condition for (100)-planes
67 if n < g:
68 for m in range(5):
69 v1 = verticies[m - 1]
70 v2 = verticies[m]
71 for i in range(n):
72 # Condition for marks re-entrence
73 if n - i < g - r and i < g - r:
74 for j in range(h - n):
75 pos = (n - i) * v1 + i * v2
76 pos += np.array(
77 [0.0, 0.0, j * b - (h - n - 1) * b / 2.0]
78 )
79 positions.append(pos)
81 symbols = [atomic_number] * len(positions)
82 return Atoms(symbols=symbols, positions=positions)