Coverage for /builds/ase/ase/ase/cluster/hexagonal.py : 76.74%

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(
37 "Improper lattice constants for %s crystal." %
38 (self.xtal_name,))
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()