root / ase / lattice / hexagonal.py @ 14
Historique | Voir | Annoter | Télécharger (3,31 ko)
| 1 |
"""Function-like object creating hexagonal lattices.
|
|---|---|
| 2 |
|
| 3 |
The following lattice creators are defined:
|
| 4 |
Hexagonal
|
| 5 |
HexagonalClosedPacked
|
| 6 |
Graphite
|
| 7 |
"""
|
| 8 |
|
| 9 |
from ase.lattice.triclinic import TriclinicFactory |
| 10 |
import numpy as np |
| 11 |
from ase.data import reference_states as _refstate |
| 12 |
|
| 13 |
|
| 14 |
class HexagonalFactory(TriclinicFactory): |
| 15 |
"A factory for creating simple hexagonal lattices."
|
| 16 |
# The name of the crystal structure in ChemicalElements
|
| 17 |
xtal_name = "hexagonal"
|
| 18 |
|
| 19 |
def make_crystal_basis(self): |
| 20 |
"Make the basis matrix for the crystal unit cell and the system unit cell."
|
| 21 |
# First convert the basis specification to a triclinic one
|
| 22 |
if type(self.latticeconstant) == type({}): |
| 23 |
self.latticeconstant['alpha'] = 90 |
| 24 |
self.latticeconstant['beta'] = 90 |
| 25 |
self.latticeconstant['gamma'] = 120 |
| 26 |
self.latticeconstant['b/a'] = 1.0 |
| 27 |
else:
|
| 28 |
if len(self.latticeconstant) == 2: |
| 29 |
a,c = self.latticeconstant
|
| 30 |
self.latticeconstant = (a,a,c,90,90,120) |
| 31 |
else:
|
| 32 |
raise ValueError, "Improper lattice constants for hexagonal crystal." |
| 33 |
TriclinicFactory.make_crystal_basis(self)
|
| 34 |
|
| 35 |
def find_directions(self, directions, miller): |
| 36 |
"""Find missing directions and miller indices from the specified ones.
|
| 37 |
|
| 38 |
Also handles the conversion of hexagonal-style 4-index notation to
|
| 39 |
the normal 3-index notation.
|
| 40 |
"""
|
| 41 |
directions = list(directions)
|
| 42 |
miller = list(miller)
|
| 43 |
for obj in (directions,miller): |
| 44 |
for i in range(3): |
| 45 |
if obj[i] is not None: |
| 46 |
(a,b,c,d) = obj[i] |
| 47 |
if a + b + c != 0: |
| 48 |
raise ValueError( |
| 49 |
("(%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 |
x = 4*a + 2*b |
| 53 |
y = 2*a + 4*b |
| 54 |
z = 3*d
|
| 55 |
obj[i] = (x,y,z) |
| 56 |
TriclinicFactory.find_directions(self, directions, miller)
|
| 57 |
|
| 58 |
def print_directions_and_miller(self, txt=""): |
| 59 |
"Print direction vectors and Miller indices."
|
| 60 |
print "Direction vectors of unit cell%s:" % (txt,) |
| 61 |
for i in (0,1,2): |
| 62 |
self.print_four_vector("[]", self.directions[i]) |
| 63 |
print "Miller indices of surfaces%s:" % (txt,) |
| 64 |
for i in (0,1,2): |
| 65 |
self.print_four_vector("()", self.miller[i]) |
| 66 |
|
| 67 |
def print_four_vector(self, bracket, numbers): |
| 68 |
bra, ket = bracket |
| 69 |
(x,y,z) = numbers |
| 70 |
a = 2*x - y
|
| 71 |
b = -x + 2*y
|
| 72 |
c = -x -y |
| 73 |
d = 2*z
|
| 74 |
print " %s%d, %d, %d%s ~ %s%d, %d, %d, %d%s" % \ |
| 75 |
(bra,x,y,z,ket, bra,a,b,c,d,ket) |
| 76 |
|
| 77 |
|
| 78 |
Hexagonal = HexagonalFactory() |
| 79 |
|
| 80 |
class HexagonalClosedPackedFactory(HexagonalFactory): |
| 81 |
"A factory for creating HCP lattices."
|
| 82 |
xtal_name = "hcp"
|
| 83 |
bravais_basis = [[0,0,0], [1.0/3.0, 2.0/3.0, 0.5]] |
| 84 |
|
| 85 |
HexagonalClosedPacked = HexagonalClosedPackedFactory() |
| 86 |
|
| 87 |
class GraphiteFactory(HexagonalFactory): |
| 88 |
"A factory for creating graphite lattices."
|
| 89 |
xtal_name = "graphite"
|
| 90 |
bravais_basis = [[0,0,0], [1.0/3.0, 2.0/3.0, 0], [1.0/3.0,2.0/3.0,0.5], [2.0/3.0,1.0/3.0,0.5]] |
| 91 |
|
| 92 |
Graphite = GraphiteFactory() |
| 93 |
|