- Timestamp:
- Aug 8, 2014 1:45:51 PM (10 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:
- ae7d639
- Parents:
- 8cdb9f1
- Location:
- Models
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
Models/code_capcyl.py
ra42fec0 r1726b21 12 12 13 13 class GpuCapCylinder(object): 14 PARS = {'scale':1, 'rad_cyl':1, 'rad_cap':1, 'len gth':1, 'sld_capcyl':1e-6, 'sld_solv':0, 'background':0,14 PARS = {'scale':1, 'rad_cyl':1, 'rad_cap':1, 'len_cyl':1, 'sld_capcyl':1e-6, 'sld_solv':0, 'background':0, 15 15 'theta':0, 'phi':0} 16 16 17 PD_PARS = ['rad_cyl', 'len gth', 'rad_cap', 'theta', 'phi']17 PD_PARS = ['rad_cyl', 'len_cyl', 'rad_cap', 'theta', 'phi'] 18 18 19 19 def __init__(self, qx, qy, dtype='float32'): … … 39 39 self.res[:] = 0 40 40 cl.enqueue_copy(queue, self.res_b, self.res) 41 rad_cyl,length,rad_cap,theta,phi = \ 41 42 rad_cyl,len_cyl,rad_cap,theta,phi = \ 42 43 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) 43 44 for base in GpuCapCylinder.PD_PARS] … … 45 46 rad_cyl.value, rad_cyl.weight = rad_cyl.get_weights(pars['rad_cyl'], 0, 10000, True) 46 47 rad_cap.value, rad_cap.weight = rad_cap.get_weights(pars['rad_cap'], 0, 10000, True) 47 len gth.value, length.weight = length.get_weights(pars['length'], 0, 10000, True)48 len_cyl.value, len_cyl.weight = len_cyl.get_weights(pars['len_cyl'], 0, 10000, True) 48 49 theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False) 49 50 phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False) … … 56 57 for i in xrange(len(rad_cyl.weight)): 57 58 for m in xrange(len(rad_cap.weight)): 58 for j in xrange(len(length.weight)): 59 for j in xrange(len(len_cyl.weight)): 60 61 hDist = -1.0*sqrt(fabs(rad_cap.value[m]*rad_cap.value[m]-rad_cyl.value[i]*rad_cyl.value[i])) 62 vol_i = 4.0*atan(1.0)*rad_cyl.value[i]*rad_cyl.value[i]*len_cyl.value[j]+2.0*4.0*atan(1.0)/3.0\ 63 *((rad_cap.value[m]-hDist)*(rad_cap.value[m]-hDist)*(2*rad_cap.value[m]+hDist)) 64 vol += rad_cyl.weight[i]*len_cyl.weight[j]*rad_cap.weight[m]*vol_i 65 norm_vol += rad_cyl.weight[i]*len_cyl.weight[j]*rad_cap.weight[m] 66 59 67 for k in xrange(len(theta.weight)): 60 68 for l in xrange(len(phi.weight)): 61 hDist = -1.0*sqrt(fabs(rad_cap.value[m]*rad_cap.value[m]-rad_cyl.value[i]*rad_cyl.value[i])) 62 vol_i = 4.0*atan(1.0)*rad_cyl.value[i]*rad_cyl.value[i]*length.value[j]+2.0*4.0*atan(1.0)/3.0\ 63 *((rad_cap.value[m]-hDist)*(rad_cap.value[m]-hDist)*(2*rad_cap.value[m]+hDist)) 69 64 70 self.prg.CapCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, 65 real(vol_i), real(hDist), real(rad_cyl.value[i]), real(rad_cap.value[m]), real(len gth.value[j]),71 real(vol_i), real(hDist), real(rad_cyl.value[i]), real(rad_cap.value[m]), real(len_cyl.value[j]), 66 72 real(theta.value[k]), real(phi.value[l]), real(sub), real(pars['scale']), 67 73 real(phi.weight[l]), real(theta.weight[k]), real(rad_cap.weight[m]), 68 real(rad_cyl.weight[i]), real(len gth.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size))74 real(rad_cyl.weight[i]), real(len_cyl.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size)) 69 75 70 vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*vol_i71 norm_vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m] 72 norm += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*theta.weight[k]*phi.weight[l] 76 norm += rad_cyl.weight[i]*len_cyl.weight[j]*rad_cap.weight[m]*theta.weight[k]*phi.weight[l] 77 78 73 79 74 80 #if size > 1: -
Models/code_coreshellcyl.py
ra42fec0 r1726b21 48 48 for r in xrange(len(radius.weight)): 49 49 for l in xrange(len(length.weight)): 50 for at in xrange(len(axis_theta.weight)): 51 for p in xrange(len(axis_phi.weight)): 52 for th in xrange(len(thickness.weight)): 50 for th in xrange(len(thickness.weight)): 51 52 vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\ 53 *(length.value[l]+2.0*thickness.value[th]) 54 norm_vol += radius.weight[r]*length.weight[l]*thickness.weight[th] 55 56 for at in xrange(len(axis_theta.weight)): 57 for p in xrange(len(axis_phi.weight)): 53 58 54 59 self.prg.CoreShellCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, … … 59 64 real(pars['shell_sld']), real(pars['solvent_sld']),np.uint32(size), 60 65 np.uint32(self.qx.size)) 61 vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\ 62 *(length.value[l]+2.0*thickness.value[th]) 63 norm_vol += radius.weight[r]*length.weight[l]*thickness.weight[th] 66 64 67 norm += radius.weight[r]*length.weight[l]*thickness.weight[th]*axis_theta.weight[at]\ 65 68 *axis_phi.weight[p] -
Models/code_cylinder.py
ra42fec0 r1726b21 6 6 7 7 from weights import GaussianDispersion 8 from sasmodel import card, set_precision, set_precision_1d 8 from sasmodel import card, set_precision, set_precision_1d, tic, toc 9 9 10 10 … … 33 33 def eval(self, pars): 34 34 35 tic() 35 36 _ctx,queue = card() 36 37 self.res[:] = 0 … … 55 56 for i in xrange(len(radius.weight)): 56 57 for j in xrange(len(length.weight)): 58 59 vol += radius.weight[i]*length.weight[j]*pow(radius.value[i], 2)*length.value[j] 60 norm_vol += radius.weight[i]*length.weight[j] 61 57 62 for k in xrange(len(cyl_theta.weight)): 58 63 for l in xrange(len(cyl_phi.weight)): … … 63 68 np.uint32(self.qx.size), np.uint32(size)) 64 69 65 vol += radius.weight[i]*length.weight[j]*pow(radius.value[i], 2)*length.value[j]66 norm_vol += radius.weight[i]*length.weight[j]67 70 norm += radius.weight[i]*length.weight[j]*cyl_theta.weight[k]*cyl_phi.weight[l] 71 68 72 69 73 # if size > 1: … … 74 78 sum *= norm_vol/vol 75 79 80 print toc()*1000, self.qx.shape[0] 76 81 return sum/norm+pars['background'] 77 82 -
Models/code_ellipse.py
ra42fec0 r1726b21 53 53 for j in xrange(len(radius_b.weight)): 54 54 #Average over theta distribution 55 vol += radius_a.weight[i]*radius_b.weight[j]*pow(radius_b.value[j], 2)*radius_a.value[i] 56 norm_vol += radius_a.weight[i]*radius_b.weight[j] 57 55 58 for k in xrange(len(axis_theta.weight)): 56 59 #Average over phi distribution … … 64 67 np.uint32(self.qx.size), np.uint32(len(axis_theta.weight))) 65 68 66 vol += radius_a.weight[i]*radius_b.weight[j]*pow(radius_b.value[j], 2)*radius_a.value[i]67 norm_vol += radius_a.weight[i]*radius_b.weight[j]68 69 norm += radius_a.weight[i]*radius_b.weight[j]*axis_theta.weight[k]*axis_phi.weight[l] 70 69 71 # Averaging in theta needs an extra normalization 70 72 # factor to account for the sin(theta) term in the -
Models/code_triaxialellipse.py
ra42fec0 r1726b21 9 9 10 10 class GpuTriEllipse: 11 PARS = {'scale':1, ' axisA':35, 'axisB':100, 'axisC':400, 'sldEll':1e-6, 'sldSolv':6.3e-6, 'background':0,12 ' theta':0, 'phi':0, 'psi':0}11 PARS = {'scale':1, 'semi_axisA':35, 'semi_axisB':100, 'semi_axisC':400, 'sldEll':1e-6, 'sldSolv':6.3e-6, 'background':0, 12 'axis_theta':0, 'axis_phi':0, 'axis_psi':0} 13 13 14 PD_PARS = [' axisA', 'axisB', 'axisC', 'theta', 'phi', 'psi']14 PD_PARS = ['semi_axisA', 'semi_axisB', 'semi_axisC', 'axis_theta', 'axis_phi', 'axis_psi'] 15 15 16 16 def __init__(self, qx, qy, dtype='float32'): … … 32 32 self.res[:] = 0 33 33 cl.enqueue_copy(queue, self.res_b, self.res) 34 axisA, axisB, axisC, theta, phi,psi = \34 semi_axisA, semi_axisB, semi_axisC, axis_theta, axis_phi, axis_psi = \ 35 35 [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) 36 36 for base in GpuTriEllipse.PD_PARS] 37 37 38 axisA.value, axisA.weight = axisA.get_weights(pars['axisA'], 0, 10000, True)39 axisB.value, axisB.weight = axisB.get_weights(pars['axisB'], 0, 10000, True)40 axisC.value, axisC.weight = axisC.get_weights(pars['axisC'], 0, 10000, True)41 theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False)42 phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False)43 psi.value, psi.weight = psi.get_weights(pars['psi'], -90, 180, False)38 semi_axisA.value, semi_axisA.weight = semi_axisA.get_weights(pars['semi_axisA'], 0, 10000, True) 39 semi_axisB.value, semi_axisB.weight = semi_axisB.get_weights(pars['semi_axisB'], 0, 10000, True) 40 semi_axisC.value, semi_axisC.weight = semi_axisC.get_weights(pars['semi_axisC'], 0, 10000, True) 41 axis_theta.value, axis_theta.weight = axis_theta.get_weights(pars['axis_theta'], -90, 180, False) 42 axis_phi.value, axis_phi.weight = axis_phi.get_weights(pars['axis_phi'], -90, 180, False) 43 axis_psi.value, axis_psi.weight = axis_psi.get_weights(pars['axis_psi'], -90, 180, False) 44 44 45 45 sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 46 size = len( theta.weight)46 size = len(axis_theta.weight) 47 47 sub = pars['sldEll'] - pars['sldSolv'] 48 48 49 49 real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 50 for a in xrange(len(axisA.weight)): 51 for b in xrange(len(axisB.weight)): 52 for c in xrange(len(axisC.weight)): 53 for t in xrange(len(theta.weight)): 54 for i in xrange(len(phi.weight)): 55 for s in xrange(len(psi.weight)): 50 for a in xrange(len(semi_axisA.weight)): 51 for b in xrange(len(semi_axisB.weight)): 52 for c in xrange(len(semi_axisC.weight)): 53 54 vol += semi_axisA.weight[a]*semi_axisB.weight[b]*semi_axisC.weight[c]*semi_axisA.value[a]*semi_axisB.value[b]*semi_axisC.value[c] 55 norm_vol += semi_axisA.weight[a]*semi_axisB.weight[b]*semi_axisC.weight[c] 56 57 for t in xrange(len(axis_theta.weight)): 58 for i in xrange(len(axis_phi.weight)): 59 for s in xrange(len(axis_psi.weight)): 56 60 self.prg.TriaxialEllipseKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, 57 real(sub), real(pars['scale']), real( axisA.value[a]), real(axisB.value[b]),58 real( axisC.value[c]), real(phi.value[i]), real(theta.value[t]), real(psi.value[s]),59 real( axisA.weight[a]), real(axisB.weight[b]), real(axisC.weight[c]), real(psi.weight[s]),60 real( phi.weight[i]), real(theta.weight[t]), np.uint32(self.qx.size), np.uint32(size))61 real(sub), real(pars['scale']), real(semi_axisA.value[a]), real(semi_axisB.value[b]), 62 real(semi_axisC.value[c]), real(axis_phi.value[i]), real(axis_theta.value[t]), real(axis_psi.value[s]), 63 real(semi_axisA.weight[a]), real(semi_axisB.weight[b]), real(semi_axisC.weight[c]), real(axis_psi.weight[s]), 64 real(axis_phi.weight[i]), real(axis_theta.weight[t]), np.uint32(self.qx.size), np.uint32(size)) 61 65 62 vol += axisA.weight[a]*axisB.weight[b]*axisC.weight[c]*axisA.value[a]*axisB.value[b]*axisC.value[c] 63 norm_vol += axisA.weight[a]*axisB.weight[b]*axisC.weight[c] 64 norm += axisA.weight[a]*axisB.weight[b]*axisC.weight[c]*theta.weight[t]*phi.weight[i]*psi.weight[s] 66 norm += semi_axisA.weight[a]*semi_axisB.weight[b]*semi_axisC.weight[c]*axis_theta.weight[t]*axis_phi.weight[i]*axis_psi.weight[s] 67 65 68 66 69 # if size > 1:
Note: See TracChangeset
for help on using the changeset viewer.