Changeset 810f196 in sasview for calculatorview/perspectives
- Timestamp:
- Jun 22, 2010 1:28:16 PM (14 years ago)
- 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.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 704a4df
- Parents:
- 3ad91de
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/perspectives/calculator/sld_panel.py
redb3a5d0 r810f196 9 9 from sans.guiframe.utils import format_number, check_float 10 10 from sans.guicomm.events import StatusEvent 11 from sans.calculator.sld_calculator import SldCalculator 12 11 12 # the calculator default value for wavelength is 6 13 import periodictable 14 from periodictable import formula 15 from periodictable.xsf import xray_energy, xray_sld_from_atoms 16 from periodictable.constants import avogadro_number 17 from periodictable.nsf import neutron_scattering 18 19 WAVELENGTH = 6.0 13 20 _BOX_WIDTH = 76 14 21 _STATICBOX_WIDTH = 350 … … 35 42 ## Flag to tell the AUI manager to put this panel in the center pane 36 43 CENTER_PANE = True 37 def __init__(self, parent, base=None, id =-1):44 def __init__(self, parent, base=None, id=-1): 38 45 wx.Panel.__init__(self, parent, id = id) 39 46 #Font size 40 47 self.SetWindowVariant(variant=FONT_VARIANT) 41 42 48 # Object that receive status event 43 49 self.base = base 44 self.calculator = SldCalculator() 45 self.wavelength = self.calculator.wavelength 46 50 self.wavelength = WAVELENGTH 51 #Draw the panel 47 52 self._do_layout() 48 53 self.SetAutoLayout(True) 49 54 self.Layout() 50 55 51 52 56 def _do_layout(self): 53 57 """ … … 146 150 self.neutron_inc_ctl.SetToolTipString("Neutron Inc. Xs") 147 151 neutron_inc_units_txt = wx.StaticText(self, -1, unit_cm1) 148 neutron_inc_txt.Hide() 149 self.neutron_inc_ctl.Hide() 150 neutron_inc_units_txt.Hide() 152 151 153 neutron_abs_txt = wx.StaticText(self, -1, 'Neutron Abs. Xs') 152 154 self.neutron_abs_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) … … 154 156 self.neutron_abs_ctl.SetToolTipString("Neutron Abs. Xs") 155 157 neutron_abs_units_txt = wx.StaticText(self, -1, unit_cm1) 156 neutron_abs_txt.Hide() 157 self.neutron_abs_ctl.Hide() 158 neutron_abs_units_txt.Hide() 158 159 159 neutron_length_txt = wx.StaticText(self, -1, 'Neutron 1/e length') 160 160 self.neutron_length_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) … … 162 162 self.neutron_length_ctl.SetToolTipString("Neutron 1/e length") 163 163 neutron_length_units_txt = wx.StaticText(self, -1, unit_cm) 164 neutron_length_txt.Hide() 165 self.neutron_length_ctl.Hide() 166 neutron_length_units_txt.Hide() 164 167 165 iy = 0 168 166 ix = 0 … … 263 261 self.SetSizer(vbox) 264 262 265 263 def calculate_xray_sld(self, element): 264 """ 265 Get an element and compute the corresponding SLD for a given formula 266 :param element: elements a string of existing atom 267 """ 268 myformula = formula(str(element)) 269 if len(myformula.atoms) != 1: 270 return 271 element = myformula.atoms.keys()[0] 272 energy = xray_energy(element.K_alpha) 273 274 self.sld_formula = formula(str(user_formula), density=self.density) 275 atom = self.sld_formula.atoms 276 return xray_sld_from_atoms(atom, density=self.density, energy= energy) 277 266 278 def check_inputs(self): 267 279 """Check validity user inputs""" … … 276 288 self.wavelength = self.wavelength_ctl.GetValue() 277 289 if self.wavelength.lstrip().rstrip() == "": 278 self.wavelength = self.calculator.wavelength290 self.wavelength = WAVELENGTH 279 291 else: 280 292 if check_float(self.wavelength_ctl): … … 282 294 else: 283 295 flag = False 284 raise ValueError,"Error for wavelen th value :expect float"296 raise ValueError,"Error for wavelength value :expect float" 285 297 286 self. formulata_text= self.compound_ctl.GetValue().lstrip().rstrip()287 if self. formulata_text!= "":298 self.compound = self.compound_ctl.GetValue().lstrip().rstrip() 299 if self.compound != "": 288 300 self.compound_ctl.SetBackgroundColour(wx.WHITE) 289 301 self.compound_ctl.Refresh() … … 295 307 return flag 296 308 309 def calculate_sld_helper(self, element, density, molecule_formula): 310 """ 311 Get an element and compute the corresponding SLD for a given formula 312 313 :param element: elements a string of existing atom 314 315 """ 316 element_formula = formula(str(element)) 317 if len(element_formula.atoms) != 1: 318 return 319 element = element_formula.atoms.keys()[0] 320 energy = xray_energy(element.K_alpha) 321 atom = molecule_formula.atoms 322 return xray_sld_from_atoms(atom, density=density, energy=energy) 323 324 297 325 def calculateSld(self, event): 298 326 """ … … 304 332 #get ready to compute 305 333 try: 306 self.calculator.set_value(self.formulata_text, 307 self.density, self.wavelength) 334 self.sld_formula = formula(self.compound, density=self.density) 308 335 except: 309 336 if self.base is not None: … … 314 341 return 315 342 343 344 (sld_real, sld_im, sld_inc), (coh,absorp,incoh), \ 345 length = neutron_scattering(self.compound, 346 self.density, self.wavelength) 347 Cu_reel, Cu_im = self.calculate_sld_helper(element="Cu", 348 density=self.density, 349 molecule_formula=self.sld_formula) 350 Mo_reel, Mo_im = self.calculate_sld_helper(element="Mo", 351 density=self.density, 352 molecule_formula=self.sld_formula) 353 # set neutron sld values 354 self.neutron_sld_reel_ctl.SetValue(format_number(sld_real * _SCALE)) 355 self.neutron_sld_im_ctl.SetValue(format_number(sld_im * _SCALE)) 316 356 # Compute the Cu SLD 317 Cu_reel, Cu_im = self.calculator.calculate_xray_sld( "Cu")318 357 self.cu_ka_sld_reel_ctl.SetValue(format_number(Cu_reel *_SCALE)) 319 358 self.cu_ka_sld_im_ctl.SetValue(format_number(Cu_im * _SCALE)) 320 321 359 # Compute the Mo SLD 322 Mo_reel, Mo_im = self.calculator.calculate_xray_sld( "Mo")323 360 self.mo_ka_sld_reel_ctl.SetValue(format_number(Mo_reel *_SCALE)) 324 361 self.mo_ka_sld_im_ctl.SetValue(format_number(Mo_im * _SCALE)) 325 326 sld_real, sld_im, inc = self.calculator.calculate_neutron_sld() 327 length = self.calculator.calculate_length() 328 # Neutron SLD 329 #need to be compute by element package 330 absorp = 1.0 331 length = 1.0 332 self.neutron_sld_reel_ctl.SetValue(format_number(sld_real * _SCALE)) 333 self.neutron_sld_im_ctl.SetValue(format_number(sld_im * _SCALE)) 334 self.neutron_inc_ctl.SetValue(format_number(inc)) 362 # set incoherence and absorption 363 self.neutron_inc_ctl.SetValue(format_number(incoh)) 335 364 self.neutron_abs_ctl.SetValue(format_number(absorp)) 336 365 # Neutron length … … 347 376 348 377 349 350 351 352 353 354 355 356 378 class SldWindow(wx.Frame): 357 379 def __init__(self, parent=None, id=1, title="SLD Calculator",base=None):
Note: See TracChangeset
for help on using the changeset viewer.