Coverage for ase/cluster/cubic.py: 92.86%
28 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
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 SimpleCubicFactory(ClusterFactory):
12 spacegroup = 221
14 xtal_name = 'sc'
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(
21 f'Cannot guess the {self.xtal_name} '
22 + 'lattice constant of an element with crystal '
23 + f'structure {symmetry}.'
24 )
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.'
32 )
34 self.lattice_basis = np.array(
35 [[a, 0.0, 0.0], [0.0, a, 0.0], [0.0, 0.0, a]]
36 )
38 self.resiproc_basis = self.get_resiproc_basis(self.lattice_basis)
41SimpleCubic = SimpleCubicFactory()
44class BodyCenteredCubicFactory(SimpleCubicFactory):
45 spacegroup = 229
47 xtal_name = 'bcc'
49 atomic_basis = np.array([[0.0, 0.0, 0.0], [0.5, 0.5, 0.5]])
52BodyCenteredCubic = BodyCenteredCubicFactory()
55class FaceCenteredCubicFactory(SimpleCubicFactory):
56 """
57 Class to create FCC atom clusters.
59 Examples
60 --------
62 This example sets up a nanoparticle of copper in the FCC crystal structure,
63 by specifying 6 layers in the (100) directions, 9 in the (110) directions
64 and 5 in the (111) directions::
66 >>> from ase.cluster.cubic import FaceCenteredCubic
68 >>> surfaces = [(1, 0, 0), (1, 1, 0), (1, 1, 1)]
69 >>> layers = [6, 9, 5]
70 >>> lc = 3.61000
71 >>> atoms = FaceCenteredCubic('Cu', surfaces, layers, latticeconstant=lc)
72 """
74 spacegroup = 225
76 xtal_name = 'fcc'
78 atomic_basis = np.array(
79 [[0.0, 0.0, 0.0], [0.0, 0.5, 0.5], [0.5, 0.0, 0.5], [0.5, 0.5, 0.0]]
80 )
83FaceCenteredCubic = FaceCenteredCubicFactory()