From b4b84a5934b8a0cebd0eabe52f762889f52a595c Mon Sep 17 00:00:00 2001 From: Michael Wedel <michael.wedel@esss.se> Date: Fri, 15 Jan 2016 15:48:22 +0100 Subject: [PATCH] Refs #11268. Errors are removed from numbers. The numbers in CIFs may contain error estimates, indicated like this: 0.03(1), the strings are cut off starting with ( now. --- .../PythonInterface/plugins/algorithms/LoadCIF.py | 15 +++++++++++++-- .../test/python/plugins/algorithms/LoadCIFTest.py | 11 +++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/Framework/PythonInterface/plugins/algorithms/LoadCIF.py b/Framework/PythonInterface/plugins/algorithms/LoadCIF.py index f8ebacaca33..74a601627fd 100644 --- a/Framework/PythonInterface/plugins/algorithms/LoadCIF.py +++ b/Framework/PythonInterface/plugins/algorithms/LoadCIF.py @@ -6,6 +6,15 @@ from mantid.geometry import SpaceGroupFactory, CrystalStructure import re +# pylint: disable=invalid-name +def removeErrorEstimateFromNumber(numberString): + errorBegin = numberString.find('(') + + if errorBegin == -1: + return numberString + + return numberString[:errorBegin] + class CrystalStructureBuilder(object): ''' @@ -80,7 +89,8 @@ class CrystalStructureBuilder(object): unitCellComponents = [u'_cell_length_a', u'_cell_length_b', u'_cell_length_c', u'_cell_angle_alpha', u'_cell_angle_beta', u'_cell_angle_gamma'] - unitCellValueMap = dict([(str(x), str(cifData[x])) if x in cifData.keys() else (str(x), None) for x in + unitCellValueMap = dict([(str(x), removeErrorEstimateFromNumber(str(cifData[x]))) if x in cifData.keys() + else (str(x), None) for x in unitCellComponents]) if unitCellValueMap['_cell_length_a'] is None: @@ -123,7 +133,8 @@ class CrystalStructureBuilder(object): for atomLine in zip(*atomLists): stringAtomLine = [str(x) for x in atomLine] - cleanLine = [self._getCleanAtomSymbol(stringAtomLine[0])] + list(stringAtomLine[1:]) + cleanLine = [self._getCleanAtomSymbol(stringAtomLine[0])] + [removeErrorEstimateFromNumber(x) for x in + list(stringAtomLine[1:])] atomLines.append(' '.join(cleanLine)) return ';'.join(atomLines) diff --git a/Framework/PythonInterface/test/python/plugins/algorithms/LoadCIFTest.py b/Framework/PythonInterface/test/python/plugins/algorithms/LoadCIFTest.py index 5c44110e723..816408b3e30 100644 --- a/Framework/PythonInterface/test/python/plugins/algorithms/LoadCIFTest.py +++ b/Framework/PythonInterface/test/python/plugins/algorithms/LoadCIFTest.py @@ -90,8 +90,11 @@ class CrystalStructureBuilderTestUnitCell(unittest.TestCase): def test_getUnitCell_hexagonal(self): cell = {u'_cell_length_a': u'5.6', u'_cell_length_c': u'2.3', u'_cell_angle_gamma': u'120.0'} + cell_errors = {u'_cell_length_a': u'5.6(1)', u'_cell_length_c': u'2.3(1)', u'_cell_angle_gamma': u'120.0'} self.assertEqual(self.builder._getUnitCell(cell), '5.6 5.6 2.3 90.0 90.0 120.0') + self.assertEqual(self.builder._getUnitCell(cell_errors), '5.6 5.6 2.3 90.0 90.0 120.0') + class CrystalStructureBuilderTestAtoms(unittest.TestCase): @@ -111,10 +114,10 @@ class CrystalStructureBuilderTestAtoms(unittest.TestCase): def test_getAtoms_correct(self): data = dict([(u'_atom_site_label', [u'Si', u'Al']), - (u'_atom_site_fract_x', [u'1/8', u'0.34']), - (u'_atom_site_fract_y', [u'1/8', u'0.56']), - (u'_atom_site_fract_z', [u'1/8', u'0.23']), - (u'_atom_site_occupancy', [u'1.0', u'1.0']), + (u'_atom_site_fract_x', [u'1/8', u'0.34(1)']), + (u'_atom_site_fract_y', [u'1/8', u'0.56(2)']), + (u'_atom_site_fract_z', [u'1/8', u'0.23(2)']), + (u'_atom_site_occupancy', [u'1.0', u'1.0(0)']), (u'_atom_site_U_iso_or_equiv', [u'0.01', u'0.02'])]) self.assertEqual(self.builder._getAtoms(data), 'Si 1/8 1/8 1/8 1.0 0.01;Al 0.34 0.56 0.23 1.0 0.02') -- GitLab