Skip to content

Commit

Permalink
added optional to some phase params to make possible editing CIF in
Browse files Browse the repository at this point in the history
place
modified setup for the cryspy job object
  • Loading branch information
rozyczko committed Feb 12, 2025
1 parent 1fe8c4e commit 107675c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 32 deletions.
63 changes: 33 additions & 30 deletions src/easydiffraction/calculators/cryspy/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,12 +444,13 @@ def powder_1d_calculate(self, x_array: np.ndarray, full_return: bool = False, **

if self.pattern is None:
scale = 1.0
offset = 0
# offset = 0
else:
scale = self.pattern.scale.value / norm
offset = self.pattern.zero_shift.value
# offset = self.pattern.zero_shift.value

this_x_array = x_array - offset
# this_x_array = x_array - offset
this_x_array = x_array

if 'excluded_points' in kwargs:
setattr(self.model, 'excluded_points', kwargs['excluded_points'])
Expand Down Expand Up @@ -796,17 +797,19 @@ def updateCryspyDict(self, item, key, value):
cryspy_key = CRYSPY_MODEL_PHASE_KEYS[key]
loc = cryspy_dict[cryspy_key]
# find the text in `item` after the last underscore
# will fail if new phase added
atom_index = int(item[item.rfind('_') + 1 :])
# is this a fractional coordinate?
if 'fract' in key:
coord_index = CRYSPY_MODEL_COORD_INDEX[key]
loc[coord_index][atom_index] = value
elif 'length' in key:
coord_index = CRYSPY_MODEL_COORD_INDEX[key]
loc[coord_index] = value
else:
loc[atom_index] = value
return
if atom_index < len(loc):
# is this a fractional coordinate?
if 'fract' in key:
coord_index = CRYSPY_MODEL_COORD_INDEX[key]
loc[coord_index][atom_index] = value
elif 'length' in key:
coord_index = CRYSPY_MODEL_COORD_INDEX[key]
loc[coord_index] = value
else:
loc[atom_index] = value
return
elif key in CRYSPY_MODEL_INSTR_KEYS:
# instrument param
exp_name = list(self._cryspyData._cryspyDict.keys())[1]
Expand Down Expand Up @@ -888,7 +891,6 @@ def polarized_update(func, crystals, profiles, peak_dat, scales, x_str):
def _do_run(self, model, polarized, x_array, crystals, phase_list, bg, phase_scales):
idx = [idx for idx, item in enumerate(model.items) if isinstance(item, cryspy.PhaseL)][0]
model.items[idx] = phase_list

data_name = crystals.data_name

is_tof = False
Expand All @@ -903,32 +905,33 @@ def _do_run(self, model, polarized, x_array, crystals, phase_list, bg, phase_sca
if not self._cryspyData._cryspyDict:
return None

new_exp_key = ''

phase_name = ''
exp_name_model = ''
# Find the name of the experiment in the model
for key in self._cryspyData._cryspyDict.keys():
# skip phases
if 'crystal_' in key:
# remove 'crytal_' from the key
phase_name = key.split('_', 1)[1]
continue
new_exp_key = key
exp_name_model = key
break
if new_exp_key:
exp_name_model_split = new_exp_key.split('_', 1)[1]
exp_name_model = new_exp_key

# model -> dict
setattr(self.model, 'data_name', exp_name_model_split)

# get cryspy experiment dict from the model
experiment_dict_model = self.model.get_dictionary()

# update scale in experimental_dict_model
experiment_dict_model['phase_scale'] = np.array(phase_scales)
if not exp_name_model:
# no exp defined, default
# exp_name_model_split = self.model.PREFIX
exp_name_model = self.model.PREFIX + '_' + phase_name
# get cryspy experiment dict from the model: expensive!
# model -> dict
setattr(self.model, 'data_name', phase_name)
experiment_dict_model = self.model.get_dictionary()
self._cryspyData._cryspyDict[exp_name_model] = experiment_dict_model

self._cryspyDict = self._cryspyData._cryspyDict
# update _cryspyDict with the experiment
self._cryspyDict[exp_name_model] = experiment_dict_model

# add extra fluff
self._cryspyDict[exp_name_model]['phase_scale'] = np.array(phase_scales)

self.excluded_points = np.full(len(ttheta), False)
if hasattr(self.model, 'excluded_points'):
self.excluded_points = self.model.excluded_points
Expand Down
4 changes: 2 additions & 2 deletions src/easydiffraction/io/cif.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,8 +1061,8 @@ def dataBlockToCif(block, includeBlockName=True):
# for param in category.values():
for param in category.values():
# `param` is an easyCore Parameter object
# if param["optional"]:
# continue
if 'optional' in param and param['optional']:
continue
value = param['value']
if value is None:
continue
Expand Down

0 comments on commit 107675c

Please sign in to comment.