Changeset a1b2471 in sasview
- Timestamp:
- Sep 21, 2010 5:44:24 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:
- db08737
- Parents:
- 60c320b
- Files:
-
- 1 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
sansmodels/src/sans/models/CoreMultiShellModel.py
r4523b68 ra1b2471 129 129 except: pass 130 130 131 131 def getProfile(self): 132 """ 133 Get SLD profile 134 135 : return: (r, beta) where r is a list of radius of the transition points 136 beta is a list of the corresponding SLD values 137 : Note: This works only for func_shell# = 2. 138 """ 139 r = [] 140 beta = [] 141 # for core at r=0 142 r.append(0) 143 beta.append(self.params['sld_core']) 144 # for core at r=rad_core 145 r.append(self.params['rad_core']) 146 beta.append(self.params['sld_core']) 147 148 # for shells 149 for n in range(1,self.n_shells+1): 150 # Left side of each shells 151 r0 = r[len(r)-1] 152 r.append(r0) 153 exec "beta.append(self.params['sld_shell%s'% str(n)])" 154 155 # Right side of each shells 156 exec "r0 += self.params['thick_shell%s'% str(n)]" 157 r.append(r0) 158 exec "beta.append(self.params['sld_shell%s'% str(n)])" 159 160 # for solvent 161 r0 = r[len(r)-1] 162 r.append(r0) 163 beta.append(self.params['sld_solv']) 164 r_solv = 5*r0/4 165 r.append(r_solv) 166 beta.append(self.params['sld_solv']) 167 168 return r, beta 169 132 170 def setParam(self, name, value): 133 171 """ -
sansmodels/src/sans/models/MultiplicationModel.py
r06c7fcc ra1b2471 82 82 ##set dispersion only from p_model 83 83 for name , value in self.p_model.dispersion.iteritems(): 84 self.dispersion[name]= value 85 84 self.dispersion[name]= value 85 86 def getProfile(self): 87 """ 88 Get SLD profile of p_model if exists 89 90 : return: (r, beta) where r is a list of radius of the transition points 91 beta is a list of the corresponding SLD values 92 : Note: This works only for func_shell# = 2 (exp function). 93 """ 94 try: 95 x,y = self.p_model.getProfile() 96 except: 97 x = None 98 y = None 99 100 return x, y 101 86 102 def _set_params(self): 87 103 """ -
sansmodels/src/sans/models/SphereExpShellModel.py
re096270 ra1b2471 42 42 for item in self.model.orientation_params: 43 43 self.orientation_params.append(item) 44 44 self.getProfile() 45 45 def _clone(self, obj): 46 46 """ … … 133 133 self.model.setParam(key, value) 134 134 except: pass 135 136 135 def getProfile(self): 136 """ 137 Get SLD profile 138 139 : return: (r, beta) where r is a list of radius of the transition points 140 beta is a list of the corresponding SLD values 141 : Note: This works only for func_shell# = 2. 142 """ 143 # max_pts for each shells 144 max_pts = 10 145 r = [] 146 beta = [] 147 # for core at r=0 148 r.append(0) 149 beta.append(self.params['sld_core']) 150 # for core at r=rad_core 151 r.append(self.params['rad_core']) 152 beta.append(self.params['sld_core']) 153 154 # for shells 155 for n in range(1,self.n_shells+1): 156 # Left side of each shells 157 r0 = r[len(r)-1] 158 r.append(r0) 159 exec "beta.append(self.params['sld_in_shell%s'% str(n)])" 160 161 exec "A = self.params['A_shell%s'% str(n)]" 162 if A ==0: 163 # Right side of each shells 164 exec "r0 += self.params['thick_shell%s'% str(n)]" 165 r.append(r0) 166 exec "beta.append(self.params['sld_in_shell%s'% str(n)])" 167 else: 168 from math import exp 169 rn = r0 170 for n_sub in range(0,max_pts): 171 # Right side of each sub_shells 172 exec "rn += self.params['thick_shell%s'% str(n)]/10.0" 173 r.append(rn) 174 exec "slope = (self.params['sld_out_shell%s'% str(n)] \ 175 -self.params['sld_in_shell%s'% str(n)]) \ 176 /(exp(self.params['A_shell%s'% str(n)])-1)" 177 exec "const = (self.params['sld_in_shell%s'% str(n)]-slope)" 178 exec "beta_n = slope*exp((self.params['A_shell%s'% str(n)]*(rn-r0) \ 179 /self.params['thick_shell%s'% str(n)])) + const" 180 beta.append(beta_n) 181 182 # for solvent 183 r0 = r[len(r)-1] 184 r.append(r0) 185 beta.append(self.params['sld_solv']) 186 r_solv = 5*r0/4 187 r.append(r_solv) 188 beta.append(self.params['sld_solv']) 189 190 return r, beta 191 137 192 def setParam(self, name, value): 138 193 """ -
sansmodels/src/sans/models/c_extensions/onion.c
re096270 ra1b2471 41 41 fun_type[n+1] = 0; 42 42 43 double bes,fun,alpha,f,vol, qr,r,contr,f2;43 double bes,fun,alpha,f,vol,vol_pre,vol_sub,qr,r,contr,f2; 44 44 double sign; 45 45 double pi; … … 48 48 f = 0.0; 49 49 r = 0.0; 50 vol = 0.0; 51 vol_pre = 0.0; 52 vol_sub = 0.0; 50 53 double r0 = 0.0; 51 54 … … 58 61 A[i] = 0.0; 59 62 } 63 vol_pre = vol; 60 64 switch(fun_type[i]){ 61 65 case 2 : … … 103 107 104 108 vol = 4.0 * pi / 3.0 * r * r * r; 109 if (j == 1 && fabs(sld_in[i]-sld_solv) < 1e-04*fabs(sld_solv) && A[i]==0.0){ 110 vol_sub += (vol_pre - vol); 111 } 105 112 f += vol * (contr * (fun) + (sld_in[i]-slope[i]) * bes); 106 113 } … … 141 148 } 142 149 vol = 4.0 * pi / 3.0 * r * r * r; 150 if (j == 1 && fabs(sld_in[i]-sld_solv) < 1e-04*fabs(sld_solv) && fun_type[i]==0){ 151 vol_sub += (vol_pre - vol); 152 } 143 153 f += vol * (bes * contr + fun * slope[i]); 144 154 } … … 147 157 148 158 } 149 159 vol += vol_sub; 150 160 f2 = f * f / vol * 1.0e8; 151 161 f2 *= scale; -
sansmodels/src/sans/models/test/utest_model_sphereexpshell.py
re096270 ra1b2471 14 14 from sans.models.SphereExpShellModel import SphereExpShellModel 15 15 from sans.models.CoreMultiShellModel import CoreMultiShellModel 16 from sans.models.VesicleModel import VesicleModel 16 17 17 18 self.model = SphereExpShellModel(n_shells=1) 18 19 self.model2 = SphereExpShellModel(n_shells=1).model 19 20 self.model3 = CoreMultiShellModel(n_shells=1) 21 self.model4 = VesicleModel() 20 22 21 23 def test_compare_Exp0_flat(self): … … 49 51 self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) 50 52 53 def test_compare_Exp0_flat_vesicle(self): 54 """ 55 Check if Exp function with A_shell=0 gives the same value as Flat function of vesicle model when sld_solv=sld_core 56 """ 57 print "\n*****Note: All tests (test_compare_Exp0_flat and test_compare_Expsmall_line) were passes since Sept. 18, 2010..." 58 # Exp: func_shell = 2, Line: func_shell =1 , Flat: func_shell = 0. 59 # A_shell = The coefficient of the exponential function: exp(A_shell*(r-ro)/thick_shell) 60 # exp function by default 61 # exp function crosses over to flat func at A_shell=0 62 self.model.setParam("A_shell1", 0) 63 # set A_shell=1 64 self.model2.setParam("A_shell1", 1) 65 # change the function to flat function 66 self.model2.setParam("func_shell1", 0) 67 68 # model: set param values as same as the model2 69 self.model.setParam("background", 0.0) 70 self.model.setParam("rad_core", 100.0) 71 self.model.setParam("scale", 1.0) 72 self.model.setParam("sld_core", 6.36e-006) 73 self.model.setParam("sld_in_shell1", 5e-007) 74 self.model.setParam("sld_solv", 6.36e-006) 75 self.model.setParam("thick_shell1", 30.0) 76 # model2: set param values as same as the model2 77 self.model2.setParam("background", 0.0) 78 self.model2.setParam("rad_core", 100.0) 79 self.model2.setParam("scale", 1.0) 80 self.model2.setParam("sld_core", 6.36e-006) 81 self.model2.setParam("sld_in_shell1", 5e-007) 82 self.model2.setParam("sld_solv", 6.36e-006) 83 self.model2.setParam("thick_shell1", 30.0) 84 #Compare exp(A=0) to flat (where A_shell is null) function 85 self.assertEqual(self.model.run(0.1),self.model4.run(0.1)) 86 self.assertEqual(self.model2.run(0.1),self.model4.run(0.1)) 87 #self.assertAlmostEqual(self.model2.run(0.1),self.model3.run(0.1),10) 88 51 89 52 90 def test_compare_Expsmall_line(self): -
sansmodels/src/sans/models/test/utest_models.py
r9ce41c6 ra1b2471 13 13 # pylint: disable-msg=R0201 14 14 15 15 class TestSpherew(unittest.TestCase): 16 """ Unit tests for sphere model """ 17 18 def setUp(self): 19 from sans.models.CoreFourShellModel import CoreFourShellModel 20 from sans.models.CoreMultiShellModel import CoreMultiShellModel 21 self.comp = CoreMultiShellModel(4) 22 23 def test1D(self): 24 """ Test 1D model for a sphere """ 25 self.comp._set_dispersion() 16 26 17 27 class TestSphere(unittest.TestCase): -
sansview/perspectives/fitting/basepage.py
re87f9fc ra1b2471 1622 1622 self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) 1623 1623 self.mutifactor_text = wx.StaticText( self,-1,"No. of Shells: " ) 1624 1624 self.show_sld_button = wx.Button( self,-1,"Show SLD Profile" ) 1625 self.show_sld_button.Bind(wx.EVT_BUTTON,self._on_show_sld) 1626 1625 1627 self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) 1626 1628 if self.model!= None: … … 1650 1652 mutifactor_selection.Add(self.mutifactor_text) 1651 1653 mutifactor_selection.Add(self.multifactorbox) 1652 1654 mutifactor_selection.Add((10,5)) 1655 mutifactor_selection.Add(self.show_sld_button) 1656 1653 1657 boxsizer1.Add( sizer_buttons ) 1654 1658 boxsizer1.Add( (15,15)) … … 1658 1662 1659 1663 self._set_multfactor_combobox() 1660 1664 self.show_sld_button.Hide() 1661 1665 #-------------------------------------------------------- 1662 1666 sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) 1663 1667 sizer.Layout() 1664 1668 self.SetScrollbars(20,20,25,65) 1669 1670 1671 def _on_show_sld(self, event=None): 1672 """ 1673 Plot SLD profile 1674 """ 1675 # get profile data 1676 x,y=self.model.getProfile() 1677 1678 from danse.common.plottools import Data1D 1679 from sans.perspectives.theory.profile_dialog import SLDPanel 1680 sld_data = Data1D(x,y) 1681 sld_data.name = 'SLD' 1682 1683 self.panel = SLDPanel(self, data=sld_data,id =-1 ) 1684 self.panel.ShowModal() 1665 1685 1666 1686 def _set_multfactor_combobox(self): … … 1843 1863 if form_factor().__class__ in self.model_list_box["Multi-Functions"]: 1844 1864 self._show_multfactor_combobox() 1865 self.show_sld_button.Show(True) 1845 1866 m_id = self.multifactorbox.GetCurrentSelection() 1846 1867 self.multi_factor = self.multifactorbox.GetClientData(m_id) … … 1849 1870 else: 1850 1871 self._hide_multfactor_combobox() 1872 self.show_sld_button.Hide() 1851 1873 form_factor = form_factor() 1852 1874 self.multi_factor = None 1853 1875 else: 1854 1876 self._hide_multfactor_combobox() 1877 self.show_sld_button.Hide() 1855 1878 self.multi_factor = None 1856 1879 -
sansview/perspectives/fitting/models.py
re87f9fc ra1b2471 193 193 self.shape_list.append(CoreMultiShellModel) 194 194 self.multiplication_factor.append(CoreMultiShellModel) 195 self.multi_func_list.append(CoreMultiShellModel) 195 196 196 197 from sans.models.VesicleModel import VesicleModel -
theoryview/perspectives/theory/basepage.py
re87f9fc ra1b2471 1195 1195 self.text2 = wx.StaticText( self,-1,"P(Q)*S(Q)" ) 1196 1196 self.mutifactor_text = wx.StaticText( self,-1,"No. of Shells: " ) 1197 1197 self.show_sld_button = wx.Button( self,-1,"Show SLD Profile" ) 1198 self.show_sld_button.Bind(wx.EVT_BUTTON,self._on_show_sld) 1198 1199 self.formfactorbox = wx.ComboBox(self, -1,style=wx.CB_READONLY) 1199 1200 if self.model!=None: … … 1242 1243 mutifactor_selection.Add(self.mutifactor_text) 1243 1244 mutifactor_selection.Add(self.multifactorbox) 1245 mutifactor_selection.Add((5,5)) 1246 mutifactor_selection.Add(self.show_sld_button) 1244 1247 1245 1248 boxsizer1.Add( sizer_buttons ) … … 1250 1253 1251 1254 self._set_multfactor_combobox() 1252 1255 self.show_sld_button.Hide() 1256 1253 1257 #-------------------------------------------------------- 1254 1258 sizer.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) … … 1256 1260 self.SetScrollbars(20,20,25,65) 1257 1261 1262 def _on_show_sld(self, event=None): 1263 """ 1264 Plot SLD profile 1265 """ 1266 # get profile data 1267 x,y=self.model.getProfile() 1268 1269 from danse.common.plottools import Data1D 1270 from profile_dialog import SLDPanel 1271 sld_data = Data1D(x,y) 1272 sld_data.name = 'SLD' 1273 1274 self.panel = SLDPanel(self, data=sld_data,id =-1 ) 1275 self.panel.ShowModal() 1276 1258 1277 def _set_multfactor_combobox(self): 1259 1278 """ … … 1469 1488 if form_factor().__class__ in self.model_list_box["Multi-Functions"]: 1470 1489 self._show_multfactor_combobox() 1490 self.show_sld_button.Show(True) 1471 1491 m_id = self.multifactorbox.GetCurrentSelection() 1472 1492 self.multi_factor = self.multifactorbox.GetClientData(m_id) … … 1475 1495 else: 1476 1496 self._hide_multfactor_combobox() 1497 self.show_sld_button.Hide() 1477 1498 form_factor = form_factor() 1478 1499 self.multi_factor = None 1479 1500 else: 1480 1501 self._hide_multfactor_combobox() 1502 self.show_sld_button.Hide() 1481 1503 self.multi_factor = None 1482 1504
Note: See TracChangeset
for help on using the changeset viewer.