Changes in / [5d14851a:60e20d8] in sasview


Ignore:
Location:
src/sas/qtgui/Calculators
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/Calculators/SldPanel.py

    r82efbe9 r33c0561  
    3232) 
    3333 
    34 class NeutronSldResult(object): 
    35     def __init__(self, neutron_wavelength, neutron_sld_real, 
    36                  neutron_sld_imag, neutron_inc_xs, neutron_abs_xs, 
    37                  neutron_length): 
    38  
     34class 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 
    3942        self.neutron_wavelength = neutron_wavelength 
    4043        self.neutron_sld_real = neutron_sld_real 
    4144        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 
    4248        self.neutron_inc_xs = neutron_inc_xs 
    4349        self.neutron_abs_xs = neutron_abs_xs 
    4450        self.neutron_length = neutron_length 
    4551 
    46 class XraySldResult(object): 
    47     def __init__(self, xray_wavelength, xray_sld_real, xray_sld_imag): 
    48  
    49         self.xray_wavelength = xray_wavelength 
    50         self.xray_sld_real = xray_sld_real 
    51         self.xray_sld_imag = xray_sld_imag 
    52  
    53 def neutronSldAlgorithm(molecular_formula, mass_density, neutron_wavelength): 
     52def 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) 
    5458 
    5559    (neutron_sld_real, neutron_sld_imag, _), (_, neutron_abs_xs, neutron_inc_xs), neutron_length = \ 
     
    6569    scaled_neutron_sld_imag = SCALE * abs(neutron_sld_imag) 
    6670 
    67     return NeutronSldResult(neutron_wavelength, scaled_neutron_sld_real, 
    68                             scaled_neutron_sld_imag, neutron_inc_xs, 
    69                             neutron_abs_xs, neutron_length) 
    70  
    71 def xraySldAlgorithm(molecular_formula, mass_density, xray_wavelength): 
    72  
    73     xray_sld_real, xray_sld_imag = xray_sld( 
    74             compound=molecular_formula, 
    75             density=mass_density, 
    76             wavelength=xray_wavelength) 
    77  
    78     SCALE = 1e-6 
    79  
    8071    # xray sld 
    8172    scaled_xray_sld_real = SCALE * xray_sld_real 
     
    8374 
    8475 
    85     return XraySldResult(xray_wavelength, scaled_xray_sld_real, 
    86                          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) 
    8781 
    8882 
     
    182176        xrayWavelength = self.ui.editXrayWavelength.text() 
    183177 
    184         if not formula or not density: 
    185             return 
    186  
    187         def format(value): 
    188             return ("%-5.3g" % value).strip() 
    189  
    190         if neutronWavelength: 
    191             results = neutronSldAlgorithm(str(formula), float(density), float(neutronWavelength)) 
    192  
    193             self.model.item(MODEL.NEUTRON_SLD_REAL).setText(format(results.neutron_sld_real)) 
    194             self.model.item(MODEL.NEUTRON_SLD_IMAG).setText(format(results.neutron_sld_imag)) 
    195             self.model.item(MODEL.NEUTRON_INC_XS).setText(format(results.neutron_inc_xs)) 
    196             self.model.item(MODEL.NEUTRON_ABS_XS).setText(format(results.neutron_abs_xs)) 
    197             self.model.item(MODEL.NEUTRON_LENGTH).setText(format(results.neutron_length)) 
    198             self.model.item(MODEL.NEUTRON_LENGTH).setEnabled(True) 
    199             self.ui.editNeutronSldReal.setEnabled(True) 
    200             self.ui.editNeutronSldImag.setEnabled(True) 
    201             self.ui.editNeutronIncXs.setEnabled(True) 
    202             self.ui.editNeutronLength.setEnabled(True) 
    203             self.ui.editNeutronAbsXs.setEnabled(True) 
    204         else: 
    205             self.model.item(MODEL.NEUTRON_SLD_REAL).setText("") 
    206             self.model.item(MODEL.NEUTRON_SLD_IMAG).setText("") 
    207             self.model.item(MODEL.NEUTRON_INC_XS).setText("") 
    208             self.model.item(MODEL.NEUTRON_ABS_XS).setText("") 
    209             self.model.item(MODEL.NEUTRON_LENGTH).setText("") 
    210             self.ui.editNeutronSldReal.setEnabled(False) 
    211             self.ui.editNeutronSldImag.setEnabled(False) 
    212             self.ui.editNeutronIncXs.setEnabled(False) 
    213             self.ui.editNeutronLength.setEnabled(False) 
    214             self.ui.editNeutronAbsXs.setEnabled(False) 
    215  
    216         if xrayWavelength: 
    217             results = xraySldAlgorithm(str(formula), float(density), float(xrayWavelength)) 
    218  
    219             self.model.item(MODEL.XRAY_SLD_REAL).setText(format(results.xray_sld_real)) 
    220             self.model.item(MODEL.XRAY_SLD_IMAG).setText(format(results.xray_sld_imag)) 
    221             self.ui.editXraySldReal.setEnabled(True) 
    222             self.ui.editXraySldImag.setEnabled(True) 
    223         else: 
    224             self.model.item(MODEL.XRAY_SLD_REAL).setText("") 
    225             self.model.item(MODEL.XRAY_SLD_IMAG).setText("") 
    226             self.ui.editXraySldReal.setEnabled(False) 
    227             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("") 
    228202 
    229203    def modelReset(self): 
  • src/sas/qtgui/Calculators/UI/SldPanel.ui

    r82efbe9 r5c0e717  
    182182       <widget class="QLineEdit" name="editNeutronSldReal"> 
    183183        <property name="enabled"> 
    184          <bool>true</bool> 
     184         <bool>false</bool> 
    185185        </property> 
    186186        <property name="readOnly"> 
     
    206206       <widget class="QLineEdit" name="editNeutronIncXs"> 
    207207        <property name="enabled"> 
    208          <bool>true</bool> 
     208         <bool>false</bool> 
    209209        </property> 
    210210        <property name="readOnly"> 
     
    237237       <widget class="QLineEdit" name="editNeutronSldImag"> 
    238238        <property name="enabled"> 
    239          <bool>true</bool> 
     239         <bool>false</bool> 
    240240        </property> 
    241241        <property name="readOnly"> 
     
    254254       <widget class="QLineEdit" name="editNeutronLength"> 
    255255        <property name="enabled"> 
    256          <bool>true</bool> 
     256         <bool>false</bool> 
    257257        </property> 
    258258        <property name="readOnly"> 
     
    271271       <widget class="QLineEdit" name="editNeutronAbsXs"> 
    272272        <property name="enabled"> 
    273          <bool>true</bool> 
     273         <bool>false</bool> 
    274274        </property> 
    275275        <property name="readOnly"> 
     
    340340       <widget class="QLineEdit" name="editXraySldReal"> 
    341341        <property name="enabled"> 
    342          <bool>true</bool> 
     342         <bool>false</bool> 
    343343        </property> 
    344344        <property name="readOnly"> 
     
    350350       <widget class="QLineEdit" name="editXraySldImag"> 
    351351        <property name="enabled"> 
    352          <bool>true</bool> 
     352         <bool>false</bool> 
    353353        </property> 
    354354        <property name="readOnly"> 
Note: See TracChangeset for help on using the changeset viewer.