Skip to content

Commit c92830d

Browse files
committed
Fix isotropicunit initialization.
Assign isotropicunit when Lattice is initialized from base vectors.
1 parent 68d2798 commit c92830d

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

diffpy/Structure/lattice.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,7 @@ def setLatPar(self, a=None, b=None, c=None,
202202
# bases normalized to unit reciprocal vectors
203203
self.normbase = self.base * [[ar], [br], [cr]]
204204
self.recnormbase = self.recbase / [ar, br, cr]
205-
self.isotropicunit = numpy.dot(self.recnormbase.T, self.recnormbase)
206-
# ensure there are no round-off deviations on the diagonal
207-
self.isotropicunit[0, 0] = 1
208-
self.isotropicunit[1, 1] = 1
209-
self.isotropicunit[2, 2] = 1
205+
self.isotropicunit = _isotropicunit(self.recnormbase)
210206
return
211207

212208

@@ -263,6 +259,7 @@ def setLatBase(self, base):
263259
# bases normalized to unit reciprocal vectors
264260
self.normbase = self.base * [[ar], [br], [cr]]
265261
self.recnormbase = self.recbase / [ar, br, cr]
262+
self.isotropicunit = _isotropicunit(self.recnormbase)
266263
# update metrics tensor
267264
self.metrics = numpy.array([
268265
[ a*a, a*b*cg, a*c*cb ],
@@ -482,6 +479,22 @@ def unitvolume(self):
482479

483480
# End of class Lattice
484481

482+
# Local Helper Functions -----------------------------------------------------
483+
484+
def _isotropicunit(recnormbase):
485+
"""Calculate matrix for unit isotropic displacement parameters.
486+
487+
recnormbase -- inverse of normalized base vectors of the lattice.
488+
489+
Return numpy array.
490+
"""
491+
isounit = numpy.dot(recnormbase.T, recnormbase)
492+
# ensure there are no round-off deviations on the diagonal
493+
isounit[0, 0] = 1
494+
isounit[1, 1] = 1
495+
isounit[2, 2] = 1
496+
return isounit
497+
485498
# Module Constants -----------------------------------------------------------
486499

487500
cartesian = Lattice()

diffpy/Structure/tests/TestLattice.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ def test___init__(self):
5757
self.assertTrue(numpy.array_equal(L0.base, L1.base))
5858
L2 = Lattice(base=L0.base)
5959
self.assertTrue(numpy.array_equal(L0.base, L2.base))
60+
self.assertTrue(numpy.array_equal(L0.isotropicunit, L2.isotropicunit))
6061
L3 = Lattice(*L0.abcABG(), baserot=L0.baserot)
6162
self.assertTrue(numpy.allclose(L0.base, L3.base))
63+
self.assertTrue(numpy.array_equal(L0.isotropicunit, L3.isotropicunit))
6264
return
6365

6466

0 commit comments

Comments
 (0)