Index: sansmodels/src/sans/models/SCCrystalModel.py
===================================================================
--- sansmodels/src/sans/models/SCCrystalModel.py	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/SCCrystalModel.py	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
@@ -0,0 +1,182 @@
+#!/usr/bin/env python
+
+##############################################################################
+#	This software was developed by the University of Tennessee as part of the
+#	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+#	project funded by the US National Science Foundation.
+#
+#	If you use DANSE applications to do scientific research that leads to
+#	publication, we ask that you acknowledge the use of the software with the
+#	following sentence:
+#
+#	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+#
+#	copyright 2008, University of Tennessee
+##############################################################################
+
+
+""" 
+Provide functionality for a C extension model
+
+:WARNING: THIS FILE WAS GENERATED BY WRAPPERGENERATOR.PY
+         DO NOT MODIFY THIS FILE, MODIFY ..\c_extensions\sc.h
+         AND RE-RUN THE GENERATOR SCRIPT
+
+"""
+
+from sans.models.BaseComponent import BaseComponent
+from sans_extension.c_models import CSCCrystalModel
+import copy    
+    
+class SCCrystalModel(CSCCrystalModel, BaseComponent):
+    """ 
+    Class that evaluates a SCCrystalModel model. 
+    This file was auto-generated from ..\c_extensions\sc.h.
+    Refer to that file and the structure it contains
+    for details of the model.
+    List of default parameters:
+         scale           = 1.0 
+         dnn             = 220.0 [A]
+         d_factor        = 0.06 
+         radius          = 40.0 [A]
+         sldSph          = 3e-006 [1/A^(2)]
+         sldSolv         = 6.3e-006 [1/A^(2)]
+         background      = 0.0 [1/cm]
+         theta           = 0.0 [rad]
+         phi             = 0.0 [rad]
+         psi             = 0.0 [rad]
+
+    """
+        
+    def __init__(self):
+        """ Initialization """
+        
+        # Initialize BaseComponent first, then sphere
+        BaseComponent.__init__(self)
+        CSCCrystalModel.__init__(self)
+        
+        ## Name of the model
+        self.name = "SCCrystalModel"
+        ## Model description
+        self.description ="""P(q)=(scale/Vp)*V_lattice*P(q)*Z(q)+bkg where scale is the volume
+		fraction of sphere,
+		Vp = volume of the primary particle,
+		V_lattice = volume correction for
+		for the crystal structure,
+		P(q)= form factor of the sphere (normalized),
+		Z(q)= paracrystalline structure factor
+		for a simple cubic structure.
+		Parameters;
+		scale: volume fraction of spheres
+		bkg:background, R: radius of sphere
+		dnn: Nearest neighbor distance
+		d_factor: Paracrystal distortion factor
+		radius: radius of the spheres
+		sldSph: SLD of the sphere
+		sldSolv: SLD of the solvent
+		"""
+       
+        ## Parameter details [units, min, max]
+        self.details = {}
+        self.details['scale'] = ['', None, None]
+        self.details['dnn'] = ['[A]', None, None]
+        self.details['d_factor'] = ['', None, None]
+        self.details['radius'] = ['[A]', None, None]
+        self.details['sldSph'] = ['[1/A^(2)]', None, None]
+        self.details['sldSolv'] = ['[1/A^(2)]', None, None]
+        self.details['background'] = ['[1/cm]', None, None]
+        self.details['theta'] = ['[rad]', None, None]
+        self.details['phi'] = ['[rad]', None, None]
+        self.details['psi'] = ['[rad]', None, None]
+
+        ## fittable parameters
+        self.fixed=['radius.width', 'phi.width', 'psi.width', 'theta.width']
+        
+        ## non-fittable parameters
+        self.non_fittable=[]
+        
+        ## parameters with orientation
+        self.orientation_params =['phi', 'psi', 'theta', 'phi.width', 'psi.width', 'theta.width']
+   
+    def clone(self):
+        """ Return a identical copy of self """
+        return self._clone(SCCrystalModel())   
+        
+    def __getstate__(self):
+        """
+        return object state for pickling and copying
+        """
+        model_state = {'params': self.params, 'dispersion': self.dispersion, 'log': self.log}
+        
+        return self.__dict__, model_state
+        
+    def __setstate__(self, state):
+        """
+        create object from pickled state
+        
+        :param state: the state of the current model
+        
+        """
+        
+        self.__dict__, model_state = state
+        self.params = model_state['params']
+        self.dispersion = model_state['dispersion']
+        self.log = model_state['log']
+       	
+   
+    def run(self, x=0.0):
+        """ 
+        Evaluate the model
+        
+        :param x: input q, or [q,phi]
+        
+        :return: scattering function P(q)
+        
+        """
+        
+        return CSCCrystalModel.run(self, x)
+   
+    def runXY(self, x=0.0):
+        """ 
+        Evaluate the model in cartesian coordinates
+        
+        :param x: input q, or [qx, qy]
+        
+        :return: scattering function P(q)
+        
+        """
+        
+        return CSCCrystalModel.runXY(self, x)
+        
+    def evalDistribution(self, x=[]):
+        """ 
+        Evaluate the model in cartesian coordinates
+        
+        :param x: input q[], or [qx[], qy[]]
+        
+        :return: scattering function P(q[])
+        
+        """
+        return CSCCrystalModel.evalDistribution(self, x)
+        
+    def calculate_ER(self):
+        """ 
+        Calculate the effective radius for P(q)*S(q)
+        
+        :return: the value of the effective radius
+        
+        """       
+        return CSCCrystalModel.calculate_ER(self)
+        
+    def set_dispersion(self, parameter, dispersion):
+        """
+        Set the dispersion object for a model parameter
+        
+        :param parameter: name of the parameter [string]
+        :param dispersion: dispersion object of type DispersionModel
+        
+        """
+        return CSCCrystalModel.set_dispersion(self, parameter, dispersion.cdisp)
+        
+   
+# End of file
Index: sansmodels/src/sans/models/c_extensions/sc.c
===================================================================
--- sansmodels/src/sans/models/c_extensions/sc.c	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/c_extensions/sc.c	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
@@ -0,0 +1,132 @@
+/*
+ * Scattering model for a SC_ParaCrystal
+ */
+#include "sc.h"
+#include "libSphere.h"
+#include <math.h>
+
+
+/**
+ * Function to evaluate 1D scattering function
+ * @param pars: parameters of the SC_ParaCrystal
+ * @param q: q-value
+ * @return: function value
+ */
+double sc_analytical_1D(SCParameters *pars, double q) {
+	double dp[7];
+	double result;
+
+	dp[0] = pars->scale;
+	dp[1] = pars->dnn;
+	dp[2] = pars->d_factor;
+	dp[3] = pars->radius;
+	dp[4] = pars->sldSph;
+	dp[5] = pars->sldSolv;
+	dp[6] = pars->background;
+
+	result = SC_ParaCrystal(dp, q);
+	// This FIXES a singualrity the kernel in libigor.
+	if ( result == INFINITY || result == NAN){
+		result = pars->background;
+	}
+	return result;
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the SC_ParaCrystal
+ * @param q: q-value
+ * @return: function value
+ */
+double sc_analytical_2DXY(SCParameters *pars, double qx, double qy){
+	double q;
+	q = sqrt(qx*qx+qy*qy);
+	return sc_analytical_2D_scaled(pars, q, qx/q, qy/q);
+}
+
+double sc_analytical_2D(SCParameters *pars, double q, double phi) {
+	return sc_analytical_2D_scaled(pars, q, cos(phi), sin(phi));
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the SCCrystalModel
+ * @param q: q-value
+ * @param q_x: q_x / q
+ * @param q_y: q_y / q
+ * @return: function value
+ */
+double sc_analytical_2D_scaled(SCParameters *pars, double q, double q_x, double q_y) {
+	double a3_x, a3_y, a3_z, a2_x, a2_y, a1_x, a1_y, a1_z;
+	double q_z;
+	double alpha, vol, cos_val_a3, cos_val_a2, cos_val_a1, edgeA, edgeB, edgeC;
+	double a1_dot_q, a2_dot_q,a3_dot_q;
+	double answer;
+	double Pi = 4.0*atan(1.0);
+	double aa, Da, qDa_2, latticeScale, Zq;
+
+	double dp[5];
+	dp[0] = 1.0;
+	dp[1] = pars->radius;
+	dp[2] = pars->sldSph;
+	dp[3] = pars->sldSolv;
+	dp[4] = 0.0;
+
+	aa = pars->dnn;
+	Da = pars->d_factor*aa;
+	qDa_2 = pow(q*Da,2.0);
+
+	latticeScale = (4.0/3.0)*Pi*(dp[1]*dp[1]*dp[1])/pow(aa,3.0);
+	/// Angles here are respect to detector coordinate instead of against q coordinate(PRB 36, 3, 1754)
+    // a3 axis orientation
+    a3_x = sin(pars->theta) * cos(pars->phi);//negative sign here???
+    a3_y = sin(pars->theta) * sin(pars->phi);
+    a3_z = cos(pars->theta);
+
+    // q vector
+    q_z = 0.0;
+
+    // Compute the angle btw vector q and the a3 axis
+    cos_val_a3 = a3_x*q_x + a3_y*q_y + a3_z*q_z;
+    //alpha = acos(cos_val_a3);
+    a3_dot_q = aa*q*cos_val_a3;
+    // a1 axis orientation
+    a1_x = sin(pars->psi);
+    a1_y = cos(pars->psi);
+
+    cos_val_a1 = a1_x*q_x + a1_y*q_y;
+    a1_dot_q = aa*q*cos_val_a1;
+
+    // a2 axis orientation
+    a2_x = sqrt(1-sin(pars->theta)*cos(pars->phi))*cos(pars->psi);
+    a2_y = sqrt(1-sin(pars->theta)*cos(pars->phi))*sin(pars->psi);
+    // a2 axis
+    cos_val_a2 = sin(acos(cos_val_a1)) ;
+    a2_dot_q = aa*q*cos_val_a2;
+
+    // The following test should always pass
+    if (fabs(cos_val_a3)>1.0) {
+    	printf("parallel_ana_2D: Unexpected error: cos(alpha)>1\n");
+     	return 0;
+    }
+    // Call Zq=Z1*Z2*Z3
+    Zq = (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a1_dot_q)+exp(-qDa_2));
+    Zq = Zq * (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a2_dot_q)+exp(-qDa_2));
+    Zq = Zq * (1.0-exp(-qDa_2))/(1.0-2.0*exp(-0.5*qDa_2)*cos(a3_dot_q)+exp(-qDa_2));
+
+	// Use SphereForm directly from libigor
+	answer = SphereForm(dp,q)*Zq;
+
+	//consider scales
+	answer *= latticeScale * pars->scale;
+
+	// This FIXES a singualrity the kernel in libigor.
+	if ( answer == INFINITY || answer == NAN){
+		answer = 0.0;
+	}
+
+	// add background
+	answer += pars->background;
+
+	return answer;
+}
Index: sansmodels/src/sans/models/c_extensions/sc.h
===================================================================
--- sansmodels/src/sans/models/c_extensions/sc.h	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/c_extensions/sc.h	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
@@ -0,0 +1,80 @@
+#if !defined(sc_h)
+#define sc_h
+
+/**
+ * Structure definition for SC_ParaCrystal parameters
+ */
+ //[PYTHONCLASS] = SCCrystalModel
+ //[DISP_PARAMS] = radius,phi, psi, theta
+ //[DESCRIPTION] =<text>P(q)=(scale/Vp)*V_lattice*P(q)*Z(q)+bkg where scale is the volume
+ //					 fraction of sphere,
+ //				Vp = volume of the primary particle,
+ //				V_lattice = volume correction for
+ //					for the crystal structure,
+ //				P(q)= form factor of the sphere (normalized),
+ //				Z(q)= paracrystalline structure factor
+ //					for a simple cubic structure.
+ //				Parameters;
+ //				scale: volume fraction of spheres
+ //				bkg:background, R: radius of sphere
+ //				dnn: Nearest neighbor distance
+ //				d_factor: Paracrystal distortion factor
+ //				radius: radius of the spheres
+ //				sldSph: SLD of the sphere
+ //				sldSolv: SLD of the solvent
+ //
+ //		</text>
+ //[FIXED]=  radius.width;phi.width;psi.width; theta.width
+ //[ORIENTATION_PARAMS]= <text> phi;psi; theta; phi.width;psi.width; theta.width</text>
+
+typedef struct {
+    /// Scale factor
+    //  [DEFAULT]=scale= 1.0
+    double scale;
+
+    ///	Nearest neighbor distance [A]
+    //  [DEFAULT]=dnn=220.0 [A]
+    double dnn;
+
+    ///	Paracrystal distortion factor g
+    //  [DEFAULT]=d_factor=0.06
+    double d_factor;
+
+    ///	Radius of sphere [A]
+    //  [DEFAULT]=radius=40.0 [A]
+    double radius;
+
+    ///	sldSph [1/A^(2)]
+    //  [DEFAULT]=sldSph= 3.0e-6 [1/A^(2)]
+    double sldSph;
+
+    ///	sldSolv [1/A^(2)]
+    //  [DEFAULT]=sldSolv= 6.3e-6 [1/A^(2)]
+    double sldSolv;
+
+	/// Incoherent Background [1/cm]
+	//  [DEFAULT]=background=0 [1/cm]
+	double background;
+    /// Orientation of the a1 axis w/respect incoming beam [rad]
+    //  [DEFAULT]=theta=0.0 [rad]
+    double theta;
+    /// Orientation of the a2 in the plane of the detector [rad]
+    //  [DEFAULT]=phi=0.0 [rad]
+    double phi;
+    /// Orientation of the a3 in the plane of the detector [rad]
+    //  [DEFAULT]=psi=0.0 [rad]
+    double psi;
+
+} SCParameters;
+
+
+
+/// 1D scattering function
+double sc_analytical_1D(SCParameters *pars, double q);
+
+/// 2D scattering function
+double sc_analytical_2D(SCParameters *pars, double q, double phi);
+double sc_analytical_2DXY(SCParameters *pars, double qx, double qy);
+double sc_analytical_2D_scaled(SCParameters *pars, double q, double q_x, double q_y);
+
+#endif
Index: sansmodels/src/sans/models/c_models/c_models.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/c_models.cpp	(revision 35aface36aa7573475600ebbacb987f50386d5f8)
+++ sansmodels/src/sans/models/c_models/c_models.cpp	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
@@ -20,4 +20,5 @@
 void addCHardsphereStructure(PyObject *module);
 void addCStickyHSStructure(PyObject *module);
