root / ase / lattice / triclinic.py @ 1
Historique | Voir | Annoter | Télécharger (3,15 ko)
1 |
"""Function-like object creating triclinic lattices.
|
---|---|
2 |
|
3 |
The following lattice creator is defined:
|
4 |
Triclinic
|
5 |
"""
|
6 |
|
7 |
from ase.lattice.bravais import Bravais |
8 |
import numpy as np |
9 |
from ase.data import reference_states as _refstate |
10 |
|
11 |
class TriclinicFactory(Bravais): |
12 |
"A factory for creating triclinic lattices."
|
13 |
|
14 |
# The name of the crystal structure in ChemicalElements
|
15 |
xtal_name = "triclinic"
|
16 |
|
17 |
# The natural basis vectors of the crystal structure
|
18 |
int_basis = np.array([[1, 0, 0], |
19 |
[0, 1, 0], |
20 |
[0, 0, 1]]) |
21 |
basis_factor = 1.0
|
22 |
|
23 |
# Converts the natural basis back to the crystallographic basis
|
24 |
inverse_basis = np.array([[1, 0, 0], |
25 |
[0, 1, 0], |
26 |
[0, 0, 1]]) |
27 |
inverse_basis_factor = 1.0
|
28 |
|
29 |
def get_lattice_constant(self): |
30 |
"Get the lattice constant of an element with triclinic crystal structure."
|
31 |
if _refstate[self.atomicnumber]['symmetry'].lower() != self.xtal_name: |
32 |
raise ValueError, (("Cannot guess the %s lattice constant of" |
33 |
+ " an element with crystal structure %s.")
|
34 |
% (self.xtal_name,
|
35 |
_refstate[self.atomicnumber]['symmetry'])) |
36 |
return _refstate[self.atomicnumber].copy() |
37 |
|
38 |
|
39 |
def make_crystal_basis(self): |
40 |
"Make the basis matrix for the crystal unit cell and the system unit cell."
|
41 |
lattice = self.latticeconstant
|
42 |
if type(lattice) == type({}): |
43 |
a = lattice['a']
|
44 |
try:
|
45 |
b = lattice['b']
|
46 |
except KeyError: |
47 |
b = a * lattice['b/a']
|
48 |
try:
|
49 |
c = lattice['c']
|
50 |
except KeyError: |
51 |
c = a * lattice['c/a']
|
52 |
alpha = lattice['alpha']
|
53 |
beta = lattice['beta']
|
54 |
gamma = lattice['gamma']
|
55 |
else:
|
56 |
if len(lattice) == 6: |
57 |
(a,b,c,alpha,beta,gamma) = lattice |
58 |
else:
|
59 |
raise ValueError, "Improper lattice constants for triclinic crystal." |
60 |
|
61 |
degree = np.pi / 180.0
|
62 |
cosa = np.cos(alpha*degree) |
63 |
cosb = np.cos(beta*degree) |
64 |
sinb = np.sin(beta*degree) |
65 |
cosg = np.cos(gamma*degree) |
66 |
sing = np.sin(gamma*degree) |
67 |
lattice = np.array([[a,0,0], |
68 |
[b*cosg, b*sing,0],
|
69 |
[c*cosb, c*(cosa-cosb*cosg)/sing, |
70 |
c*np.sqrt(sinb**2 - ((cosa-cosb*cosg)/sing)**2)]]) |
71 |
self.latticeconstant = lattice
|
72 |
self.miller_basis = lattice
|
73 |
self.crystal_basis = (self.basis_factor * |
74 |
np.dot(self.int_basis, lattice))
|
75 |
self.basis = np.dot(self.directions, self.crystal_basis) |
76 |
assert abs(np.dot(lattice[0],lattice[1]) - a*b*cosg) < 1e-5 |
77 |
assert abs(np.dot(lattice[0],lattice[2]) - a*c*cosb) < 1e-5 |
78 |
assert abs(np.dot(lattice[1],lattice[2]) - b*c*cosa) < 1e-5 |
79 |
assert abs(np.dot(lattice[0],lattice[0]) - a*a) < 1e-5 |
80 |
assert abs(np.dot(lattice[1],lattice[1]) - b*b) < 1e-5 |
81 |
assert abs(np.dot(lattice[2],lattice[2]) - c*c) < 1e-5 |
82 |
|
83 |
Triclinic = TriclinicFactory() |