Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Function-like objects that creates cubic clusters.
3"""
5import numpy as np
6from ase.cluster.factory import ClusterFactory
7from ase.data import reference_states as _refstate
10class HexagonalFactory(ClusterFactory):
11 spacegroup = 191
13 xtal_name = 'hexagonal'
15 def get_lattice_constant(self):
16 "Get the lattice constant of an element with cubic crystal structure."
17 symmetry = _refstate[self.atomic_numbers[0]]['symmetry']
18 if symmetry != self.xtal_name:
19 raise ValueError("Cannot guess the %s " % (self.xtal_name,) +
20 "lattice constant of an element with crystal " +
21 "structure %s." % (symmetry,))
22 return _refstate[self.atomic_numbers[0]].copy()
24 def set_basis(self):
25 lattice = self.lattice_constant
26 if isinstance(lattice, dict):
27 a = lattice['a']
28 try:
29 c = lattice['c']
30 except KeyError:
31 c = a * lattice['c/a']
32 else:
33 if len(lattice) == 2:
34 (a, c) = lattice
35 else:
36 raise ValueError("Improper lattice constants for %s crystal." % (self.xtal_name,))
38 self.lattice_constant = (a, c)
39 self.lattice_basis = np.array([[a, 0., 0.],
40 [-a/2., a*np.sqrt(3.)/2., 0.],
41 [0., 0., c]])
42 self.resiproc_basis = self.get_resiproc_basis(self.lattice_basis)
44 def set_surfaces_layers(self, surfaces, layers):
45 for i, s in enumerate(surfaces):
46 if len(s) == 4:
47 (a, b, c, d) = s
48 if a + b + c != 0:
49 raise ValueError(("(%d,%d,%d,%d) is not a valid hexagonal Miller " +
50 "index, as the sum of the first three numbers " +
51 "should be zero.") % (a, b, c, d))
52 surfaces[i] = [a, b, d]
54 ClusterFactory.set_surfaces_layers(self, surfaces, layers)
57Hexagonal = HexagonalFactory()
60class HexagonalClosedPackedFactory(HexagonalFactory):
61 """A factory for creating HCP clusters."""
62 spacegroup = 194
64 xtal_name = 'hcp'
66 atomic_basis = np.array([[0., 0., 0.],
67 [1./3., 2./3., .5]])
70HexagonalClosedPacked = HexagonalClosedPackedFactory()
73class GraphiteFactory(HexagonalFactory):
74 """A factory for creating graphite clusters."""
75 xtal_name = "graphite"
77 atomic_basis = np.array([[0., 0., 0.],
78 [1./3., 2./3., 0.],
79 [1./3., 2./3., .5],
80 [2./3., 1./3., .5]])
83Graphite = GraphiteFactory()