Skip to content

Commit

Permalink
more changes for interactions with current EDL/ES
Browse files Browse the repository at this point in the history
Projects load
Examples load
Properties change
Profile gets calculated
Charts get generated and updated
- Fitting doesn't work
  • Loading branch information
rozyczko committed Oct 7, 2024
1 parent 5a06e13 commit 8560760
Show file tree
Hide file tree
Showing 11 changed files with 1,792 additions and 1,749 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ EaElements.ComboBox {

EaComponents.TableViewParameter {
enabled: false
text: comboBox.model[index].name
// text: comboBox.model[index].name
text: "none"
}
}
}
Expand Down
31 changes: 17 additions & 14 deletions easyDiffractionApp/Logic/Experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def jobToBlock(self, job=None):
cifDict = 'core'
dataBlock = {'name': '', 'params': {}, 'loops': {}}
dataBlock['name'] = dict(Parameter(
value = job.name,
value = job.experiment.name,
icon = 'microscope'))
param = 'params'
category = '_diffrn_radiation'
Expand Down Expand Up @@ -680,7 +680,8 @@ def replaceExperiment(self, edCifNoMeas=''):
currentDataBlock = self._dataBlocksNoMeas[self.currentIndex]
currentExperimentName = currentDataBlock['name']['value']

calcObjBlockNames = [item.data_name for item in self._interface.data()._calcObj]
# calcObjBlockNames = [item.data_name for item in self._interface.data()._calcObj]
calcObjBlockNames = [item.data_name for item in self._interface.data()._cryspyObj]
calcObjBlockIdx = calcObjBlockNames.index(currentExperimentName)

if not edCifNoMeas:
Expand Down Expand Up @@ -811,7 +812,9 @@ def appendDataBlockLoopRow(self, category):
lastBkgPoint = self._dataBlocksNoMeas[blockIdx]['loops'][category][-1]

newBkgPoint = copy.deepcopy(lastBkgPoint)
newBkgPoint['line_segment_X']['value'] += 10
point = float(newBkgPoint['line_segment_X']['value'])
newBkgPoint['line_segment_X']['value'] = point + 10
# newBkgPoint['line_segment_X']['value'] += 10

self._dataBlocksNoMeas[blockIdx]['loops'][category].append(newBkgPoint)
atomsCount = len(self._dataBlocksNoMeas[blockIdx]['loops'][category])
Expand Down Expand Up @@ -891,7 +894,8 @@ def blocksToLoopJob(self, blockIdx, category, name, rowIndex, field, value):
p_category = BLOCK2JOB[category]
# get category
# assumption of the first loop, since there is only one background currently
job_with_category = getattr(self.job, p_category)[0]
# job_with_category = getattr(self.job, p_category)[0]
job_with_category = getattr(self.job, p_category)
# should we get the loop item?
# this works for the background, but not for scale etc.
try:
Expand Down Expand Up @@ -1190,21 +1194,20 @@ def isSpinPolarized(self):
def runProfileCalculations(self):

# shove it all into the calculator.

result = self._interface.calculate_profile()
# debug stuff - remove before merging
# simx = self._xArrays
# simx = self._dataBlocksMeasOnly[0]['loops']['_pd_meas'][0]['2theta_scan']['value']
# result = self._job.create_simulation(simx)

console.debug(formatMsg('sub', 'Profle calculations', 'finished'))

chiSq = result[0]
self._proxy.fitting._pointsCount = result[1]
self._proxy.fitting._freeParamsCount = len(result[4])
self._proxy.fitting.chiSq = chiSq / (self._proxy.fitting._pointsCount - self._proxy.fitting._freeParamsCount)
chiSqn = chiSq / (result[1] - len(result[4]))
self._proxy.status.goodnessOfFit = f'{chiSqn:0.2f}'

