/* CylinderFit.c A simplified project designed to act as a template for your curve fitting function. The fitting function is a Cylinder form factor. No resolution effects are included (yet) */ #include "StandardHeaders.h" // Include ANSI headers, Mac headers #include "GaussWeights.h" #include "libCylinder.h" /* CylinderForm : calculates the form factor of a cylinder at the give x-value p->x Warning: The call to WaveData() below returns a pointer to the middle of an unlocked Macintosh handle. In the unlikely event that your calculations could cause memory to move, you should copy the coefficient values to local variables or an array before such operations. */ double CylinderForm(double dp[], double q) { int i; double Pi; double scale,radius,length,delrho,bkg,halfheight,sldCyl,sldSolv; //local variables of coefficient wave int nord=76; //order of integration double uplim,lolim; //upper and lower integration limits double summ,zi,yyy,answer,vcyl; //running tally of integration Pi = 4.0*atan(1.0); lolim = 0.0; uplim = Pi/2.0; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves radius = dp[1]; length = dp[2]; sldCyl = dp[3]; sldSolv = dp[4]; bkg = dp[5]; delrho = sldCyl-sldSolv; halfheight = length/2.0; for(i=0;ix Uses 76 pt Gaussian quadrature for both integrals Warning: The call to WaveData() below returns a pointer to the middle of an unlocked Macintosh handle. In the unlikely event that your calculations could cause memory to move, you should copy the coefficient values to local variables or an array before such operations. */ double EllipCyl76(double dp[], double q) { int i,j; double Pi,slde,sld; double scale,ra,nu,length,delrho,bkg; //local variables of coefficient wave int nord=76; //order of integration double va,vb; //upper and lower integration limits double summ,zi,yyy,answer,vell; //running tally of integration double summj,vaj,vbj,zij,arg, si; //for the inner integration Pi = 4.0*atan(1.0); va = 0.0; vb = 1.0; //orintational average, outer integral vaj=0.0; vbj=Pi; //endpoints of inner integral summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves ra = dp[1]; nu = dp[2]; length = dp[3]; slde = dp[4]; sld = dp[5]; delrho = slde - sld; bkg = dp[6]; for(i=0;ix Uses 76 pt Gaussian quadrature for orientational integral Uses 20 pt quadrature for the inner integral over the elliptical cross-section Warning: The call to WaveData() below returns a pointer to the middle of an unlocked Macintosh handle. In the unlikely event that your calculations could cause memory to move, you should copy the coefficient values to local variables or an array before such operations. */ double EllipCyl20(double dp[], double q) { int i,j; double Pi,slde,sld; double scale,ra,nu,length,delrho,bkg; //local variables of coefficient wave int nordi=76; //order of integration int nordj=20; double va,vb; //upper and lower integration limits double summ,zi,yyy,answer,vell; //running tally of integration double summj,vaj,vbj,zij,arg,si; //for the inner integration Pi = 4.0*atan(1.0); va = 0.0; vb = 1.0; //orintational average, outer integral vaj=0.0; vbj=Pi; //endpoints of inner integral summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves ra = dp[1]; nu = dp[2]; length = dp[3]; slde = dp[4]; sld = dp[5]; delrho = slde - sld; bkg = dp[6]; for(i=0;ix Uses 76 pt Gaussian quadrature for both integrals Warning: The call to WaveData() below returns a pointer to the middle of an unlocked Macintosh handle. In the unlikely event that your calculations could cause memory to move, you should copy the coefficient values to local variables or an array before such operations. */ double TriaxialEllipsoid(double dp[], double q) { int i,j; double Pi; double scale,aa,bb,cc,delrho,bkg; //local variables of coefficient wave int nordi=76; //order of integration int nordj=76; double va,vb; //upper and lower integration limits double summ,zi,yyy,answer; //running tally of integration double summj,vaj,vbj,zij,slde,sld; //for the inner integration Pi = 4.0*atan(1.0); va = 0.0; vb = 1.0; //orintational average, outer integral vaj = 0.0; vbj = 1.0; //endpoints of inner integral summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves aa = dp[1]; bb = dp[2]; cc = dp[3]; slde = dp[4]; sld = dp[5]; delrho = slde - sld; bkg = dp[6]; for(i=0;ix Uses 76 pt Gaussian quadrature for both integrals Warning: The call to WaveData() below returns a pointer to the middle of an unlocked Macintosh handle. In the unlikely event that your calculations could cause memory to move, you should copy the coefficient values to local variables or an array before such operations. */ double Parallelepiped(double dp[], double q) { int i,j; double scale,aa,bb,cc,delrho,bkg; //local variables of coefficient wave int nordi=76; //order of integration int nordj=76; double va,vb; //upper and lower integration limits double summ,yyy,answer; //running tally of integration double summj,vaj,vbj; //for the inner integration double mu,mudum,arg,sigma,uu,vol,sldp,sld; // Pi = 4.0*atan(1.0); va = 0.0; vb = 1.0; //orintational average, outer integral vaj = 0.0; vbj = 1.0; //endpoints of inner integral summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves aa = dp[1]; bb = dp[2]; cc = dp[3]; sldp = dp[4]; sld = dp[5]; delrho = sldp - sld; bkg = dp[6]; mu = q*bb; vol = aa*bb*cc; // normalize all WRT bb aa = aa/bb; cc = cc/bb; for(i=0;ix Uses 76 pt Gaussian quadrature for the single integral Warning: The call to WaveData() below returns a pointer to the middle of an unlocked Macintosh handle. In the unlikely event that your calculations could cause memory to move, you should copy the coefficient values to local variables or an array before such operations. */ double HollowCylinder(double dp[], double q) { int i; double scale,rcore,rshell,length,delrho,bkg; //local variables of coefficient wave int nord=76; //order of integration double va,vb,zi; //upper and lower integration limits double summ,answer,pi,sldc,sld; //running tally of integration pi = 4.0*atan(1.0); va = 0.0; vb = 1.0; //limits of numerical integral summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves rcore = dp[1]; rshell = dp[2]; length = dp[3]; sldc = dp[4]; sld = dp[5]; delrho = sldc - sld; bkg = dp[6]; for(i=0;ix Uses 76 pt Gaussian quadrature for the single integral Warning: The call to WaveData() below returns a pointer to the middle of an unlocked Macintosh handle. In the unlikely event that your calculations could cause memory to move, you should copy the coefficient values to local variables or an array before such operations. */ double EllipsoidForm(double dp[], double q) { int i; double scale,a,nua,delrho,bkg; //local variables of coefficient wave int nord=76; //order of integration double va,vb,zi; //upper and lower integration limits double summ,answer,pi,slde,sld; //running tally of integration pi = 4.0*atan(1.0); va = 0.0; vb = 1.0; //limits of numerical integral summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves nua = dp[1]; a = dp[2]; slde = dp[3]; sld = dp[4]; delrho = slde - sld; bkg = dp[5]; for(i=0;ix the cylinder has a polydisperse cross section */ double Cyl_PolyRadius(double dp[], double q) { int i; double scale,radius,length,pd,delrho,bkg; //local variables of coefficient wave int nord=20; //order of integration double uplim,lolim; //upper and lower integration limits double summ,zi,yyy,answer,Vpoly; //running tally of integration double range,zz,Pi,sldc,sld; Pi = 4.0*atan(1.0); range = 3.4; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves radius = dp[1]; length = dp[2]; pd = dp[3]; sldc = dp[4]; sld = dp[5]; delrho = sldc - sld; bkg = dp[6]; zz = (1.0/pd)*(1.0/pd) - 1.0; lolim = radius*(1.0-range*pd); //set the upper/lower limits to cover the distribution if(lolim<0.0) { lolim = 0.0; } if(pd>0.3) { range = 3.4 + (pd-0.3)*18.0; } uplim = radius*(1.0+range*pd); for(i=0;ix the cylinder has a polydisperse Length */ double Cyl_PolyLength(double dp[], double q) { int i; double scale,radius,length,pd,delrho,bkg; //local variables of coefficient wave int nord=20; //order of integration double uplim,lolim; //upper and lower integration limits double summ,zi,yyy,answer,Vpoly; //running tally of integration double range,zz,Pi,sldc,sld; Pi = 4.0*atan(1.0); range = 3.4; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves radius = dp[1]; length = dp[2]; pd = dp[3]; sldc = dp[4]; sld = dp[5]; delrho = sldc - sld; bkg = dp[6]; zz = (1.0/pd)*(1.0/pd) - 1.0; lolim = length*(1.0-range*pd); //set the upper/lower limits to cover the distribution if(lolim<0.0) { lolim = 0.0; } if(pd>0.3) { range = 3.4 + (pd-0.3)*18.0; } uplim = length*(1.0+range*pd); for(i=0;ix the cylinder has a core-shell structure */ double CoreShellCylinder(double dp[], double q) { int i; double scale,rcore,length,bkg; //local variables of coefficient wave double thick,rhoc,rhos,rhosolv; int nord=76; //order of integration double uplim,lolim,halfheight; //upper and lower integration limits double summ,zi,yyy,answer,Vcyl; //running tally of integration double Pi; Pi = 4.0*atan(1.0); lolim = 0.0; uplim = Pi/2.0; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves rcore = dp[1]; thick = dp[2]; length = dp[3]; rhoc = dp[4]; rhos = dp[5]; rhosolv = dp[6]; bkg = dp[7]; halfheight = length/2.0; for(i=0;ix the cylinder has a polydisperse CORE radius */ double PolyCoShCylinder(double dp[], double q) { int i; double scale,radius,length,sigma,bkg; //local variables of coefficient wave double rad,radthick,facthick,rhoc,rhos,rhosolv; int nord=20; //order of integration double uplim,lolim; //upper and lower integration limits double summ,yyy,answer,Vpoly; //running tally of integration double Pi,AR,Rsqrsumm,Rsqryyy,Rsqr; Pi = 4.0*atan(1.0); summ = 0.0; //initialize intergral Rsqrsumm = 0.0; scale = dp[0]; radius = dp[1]; sigma = dp[2]; //sigma is the standard mean deviation length = dp[3]; radthick = dp[4]; facthick= dp[5]; rhoc = dp[6]; rhos = dp[7]; rhosolv = dp[8]; bkg = dp[9]; lolim = exp(log(radius)-(4.*sigma)); if (lolim<0.0) { lolim=0.0; //to avoid numerical error when va<0 (-ve r value) } uplim = exp(log(radius)+(4.*sigma)); for(i=0;ix the ellipsoid has a core-shell structure */ double OblateForm(double dp[], double q) { int i; double scale,crmaj,crmin,trmaj,trmin,delpc,delps,bkg; int nord=76; //order of integration double uplim,lolim; //upper and lower integration limits double summ,zi,yyy,answer,oblatevol; //running tally of integration double Pi,sldc,slds,sld; Pi = 4.0*atan(1.0); lolim = 0.0; uplim = 1.0; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves crmaj = dp[1]; crmin = dp[2]; trmaj = dp[3]; trmin = dp[4]; sldc = dp[5]; slds = dp[6]; sld = dp[7]; delpc = sldc - slds; //core - shell delps = slds - sld; //shell - solvent bkg = dp[8]; for(i=0;ix the ellipsoid has a core-shell structure */ double ProlateForm(double dp[], double q) { int i; double scale,crmaj,crmin,trmaj,trmin,delpc,delps,bkg; int nord=76; //order of integration double uplim,lolim; //upper and lower integration limits double summ,zi,yyy,answer,prolatevol; //running tally of integration double Pi,sldc,slds,sld; Pi = 4.0*atan(1.0); lolim = 0.0; uplim = 1.0; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves crmaj = dp[1]; crmin = dp[2]; trmaj = dp[3]; trmin = dp[4]; sldc = dp[5]; slds = dp[6]; sld = dp[7]; delpc = sldc - slds; //core - shell delps = slds - sld; //shell - sovent bkg = dp[8]; for(i=0;ix the cylinder has a polydisperse Length */ double FlexCyl_PolyLen(double dp[], double q) { int i; double scale,radius,length,pd,bkg,lb,delrho,sldc,slds; //local variables of coefficient wave int nord=20; //order of integration double uplim,lolim; //upper and lower integration limits double summ,zi,yyy,answer,Vpoly; //running tally of integration double range,zz,Pi; Pi = 4.0*atan(1.0); range = 3.4; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves length = dp[1]; //radius pd = dp[2]; // average length lb = dp[3]; radius = dp[4]; sldc = dp[5]; slds = dp[6]; bkg = dp[7]; delrho = sldc - slds; zz = (1.0/pd)*(1.0/pd) - 1.0; lolim = length*(1.0-range*pd); //set the upper/lower limits to cover the distribution if(lolim<0.0) { lolim = 0.0; } if(pd>0.3) { range = 3.4 + (pd-0.3)*18.0; } uplim = length*(1.0+range*pd); for(i=0;ix the cylinder has a polydisperse cross sectional radius */ double FlexCyl_PolyRad(double dp[], double q) { int i; double scale,radius,length,pd,delrho,bkg,lb,sldc,slds; //local variables of coefficient wave int nord=76; //order of integration double uplim,lolim; //upper and lower integration limits double summ,zi,yyy,answer,Vpoly; //running tally of integration double range,zz,Pi; Pi = 4.0*atan(1.0); range = 3.4; summ = 0.0; //initialize intergral scale = dp[0]; //make local copies in case memory moves length = dp[1]; //radius lb = dp[2]; // average length radius = dp[3]; pd = dp[4]; sldc = dp[5]; slds = dp[6]; bkg = dp[7]; delrho = sldc-slds; zz = (1.0/pd)*(1.0/pd) - 1.0; lolim = radius*(1.0-range*pd); //set the upper/lower limits to cover the distribution if(lolim<0.0) { lolim = 0.0; } if(pd>0.3) { range = 3.4 + (pd-0.3)*18.0; } uplim = radius*(1.0+range*pd); for(i=0;i // double gfn2(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq) { // local variables double aa,bb,u2,ut2,uq,ut,vc,vt,siq,sit,gfnc,gfnt,gfn2,pi43,gfn,Pi; Pi = 4.0*atan(1.0); pi43=4.0/3.0*Pi; aa = crmaj; bb = crmin; u2 = (aa*aa*xx*xx + bb*bb*(1.0-xx*xx)); ut2 = (trmaj*trmaj*xx*xx + trmin*trmin*(1.0-xx*xx)); uq = sqrt(u2)*qq; ut= sqrt(ut2)*qq; vc = pi43*aa*bb*bb; vt = pi43*trmaj*trmin*trmin; if (uq == 0.0){ siq = 1.0/3.0; }else{ siq = (sin(uq)/uq/uq - cos(uq)/uq)/uq; } if (ut == 0.0){ sit = 1.0/3.0; }else{ sit = (sin(ut)/ut/ut - cos(ut)/ut)/ut; } gfnc = 3.0*siq*vc*delpc; gfnt = 3.0*sit*vt*delps; gfn = gfnc+gfnt; gfn2 = gfn*gfn; return (gfn2); } // // FUNCTION gfn4: CONTAINS F(Q,A,B,MU)**2 AS GIVEN // BY (53) & (58-59) IN CHEN AND // KOTLARCHYK REFERENCE // // // function gfn4 for oblate ellipsoids double gfn4(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq) { // local variables double aa,bb,u2,ut2,uq,ut,vc,vt,siq,sit,gfnc,gfnt,tgfn,gfn4,pi43,Pi; Pi = 4.0*atan(1.0); pi43=4.0/3.0*Pi; aa = crmaj; bb = crmin; u2 = (bb*bb*xx*xx + aa*aa*(1.0-xx*xx)); ut2 = (trmin*trmin*xx*xx + trmaj*trmaj*(1.0-xx*xx)); uq = sqrt(u2)*qq; ut= sqrt(ut2)*qq; vc = pi43*aa*aa*bb; vt = pi43*trmaj*trmaj*trmin; if (uq == 0.0){ siq = 1.0/3.0; }else{ siq = (sin(uq)/uq/uq - cos(uq)/uq)/uq; } if (ut == 0.0){ sit = 1.0/3.0; }else{ sit = (sin(ut)/ut/ut - cos(ut)/ut)/ut; } gfnc = 3.0*siq*vc*delpc; gfnt = 3.0*sit*vt*delps; tgfn = gfnc+gfnt; gfn4 = tgfn*tgfn; return (gfn4); } double FlePolyLen_kernel(double q, double radius, double length, double lb, double zz, double delrho, double zi) { double Pq,vcyl,dl; double Pi,qr; Pi = 4.0*atan(1.0); qr = q*radius; Pq = Sk_WR(q,zi,lb); //does not have cross section term if (qr !=0){ Pq *= (2.0*NR_BessJ1(qr)/qr)*(2.0*NR_BessJ1(qr)/qr); } vcyl=Pi*radius*radius*zi; Pq *= vcyl*vcyl; dl = SchulzPoint_cpr(zi,length,zz); return (Pq*dl); } double FlePolyRad_kernel(double q, double ravg, double Lc, double Lb, double zz, double delrho, double zi) { double Pq,vcyl,dr; double Pi,qr; Pi = 4.0*atan(1.0); qr = q*zi; Pq = Sk_WR(q,Lc,Lb); //does not have cross section term if (qr !=0){ Pq *= (2.0*NR_BessJ1(qr)/qr)*(2.0*NR_BessJ1(qr)/qr); } vcyl=Pi*zi*zi*Lc; Pq *= vcyl*vcyl; dr = SchulzPoint_cpr(zi,ravg,zz); return (Pq*dr); } double CSCylIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length) { double answer,halfheight,Pi; double lolim,uplim,summ,yyy,zi; int nord,i; // set up the integration end points Pi = 4.0*atan(1.0); nord = 76; lolim = 0.0; uplim = Pi/2.0; halfheight = length/2.0; summ = 0.0; // initialize integral i=0; for(i=0;i 1 as t->0 arg1 = (mu/2.0)*cos(Pi*uu/2.0); arg2 = (mu*aa/2.0)*sin(Pi*uu/2.0); if(arg1==0.0) { tmp1 = 1.0; } else { tmp1 = sin(arg1)*sin(arg1)/arg1/arg1; } if (arg2==0.0) { tmp2 = 1.0; } else { tmp2 = sin(arg2)*sin(arg2)/arg2/arg2; } return (tmp1*tmp2); }//Function PPKernel() double TriaxialKernel(double q, double aa, double bb, double cc, double dx, double dy) { double arg,val,pi; //local variables pi = 4.0*atan(1.0); arg = aa*aa*cos(pi*dx/2)*cos(pi*dx/2); arg += bb*bb*sin(pi*dx/2)*sin(pi*dx/2)*(1-dy*dy); arg += cc*cc*dy*dy; arg = q*sqrt(arg); if (arg == 0.0){ val = 1.0; // as arg --> 0, val should go to 1.0 }else{ val = 9.0 * ( (sin(arg) - arg*cos(arg))/(arg*arg*arg) ) * ( (sin(arg) - arg*cos(arg))/(arg*arg*arg) ); } return (val); }//Function TriaxialKernel() double CylKernel(double qq, double rr,double h, double theta) { // qq is the q-value for the calculation (1/A) // rr is the radius of the cylinder (A) // h is the HALF-LENGTH of the cylinder = L/2 (A) double besarg,bj,retval,d1,t1,b1,t2,b2,siarg,be,si; //Local variables besarg = qq*rr*sin(theta); siarg = qq * h * cos(theta); bj =NR_BessJ1(besarg); //* Computing 2nd power */ d1 = sin(siarg); t1 = d1 * d1; //* Computing 2nd power */ d1 = bj; t2 = d1 * d1 * 4.0 * sin(theta); //* Computing 2nd power */ d1 = siarg; b1 = d1 * d1; //* Computing 2nd power */ d1 = qq * rr * sin(theta); b2 = d1 * d1; if (besarg == 0.0){ be = sin(theta); }else{ be = t2 / b2; } if (siarg == 0.0){ si = 1.0; }else{ si = t1 / b1; } retval = be * si; return (retval); }//Function CylKernel() double EllipCylKernel(double qq, double ra,double nu, double theta) { //this is the function LAMBDA1^2 in Feigin's notation // qq is the q-value for the calculation (1/A) // ra is the transformed radius"a" in Feigin's notation // nu is the ratio (major radius)/(minor radius) of the Ellipsoid [=] --- // theta is the dummy variable of the integration double retval,arg; //Local variables arg = qq*ra*sqrt((1.0+nu*nu)/2+(1.0-nu*nu)*cos(theta)/2); if (arg == 0.0){ retval = 1.0; }else{ retval = 2.0*NR_BessJ1(arg)/arg; } //square it retval *= retval; return(retval); }//Function EllipCylKernel() double NR_BessJ1(double x) { double ax,z; double xx,y,ans,ans1,ans2; if ((ax=fabs(x)) < 8.0) { y=x*x; ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1 +y*(-2972611.439+y*(15704.48260+y*(-30.16036606)))))); ans2=144725228442.0+y*(2300535178.0+y*(18583304.74 +y*(99447.43394+y*(376.9991397+y*1.0)))); ans=ans1/ans2; } else { z=8.0/ax; y=z*z; xx=ax-2.356194491; ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4 +y*(0.2457520174e-5+y*(-0.240337019e-6)))); ans2=0.04687499995+y*(-0.2002690873e-3 +y*(0.8449199096e-5+y*(-0.88228987e-6 +y*0.105787412e-6))); ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2); if (x < 0.0) ans = -ans; } return(ans); } /* Lamellar_ParaCrystal - Pedersen's model */ double Lamellar_ParaCrystal(double w[], double q) { // Input (fitting) variables are: //[0] scale factor //[1] thickness //[2] number of layers //[3] spacing between layers //[4] polydispersity of spacing //[5] SLD lamellar //[6] SLD solvent //[7] incoherent background // give them nice names double inten,qval,scale,th,nl,davg,pd,contr,bkg,xn; double xi,ww,Pbil,Znq,Snq,an,sldLayer,sldSolvent,pi; long n1,n2; pi = 4.0*atan(1.0); scale = w[0]; th = w[1]; nl = w[2]; davg = w[3]; pd = w[4]; sldLayer = w[5]; sldSolvent = w[6]; bkg = w[7]; contr = w[5] - w[6]; qval = q; //get the fractional part of nl, to determine the "mixing" of N's n1 = trunc(nl); //rounds towards zero n2 = n1 + 1; xn = (double)n2 - nl; //fractional contribution of n1 ww = exp(-qval*qval*pd*pd*davg*davg/2.0); //calculate the n1 contribution an = paraCryst_an(ww,qval,davg,n1); Snq = paraCryst_sn(ww,qval,davg,n1,an); Znq = xn*Snq; //calculate the n2 contribution an = paraCryst_an(ww,qval,davg,n2); Snq = paraCryst_sn(ww,qval,davg,n2,an); Znq += (1.0-xn)*Snq; //and the independent contribution Znq += (1.0-ww*ww)/(1.0+ww*ww-2.0*ww*cos(qval*davg)); //the limit when NL approaches infinity // Zq = (1-ww^2)/(1+ww^2-2*ww*cos(qval*davg)) xi = th/2.0; //use 1/2 the bilayer thickness Pbil = (sin(qval*xi)/(qval*xi))*(sin(qval*xi)/(qval*xi)); inten = 2.0*pi*contr*contr*Pbil*Znq/(qval*qval); inten *= 1.0e8; return(scale*inten+bkg); } // functions for the lamellar paracrystal model double paraCryst_sn(double ww, double qval, double davg, long nl, double an) { double Snq; Snq = an/( (double)nl*pow((1.0+ww*ww-2.0*ww*cos(qval*davg)),2) ); return(Snq); } double paraCryst_an(double ww, double qval, double davg, long nl) { double an; an = 4.0*ww*ww - 2.0*(ww*ww*ww+ww)*cos(qval*davg); an -= 4.0*pow(ww,(nl+2))*cos((double)nl*qval*davg); an += 2.0*pow(ww,(nl+3))*cos((double)(nl-1)*qval*davg); an += 2.0*pow(ww,(nl+1))*cos((double)(nl+1)*qval*davg); return(an); } /* Spherocylinder : Uses 76 pt Gaussian quadrature for both integrals */ double Spherocylinder(double w[], double x) { int i,j; double Pi; double scale,contr,bkg,sldc,slds; double len,rad,hDist,endRad; int nordi=76; //order of integration int nordj=76; double va,vb; //upper and lower integration limits double summ,zi,yyy,answer; //running tally of integration double summj,vaj,vbj,zij; //for the inner integration double SphCyl_tmp[7],arg1,arg2,inner,be; scale = w[0]; rad = w[1]; len = w[2]; sldc = w[3]; slds = w[4]; bkg = w[5]; SphCyl_tmp[0] = w[0]; SphCyl_tmp[1] = w[1]; SphCyl_tmp[2] = w[2]; SphCyl_tmp[3] = w[1]; //end radius is same as cylinder radius SphCyl_tmp[4] = w[3]; SphCyl_tmp[5] = w[4]; SphCyl_tmp[6] = w[5]; hDist = 0; //by definition for this model endRad = rad; contr = sldc-slds; Pi = 4.0*atan(1.0); va = 0.0; vb = Pi/2.0; //orintational average, outer integral vaj = -1.0*hDist/endRad; vbj = 1.0; //endpoints of inner integral summ = 0.0; //initialize intergral for(i=0;i 0 Uses 76 pt Gaussian quadrature for both integrals */ double Dumbbell(double w[], double x) { int i,j; double Pi; double scale,contr,bkg,sldc,slds; double len,rad,hDist,endRad; int nordi=76; //order of integration int nordj=76; double va,vb; //upper and lower integration limits double summ,zi,yyy,answer; //running tally of integration double summj,vaj,vbj,zij; //for the inner integration double Dumb_tmp[7],arg1,arg2,inner,be; scale = w[0]; rad = w[1]; // len = w[2] endRad = w[2]; sldc = w[3]; slds = w[4]; bkg = w[5]; len = 0.01; Dumb_tmp[0] = w[0]; Dumb_tmp[1] = w[1]; Dumb_tmp[2] = len; //length is some small number, essentially zero Dumb_tmp[3] = w[2]; Dumb_tmp[4] = w[3]; Dumb_tmp[5] = w[4]; Dumb_tmp[6] = w[5]; hDist = sqrt(fabs(endRad*endRad-rad*rad)); //by definition for this model contr = sldc-slds; Pi = 4.0*atan(1.0); va = 0.0; vb = Pi/2.0; //orintational average, outer integral vaj = -1.0*hDist/endRad; vbj = 1.0; //endpoints of inner integral summ = 0.0; //initialize intergral for(i=0;i 0 -- uses the same kernel as the Dumbbell case Uses 76 pt Gaussian quadrature for both integrals */ double Barbell(double w[], double x) { int i,j; double Pi; double scale,contr,bkg,sldc,slds; double len,rad,hDist,endRad; int nordi=76; //order of integration int nordj=76; double va,vb; //upper and lower integration limits double summ,zi,yyy,answer; //running tally of integration double summj,vaj,vbj,zij; //for the inner integration double arg1,arg2,inner,be; scale = w[0]; rad = w[1]; len = w[2]; endRad = w[3]; sldc = w[4]; slds = w[5]; bkg = w[6]; hDist = sqrt(fabs(endRad*endRad-rad*rad)); //by definition for this model contr = sldc-slds; Pi = 4.0*atan(1.0); va = 0.0; vb = Pi/2.0; //orintational average, outer integral vaj = -1.0*hDist/endRad; vbj = 1.0; //endpoints of inner integral summ = 0.0; //initialize intergral for(i=0;i0 summj += yyy; } //now calculate the value of the inner integral inner = (vbj-vaj)/2.0*summj; inner *= 4.0*Pi*endRad*endRad*endRad; //now calculate outer integrand arg1 = x*len/2.0*cos(zi); arg2 = x*rad*sin(zi); yyy = inner; if(arg2 == 0) { be = 0.5; } else { be = NR_BessJ1(arg2)/arg2; } if(arg1 == 0.0) { //limiting value of sinc(0) is 1; sinc is not defined in math.h yyy += Pi*rad*rad*len*2.0*be; } else { yyy += Pi*rad*rad*len*sin(arg1)/arg1*2.0*be; } yyy *= yyy; yyy *= sin(zi); // = |A(q)|^2*sin(theta) yyy *= Gauss76Wt[i]; summ += yyy; } //final scaling is done at the end of the function, after the NT_FP64 case answer = (vb-va)/2.0*summ; answer /= Pi*rad*rad*len + 2.0*Pi*(2.0*endRad*endRad*endRad/3.0+endRad*endRad*hDist-hDist*hDist*hDist/3.0); //divide by volume answer *= 1.0e8; //convert to cm^-1 answer *= contr*contr; answer *= scale; answer += bkg; return answer; } // inner integral of the Dumbbell model, special case where L ~ 0 and hDist > 0 // // inner integral of the Barbell model if L is nonzero // double Dumb_kernel(double w[], double x, double tt, double theta) { double val,arg1,arg2; double scale,bkg,sldc,slds; double len,rad,hDist,endRad,be; scale = w[0]; rad = w[1]; len = w[2]; endRad = w[3]; sldc = w[4]; slds = w[5]; bkg = w[6]; hDist = sqrt(fabs(endRad*endRad-rad*rad)); arg1 = x*cos(theta)*(endRad*tt+hDist+len/2.0); arg2 = x*endRad*sin(theta)*sqrt(1.0-tt*tt); if(arg2 == 0) { be = 0.5; } else { be = NR_BessJ1(arg2)/arg2; } val = cos(arg1)*(1.0-tt*tt)*be; return(val); } double PolyCoreBicelle(double dp[], double q) { int i; int nord = 20; double scale, length, sigma, bkg, radius, radthick, facthick; double rhoc, rhoh, rhor, rhosolv; double answer, Vpoly; double Pi,lolim,uplim,summ,yyy,rad,AR,Rsqr,Rsqrsumm,Rsqryyy; scale = dp[0]; radius = dp[1]; sigma = dp[2]; //sigma is the standard mean deviation length = dp[3]; radthick = dp[4]; facthick= dp[5]; rhoc = dp[6]; rhoh = dp[7]; rhor=dp[8]; rhosolv = dp[9]; bkg = dp[10]; Pi = 4.0*atan(1.0); lolim = exp(log(radius)-(4.*sigma)); if (lolim<0.0) { lolim=0.0; //to avoid numerical error when va<0 (-ve r value) } uplim = exp(log(radius)+(4.*sigma)); summ = 0.0; Rsqrsumm = 0.0; for(i=0;i