Coverage for /builds/ase/ase/ase/cluster/cubic.py: 92.86%
28 statements
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2025-08-02 00:12 +0000
1# fmt: off
3"""
4Function-like objects that creates cubic clusters.
5"""
7import numpy as np
9from ase.cluster.factory import ClusterFactory
10from ase.data import reference_states as _refstate
13class SimpleCubicFactory(ClusterFactory):
14 spacegroup = 221
16 xtal_name = 'sc'
18 def get_lattice_constant(self):
19 "Get the lattice constant of an element with cubic crystal structure."
20 symmetry = _refstate[self.atomic_numbers[0]]['symmetry']
21 if symmetry != self.xtal_name:
22 raise ValueError(f"Cannot guess the {self.xtal_name} " +
23 "lattice constant of an element with crystal " +
24 f"structure {symmetry}.")
25 return _refstate[self.atomic_numbers[0]]['a']
27 def set_basis(self):
28 a = self.lattice_constant
29 if not isinstance(a, (int, float)):
30 raise ValueError(
31 f"Improper lattice constant for {self.xtal_name} crystal.")
33 self.lattice_basis = np.array([[a, 0., 0.],
34 [0., a, 0.],
35 [0., 0., a]])
37 self.resiproc_basis = self.get_resiproc_basis(self.lattice_basis)
40SimpleCubic = SimpleCubicFactory()
43class BodyCenteredCubicFactory(SimpleCubicFactory):
44 spacegroup = 229
46 xtal_name = 'bcc'
48 atomic_basis = np.array([[0., 0., 0.],
49 [.5, .5, .5]])
52BodyCenteredCubic = BodyCenteredCubicFactory()
55class FaceCenteredCubicFactory(SimpleCubicFactory):
56 spacegroup = 225
58 xtal_name = 'fcc'
60 atomic_basis = np.array([[0., 0., 0.],
61 [0., .5, .5],
62 [.5, 0., .5],
63 [.5, .5, 0.]])
66FaceCenteredCubic = FaceCenteredCubicFactory()