# code left to reuse the format statements later
#################################################
# self._proxy.fitting._pointsCount = result[1]
# self._proxy.fitting._freeParamsCount = len(result[4])
# self._proxy.fitting.chiSq = chiSq / (self._proxy.fitting._pointsCount - self._proxy.fitting._freeParamsCount)

gofLastIter = self._proxy.fitting.chiSq # NEED FIX
# gofLastIter = self._proxy.fitting.chiSq # NEED FIX
# if self._proxy.fitting.chiSqStart is None:
# self._proxy.status.goodnessOfFit = f'{gofLastIter:0.2f}' # NEED move to connection
# else:
Expand Down
2 changes: 1 addition & 1 deletion easyDiffractionApp/Logic/Fittables.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def resetAll(self):
def data(self):
#console.error('FITTABLES DATA GETTER')
return self._data

@Property(str, notify=dataJsonChanged)
def dataJson(self):
return self._dataJson
Expand Down
2 changes: 1 addition & 1 deletion easyDiffractionApp/Logic/Fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from PySide6.QtCore import QObject, Signal, Slot, Property, QThreadPool

from EasyApp.Logic.Logging import console
from easydiffraction.io.helpers import formatMsg
from easydiffraction.io.Helpers import formatMsg
from Logic.Data import Data

try:
Expand Down
4 changes: 4 additions & 0 deletions easyDiffractionApp/Logic/Fitting2.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, proxy=None, interface=None):
self._job = self.parent.job
# self.fitter = CoreFitter(self.parent.sample(), self.interface.fit_func)
self.fitter = CoreFitter(self._job, self._job.calculate_profile)
# self.fitter = CoreFitter(self._job, self._job.interface.calculate_profile)
# self.fitter = CoreFitter(self.parent.experiment.job(), self.interface.fit_func)

# Multithreading
Expand Down Expand Up @@ -91,6 +92,9 @@ def fit_nonpolar(self):
try:
res = self.fitter.fit(x, y, **kwargs)

#self._job.fit(**kwargs)
# res = self._job.fitting_results

except Exception as ex:
self.failed.emit(str(ex))
return
Expand Down
33 changes: 20 additions & 13 deletions easyDiffractionApp/Logic/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

BLOCK2PHASE = {
'_cell': 'cell',
'_space_group': 'spacegroup',
'_space_group': 'space_group',
'_atom_site': 'atoms',
'occupancy': 'occupancy',
'fract_x': 'fract_x',
Expand All @@ -66,6 +66,7 @@
'crystal_system': 'crystal_system',
'IT_number': 'int_number',
'IT_coordinate_system_code': 'setting',
'B_iso_or_equiv': 'Biso',
}
class Model(QObject):
definedChanged = Signal()
Expand Down Expand Up @@ -197,7 +198,7 @@ def atomData(self, typeSymbol, key):
def addDefaultModel(self):
console.debug("Adding default model(s)")
self.loadModelsFromEdCif(_DEFAULT_CIF_BLOCK)
self.addDefaultPhase()
# self.addDefaultPhase()

@Slot('QVariant')
def loadModelsFromResources(self, fpaths):
Expand Down Expand Up @@ -228,27 +229,31 @@ def loadModelsFromFiles(self, fpaths):
# @Slot(str)
def loadModelsFromEdCif(self, edCif):
# Update the Phases object
phases = Phases.from_cif_string(edCif)
phases.interface = self._interface
for phase in phases:
phase.scale.fixed = True
# self.phases.append(phase)
self.job.add_phase(phase=phase)
self.job.add_sample_from_string(edCif)

# phases = Phases.from_cif_string(edCif)
# phases.interface = self._interface
# for phase in phases:
# phase.scale.fixed = True
# # self.phases.append(phase)
# self.job.add_phase(phase=phase)

self._currentIndex = len(self.job.phases) - 1
# convert phase into dataBlocks
dataBlocks = self.phaseToBlocks(self.job.phases)
self._dataBlocks.append(dataBlocks)
self.defined = bool(len(self._dataBlocks))

