Coverage for /builds/kinetik161/ase/ase/cluster/hexagonal.py: 76.74%
43 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-12-10 11:04 +0000
1"""
2Function-like objects that creates cubic clusters.
3"""
5import numpy as np
7from ase.cluster.factory import ClusterFactory
8from ase.data import reference_states as _refstate
11class HexagonalFactory(ClusterFactory):
12 spacegroup = 191
14 xtal_name = 'hexagonal'
16 def get_lattice_constant(self):
17 "Get the lattice constant of an element with cubic crystal structure."
18 symmetry = _refstate[self.atomic_numbers[0]]['symmetry']
19 if symmetry != self.xtal_name:
20 raise ValueError(f"Cannot guess the {self.xtal_name} " +
21 "lattice constant of an element with crystal " +
22 f"structure {symmetry}.")
23 return _refstate[self.atomic_numbers[0]].copy()
25 def set_basis(self):
26 lattice = self.lattice_constant
27 if isinstance(lattice, dict):
28 a = lattice['a']
29 try:
30 c = lattice['c']
31 except KeyError:
32 c = a * lattice['c/a']
33 else:
34 if len(lattice) == 2:
35 (a, c) = lattice
36 else:
37 raise ValueError(
38 f"Improper lattice constants for {self.xtal_name} crystal.")
40 self.lattice_constant = (a, c)
41 self.lattice_basis = np.array([[a, 0., 0.],
42 [-a / 2., a * np.sqrt(3.) / 2., 0.],
43 [0., 0., c]])
44 self.resiproc_basis = self.get_resiproc_basis(self.lattice_basis)
46 def set_surfaces_layers(self, surfaces, layers):
47 for i, s in enumerate(surfaces):
48 if len(s) == 4:
49 (a, b, c, d) = s
50 if a + b + c != 0:
51 raise ValueError(
52 "(%d,%d,%d,%d) is not a valid hexagonal Miller "
53 "index, as the sum of the first three numbers "
54 "should be zero." % (a, b, c, d))
55 surfaces[i] = [a, b, d]
57 ClusterFactory.set_surfaces_layers(self, surfaces, layers)
60Hexagonal = HexagonalFactory()
63class HexagonalClosedPackedFactory(HexagonalFactory):
64 """A factory for creating HCP clusters."""
65 spacegroup = 194
67 xtal_name = 'hcp'
69 atomic_basis = np.array([[0., 0., 0.],
70 [1. / 3., 2. / 3., .5]])
73HexagonalClosedPacked = HexagonalClosedPackedFactory()
76class GraphiteFactory(HexagonalFactory):
77 """A factory for creating graphite clusters."""
78 xtal_name = "graphite"
80 atomic_basis = np.array([[0., 0., 0.],
81 [1. / 3., 2. / 3., 0.],
82 [1. / 3., 2. / 3., .5],
83 [2. / 3., 1. / 3., .5]])
86Graphite = GraphiteFactory()