Changeset bd8411d5 in sasview


Ignore:
Timestamp:
Apr 10, 2017 3:04:56 AM (7 years ago)
Author:
Tim Snow <tim.snow@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.2.2, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
fe09e9b
Parents:
8963a55
Message:

Implementation finished

Code the underpins the GUI created yesterday is now finished to give a
richer x-ray SLD calculator for users.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sas/sasgui/perspectives/calculator/sld_panel.py

    r8963a55 rbd8411d5  
    6161        self.base = base 
    6262        self.neutron_wavelength = WAVELENGTH 
    63         self.xray_wavelength = WAVELENGTH 
     63        self.xray_source_input = WAVELENGTH 
    6464        self.parent = parent 
    6565        #layout attribute 
     
    6969        self.density = "" 
    7070        self.neutron_wavelength_ctl = None 
    71         self.xray_wavelength_ctl = None 
     71        self.xray_source_input_ctl = None 
    7272        self.xray_cbox = None 
    7373        self.neutron_sld_real_ctl = None 
     
    114114        self.neutron_wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    115115        self.neutron_wavelength_ctl.SetValue(str(self.neutron_wavelength)) 
    116         xray_wavelength_txt = wx.StaticText(self, -1, 'X-ray wavelength') 
    117         self.xray_wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
    118         self.xray_wavelength_ctl.SetValue(str(self.xray_wavelength)) 
     116        xray_source_input_txt = wx.StaticText(self, -1, 'X-ray wavelength') 
     117        self.xray_source_input_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH, -1)) 
     118        self.xray_source_input_ctl.SetValue(str(self.xray_source_input)) 
    119119        neutron_unit_a_txt = wx.StaticText(self, -1, unit_a) 
    120120 
     
    153153        iy += 1 
    154154        ix = 0 
    155         sizer_input.Add(xray_wavelength_txt, (iy, ix), (1, 1), 
    156                              wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
    157         ix += 1 
    158         sizer_input.Add(self.xray_wavelength_ctl, (iy, ix), (1, 1), 
     155        sizer_input.Add(xray_source_input_txt, (iy, ix), (1, 1), 
     156                             wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     157        ix += 1 
     158        sizer_input.Add(self.xray_source_input_ctl, (iy, ix), (1, 1), 
    159159                            wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    160160        ix += 1 
     
    309309        fill the x-ray combobox with the sources 
    310310        """ 
    311         # source_list = ['Element', 'Energy (keV)', 'Wavelength (A)'] 
    312311        source_list = ['[A]', '[keV]', 'Element'] 
    313312        for source in source_list: 
     
    315314            self.xray_cbox.SetClientData(pos, str(source.strip())) 
    316315        self.xray_cbox.SetSelection(0) 
     316        self.xray_source = source_list[0] 
    317317 
    318318    def on_select_xray(self, event=None): 
     
    377377 
    378378        self.neutron_wavelength = self.neutron_wavelength_ctl.GetValue() 
    379         self.xray_wavelength = self.xray_wavelength_ctl.GetValue() 
     379        self.xray_source_input = self.xray_source_input_ctl.GetValue() 
    380380 
    381381        if str(self.neutron_wavelength).lstrip().rstrip() == "": 
     
    392392                msg += "Error for wavelength value :expect float" 
    393393 
    394         if str(self.xray_wavelength).lstrip().rstrip() == "": 
    395             self.xray_wavelength = WAVELENGTH 
    396             self.xray_wavelength_ctl.SetValue(str(WAVELENGTH)) 
    397             self.xray_wavelength_ctl.SetBackgroundColour(wx.WHITE) 
    398             self.xray_wavelength_ctl.Refresh() 
     394        if str(self.xray_source_input).lstrip().rstrip() == "": 
     395            self.xray_source_input = WAVELENGTH 
     396            self.xray_source_input_ctl.SetValue(str(WAVELENGTH)) 
     397            self.xray_source_input_ctl.SetBackgroundColour(wx.WHITE) 
     398            self.xray_source_input_ctl.Refresh() 
    399399            msg += "Default value for wavelength is 6.0" 
    400400        else: 
    401             if check_float(self.xray_wavelength_ctl): 
    402                 self.xray_wavelength = float(self.xray_wavelength) 
    403             else: 
    404                 flag = False 
    405                 msg += "Error for wavelength value :expect float" 
     401            if (self.xray_source == '[A]') or (self.xray_source == '[keV]'): 
     402                if check_float(self.xray_source_input_ctl): 
     403                    self.xray_source_input = float(self.xray_source_input) 
     404                else: 
     405                    flag = False 
     406                    msg += "Error for wavelength value :expect float" 
     407            elif (self.xray_source == 'Element'): 
     408                try: 
     409                    import periodictable 
     410                    exec("periodictable." + self.xray_source_input) 
     411                except AttributeError: 
     412                    flag = False 
     413                    msg += "X-ray element supplied isn't in the database" 
     414 
     415 
    406416 
    407417        self.compound = self.compound_ctl.GetValue().lstrip().rstrip() 
     
    438448        return xray_sld_from_atoms(atom, density=density, energy=energy) 
    439449 
    440  
    441450    def calculateSld(self, event): 
    442451        """ 
     
    460469                                   wavelength=self.neutron_wavelength) 
    461470            if self.xray_source == "[A]": 
    462                 # xray_real, xray_im = self.calculate_sld_helper(element=self.xray_wavelength, 
    463                 #                                      density=self.density, 
    464                 #                             molecule_formula=self.sld_formula) 
    465                 pass 
     471                energy = xray_energy(self.xray_source_input) 
     472                xray_real, xray_im = xray_sld_from_atoms(self.sld_formula.atoms, 
     473                                                         density=self.density, 
     474                                                         energy=energy) 
    466475            elif self.xray_source == "[keV]": 
    467                 # xray_real, xray_im = self.calculate_sld_helper(element=self.xray_wavelength, 
    468                 #                                      density=self.density, 
    469                 #                             molecule_formula=self.sld_formula) 
    470                 pass 
     476                xray_real, xray_im = xray_sld_from_atoms(self.sld_formula.atoms, 
     477                                                         density=self.density, 
     478                                                         energy=self.xray_source_input) 
    471479            elif self.xray_source == "Element": 
    472                 # xray_real, xray_im = self.calculate_sld_helper(element=self.xray_wavelength, 
    473                 #                                      density=self.density, 
    474                 #                             molecule_formula=self.sld_formula) 
    475                 pass 
     480                xray_real, xray_im = self.calculate_sld_helper(element=self.xray_source_input, 
     481                                                               density=self.density, 
     482                                                               molecule_formula=self.sld_formula) 
    476483            # set neutron sld values 
    477484            val = format_number(sld_real * _SCALE) 
     
    504511        self.neutron_sld_real_ctl.SetValue("") 
    505512        self.neutron_sld_im_ctl.SetValue("") 
    506         self.mo_ka_sld_real_ctl.SetValue("") 
    507         self.mo_ka_sld_im_ctl.SetValue("") 
    508         self.cu_ka_sld_real_ctl.SetValue("") 
    509         self.cu_ka_sld_im_ctl.SetValue("") 
     513        self.xray_sld_real_ctl.SetValue("") 
     514        self.xray_sld_im_ctl.SetValue("") 
    510515        self.neutron_abs_ctl.SetValue("") 
    511516        self.neutron_inc_ctl.SetValue("") 
Note: See TracChangeset for help on using the changeset viewer.