self.setDataBlocksCif()
self.updateCifOnInterface()
self.updateCifOnInterface(cif=edCif)
self.dataBlocksChanged.emit()

def updateCifOnInterface(self):
def updateCifOnInterface(self, cif=None):
'''
Update the CIF representation on the current interface
'''
cif = self._dataBlocksCif[self.currentIndex][0]
if cif is None:
cif = self._dataBlocksCif[self.currentIndex][0]
self._interface.updateModelCif(cif)

def phaseToBlocks(self, phases):
Expand Down Expand Up @@ -483,6 +488,8 @@ def blocksToLoopPhase(self, blockIdx, category, name, rowIndex, field, value):
p_category = BLOCK2PHASE[category]
# get category
phase_with_category = getattr(phase, p_category)[rowIndex]
if p_name == 'Biso':
phase_with_category = getattr(phase_with_category, 'adp')
# get loop item
phase_with_item = getattr(phase_with_category, p_name)
if field == 'value':
Expand Down Expand Up @@ -691,10 +698,10 @@ def editCalculatorDictByMainParam(self, blockIdx, category, name, field, value):
if field == 'fit':
path[1] = f'flags_{path[1]}'

oldValue = self._interface.data()._cryspyDict[path[0]][path[1]][path[2]]
oldValue = self._interface.data()._cryspyDict[path[0].lower()][path[1]][path[2]]
if oldValue == value:
return False
self._interface.data()._cryspyDict[path[0]][path[1]][path[2]] = value
self._interface.data()._cryspyDict[path[0].lower()][path[1]][path[2]] = value

console.debug(formatMsg('sub', 'Calculator dict', f'{oldValue}{value}', f'{path}'))
return True
Expand Down
2 changes: 1 addition & 1 deletion easyDiffractionApp/Logic/Plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def setQtChartsSerieRef(self, page, serie, ref):
#if self._chartRefs['QtCharts'][page][serie] == ref:
# return
if ref.name(): # braggSeries
self._chartRefs['QtCharts'][page][serie][ref.name()] = ref
self._chartRefs['QtCharts'][page][serie][ref.name().lower()] = ref
console.debug(formatMsg('sub', f'{serie} with name {ref.name()} on {page}: {ref}'))
else: # other series
self._chartRefs['QtCharts'][page][serie] = ref
Expand Down
3 changes: 2 additions & 1 deletion easyDiffractionApp/Logic/PyProxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@
class PyProxy(QObject):
def __init__(self, parent=None):
super().__init__(parent)
# self.interface = InterfaceFactory()
# instantiate the Job object.
# This is done only once, since in the App world there is only one Job
self._job = Job()
self.interface = InterfaceFactory()
self.interface = self._job.interface
self._logger = LoggerLevelHandler(self)
self._project = Project(self)
self._experiment = Experiment(self, interface=self.interface)
Expand Down
17 changes: 17 additions & 0 deletions easyDiffractionApp/Logic/Tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,23 @@
"U": "#D0D0E0",
"Np": "#D0D0E0",
"Pu": "#D0D0E0",
"Am": "#D0D0E0",
"Cm": "#D0D0E0",
"Bk": "#D0D0E0",
"Cf": "#D0D0E0",
"Es": "#D0D0E0",
"Fm": "#D0D0E0",
"Md": "#D0D0E0",
"No": "#D0D0E0",
"Lr": "#D0D0E0",
"Rf": "#D0D0E0",
"Db": "#D0D0E0",
"Sg": "#D0D0E0",
"Bh": "#D0D0E0",
"Hs": "#D0D0E0",
"Mt": "#D0D0E0",
"Ds": "#D0D0E0",
"Rg": "#D0D0E0",
}
PERIODIC_TABLE = {
"H": {
Expand Down
Loading

0 comments on commit 8560760

Please sign in to comment.