def __init__(self, aa=FitParameter(parameter_name="aa", value=1e-3), bb=FitParameter(parameter_name="bb", value=1e-3), e1 = FitParameter(parameter_name="e1" , value=1e-4), e3 = FitParameter(parameter_name="e3" , value=1e-4), e6 = FitParameter(parameter_name="e6" , value=1e-4)): super().__init__(aa, bb, 12, e1, e3=e3, e6=e6)
def __init__(self, aa=FitParameter(parameter_name="aa", value=1e-3), bb=FitParameter(parameter_name="bb", value=1e-3), e1 = FitParameter(parameter_name="e1" , value=1e-4), e3 = FitParameter(parameter_name="e3" , value=1e-4), e6 = FitParameter(parameter_name="e6" , value=1e-4)): super().__init__(aa, bb, 11, e1, e3=e3, e6=e6) raise NotImplementedError("TO BE CHECKED")
def send_contrast_factor_a_b(self): try: if not self.fit_global_parameters is None: if self.fit_global_parameters.fit_initialization is None: raise ValueError( "Calculation is not possibile, Crystal Structure is missing" ) if self.fit_global_parameters.fit_initialization.crystal_structures is None: raise ValueError( "Calculation is not possibile, Crystal Structure is missing" ) congruence.checkStrictlyPositiveNumber(self.c11, "c11") congruence.checkStrictlyPositiveNumber(self.c12, "c12") congruence.checkStrictlyPositiveNumber(self.c44, "c44") symmetry = self.fit_global_parameters.fit_initialization.crystal_structures[ 0].symmetry Ae, Be, As, Bs = calculate_A_B_coefficients( self.c11, self.c12, self.c44, symmetry) text = "Ae = " + str(Ae) + "\n" text += "Be = " + str(Be) + "\n" text += "As = " + str(As) + "\n" text += "Bs = " + str(Bs) + "\n" self.text_area.setText(text) self.fit_global_parameters.strain_parameters = [ KrivoglazWilkensModel( Ae=FitParameter(parameter_name=KrivoglazWilkensModel. get_parameters_prefix() + "Ae", value=Ae, fixed=True), Be=FitParameter(parameter_name=KrivoglazWilkensModel. get_parameters_prefix() + "Be", value=Be, fixed=True), As=FitParameter(parameter_name=KrivoglazWilkensModel. get_parameters_prefix() + "As", value=As, fixed=True), Bs=FitParameter(parameter_name=KrivoglazWilkensModel. get_parameters_prefix() + "Bs", value=Bs, fixed=True)) ] self.send("Fit Global Parameters", self.fit_global_parameters) except Exception as e: QMessageBox.critical(self, "Error", str(e), QMessageBox.Ok) if self.IS_DEVELOP: raise e
def __init__(self, aa=FitParameter(parameter_name="aa", value=1e-3), bb=FitParameter(parameter_name="bb", value=1e-3), laue_id = 13, e1 = FitParameter(parameter_name="e1" , value=1e-4), e4 = FitParameter(parameter_name="e4" , value=1e-4)): super(InvariantPAHCubic, self).__init__(aa, bb, laue_id, e1=e1, e2=FitParameter(parameter_name=self.get_parameters_prefix() + "e2", value=e1.value, function=True, function_value=e1.parameter_name), e3=FitParameter(parameter_name=self.get_parameters_prefix() + "e3", value=e1.value, function=True, function_value=e1.parameter_name), e4=e4, e5=FitParameter(parameter_name=self.get_parameters_prefix() + "e5", value=e4.value, function=True, function_value=e4.parameter_name), e6=FitParameter(parameter_name=self.get_parameters_prefix() + "e6", value=e4.value, function=True, function_value=e4.parameter_name))
def __init__(self, aa=FitParameter(parameter_name="aa", value=1e-3), bb=FitParameter(parameter_name="bb", value=1e-3), e1 = FitParameter(parameter_name="e1" , value=1e-4), e2 = FitParameter(parameter_name="e2" , value=1e-4), e3 = FitParameter(parameter_name="e3" , value=1e-4), e4 = FitParameter(parameter_name="e4" , value=1e-4), e5 = FitParameter(parameter_name="e5" , value=1e-4), e6 = FitParameter(parameter_name="e6" , value=1e-4), e7 = FitParameter(parameter_name="e7" , value=1e-4)): super().__init__(aa, bb, 3, e1, e2, e3, e4, e5, e6, e7) raise NotImplementedError("TO BE CHECKED")
def __init__(self, aa=FitParameter(parameter_name="aa", value=1e-3), bb=FitParameter(parameter_name="bb", value=1e-3), e1 = FitParameter(parameter_name="e1" , value=1e-4), e3 = FitParameter(parameter_name="e3" , value=1e-4), e4 = FitParameter(parameter_name="e4" , value=1e-4), e6 = FitParameter(parameter_name="e6" , value=1e-4), e7 = FitParameter(parameter_name="e7" , value=1e-4), e9 = FitParameter(parameter_name="e9" , value=1e-4), e15 = FitParameter(parameter_name="e15", value=1e-4)): super().__init__(aa, bb, 8, e1, e3=e3, e4=e4, e6=e6, e7=e7, e9=e9, e15=e15) raise NotImplementedError("TO BE CHECKED")
def generate_reflections(self): if self.widget.populate_parameter_in_widget(self, "a", "").function: QMessageBox.critical( self, "Error", "a0 value is a function, generation is not possibile", QMessageBox.Ok) return if not self.reflections is None and not self.reflections.strip() == "": if not ConfirmDialog.confirmed( self, "Confirm overwriting of exisiting reflections?"): return if self.limit_type == 0: list = list_of_s_bragg(self.a, symmetry=self.cb_symmetry.currentText()) elif self.limit_type == 1: list = list_of_s_bragg(self.a, symmetry=self.cb_symmetry.currentText(), n_peaks=int(self.limit)) elif self.limit_type == 2: if not self.widget.fit_global_parameters is None \ and not self.widget.fit_global_parameters.fit_initialization is None \ and not self.widget.fit_global_parameters.fit_initialization.diffraction_patterns is None \ and not self.widget.fit_global_parameters.fit_initialization.diffraction_patterns[self.index].wavelength.function: wavelength = self.widget.fit_global_parameters.fit_initialization.diffraction_patterns[ self.index].wavelength.value list = list_of_s_bragg(self.a, symmetry=self.cb_symmetry.currentText(), s_max=Utilities.s( numpy.radians(self.limit / 2), wavelength)) else: QMessageBox.critical( self, "Error", "No wavelenght is available, 2theta limit is not possibile", QMessageBox.Ok) return text = "" for index in range(0, len(list)): h = list[index][0][0] k = list[index][0][1] l = list[index][0][2] text += Reflection( h, k, l, FitParameter( parameter_name="I" + str(h) + str(k) + str(l), value=1000, boundary=Boundary(min_value=0.0))).to_text() + "\n" self.text_area.setText(text)
def populate_parameter_in_widget(cls, widget, parameter_name, parameter_prefix, parameter_suffix=""): if hasattr(widget, parameter_name + "_function") and getattr( widget, parameter_name + "_function") == 1: return FitParameter(parameter_name=parameter_prefix + parameter_name + parameter_suffix, function=True, function_value=getattr( widget, parameter_name + "_function_value")) elif getattr(widget, parameter_name + "_fixed") == 1: return FitParameter(parameter_name=parameter_prefix + parameter_name + parameter_suffix, value=getattr(widget, parameter_name), fixed=True) else: boundary = None min_value = PARAM_HWMIN max_value = PARAM_HWMAX if getattr(widget, parameter_name + "_has_min") == 1: min_value = getattr(widget, parameter_name + "_min") if getattr(widget, parameter_name + "_has_max") == 1: max_value = getattr(widget, parameter_name + "_max") if min_value != PARAM_HWMIN or max_value != PARAM_HWMAX: boundary = Boundary(min_value=min_value, max_value=max_value) return FitParameter(parameter_name=parameter_prefix + parameter_name, value=getattr(widget, parameter_name), boundary=boundary)
step = (D_max-D_min)/1000 x = numpy.arange(start=D_min, stop=D_max, step=step) try: if self.distribution == Distribution.LOGNORMAL: y = lognormal_distribution(self.mu.value, self.sigma.value, x) else: y = numpy.zeros(len(x)) if auto: D_min = 0.0 D_max = x[numpy.where(y > 1e-5)][-1] if D_min == D_max: D_min==x[0] x, y, D_min, D_max = self.get_distribution(auto=False, D_min=D_min, D_max=D_max) except: pass return x, y, D_min, D_max if __name__=="__main__": fpl = SizeParameters(shape=Shape.SPHERE, distribution=Distribution.DELTA, mu=FitParameter(value=10, parameter_name="mu"), sigma=None, add_saxs=True) print(fpl.get_parameters())
def parse_reflections(self, text, progressive=""): congruence.checkEmptyString(text, "Reflections") lines = text.splitlines() reflections = [] for i in range(len(lines)): congruence.checkEmptyString(lines[i], "Reflections: line " + str(i + 1)) if not lines[i].strip().startswith("#"): data = lines[i].strip().split(",") if len(data) < 4: raise ValueError("Reflections, malformed line: " + str(i + 1)) h = int(data[0].strip()) k = int(data[1].strip()) l = int(data[2].strip()) if ":=" in data[3].strip(): intensity_data = data[3].strip().split(":=") if len(intensity_data) == 2: intensity_name = intensity_data[0].strip() function_value = intensity_data[1].strip() else: intensity_name = None function_value = data[3].strip() if intensity_name is None: intensity_name = CrystalStructure.get_parameters_prefix( ) + progressive + "I" + str(h) + str(k) + str(l) elif not intensity_name.startswith( CrystalStructure.get_parameters_prefix()): intensity_name = CrystalStructure.get_parameters_prefix( ) + progressive + intensity_name reflection = Reflection(h, k, l, intensity=FitParameter( parameter_name=intensity_name, function=True, function_value=function_value)) else: intensity_data = data[3].strip().split() if len(intensity_data) == 2: intensity_name = intensity_data[0].strip() intensity_value = float(intensity_data[1]) else: intensity_name = None intensity_value = float(data[3]) boundary = None fixed = False if len(data) > 4: min_value = PARAM_HWMIN max_value = PARAM_HWMAX for j in range(4, len(data)): boundary_data = data[j].strip().split() if boundary_data[0] == "min": min_value = float(boundary_data[1].strip()) elif boundary_data[0] == "max": max_value = float(boundary_data[1].strip()) elif boundary_data[0] == "fixed": fixed = True if not fixed: if min_value != PARAM_HWMIN or max_value != PARAM_HWMAX: boundary = Boundary(min_value=min_value, max_value=max_value) else: boundary = Boundary() if intensity_name is None: intensity_name = CrystalStructure.get_parameters_prefix( ) + progressive + "I" + str(h) + str(k) + str(l) elif not intensity_name.startswith( CrystalStructure.get_parameters_prefix()): intensity_name = CrystalStructure.get_parameters_prefix( ) + progressive + intensity_name reflection = Reflection(h, k, l, intensity=FitParameter( parameter_name=intensity_name, value=intensity_value, fixed=fixed, boundary=boundary)) reflections.append(reflection) self.reflections = reflections self.update_reflections()
def init_cube(cls, a0, symmetry=Symmetry.FCC, use_structure=False, formula=None, intensity_scale_factor=None, progressive=""): if not cls.is_cube(symmetry): raise ValueError("Symmetry doesn't belong to a cubic crystal cell") if a0.fixed: a = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "a", value=a0.value, fixed=a0.fixed, boundary=a0.boundary) b = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "b", value=a0.value, fixed=a0.fixed, boundary=a0.boundary) c = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "c", value=a0.value, fixed=a0.fixed, boundary=a0.boundary) else: a = a0 b = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "b", function=True, function_value=CrystalStructure.get_parameters_prefix() + progressive + "a") c = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "c", function=True, function_value=CrystalStructure.get_parameters_prefix() + progressive + "a") alpha = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "alpha", value=90, fixed=True) beta = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "beta", value=90, fixed=True) gamma = FitParameter( parameter_name=CrystalStructure.get_parameters_prefix() + progressive + "gamma", value=90, fixed=True) return CrystalStructure(a, b, c, alpha, beta, gamma, symmetry, use_structure, formula, intensity_scale_factor)
text += "-----------------------------------\n" return text def get_parameters(self): parameters = super().get_parameters() for reflection in self.reflections: parameters.append(reflection.intensity) return parameters if __name__ == "__main__": test = CrystalStructure.init_cube(a0=FitParameter(value=0.55, fixed=True), symmetry=Symmetry.BCC) test = CrystalStructure(a=FitParameter(parameter_name="a", value=0.55), b=FitParameter(parameter_name="b", value=0.66), c=FitParameter(parameter_name="c", value=0.77), alpha=FitParameter(value=10), beta=FitParameter(value=20), gamma=FitParameter(value=30), symmetry=Symmetry.NONE) test.add_reflection( Reflection(1, 0, 3, intensity=FitParameter(
def __init__(self, aa=FitParameter(parameter_name="aa", value=1e-3), bb=FitParameter(parameter_name="bb", value=1e-3), e1 = FitParameter(parameter_name="e1" , value=1e-4), e4 = FitParameter(parameter_name="e4" , value=1e-4)): super(InvariantPAHLaueGroup14, self).__init__(aa, bb, 14, e1, e4)
def __init__(self, aa =FitParameter(parameter_name="aa", value=1e-3), bb =FitParameter(parameter_name="bb", value=1e-3), e1 = FitParameter(parameter_name="e1" , value=1e-4), e2 = FitParameter(parameter_name="e2" , value=1e-4), e3 = FitParameter(parameter_name="e3" , value=1e-4), e4 = FitParameter(parameter_name="e4" , value=1e-4), e5 = FitParameter(parameter_name="e5" , value=1e-4), e6 = FitParameter(parameter_name="e6" , value=1e-4), e7 = FitParameter(parameter_name="e7" , value=1e-4), e8 = FitParameter(parameter_name="e8" , value=1e-4), e9 = FitParameter(parameter_name="e9" , value=1e-4), e10 = FitParameter(parameter_name="e10", value=1e-4), e11 = FitParameter(parameter_name="e11", value=1e-4), e12 = FitParameter(parameter_name="e12", value=1e-4), e13 = FitParameter(parameter_name="e13", value=1e-4), e14 = FitParameter(parameter_name="e14", value=1e-4), e15 = FitParameter(parameter_name="e15", value=1e-4)): super().__init__(aa, bb, 1, e1, e2, e3, e4, e5, e6, e7, e8, e9, e10, e11, e12, e13, e14, e15) raise NotImplementedError("TO BE CHECKED")
text += "Goniometer Radius: " + str(self.goniometer_radius) + "\n" text += self.displacement.to_text() + "\n" text += "-----------------------------------\n" return text def duplicate(self): return SpecimenDisplacement( goniometer_radius=self.goniometer_radius, displacement=None if self.displacement is None else self.displacement.duplicate()) if __name__ == "__main__": test = Caglioti(U=FitParameter(parameter_name="U", value=1.0, fixed=True), V=FitParameter(parameter_name="V", value=2.0, boundary=Boundary(max_value=10.0)), W=FitParameter(parameter_name="W", value=3.0, boundary=Boundary(min_value=-10.0)), a=FitParameter(parameter_name="a", value=4.0, fixed=True), b=FitParameter(parameter_name="b", value=5.0, boundary=Boundary(min_value=-10.0, max_value=10.0)), c=FitParameter(parameter_name="c", value=6.0, boundary=Boundary(min_value=-10.0, max_value=10.0)))
from orangecontrib.xrdanalyzer.controller.fit.instrument.background_parameters import ChebyshevBackground from orangecontrib.xrdanalyzer.controller.fit.instrument.instrumental_parameters import Caglioti, Lab6TanCorrection from orangecontrib.xrdanalyzer.controller.fit.microstructure.size import SizeParameters, Distribution, Shape from orangecontrib.xrdanalyzer.controller.fit.microstructure.strain import InvariantPAHLaueGroup14, InvariantPAH if __name__ == "__main__": fit_global_parameters = FitGlobalParameters() fit_global_parameters.free_input_parameters.set_parameter("A", 10) fit_global_parameters.free_input_parameters.set_parameter("C", 20) parameter_prefix = Caglioti.get_parameters_prefix() fit_global_parameters.instrumental_parameters = Caglioti( a=FitParameter(parameter_name=parameter_prefix + "a", value=0.5, boundary=Boundary(min_value=-10, max_value=10)), b=FitParameter(parameter_name=parameter_prefix + "b", value=0.001, boundary=Boundary(min_value=0, max_value=10)), c=FitParameter(parameter_name=parameter_prefix + "c", function=True, function_value="numpy.exp(A +C)"), U=FitParameter(parameter_name=parameter_prefix + "U", function=True, function_value="numpy.exp(-(A +C))"), V=FitParameter(parameter_name=parameter_prefix + "V", value=0.001, fixed=True), W=FitParameter(parameter_name=parameter_prefix + "W", value=-0.001,