Skip to content

Commit

Permalink
Fixed some error and add 1 unit test. Refs #7847.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdzhou committed Sep 10, 2013
1 parent 4bc6fec commit 3745fc2
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,15 +182,28 @@ def createPeakParameterWorkspace(self, irffilename):
def generateBraggReflections(self, hklmax):
""" Generate Bragg reflections from (0, 0, 0) to (HKL)_max
"""
import math

# Generate reflections
max_hkl_sq = hklmax[0]**2 + hklmax[1]**2 + hklmax[2]**2
max_m = int(math.sqrt(max_hkl_sq)) + 1

# Note: the maximum HKL is defined by (HKL)^2. Therefore, the iteration should reach some larger integer
# to avoid skipping some valid reflections

hkldict = {}
for h in xrange(0, hklmax[0]):
for k in xrange(h, hklmax[1]):
for l in xrange(k, hklmax[2]):
for h in xrange(0, max_m):
for k in xrange(h, max_m):
for l in xrange(k, max_m):
dsq = h*h + k*k + l*l
if hkldict.has_key(dsq) is False:
hkldict[dsq] = []
hkldict[dsq].append([h, k, l])
if dsq <= max_hkl_sq:
if hkldict.has_key(dsq) is False:
hkldict[dsq] = []
hkldict[dsq].append([h, k, l])
# ENDIF
# ENDFOR (l)
# ENDFOR (k)
# ENDFOR (h)

# Create table workspace
tablews = WorkspaceFactory.createTable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,55 @@ def test_LoadHKLFile(self):

return

def test_genHKLList(self):
""" Test to load a .hkl file
"""
# Set up
alg_test = run_algorithm("CreateLeBailFitInput",
Instrument = "POWGEN",
ReflectionsFile = "",
MaxHKL = "12,12,12",
FullprofParameterFile = "2011B_HR60b2.irf",
Bank = 2,
LatticeConstant = 4.66,
GenerateBraggReflections = True,
InstrumentParameterWorkspace = "PG3_Bank2_Foo2",
BraggPeakParameterWorkspace = "Arb_Peaks"
)

# Execute
self.assertTrue(alg_test.isExecuted())

# Verify some values
# Profile parameter workspace
paramws = AnalysisDataService.retrieve("PG3_Bank2_Foo2")

paramname0 = paramws.cell(0, 0)

if paramname0.lower() == "bank":
numrowgood = 28
else:
numrowgood = 27
print "Parameter name of first line = ", paramname0

self.assertEqual(numrowgood, paramws.rowCount())

paramnames = []
for i in xrange(numrowgood):
paramname = paramws.cell(i, 0)
paramnames.append(paramname)
self.assertEqual(paramnames.count("LatticeConstant"), 1)


# Bragg peak list
braggws = AnalysisDataService.retrieve("Arb_Peaks")
self.assertEqual(braggws.rowCount() > 20, True)

# 4. Delete the test hkl file
AnalysisDataService.remove("PG3_Bank2_Foo2")
AnalysisDataService.remove("Arb_Peaks")

return

if __name__ == '__main__':
unittest.main()

0 comments on commit 3745fc2

Please sign in to comment.