Skip to content

Commit 2970874

Browse files
committed
2theta_offset is cwl only.
Added 3 fist and 3 last lines of the experimental data Added wyckoff symbol parser Minor fixes
1 parent 9627fc3 commit 2970874

File tree

4 files changed

+114
-40
lines changed

4 files changed

+114
-40
lines changed

easyDiffractionApp/Gui/Components/Pages/Model/SideBarBasic/AtomSite.qml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ EaElements.GroupColumn {
155155

156156
EaComponents.TableViewParameter {
157157
enabled: false
158-
text: ""
159-
// text: Globals.Proxies.modelLoopParam('_atom_site', 'site_symmetry_multiplicity', index).value +
160-
// Globals.Proxies.modelLoopParam('_atom_site', 'Wyckoff_symbol', index).value
158+
text: Globals.Proxies.modelLoopParam('_atom_site', 'Wyckoff_symbol', index).value
161159
}
162160

163161
EaComponents.TableViewParameter {

easyDiffractionApp/Logic/Experiment.py

Lines changed: 75 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,29 @@ def jobToBlock(self, job=None, name=None):
315315
cifDict = cifDict
316316
))
317317
if job.type.is_cwl:
318+
# _pd_calib
319+
category = '_pd_calib'
320+
prettyCategory = 'calib'
321+
icon = 'arrows-alt-h'
322+
name = '2theta_offset'
323+
dataBlock[param][category] = {}
324+
dataBlock[param][category][name] = dict(Parameter(
325+
float(job.pattern.zero_shift.value),
326+
error = float(job.pattern.zero_shift.error),
327+
category = category,
328+
prettyCategory = prettyCategory,
329+
name = name,
330+
prettyName = '2θ offset',
331+
shortPrettyName = "offset",
332+
icon = icon,
333+
url = url + category,
334+
cifDict = 'pd',
335+
absDelta = 0.2,
336+
unit = '°',
337+
fittable = True,
338+
fit = not job.pattern.zero_shift.fixed
339+
))
340+
318341
name = 'wavelength'
319342
category = '_diffrn_radiation_wavelength'
320343
prettyCategory = 'radiation'
@@ -658,29 +681,6 @@ def jobToBlock(self, job=None, name=None):
658681
fittable = True,
659682
fit = not job.parameters.sigma2.fixed
660683
))
661-
# _pd_calib
662-
category = '_pd_calib'
663-
prettyCategory = 'calib'
664-
icon = 'arrows-alt-h'
665-
name = '2theta_offset'
666-
dataBlock[param][category] = {}
667-
dataBlock[param][category][name] = dict(Parameter(
668-
float(job.pattern.zero_shift.value),
669-
error = float(job.pattern.zero_shift.error),
670-
category = category,
671-
prettyCategory = prettyCategory,
672-
name = name,
673-
prettyName = '2θ offset',
674-
shortPrettyName = "offset",
675-
icon = icon,
676-
url = url + category,
677-
cifDict = 'pd',
678-
absDelta = 0.2,
679-
unit = '°',
680-
fittable = True,
681-
fit = not job.pattern.zero_shift.fixed
682-
))
683-
684684
#
685685
# _pd_meas
686686
category = '_pd_meas'
@@ -859,20 +859,31 @@ def jobToData(self, job=None):
859859
y_name = name_core + '_I0'
860860
err_name = "s_" + name_core + '_I0'
861861
x_points = job.datastore.store[x_name].data
862-
y_points = np.ones_like(x_points) #job.datastore.store[y_name].data
862+
y_points = job.datastore.store[y_name].data
863863
err_points = job.datastore.store[err_name].data
864864

