-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathlattice.py
More file actions
799 lines (682 loc) · 24.2 KB
/
lattice.py
File metadata and controls
799 lines (682 loc) · 24.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
#!/usr/bin/env python
##############################################################################
#
# diffpy.structure by DANSE Diffraction group
# Simon J. L. Billinge
# (c) 2008 trustees of the Michigan State University.
# All rights reserved.
#
# File coded by: Pavol Juhas
#
# See AUTHORS.txt for a list of people who contributed.
# See LICENSE_DANSE.txt for license information.
#
##############################################################################
"""Class Lattice stores properties and provides simple operations in
lattice coordinate system.
Attributes
----------
cartesian : Lattice
Constant instance of Lattice, default Cartesian system.
"""
import math
import numpy
import numpy.linalg as numalg
from diffpy.structure.structureerrors import LatticeError
from diffpy.utils._deprecator import build_deprecation_message, deprecated
base = "diffpy.structure.Lattice"
removal_version = "4.0.0"
setLatPar_deprecation_msg = build_deprecation_message(
base,
"setLatPar",
"set_latt_parms",
removal_version,
)
setLatBase_deprecation_msg = build_deprecation_message(
base,
"setLatBase",
"set_new_latt_base_vec",
removal_version,
)
abcABG_deprecation_msg = build_deprecation_message(
base,
"abcABG",
"cell_parms",
removal_version,
)
# Helper Functions -----------------------------------------------------------
# exact values of cosd
_EXACT_COSD = {
0.0: +1.0,
60.0: +0.5,
90.0: 0.0,
120.0: -0.5,
180.0: -1.0,
240.0: -0.5,
270.0: 0.0,
300.0: +0.5,
}
def cosd(x):
"""Return the cosine of *x* (measured in degrees).
Avoid round-off errors for exact cosine values.
Parameters
----------
x : float
The angle in degrees.
Returns
-------
float
The cosine of the angle *x*.
"""
rv = _EXACT_COSD.get(x % 360.0)
if rv is None:
rv = math.cos(math.radians(x))
return rv
def sind(x):
"""Return the sine of *x* (measured in degrees).
Avoid round-off errors for exact sine values.
Parameters
----------
x : float
The angle in degrees.
Returns
-------
float
The sine of the angle *x*.
"""
return cosd(90.0 - x)
# ----------------------------------------------------------------------------
class Lattice(object):
"""General coordinate system and associated operations.
Parameters
----------
a : float or Lattice, Optional
The cell length *a*. When present, other cell parameters
must be also specified. When of the *Lattice* type, create
a duplicate Lattice.
b : float
The cell length *b*.
c : float
The cell length *c*.
alpha : float
The angle between the *b* and *c* axes in degrees.
beta : float
The angle between the *b* and *c* axes in degrees.
gamma : float
The angle between the *a* and *b* axes in degrees.
baserot : array_like, Optional
The 3x3 rotation matrix of the base vectors with respect
to their standard setting.
base : array_like, Optional
The 3x3 array of row base vectors. This must be the
only argument when present.
Attributes
----------
metrics : numpy.ndarray
The metrics tensor.
base : numpy.ndarray
The 3x3 matrix of row base vectors in Cartesian coordinates,
which may be rotated, i.e., ``base = stdbase @ baserot``.
stdbase : numpy.ndarray
The 3x3 matrix of row base vectors in standard orientation.
baserot : numpy.ndarray
The rotation matrix for the `base`.
recbase : numpy.ndarray
The inverse of the `base` matrix, where the columns give
reciprocal vectors in Cartesian coordinates.
normbase : numpy.ndarray
The `base` vectors scaled by magnitudes of reciprocal cell lengths.
recnormbase : numpy.ndarray
The inverse of the `normbase` matrix.
isotropicunit : numpy.ndarray
The 3x3 tensor for a unit isotropic displacement parameters in this
coordinate system. This is an identity matrix when this Lattice
is orthonormal.
Note
----
The array attributes are read-only. They get updated by changing
some lattice parameters or by calling the `setLatPar()` or
`setLatBase()` methods.
Examples
--------
Create a Cartesian coordinate system:
>>> Lattice()
Create coordinate system with the cell lengths `a`, `b`, `c`
and cell angles `alpha`, `beta`, `gamma` in degrees:
>>> Lattice(a, b, c, alpha, beta, gamma)
Create a duplicate of an existing Lattice `lat`:
>>> Lattice(lat)
Create coordinate system with the base vectors given by rows
of the `abc` matrix:
>>> Lattice(base=abc)
"""
# round-off tolerance
_epsilon = 1.0e-8
# properties -------------------------------------------------------------
a = property(
lambda self: self._a,
lambda self, value: self.set_latt_parms(a=value),
doc="The unit cell length *a*.",
)
b = property(
lambda self: self._b,
lambda self, value: self.set_latt_parms(b=value),
doc="The unit cell length *b*.",
)
c = property(
lambda self: self._c,
lambda self, value: self.set_latt_parms(c=value),
doc="The unit cell length *c*.",
)
alpha = property(
lambda self: self._alpha,
lambda self, value: self.set_latt_parms(alpha=value),
doc="The cell angle *alpha* in degrees.",
)
beta = property(
lambda self: self._beta,
lambda self, value: self.set_latt_parms(beta=value),
doc="The cell angle *beta* in degrees.",
)
gamma = property(
lambda self: self._gamma,
lambda self, value: self.set_latt_parms(gamma=value),
doc="The cell angle *gamma* in degrees.",
)
# read-only derived properties
@property
def unitvolume(self):
"""The unit cell volume when `a = b = c = 1`."""
# Recalculate lattice cosines to ensure this is right
# even if ca, cb, cg data were not yet updated.
ca = cosd(self.alpha)
cb = cosd(self.beta)
cg = cosd(self.gamma)
rv = math.sqrt(1.0 + 2.0 * ca * cb * cg - ca * ca - cb * cb - cg * cg)
return rv
volume = property(
lambda self: self.a * self.b * self.c * self.unitvolume,
doc="The unit cell volume.",
)
ar = property(
lambda self: self._ar,
doc="The cell length *a* of the reciprocal lattice.",
)
br = property(
lambda self: self._br,
doc="The cell length *b* of the reciprocal lattice.",
)
cr = property(
lambda self: self._cr,
doc="The cell length *c* of the reciprocal lattice.",
)
alphar = property(
lambda self: self._alphar,
doc="The reciprocal cell angle *alpha* in degrees.",
)
betar = property(
lambda self: self._betar,
doc="The reciprocal cell angle *beta* in degrees",
)
gammar = property(
lambda self: self._gammar,
doc="The reciprocal cell angle *gamma* in degrees",
)
ca = property(lambda self: self._ca, doc="The cosine of the cell angle *alpha*.")
cb = property(lambda self: self._cb, doc="The cosine of the cell angle *beta*.")
cg = property(lambda self: self._cg, doc="The cosine of the cell angle *gamma*.")
sa = property(lambda self: self._sa, doc="The sine of the cell angle *alpha*.")
sb = property(lambda self: self._sb, doc="The sine of the cell angle *beta*.")
sg = property(lambda self: self._sg, doc="The sine of the cell angle *gamma*.")
car = property(
lambda self: self._car,
doc="The cosine of the reciprocal angle *alpha*.",
)
cbr = property(
lambda self: self._cbr,
doc="The cosine of the reciprocal angle *beta*.",
)
cgr = property(
lambda self: self._cgr,
doc="The cosine of the reciprocal angle *gamma*.",
)
sar = property(lambda self: self._sar, doc="The sine of the reciprocal angle *alpha*.")
sbr = property(lambda self: self._sbr, doc="The sine of the reciprocal angle *beta*.")
sgr = property(lambda self: self._sgr, doc="The sine of the reciprocal angle *gamma*.")
# done with properties ---------------------------------------------------
def __init__(
self,
a=None,
b=None,
c=None,
alpha=None,
beta=None,
gamma=None,
baserot=None,
base=None,
):
# build a set of provided argument names for later use.
apairs = (
("a", a),
("b", b),
("c", c),
("alpha", alpha),
("beta", beta),
("gamma", gamma),
("baserot", baserot),
("base", base),
)
argset = set(n for n, v in apairs if v is not None)
# initialize data members, they values will be set by setLatPar()
self._a = self._b = self._c = None
self._alpha = self._beta = self._gamma = None
self._ca = self._cb = self._cg = None
self._sa = self._sb = self._sg = None
self._ar = self._br = self._cr = None
self._alphar = self._betar = self._gammar = None
self._car = self._cbr = self._cgr = None
self._sar = self._sbr = self._sgr = None
self.baserot = numpy.identity(3)
self.base = self.recbase = None
self.normbase = self.recnormbase = None
# work out argument variants
# Lattice()
if not argset:
self.set_latt_parms(1.0, 1.0, 1.0, 90.0, 90.0, 90.0, baserot)
# Lattice(base=abc)
elif base is not None:
if len(argset) > 1:
raise ValueError("'base' must be the only argument.")
self.set_new_latt_base_vec(base)
# Lattice(lat)
elif isinstance(a, Lattice):
if len(argset) > 1:
raise ValueError("Lattice object must be the only argument.")
self.__dict__.update(a.__dict__)
# otherwise do default Lattice(a, b, c, alpha, beta, gamma)
else:
abcabg = ("a", "b", "c", "alpha", "beta", "gamma")
if not argset.issuperset(abcabg):
raise ValueError("Provide all 6 cell parameters.")
self.set_latt_parms(a, b, c, alpha, beta, gamma, baserot=baserot)
return
def set_latt_parms(
self,
a=None,
b=None,
c=None,
alpha=None,
beta=None,
gamma=None,
baserot=None,
):
"""Set one or more lattice parameters.
This updates all attributes that depend on the lattice parameters.
Parameters
----------
a : float, Optional
The new value of the cell length *a*.
b : float, Optional
The new value of the cell length *b*.
c : float, Optional
The new value of the cell length *c*.
alpha : float, Optional
The new value of the cell angle *alpha* in degrees.
beta : float, Optional
The new value of the cell angle *beta* in degrees.
gamma : float, Optional
The new value of the cell angle *gamma* in degrees.
baserot : array_like, Optional
The new 3x3 rotation matrix of the base vectors with respect
to their standard setting in Cartesian coordinates.
Note
----
Parameters that are not specified will keep their initial
values.
"""
if a is not None:
self._a = float(a)
if b is not None:
self._b = float(b)
if c is not None:
self._c = float(c)
if alpha is not None:
self._alpha = float(alpha)
if beta is not None:
self._beta = float(beta)
if gamma is not None:
self._gamma = float(gamma)
if baserot is not None:
self.baserot = numpy.array(baserot)
self._ca = ca = cosd(self.alpha)
self._cb = cb = cosd(self.beta)
self._cg = cg = cosd(self.gamma)
self._sa = sa = sind(self.alpha)
self._sb = sb = sind(self.beta)
self._sg = sg = sind(self.gamma)
# cache the unit volume value
Vunit = self.unitvolume
# reciprocal lattice
self._ar = ar = sa / (self.a * Vunit)
self._br = br = sb / (self.b * Vunit)
self._cr = cr = sg / (self.c * Vunit)
self._car = car = (cb * cg - ca) / (sb * sg)
self._cbr = cbr = (ca * cg - cb) / (sa * sg)
self._cgr = cgr = (ca * cb - cg) / (sa * sb)
self._sar = math.sqrt(1.0 - car * car)
self._sbr = math.sqrt(1.0 - cbr * cbr)
self._sgr = sgr = math.sqrt(1.0 - cgr * cgr)
self._alphar = math.degrees(math.acos(car))
self._betar = math.degrees(math.acos(cbr))
self._gammar = math.degrees(math.acos(cgr))
# metrics tensor
self.metrics = numpy.array(
[
[self.a * self.a, self.a * self.b * cg, self.a * self.c * cb],
[self.b * self.a * cg, self.b * self.b, self.b * self.c * ca],
[self.c * self.a * cb, self.c * self.b * ca, self.c * self.c],
],
dtype=float,
)
# standard Cartesian coordinates of lattice vectors
self.stdbase = numpy.array(
[
[1.0 / ar, -cgr / sgr / ar, cb * self.a],
[0.0, self.b * sa, self.b * ca],
[0.0, 0.0, self.c],
],
dtype=float,
)
# Cartesian coordinates of lattice vectors
self.base = numpy.dot(self.stdbase, self.baserot)
self.recbase = numalg.inv(self.base)
# bases normalized to unit reciprocal vectors
self.normbase = self.base * [[ar], [br], [cr]]
self.recnormbase = self.recbase / [ar, br, cr]
self.isotropicunit = _isotropicunit(self.recnormbase)
return
@deprecated(setLatPar_deprecation_msg)
def setLatPar(
self,
a=None,
b=None,
c=None,
alpha=None,
beta=None,
gamma=None,
baserot=None,
):
"""This function has been deprecated and will be removed in
version 4.0.0.
Please use diffpy.structure.Lattice.set_lat_par instead.
"""
return self.set_latt_parms(a, b, c, alpha, beta, gamma, baserot)
@deprecated(setLatBase_deprecation_msg)
def setLatBase(self, base):
"""This function has been deprecated and will be removed in
version 4.0.0.
Please use diffpy.structure.Lattice.set_lat_base instead.
"""
return self.set_new_latt_base_vec(base)
def set_new_latt_base_vec(self, base):
"""Set new base vectors for this lattice.
This updates the cell lengths and cell angles according to the
new base. The `stdbase`, `baserot`, and `metrics` attributes
are also updated.
Parameters
----------
base : array_like
The 3x3 matrix of row base vectors expressed
in Cartesian coordinates.
"""
self.base = numpy.array(base)
detbase = numalg.det(self.base)
if abs(detbase) < 1.0e-8:
emsg = "base vectors are degenerate"
raise LatticeError(emsg)
elif detbase < 0.0:
emsg = "base is not right-handed"
raise LatticeError(emsg)
self._a = a = math.sqrt(numpy.dot(self.base[0, :], self.base[0, :]))
self._b = b = math.sqrt(numpy.dot(self.base[1, :], self.base[1, :]))
self._c = c = math.sqrt(numpy.dot(self.base[2, :], self.base[2, :]))
self._ca = ca = numpy.dot(self.base[1, :], self.base[2, :]) / (b * c)
self._cb = cb = numpy.dot(self.base[0, :], self.base[2, :]) / (a * c)
self._cg = cg = numpy.dot(self.base[0, :], self.base[1, :]) / (a * b)
self._sa = sa = math.sqrt(1.0 - ca**2)
self._sb = sb = math.sqrt(1.0 - cb**2)
self._sg = sg = math.sqrt(1.0 - cg**2)
self._alpha = math.degrees(math.acos(ca))
self._beta = math.degrees(math.acos(cb))
self._gamma = math.degrees(math.acos(cg))
# cache the unit volume value
Vunit = self.unitvolume
# reciprocal lattice
self._ar = ar = sa / (self.a * Vunit)
self._br = br = sb / (self.b * Vunit)
self._cr = cr = sg / (self.c * Vunit)
self._car = car = (cb * cg - ca) / (sb * sg)
self._cbr = cbr = (ca * cg - cb) / (sa * sg)
self._cgr = cgr = (ca * cb - cg) / (sa * sb)
self._sar = math.sqrt(1.0 - car**2)
self._sbr = math.sqrt(1.0 - cbr**2)
self._sgr = sgr = math.sqrt(1.0 - cgr**2)
self._alphar = math.degrees(math.acos(car))
self._betar = math.degrees(math.acos(cbr))
self._gammar = math.degrees(math.acos(cgr))
# standard orientation of lattice vectors
self.stdbase = numpy.array(
[
[1.0 / ar, -cgr / sgr / ar, cb * a],
[0.0, b * sa, b * ca],
[0.0, 0.0, c],
],
dtype=float,
)
# calculate unit cell rotation matrix, base = stdbase @ baserot
self.baserot = numpy.dot(numalg.inv(self.stdbase), self.base)
self.recbase = numalg.inv(self.base)
# bases normalized to unit reciprocal vectors
self.normbase = self.base * [[ar], [br], [cr]]
self.recnormbase = self.recbase / [ar, br, cr]
self.isotropicunit = _isotropicunit(self.recnormbase)
# update metrics tensor
self.metrics = numpy.array(
[
[a * a, a * b * cg, a * c * cb],
[b * a * cg, b * b, b * c * ca],
[c * a * cb, c * b * ca, c * c],
],
dtype=float,
)
return
@deprecated(abcABG_deprecation_msg)
def abcABG(self):
"""'diffpy.structure.Lattice.abcABG' is deprecated and will be
removed in version 4.0.0.
Please use 'diffpy.structure.Lattice.cell_parms' instead.
"""
return self.cell_parms()
def cell_parms(self):
"""Return the cell parameters in the standard setting.
Returns
-------
tuple :
A tuple of ``(a, b, c, alpha, beta, gamma)``.
"""
rv = (self.a, self.b, self.c, self.alpha, self.beta, self.gamma)
return rv
def reciprocal(self):
"""Return the reciprocal lattice of the current lattice.
Returns
-------
Lattice
The reciprocal lattice of the current lattice.
"""
rv = Lattice(base=numpy.transpose(self.recbase))
return rv
def cartesian(self, u):
"""Transform lattice vector to Cartesian coordinates.
Parameters
----------
u : array_like
Vector of lattice coordinates or an Nx3 array
of lattice vectors.
Returns
-------
rc : numpy.ndarray
Cartesian coordinates of the *u* vector.
"""
rc = numpy.dot(u, self.base)
return rc
def fractional(self, rc):
"""Transform Cartesian vector to fractional lattice coordinates.
Parameters
----------
rc : array_like
A vector of Cartesian coordinates or an Nx3 array of
Cartesian vectors.
Returns
-------
u : numpy.ndarray
Fractional coordinates of the Cartesian vector *rc*.
"""
u = numpy.dot(rc, self.recbase)
return u
def dot(self, u, v):
"""Calculate dot product of 2 lattice vectors.
Parameters
----------
u : array_like
The first lattice vector or an Nx3 array.
v : array_like
The second lattice vector or an array of
the same shape as *u*.
Returns
-------
float or numpy.ndarray
The dot product of lattice vectors *u*, *v*.
"""
dp = (u * numpy.dot(v, self.metrics)).sum(axis=-1)
return dp
def norm(self, xyz):
"""Calculate norm of a lattice vector.
Parameters
----------
xyz : array_like
A vector or an Nx3 array of fractional coordinates.
Returns
-------
float or numpy.ndarray
The magnitude of the lattice vector *xyz*.
"""
# this is a few percent faster than sqrt(dot(u, u)).
return numpy.sqrt((self.cartesian(xyz) ** 2).sum(axis=-1))
def rnorm(self, hkl):
"""Calculate norm of a reciprocal vector.
Parameters
----------
hkl : array_like
A vector or an Nx3 array of reciprocal coordinates.
Returns
-------
float or numpy.ndarray
The magnitude of the reciprocal vector *hkl*.
"""
hklcartn = numpy.dot(hkl, self.recbase.T)
return numpy.sqrt((hklcartn**2).sum(axis=-1))
def dist(self, u, v):
"""Calculate distance between 2 points in lattice coordinates.
Parameters
----------
u : array_like
A vector or an Nx3 matrix of fractional coordinates.
v : numpy.ndarray
A vector or an Nx3 matrix of fractional coordinates.
Note
----
*u* and *v* must be of the same shape when matrices.
Returns
-------
float or numpy.ndarray
The distance between lattice points *u* and *v*.
"""
duv = numpy.asarray(u) - v
return self.norm(duv)
def angle(self, u, v):
"""Calculate angle between 2 lattice vectors in degrees.
Parameters
----------
u : array_like
The first lattice vector.
v : array_like
The second lattice vector.
Returns
-------
float
The angle between lattice vectors *u* and *v* in degrees.
"""
ca = self.dot(u, v) / (self.norm(u) * self.norm(v))
# avoid round-off errors that would make abs(ca) greater than 1
if numpy.isscalar(ca):
ca = max(min(ca, 1), -1)
rv = math.degrees(math.acos(ca))
else:
ca[ca < -1] = -1
ca[ca > +1] = +1
rv = numpy.degrees(numpy.arccos(ca))
return rv
def isanisotropic(self, umx):
"""True if displacement parameter matrix is anisotropic.
This checks if the specified matrix of anisotropic displacement
parameters (ADP) differs from isotropic values for this lattice
by more than a small round-off error.
Parameters
----------
umx : array_like
The 3x3 matrix of displacement parameters.
Returns
-------
bool
True when *umx* is anisotropic by more than a round-off error.
"""
umx = numpy.asarray(umx)
utr = numpy.trace(umx) / umx.shape[0]
udmax = numpy.fabs(umx - utr * self.isotropicunit).max()
rv = udmax > self._epsilon
return rv
def __repr__(self):
"""String representation of this lattice."""
I3 = numpy.identity(3, dtype=float)
rotbaseI3diff = max(numpy.reshape(numpy.fabs(self.baserot - I3), 9))
cartlatpar = numpy.array([1.0, 1.0, 1.0, 90.0, 90.0, 90.0])
latpardiff = cartlatpar - self.abcABG()
if rotbaseI3diff > self._epsilon:
s = "Lattice(base=%r)" % self.base
elif numpy.fabs(latpardiff).max() < self._epsilon:
s = "Lattice()"
else:
s = "Lattice(a=%g, b=%g, c=%g, alpha=%g, beta=%g, gamma=%g)" % self.abcABG()
return s
# End of class Lattice
# Local Helpers --------------------------------------------------------------
def _isotropicunit(recnormbase):
"""Calculate tensor of unit isotropic displacement parameters.
Parameters
----------
recnormbase : numpy.ndarray
The inverse of normalized base vectors of some lattice.
Returns
-------
numpy.ndarray
The 3x3 matrix of displacement parameters corresponding to
a unit isotropic displacements.
"""
isounit = numpy.dot(recnormbase.T, recnormbase)
# ensure there are no round-off deviations on the diagonal
isounit[0, 0] = 1
isounit[1, 1] = 1
isounit[2, 2] = 1
return isounit
# Module Constants -----------------------------------------------------------
cartesian = Lattice()