Changeset c1c37d5 in sasmodels
- Timestamp:
- Mar 18, 2016 12:06:08 PM (9 years ago)
- Branches:
- master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 31c64d9, 3a45c2c
- Parents:
- 89ab393 (diff), a629d8e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Files:
-
- 4 added
- 9 edited
- 7 moved
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/core.py
r02e70ff rd5ba841 170 170 """ 171 171 value, weight = zip(*pars) 172 if len(value) > 1: 173 value = [v.flatten() for v in np.meshgrid(*value)] 174 weight = np.vstack([v.flatten() for v in np.meshgrid(*weight)]) 175 weight = np.prod(weight, axis=0) 172 value = [v.flatten() for v in np.meshgrid(*value)] 173 weight = np.vstack([v.flatten() for v in np.meshgrid(*weight)]) 174 weight = np.prod(weight, axis=0) 176 175 return value, weight 177 176 -
sasmodels/models/bessel.py
rcbd37a7 ra5af4e1 78 78 79 79 Iq = """ 80 return 2.0*j1(q)/q;80 return J1(q); 81 81 """ 82 82 -
sasmodels/models/hardsphere.py
raa2edb2 r934f906 58 58 category = "structure-factor" 59 59 structure_factor = True 60 single = False 60 61 61 62 # ["name", "units", default, [lower, upper], "type","description"], … … 74 75 Iq = """ 75 76 double D,A,B,G,X,X2,X4,S,C,FF,HARDSPH; 77 // these are c compiler instructions, can also put normal code inside the "if else" structure 78 #if FLOAT_SIZE > 4 79 // double precision orig had 0.2, don't call the variable cutoff as PAK already has one called that! Must use UPPERCASE name please. 80 // 0.05 better, 0.1 OK 81 #define CUTOFFHS 0.05 82 #else 83 // 0.1 bad, 0.2 OK, 0.3 good, 0.4 better, 0.8 no good 84 #define CUTOFFHS 0.4 85 #endif 76 86 77 87 if(fabs(radius_effective) < 1.E-12) { … … 96 106 G=0.5*volfraction*A; 97 107 98 if(X < 0.2) {99 // RKH Feb 2016, use Taylor series expansion for small X , IT IS VERY PICKY ABOUT THE X CUT OFF VALUE, ought to be lower in double.108 if(X < CUTOFFHS) { 109 // RKH Feb 2016, use Taylor series expansion for small X 100 110 // else no obvious way to rearrange the equations to avoid needing a very high number of significant figures. 101 111 // Series expansion found using Mathematica software. Numerical test in .xls showed terms to X^2 are sufficient -
sasmodels/models/lamellar.py
raa2edb2 r7c391dd 5 5 ---------- 6 6 7 The scattering intensity $I(q)$ is7 The scattering intensity $I(q)$ for dilute, randomly oriented, "infinitely large" sheets or lamellae is 8 8 9 9 .. math:: 10 10 11 I(q) = \frac{2\pi P(q)}{\delta q^2}11 I(q) = scale*\frac{2\pi P(q)}{q^2\delta } 12 12 13 13 … … 16 16 .. math:: 17 17 18 P(q) = \frac{2\Delta\rho^2}{q^2}(1-cos(q\delta))18 P(q) = \frac{2\Delta\rho^2}{q^2}(1-cos(q\delta)) = \frac{4\Delta\rho^2}{q^2}sin^2(\frac{q\delta}{2}) 19 19 20 where $\delta$ is the total layer thickness and $\Delta\rho$ is the scattering length density difference. 20 21 21 where $\delta$ is the bilayer thickness. 22 This is the limiting form for a spherical shell of infinitely large radius. Note that the division by $\delta$ 23 means that $scale$ in sasview is the volume fraction of sheet, $\phi = S\delta$ where $S$ is the area of 24 sheet per unit volume. $S$ is half the Porod surface area per unit volume of a thicker layer (as that would 25 include both faces of the sheet). 22 26 23 27 The 2D scattering intensity is calculated in the same way as 1D, where … … 56 60 57 61 # ["name", "units", default, [lower, upper], "type","description"], 58 parameters = [["sld", "1e-6/Ang^2", 1, [-inf, inf], "", 59 "Layer scattering length density" ], 60 ["solvent_sld", "1e-6/Ang^2", 6, [-inf, inf], "", 61 "Solvent scattering length density" ], 62 ["thickness", "Ang", 50, [0, inf], "volume","Bilayer thickness" ], 62 parameters = [ ["thickness", "Ang", 50, [0, inf], "volume","total layer thickness" ], 63 ["sld", "1e-6/Ang^2", 1, [-inf, inf], "","Layer scattering length density" ], 64 ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "","Solvent scattering length density" ], 63 65 ] 64 66 65 66 67 # No volume normalization despite having a volume parameter 67 # This should perhaps be volume normalized? 68 # This should perhaps be volume normalized? - it is! 68 69 form_volume = """ 69 70 return 1.0; … … 71 72 72 73 Iq = """ 73 const double sub = sld - s olvent_sld;74 const double sub = sld - sld_solvent; 74 75 const double qsq = q*q; 75 76 // Original expression … … 89 90 90 91 demo = dict(scale=1, background=0, 91 sld=6, s olvent_sld=1,92 sld=6, sld_solvent=1, 92 93 thickness=40, 93 94 thickness_pd=0.2, thickness_pd_n=40) 94 95 oldname = 'LamellarModel' 95 oldpars = dict(sld='sld_bi', s olvent_sld='sld_sol', thickness='bi_thick')96 oldpars = dict(sld='sld_bi', sld_solvent='sld_sol', thickness='bi_thick') 96 97 tests = [ 97 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'s olvent_sld' : 6.3, 'thickness_pd' : 0.0,98 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 50.0, 'sld' : 1.0,'sld_solvent' : 6.3, 'thickness_pd' : 0.0, 98 99 }, [0.001], [882289.54309]] 99 100 ] -
sasmodels/models/lamellar_hg.py
raa2edb2 r52a3db3 26 26 27 27 where $\delta_T$ is *tail_length*, $\delta_H$ is *head_length*, 28 $\Delta\rho_H$ is the head contrast (*head_sld* $-$ *solvent_sld*), 29 and $\Delta\rho_T$ is tail contrast (*sld* $-$ *solvent_sld*). 28 $\Delta\rho_H$ is the head contrast (*sld_head* $-$ *sld_solvent*), 29 and $\Delta\rho_T$ is tail contrast (*sld* $-$ *sld_solvent*). 30 31 The total thickness of the lamellar sheet is $\delta_H$ + $\delta_T$ + $\delta_T$ + $\delta_H$. 32 Note that in a non aqueous solvent the chemical "head" group may be the 33 "Tail region" and vice-versa. 30 34 31 35 The 2D scattering intensity is calculated in the same way as 1D, where … … 49 53 from numpy import inf 50 54 51 name = "lamellar_ FFHG"52 title = "Random lamellar phase with Head Groups"55 name = "lamellar_hg" 56 title = "Random lamellar phase with Head and Tail Groups" 53 57 description = """\ 54 [Random lamellar phase with Head Groups]58 [Random lamellar phase with Head and Tail Groups] 55 59 I(q)= 2*pi*P(q)/(2(H+T)*q^(2)), where 56 60 P(q)= see manual 57 61 layer thickness =(H+T+T+H) = 2(Head+Tail) 58 62 sld = Tail scattering length density 59 head_sld = Head scattering length density60 s olvent_sld= solvent scattering length density63 sld_head = Head scattering length density 64 sld_solvent = solvent scattering length density 61 65 background = incoherent background 62 66 scale = scale factor … … 66 70 # pylint: disable=bad-whitespace, line-too-long 67 71 # ["name", "units", default, [lower, upper], "type","description"], 68 parameters = [["tail_length", "Ang", 15, [0, inf], "volume", "Tail thickness "],69 ["head_length", "Ang", 10, [0, inf], "volume", " head thickness"],72 parameters = [["tail_length", "Ang", 15, [0, inf], "volume", "Tail thickness ( total = H+T+T+H)"], 73 ["head_length", "Ang", 10, [0, inf], "volume", "Head thickness"], 70 74 ["sld", "1e-6/Ang^2", 0.4, [-inf,inf], "", "Tail scattering length density"], 71 [" head_sld", "1e-6/Ang^2", 3.0, [-inf,inf], "", "Head scattering length density"],72 ["s olvent_sld", "1e-6/Ang^2", 6, [-inf,inf], "", "Solvent scattering length density"]]75 ["sld_head", "1e-6/Ang^2", 3.0, [-inf,inf], "", "Head scattering length density"], 76 ["sld_solvent", "1e-6/Ang^2", 6, [-inf,inf], "", "Solvent scattering length density"]] 73 77 # pylint: enable=bad-whitespace, line-too-long 74 78 … … 81 85 Iq = """ 82 86 const double qsq = q*q; 83 const double drh = head_sld - solvent_sld;84 const double drt = sld - s olvent_sld; //correction 13FEB06 by L.Porcar87 const double drh = sld_head - sld_solvent; 88 const double drt = sld - sld_solvent; //correction 13FEB06 by L.Porcar 85 89 const double qT = q*tail_length; 86 90 double Pq, inten; … … 106 110 demo = dict(scale=1, background=0, 107 111 tail_length=15, head_length=10, 108 sld=0.4, head_sld=3.0, solvent_sld=6.0,112 sld=0.4, sld_head=3.0, sld_solvent=6.0, 109 113 tail_length_pd=0.2, tail_length_pd_n=40, 110 114 head_length_pd=0.01, head_length_pd_n=40) … … 112 116 oldname = 'LamellarFFHGModel' 113 117 oldpars = dict(head_length='h_thickness', tail_length='t_length', 114 sld='sld_tail', head_sld='sld_head', solvent_sld='sld_solvent')118 sld='sld_tail', sld_head='sld_head', sld_solvent='sld_solvent') 115 119 # 116 120 tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 15.0, 'head_length': 10.0, 117 'sld': 0.4, 'head_sld': 3.0, 'solvent_sld': 6.0}, [0.001], [653143.9209]]] 121 'sld': 0.4, 'sld_head': 3.0, 'sld_solvent': 6.0}, [0.001], [653143.9209]]] 122 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lamellar_hg_stack_caille.py
raa2edb2 r6ab4ed8 9 9 .. math:: 10 10 11 I(q) = 2 \pi \frac{P(q)S(q)}{ \delta q^2}11 I(q) = 2 \pi \frac{P(q)S(q)}{q^2\delta } 12 12 13 13 … … 56 56 results for the next lower and higher values. 57 57 58 Be aware that the computations may be very slow. 59 58 60 The 2D scattering intensity is calculated in the same way as 1D, where 59 61 the $q$ vector is defined as … … 73 75 from numpy import inf 74 76 75 name = "lamellar CailleHG"76 title = "Random lamellar sheet with Caille structure factor"77 name = "lamellar_hg_stack_caille" 78 title = "Random lamellar head/tail/tail/head sheet with Caille structure factor" 77 79 description = """\ 78 80 [Random lamellar phase with Caille structure factor] … … 104 106 ["sld", "1e-6/Ang^2", 0.4, [-inf, inf], "", 105 107 "Tail scattering length density"], 106 [" head_sld", "1e-6/Ang^2", 2.0, [-inf, inf], "",108 ["sld_head", "1e-6/Ang^2", 2.0, [-inf, inf], "", 107 109 "Head scattering length density"], 108 ["s olvent_sld", "1e-6/Ang^2", 6, [-inf, inf], "",110 ["sld_solvent", "1e-6/Ang^2", 6, [-inf, inf], "", 109 111 "Solvent scattering length density"], 110 112 ] 111 113 112 source = ["lamellar CailleHG_kernel.c"]114 source = ["lamellar_hg_stack_caille_kernel.c"] 113 115 114 116 # No volume normalization despite having a volume parameter … … 129 131 Nlayers=20, spacing=200., Caille_parameter=0.05, 130 132 tail_length=15, head_length=10, 131 #sld=-1, head_sld=4.0, solvent_sld=6.0,132 sld=-1, head_sld=4.1, solvent_sld=6.0,133 #sld=-1, sld_head=4.0, sld_solvent=6.0, 134 sld=-1, sld_head=4.1, sld_solvent=6.0, 133 135 tail_length_pd=0.1, tail_length_pd_n=20, 134 136 head_length_pd=0.05, head_length_pd_n=30, … … 140 142 oldpars = dict( 141 143 tail_length='deltaT', head_length='deltaH', Nlayers='n_plates', 142 Caille_parameter='caille', sld='sld_tail', head_sld='sld_head',143 s olvent_sld='sld_solvent')144 Caille_parameter='caille', sld='sld_tail', sld_head='sld_head', 145 sld_solvent='sld_solvent') 144 146 # 145 147 tests = [[{'scale': 1.0, 'background': 0.0, 'tail_length': 10.0, 'head_length': 2.0, 146 148 'Nlayers': 30.0, 'spacing': 40., 'Caille_parameter': 0.001, 'sld': 0.4, 147 ' head_sld': 2.0, 'solvent_sld': 6.0, 'tail_length_pd': 0.0,149 'sld_head': 2.0, 'sld_solvent': 6.0, 'tail_length_pd': 0.0, 148 150 'head_length_pd': 0.0, 'spacing_pd': 0.0}, [0.001], [6838238.571488]]] 151 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lamellar_stack_caille.py
raa2edb2 r6ab4ed8 11 11 .. math:: 12 12 13 I(q) = 2\pi \frac{P(q)S(q)}{ \delta q^2}13 I(q) = 2\pi \frac{P(q)S(q)}{q^2\delta } 14 14 15 15 The form factor is … … 70 70 from numpy import inf 71 71 72 name = "lamellar PS"72 name = "lamellar_stack_caille" 73 73 title = "Random lamellar sheet with Caille structure factor" 74 74 description = """\ … … 92 92 ["Caille_parameter", "1/Ang^2", 0.1, [0.0,0.8], "", "Caille parameter"], 93 93 ["sld", "1e-6/Ang^2", 6.3, [-inf,inf], "", "layer scattering length density"], 94 ["s olvent_sld", "1e-6/Ang^2", 1.0, [-inf,inf], "", "Solvent scattering length density"],94 ["sld_solvent", "1e-6/Ang^2", 1.0, [-inf,inf], "", "Solvent scattering length density"], 95 95 ] 96 96 # pylint: enable=bad-whitespace, line-too-long 97 97 98 source = ["lamellar Caille_kernel.c"]98 source = ["lamellar_stack_caille_kernel.c"] 99 99 100 100 # No volume normalization despite having a volume parameter … … 113 113 demo = dict(scale=1, background=0, 114 114 thickness=67., Nlayers=3.75, spacing=200., 115 Caille_parameter=0.268, sld=1.0, s olvent_sld=6.34,115 Caille_parameter=0.268, sld=1.0, sld_solvent=6.34, 116 116 thickness_pd=0.1, thickness_pd_n=100, 117 117 spacing_pd=0.05, spacing_pd_n=40) … … 120 120 oldpars = dict(thickness='delta', Nlayers='N_plates', 121 121 Caille_parameter='caille', 122 sld='sld_bi', s olvent_sld='sld_sol')122 sld='sld_bi', sld_solvent='sld_sol') 123 123 # 124 124 tests = [ 125 125 [{'scale': 1.0, 'background': 0.0, 'thickness': 30., 'Nlayers': 20.0, 126 126 'spacing': 400., 'Caille_parameter': 0.1, 'sld': 6.3, 127 's olvent_sld': 1.0, 'thickness_pd': 0.0, 'spacing_pd': 0.0},127 'sld_solvent': 1.0, 'thickness_pd': 0.0, 'spacing_pd': 0.0}, 128 128 [0.001], [28895.13397]] 129 129 ] 130 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lamellar_stack_paracrystal.py
raa2edb2 r6ab4ed8 16 16 *not* the total excluded volume of the paracrystal), 17 17 18 - *sld* $-$ *s olvent_sld* is the contrast $\Delta \rho$,18 - *sld* $-$ *sld_solvent* is the contrast $\Delta \rho$, 19 19 20 20 - *thickness* is the layer thickness $t$, … … 36 36 37 37 The form factor of the bilayer is approximated as the cross section of an 38 infinite, planar bilayer of thickness $t$ 38 infinite, planar bilayer of thickness $t$ (compare the equations for the 39 lamellar model). 39 40 40 41 .. math:: … … 94 95 from numpy import inf 95 96 96 name = "lamellar PC"97 name = "lamellar_stack_paracrystal" 97 98 title = "Random lamellar sheet with paracrystal structure factor" 98 99 description = """\ … … 120 121 ["sld", "1e-6/Ang^2", 1.0, [-inf, inf], "", 121 122 "layer scattering length density"], 122 ["s olvent_sld", "1e-6/Ang^2", 6.34, [-inf, inf], "",123 ["sld_solvent", "1e-6/Ang^2", 6.34, [-inf, inf], "", 123 124 "Solvent scattering length density"], 124 125 ] 125 126 126 127 127 source = ["lamellar PC_kernel.c"]128 source = ["lamellar_stack_paracrystal_kernel.c"] 128 129 129 130 form_volume = """ … … 140 141 demo = dict(scale=1, background=0, 141 142 thickness=33, Nlayers=20, spacing=250, spacing_polydisp=0.2, 142 sld=1.0, s olvent_sld=6.34,143 sld=1.0, sld_solvent=6.34, 143 144 thickness_pd=0.2, thickness_pd_n=40) 144 145 145 146 oldname = 'LamellarPCrystalModel' 146 147 oldpars = dict(spacing_polydisp='pd_spacing', sld='sld_layer', 147 s olvent_sld='sld_solvent')148 sld_solvent='sld_solvent') 148 149 # 149 150 tests = [ 150 151 [ {'scale': 1.0, 'background' : 0.0, 'thickness' : 33.,'Nlayers' : 20.0, 'spacing' : 250., 'spacing_polydisp' : 0.2, 151 'sld' : 1.0, 's olvent_sld' : 6.34,152 'sld' : 1.0, 'sld_solvent' : 6.34, 152 153 'thickness_pd' : 0.0, 'thickness_pd_n' : 40 }, [0.001, 0.215268], [21829.3, 0.00487686]] 153 154 ] 155 # ADDED by: RKH ON: 18Mar2016 converted from sasview previously, now renaming everything & sorting the docs -
sasmodels/models/lib/j1_cephes.c
re2af2a9 rfad5dc1 39 39 Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier 40 40 */ 41 double j1(double ); 42 43 double j1(double x) { 44 45 //Cephes double pression function 46 #if FLOAT_SIZE>4 47 48 double w, z, p, q, xn; 49 50 const double DR1 = 5.78318596294678452118E0; 51 const double DR2 = 3.04712623436620863991E1; 52 const double Z1 = 1.46819706421238932572E1; 53 const double Z2 = 4.92184563216946036703E1; 54 const double THPIO4 = 2.35619449019234492885; 55 const double SQ2OPI = 0.79788456080286535588; 56 57 double RP[8] = { 41 42 constant double RP[8] = { 58 43 -8.99971225705559398224E8, 59 44 4.52228297998194034323E11, … … 63 48 0.0, 64 49 0.0, 65 0.0 66 }; 67 68 double RQ[8] = { 69 /* 1.00000000000000000000E0,*/ 70 6.20836478118054335476E2, 71 2.56987256757748830383E5, 72 8.35146791431949253037E7, 73 2.21511595479792499675E10, 74 4.74914122079991414898E12, 75 7.84369607876235854894E14, 76 8.95222336184627338078E16, 77 5.32278620332680085395E18, 78 }; 79 80 double PP[8] = { 50 0.0 }; 51 52 constant double RQ[8] = { 53 6.20836478118054335476E2, 54 2.56987256757748830383E5, 55 8.35146791431949253037E7, 56 2.21511595479792499675E10, 57 4.74914122079991414898E12, 58 7.84369607876235854894E14, 59 8.95222336184627338078E16, 60 5.32278620332680085395E18 61 }; 62 63 constant double PP[8] = { 81 64 7.62125616208173112003E-4, 82 65 7.31397056940917570436E-2, … … 86 69 5.21451598682361504063E0, 87 70 1.00000000000000000254E0, 88 0.0, 89 }; 90 double PQ[8] = { 71 0.0} ; 72 73 74 constant double PQ[8] = { 91 75 5.71323128072548699714E-4, 92 76 6.88455908754495404082E-2, … … 96 80 5.20982848682361821619E0, 97 81 9.99999999999999997461E-1, 98 0.0, 99 }; 100 101 double QP[8] = { 82 0.0 }; 83 84 constant double QP[8] = { 102 85 5.10862594750176621635E-2, 103 86 4.98213872951233449420E0, … … 107 90 5.97489612400613639965E2, 108 91 2.11688757100572135698E2, 109 2.52070205858023719784E1, 110 }; 111 112 double QQ[8] = { 113 /* 1.00000000000000000000E0,*/ 92 2.52070205858023719784E1 }; 93 94 constant double QQ[8] = { 114 95 7.42373277035675149943E1, 115 96 1.05644886038262816351E3, … … 119 100 2.82619278517639096600E3, 120 101 3.36093607810698293419E2, 121 0.0, 122 }; 123 124 w = x; 125 if( x < 0 ) 126 w = -x; 127 128 if( w <= 5.0 ) 129 { 130 z = x * x; 131 w = polevl( z, RP, 3 ) / p1evl( z, RQ, 8 ); 132 w = w * x * (z - Z1) * (z - Z2); 133 return( w ); 134 } 135 136 w = 5.0/x; 137 z = w * w; 138 p = polevl( z, PP, 6)/polevl( z, PQ, 6 ); 139 q = polevl( z, QP, 7)/p1evl( z, QQ, 7 ); 140 xn = x - THPIO4; 141 142 double sn, cn; 143 SINCOS(xn, sn, cn); 144 p = p * cn - w * q * sn; 145 146 return( p * SQ2OPI / sqrt(x) ); 147 148 149 //Single precission version of cephes 150 #else 151 double xx, w, z, p, q, xn; 152 153 const double Z1 = 1.46819706421238932572E1; 154 const double THPIO4F = 2.35619449019234492885; /* 3*pi/4 */ 155 156 157 double JP[8] = { 102 0.0 }; 103 104 constant double JP[8] = { 158 105 -4.878788132172128E-009, 159 106 6.009061827883699E-007, … … 166 113 }; 167 114 168 115 constant double MO1[8] = { 169 116 6.913942741265801E-002, 170 117 -2.284801500053359E-001, … … 177 124 }; 178 125 179 126 constant double PH1[8] = { 180 127 -4.497014141919556E+001, 181 128 5.073465654089319E+001, … … 188 135 }; 189 136 137 double J1(double x) { 138 139 //Cephes double pression function 140 #if FLOAT_SIZE>4 141 142 double w, z, p, q, xn; 143 144 const double Z1 = 1.46819706421238932572E1; 145 const double Z2 = 4.92184563216946036703E1; 146 const double THPIO4 = 2.35619449019234492885; 147 const double SQ2OPI = 0.79788456080286535588; 148 149 w = x; 150 if( x < 0 ) 151 w = -x; 152 153 if( w <= 5.0 ) 154 { 155 z = x * x; 156 w = polevl( z, RP, 3 ) / p1evl( z, RQ, 8 ); 157 w = w * x * (z - Z1) * (z - Z2); 158 return( w ); 159 } 160 161 w = 5.0/x; 162 z = w * w; 163 164 p = polevl( z, PP, 6)/polevl( z, PQ, 6 ); 165 q = polevl( z, QP, 7)/p1evl( z, QQ, 7 ); 166 167 xn = x - THPIO4; 168 169 double sn, cn; 170 SINCOS(xn, sn, cn); 171 p = p * cn - w * q * sn; 172 173 return( p * SQ2OPI / sqrt(x) ); 174 175 176 //Single precission version of cephes 177 #else 178 double xx, w, z, p, q, xn; 179 180 const double Z1 = 1.46819706421238932572E1; 181 const double THPIO4F = 2.35619449019234492885; /* 3*pi/4 */ 182 183 190 184 xx = x; 191 185 if( xx < 0 ) … … 211 205 } 212 206 207 208 /*double J1c(double x) { 209 return 210 }*/ -
sasmodels/models/lib/polevl.c
re2af2a9 rfad5dc1 51 51 */ 52 52 53 double polevl( double x, double coef[8], int N );54 double p1evl( double x, double coef[8], int N );55 53 56 double polevl( double x, double coef[8], int N ) {54 double polevl( double x, constant double *coef, int N ) { 57 55 58 56 int i = 0; … … 74 72 */ 75 73 76 double p1evl( double x, double coef[8], int N ) {74 double p1evl( double x, constant double *coef, int N ) { 77 75 int i=0; 78 76 double ans = x+coef[i]; … … 84 82 85 83 return( ans ); 86 87 84 } -
sasmodels/product.py
r3bcd03d rd5ba841 124 124 # so borrow values from end of p_fixed. This makes volfraction the 125 125 # first S parameter. 126 start += num_p_fixed - 2 127 par_map['s_fixed'] = np.arange(start, start+num_s_fixed) 126 start += num_p_fixed 127 par_map['s_fixed'] = np.hstack(([start,start], 128 np.arange(start, start+num_s_fixed-2))) 128 129 par_map['volfraction'] = num_p_fixed 129 start += num_s_fixed 130 start += num_s_fixed-2 130 131 # vol pars offset from the start of pd pars 131 132 par_map['vol_pars'] = [start+k for k in vol_par_idx] 132 133 par_map['p_pd'] = np.arange(start, start+num_p_pd) 133 start += num_p_pd 134 par_map['s_pd'] = np.arange(start-1, start+num_s_pd) # should be empty... 134 start += num_p_pd-1 135 par_map['s_pd'] = np.hstack((start, 136 np.arange(start, start+num_s_pd-1))) 135 137 136 138 self.fixed_pars = model_info['partype']['fixed-' + dim] -
sasmodels/sasview_model.py
r2622b3f r08376e7 23 23 from . import core 24 24 25 def make_class(model_info, dtype='single', namestyle='name'): 25 def standard_models(): 26 return [make_class(model_name) for model_name in core.list_models()] 27 28 def make_class(model_name, namestyle='name'): 26 29 """ 27 30 Load the sasview model defined in *kernel_module*. 28 31 29 Returns a class that can be used directly as a sasview model. 32 Returns a class that can be used directly as a sasview model.t 30 33 31 34 Defaults to using the new name for a model. Setting … … 33 36 compatible with SasView. 34 37 """ 35 model = core.build_model(model_info, dtype=dtype)38 model_info = core.load_model_info(model_name) 36 39 def __init__(self, multfactor=1): 37 SasviewModel.__init__(self , model)38 attrs = dict(__init__=__init__ )39 ConstructedModel = type(model .info[namestyle], (SasviewModel,), attrs)40 SasviewModel.__init__(self) 41 attrs = dict(__init__=__init__, _model_info=model_info) 42 ConstructedModel = type(model_info[namestyle], (SasviewModel,), attrs) 40 43 return ConstructedModel 41 44 … … 44 47 Sasview wrapper for opencl/ctypes model. 45 48 """ 46 def __init__(self , model):47 """Initialization"""48 self._model = model49 50 self.name = model .info['name']51 self.oldname = model .info['oldname']52 self.description = model .info['description']49 def __init__(self): 50 self._kernel = None 51 model_info = self._model_info 52 53 self.name = model_info['name'] 54 self.oldname = model_info['oldname'] 55 self.description = model_info['description'] 53 56 self.category = None 54 57 self.multiplicity_info = None … … 60 63 self.params = collections.OrderedDict() 61 64 self.dispersion = dict() 62 partype = model .info['partype']63 64 for p in model .info['parameters']:65 partype = model_info['partype'] 66 67 for p in model_info['parameters']: 65 68 self.params[p.name] = p.default 66 69 self.details[p.name] = [p.units] + p.limits … … 83 86 84 87 ## independent parameter name and unit [string] 85 self.input_name = model .info.get("input_name", "Q")86 self.input_unit = model .info.get("input_unit", "A^{-1}")87 self.output_name = model .info.get("output_name", "Intensity")88 self.output_unit = model .info.get("output_unit", "cm^{-1}")88 self.input_name = model_info.get("input_name", "Q") 89 self.input_unit = model_info.get("input_unit", "A^{-1}") 90 self.output_name = model_info.get("output_name", "Intensity") 91 self.output_unit = model_info.get("output_unit", "cm^{-1}") 89 92 90 93 ## _persistency_dict is used by sas.perspectives.fitting.basepage … … 95 98 ## New fields introduced for opencl rewrite 96 99 self.cutoff = 1e-5 100 101 def __get_state__(self): 102 state = self.__dict__.copy() 103 model_id = self._model_info['id'] 104 state.pop('_kernel') 105 # May need to reload model info on set state since it has pointers 106 # to python implementations of Iq, etc. 107 #state.pop('_model_info') 108 return state 109 110 def __set_state__(self, state): 111 self.__dict__ = state 112 self._kernel = None 97 113 98 114 def __str__(self): … … 187 203 # TODO: fix test so that parameter order doesn't matter 188 204 ret = ['%s.%s' % (d.lower(), p) 189 for d in self._model .info['partype']['pd-2d']205 for d in self._model_info['partype']['pd-2d'] 190 206 for p in ('npts', 'nsigmas', 'width')] 191 207 #print(ret) … … 261 277 # Check whether we have a list of ndarrays [qx,qy] 262 278 qx, qy = qdist 263 partype = self._model .info['partype']279 partype = self._model_info['partype'] 264 280 if not partype['orientation'] and not partype['magnetic']: 265 281 return self.calculate_Iq(np.sqrt(qx ** 2 + qy ** 2)) … … 284 300 to the card for each evaluation. 285 301 """ 302 if self._kernel is None: 303 self._kernel = core.build_model(self._model_info) 286 304 q_vectors = [np.asarray(q) for q in args] 287 fn = self._ model(q_vectors)305 fn = self._kernel(q_vectors) 288 306 pars = [self.params[v] for v in fn.fixed_pars] 289 307 pd_pars = [self._get_weights(p) for p in fn.pd_pars] … … 299 317 :return: the value of the effective radius 300 318 """ 301 ER = self._model .info.get('ER', None)319 ER = self._model_info.get('ER', None) 302 320 if ER is None: 303 321 return 1.0 … … 314 332 :return: the value of the volf ratio 315 333 """ 316 VR = self._model .info.get('VR', None)334 VR = self._model_info.get('VR', None) 317 335 if VR is None: 318 336 return 1.0 … … 358 376 parameter set in the vector. 359 377 """ 360 pars = self._model .info['partype']['volume']378 pars = self._model_info['partype']['volume'] 361 379 return core.dispersion_mesh([self._get_weights(p) for p in pars]) 362 380 … … 368 386 from . import weights 369 387 370 relative = self._model .info['partype']['pd-rel']371 limits = self._model .info['limits']388 relative = self._model_info['partype']['pd-rel'] 389 limits = self._model_info['limits'] 372 390 dis = self.dispersion[par] 373 391 value, weight = weights.get_weights( … … 375 393 self.params[par], limits[par], par in relative) 376 394 return value, weight / np.sum(weight) 395 -
example/sesansfit.py
r170ea69 r89ab393 2 2 from sasmodels import core, bumps_model, sesans 3 3 from sas.sascalc.dataloader.loader import Loader 4 5 HAS_CONVERTER = True6 try:7 from sas.sascalc.data_util.nxsunit import Converter8 except ImportError:9 HAS_CONVERTER = False10 11 4 12 5 def get_bumps_model(model_name): … … 30 23 data = loader.load(file) 31 24 if data is None: raise IOError("Could not load file %r"%(file)) 32 if HAS_CONVERTER == True:33 default_unit = "A"34 data_conv_q = Converter(data._xunit)35 for x in data.x:36 print x37 data.x = data_conv_q(data.x, units=default_unit)38 for x in data.x:39 print x40 data._xunit = default_unit41 25 42 26 except:
Note: See TracChangeset
for help on using the changeset viewer.