+void addCSCCrystalModel(PyObject *module);
 void addCSquareWellStructure(PyObject *module);
 void addCHayterMSAStructure(PyObject *module);
@@ -229,4 +230,5 @@
 	addCHardsphereStructure(m);
 	addCStickyHSStructure(m);
+	addCSCCrystalModel(m);
 	addCSquareWellStructure(m);
 	addCHayterMSAStructure(m);
Index: sansmodels/src/sans/models/c_models/models.hh
===================================================================
--- sansmodels/src/sans/models/c_models/models.hh	(revision 35aface36aa7573475600ebbacb987f50386d5f8)
+++ sansmodels/src/sans/models/c_models/models.hh	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
@@ -278,4 +278,29 @@
 	// Constructor
 	SphereModel();
+
+	// Operators to get I(Q)
+	double operator()(double q);
+	double operator()(double qx, double qy);
+	double calculate_ER();
+	double evaluate_rphi(double q, double phi);
+};
+
+
+class SCCrystalModel{
+public:
+	// Model parameters
+	Parameter scale;
+	Parameter dnn;
+	Parameter d_factor;
+	Parameter radius;
+	Parameter sldSph;
+	Parameter sldSolv;
+	Parameter background;
+	Parameter theta;
+	Parameter phi;
+	Parameter psi;
+
+	// Constructor
+	SCCrystalModel();
 
 	// Operators to get I(Q)
Index: sansmodels/src/sans/models/c_models/sc.cpp
===================================================================
--- sansmodels/src/sans/models/c_models/sc.cpp	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
+++ sansmodels/src/sans/models/c_models/sc.cpp	(revision 94a3f8f49326fa54618105cf9c371ebe39bb3dda)
@@ -0,0 +1,214 @@
+/**
+	This software was developed by the University of Tennessee as part of the
+	Distributed Data Analysis of Neutron Scattering Experiments (DANSE)
+	project funded by the US National Science Foundation.
+
+	If you use DANSE applications to do scientific research that leads to
+	publication, we ask that you acknowledge the use of the software with the
+	following sentence:
+
+	"This work benefited from DANSE software developed under NSF award DMR-0520547."
+
+	copyright 2008, University of Tennessee
+ */
+
+/**
+ * Scattering model classes
+ * The classes use the IGOR library found in
+ *   sansmodels/src/libigor
+ *
+ */
+
+#include <math.h>
+#include "models.hh"
+#include "parameters.hh"
+#include <stdio.h>
+using namespace std;
+
+extern "C" {
+	#include "libSphere.h"
+	#include "sc.h"
+}
+
+SCCrystalModel :: SCCrystalModel() {
+	scale      = Parameter(1.0);
+	dnn		= Parameter(220.0);
+	d_factor = Parameter(0.06);
+	radius     = Parameter(40.0, true);
+	radius.set_min(0.0);
+	sldSph   = Parameter(3.0e-6);
+	sldSolv   = Parameter(6.3e-6);
+	background = Parameter(0.0);
+	theta  = Parameter(0.0, true);
+	phi    = Parameter(0.0, true);
+	psi    = Parameter(0.0, true);
+}
+
+/**
+ * Function to evaluate 1D scattering function
+ * The NIST IGOR library is used for the actual calculation.
+ * @param q: q-value
+ * @return: function value
+ */
+double SCCrystalModel :: operator()(double q) {
+	double dp[7];
+
+	// Fill parameter array for IGOR library
+	// Add the background after averaging
+	dp[0] = scale();
+	dp[1] = dnn();
+	dp[2] = d_factor();
+	dp[3] = radius();
+	dp[4] = sldSph();
+	dp[5] = sldSolv();
+	dp[6] = 0.0;
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_rad;
+	radius.get_weights(weights_rad);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+	double vol = 0.0;
+	double result;
+
+	// Loop over radius weight points
+	for(int i=0; i<weights_rad.size(); i++) {
+		dp[3] = weights_rad[i].value;
+
+		//Un-normalize SphereForm by volume
+		result = SC_ParaCrystal(dp, q) * pow(weights_rad[i].value,3);
+		// This FIXES a singualrity the kernel in libigor.
+		if ( result == INFINITY || result == NAN){
+			result = 0.0;
+		}
+		sum += weights_rad[i].weight
+			* result;
+		//Find average volume
+		vol += weights_rad[i].weight
+			* pow(weights_rad[i].value,3);
+
+		norm += weights_rad[i].weight;
+	}
+
+	if (vol != 0.0 && norm != 0.0) {
+		//Re-normalize by avg volume
+		sum = sum/(vol/norm);}
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param q_x: value of Q along x
+ * @param q_y: value of Q along y
+ * @return: function value
+ */
+double SCCrystalModel :: operator()(double qx, double qy) {
+	SCParameters dp;
+	double q = sqrt(qx*qx + qy*qy);
+	dp.scale      = scale();
+	dp.dnn   = dnn();
+	dp.d_factor   = d_factor();
+	dp.radius  = radius();
+	dp.sldSph   = sldSph();
+	dp.sldSolv   = sldSolv();
+	dp.background = 0.0;
+	dp.theta  = theta();
+	dp.phi    = phi();
+	dp.psi    = psi();
+
+	// Get the dispersion points for the radius
+	vector<WeightPoint> weights_rad;
+	radius.get_weights(weights_rad);
+
+	// Get angular averaging for theta
+	vector<WeightPoint> weights_theta;
+	theta.get_weights(weights_theta);
+
+	// Get angular averaging for phi
+	vector<WeightPoint> weights_phi;
+	phi.get_weights(weights_phi);
+
+	// Get angular averaging for psi
+	vector<WeightPoint> weights_psi;
+	psi.get_weights(weights_psi);
+
+	// Perform the computation, with all weight points
+	double sum = 0.0;
+	double norm = 0.0;
+	double norm_vol = 0.0;
+	double vol = 0.0;
+
+	// Loop over radius weight points
+	for(int i=0; i<weights_rad.size(); i++) {
+		dp.radius = weights_rad[i].value;
+		// Average over theta distribution
+		for(int j=0; j< weights_theta.size(); j++) {
+			dp.theta = weights_theta[j].value;
+			// Average over phi distribution
+			for(int k=0; k< weights_phi.size(); k++) {
+				dp.phi = weights_phi[k].value;
+				// Average over phi distribution
+				for(int l=0; l< weights_psi.size(); l++) {
+					dp.psi = weights_psi[l].value;
+					//Un-normalize SphereForm by volume
+					double _ptvalue = weights_rad[i].weight
+										* weights_theta[j].weight
+										* weights_phi[k].weight
+										* weights_psi[l].weight
+										* sc_analytical_2DXY(&dp, qx, qy);
+										//* pow(weights_rad[i].value,3.0);
+					// Consider when there is infinte or nan.
+					if ( _ptvalue == INFINITY || _ptvalue == NAN){
+						_ptvalue = 0.0;
+					}
+					if (weights_theta.size()>1) {
+						_ptvalue *= sin(weights_theta[j].value);
+					}
+					sum += _ptvalue;
+					// This model dose not need the volume of spheres correction!!!
+					//Find average volume
+					//vol += weights_rad[i].weight
+					//	* pow(weights_rad[i].value,3);
+					//Find norm for volume
+					//norm_vol += weights_rad[i].weight;
+
+					norm += weights_rad[i].weight
+							* weights_theta[j].weight
+							* weights_phi[k].weight
+							* weights_psi[l].weight;
+				}
+			}
+		}
+	}
+	// Averaging in theta needs an extra normalization
+	// factor to account for the sin(theta) term in the
+	// integration (see documentation).
+	if (weights_theta.size()>1) norm = norm / asin(1.0);
+
+	if (vol != 0.0 && norm_vol != 0.0) {
+		//Re-normalize by avg volume
+		sum = sum/(vol/norm_vol);}
+
+	return sum/norm + background();
+}
+
+/**
+ * Function to evaluate 2D scattering function
+ * @param pars: parameters of the SCCrystal
+ * @param q: q-value
+ * @param phi: angle phi
+ * @return: function value
+ */
+double SCCrystalModel :: evaluate_rphi(double q, double phi) {
+	return (*this).operator()(q);
+}
+
+/**
+ * Function to calculate effective radius
+ * @return: effective radius value
+ */
+double SCCrystalModel :: calculate_ER() {
+	//NOT implemented yet!!!
+}