865-
name = '2theta_scan'
866-
867-
ed_points[name] = dict(Parameter(
868-
x_points,
869-
category = category,
870-
name = name,
871-
prettyName = '2θ',
872-
shortPrettyName = '2θ',
873-
url = url + category,
874-
cifDict = cifDict
875-
))
865+
if job.type.is_cwl:
866+
name = '2theta_scan'
867+
ed_points[name] = dict(Parameter(
868+
x_points,
869+
category = category,
870+
name = name,
871+
prettyName = '2θ',
872+
shortPrettyName = '2θ',
873+
url = url + category,
874+
cifDict = cifDict
875+
))
876+
else:
877+
name = 'time_of_flight'
878+
ed_points[name] = dict(Parameter(
879+
x_points,
880+
category = category,
881+
name = name,
882+
prettyName = 'ms',
883+
shortPrettyName = 'ms',
884+
url = url + category,
885+
cifDict = cifDict
886+
))
876887
name = 'intensity_total'
877888
ed_points[name] = dict(Parameter(
878889
y_points,
@@ -1119,7 +1130,7 @@ def blocksToLoopJob(self, blockIdx, category, name, rowIndex, field, value):
11191130
p_category = BLOCK2JOB[category]
11201131
# get category
11211132
# assumption of the first loop, since there is only one background currently
1122-
job_with_category = getattr(self._job, p_category)[0]
1133+
job_with_category = getattr(self._job, p_category)[rowIndex]
11231134
# should we get the loop item?
11241135
# this works for the background, but not for scale etc.
11251136
try:
@@ -1749,6 +1760,34 @@ def setDataBlocksCif(self):
17491760
cifMeasOnlyReduced = ['\n'.join(block) for block in cifMeasOnlyReduced]
17501761
cifMeasOnlyReduced = [f'\n{block}' for block in cifMeasOnlyReduced]
17511762
cifMeasOnlyReduced = [block.rstrip() for block in cifMeasOnlyReduced]
1763+
# remove all the values from the last block
1764+
cifMeasOnlyReduced[0] = cifMeasOnlyReduced[0].split('[')[0]
1765+
1766+
meas_string = [block.split('\n')[-1] for block in self._dataBlocksCifMeasOnly][-1]
17521767
self._dataBlocksCif = [[noMeas, measOnlyReduced] for (noMeas, measOnlyReduced) in zip(self._dataBlocksCifNoMeas, cifMeasOnlyReduced)]
1768+
1769+
import re
1770+
# Extract the three lists using regex
1771+
matches = re.findall(r'\[([^\]]+)\]', meas_string)
1772+
if len(matches) == 3:
1773+
ast, ae = self.parse_numbers(matches[0])
1774+
bs, be = self.parse_numbers(matches[1])
1775+
cs, ce = self.parse_numbers(matches[2])
1776+
1777+
values = ""
1778+
for i in range(3):
1779+
values += f"{ast[i]:<6} {bs[i]:<8} {cs[i]:<6}\n"
1780+
print("... ... ...")
1781+
values += (".. ... ...\n")
1782+
for i in range(3):
1783+
values += f"{ae[i]:<6} {be[i]:<8} {ce[i]:<6}\n"
1784+
self._dataBlocksCif[0].extend([values])
1785+
17531786
console.debug(formatMsg('sub', f'{len(self._dataBlocksCif)} experiment(s)', 'simplified meas data', 'to CIF string', 'converted'))
17541787
self.dataBlocksCifChanged.emit()
1788+
1789+
# Function to parse numbers, ignoring "..."
1790+
@staticmethod
1791+
def parse_numbers(lst_str):
1792+
values = [float(num) for num in lst_str.split() if num != '...']
1793+
return values[:3], values[-3:] # First 3 and last 3 elements

easyDiffractionApp/Logic/Model.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,14 @@ def addKeys():
398398
icon = 'fill'
399399
addKeys()
400400

401+
atomDict['Wyckoff_symbol'] = {'shortPrettyName': 'WP',
402+
'value': self.getWyckoffSymbol(atom),
403+
'name': 'Wyckoff_symbol',
404+
'category': category,
405+
'idx': idx,
406+
'optional': True,
407+
'fittable': False}
408+
401409
if hasattr(atom, 'adp') and isinstance(atom.adp, AtomicDisplacement):
402410
atomDict['ADP_type'] = {}
403411
atomDict['ADP_type']['display_name'] = 'type'
@@ -514,6 +522,31 @@ def removePhase(self, phase_name: str):
514522
return True
515523
return False
516524

525+
def getWyckoffSymbol(self, atom):
526+
"""
527+
Query the calculator for the list of Wyckoff symbols.
528+
THIS IS NOT HOW IT SHOULD BE DONE!
529+
The method explicitly relies on Cryspy objects and therefore is not general.
530+
"""
531+
if not hasattr(self._interface.data(), '_cryspyObj'):
532+
return ''
533+
c_obj = self._interface.data()._cryspyObj
534+
if c_obj is None:
535+
return ''
536+
537+
current_phase_name = self.phases[self.currentIndex].name.lower()
538+
539+
for crystal in c_obj:
540+
if crystal.data_name.lower() == current_phase_name:
541+
for a in crystal.atom_site:
542+
if a.label == atom.label.value:
543+
s = a.wyckoff_symbol
544+
m = a.multiplicity
545+
if s and m:
546+
return f'{m}{s}'
547+
548+
return ''
549+
517550
@Slot(str)
518551
def replaceModel(self, edCif=''):
519552
"""

easyDiffractionApp/Logic/Project.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,8 +499,12 @@ def gemmiObjToEdProject(starObj):
499499
category, name = param.pair[0].split('.')
500500
if category not in edProject['params']:
501501
edProject['params'][category] = {}
502+
# remove double quotes from param.pair[1]
503+
value = param.pair[1]
504+
if '"' in value:
505+
value = value[1:-1]
502506
edProject['params'][category][name] = dict(Parameter(
503-
param.pair[0],
507+
value,
504508
category = category,
505509
name = name,
506510
prettyName = 'Description',

0 commit comments

Comments
 (0)