- Timestamp:
- Sep 5, 2018 8:13:45 AM (6 years ago)
- Branches:
- ESS_GUI, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- c3e83d3
- Parents:
- d738feb
- Location:
- src/sas/qtgui/Calculators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/qtgui/Calculators/SldPanel.py
rd738feb r5c0e717 6 6 7 7 from periodictable import formula as Formula 8 from periodictable.xsf import xray_energy, xray_sld _from_atoms8 from periodictable.xsf import xray_energy, xray_sld 9 9 from periodictable.nsf import neutron_scattering 10 10 … … 21 21 'MOLECULAR_FORMULA', 22 22 'MASS_DENSITY', 23 ' WAVELENGTH',23 'NEUTRON_WAVELENGTH', 24 24 'NEUTRON_SLD_REAL', 25 25 'NEUTRON_SLD_IMAG', 26 'CU_KA_SLD_REAL', 27 'CU_KA_SLD_IMAG', 28 'MO_KA_SLD_REAL', 29 'MO_KA_SLD_IMAG', 26 'XRAY_WAVELENGTH', 27 'XRAY_SLD_REAL', 28 'XRAY_SLD_IMAG', 30 29 'NEUTRON_INC_XS', 31 30 'NEUTRON_ABS_XS', … … 34 33 35 34 class SldResult(object): 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, 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, 40 38 neutron_inc_xs, neutron_abs_xs, neutron_length): 41 39 42 40 self.molecular_formula = molecular_formula 43 41 self.mass_density = mass_density 44 self. wavelength =wavelength42 self.neutron_wavelength = neutron_wavelength 45 43 self.neutron_sld_real = neutron_sld_real 46 44 self.neutron_sld_imag = neutron_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 45 self.xray_wavelength = xray_wavelength 46 self.xray_sld_real = xray_sld_real 47 self.xray_sld_imag = xray_sld_imag 51 48 self.neutron_inc_xs = neutron_inc_xs 52 49 self.neutron_abs_xs = neutron_abs_xs 53 50 self.neutron_length = neutron_length 54 51 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, 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, 65 56 density=mass_density, 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 = \ 57 wavelength=xray_wavelength) 58 59 (neutron_sld_real, neutron_sld_imag, _), (_, neutron_abs_xs, neutron_inc_xs), neutron_length = \ 72 60 neutron_scattering( 73 61 compound=molecular_formula, 74 62 density=mass_density, 75 wavelength= wavelength)63 wavelength=neutron_wavelength) 76 64 77 65 SCALE = 1e-6 78 66 79 67 # neutron sld 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) 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 90 75 91 76 return SldResult( 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, 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, 96 80 neutron_inc_xs, neutron_abs_xs, neutron_length) 97 81 … … 112 96 MODEL.NEUTRON_SLD_REAL: self.ui.editNeutronSldReal, 113 97 MODEL.NEUTRON_SLD_IMAG: self.ui.editNeutronSldImag, 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, 98 MODEL.XRAY_SLD_REAL: self.ui.editXraySldReal, 99 MODEL.XRAY_SLD_IMAG: self.ui.editXraySldImag, 118 100 MODEL.NEUTRON_INC_XS: self.ui.editNeutronIncXs, 119 101 MODEL.NEUTRON_ABS_XS: self.ui.editNeutronAbsXs, … … 131 113 rx = QtCore.QRegExp("[+\-]?(?:0|[1-9]\d*)(?:\.\d*)?(?:[eE][+\-]?\d+)?") 132 114 self.ui.editMassDensity.setValidator(QtGui.QRegExpValidator(rx, self.ui.editMassDensity)) 133 self.ui.editWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editWavelength)) 115 self.ui.editNeutronWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editNeutronWavelength)) 116 self.ui.editXrayWavelength.setValidator(QtGui.QRegExpValidator(rx, self.ui.editXrayWavelength)) 134 117 135 118 # signals … … 143 126 def setupModel(self): 144 127 self.model = QtGui.QStandardItemModel(self) 145 self.model.setItem(MODEL.MOLECULAR_FORMULA, QtGui.QStandardItem()) 146 self.model.setItem(MODEL.MASS_DENSITY , QtGui.QStandardItem()) 147 self.model.setItem(MODEL.WAVELENGTH , QtGui.QStandardItem()) 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()) 148 132 149 133 for key in list(self._getOutputs().keys()): … … 151 135 152 136 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) 153 142 154 143 self.modelReset() … … 158 147 self.mapper.setModel(self.model) 159 148 self.mapper.setOrientation(QtCore.Qt.Vertical) 160 self.mapper.addMapping(self.ui.editMolecularFormula, MODEL.MOLECULAR_FORMULA) 161 self.mapper.addMapping(self.ui.editMassDensity , MODEL.MASS_DENSITY) 162 self.mapper.addMapping(self.ui.editWavelength , MODEL.WAVELENGTH) 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) 163 153 164 154 for key, edit in self._getOutputs().items(): … … 170 160 update = False 171 161 for index in range(top.row(), bottom.row() + 1): 172 if (index == MODEL.MOLECULAR_FORMULA) or (index == MODEL.MASS_DENSITY) or (index == MODEL. WAVELENGTH):162 if (index == MODEL.MOLECULAR_FORMULA) or (index == MODEL.MASS_DENSITY) or (index == MODEL.NEUTRON_WAVELENGTH) or (index == MODEL.XRAY_WAVELENGTH): 173 163 update = True 174 164 … … 178 168 179 169 def recalculateSLD(self): 180 formula = self.model.item(MODEL.MOLECULAR_FORMULA).text() 181 density = self.model.item(MODEL.MASS_DENSITY).text() 182 wavelength = self.model.item(MODEL.WAVELENGTH).text() 183 if len(formula) > 0 and len(density) > 0 and len(wavelength) > 0: 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: 184 176 try: 185 results = sldAlgorithm(str(formula), float(density), float( wavelength))177 results = sldAlgorithm(str(formula), float(density), float(neutronWavelength), float(xrayWavelength)) 186 178 187 179 def format(value): … … 191 183 self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 192 184 193 self.model.item(MODEL.CU_KA_SLD_REAL).setText(format(results.cu_ka_sld_real)) 194 self.model.item(MODEL.CU_KA_SLD_IMAG).setText(format(results.cu_ka_sld_imag)) 195 196 self.model.item(MODEL.MO_KA_SLD_REAL).setText(format(results.mo_ka_sld_real)) 197 self.model.item(MODEL.MO_KA_SLD_IMAG).setText(format(results.mo_ka_sld_imag)) 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)) 198 187 199 188 self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) … … 212 201 #self.model.beginResetModel() 213 202 try: 214 self.model.item(MODEL.MOLECULAR_FORMULA).setText("H2O") 215 self.model.item(MODEL.MASS_DENSITY ).setText("1") 216 self.model.item(MODEL.WAVELENGTH ).setText("6") 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() 217 208 finally: 218 209 pass -
src/sas/qtgui/Calculators/UI/SldPanel.ui
rd738feb r5c0e717 7 7 <x>0</x> 8 8 <y>0</y> 9 <width>4 87</width>10 <height>4 88</height>9 <width>490</width> 10 <height>490</height> 11 11 </rect> 12 12 </property> … … 120 120 <widget class="QLineEdit" name="editMassDensity"/> 121 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> 122 144 <item row="2" column="1"> 123 <widget class="QLineEdit" name="edit Wavelength">145 <widget class="QLineEdit" name="editNeutronWavelength"> 124 146 <property name="styleSheet"> 125 147 <string notr="true"/> … … 130 152 </widget> 131 153 </item> 132 <item row="2" column="2"> 133 <widget class="QLabel" name="label_12"> 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"> 134 166 <property name="text"> 135 167 <string>à 136 168 </string> 137 </property>138 </widget>139 </item>140 <item row="0" column="0">141 <widget class="QLabel" name="label_9">142 <property name="text">143 <string>Molecular Formula</string>144 </property>145 </widget>146 </item>147 <item row="2" column="0">148 <widget class="QLabel" name="label_11">149 <property name="text">150 <string>Wavelength</string>151 169 </property> 152 170 </widget> … … 161 179 </property> 162 180 <layout class="QGridLayout" name="gridLayoutOutput"> 181 <item row="0" column="1"> 182 <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> 163 191 <item row="0" column="0"> 164 192 <widget class="QLabel" name="label_17"> … … 168 196 </widget> 169 197 </item> 170 <item row="0" column="1"> 171 <widget class="QLineEdit" name="editNeutronSldReal"> 172 <property name="readOnly"> 173 <bool>true</bool> 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> 174 219 </property> 175 220 </widget> … … 182 227 </widget> 183 228 </item> 229 <item row="1" column="2"> 230 <widget class="QLabel" name="label_20"> 231 <property name="text"> 232 <string>-i</string> 233 </property> 234 </widget> 235 </item> 184 236 <item row="0" column="3"> 185 237 <widget class="QLineEdit" name="editNeutronSldImag"> 186 <property name="readOnly"> 187 <bool>true</bool> 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> 291 </property> 292 </widget> 293 </item> 294 <item row="1" column="4"> 295 <widget class="QLabel" name="label_6"> 296 <property name="text"> 297 <string>1/à 298 ²</string> 299 </property> 300 </widget> 301 </item> 302 <item row="1" column="0"> 303 <widget class="QLabel" name="label_19"> 304 <property name="text"> 305 <string>X-Ray SLD</string> 188 306 </property> 189 307 </widget> … … 197 315 </widget> 198 316 </item> 199 <item row="1" column="0"> 200 <widget class="QLabel" name="label_19"> 201 <property name="text"> 202 <string>Cu Ka SLD</string> 203 </property> 204 </widget> 205 </item> 206 <item row="1" column="1"> 207 <widget class="QLineEdit" name="editCuKaSldReal"> 208 <property name="styleSheet"> 209 <string notr="true"/> 210 </property> 211 <property name="readOnly"> 212 <bool>true</bool> 213 </property> 214 </widget> 215 </item> 216 <item row="1" column="2"> 217 <widget class="QLabel" name="label_20"> 218 <property name="text"> 219 <string>-i</string> 220 </property> 221 </widget> 222 </item> 223 <item row="1" column="3"> 224 <widget class="QLineEdit" name="editCuKaSldImag"> 225 <property name="readOnly"> 226 <bool>true</bool> 227 </property> 228 </widget> 229 </item> 230 <item row="1" column="4"> 231 <widget class="QLabel" name="label_6"> 232 <property name="text"> 233 <string>1/à 234 ²</string> 235 </property> 236 </widget> 237 </item> 238 <item row="2" column="0"> 239 <widget class="QLabel" name="label"> 240 <property name="text"> 241 <string>Mo Ka SLD</string> 242 </property> 243 </widget> 244 </item> 245 <item row="2" column="1"> 246 <widget class="QLineEdit" name="editMoKaSldReal"> 247 <property name="readOnly"> 248 <bool>true</bool> 249 </property> 250 </widget> 251 </item> 252 <item row="2" column="2"> 253 <widget class="QLabel" name="label_2"> 254 <property name="text"> 255 <string>-i</string> 256 </property> 257 </widget> 258 </item> 259 <item row="2" column="3"> 260 <widget class="QLineEdit" name="editMoKaSldImag"> 261 <property name="readOnly"> 262 <bool>true</bool> 263 </property> 264 </widget> 265 </item> 266 <item row="2" column="4"> 267 <widget class="QLabel" name="label_7"> 268 <property name="text"> 269 <string>1/à 270 ²</string> 271 </property> 272 </widget> 273 </item> 274 <item row="3" column="0" colspan="5"> 317 <item row="2" column="0" colspan="5"> 275 318 <widget class="QFrame" name="frame"> 276 319 <property name="minimumSize"> … … 294 337 </widget> 295 338 </item> 296 <item row="4" column="0"> 297 <widget class="QLabel" name="label_21"> 298 <property name="text"> 299 <string>Neutron Inc. Xs</string> 300 </property> 301 </widget> 302 </item> 303 <item row="4" column="1"> 304 <widget class="QLineEdit" name="editNeutronIncXs"> 305 <property name="readOnly"> 306 <bool>true</bool> 307 </property> 308 </widget> 309 </item> 310 <item row="4" column="2" colspan="2"> 311 <widget class="QLabel" name="label_22"> 312 <property name="text"> 313 <string>1/cm</string> 314 </property> 315 </widget> 316 </item> 317 <item row="5" column="0"> 318 <widget class="QLabel" name="label_23"> 319 <property name="text"> 320 <string>Neutron Abs. Xs</string> 321 </property> 322 </widget> 323 </item> 324 <item row="5" column="1"> 325 <widget class="QLineEdit" name="editNeutronAbsXs"> 326 <property name="readOnly"> 327 <bool>true</bool> 328 </property> 329 </widget> 330 </item> 331 <item row="5" column="2" colspan="2"> 332 <widget class="QLabel" name="label_24"> 333 <property name="text"> 334 <string>1/cm</string> 335 </property> 336 </widget> 337 </item> 338 <item row="6" column="0"> 339 <widget class="QLabel" name="label_3"> 340 <property name="text"> 341 <string>Neutron 1/e length</string> 342 </property> 343 </widget> 344 </item> 345 <item row="6" column="1"> 346 <widget class="QLineEdit" name="editNeutronLength"> 347 <property name="readOnly"> 348 <bool>true</bool> 349 </property> 350 </widget> 351 </item> 352 <item row="6" column="2" colspan="2"> 353 <widget class="QLabel" name="label_4"> 354 <property name="text"> 355 <string>cm</string> 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> 356 356 </property> 357 357 </widget> … … 365 365 <tabstop>editMolecularFormula</tabstop> 366 366 <tabstop>editMassDensity</tabstop> 367 <tabstop>edit Wavelength</tabstop>367 <tabstop>editNeutronWavelength</tabstop> 368 368 <tabstop>editNeutronSldReal</tabstop> 369 369 <tabstop>editNeutronSldImag</tabstop> 370 <tabstop>editCuKaSldReal</tabstop>371 <tabstop>editCuKaSldImag</tabstop>372 <tabstop>editMoKaSldReal</tabstop>373 <tabstop>editMoKaSldImag</tabstop>374 370 <tabstop>editNeutronIncXs</tabstop> 375 371 <tabstop>editNeutronAbsXs</tabstop>
Note: See TracChangeset
for help on using the changeset viewer.