Changeset 66bfacf in sasview
- Timestamp:
- Dec 6, 2010 5:32:46 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:
- bdcc69e
- Parents:
- 82826c4
- Location:
- calculatorview
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
calculatorview/perspectives/calculator/sld_panel.py
r6996942 r66bfacf 68 68 self.neutron_inc_ctl = None 69 69 self.neutron_length_ctl = None 70 self.button_calculate = None 70 71 #Draw the panel 71 72 self._do_layout() … … 274 275 275 276 id = wx.NewId() 276 button_calculate = wx.Button(self, id, "Calculate")277 button_calculate.SetToolTipString("Calculate SLD.")277 self.button_calculate = wx.Button(self, id, "Calculate") 278 self.button_calculate.SetToolTipString("Calculate SLD.") 278 279 self.Bind(wx.EVT_BUTTON, self.calculateSld, id=id) 279 280 280 281 sizer_button.Add((250, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) 281 sizer_button.Add( button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 20)282 sizer_button.Add(self.button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 20) 282 283 sizer3.Add(sizer_button) 283 284 #---------layout---------------- … … 309 310 """Check validity user inputs""" 310 311 flag = True 311 312 msg = "" 312 313 if check_float(self.density_ctl): 313 314 self.density = float(self.density_ctl.GetValue()) 314 315 else: 315 316 flag = False 316 raise ValueError,"Error for Density value :expect float"317 msg += "Error for Density value :expect float" 317 318 318 319 self.wavelength = self.wavelength_ctl.GetValue() 319 320 if self.wavelength.lstrip().rstrip() == "": 320 321 self.wavelength = WAVELENGTH 322 self.wavelength_ctl.SetValue(str(WAVELENGTH)) 323 self.wavelength_ctl.SetBackgroundColour(wx.WHITE) 324 self.wavelength_ctl.Refresh() 325 msg += "Default value for wavelength is 6.0" 321 326 else: 322 327 if check_float(self.wavelength_ctl): … … 324 329 else: 325 330 flag = False 326 raise ValueError,"Error for wavelength value :expect float"331 msg += "Error for wavelength value :expect float" 327 332 328 333 self.compound = self.compound_ctl.GetValue().lstrip().rstrip() 329 334 if self.compound != "": 330 self.compound_ctl.SetBackgroundColour(wx.WHITE) 331 self.compound_ctl.Refresh() 335 try : 336 formula(self.compound) 337 self.compound_ctl.SetBackgroundColour(wx.WHITE) 338 self.compound_ctl.Refresh() 339 except: 340 self.compound_ctl.SetBackgroundColour("pink") 341 self.compound_ctl.Refresh() 342 flag = False 343 msg += "Enter correct formula" 332 344 else: 333 345 self.compound_ctl.SetBackgroundColour("pink") 334 346 self.compound_ctl.Refresh() 335 347 flag = False 336 raise ValueError,"Enter a formula"337 return flag 348 msg += "Enter a formula" 349 return flag, msg 338 350 339 351 def calculate_sld_helper(self, element, density, molecule_formula): … … 357 369 Calculate the neutron scattering density length of a molecule 358 370 """ 371 self.clear_outputs() 359 372 try: 360 373 #Check validity user inputs 361 if self.check_inputs(): 362 #get ready to compute 363 try: 364 self.sld_formula = formula(self.compound, 365 density=self.density) 366 except: 367 if self.base is not None: 368 msg = "SLD Calculator: %s" % (sys.exc_value) 369 wx.PostEvent(self.base, StatusEvent(status=msg)) 370 else: 371 raise 372 return 373 374 375 (sld_real, sld_im, _), (_, absorp, incoh), \ 376 length = neutron_scattering(compound=self.compound, 377 density=self.density, 378 wavelength=self.wavelength) 379 cu_real, cu_im = self.calculate_sld_helper(element="Cu", 380 density=self.density, 381 molecule_formula=self.sld_formula) 382 mo_real, mo_im = self.calculate_sld_helper(element="Mo", 383 density=self.density, 384 molecule_formula=self.sld_formula) 385 # set neutron sld values 386 val = format_number(sld_real * _SCALE) 387 self.neutron_sld_reel_ctl.SetValue(val) 388 val = format_number(math.fabs(sld_im) * _SCALE) 389 self.neutron_sld_im_ctl.SetValue(val) 390 # Compute the Cu SLD 391 self.cu_ka_sld_reel_ctl.SetValue(format_number(cu_real *_SCALE)) 392 val = format_number(math.fabs(cu_im )* _SCALE) 393 self.cu_ka_sld_im_ctl.SetValue(val) 394 # Compute the Mo SLD 395 self.mo_ka_sld_reel_ctl.SetValue(format_number(mo_real *_SCALE)) 396 val = format_number(math.fabs(mo_im)* _SCALE) 397 self.mo_ka_sld_im_ctl.SetValue(val) 398 # set incoherence and absorption 399 self.neutron_inc_ctl.SetValue(format_number(incoh)) 400 self.neutron_abs_ctl.SetValue(format_number(absorp)) 401 # Neutron length 402 self.neutron_length_ctl.SetValue(format_number(length)) 403 # display wavelength 404 self.wavelength_ctl.SetValue(str(self.wavelength)) 374 flag, msg = self.check_inputs() 375 if self.base is not None and msg.lstrip().rstrip() != "": 376 msg = "SLD Calculator: %s" % str(msg) 377 wx.PostEvent(self.base, StatusEvent(status=msg)) 378 if not flag: 379 return 380 #get ready to compute 381 self.sld_formula = formula(self.compound, 382 density=self.density) 383 (sld_real, sld_im, _), (_, absorp, incoh), \ 384 length = neutron_scattering(compound=self.compound, 385 density=self.density, 386 wavelength=self.wavelength) 387 cu_real, cu_im = self.calculate_sld_helper(element="Cu", 388 density=self.density, 389 molecule_formula=self.sld_formula) 390 mo_real, mo_im = self.calculate_sld_helper(element="Mo", 391 density=self.density, 392 molecule_formula=self.sld_formula) 393 # set neutron sld values 394 val = format_number(sld_real * _SCALE) 395 self.neutron_sld_reel_ctl.SetValue(val) 396 val = format_number(math.fabs(sld_im) * _SCALE) 397 self.neutron_sld_im_ctl.SetValue(val) 398 # Compute the Cu SLD 399 self.cu_ka_sld_reel_ctl.SetValue(format_number(cu_real *_SCALE)) 400 val = format_number(math.fabs(cu_im )* _SCALE) 401 self.cu_ka_sld_im_ctl.SetValue(val) 402 # Compute the Mo SLD 403 self.mo_ka_sld_reel_ctl.SetValue(format_number(mo_real *_SCALE)) 404 val = format_number(math.fabs(mo_im)* _SCALE) 405 self.mo_ka_sld_im_ctl.SetValue(val) 406 # set incoherence and absorption 407 self.neutron_inc_ctl.SetValue(format_number(incoh)) 408 self.neutron_abs_ctl.SetValue(format_number(absorp)) 409 # Neutron length 410 self.neutron_length_ctl.SetValue(format_number(length)) 411 # display wavelength 412 self.wavelength_ctl.SetValue(str(self.wavelength)) 405 413 except: 406 raise407 """408 414 if self.base is not None: 409 415 msg = "SLD Calculator: %s"%(sys.exc_value) 410 416 wx.PostEvent(self.base, StatusEvent(status=msg)) 411 else:412 raise413 return414 """415 417 if event is not None: 416 418 event.Skip() 417 419 420 def clear_outputs(self): 421 """ 422 Clear the outputs textctrl 423 """ 424 self.neutron_sld_reel_ctl.SetValue("") 425 self.neutron_sld_im_ctl.SetValue("") 426 self.mo_ka_sld_reel_ctl.SetValue("") 427 self.mo_ka_sld_im_ctl.SetValue("") 428 self.cu_ka_sld_reel_ctl.SetValue("") 429 self.cu_ka_sld_im_ctl.SetValue("") 430 self.neutron_abs_ctl.SetValue("") 431 self.neutron_inc_ctl.SetValue("") 432 self.neutron_length_ctl.SetValue("") 433 434 418 435 class SldWindow(wx.Frame): 419 436 """ -
calculatorview/test/utest_sld.py
r810f196 r66bfacf 45 45 #Compute incoherence , absorption, and incoherence 46 46 (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound, 47 self.density,self.wavelength)47 density=self.density, wavelength=self.wavelength) 48 48 cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density, 49 49 molecule_formula=self.sld_formula) … … 85 85 #Compute incoherence , absorption, and incoherence 86 86 (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound, 87 self.density,self.wavelength)87 density=self.density, wavelength=self.wavelength) 88 88 cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density, 89 89 molecule_formula=self.sld_formula) … … 125 125 #Compute incoherence , absorption, and incoherence 126 126 (sld_real,sld_im,sld_inc), (coh,abs,incoh), length = neutron_scattering(self.compound, 127 self.density,self.wavelength)127 density=self.density, wavelength=self.wavelength) 128 128 cu_reel, cu_im = calculate_xray_sld(element="Cu", density=self.density, 129 129 molecule_formula=self.sld_formula)
Note: See TracChangeset
for help on using the changeset viewer.