4
4
from .calculator_base import CalculatorBase
5
5
from easydiffraction .utils .formatting import warning
6
6
7
- from easydiffraction .sample_models .sample_models import SampleModels
8
- from easydiffraction .experiments .experiments import Experiments
7
+ from easydiffraction .sample_models .sample_model import SampleModel
9
8
from easydiffraction .experiments .experiment import Experiment
10
9
11
10
try :
@@ -33,19 +32,21 @@ def __init__(self) -> None:
33
32
super ().__init__ ()
34
33
self ._cryspy_dicts : Dict [str , Dict [str , Any ]] = {}
35
34
36
- def calculate_structure_factors (self , sample_models : SampleModels , experiments : Experiments ) -> None :
35
+ def calculate_structure_factors (self ,
36
+ sample_model : SampleModel ,
37
+ experiment : Experiment ) -> None :
37
38
"""
38
39
Raises a NotImplementedError as HKL calculation is not implemented.
39
40
40
41
Args:
41
- sample_models : The sample models to calculate structure factors for.
42
- experiments : The experiments associated with the sample models.
42
+ sample_model : The sample model to calculate structure factors for.
43
+ experiment : The experiment associated with the sample models.
43
44
"""
44
45
raise NotImplementedError ("HKL calculation is not implemented for CryspyCalculator." )
45
46
46
47
def _calculate_single_model_pattern (
47
48
self ,
48
- sample_model : SampleModels ,
49
+ sample_model : SampleModel ,
49
50
experiment : Experiment ,
50
51
called_by_minimizer : bool = False
51
52
) -> Union [np .ndarray , List [float ]]:
@@ -65,8 +66,10 @@ def _calculate_single_model_pattern(
65
66
Returns:
66
67
The calculated diffraction pattern as a NumPy array or a list of floats.
67
68
"""
69
+ combined_name = f"{ sample_model .name } _{ experiment .name } "
70
+
68
71
if called_by_minimizer :
69
- if self ._cryspy_dicts and experiment . name in self ._cryspy_dicts :
72
+ if self ._cryspy_dicts and combined_name in self ._cryspy_dicts :
70
73
cryspy_dict = self ._recreate_cryspy_dict (sample_model , experiment )
71
74
else :
72
75
cryspy_obj = self ._recreate_cryspy_obj (sample_model , experiment )
@@ -75,7 +78,7 @@ def _calculate_single_model_pattern(
75
78
cryspy_obj = self ._recreate_cryspy_obj (sample_model , experiment )
76
79
cryspy_dict = cryspy_obj .get_dictionary ()
77
80
78
- self ._cryspy_dicts [experiment . name ] = copy .deepcopy (cryspy_dict )
81
+ self ._cryspy_dicts [combined_name ] = copy .deepcopy (cryspy_dict )
79
82
80
83
cryspy_in_out_dict : Dict [str , Any ] = {}
81
84
rhochi_calc_chi_sq_by_dictionary (
@@ -99,14 +102,16 @@ def _calculate_single_model_pattern(
99
102
try :
100
103
signal_plus = cryspy_in_out_dict [cryspy_block_name ]['signal_plus' ]
101
104
signal_minus = cryspy_in_out_dict [cryspy_block_name ]['signal_minus' ]
102
- y_calc_total = signal_plus + signal_minus
105
+ y_calc = signal_plus + signal_minus
103
106
except KeyError :
104
107
print (f"[CryspyCalculator] Error: No calculated data for { cryspy_block_name } " )
105
108
return []
106
109
107
- return y_calc_total
110
+ return y_calc
108
111
109
- def _recreate_cryspy_dict (self , sample_model : SampleModels , experiment : Experiment ) -> Dict [str , Any ]:
112
+ def _recreate_cryspy_dict (self ,
113
+ sample_model : SampleModel ,
114
+ experiment : Experiment ) -> Dict [str , Any ]:
110
115
"""
111
116
Recreates the Cryspy dictionary for the given sample model and experiment.
112
117
@@ -117,7 +122,8 @@ def _recreate_cryspy_dict(self, sample_model: SampleModels, experiment: Experime
117
122
Returns:
118
123
The updated Cryspy dictionary.
119
124
"""
120
- cryspy_dict = copy .deepcopy (self ._cryspy_dicts [experiment .name ])
125
+ combined_name = f"{ sample_model .name } _{ experiment .name } "
126
+ cryspy_dict = copy .deepcopy (self ._cryspy_dicts [combined_name ])
121
127
122
128
cryspy_model_id = f'crystal_{ sample_model .name } '
123
129
cryspy_model_dict = cryspy_dict [cryspy_model_id ]
@@ -185,7 +191,9 @@ def _recreate_cryspy_dict(self, sample_model: SampleModels, experiment: Experime
185
191
186
192
return cryspy_dict
187
193
188
- def _recreate_cryspy_obj (self , sample_model : SampleModels , experiment : Experiment ) -> Any :
194
+ def _recreate_cryspy_obj (self ,
195
+ sample_model : SampleModel ,
196
+ experiment : Experiment ) -> Any :
189
197
"""
190
198
Recreates the Cryspy object for the given sample model and experiment.
191
199
@@ -212,7 +220,8 @@ def _recreate_cryspy_obj(self, sample_model: SampleModels, experiment: Experimen
212
220
213
221
return cryspy_obj
214
222
215
- def _convert_sample_model_to_cryspy_cif (self , sample_model : SampleModels ) -> str :
223
+ def _convert_sample_model_to_cryspy_cif (self ,
224
+ sample_model : SampleModel ) -> str :
216
225
"""
217
226
Converts a sample model to a Cryspy CIF string.
218
227
@@ -224,7 +233,9 @@ def _convert_sample_model_to_cryspy_cif(self, sample_model: SampleModels) -> str
224
233
"""
225
234
return sample_model .as_cif ()
226
235
227
- def _convert_experiment_to_cryspy_cif (self , experiment : Experiment , linked_phase : Any ) -> str :
236
+ def _convert_experiment_to_cryspy_cif (self ,
237
+ experiment : Experiment ,
238
+ linked_phase : Any ) -> str :
228
239
"""
229
240
Converts an experiment to a Cryspy CIF string.
230
241
0 commit comments