Skip to content

Commit 47e7598

Browse files
committed
Merge branch 'fix-sg-posvars'
* fix null-space normalization w/r to round-offs * fix signedRatStr for near-integer numbers * fix position formula for Wyckoff site e in SG 209 F432 Resolve #43.
2 parents f4ff1a0 + b230208 commit 47e7598

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

src/diffpy/structure/symmetryutilities.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ def signedRatStr(self, x):
362362
363363
Return string.
364364
"""
365-
s = str(x)
365+
s = "{:.8g}".format(x)
366366
if len(s) < 6: return "%+g" % x
367367
den = numpy.array([3.0, 6.0, 7.0, 9.0])
368368
nom = x * den
@@ -387,11 +387,19 @@ def _findNullSpace(self):
387387
self.null_space = self.null_space[order[::-1]]
388388
# rationalize by the smallest element larger than cutoff
389389
cutoff = 1.0/32
390-
for i in range(len(self.null_space)):
391-
row = self.null_space[i]
392-
small = numpy.fabs(row[numpy.fabs(row) > cutoff]).min()
393-
signedsmall = row[numpy.fabs(row) == small][0]
394-
self.null_space[i] = self.null_space[i] / signedsmall
390+
for row in self.null_space:
391+
abrow = numpy.abs(row)
392+
sgrow = numpy.sign(row)
393+
# equalize items with round-off-equal absolute value
394+
ii = abrow.argsort()
395+
delta = 1e-8 * abrow[ii[-1]]
396+
for k in ii[1:]:
397+
if abrow[k] - abrow[k - 1] < delta:
398+
abrow[k] = abrow[k - 1]
399+
# find the smallest nonzero absolute element
400+
jnz = numpy.flatnonzero(abrow > cutoff)
401+
idx = jnz[abrow[jnz].argmin()]
402+
row[:] = (sgrow * abrow) / sgrow[idx] / abrow[idx]
395403
return
396404

397405

src/diffpy/structure/tests/testsymmetryutilities.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ def test___init__(self):
210210
self.assertEqual(16, self.g227oc.multiplicity)
211211
return
212212

213+
214+
def test_signedRatStr(self):
215+
"check GeneratorSite.signedRatStr()"
216+
g = self.g117c
217+
self.assertEqual('-1', g.signedRatStr(-1.00000000000002))
218+
self.assertEqual('+1', g.signedRatStr(1.00000000000002))
219+
return
220+
221+
213222
def test_positionFormula(self):
214223
"""check GeneratorSite.positionFormula()
215224
"""
@@ -236,6 +245,20 @@ def test_positionFormula(self):
236245
self.assertEqual([], self.g227oc.pparameters)
237246
return
238247

248+
249+
def test_positionFormula_sg209(self):
250+
"""check positionFormula at [x, 1-x, -x] site or F432 space group.
251+
"""
252+
sg209 = GetSpaceGroup('F 4 3 2')
253+
xyz = [0.05198, 0.94802, -0.05198]
254+
g209e = GeneratorSite(sg209, xyz)
255+
pfm = g209e.positionFormula(xyz)
256+
self.assertEqual('x', pfm['x'])
257+
self.assertEqual('-x+1', pfm['y'].replace(' ', ''))
258+
self.assertEqual('-x+1', pfm['z'].replace(' ', ''))
259+
return
260+
261+
239262
def test_UFormula(self):
240263
"""check GeneratorSite.UFormula()
241264
"""

0 commit comments

Comments
 (0)