Skip to content
Snippets Groups Projects
Commit cea186a6 authored by Michael Wedel's avatar Michael Wedel
Browse files

Refs #11418. Adding documentation, changing algorithm name

The new algorithm name is a better reflection of what it's actually doing.
parent f72c6503
No related branches found
No related tags found
No related merge requests found
......@@ -10,6 +10,7 @@ import os
class PoldiCompound(object):
"""Small helper class to handle the results from PoldiCrystalFileParser."""
_name = ""
_spacegroup = ""
_atomString = ""
......@@ -48,6 +49,31 @@ def raiseParseErrorException(message):
class PoldiCrystalFileParser(object):
"""Small parser for crystal structure files used at POLDI
This class encapsulates a small parser for crystal structure files that are used at
POLDI. The files contains information about the lattice, the space group and the basis (atoms
in the asymmetric unit).
The file format is defined as follows:
Compound_1 {
Lattice: [1 - 6 floats] => a, b, c, alpha, beta, gamma
Spacegroup: [valid space group symbol]
Atoms; {
Element x y z [occupancy [U_eq]]
Element x y z [occupancy [U_eq]]
}
}
Compound_2 {
...
}
The parser returns a list of PoldiCompound objects with the compounds that were found
in the file. These are then processed by PoldiCreatePeaksFromFile to generate arguments
for calling PoldiCreatePeaksFromCell.
"""
elementSymbol = Word(alphas, min=1, max=2).setFailAction(
lambda o, s, loc, token: raiseParseErrorException("Element symbol must be one or two characters."))
integerNumber = Word(nums)
......@@ -109,7 +135,7 @@ class PoldiCrystalFileParser(object):
return self.compounds.parseString(stringContent)
class PoldiLoadCrystalData(PythonAlgorithm):
class PoldiCreatePeaksFromFile(PythonAlgorithm):
_parser = PoldiCrystalFileParser()
def category(self):
......@@ -184,4 +210,4 @@ class PoldiLoadCrystalData(PythonAlgorithm):
return compound.getName()
AlgorithmFactory.subscribe(PoldiLoadCrystalData)
AlgorithmFactory.subscribe(PoldiCreatePeaksFromFile)
......@@ -57,7 +57,7 @@ set ( TEST_PY_FILES
ExportExperimentLogTest.py
PoldiMergeTest.py
VesuvioResolutionTest.py
PoldiLoadCrystalDataTest.py
PoldiCreatePeaksFromFileTest.py
)
check_tests_valid ( ${CMAKE_CURRENT_SOURCE_DIR} ${TEST_PY_FILES} )
......
......@@ -11,14 +11,14 @@ from mantid.simpleapi import *
import os
class PoldiLoadCrystalDataTest(unittest.TestCase):
class PoldiCreatePeaksFromFileTest(unittest.TestCase):
testname = None
def __init__(self, *args):
unittest.TestCase.__init__(self, *args)
def test_Init(self):
assertRaisesNothing(self, AlgorithmManager.create, ("PoldiLoadCrystalData"))
assertRaisesNothing(self, AlgorithmManager.create, ("PoldiCreatePeaksFromFile"))
def test_FileOneCompoundOneAtom(self):
fileHelper = TemporaryFileHelper("""Silicon {
......@@ -28,7 +28,7 @@ class PoldiLoadCrystalDataTest(unittest.TestCase):
Si 0 0 0 1.0 0.05
}
}""")
ws = PoldiLoadCrystalData(fileHelper.getName(), 0.7, 10.0)
ws = PoldiCreatePeaksFromFile(fileHelper.getName(), 0.7, 10.0)
# Check output GroupWorkspace
self.assertEquals(ws.getNumberOfEntries(), 1)
......@@ -52,7 +52,7 @@ class PoldiLoadCrystalDataTest(unittest.TestCase):
C 0 0 0 0.1 0.05
}
}""")
ws = PoldiLoadCrystalData(fileHelper.getName(), 0.7, 10.0)
ws = PoldiCreatePeaksFromFile(fileHelper.getName(), 0.7, 10.0)
self.assertEquals(ws.getNumberOfEntries(), 1)
self.assertTrue(ws.contains("SiliconCarbon"))
......@@ -82,7 +82,7 @@ class PoldiLoadCrystalDataTest(unittest.TestCase):
Si 0 0 0 1.0 0.05
}
}""")
ws = PoldiLoadCrystalData(fileHelper.getName(), 0.7, 10.0)
ws = PoldiCreatePeaksFromFile(fileHelper.getName(), 0.7, 10.0)
self.assertEquals(ws.getNumberOfEntries(), 2)
self.assertTrue(ws.contains("SiliconCarbon"))
......@@ -114,9 +114,9 @@ class PoldiLoadCrystalDataTest(unittest.TestCase):
}
}""")
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhLatticeMissing.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhNoLattice.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhInvalidLattice.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhLatticeMissing.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhNoLattice.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhInvalidLattice.getName(), 0.7, 10.0, 'ws'))
def test_FileFaultySpaceGroupStrings(self):
......@@ -135,8 +135,8 @@ class PoldiLoadCrystalDataTest(unittest.TestCase):
}
}""")
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhSgMissing.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhSgInvalid.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhSgMissing.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhSgInvalid.getName(), 0.7, 10.0, 'ws'))
def test_FileFaultyAtomStrings(self):
fhAtomsMissing = TemporaryFileHelper("""Silicon {
......@@ -156,9 +156,9 @@ class PoldiLoadCrystalDataTest(unittest.TestCase):
Atoms: { }
}""")
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhAtomsMissing.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhAtomsNoBraces.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiLoadCrystalData, *(fhAtomsEmpty.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhAtomsMissing.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhAtomsNoBraces.getName(), 0.7, 10.0, 'ws'))
self.assertRaises(RuntimeError, PoldiCreatePeaksFromFile, *(fhAtomsEmpty.getName(), 0.7, 10.0, 'ws'))
def _tablesAreEqual(self, lhs, rhs):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment