Skip to content

Commit

Permalink
Refs #11268. Errors are removed from numbers.
Browse files Browse the repository at this point in the history
The numbers in CIFs may contain error estimates, indicated like this: 0.03(1), the strings are cut off starting with ( now.
  • Loading branch information
Michael Wedel committed Jan 15, 2016
1 parent c99b141 commit b4b84a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
15 changes: 13 additions & 2 deletions Framework/PythonInterface/plugins/algorithms/LoadCIF.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@

import re

# pylint: disable=invalid-name
def removeErrorEstimateFromNumber(numberString):
errorBegin = numberString.find('(')

if errorBegin == -1:
return numberString

return numberString[:errorBegin]


class CrystalStructureBuilder(object):
'''
Expand Down Expand Up @@ -80,7 +89,8 @@ def _getUnitCell(self, cifData):
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:
Expand Down Expand Up @@ -123,7 +133,8 @@ def _getAtoms(self, cifData):
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ def test_getUnitCell_orthorhombic(self):

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):
Expand All @@ -111,10 +114,10 @@ def test_getAtoms_required_keys(self):

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')
Expand Down

0 comments on commit b4b84a5

Please sign in to comment.