@@ -44,7 +44,7 @@ def test___init__(self):
4444 self .assertRaises (ValueError , Lattice , 1 , 2 , 3 )
4545 self .assertRaises (ValueError , Lattice , 1 , 2 , 3 , 80 , 90 )
4646 L0 = self .lattice
47- L0 .setLatBase (L0 .cartesian ([[1 , 1 , 0 ], [0 , 1 , 1 ], [1 , 0 , 1 ]]))
47+ L0 .set_new_latt_base_vec (L0 .cartesian ([[1 , 1 , 0 ], [0 , 1 , 1 ], [1 , 0 , 1 ]]))
4848 L1 = Lattice (L0 )
4949 self .assertTrue (numpy .array_equal (L0 .base , L1 .base ))
5050 L2 = Lattice (base = L0 .base )
@@ -77,6 +77,28 @@ def cosd(x):
7777 self .assertAlmostEqual (cosd (120.0 ), dot (base [0 ], base [1 ]) / (1 * 2 ), self .places )
7878 return
7979
80+ def test_set_lat_par (self ):
81+ """Check calculation of standard unit cell vectors."""
82+ from math import cos , radians , sqrt
83+
84+ from numpy import dot
85+
86+ def norm (x ):
87+ return sqrt (sum ([xi ** 2 for xi in x ]))
88+
89+ def cosd (x ):
90+ return cos (radians (x ))
91+
92+ self .lattice .set_latt_parms (1.0 , 2.0 , 3.0 , 80 , 100 , 120 )
93+ base = self .lattice .base
94+ self .assertAlmostEqual (1.0 , norm (base [0 ]), self .places )
95+ self .assertAlmostEqual (2.0 , norm (base [1 ]), self .places )
96+ self .assertAlmostEqual (3.0 , norm (base [2 ]), self .places )
97+ self .assertAlmostEqual (cosd (80.0 ), dot (base [1 ], base [2 ]) / (2 * 3 ), self .places )
98+ self .assertAlmostEqual (cosd (100.0 ), dot (base [0 ], base [2 ]) / (1 * 3 ), self .places )
99+ self .assertAlmostEqual (cosd (120.0 ), dot (base [0 ], base [1 ]) / (1 * 2 ), self .places )
100+ return
101+
80102 def test_latpar_properties (self ):
81103 """Check assignment to a, b, c, alpha, beta, gamma."""
82104 lat = self .lattice
@@ -152,9 +174,9 @@ def test_setLatBase(self):
152174 self .assertAlmostEqual (detR0 , 1.0 , self .places )
153175 # try if rotation matrix works
154176 self .assertEqual (numpy .all (base == self .lattice .base ), True )
155- self .lattice .setLatPar (alpha = 44 , beta = 66 , gamma = 88 )
177+ self .lattice .set_latt_parms (alpha = 44 , beta = 66 , gamma = 88 )
156178 self .assertNotEqual (numpy .all (base == self .lattice .base ), True )
157- self .lattice .setLatPar (alpha = 60 , beta = 60 , gamma = 60 )
179+ self .lattice .set_latt_parms (alpha = 60 , beta = 60 , gamma = 60 )
158180 self .assertTrue (numpy .allclose (base [0 ], self .lattice .base [0 ]))
159181 self .assertTrue (numpy .allclose (base [1 ], self .lattice .base [1 ]))
160182 self .assertTrue (numpy .allclose (base [2 ], self .lattice .base [2 ]))
@@ -171,6 +193,39 @@ def test_setLatBase(self):
171193 )
172194 return
173195
196+ def test_set_lat_base (self ):
197+ """Check calculation of unit cell rotation."""
198+ base = numpy .array ([[1.0 , 1.0 , 0.0 ], [0.0 , 1.0 , 1.0 ], [1.0 , 0.0 , 1.0 ]])
199+ self .lattice .set_new_latt_base_vec (base )
200+ self .assertAlmostEqual (self .lattice .a , numpy .sqrt (2.0 ), self .places )
201+ self .assertAlmostEqual (self .lattice .b , numpy .sqrt (2.0 ), self .places )
202+ self .assertAlmostEqual (self .lattice .c , numpy .sqrt (2.0 ), self .places )
203+ self .assertAlmostEqual (self .lattice .alpha , 60.0 , self .places )
204+ self .assertAlmostEqual (self .lattice .beta , 60.0 , self .places )
205+ self .assertAlmostEqual (self .lattice .gamma , 60.0 , self .places )
206+ detR0 = numalg .det (self .lattice .baserot )
207+ self .assertAlmostEqual (detR0 , 1.0 , self .places )
208+ # try if rotation matrix works
209+ self .assertEqual (numpy .all (base == self .lattice .base ), True )
210+ self .lattice .set_latt_parms (alpha = 44 , beta = 66 , gamma = 88 )
211+ self .assertNotEqual (numpy .all (base == self .lattice .base ), True )
212+ self .lattice .set_latt_parms (alpha = 60 , beta = 60 , gamma = 60 )
213+ self .assertTrue (numpy .allclose (base [0 ], self .lattice .base [0 ]))
214+ self .assertTrue (numpy .allclose (base [1 ], self .lattice .base [1 ]))
215+ self .assertTrue (numpy .allclose (base [2 ], self .lattice .base [2 ]))
216+ # try base checking
217+ self .assertRaises (
218+ LatticeError ,
219+ self .lattice .set_new_latt_base_vec ,
220+ [[1 , 0 , 0 ], [1 , 0 , 0 ], [0 , 0 , 1 ]],
221+ )
222+ self .assertRaises (
223+ LatticeError ,
224+ self .lattice .set_new_latt_base_vec ,
225+ [[1 , 0 , 0 ], [0 , 0 , 1 ], [0 , 1 , 0 ]],
226+ )
227+ return
228+
174229 def test_reciprocal (self ):
175230 """Check calculation of reciprocal lattice."""
176231 r1 = self .lattice .reciprocal ()
@@ -185,7 +240,7 @@ def test_reciprocal(self):
185240 def test_dot (self ):
186241 """Check dot product of lattice vectors."""
187242 L = self .lattice
188- L .setLatPar (gamma = 120 )
243+ L .set_latt_parms (gamma = 120 )
189244 self .assertAlmostEqual (- 0.5 , L .dot ([1 , 0 , 0 ], [0 , 1 , 0 ]), self .places )
190245 va5 = numpy .tile ([1.0 , 0.0 , 0.0 ], (5 , 1 ))
191246 vb5 = numpy .tile ([0.0 , 1.0 , 0.0 ], (5 , 1 ))
@@ -199,14 +254,14 @@ def test_norm(self):
199254 self .assertEqual (1 , self .lattice .norm ([1 , 0 , 0 ]))
200255 u = numpy .array ([[3 , 4 , 0 ], [1 , 1 , 1 ]])
201256 self .assertTrue (numpy .allclose ([5 , 3 ** 0.5 ], self .lattice .norm (u )))
202- self .lattice .setLatPar (gamma = 120 )
257+ self .lattice .set_latt_parms (gamma = 120 )
203258 self .assertAlmostEqual (1 , self .lattice .norm ([1 , 1 , 0 ]), self .places )
204259 return
205260
206261 def test_rnorm (self ):
207262 """Check norm of a reciprocal vector."""
208263 L = self .lattice
209- L .setLatPar (1 , 1.5 , 2.3 , 80 , 95 , 115 )
264+ L .set_latt_parms (1 , 1.5 , 2.3 , 80 , 95 , 115 )
210265 r = L .reciprocal ()
211266 hkl = [0.5 , 0.3 , 0.2 ]
212267 self .assertAlmostEqual (r .norm (hkl ), L .rnorm (hkl ), self .places )
@@ -217,7 +272,7 @@ def test_rnorm(self):
217272 def test_dist (self ):
218273 """Check dist function for distance between lattice points."""
219274 L = self .lattice
220- L .setLatPar (1 , 1.5 , 2.3 , 80 , 95 , 115 )
275+ L .set_latt_parms (1 , 1.5 , 2.3 , 80 , 95 , 115 )
221276 u = [0.1 , 0.3 , 0.7 ]
222277 v = [0.3 , 0.7 , 0.7 ]
223278 d0 = numalg .norm (L .cartesian (numpy .array (u ) - v ))
@@ -235,7 +290,7 @@ def test_angle(self):
235290 from math import acos , degrees
236291
237292 L = self .lattice
238- L .setLatPar (1 , 1.5 , 2.3 , 80 , 95 , 115 )
293+ L .set_latt_parms (1 , 1.5 , 2.3 , 80 , 95 , 115 )
239294 u = [0.1 , 0.3 , 0.7 ]
240295 v = [0.3 , 0.7 , 0.7 ]
241296 uc = L .cartesian (u )
@@ -254,12 +309,12 @@ def test_repr(self):
254309 """Check string representation of this lattice."""
255310 r = repr (self .lattice )
256311 self .assertEqual (r , "Lattice()" )
257- self .lattice .setLatPar (1 , 2 , 3 , 10 , 20 , 30 )
312+ self .lattice .set_latt_parms (1 , 2 , 3 , 10 , 20 , 30 )
258313 r = repr (self .lattice )
259314 r0 = "Lattice(a=1, b=2, c=3, alpha=10, beta=20, gamma=30)"
260315 self .assertEqual (r , r0 )
261316 base = [[1.0 , 1.0 , 0.0 ], [0.0 , 2.0 , 2.0 ], [3.0 , 0.0 , 3.0 ]]
262- self .lattice .setLatBase (base )
317+ self .lattice .set_new_latt_base_vec (base )
263318 r = repr (self .lattice )
264319 self .assertEqual (r , "Lattice(base=%r)" % self .lattice .base )
265320
0 commit comments