Changes in / [3522037:6701a0b] in sasview
- Location:
- src/sas/qtgui
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Calculators/SldPanel.py
r5c0e717 raed0532 6 6 7 7 from periodictable import formula as Formula 8 from periodictable.xsf import xray_energy, xray_sld 8 from periodictable.xsf import xray_energy, xray_sld_from_atoms 9 9 from periodictable.nsf import neutron_scattering 10 10 … … 21 21 'MOLECULAR_FORMULA', 22 22 'MASS_DENSITY', 23 ' NEUTRON_WAVELENGTH',23 'WAVELENGTH', 24 24 'NEUTRON_SLD_REAL', 25 25 'NEUTRON_SLD_IMAG', 26 'XRAY_WAVELENGTH', 27 'XRAY_SLD_REAL', 28 'XRAY_SLD_IMAG', 26 'CU_KA_SLD_REAL', 27 'CU_KA_SLD_IMAG', 28 'MO_KA_SLD_REAL', 29 'MO_KA_SLD_IMAG', 29 30 'NEUTRON_INC_XS', 30 31 'NEUTRON_ABS_XS', … … 33 34 34 35 class SldResult(object): 35 def __init__(self, molecular_formula, mass_density, 36 neutron_wavelength, neutron_sld_real, neutron_sld_imag, 37 xray_wavelength, xray_sld_real, xray_sld_imag, 36 def __init__(self, molecular_formula, mass_density, wavelength, 37 neutron_sld_real, neutron_sld_imag, 38 cu_ka_sld_real, cu_ka_sld_imag, 39 mo_ka_sld_real, mo_ka_sld_imag, 38 40 neutron_inc_xs, neutron_abs_xs, neutron_length): 39 41 40 42 self.molecular_formula = molecular_formula 41 43 self.mass_density = mass_density 42 self. neutron_wavelength = neutron_wavelength44 self.wavelength = wavelength 43 45 self.neutron_sld_real = neutron_sld_real 44 46 self.neutron_sld_imag = neutron_sld_imag 45 self.xray_wavelength = xray_wavelength 46 self.xray_sld_real = xray_sld_real 47 self.xray_sld_imag = xray_sld_imag 47 self.cu_ka_sld_real = cu_ka_sld_real 48 self.cu_ka_sld_imag = cu_ka_sld_imag 49 self.mo_ka_sld_real = mo_ka_sld_real 50 self.mo_ka_sld_imag = mo_ka_sld_imag 48 51 self.neutron_inc_xs = neutron_inc_xs 49 52 self.neutron_abs_xs = neutron_abs_xs 50 53 self.neutron_length = neutron_length 51 54 52 def sldAlgorithm(molecular_formula, mass_density, neutron_wavelength, xray_wavelength): 53 54 xray_sld_real, xray_sld_imag = xray_sld( 55 compound=molecular_formula, 55 def sldAlgorithm(molecular_formula, mass_density, wavelength): 56 57 sld_formula = Formula(molecular_formula, density=mass_density) 58 59 def calculate_sld(formula): 60 if len(formula.atoms) != 1: 61 raise NotImplementedError() 62 energy = xray_energy(list(formula.atoms.keys())[0].K_alpha) 63 return xray_sld_from_atoms( 64 sld_formula.atoms, 56 65 density=mass_density, 57 wavelength=xray_wavelength) 58 59 (neutron_sld_real, neutron_sld_imag, _), (_, neutron_abs_xs, neutron_inc_xs), neutron_length = \ 66 energy=energy) 67 68 cu_real, cu_imag = calculate_sld(Formula("Cu")) 69 mo_real, mo_imag = calculate_sld(Formula("Mo")) 70 71 (sld_real, sld_imag, _), (_, neutron_abs_xs, neutron_inc_xs), neutron_length = \ 60 72 neutron_scattering( 61 73 compound=molecular_formula, 62 74 density=mass_density, 63 wavelength= neutron_wavelength)75 wavelength=wavelength) 64 76 65 77 SCALE = 1e-6 66 78 67 79 # neutron sld 68 scaled_neutron_sld_real = SCALE * neutron_sld_real 69 scaled_neutron_sld_imag = SCALE * abs(neutron_sld_imag) 70 71 # xray sld 72 scaled_xray_sld_real = SCALE * xray_sld_real 73 scaled_xray_sld_imag = SCALE * abs(xray_sld_imag) 74 80 neutron_sld_real = SCALE * sld_real 81 neutron_sld_imag = SCALE * abs(sld_imag) 82 83 # Cu sld 84 cu_ka_sld_real = SCALE * cu_real 85 cu_ka_sld_imag = SCALE * abs(cu_imag) 86 87 # Mo sld 88 mo_ka_sld_real = SCALE * mo_real 89 mo_ka_sld_imag = SCALE * abs(mo_imag) 75 90 76 91 return SldResult( 77 molecular_formula, mass_density, 78 neutron_wavelength, scaled_neutron_sld_real, scaled_neutron_sld_imag, 79 xray_wavelength, scaled_xray_sld_real, scaled_xray_sld_imag, 92 molecular_formula, mass_density, wavelength, 93 neutron_sld_real, neutron_sld_imag, 94 cu_ka_sld_real, cu_ka_sld_imag, 95 mo_ka_sld_real, mo_ka_sld_imag, 80 96 neutron_inc_xs, neutron_abs_xs, neutron_length) 81 97 … … 96 112 MODEL.NEUTRON_SLD_REAL: self.ui.editNeutronSldReal, 97 113 MODEL.NEUTRON_SLD_IMAG: self.ui.editNeutronSldImag, 98 MODEL.XRAY_SLD_REAL: self.ui.editXraySldReal, 99 MODEL.XRAY_SLD_IMAG: self.ui.editXraySldImag, 114 MODEL.CU_KA_SLD_REAL: self.ui.editCuKaSldReal, 115 MODEL.CU_KA_SLD_IMAG: self.ui.editCuKaSldImag, 116 MODEL.MO_KA_SLD_REAL: self.ui.editMoKaSldReal, 117 MODEL.MO_KA_SLD_IMAG: self.ui.editMoKaSldImag, 100 118 MODEL.NEUTRON_INC_XS: self.ui.editNeutronIncXs, 101 119 MODEL.NEUTRON_ABS_XS: self.ui.editNeutronAbsXs, … … 113 131 rx = QtCore.QRegExp("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") 114 132 self.ui.editMassDensity.setValidator(QtGui.QRegExpValidator(rx, self.ui.editMassDensity)) 115 self.ui.editNeutronWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editNeutronWavelength)) 116 self.ui.editXrayWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editXrayWavelength)) 133 self.ui.editWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editWavelength)) 117 134 118 135 # signals 119 self.ui.helpButton.clicked.connect(self.displayHelp) 120 self.ui.closeButton.clicked.connect(self.closePanel) 121 self.ui.recalculateButton.clicked.connect(self.calculateSLD) 122 123 def calculateSLD(self): 124 self.recalculateSLD() 136 self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Reset).clicked.connect(self.modelReset) 137 self.ui.buttonBox.button(QtWidgets.QDialogButtonBox.Help).clicked.connect(self.displayHelp) 125 138 126 139 def setupModel(self): 127 140 self.model = QtGui.QStandardItemModel(self) 128 self.model.setItem(MODEL.MOLECULAR_FORMULA , QtGui.QStandardItem()) 129 self.model.setItem(MODEL.MASS_DENSITY , QtGui.QStandardItem()) 130 self.model.setItem(MODEL.NEUTRON_WAVELENGTH, QtGui.QStandardItem()) 131 self.model.setItem(MODEL.XRAY_WAVELENGTH , QtGui.QStandardItem()) 141 self.model.setItem(MODEL.MOLECULAR_FORMULA, QtGui.QStandardItem()) 142 self.model.setItem(MODEL.MASS_DENSITY , QtGui.QStandardItem()) 143 self.model.setItem(MODEL.WAVELENGTH , QtGui.QStandardItem()) 132 144 133 145 for key in list(self._getOutputs().keys()): … … 135 147 136 148 self.model.dataChanged.connect(self.dataChanged) 137 138 self.ui.editMassDensity.textEdited.connect(self.recalculateSLD)139 self.ui.editMolecularFormula.textEdited.connect(self.recalculateSLD)140 self.ui.editNeutronWavelength.textEdited.connect(self.recalculateSLD)141 self.ui.editXrayWavelength.textEdited.connect(self.recalculateSLD)142 149 143 150 self.modelReset() … … 147 154 self.mapper.setModel(self.model) 148 155 self.mapper.setOrientation(QtCore.Qt.Vertical) 149 self.mapper.addMapping(self.ui.editMolecularFormula , MODEL.MOLECULAR_FORMULA) 150 self.mapper.addMapping(self.ui.editMassDensity , MODEL.MASS_DENSITY) 151 self.mapper.addMapping(self.ui.editNeutronWavelength, MODEL.NEUTRON_WAVELENGTH) 152 self.mapper.addMapping(self.ui.editXrayWavelength , MODEL.XRAY_WAVELENGTH) 156 self.mapper.addMapping(self.ui.editMolecularFormula, MODEL.MOLECULAR_FORMULA) 157 self.mapper.addMapping(self.ui.editMassDensity , MODEL.MASS_DENSITY) 158 self.mapper.addMapping(self.ui.editWavelength , MODEL.WAVELENGTH) 153 159 154 160 for key, edit in self._getOutputs().items(): … … 160 166 update = False 161 167 for index in range(top.row(), bottom.row() + 1): 162 if (index == MODEL.MOLECULAR_FORMULA) or (index == MODEL.MASS_DENSITY) or (index == MODEL. NEUTRON_WAVELENGTH) or (index == MODEL.XRAY_WAVELENGTH):168 if (index == MODEL.MOLECULAR_FORMULA) or (index == MODEL.MASS_DENSITY) or (index == MODEL.WAVELENGTH): 163 169 update = True 164 170 165 # calcu lation171 # calcualtion 166 172 if update: 167 self.recalculateSLD() 168 169 def recalculateSLD(self): 170 formula = self.ui.editMolecularFormula.text() 171 density = self.ui.editMassDensity.text() 172 neutronWavelength = self.ui.editNeutronWavelength.text() 173 xrayWavelength = self.ui.editXrayWavelength.text() 174 175 if len(formula) > 0 and len(density) > 0 and len(neutronWavelength) > 0 and len(xrayWavelength) > 0: 176 try: 177 results = sldAlgorithm(str(formula), float(density), float(neutronWavelength), float(xrayWavelength)) 178 179 def format(value): 180 return ("%-5.3g" % value).strip() 181 182 self.model.item(MODEL.NEUTRON_SLD_REAL).setText(format(results.neutron_sld_real)) 183 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 184 185 self.model.item(MODEL.XRAY_SLD_REAL).setText(format(results.xray_sld_real)) 186 self.model.item(MODEL.XRAY_SLD_IMAG).setText(format(results.xray_sld_imag)) 187 188 self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) 189 self.model.item(MODEL.NEUTRON_ABS_XS).setText(format(results.neutron_abs_xs)) 190 self.model.item(MODEL.NEUTRON_LENGTH).setText(format(results.neutron_length)) 191 192 return 193 194 except Exception as e: 195 pass 196 197 for key in list(self._getOutputs().keys()): 198 self.model.item(key).setText("") 173 formula = self.model.item(MODEL.MOLECULAR_FORMULA).text() 174 density = self.model.item(MODEL.MASS_DENSITY).text() 175 wavelength = self.model.item(MODEL.WAVELENGTH).text() 176 if len(formula) > 0 and len(density) > 0 and len(wavelength) > 0: 177 try: 178 results = sldAlgorithm(str(formula), float(density), float(wavelength)) 179 180 def format(value): 181 return ("%-5.3g" % value).strip() 182 183 self.model.item(MODEL.NEUTRON_SLD_REAL).setText(format(results.neutron_sld_real)) 184 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 185 186 self.model.item(MODEL.CU_KA_SLD_REAL).setText(format(results.cu_ka_sld_real)) 187 self.model.item(MODEL.CU_KA_SLD_IMAG).setText(format(results.cu_ka_sld_imag)) 188 189 self.model.item(MODEL.MO_KA_SLD_REAL).setText(format(results.mo_ka_sld_real)) 190 self.model.item(MODEL.MO_KA_SLD_IMAG).setText(format(results.mo_ka_sld_imag)) 191 192 self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) 193 self.model.item(MODEL.NEUTRON_ABS_XS).setText(format(results.neutron_abs_xs)) 194 self.model.item(MODEL.NEUTRON_LENGTH).setText(format(results.neutron_length)) 195 196 return 197 198 except Exception as e: 199 pass 200 201 for key in list(self._getOutputs().keys()): 202 self.model.item(key).setText("") 199 203 200 204 def modelReset(self): 201 205 #self.model.beginResetModel() 202 206 try: 203 self.model.item(MODEL.MOLECULAR_FORMULA ).setText("H2O") 204 self.model.item(MODEL.MASS_DENSITY ).setText("1.0") 205 self.model.item(MODEL.NEUTRON_WAVELENGTH).setText("6.0") 206 self.model.item(MODEL.XRAY_WAVELENGTH ).setText("1.0") 207 self.recalculateSLD() 207 self.model.item(MODEL.MOLECULAR_FORMULA).setText("H2O") 208 self.model.item(MODEL.MASS_DENSITY ).setText("1") 209 self.model.item(MODEL.WAVELENGTH ).setText("6") 208 210 finally: 209 211 pass … … 215 217 216 218 217 def closePanel(self):218 """219 close the window containing this panel220 """221 self.close()222 -
src/sas/qtgui/Calculators/UI/SldPanel.ui
r5c0e717 rcd2cc745 7 7 <x>0</x> 8 8 <y>0</y> 9 <width>4 90</width>10 <height>4 90</height>9 <width>447</width> 10 <height>403</height> 11 11 </rect> 12 12 </property> … … 25 25 </property> 26 26 <layout class="QGridLayout" name="gridLayout_2"> 27 <item row="3" column="0">28 <spacer name="verticalSpacer">29 <property name="orientation">30 <enum>Qt::Vertical</enum>31 </property>32 <property name="sizeHint" stdset="0">33 <size>34 <width>20</width>35 <height>40</height>36 </size>37 </property>38 </spacer>39 </item>40 <item row="4" column="0">41 <widget class="QWidget" name="widget" native="true">42 <property name="minimumSize">43 <size>44 <width>466</width>45 <height>32</height>46 </size>47 </property>48 <widget class="QPushButton" name="recalculateButton">49 <property name="geometry">50 <rect>51 <x>0</x>52 <y>0</y>53 <width>114</width>54 <height>32</height>55 </rect>56 </property>57 <property name="text">58 <string>Recalculate</string>59 </property>60 </widget>61 <widget class="QPushButton" name="helpButton">62 <property name="geometry">63 <rect>64 <x>176</x>65 <y>0</y>66 <width>114</width>67 <height>32</height>68 </rect>69 </property>70 <property name="text">71 <string>Help</string>72 </property>73 </widget>74 <widget class="QPushButton" name="closeButton">75 <property name="geometry">76 <rect>77 <x>352</x>78 <y>0</y>79 <width>114</width>80 <height>32</height>81 </rect>82 </property>83 <property name="text">84 <string>Close</string>85 </property>86 </widget>87 </widget>88 </item>89 27 <item row="0" column="0"> 90 28 <widget class="QGroupBox" name="groupBoxInput"> … … 120 58 <widget class="QLineEdit" name="editMassDensity"/> 121 59 </item> 60 <item row="2" column="1"> 61 <widget class="QLineEdit" name="editWavelength"> 62 <property name="styleSheet"> 63 <string notr="true"/> 64 </property> 65 <property name="readOnly"> 66 <bool>false</bool> 67 </property> 68 </widget> 69 </item> 122 70 <item row="2" column="2"> 123 71 <widget class="QLabel" name="label_12"> … … 138 86 <widget class="QLabel" name="label_11"> 139 87 <property name="text"> 140 <string>Neutron Wavelength</string> 141 </property> 142 </widget> 143 </item> 144 <item row="2" column="1"> 145 <widget class="QLineEdit" name="editNeutronWavelength"> 146 <property name="styleSheet"> 147 <string notr="true"/> 148 </property> 149 <property name="readOnly"> 150 <bool>false</bool> 151 </property> 152 </widget> 153 </item> 154 <item row="3" column="1"> 155 <widget class="QLineEdit" name="editXrayWavelength"/> 156 </item> 157 <item row="3" column="0"> 158 <widget class="QLabel" name="label_13"> 159 <property name="text"> 160 <string>X-Ray Wavelength</string> 161 </property> 162 </widget> 163 </item> 164 <item row="3" column="2"> 165 <widget class="QLabel" name="label"> 166 <property name="text"> 167 <string>à 168 </string> 88 <string>Wavelength</string> 169 89 </property> 170 90 </widget> … … 179 99 </property> 180 100 <layout class="QGridLayout" name="gridLayoutOutput"> 101 <item row="0" column="0"> 102 <widget class="QLabel" name="label_17"> 103 <property name="text"> 104 <string>Neutron SLD</string> 105 </property> 106 </widget> 107 </item> 181 108 <item row="0" column="1"> 182 109 <widget class="QLineEdit" name="editNeutronSldReal"> 183 <property name="enabled"> 184 <bool>false</bool> 185 </property> 186 <property name="readOnly"> 187 <bool>true</bool> 188 </property> 189 </widget> 190 </item> 191 <item row="0" column="0"> 192 <widget class="QLabel" name="label_17"> 193 <property name="text"> 194 <string>Neutron SLD</string> 195 </property> 196 </widget> 197 </item> 198 <item row="5" column="0"> 199 <widget class="QLabel" name="label_3"> 200 <property name="text"> 201 <string>Neutron 1/e length</string> 202 </property> 203 </widget> 204 </item> 205 <item row="3" column="1"> 206 <widget class="QLineEdit" name="editNeutronIncXs"> 207 <property name="enabled"> 208 <bool>false</bool> 209 </property> 210 <property name="readOnly"> 211 <bool>true</bool> 212 </property> 213 </widget> 214 </item> 215 <item row="3" column="0"> 216 <widget class="QLabel" name="label_21"> 217 <property name="text"> 218 <string>Neutron Inc. Xs</string> 110 <property name="readOnly"> 111 <bool>true</bool> 219 112 </property> 220 113 </widget> … … 227 120 </widget> 228 121 </item> 122 <item row="0" column="3"> 123 <widget class="QLineEdit" name="editNeutronSldImag"> 124 <property name="readOnly"> 125 <bool>true</bool> 126 </property> 127 </widget> 128 </item> 129 <item row="0" column="4"> 130 <widget class="QLabel" name="label_5"> 131 <property name="text"> 132 <string>1/à 133 ²</string> 134 </property> 135 </widget> 136 </item> 137 <item row="1" column="0"> 138 <widget class="QLabel" name="label_19"> 139 <property name="text"> 140 <string>Cu Ka SLD</string> 141 </property> 142 </widget> 143 </item> 144 <item row="1" column="1"> 145 <widget class="QLineEdit" name="editCuKaSldReal"> 146 <property name="styleSheet"> 147 <string notr="true"/> 148 </property> 149 <property name="readOnly"> 150 <bool>true</bool> 151 </property> 152 </widget> 153 </item> 229 154 <item row="1" column="2"> 230 155 <widget class="QLabel" name="label_20"> … … 234 159 </widget> 235 160 </item> 236 <item row="0" column="3"> 237 <widget class="QLineEdit" name="editNeutronSldImag"> 238 <property name="enabled"> 239 <bool>false</bool> 240 </property> 241 <property name="readOnly"> 242 <bool>true</bool> 243 </property> 244 </widget> 245 </item> 246 <item row="5" column="2" colspan="2"> 247 <widget class="QLabel" name="label_4"> 248 <property name="text"> 249 <string>cm</string> 250 </property> 251 </widget> 252 </item> 253 <item row="5" column="1"> 254 <widget class="QLineEdit" name="editNeutronLength"> 255 <property name="enabled"> 256 <bool>false</bool> 257 </property> 258 <property name="readOnly"> 259 <bool>true</bool> 260 </property> 261 </widget> 262 </item> 263 <item row="4" column="2" colspan="2"> 264 <widget class="QLabel" name="label_24"> 265 <property name="text"> 266 <string>1/cm</string> 267 </property> 268 </widget> 269 </item> 270 <item row="4" column="1"> 271 <widget class="QLineEdit" name="editNeutronAbsXs"> 272 <property name="enabled"> 273 <bool>false</bool> 274 </property> 275 <property name="readOnly"> 276 <bool>true</bool> 277 </property> 278 </widget> 279 </item> 280 <item row="4" column="0"> 281 <widget class="QLabel" name="label_23"> 282 <property name="text"> 283 <string>Neutron Abs. Xs</string> 284 </property> 285 </widget> 286 </item> 287 <item row="3" column="2" colspan="2"> 288 <widget class="QLabel" name="label_22"> 289 <property name="text"> 290 <string>1/cm</string> 161 <item row="1" column="3"> 162 <widget class="QLineEdit" name="editCuKaSldImag"> 163 <property name="readOnly"> 164 <bool>true</bool> 291 165 </property> 292 166 </widget> … … 300 174 </widget> 301 175 </item> 302 <item row="1" column="0"> 303 <widget class="QLabel" name="label_19"> 304 <property name="text"> 305 <string>X-Ray SLD</string> 306 </property> 307 </widget> 308 </item> 309 <item row="0" column="4"> 310 <widget class="QLabel" name="label_5"> 176 <item row="2" column="0"> 177 <widget class="QLabel" name="label"> 178 <property name="text"> 179 <string>Mo Ka SLD</string> 180 </property> 181 </widget> 182 </item> 183 <item row="2" column="1"> 184 <widget class="QLineEdit" name="editMoKaSldReal"> 185 <property name="readOnly"> 186 <bool>true</bool> 187 </property> 188 </widget> 189 </item> 190 <item row="2" column="2"> 191 <widget class="QLabel" name="label_2"> 192 <property name="text"> 193 <string>-i</string> 194 </property> 195 </widget> 196 </item> 197 <item row="2" column="3"> 198 <widget class="QLineEdit" name="editMoKaSldImag"> 199 <property name="readOnly"> 200 <bool>true</bool> 201 </property> 202 </widget> 203 </item> 204 <item row="2" column="4"> 205 <widget class="QLabel" name="label_7"> 311 206 <property name="text"> 312 207 <string>1/à … … 315 210 </widget> 316 211 </item> 317 <item row=" 2" column="0" colspan="5">212 <item row="3" column="0" colspan="5"> 318 213 <widget class="QFrame" name="frame"> 319 214 <property name="minimumSize"> … … 337 232 </widget> 338 233 </item> 339 <item row="1" column="1"> 340 <widget class="QLineEdit" name="editXraySldReal"> 341 <property name="enabled"> 342 <bool>false</bool> 343 </property> 344 <property name="readOnly"> 345 <bool>true</bool> 346 </property> 347 </widget> 348 </item> 349 <item row="1" column="3"> 350 <widget class="QLineEdit" name="editXraySldImag"> 351 <property name="enabled"> 352 <bool>false</bool> 353 </property> 354 <property name="readOnly"> 355 <bool>true</bool> 234 <item row="4" column="0"> 235 <widget class="QLabel" name="label_21"> 236 <property name="text"> 237 <string>Neutron Inc. Xs</string> 238 </property> 239 </widget> 240 </item> 241 <item row="4" column="1"> 242 <widget class="QLineEdit" name="editNeutronIncXs"> 243 <property name="readOnly"> 244 <bool>true</bool> 245 </property> 246 </widget> 247 </item> 248 <item row="4" column="2" colspan="2"> 249 <widget class="QLabel" name="label_22"> 250 <property name="text"> 251 <string>1/cm</string> 252 </property> 253 </widget> 254 </item> 255 <item row="5" column="0"> 256 <widget class="QLabel" name="label_23"> 257 <property name="text"> 258 <string>Neutron Abs. Xs</string> 259 </property> 260 </widget> 261 </item> 262 <item row="5" column="1"> 263 <widget class="QLineEdit" name="editNeutronAbsXs"> 264 <property name="readOnly"> 265 <bool>true</bool> 266 </property> 267 </widget> 268 </item> 269 <item row="5" column="2" colspan="2"> 270 <widget class="QLabel" name="label_24"> 271 <property name="text"> 272 <string>1/cm</string> 273 </property> 274 </widget> 275 </item> 276 <item row="6" column="0"> 277 <widget class="QLabel" name="label_3"> 278 <property name="text"> 279 <string>Neutron 1/e length</string> 280 </property> 281 </widget> 282 </item> 283 <item row="6" column="1"> 284 <widget class="QLineEdit" name="editNeutronLength"> 285 <property name="readOnly"> 286 <bool>true</bool> 287 </property> 288 </widget> 289 </item> 290 <item row="6" column="2" colspan="2"> 291 <widget class="QLabel" name="label_4"> 292 <property name="text"> 293 <string>cm</string> 356 294 </property> 357 295 </widget> 358 296 </item> 359 297 </layout> 298 </widget> 299 </item> 300 <item row="2" column="0"> 301 <spacer name="verticalSpacer"> 302 <property name="orientation"> 303 <enum>Qt::Vertical</enum> 304 </property> 305 <property name="sizeHint" stdset="0"> 306 <size> 307 <width>20</width> 308 <height>40</height> 309 </size> 310 </property> 311 </spacer> 312 </item> 313 <item row="3" column="0"> 314 <widget class="QDialogButtonBox" name="buttonBox"> 315 <property name="orientation"> 316 <enum>Qt::Horizontal</enum> 317 </property> 318 <property name="standardButtons"> 319 <set>QDialogButtonBox::Close|QDialogButtonBox::Help|QDialogButtonBox::Reset</set> 320 </property> 321 <property name="centerButtons"> 322 <bool>true</bool> 323 </property> 360 324 </widget> 361 325 </item> … … 365 329 <tabstop>editMolecularFormula</tabstop> 366 330 <tabstop>editMassDensity</tabstop> 367 <tabstop>edit NeutronWavelength</tabstop>331 <tabstop>editWavelength</tabstop> 368 332 <tabstop>editNeutronSldReal</tabstop> 369 333 <tabstop>editNeutronSldImag</tabstop> 334 <tabstop>editCuKaSldReal</tabstop> 335 <tabstop>editCuKaSldImag</tabstop> 336 <tabstop>editMoKaSldReal</tabstop> 337 <tabstop>editMoKaSldImag</tabstop> 370 338 <tabstop>editNeutronIncXs</tabstop> 371 339 <tabstop>editNeutronAbsXs</tabstop> 372 340 <tabstop>editNeutronLength</tabstop> 341 <tabstop>buttonBox</tabstop> 373 342 </tabstops> 374 343 <resources/> 375 <connections/> 344 <connections> 345 <connection> 346 <sender>buttonBox</sender> 347 <signal>accepted()</signal> 348 <receiver>SldPanel</receiver> 349 <slot>accept()</slot> 350 <hints> 351 <hint type="sourcelabel"> 352 <x>248</x> 353 <y>254</y> 354 </hint> 355 <hint type="destinationlabel"> 356 <x>157</x> 357 <y>274</y> 358 </hint> 359 </hints> 360 </connection> 361 <connection> 362 <sender>buttonBox</sender> 363 <signal>rejected()</signal> 364 <receiver>SldPanel</receiver> 365 <slot>reject()</slot> 366 <hints> 367 <hint type="sourcelabel"> 368 <x>316</x> 369 <y>260</y> 370 </hint> 371 <hint type="destinationlabel"> 372 <x>286</x> 373 <y>274</y> 374 </hint> 375 </hints> 376 </connection> 377 </connections> 376 378 </ui> -
src/sas/qtgui/MainWindow/DataExplorer.py
r6b50296 ra24eacf 394 394 # Notify the GuiManager about the send request 395 395 self._perspective().setData(data_item=selected_items, is_batch=self.chkBatch.isChecked()) 396 397 def freezeCheckedData(self):398 """399 Convert checked results (fitted model, residuals) into separate dataset.400 """401 outer_index = -1402 theories_copied = 0403 orig_model_size = self.model.rowCount()404 while outer_index < orig_model_size:405 outer_index += 1406 outer_item = self.model.item(outer_index)407 if not outer_item:408 continue409 if not outer_item.isCheckable():410 continue411 # Look for checked inner items412 inner_index = -1413 while inner_index < outer_item.rowCount():414 inner_item = outer_item.child(inner_index)415 inner_index += 1416 if not inner_item:417 continue418 if not inner_item.isCheckable():419 continue420 if inner_item.checkState() != QtCore.Qt.Checked:421 continue422 self.model.beginResetModel()423 theories_copied += 1424 new_item = self.cloneTheory(inner_item)425 self.model.appendRow(new_item)426 self.model.endResetModel()427 428 freeze_msg = ""429 if theories_copied == 0:430 return431 elif theories_copied == 1:432 freeze_msg = "1 theory copied to a separate data set"433 elif theories_copied > 1:434 freeze_msg = "%i theories copied to separate data sets" % theories_copied435 else:436 freeze_msg = "Unexpected number of theories copied: %i" % theories_copied437 raise AttributeError(freeze_msg)438 self.communicator.statusBarUpdateSignal.emit(freeze_msg)439 396 440 397 def freezeTheory(self, event): -
src/sas/qtgui/MainWindow/GuiManager.py
r6b50296 raa1db44 438 438 self._workspace.actionImage_Viewer.triggered.connect(self.actionImage_Viewer) 439 439 self._workspace.actionOrientation_Viewer.triggered.connect(self.actionOrientation_Viewer) 440 self._workspace.actionFreeze_Theory.triggered.connect(self.actionFreeze_Theory)441 440 # Fitting 442 441 self._workspace.actionNew_Fit_Page.triggered.connect(self.actionNew_Fit_Page) … … 684 683 self._workspace.addDockWidget(Qt.RightDockWidgetArea, self.ipDockWidget) 685 684 686 def actionFreeze_Theory(self):687 """688 Convert a child index with data into a separate top level dataset689 """690 self.filesWidget.freezeCheckedData()691 692 685 def actionOrientation_Viewer(self): 693 686 """ -
src/sas/qtgui/MainWindow/UI/MainWindowUI.ui
r6b50296 raa1db44 64 64 <addaction name="actionReport"/> 65 65 <addaction name="actionReset"/> 66 <addaction name="separator"/>67 <addaction name="actionFreeze_Theory"/>68 66 </widget> 69 67 <widget class="QMenu" name="menuView"> … … 537 535 </property> 538 536 </action> 539 <action name="actionFreeze_Theory">540 <property name="text">541 <string>Freeze Theory</string>542 </property>543 </action>544 537 </widget> 545 538 <resources/> -
src/sas/qtgui/Perspectives/Fitting/FittingUtilities.py
rf6c19cf rff3b293 430 430 431 431 theory_name = str(current_data.name.split()[0]) 432 res _name = reference_data.filename if reference_data.filename else reference_data.name433 residuals.name = "Residuals for " + str(theory_name) + "[" + res_name+ "]"432 residuals.name = "Residuals for " + str(theory_name) + "[" + \ 433 str(reference_data.filename) + "]" 434 434 residuals.title = residuals.name 435 435 residuals.ytransform = 'y' -
src/sas/qtgui/Perspectives/Fitting/FittingWidget.py
r5aad7a5 r6dbff18 267 267 self.has_magnet_error_column = False 268 268 269 # If the widget generated theory item, save it270 self.theory_item = None271 272 269 # signal communicator 273 270 self.communicate = self.parent.communicate … … 392 389 # Tag along functionality 393 390 self.label.setText("Data loaded from: ") 394 if self.logic.data.filename: 395 self.lblFilename.setText(self.logic.data.filename) 396 else: 397 self.lblFilename.setText(self.logic.data.name) 391 self.lblFilename.setText(self.logic.data.filename) 398 392 self.updateQRange() 399 393 # Switch off Data2D control … … 958 952 model = self.cbModel.currentText() 959 953 960 # Assure the control is active 961 if not self.cbModel.isEnabled(): 962 return 963 # Empty combobox forced to be read 954 # empty combobox forced to be read 964 955 if not model: 965 956 return … … 1115 1106 self.disableModelCombo() 1116 1107 self.enableStructureCombo() 1117 # set the index to 01118 self.cbStructureFactor.setCurrentIndex(0)1119 self.model_parameters = None1120 1108 self._model_model.clear() 1121 1109 return … … 1142 1130 model_row = item.row() 1143 1131 name_index = self._poly_model.index(model_row, 0) 1144 parameter_name = str(name_index.data()) # "distribution of sld" etc.1145 if " istribution of" in parameter_name:1132 parameter_name = str(name_index.data()).lower() # "distribution of sld" etc. 1133 if "distribution of" in parameter_name: 1146 1134 # just the last word 1147 1135 parameter_name = parameter_name.rsplit()[-1] … … 2003 1991 """ 2004 1992 name = model_name 2005 kernel_module = None2006 1993 if self.cbCategory.currentText() == CATEGORY_CUSTOM: 2007 1994 # custom kernel load requires full path … … 2009 1996 try: 2010 1997 kernel_module = generate.load_kernel_module(name) 2011 except ModuleNotFoundError as ex: 2012 pass 2013 2014 if kernel_module is None: 2015 # mismatch between "name" attribute and actual filename. 2016 curr_model = self.models[model_name] 2017 name, _ = os.path.splitext(os.path.basename(curr_model.filename)) 2018 try: 2019 kernel_module = generate.load_kernel_module(name) 2020 except ModuleNotFoundError as ex: 2021 logging.error("Can't find the model "+ str(ex)) 2022 return 1998 except ModuleNotFoundError: 1999 # maybe it's a recategorised custom model? 2000 name = os.path.join(ModelUtilities.find_plugins_dir(), model_name+".py") 2001 # If this rises, it's a valid problem. 2002 kernel_module = generate.load_kernel_module(name) 2023 2003 2024 2004 if hasattr(kernel_module, 'parameters'): … … 2213 2193 name = self.nameFromData(fitted_data) 2214 2194 # Notify the GUI manager so it can create the theory model in DataExplorer 2215 self.theory_item = GuiUtils.createModelItemWithPlot(fitted_data, name=name)2216 self.communicate.updateTheoryFromPerspectiveSignal.emit( self.theory_item)2195 new_item = GuiUtils.createModelItemWithPlot(fitted_data, name=name) 2196 self.communicate.updateTheoryFromPerspectiveSignal.emit(new_item) 2217 2197 2218 2198 def nameFromData(self, fitted_data): … … 2304 2284 residuals = self.calculateResiduals(fitted_data) 2305 2285 self.model_data = fitted_data 2306 new_plots = [fitted_data] 2307 if residuals is not None: 2308 new_plots.append(residuals) 2286 2287 new_plots = [fitted_data, residuals] 2309 2288 2310 2289 # Create plots for intermediate product data … … 2324 2303 GuiUtils.deleteRedundantPlots(self.all_data[self.data_index], new_plots) 2325 2304 2326 # Update/generate plots2327 2305 for plot in new_plots: 2328 self.communicate.plotUpdateSignal.emit([plot]) 2306 if hasattr(plot, "id") and "esidual" in plot.id: 2307 # TODO: fix updates to residuals plot 2308 pass 2309 elif plot is not None: 2310 self.communicate.plotUpdateSignal.emit([plot]) 2329 2311 2330 2312 def complete2D(self, return_data): … … 2428 2410 self._poly_model.clear() 2429 2411 2430 parameters = self.model_parameters.form_volume_parameters2431 if self.is2D:2432 parameters += self.model_parameters.orientation_parameters2433 2434 2412 [self.setPolyModelParameters(i, param) for i, param in \ 2435 enumerate(parameters) if param.polydisperse] 2436 2413 enumerate(self.model_parameters.form_volume_parameters) if param.polydisperse] 2437 2414 FittingUtilities.addPolyHeadersToModel(self._poly_model) 2438 2415 … … 2854 2831 if self.all_data: 2855 2832 index = self.all_data[self.data_index] 2856 else:2857 index = self.theory_item2858 2833 report_logic = ReportPageLogic(self, 2859 2834 kernel_module=self.kernel_module, -
src/sas/qtgui/Perspectives/Fitting/OptionsWidget.py
rc0a3b22e re20870bc 127 127 Callback for running the mask editor 128 128 """ 129 if isinstance(self.logic.data, Data2D):130 self.parent.communicate.maskEditorSignal.emit(self.logic.data)129 self.parent.communicate.maskEditorSignal.emit(self.logic.data) 130 pass 131 131 132 132 def onRangeReset(self): … … 157 157 Enable/disable various UI elements based on data loaded 158 158 """ 159 is2Ddata = isinstance(self.logic.data, Data2D)160 159 self.boxWeighting.setEnabled(True) 161 self.cmdMaskEdit.setEnabled( is2Ddata)160 self.cmdMaskEdit.setEnabled(True) 162 161 # Switch off txtNpts related controls 163 162 self.txtNpts.setEnabled(False) -
src/sas/qtgui/Utilities/AddMultEditor.py
r287d356 raed0532 15 15 import re 16 16 import logging 17 import traceback18 19 17 import sas.qtgui.Utilities.GuiUtils as GuiUtils 20 18 from sasmodels.sasview_model import load_standard_models … … 204 202 self.cbOperator.currentText()) 205 203 206 try: 207 success = GuiUtils.checkModel(self.plugin_filename) 208 except Exception as ex: 209 # broad exception from sasmodels 210 msg = "Error building model: "+ str(ex) 211 logging.error(msg) 212 #print three last lines of the stack trace 213 # this will point out the exact line failing 214 last_lines = traceback.format_exc().split('\n')[-4:] 215 traceback_to_show = '\n'.join(last_lines) 216 logging.error(traceback_to_show) 217 218 # Set the status bar message 219 self.parent.communicate.statusBarUpdateSignal.emit("Model check failed") 220 return 204 success = GuiUtils.checkModel(self.plugin_filename) 221 205 222 206 if not success: -
src/sas/qtgui/Utilities/ReportDialog.py
rcb90b65 rce30949 73 73 # Use a sensible filename default 74 74 default_name = os.path.join(location, 'fit_report.pdf') 75 76 75 kwargs = { 77 76 'parent' : self, 78 77 'caption' : 'Save Report', 79 # don't use 'directory' in order to remember the previous user choice 80 #'directory': default_name, 78 'directory': default_name, 81 79 'filter' : 'PDF file (*.pdf);;HTML file (*.html);;Text file (*.txt)', 82 80 'options' : QtWidgets.QFileDialog.DontUseNativeDialog} … … 101 99 102 100 # Create files with charts 103 pictures = [] 104 if self.data_images is not None: 105 pictures = self.getPictures(basename) 101 pictures = self.getPictures(basename) 106 102 107 103 # self.data_html contains all images at the end of the report, in base64 form; -
src/sas/qtgui/Utilities/UnitTesting/ReportDialogTest.py
rcb90b65 r144fe21 158 158 159 159 self.assertTrue(logging.error.called) 160 #logging.error.assert_called_with("Error creating pdf")160 logging.error.assert_called_with("Error creating pdf: Failed") 161 161
Note: See TracChangeset
for help on using the changeset viewer.