18
18
19
19
import unittest
20
20
import numpy
21
+ import numpy .linalg as numalg
21
22
22
23
from diffpy .Structure import Lattice , LatticeError
23
24
@@ -168,8 +169,6 @@ def test_readonly_properties(self):
168
169
169
170
def test_setLatBase (self ):
170
171
"""check calculation of unit cell rotation"""
171
- import numpy
172
- import numpy .linalg as numalg
173
172
base = numpy .array ([[ 1.0 , 1.0 , 0.0 ],
174
173
[ 0.0 , 1.0 , 1.0 ],
175
174
[ 1.0 , 0.0 , 1.0 ]])
@@ -214,7 +213,7 @@ def test_dot(self):
214
213
'''check dot product of lattice vectors.'''
215
214
L = self .lattice
216
215
L .setLatPar (gamma = 120 )
217
- self .assertAlmostEqual (- 0.5 , L .dot ([1 , 0 , 0 ], [0 , 1 , 0 ]))
216
+ self .assertAlmostEqual (- 0.5 , L .dot ([1 , 0 , 0 ], [0 , 1 , 0 ]), self . places )
218
217
va5 = numpy .tile ([1.0 , 0.0 , 0.0 ], (5 , 1 ))
219
218
vb5 = numpy .tile ([0.0 , 1.0 , 0.0 ], (5 , 1 ))
220
219
self .assertTrue (numpy .array_equal (5 * [- 0.5 ], L .dot (va5 , vb5 )))
@@ -229,7 +228,7 @@ def test_norm(self):
229
228
u = numpy .array ([[3 , 4 , 0 ], [1 , 1 , 1 ]])
230
229
self .assertListAlmostEqual ([5 , 3 ** 0.5 ], self .lattice .norm (u ))
231
230
self .lattice .setLatPar (gamma = 120 )
232
- self .assertAlmostEqual (1 , self .lattice .norm ([1 , 1 , 0 ]))
231
+ self .assertAlmostEqual (1 , self .lattice .norm ([1 , 1 , 0 ]), self . places )
233
232
return
234
233
235
234
@@ -239,12 +238,51 @@ def test_rnorm(self):
239
238
L .setLatPar (1 , 1.5 , 2.3 , 80 , 95 , 115 )
240
239
r = L .reciprocal ()
241
240
hkl = [0.5 , 0.3 , 0.2 ]
242
- self .assertAlmostEqual (r .norm (hkl ), L .rnorm (hkl ))
241
+ self .assertAlmostEqual (r .norm (hkl ), L .rnorm (hkl ), self . places )
243
242
hkl5 = numpy .tile (hkl , (5 , 1 ))
244
243
self .assertListAlmostEqual (5 * [r .norm (hkl )], L .rnorm (hkl5 ))
245
244
return
246
245
247
246
247
+ def test_dist (self ):
248
+ '''check dist function for distance between lattice points.'''
249
+ L = self .lattice
250
+ L .setLatPar (1 , 1.5 , 2.3 , 80 , 95 , 115 )
251
+ u = [0.1 , 0.3 , 0.7 ]
252
+ v = [0.3 , 0.7 , 0.7 ]
253
+ d0 = numalg .norm (L .cartesian (numpy .array (u ) - v ))
254
+ self .assertAlmostEqual (d0 , L .dist (u , v ), self .places )
255
+ self .assertAlmostEqual (d0 , L .dist (v , u ), self .places )
256
+ u5 = numpy .tile (u , (5 , 1 ))
257
+ v5 = numpy .tile (v , (5 , 1 ))
258
+ self .assertListAlmostEqual (5 * [d0 ], L .dist (u , v5 ))
259
+ self .assertListAlmostEqual (5 * [d0 ], L .dist (u5 , v ))
260
+ self .assertListAlmostEqual (5 * [d0 ], L .dist (v5 , u5 ))
261
+ return
262
+
263
+
264
+ def test_angle (self ):
265
+ '''check angle calculation between lattice vectors.'''
266
+ from math import degrees , acos
267
+ L = self .lattice
268
+ L .setLatPar (1 , 1.5 , 2.3 , 80 , 95 , 115 )
269
+ u = [0.1 , 0.3 , 0.7 ]
270
+ v = [0.3 , 0.7 , 0.7 ]
271
+ uc = L .cartesian (u )
272
+ vc = L .cartesian (v )
273
+ a0 = degrees (acos (numpy .dot (uc , vc ) /
274
+ (numalg .norm (uc ) * numalg .norm (vc ))))
275
+ self .assertAlmostEqual (a0 , L .angle (u , v ), self .places )
276
+ self .assertAlmostEqual (a0 , L .angle (v , u ), self .places )
277
+ u5 = numpy .tile (u , (5 , 1 ))
278
+ v5 = numpy .tile (v , (5 , 1 ))
279
+ self .assertListAlmostEqual (5 * [a0 ], L .angle (u , v5 ))
280
+ self .assertListAlmostEqual (5 * [a0 ], L .angle (u5 , v ))
281
+ self .assertListAlmostEqual (5 * [a0 ], L .angle (v5 , u5 ))
282
+ return
283
+
284
+
285
+
248
286
def test_repr (self ):
249
287
"""check string representation of this lattice"""
250
288
r = repr (self .lattice )
0 commit comments