Changes in / [5123512:85503bc] in sasview
- Location:
- src/sas/qtgui/Calculators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Calculators/SldPanel.py
r9f3db13 r33c0561 1 1 # global 2 import numpy as np3 2 import logging 4 3 from PyQt5 import QtCore … … 33 32 ) 34 33 35 class NeutronSldResult(object): 36 def __init__(self, neutron_wavelength, neutron_sld_real, 37 neutron_sld_imag, neutron_inc_xs, neutron_abs_xs, 38 neutron_length): 39 34 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, 38 neutron_inc_xs, neutron_abs_xs, neutron_length): 39 40 self.molecular_formula = molecular_formula 41 self.mass_density = mass_density 40 42 self.neutron_wavelength = neutron_wavelength 41 43 self.neutron_sld_real = neutron_sld_real 42 44 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 43 48 self.neutron_inc_xs = neutron_inc_xs 44 49 self.neutron_abs_xs = neutron_abs_xs 45 50 self.neutron_length = neutron_length 46 51 47 class XraySldResult(object): 48 def __init__(self, xray_wavelength, xray_sld_real, xray_sld_imag): 49 50 self.xray_wavelength = xray_wavelength 51 self.xray_sld_real = xray_sld_real 52 self.xray_sld_imag = xray_sld_imag 53 54 def neutronSldAlgorithm(molecular_formula, mass_density, neutron_wavelength): 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, 56 density=mass_density, 57 wavelength=xray_wavelength) 55 58 56 59 (neutron_sld_real, neutron_sld_imag, _), (_, neutron_abs_xs, neutron_inc_xs), neutron_length = \ … … 66 69 scaled_neutron_sld_imag = SCALE * abs(neutron_sld_imag) 67 70 68 return NeutronSldResult(neutron_wavelength, scaled_neutron_sld_real,69 scaled_neutron_sld_imag, neutron_inc_xs,70 neutron_abs_xs, neutron_length)71 72 def xraySldAlgorithm(molecular_formula, mass_density, xray_wavelength):73 74 xray_sld_real, xray_sld_imag = xray_sld(75 compound=molecular_formula,76 density=mass_density,77 wavelength=xray_wavelength)78 79 SCALE = 1e-680 81 71 # xray sld 82 72 scaled_xray_sld_real = SCALE * xray_sld_real … … 84 74 85 75 86 return XraySldResult(xray_wavelength, scaled_xray_sld_real, 87 scaled_xray_sld_imag) 76 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, 80 neutron_inc_xs, neutron_abs_xs, neutron_length) 88 81 89 82 … … 121 114 #self.ui.editMolecularFormula.setValidator(GuiUtils.FormulaValidator(self.ui.editMolecularFormula)) 122 115 123 # No need for recalculate124 self.ui.recalculateButton.setVisible(False)125 126 116 rx = QtCore.QRegExp("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") 127 117 self.ui.editMassDensity.setValidator(QtGui.QRegExpValidator(rx, self.ui.editMassDensity)) … … 147 137 self.model.setItem(key, QtGui.QStandardItem()) 148 138 149 #self.model.dataChanged.connect(self.dataChanged)139 self.model.dataChanged.connect(self.dataChanged) 150 140 151 141 self.ui.editMassDensity.textChanged.connect(self.recalculateSLD) … … 186 176 xrayWavelength = self.ui.editXrayWavelength.text() 187 177 188 if not formula or not density: 189 return 190 191 def format(value): 192 return ("%-5.3g" % value).strip() 193 194 if neutronWavelength and float(neutronWavelength) > np.finfo(float).eps: 195 results = neutronSldAlgorithm(str(formula), float(density), float(neutronWavelength)) 196 197 self.model.item(MODEL.NEUTRON_SLD_REAL).setText(format(results.neutron_sld_real)) 198 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 199 self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) 200 self.model.item(MODEL.NEUTRON_ABS_XS).setText(format(results.neutron_abs_xs)) 201 self.model.item(MODEL.NEUTRON_LENGTH).setText(format(results.neutron_length)) 202 self.model.item(MODEL.NEUTRON_LENGTH).setEnabled(True) 203 self.ui.editNeutronSldReal.setEnabled(True) 204 self.ui.editNeutronSldImag.setEnabled(True) 205 self.ui.editNeutronIncXs.setEnabled(True) 206 self.ui.editNeutronLength.setEnabled(True) 207 self.ui.editNeutronAbsXs.setEnabled(True) 208 else: 209 self.model.item(MODEL.NEUTRON_SLD_REAL).setText("") 210 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText("") 211 self.model.item(MODEL.NEUTRON_INC_XS).setText("") 212 self.model.item(MODEL.NEUTRON_ABS_XS).setText("") 213 self.model.item(MODEL.NEUTRON_LENGTH).setText("") 214 self.ui.editNeutronSldReal.setEnabled(False) 215 self.ui.editNeutronSldImag.setEnabled(False) 216 self.ui.editNeutronIncXs.setEnabled(False) 217 self.ui.editNeutronLength.setEnabled(False) 218 self.ui.editNeutronAbsXs.setEnabled(False) 219 220 if xrayWavelength and float(xrayWavelength) > np.finfo(float).eps: 221 results = xraySldAlgorithm(str(formula), float(density), float(xrayWavelength)) 222 223 self.model.item(MODEL.XRAY_SLD_REAL).setText(format(results.xray_sld_real)) 224 self.model.item(MODEL.XRAY_SLD_IMAG).setText(format(results.xray_sld_imag)) 225 self.ui.editXraySldReal.setEnabled(True) 226 self.ui.editXraySldImag.setEnabled(True) 227 else: 228 self.model.item(MODEL.XRAY_SLD_REAL).setText("") 229 self.model.item(MODEL.XRAY_SLD_IMAG).setText("") 230 self.ui.editXraySldReal.setEnabled(False) 231 self.ui.editXraySldImag.setEnabled(False) 178 if len(formula) > 0 and len(density) > 0 and len(neutronWavelength) > 0 and len(xrayWavelength) > 0: 179 try: 180 results = sldAlgorithm(str(formula), float(density), float(neutronWavelength), float(xrayWavelength)) 181 182 def format(value): 183 return ("%-5.3g" % value).strip() 184 185 self.model.item(MODEL.NEUTRON_SLD_REAL).setText(format(results.neutron_sld_real)) 186 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 187 188 self.model.item(MODEL.XRAY_SLD_REAL).setText(format(results.xray_sld_real)) 189 self.model.item(MODEL.XRAY_SLD_IMAG).setText(format(results.xray_sld_imag)) 190 191 self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) 192 self.model.item(MODEL.NEUTRON_ABS_XS).setText(format(results.neutron_abs_xs)) 193 self.model.item(MODEL.NEUTRON_LENGTH).setText(format(results.neutron_length)) 194 195 return 196 197 except Exception as e: 198 pass 199 200 for key in list(self._getOutputs().keys()): 201 self.model.item(key).setText("") 232 202 233 203 def modelReset(self): -
src/sas/qtgui/Calculators/UI/SldPanel.ui
r9f3db13 r5c0e717 8 8 <y>0</y> 9 9 <width>490</width> 10 <height>4 46</height>10 <height>490</height> 11 11 </rect> 12 12 </property> … … 38 38 </spacer> 39 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 <item row="0" column="0"> 90 <widget class="QGroupBox" name="groupBoxInput"> 91 <property name="title"> 92 <string>Input</string> 93 </property> 94 <layout class="QGridLayout" name="gridLayoutInput"> 95 <item row="1" column="0"> 96 <widget class="QLabel" name="label_8"> 97 <property name="text"> 98 <string>Mass Density</string> 99 </property> 100 </widget> 101 </item> 102 <item row="1" column="2"> 103 <widget class="QLabel" name="label_16"> 104 <property name="text"> 105 <string>g/cm³</string> 106 </property> 107 </widget> 108 </item> 109 <item row="0" column="2"> 110 <widget class="QLabel" name="label_10"> 111 <property name="text"> 112 <string>e.g. H2O</string> 113 </property> 114 </widget> 115 </item> 116 <item row="0" column="1"> 117 <widget class="QLineEdit" name="editMolecularFormula"/> 118 </item> 119 <item row="1" column="1"> 120 <widget class="QLineEdit" name="editMassDensity"/> 121 </item> 122 <item row="2" column="2"> 123 <widget class="QLabel" name="label_12"> 124 <property name="text"> 125 <string>à 126 </string> 127 </property> 128 </widget> 129 </item> 130 <item row="0" column="0"> 131 <widget class="QLabel" name="label_9"> 132 <property name="text"> 133 <string>Molecular Formula</string> 134 </property> 135 </widget> 136 </item> 137 <item row="2" column="0"> 138 <widget class="QLabel" name="label_11"> 139 <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> 169 </property> 170 </widget> 171 </item> 172 </layout> 173 </widget> 174 </item> 40 175 <item row="1" column="0"> 41 176 <widget class="QGroupBox" name="groupBoxOutput"> … … 47 182 <widget class="QLineEdit" name="editNeutronSldReal"> 48 183 <property name="enabled"> 49 <bool> true</bool>184 <bool>false</bool> 50 185 </property> 51 186 <property name="readOnly"> … … 71 206 <widget class="QLineEdit" name="editNeutronIncXs"> 72 207 <property name="enabled"> 73 <bool> true</bool>208 <bool>false</bool> 74 209 </property> 75 210 <property name="readOnly"> … … 102 237 <widget class="QLineEdit" name="editNeutronSldImag"> 103 238 <property name="enabled"> 104 <bool> true</bool>239 <bool>false</bool> 105 240 </property> 106 241 <property name="readOnly"> … … 119 254 <widget class="QLineEdit" name="editNeutronLength"> 120 255 <property name="enabled"> 121 <bool> true</bool>256 <bool>false</bool> 122 257 </property> 123 258 <property name="readOnly"> … … 136 271 <widget class="QLineEdit" name="editNeutronAbsXs"> 137 272 <property name="enabled"> 138 <bool> true</bool>273 <bool>false</bool> 139 274 </property> 140 275 <property name="readOnly"> … … 205 340 <widget class="QLineEdit" name="editXraySldReal"> 206 341 <property name="enabled"> 207 <bool> true</bool>342 <bool>false</bool> 208 343 </property> 209 344 <property name="readOnly"> … … 215 350 <widget class="QLineEdit" name="editXraySldImag"> 216 351 <property name="enabled"> 217 <bool>true</bool> 218 </property> 219 <property name="readOnly"> 220 <bool>true</bool> 221 </property> 222 </widget> 223 </item> 224 </layout> 225 </widget> 226 </item> 227 <item row="0" column="0"> 228 <widget class="QGroupBox" name="groupBoxInput"> 229 <property name="title"> 230 <string>Input</string> 231 </property> 232 <layout class="QGridLayout" name="gridLayoutInput"> 233 <item row="1" column="0"> 234 <widget class="QLabel" name="label_8"> 235 <property name="text"> 236 <string>Mass Density</string> 237 </property> 238 </widget> 239 </item> 240 <item row="1" column="2"> 241 <widget class="QLabel" name="label_16"> 242 <property name="text"> 243 <string>g/cm³</string> 244 </property> 245 </widget> 246 </item> 247 <item row="0" column="2"> 248 <widget class="QLabel" name="label_10"> 249 <property name="text"> 250 <string>e.g. H2O</string> 251 </property> 252 </widget> 253 </item> 254 <item row="0" column="1"> 255 <widget class="QLineEdit" name="editMolecularFormula"/> 256 </item> 257 <item row="1" column="1"> 258 <widget class="QLineEdit" name="editMassDensity"/> 259 </item> 260 <item row="2" column="2"> 261 <widget class="QLabel" name="label_12"> 262 <property name="text"> 263 <string>à 264 </string> 265 </property> 266 </widget> 267 </item> 268 <item row="0" column="0"> 269 <widget class="QLabel" name="label_9"> 270 <property name="text"> 271 <string>Molecular Formula</string> 272 </property> 273 </widget> 274 </item> 275 <item row="2" column="0"> 276 <widget class="QLabel" name="label_11"> 277 <property name="text"> 278 <string>Neutron Wavelength</string> 279 </property> 280 </widget> 281 </item> 282 <item row="2" column="1"> 283 <widget class="QLineEdit" name="editNeutronWavelength"> 284 <property name="styleSheet"> 285 <string notr="true"/> 286 </property> 287 <property name="readOnly"> 288 <bool>false</bool> 289 </property> 290 </widget> 291 </item> 292 <item row="3" column="1"> 293 <widget class="QLineEdit" name="editXrayWavelength"/> 294 </item> 295 <item row="3" column="0"> 296 <widget class="QLabel" name="label_13"> 297 <property name="text"> 298 <string>X-Ray Wavelength</string> 299 </property> 300 </widget> 301 </item> 302 <item row="3" column="2"> 303 <widget class="QLabel" name="label"> 304 <property name="text"> 305 <string>à 306 </string> 307 </property> 308 </widget> 309 </item> 310 </layout> 311 </widget> 312 </item> 313 <item row="4" column="0"> 314 <widget class="QWidget" name="widget" native="true"> 315 <property name="minimumSize"> 316 <size> 317 <width>466</width> 318 <height>32</height> 319 </size> 320 </property> 321 <layout class="QGridLayout" name="gridLayout"> 322 <item row="0" column="0"> 323 <widget class="QPushButton" name="recalculateButton"> 324 <property name="enabled"> 325 <bool>true</bool> 326 </property> 327 <property name="text"> 328 <string>Recalculate</string> 329 </property> 330 </widget> 331 </item> 332 <item row="0" column="1"> 333 <spacer name="horizontalSpacer"> 334 <property name="orientation"> 335 <enum>Qt::Horizontal</enum> 336 </property> 337 <property name="sizeHint" stdset="0"> 338 <size> 339 <width>208</width> 340 <height>20</height> 341 </size> 342 </property> 343 </spacer> 344 </item> 345 <item row="0" column="2"> 346 <widget class="QPushButton" name="closeButton"> 347 <property name="text"> 348 <string>Close</string> 349 </property> 350 </widget> 351 </item> 352 <item row="0" column="3"> 353 <widget class="QPushButton" name="helpButton"> 354 <property name="text"> 355 <string>Help</string> 352 <bool>false</bool> 353 </property> 354 <property name="readOnly"> 355 <bool>true</bool> 356 356 </property> 357 357 </widget>
Note: See TracChangeset
for help on using the changeset viewer.