Index: src/sas/calculator/sans_gen.py
===================================================================
--- src/sas/calculator/sans_gen.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,1170 +1,0 @@
-"""
-SANS generic computation and sld file readers
-"""
-from sas.models.BaseComponent import BaseComponent
-import sas.models.sas_extension.sld2i as mod
-from periodictable import formula
-from periodictable import nsf
-import numpy
-import os
-import copy
-
-MFactor_AM = 2.853E-12
-MFactor_mT = 2.3164E-9
-METER2ANG = 1.0E+10
-#Avogadro constant [1/mol]
-NA = 6.02214129e+23
-
-def mag2sld(mag, v_unit=None):
-    """
-    Convert magnetization to magnatic SLD
-    sldm = Dm * mag where Dm = gamma * classical elec. radius/(2*Bohr magneton)
-    Dm ~ 2.853E-12 [A^(-2)] ==> Shouldn't be 2.90636E-12 [A^(-2)]???
-    """ 
-    if v_unit == "A/m":
-        factor = MFactor_AM
-    elif v_unit == "mT":
-        factor = MFactor_mT
-    else:
-        raise ValueError, "Invalid valueunit"
-    sld_m = factor * mag
-    return sld_m
-
-def transform_center(pos_x, pos_y, pos_z):
-    """
-    re-center 
-    
-    :return: posx, posy, posz   [arrays]
-    """ 
-    posx = pos_x - (min(pos_x) + max(pos_x)) / 2.0
-    posy = pos_y - (min(pos_y) + max(pos_y)) / 2.0
-    posz = pos_z - (min(pos_z) + max(pos_z)) / 2.0  
-    return posx, posy, posz   
-
-class GenSAS(BaseComponent):
-    """
-    Generic SAS computation Model based on sld (n & m) arrays
-    """
-    def __init__(self):
-        """
-        Init
-        
-        :Params sld_data: MagSLD object
-        """
-        # Initialize BaseComponent
-        BaseComponent.__init__(self)
-        self.sld_data = None
-        self.data_pos_unit = None
-        self.data_x = None
-        self.data_y = None
-        self.data_z = None
-        self.data_sldn = None
-        self.data_mx = None
-        self.data_my = None
-        self.data_mz = None
-        self.data_vol = None #[A^3]
-        self.is_avg = False
-        ## Name of the model
-        self.name = "GenSAS"
-        ## Define parameters
-        self.params = {}
-        self.params['scale']       = 1.0
-        self.params['background']  = 0.0
-        self.params['solvent_SLD']     = 0.0
-        self.params['total_volume'] = 1.0
-        self.params['Up_frac_in']     = 1.0
-        self.params['Up_frac_out']    = 1.0
-        self.params['Up_theta']  = 0.0
-        self.description = 'GenSAS'
-        ## Parameter details [units, min, max]
-        self.details = {}
-        self.details['scale']      = ['', None, None]
-        self.details['background'] = ['[1/cm]', None, None]
-        self.details['solvent_SLD']    = ['1/A^(2)', None, None]
-        self.details['total_volume']    = ['A^(3)', None, None]
-        self.details['Up_frac_in']    = ['[u/(u+d)]', None, None]
-        self.details['Up_frac_out']   = ['[u/(u+d)]', None, None]
-        self.details['Up_theta'] = ['[deg]', None, None]
-        # fixed parameters
-        self.fixed = []
-        
-    def set_pixel_volumes(self, volume):     
-        """
-        Set the volume of a pixel in (A^3) unit
-        :Param volume: pixel volume [float]
-        """
-        if self.data_vol == None:
-            raise
-        self.data_vol = volume
-    
-    def set_is_avg(self, is_avg=False):  
-        """
-        Sets is_avg: [bool]
-        """
-        self.is_avg = is_avg
-          
-    def _gen(self, x, y, i):
-        """
-        Evaluate the function
-        :Param x: array of x-values
-        :Param y: array of y-values
-        :Param i: array of initial i-value 
-        :return: function value
-        """
-        pos_x = self.data_x
-        pos_y = self.data_y
-        pos_z = self.data_z
-        len_x = len(pos_x)
-        if self.is_avg == None:
-            len_x *= -1
-            pos_x, pos_y, pos_z = transform_center(pos_x, pos_y, pos_z)
-        len_q = len(x)
-        sldn = copy.deepcopy(self.data_sldn)
-        sldn -= self.params['solvent_SLD']
-        model = mod.new_GenI(len_x, pos_x, pos_y, pos_z, 
-                             sldn, self.data_mx, self.data_my, 
-                             self.data_mz, self.data_vol,
-                             self.params['Up_frac_in'], 
-                             self.params['Up_frac_out'], 
-                             self.params['Up_theta'])
-        if y == []:
-            mod.genicom(model, len_q, x, i)
-        else:
-            mod.genicomXY(model, len_q, x, y, i)
-        vol_correction = self.data_total_volume / self.params['total_volume']
-        return  self.params['scale'] * vol_correction * i + \
-                        self.params['background']
-        
-    def set_sld_data(self, sld_data=None):   
-        """
-        Sets sld_data
-        """
-        self.sld_data = sld_data
-        self.data_pos_unit = sld_data.pos_unit
-        self.data_x = sld_data.pos_x
-        self.data_y = sld_data.pos_y
-        self.data_z = sld_data.pos_z
-        self.data_sldn = sld_data.sld_n
-        self.data_mx = sld_data.sld_mx
-        self.data_my = sld_data.sld_my
-        self.data_mz = sld_data.sld_mz
-        self.data_vol = sld_data.vol_pix
-        self.data_total_volume = sum(sld_data.vol_pix)
-        self.params['total_volume'] = sum(sld_data.vol_pix)
-        
-    def getProfile(self):
-        """
-        Get SLD profile 
-        
-        : return: sld_data
-        """
-        return self.sld_data
-     
-    def run(self, x = 0.0):
-        """ 
-        Evaluate the model
-        :param x: simple value
-        :return: (I value)
-        """
-        if x.__class__.__name__ == 'list':
-            if len(x[1]) > 0:
-                msg = "Not a 1D."
-                raise ValueError, msg
-            i_out = numpy.zeros_like(x[0])
-            # 1D I is found at y =0 in the 2D pattern
-            out = self._gen(x[0], [], i_out )
-            return out
-        else:
-            msg = "Q must be given as list of qx's and qy's"
-            raise ValueError, msg
-   
-    def runXY(self, x = 0.0):
-        """ 
-        Evaluate the model
-        :param x: simple value
-        :return: I value
-        :Use this runXY() for the computation
-        """
-        if x.__class__.__name__ == 'list':
-            i_out = numpy.zeros_like(x[0])
-            out = self._gen(x[0], x[1], i_out)
-            return out
-        else:
-            msg = "Q must be given as list of qx's and qy's"
-            raise ValueError, msg
-        
-    def evalDistribution(self, qdist):
-        """
-        Evaluate a distribution of q-values.
-        * For 1D, a numpy array is expected as input: evalDistribution(q) where q is a numpy array.
-        * For 2D, a list of numpy arrays are expected: [qx_prime,qy_prime], where 1D arrays.
-        :param qdist: ndarray of scalar q-values or list [qx,qy] where qx,qy are 1D ndarrays 
-        """
-        if qdist.__class__.__name__ == 'list':
-            if len(qdist[1]) < 1:
-                out = self.run(qdist)
-            else:
-                out = self.runXY(qdist)
-            return out
-        else:
-            mesg = "evalDistribution is expecting an ndarray of "
-            mesg += "a list [qx,qy] where qx,qy are arrays."
-            raise RuntimeError, mesg
-      
-class OMF2SLD:
-    """
-    Convert OMFData to MAgData
-    """
-    def __init__(self): 
-        """
-        Init
-        """
-        self.pos_x = None
-        self.pos_y = None
-        self.pos_z = None
-        self.mx = None
-        self.my = None
-        self.mz = None
-        self.sld_n = None
-        self.vol_pix = None
-        self.output = None
-        self.omfdata = None
-    
-    def set_data(self, omfdata, shape='rectangular'):
-        """
-        Set all data
-        """
-        self.omfdata = omfdata
-        length = int(omfdata.xnodes * omfdata.ynodes * omfdata.znodes)
-        pos_x = numpy.arange(omfdata.xmin, 
-                             omfdata.xnodes*omfdata.xstepsize + omfdata.xmin, 
-                             omfdata.xstepsize)
-        pos_y = numpy.arange(omfdata.ymin,  
-                             omfdata.ynodes*omfdata.ystepsize + omfdata.ymin, 
-                             omfdata.ystepsize)
-        pos_z = numpy.arange(omfdata.zmin, 
-                             omfdata.znodes*omfdata.zstepsize + omfdata.zmin, 
-                             omfdata.zstepsize)
-        self.pos_x = numpy.tile(pos_x, int(omfdata.ynodes * omfdata.znodes))
-        self.pos_y = pos_y.repeat(int(omfdata.xnodes))
-        self.pos_y = numpy.tile(self.pos_y, int(omfdata.znodes))
-        self.pos_z = pos_z.repeat(int(omfdata.xnodes * omfdata.ynodes))
-        self.mx = omfdata.mx
-        self.my = omfdata.my
-        self.mz = omfdata.mz
-        self.sld_n = numpy.zeros(length)
-            
-        if omfdata.mx == None:
-            self.mx = numpy.zeros(length)
-        if omfdata.my == None:
-            self.my = numpy.zeros(length)
-        if omfdata.mz == None:
-            self.mz = numpy.zeros(length)
-        
-        self._check_data_length(length)
-        self.remove_null_points(False, False)
-        mask = numpy.ones(len(self.sld_n), dtype=bool)
-        if shape.lower() == 'ellipsoid':
-            try:
-                # Pixel (step) size included
-                x_c = max(self.pos_x) + min(self.pos_x)
-                y_c = max(self.pos_y) + min(self.pos_y)
-                z_c = max(self.pos_z) + min(self.pos_z)
-                x_d = max(self.pos_x) - min(self.pos_x)
-                y_d = max(self.pos_y) - min(self.pos_y)
-                z_d = max(self.pos_z) - min(self.pos_z)
-                x_r = (x_d + omfdata.xstepsize) / 2.0
-                y_r = (y_d + omfdata.ystepsize) / 2.0
-                z_r = (z_d + omfdata.zstepsize) / 2.0
-                x_dir2 = ((self.pos_x - x_c / 2.0) / x_r)
-                x_dir2 *= x_dir2
-                y_dir2 = ((self.pos_y - y_c / 2.0) / y_r)
-                y_dir2 *= y_dir2
-                z_dir2 = ((self.pos_z - z_c / 2.0) / z_r)
-                z_dir2 *= z_dir2
-                mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0
-            except:
-                pass
-        self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 
-                             self.pos_z[mask], self.sld_n[mask], 
-                             self.mx[mask], self.my[mask], self.mz[mask])
-        self.output.set_pix_type('pixel')
-        self.output.set_pixel_symbols('pixel')
-        
-    def get_omfdata(self):
-        """
-        Return all data
-        """
-        return self.omfdata
-    
-    def get_output(self):
-        """
-        Return output
-        """
-        return self.output
-    
-    def _check_data_length(self, length):
-        """
-        Check if the data lengths are consistent
-        :Params length: data length
-        """
-        msg = "Error: Inconsistent data length."
-        if len(self.pos_x) != length:
-            raise ValueError, msg
-        if len(self.pos_y) != length:
-            raise ValueError, msg
-        if len(self.pos_z) != length:
-            raise ValueError, msg
-        if len(self.mx) != length:
-            raise ValueError, msg
-        if len(self.my) != length:
-            raise ValueError, msg
-        if len(self.mz) != length:
-            raise ValueError, msg
-        
-    def remove_null_points(self, remove=False, recenter=False):
-        """
-        Removes any mx, my, and mz = 0 points
-        """
-        if remove:
-            is_nonzero = (numpy.fabs(self.mx) + numpy.fabs(self.my) + 
-                          numpy.fabs(self.mz)).nonzero()  
-            if len(is_nonzero[0]) > 0: 
-                self.pos_x = self.pos_x[is_nonzero]
-                self.pos_y = self.pos_y[is_nonzero]
-                self.pos_z = self.pos_z[is_nonzero]
-                self.sld_n = self.sld_n[is_nonzero]
-                self.mx = self.mx[is_nonzero]
-                self.my = self.my[is_nonzero]
-                self.mz = self.mz[is_nonzero]
-        if recenter:
-            self.pos_x -= (min(self.pos_x) + max(self.pos_x)) / 2.0
-            self.pos_y -= (min(self.pos_y) + max(self.pos_y)) / 2.0
-            self.pos_z -= (min(self.pos_z) + max(self.pos_z)) / 2.0
- 
-    def get_magsld(self):
-        """
-        return MagSLD
-        """
-        return self.output
-    
-        
-class OMFReader:
-    """
-    Class to load omf/ascii files (3 columns w/header).
-    """
-    ## File type
-    type_name = "OMF ASCII"
-    
-    ## Wildcards
-    type = ["OMF files (*.OMF, *.omf)|*.omf"]
-    ## List of allowed extensions
-    ext = ['.omf', '.OMF']
-        
-    def read(self, path):
-        """
-        Load data file
-        :param path: file path
-        :return: x, y, z, sld_n, sld_mx, sld_my, sld_mz
-        """
-        #data_conv_m = None
-        desc = ""
-        mx = numpy.zeros(0)
-        my = numpy.zeros(0)
-        mz = numpy.zeros(0)
-        try:
-            data_conv_val = None
-            data_conv_mesh = None
-            input_f = open(path, 'rb')
-            buff = input_f.read()
-            lines = buff.split('\n')
-            input_f.close()
-            output = OMFData()
-            valueunit = None
-            for line in lines:
-                toks = line.split()
-                # Read data
-                try:
-                    _mx = float(toks[0])
-                    _my = float(toks[1])
-                    _mz = float(toks[2])
-                    _mx = mag2sld(_mx, valueunit)
-                    _my = mag2sld(_my, valueunit)
-                    _mz = mag2sld(_mz, valueunit)
-                    mx = numpy.append(mx, _mx)
-                    my = numpy.append(my, _my)
-                    mz = numpy.append(mz, _mz)
-                except:
-                    # Skip non-data lines
-                    pass
-                #Reading Header; Segment count ignored
-                s_line = line.split(":", 1)
-                if s_line[0].lower().count("oommf") > 0:
-                    oommf = s_line[1].lstrip()
-                if s_line[0].lower().count("title") > 0:
-                    title = s_line[1].lstrip()
-                if s_line[0].lower().count("desc") > 0:
-                    desc += s_line[1].lstrip()
-                    desc += '\n'
-                if s_line[0].lower().count("meshtype") > 0:
-                    meshtype = s_line[1].lstrip()
-                if s_line[0].lower().count("meshunit") > 0:
-                    meshunit = s_line[1].lstrip()
-                    if meshunit.count("m") < 1:
-                        msg = "Error: \n"
-                        msg += "We accept only m as meshunit"
-                        raise ValueError, msg
-                if s_line[0].lower().count("xbase") > 0:
-                    xbase = s_line[1].lstrip()
-                if s_line[0].lower().count("ybase") > 0:
-                    ybase = s_line[1].lstrip()
-                if s_line[0].lower().count("zbase") > 0:
-                    zbase = s_line[1].lstrip()
-                if s_line[0].lower().count("xstepsize") > 0:
-                    xstepsize = s_line[1].lstrip()
-                if s_line[0].lower().count("ystepsize") > 0:
-                    ystepsize = s_line[1].lstrip()
-                if s_line[0].lower().count("zstepsize") > 0:
-                    zstepsize = s_line[1].lstrip()
-                if s_line[0].lower().count("xnodes") > 0:
-                    xnodes = s_line[1].lstrip()
-                if s_line[0].lower().count("ynodes") > 0:
-                    ynodes = s_line[1].lstrip()
-                if s_line[0].lower().count("znodes") > 0:
-                    znodes = s_line[1].lstrip()
-                if s_line[0].lower().count("xmin") > 0:
-                    xmin = s_line[1].lstrip()
-                if s_line[0].lower().count("ymin") > 0:
-                    ymin = s_line[1].lstrip()
-                if s_line[0].lower().count("zmin") > 0:
-                    zmin = s_line[1].lstrip()
-                if s_line[0].lower().count("xmax") > 0:
-                    xmax = s_line[1].lstrip()
-                if s_line[0].lower().count("ymax") > 0:
-                    ymax = s_line[1].lstrip()
-                if s_line[0].lower().count("zmax") > 0:
-                    zmax = s_line[1].lstrip()
-                if s_line[0].lower().count("valueunit") > 0:
-                    valueunit = s_line[1].lstrip().rstrip()
-                if s_line[0].lower().count("valuemultiplier") > 0:
-                    valuemultiplier = s_line[1].lstrip()
-                if s_line[0].lower().count("valuerangeminmag") > 0:
-                    valuerangeminmag = s_line[1].lstrip()
-                if s_line[0].lower().count("valuerangemaxmag") > 0:
-                    valuerangemaxmag = s_line[1].lstrip()
-                if s_line[0].lower().count("end") > 0:
-                    #output.set_sldms(mx, my, mz)    
-                    output.filename = os.path.basename(path)
-                    output.oommf = oommf
-                    output.title = title
-                    output.desc = desc
-                    output.meshtype = meshtype
-                    output.xbase = float(xbase) * METER2ANG
-                    output.ybase = float(ybase) * METER2ANG
-                    output.zbase = float(zbase) * METER2ANG
-                    output.xstepsize = float(xstepsize) * METER2ANG
-                    output.ystepsize = float(ystepsize) * METER2ANG
-                    output.zstepsize = float(zstepsize) * METER2ANG
-                    output.xnodes = float(xnodes)
-                    output.ynodes = float(ynodes)
-                    output.znodes = float(znodes)
-                    output.xmin = float(xmin) * METER2ANG
-                    output.ymin = float(ymin) * METER2ANG
-                    output.zmin = float(zmin) * METER2ANG
-                    output.xmax = float(xmax) * METER2ANG
-                    output.ymax = float(ymax) * METER2ANG
-                    output.zmax = float(zmax) * METER2ANG
-                    output.valuemultiplier = valuemultiplier
-                    output.valuerangeminmag = mag2sld(float(valuerangeminmag), \
-                                                      valueunit)
-                    output.valuerangemaxmag = mag2sld(float(valuerangemaxmag), \
-                                                      valueunit)
-            output.set_m(mx, my, mz)
-            return output
-        except:
-            msg = "%s is not supported: \n" % path
-            msg += "We accept only Text format OMF file."
-            raise RuntimeError, msg
-
-class PDBReader:
-    """
-    PDB reader class: limited for reading the lines starting with 'ATOM'
-    """
-    type_name = "PDB"
-    ## Wildcards
-    type = ["pdb files (*.PDB, *.pdb)|*.pdb"]
-    ## List of allowed extensions
-    ext = ['.pdb', '.PDB']   
-    
-    def read(self, path):
-        """
-        Load data file
-        
-        :param path: file path
-        
-        :return: MagSLD
-        
-        :raise RuntimeError: when the file can't be opened
-        """
-        pos_x = numpy.zeros(0)
-        pos_y = numpy.zeros(0)
-        pos_z = numpy.zeros(0)
-        sld_n = numpy.zeros(0)
-        sld_mx = numpy.zeros(0)
-        sld_my = numpy.zeros(0)
-        sld_mz = numpy.zeros(0)
-        vol_pix = numpy.zeros(0)
-        pix_symbol = numpy.zeros(0)
-        x_line = []
-        y_line = []
-        z_line = []
-        x_lines = []
-        y_lines = []
-        z_lines = []        
-        try:
-            input_f = open(path, 'rb')
-            buff = input_f.read()
-            lines = buff.split('\n')
-            input_f.close()
-            pre_num = 0
-            num = 0
-            for line in lines:
-                try:
-                    # check if line starts with "ATOM"
-                    if line[0:6].strip().count('ATM') > 0 or \
-                                line[0:6].strip() == 'ATOM':
-                        # define fields of interest
-                        atom_id = line[6:11].strip()
-                        atom_name = line[12:16].strip()
-                        try:
-                            float(line[12])
-                            atom_name = atom_name[1].upper()
-                        except:
-                            if len(atom_name) == 4:
-                                atom_name = atom_name[0].upper()
-                            elif line[12] != ' ': 
-                                atom_name = atom_name[0].upper() + \
-                                        atom_name[1].lower() 
-                            else:
-                                atom_name = atom_name[0].upper()
-                        #res_name = line[17:20].strip()
-                        #chain_name = line[21:22].strip()
-                        _pos_x = float(line[30:38].strip())
-                        _pos_y = float(line[38:46].strip())
-                        _pos_z = float(line[46:54].strip())
-                        
-                        pos_x = numpy.append(pos_x, _pos_x)
-                        pos_y = numpy.append(pos_y, _pos_y)
-                        pos_z = numpy.append(pos_z, _pos_z)
-                        try:
-                            # sld in Ang unit (from fm)
-                            #val = formula(atom_name).atoms.keys()[0].neutron.b_c
-                            #val *= 1.0e-5
-                            val = nsf.neutron_sld(atom_name)[0]
-                            # sld in Ang^-2 unit
-                            val *= 1.0e-6
-                            sld_n = numpy.append(sld_n, val)
-                            atom = formula(atom_name)
-                            # cm to A units
-                            vol = 1.0e+24 * atom.mass / atom.density / NA
-                            vol_pix = numpy.append(vol_pix, vol)
-                        except:
-                            print "Error: set the sld of %s to zero"% atom_name
-                            sld_n = numpy.append(sld_n,  0.0)                     
-                        sld_mx = numpy.append(sld_mx, 0)
-                        sld_my = numpy.append(sld_my, 0)
-                        sld_mz = numpy.append(sld_mz, 0)
-                        pix_symbol = numpy.append(pix_symbol, atom_name)
-                    elif line[0:6].strip().count('CONECT') > 0 :
-                        toks = line.split()
-                        num = int(toks[1]) - 1  
-                        val_list = [] 
-                        for val in toks[2:]:
-                            try:
-                                int_val = int(val)
-                            except:
-                                break
-                            if int_val == 0:
-                                break
-                            val_list.append(int_val)
-                        #need val_list ordered      
-                        for val in val_list:
-                            index = val - 1
-                            if (pos_x[index], pos_x[num]) in x_line and \
-                               (pos_y[index], pos_y[num]) in y_line and \
-                               (pos_z[index], pos_z[num]) in z_line:
-                                continue
-                            x_line.append((pos_x[num], pos_x[index]))
-                            y_line.append((pos_y[num], pos_y[index]))
-                            z_line.append((pos_z[num], pos_z[index]))
-                    if len(x_line) > 0:
-                        x_lines.append(x_line) 
-                        y_lines.append(y_line)
-                        z_lines.append(z_line)            
-                except:
-                    pass
-            #re-centering
-            #pos_x -= (min(pos_x) + max(pos_x)) / 2.0
-            #pos_y -= (min(pos_y) + max(pos_y)) / 2.0
-            #pos_z -= (min(pos_z) + max(pos_z)) / 2.0
-            
-            output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz)
-            output.set_conect_lines(x_line, y_line, z_line)
-            output.filename = os.path.basename(path)
-            output.set_pix_type('atom')
-            output.set_pixel_symbols(pix_symbol)
-            output.set_nodes()
-            output.set_pixel_volumes(vol_pix)
-            output.sld_unit = '1/A^(2)'
-            return output
-        except:
-            RuntimeError, "%s is not a sld file" % path
-
-    def write(self, path, data):
-        """
-        Write
-        """
-        #Not implemented 
-        print "Not implemented... "
-
-class SLDReader:
-    """
-    Class to load ascii files (7 columns).
-    """
-    ## File type
-    type_name = "SLD ASCII"
-    
-    ## Wildcards
-    type = ["sld files (*.SLD, *.sld)|*.sld",
-            "txt files (*.TXT, *.txt)|*.txt",
-            "all files (*.*)|*.*"]
-    ## List of allowed extensions
-    ext = ['.sld', '.SLD', '.txt', '.TXT', '.*']
-    
-    def read(self, path):
-        """
-        Load data file
-        
-        :param path: file path
-        
-        :return MagSLD: x, y, z, sld_n, sld_mx, sld_my, sld_mz
-        
-        :raise RuntimeError: when the file can't be opened
-        :raise ValueError: when the length of the data vectors are inconsistent
-        """
-        try:
-            pos_x = numpy.zeros(0)
-            pos_y = numpy.zeros(0)
-            pos_z = numpy.zeros(0)
-            sld_n = numpy.zeros(0)
-            sld_mx = numpy.zeros(0)
-            sld_my = numpy.zeros(0)
-            sld_mz = numpy.zeros(0)
-            try:
-                # Use numpy to speed up loading
-                input_f = numpy.loadtxt(path, dtype='float', skiprows=1, 
-                                        ndmin=1, unpack=True)
-                pos_x = numpy.array(input_f[0])
-                pos_y = numpy.array(input_f[1])
-                pos_z = numpy.array(input_f[2])
-                sld_n = numpy.array(input_f[3])
-                sld_mx = numpy.array(input_f[4])
-                sld_my = numpy.array(input_f[5])
-                sld_mz = numpy.array(input_f[6])
-                ncols = len(input_f)
-                if ncols == 8:
-                    vol_pix = numpy.array(input_f[7])
-                elif ncols == 7:
-                     vol_pix = None
-            except:
-                # For older version of numpy
-                input_f = open(path, 'rb')
-                buff = input_f.read()
-                lines = buff.split('\n')
-                input_f.close()
-                for line in lines:
-                    toks = line.split()
-                    try:
-                        _pos_x = float(toks[0])
-                        _pos_y = float(toks[1])
-                        _pos_z = float(toks[2])
-                        _sld_n = float(toks[3])
-                        _sld_mx = float(toks[4])
-                        _sld_my = float(toks[5])
-                        _sld_mz = float(toks[6])
-    
-                        pos_x = numpy.append(pos_x, _pos_x)
-                        pos_y = numpy.append(pos_y, _pos_y)
-                        pos_z = numpy.append(pos_z, _pos_z)
-                        sld_n = numpy.append(sld_n, _sld_n)
-                        sld_mx = numpy.append(sld_mx, _sld_mx)
-                        sld_my = numpy.append(sld_my, _sld_my)
-                        sld_mz = numpy.append(sld_mz, _sld_mz)
-                        try:
-                            _vol_pix =  float(toks[7])
-                            vol_pix = numpy.append(vol_pix, _vol_pix)
-                        except:
-                            vol_pix = None
-                    except:
-                        # Skip non-data lines
-                        pass
-            
-            # re-center     
-            #pos_x -= (min(pos_x) + max(pos_x)) / 2.0
-            #pos_y -= (min(pos_y) + max(pos_y)) / 2.0
-            #pos_z -= (min(pos_z) + max(pos_z)) / 2.0
-
-            output = MagSLD(pos_x, pos_y, pos_z, sld_n, 
-                            sld_mx, sld_my, sld_mz)
-
-            output.filename = os.path.basename(path)
-            output.set_pix_type('pixel')
-            output.set_pixel_symbols('pixel')
-            if vol_pix != None:
-                output.set_pixel_volumes(vol_pix)
-            return output
-        except:
-            RuntimeError, "%s is not a sld file" % path
-        
-    def write(self, path, data):
-        """
-        Write sld file
-        
-        :Param path: file path 
-        :Param data: MagSLD data object
-        """
-        if path == None:
-            raise ValueError, "Missing the file path."
-        if data == None:
-            raise ValueError, "Missing the data to save."
-        
-        x_val = data.pos_x
-        y_val = data.pos_y
-        z_val = data.pos_z
-        vol_pix = data.vol_pix
-        
-        length = len(x_val)
-        
-        sld_n = data.sld_n
-        if sld_n == None:
-            sld_n = numpy.zerros(length)
-            
-        sld_mx = data.sld_mx
-        if sld_mx == None:
-            sld_mx = numpy.zerros(length)
-            sld_my = numpy.zerros(length)
-            sld_mz = numpy.zerros(length)
-        else:
-            sld_my = data.sld_my
-            sld_mz = data.sld_mz
-            
-        out = open(path, 'w')
-        # First Line: Column names
-        out.write("X  Y  Z  SLDN SLDMx  SLDMy  SLDMz VOLUMEpix")
-        for ind in range(length):
-            out.write("\n%g  %g  %g  %g  %g  %g  %g %g" % (x_val[ind], y_val[ind], 
-                                                    z_val[ind], sld_n[ind], 
-                                                    sld_mx[ind], sld_my[ind], 
-                                                    sld_mz[ind], vol_pix[ind]))  
-        out.close()       
-            
-            
-class OMFData:
-    """
-    OMF Data.
-    """
-    _meshunit = "A"
-    _valueunit = "A^(-2)"
-    def __init__(self):
-        """
-        Init for mag SLD
-        """
-        self.filename = 'default'
-        self.oommf = ''
-        self.title = ''
-        self.desc = ''
-        self.meshtype = ''
-        self.meshunit = self._meshunit
-        self.valueunit = self._valueunit
-        self.xbase = 0.0
-        self.ybase = 0.0
-        self.zbase = 0.0
-        self.xstepsize = 6.0
-        self.ystepsize = 6.0
-        self.zstepsize = 6.0
-        self.xnodes = 10.0
-        self.ynodes = 10.0
-        self.znodes = 10.0
-        self.xmin = 0.0
-        self.ymin = 0.0
-        self.zmin = 0.0
-        self.xmax = 60.0
-        self.ymax = 60.0
-        self.zmax = 60.0
-        self.mx = None
-        self.my = None
-        self.mz = None
-        self.valuemultiplier = 1.
-        self.valuerangeminmag = 0
-        self.valuerangemaxmag = 0
-        
-    def __str__(self):
-        """
-        doc strings
-        """
-        _str =  "Type:            %s\n" % self.__class__.__name__
-        _str += "File:            %s\n" % self.filename
-        _str += "OOMMF:           %s\n" % self.oommf
-        _str += "Title:           %s\n" % self.title
-        _str += "Desc:            %s\n" % self.desc
-        _str += "meshtype:        %s\n" % self.meshtype
-        _str += "meshunit:        %s\n" % str(self.meshunit)
-        _str += "xbase:           %s [%s]\n" % (str(self.xbase), self.meshunit)
-        _str += "ybase:           %s [%s]\n" % (str(self.ybase), self.meshunit)
-        _str += "zbase:           %s [%s]\n" % (str(self.zbase), self.meshunit)
-        _str += "xstepsize:       %s [%s]\n" % (str(self.xstepsize), 
-                                                self.meshunit)
-        _str += "ystepsize:       %s [%s]\n" % (str(self.ystepsize), 
-                                                self.meshunit)
-        _str += "zstepsize:       %s [%s]\n" % (str(self.zstepsize), 
-                                                self.meshunit)
-        _str += "xnodes:          %s\n" % str(self.xnodes)
-        _str += "ynodes:          %s\n" % str(self.ynodes)
-        _str += "znodes:          %s\n" % str(self.znodes)
-        _str += "xmin:            %s [%s]\n" % (str(self.xmin), self.meshunit)
-        _str += "ymin:            %s [%s]\n" % (str(self.ymin), self.meshunit)
-        _str += "zmin:            %s [%s]\n" % (str(self.zmin), self.meshunit)
-        _str += "xmax:            %s [%s]\n" % (str(self.xmax), self.meshunit)
-        _str += "ymax:            %s [%s]\n" % (str(self.ymax), self.meshunit)
-        _str += "zmax:            %s [%s]\n" % (str(self.zmax), self.meshunit)
-        _str += "valueunit:       %s\n" % self.valueunit
-        _str += "valuemultiplier: %s\n" % str(self.valuemultiplier)
-        _str += "ValueRangeMinMag:%s [%s]\n" % (str(self.valuerangeminmag), 
-                                                 self.valueunit)
-        _str += "ValueRangeMaxMag:%s [%s]\n" % (str(self.valuerangemaxmag), 
-                                                 self.valueunit)
-        return _str
-    
-    def set_m(self, mx, my, mz):
-        """
-        Set the Mx, My, Mz values
-        """
-        self.mx = mx
-        self.my = my
-        self.mz = mz
-               
-class MagSLD:
-    """
-    Magnetic SLD.
-    """
-    pos_x = None
-    pos_y = None
-    pos_z = None
-    sld_n = None
-    sld_mx = None
-    sld_my = None
-    sld_mz = None
-    # Units
-    _pos_unit = 'A'
-    _sld_unit = '1/A^(2)'
-    _pix_type = 'pixel'
-    
-    def __init__(self, pos_x, pos_y, pos_z, sld_n=None, 
-                 sld_mx=None, sld_my=None, sld_mz=None, vol_pix=None):
-        """
-        Init for mag SLD
-        :params : All should be numpy 1D array
-        """
-        self.is_data = True
-        self.filename = ''
-        self.xstepsize = 6.0
-        self.ystepsize = 6.0
-        self.zstepsize = 6.0
-        self.xnodes = 10.0
-        self.ynodes = 10.0
-        self.znodes = 10.0
-        self.has_stepsize = False
-        self.has_conect = False
-        self.pos_unit = self._pos_unit
-        self.sld_unit = self._sld_unit
-        self.pix_type = 'pixel'
-        self.pos_x = pos_x
-        self.pos_y = pos_y
-        self.pos_z = pos_z
-        self.sld_n = sld_n
-        self.line_x = None
-        self.line_y = None
-        self.line_z = None
-        self.sld_mx = sld_mx
-        self.sld_my = sld_my
-        self.sld_mz = sld_mz
-        self.vol_pix = vol_pix
-        self.sld_m = None
-        self.sld_phi = None
-        self.sld_theta = None
-        self.pix_symbol = None
-        if sld_mx != None and sld_my != None and sld_mz != None:
-            self.set_sldms(sld_mx, sld_my, sld_mz)
-        self.set_nodes()
-                   
-    def __str__(self):
-        """
-        doc strings
-        """
-        _str =  "Type:       %s\n" % self.__class__.__name__
-        _str += "File:       %s\n" % self.filename
-        _str += "Axis_unit:  %s\n" % self.pos_unit
-        _str += "SLD_unit:   %s\n" % self.sld_unit
-        return _str
-    
-    def set_pix_type(self, pix_type):
-        """
-        Set pixel type
-        :Param pix_type: string, 'pixel' or 'atom'
-        """
-        self.pix_type = pix_type
-        
-    def set_sldn(self, sld_n):
-        """
-        Sets neutron SLD
-        """
-        if sld_n.__class__.__name__ == 'float':
-            if self.is_data:
-                # For data, put the value to only the pixels w non-zero M 
-                is_nonzero = (numpy.fabs(self.sld_mx) + 
-                                  numpy.fabs(self.sld_my) + 
-                                  numpy.fabs(self.sld_mz)).nonzero() 
-                self.sld_n = numpy.zeros(len(self.pos_x))
-                if len(self.sld_n[is_nonzero]) > 0:
-                    self.sld_n[is_nonzero] = sld_n
-                else:
-                    self.sld_n.fill(sld_n)
-            else:
-                # For non-data, put the value to all the pixels
-                self.sld_n = numpy.ones(len(self.pos_x)) * sld_n
-        else:
-            self.sld_n = sld_n
-           
-    def set_sldms(self, sld_mx, sld_my, sld_mz):
-        """
-        Sets (\|m\|, m_theta, m_phi)
-        """
-        if sld_mx.__class__.__name__ == 'float':
-            self.sld_mx = numpy.ones(len(self.pos_x)) * sld_mx
-        else:
-            self.sld_mx = sld_mx
-        if sld_my.__class__.__name__ == 'float':
-            self.sld_my = numpy.ones(len(self.pos_x)) * sld_my
-        else:
-            self.sld_my = sld_my
-        if sld_mz.__class__.__name__ == 'float':
-            self.sld_mz = numpy.ones(len(self.pos_x)) * sld_mz
-        else:
-            self.sld_mz = sld_mz
-
-        sld_m = numpy.sqrt(sld_mx * sld_mx + sld_my * sld_my + \
-                                sld_mz * sld_mz)  
-        self.sld_m = sld_m
-    
-    def set_pixel_symbols(self, symbol='pixel'):  
-        """
-        Set pixel
-        :Params pixel: str; pixel or atomic symbol, or array of strings
-        """
-        if self.sld_n == None:
-            return
-        if symbol.__class__.__name__ == 'str':
-            self.pix_symbol = numpy.repeat(symbol, len(self.sld_n))
-        else:
-            self.pix_symbol = symbol
-            
-    def set_pixel_volumes(self, vol):  
-        """
-        Set pixel volumes
-        :Params pixel: str; pixel or atomic symbol, or array of strings
-        """
-        if self.sld_n == None:
-            return
-        if vol.__class__.__name__ == 'ndarray':
-            self.vol_pix = vol
-        elif vol.__class__.__name__.count('float') > 0:
-            self.vol_pix = numpy.repeat(vol, len(self.sld_n))
-        else:
-            self.vol_pix = None
-
-    def get_sldn(self):
-        """
-        Returns nuclear sld
-        """
-        return self.sld_n
-    
-    def get_sld_mxyz(self):
-        """
-        Returns (sld_mx, sldmy, sld_mz)
-        """
-        return (self.sld_mx, self.sldmy, self.sld_mz)
-    
-    def get_sld_m(self):
-        """
-        Returns (sldm, sld_theta, sld_phi)
-        """
-        return (self.sldm, self.sld_theta, self.sld_phi)
-    
-    def set_nodes(self):
-        """
-        Set xnodes, ynodes, and znodes
-        """
-        self.set_stepsize()
-        if self.pix_type == 'pixel':
-            try:
-                xdist = (max(self.pos_x) - min(self.pos_x)) / self.xstepsize
-                ydist = (max(self.pos_y) - min(self.pos_y)) / self.ystepsize
-                zdist = (max(self.pos_z) - min(self.pos_z)) / self.zstepsize
-                self.xnodes = int(xdist) + 1
-                self.ynodes = int(ydist) + 1
-                self.znodes = int(zdist) + 1
-            except:
-                self.xnodes = None
-                self.ynodes = None
-                self.znodes = None
-        else:
-            self.xnodes = None
-            self.ynodes = None
-            self.znodes = None
-      
-    def set_stepsize(self):
-        """
-        Set xtepsize, ystepsize, and zstepsize
-        """
-        if self.pix_type == 'pixel':
-            try:
-                xpos_pre = self.pos_x[0]
-                ypos_pre = self.pos_y[0]
-                zpos_pre = self.pos_z[0]
-                for x_pos in self.pos_x:
-                    if xpos_pre != x_pos:
-                        self.xstepsize = numpy.fabs(x_pos - xpos_pre)
-                        break
-                for y_pos in self.pos_y:
-                    if ypos_pre != y_pos:
-                        self.ystepsize = numpy.fabs(y_pos - ypos_pre)
-                        break
-                for z_pos in self.pos_z:
-                    if zpos_pre != z_pos:
-                        self.zstepsize = numpy.fabs(z_pos - zpos_pre)
-                        break
-                #default pix volume
-                self.vol_pix = numpy.ones(len(self.pos_x))
-                vol = self.xstepsize * self.ystepsize * self.zstepsize
-                self.set_pixel_volumes(vol)
-                self.has_stepsize = True
-            except:
-                self.xstepsize = None
-                self.ystepsize = None
-                self.zstepsize = None
-                self.vol_pix = None
-                self.has_stepsize = False
-        else:
-            self.xstepsize = None
-            self.ystepsize = None
-            self.zstepsize = None
-            self.has_stepsize = True
-        return self.xstepsize, self.ystepsize, self.zstepsize
-
-    def set_conect_lines(self, line_x, line_y, line_z):
-        """
-        Set bonding line data if taken from pdb
-        """
-        if line_x.__class__.__name__ != 'list' or len(line_x) < 1:
-            return
-        if line_y.__class__.__name__ != 'list' or len(line_y) < 1:
-            return
-        if line_z.__class__.__name__ != 'list' or len(line_z) < 1:
-            return
-        self.has_conect = True
-        self.line_x = line_x 
-        self.line_y = line_y 
-        self.line_z = line_z
-        
-
-def test_load():
-    from sas.plottools.arrow3d import Arrow3D
-    import os
-    dir = os.path.abspath(os.path.curdir)
-    print dir
-    for i in range(6):
-        dir, _ = os.path.split(dir)
-        tfile = os.path.join(dir, "test", "CoreXY_ShellZ.txt")
-        ofile = os.path.join(dir, "test", "A_Raw_Example-1.omf")
-        if os.path.isfile(tfile):
-            tfpath = tfile
-            ofpath = ofile
-            break
-    reader = SLDReader()
-    oreader = OMFReader()
-    output = reader.read(tfpath)
-    ooutput = oreader.read(ofpath)
-    foutput = OMF2SLD()
-    foutput.set_data(ooutput)
-
-    import matplotlib.pyplot as plt
-    from mpl_toolkits.mplot3d import Axes3D
-    fig = plt.figure()
-    ax = fig.gca(projection='3d')
-    ax.plot(output.pos_x, output.pos_y, output.pos_z, '.', c="g", 
-            alpha = 0.7, markeredgecolor='gray',rasterized=True)
-    gap = 7
-    max_mx = max(output.sld_mx)
-    max_my = max(output.sld_my)
-    max_mz = max(output.sld_mz)
-    max_m = max(max_mx,max_my,max_mz)
-    x2 = output.pos_x+output.sld_mx/max_m * gap
-    y2 = output.pos_y+output.sld_my/max_m * gap
-    z2 = output.pos_z+output.sld_mz/max_m * gap
-    x_arrow = numpy.column_stack((output.pos_x,x2))
-    y_arrow = numpy.column_stack((output.pos_y,y2))
-    z_arrow = numpy.column_stack((output.pos_z,z2))
-    unit_x2 = output.sld_mx / max_m
-    unit_y2 = output.sld_my / max_m
-    unit_z2 = output.sld_mz / max_m
-    color_x = numpy.fabs(unit_x2 * 0.8)
-    color_y = numpy.fabs(unit_y2 * 0.8)
-    color_z = numpy.fabs(unit_z2 * 0.8)
-    colors =  numpy.column_stack((color_x, color_y, color_z))
-    a = Arrow3D(None, x_arrow,y_arrow,z_arrow, colors, mutation_scale=10, lw=1, 
-                arrowstyle="->", color="y", alpha = 0.5)
-
-    ax.add_artist(a)
-    plt.show()
-    
-def test():
-    import os
-    dir = os.path.abspath(os.path.curdir)
-    for i in range(3):
-        dir, _ = os.path.split(dir)
-        #tfile = os.path.join(dir, "test", "C_Example_Converted.txt")
-        ofile = os.path.join(dir, "test", "A_Raw_Example-1.omf")
-        if os.path.isfile(ofile):
-            #tfpath = tfile
-            ofpath = ofile
-            break
-    #reader = SLDReader()
-    oreader = OMFReader()
-    #output = reader.read(tfpath)
-    ooutput = oreader.read(ofpath)
-    foutput = OMF2SLD() 
-    foutput.set_data(ooutput)  
-    writer =  SLDReader() 
-    writer.write(os.path.join(os.path.dirname(ofpath), "out.txt"), 
-                 foutput.output)
-    model = GenSAS()
-    model.set_sld_data(foutput.output) 
-    x = numpy.arange(1000)/10000. + 1e-5
-    y = numpy.arange(1000)/10000. + 1e-5
-    #z = numpy.arange(1000)/10000. + 1e-5
-    i = numpy.zeros(1000)
-    out = model.runXY([x,y,i])
-        
-if __name__ == "__main__": 
-    test()
-    test_load()
Index: src/sas/calculator/sas_gen.py
===================================================================
--- src/sas/calculator/sas_gen.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
+++ src/sas/calculator/sas_gen.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -0,0 +1,1170 @@
+"""
+SAS generic computation and sld file readers
+"""
+from sas.models.BaseComponent import BaseComponent
+import sas.models.sas_extension.sld2i as mod
+from periodictable import formula
+from periodictable import nsf
+import numpy
+import os
+import copy
+
+MFactor_AM = 2.853E-12
+MFactor_mT = 2.3164E-9
+METER2ANG = 1.0E+10
+#Avogadro constant [1/mol]
+NA = 6.02214129e+23
+
+def mag2sld(mag, v_unit=None):
+    """
+    Convert magnetization to magnatic SLD
+    sldm = Dm * mag where Dm = gamma * classical elec. radius/(2*Bohr magneton)
+    Dm ~ 2.853E-12 [A^(-2)] ==> Shouldn't be 2.90636E-12 [A^(-2)]???
+    """ 
+    if v_unit == "A/m":
+        factor = MFactor_AM
+    elif v_unit == "mT":
+        factor = MFactor_mT
+    else:
+        raise ValueError, "Invalid valueunit"
+    sld_m = factor * mag
+    return sld_m
+
+def transform_center(pos_x, pos_y, pos_z):
+    """
+    re-center 
+    
+    :return: posx, posy, posz   [arrays]
+    """ 
+    posx = pos_x - (min(pos_x) + max(pos_x)) / 2.0
+    posy = pos_y - (min(pos_y) + max(pos_y)) / 2.0
+    posz = pos_z - (min(pos_z) + max(pos_z)) / 2.0  
+    return posx, posy, posz   
+
+class GenSAS(BaseComponent):
+    """
+    Generic SAS computation Model based on sld (n & m) arrays
+    """
+    def __init__(self):
+        """
+        Init
+        
+        :Params sld_data: MagSLD object
+        """
+        # Initialize BaseComponent
+        BaseComponent.__init__(self)
+        self.sld_data = None
+        self.data_pos_unit = None
+        self.data_x = None
+        self.data_y = None
+        self.data_z = None
+        self.data_sldn = None
+        self.data_mx = None
+        self.data_my = None
+        self.data_mz = None
+        self.data_vol = None #[A^3]
+        self.is_avg = False
+        ## Name of the model
+        self.name = "GenSAS"
+        ## Define parameters
+        self.params = {}
+        self.params['scale']       = 1.0
+        self.params['background']  = 0.0
+        self.params['solvent_SLD']     = 0.0
+        self.params['total_volume'] = 1.0
+        self.params['Up_frac_in']     = 1.0
+        self.params['Up_frac_out']    = 1.0
+        self.params['Up_theta']  = 0.0
+        self.description = 'GenSAS'
+        ## Parameter details [units, min, max]
+        self.details = {}
+        self.details['scale']      = ['', None, None]
+        self.details['background'] = ['[1/cm]', None, None]
+        self.details['solvent_SLD']    = ['1/A^(2)', None, None]
+        self.details['total_volume']    = ['A^(3)', None, None]
+        self.details['Up_frac_in']    = ['[u/(u+d)]', None, None]
+        self.details['Up_frac_out']   = ['[u/(u+d)]', None, None]
+        self.details['Up_theta'] = ['[deg]', None, None]
+        # fixed parameters
+        self.fixed = []
+        
+    def set_pixel_volumes(self, volume):     
+        """
+        Set the volume of a pixel in (A^3) unit
+        :Param volume: pixel volume [float]
+        """
+        if self.data_vol == None:
+            raise
+        self.data_vol = volume
+    
+    def set_is_avg(self, is_avg=False):  
+        """
+        Sets is_avg: [bool]
+        """
+        self.is_avg = is_avg
+          
+    def _gen(self, x, y, i):
+        """
+        Evaluate the function
+        :Param x: array of x-values
+        :Param y: array of y-values
+        :Param i: array of initial i-value 
+        :return: function value
+        """
+        pos_x = self.data_x
+        pos_y = self.data_y
+        pos_z = self.data_z
+        len_x = len(pos_x)
+        if self.is_avg == None:
+            len_x *= -1
+            pos_x, pos_y, pos_z = transform_center(pos_x, pos_y, pos_z)
+        len_q = len(x)
+        sldn = copy.deepcopy(self.data_sldn)
+        sldn -= self.params['solvent_SLD']
+        model = mod.new_GenI(len_x, pos_x, pos_y, pos_z, 
+                             sldn, self.data_mx, self.data_my, 
+                             self.data_mz, self.data_vol,
+                             self.params['Up_frac_in'], 
+                             self.params['Up_frac_out'], 
+                             self.params['Up_theta'])
+        if y == []:
+            mod.genicom(model, len_q, x, i)
+        else:
+            mod.genicomXY(model, len_q, x, y, i)
+        vol_correction = self.data_total_volume / self.params['total_volume']
+        return  self.params['scale'] * vol_correction * i + \
+                        self.params['background']
+        
+    def set_sld_data(self, sld_data=None):   
+        """
+        Sets sld_data
+        """
+        self.sld_data = sld_data
+        self.data_pos_unit = sld_data.pos_unit
+        self.data_x = sld_data.pos_x
+        self.data_y = sld_data.pos_y
+        self.data_z = sld_data.pos_z
+        self.data_sldn = sld_data.sld_n
+        self.data_mx = sld_data.sld_mx
+        self.data_my = sld_data.sld_my
+        self.data_mz = sld_data.sld_mz
+        self.data_vol = sld_data.vol_pix
+        self.data_total_volume = sum(sld_data.vol_pix)
+        self.params['total_volume'] = sum(sld_data.vol_pix)
+        
+    def getProfile(self):
+        """
+        Get SLD profile 
+        
+        : return: sld_data
+        """
+        return self.sld_data
+     
+    def run(self, x = 0.0):
+        """ 
+        Evaluate the model
+        :param x: simple value
+        :return: (I value)
+        """
+        if x.__class__.__name__ == 'list':
+            if len(x[1]) > 0:
+                msg = "Not a 1D."
+                raise ValueError, msg
+            i_out = numpy.zeros_like(x[0])
+            # 1D I is found at y =0 in the 2D pattern
+            out = self._gen(x[0], [], i_out )
+            return out
+        else:
+            msg = "Q must be given as list of qx's and qy's"
+            raise ValueError, msg
+   
+    def runXY(self, x = 0.0):
+        """ 
+        Evaluate the model
+        :param x: simple value
+        :return: I value
+        :Use this runXY() for the computation
+        """
+        if x.__class__.__name__ == 'list':
+            i_out = numpy.zeros_like(x[0])
+            out = self._gen(x[0], x[1], i_out)
+            return out
+        else:
+            msg = "Q must be given as list of qx's and qy's"
+            raise ValueError, msg
+        
+    def evalDistribution(self, qdist):
+        """
+        Evaluate a distribution of q-values.
+        * For 1D, a numpy array is expected as input: evalDistribution(q) where q is a numpy array.
+        * For 2D, a list of numpy arrays are expected: [qx_prime,qy_prime], where 1D arrays.
+        :param qdist: ndarray of scalar q-values or list [qx,qy] where qx,qy are 1D ndarrays 
+        """
+        if qdist.__class__.__name__ == 'list':
+            if len(qdist[1]) < 1:
+                out = self.run(qdist)
+            else:
+                out = self.runXY(qdist)
+            return out
+        else:
+            mesg = "evalDistribution is expecting an ndarray of "
+            mesg += "a list [qx,qy] where qx,qy are arrays."
+            raise RuntimeError, mesg
+      
+class OMF2SLD:
+    """
+    Convert OMFData to MAgData
+    """
+    def __init__(self): 
+        """
+        Init
+        """
+        self.pos_x = None
+        self.pos_y = None
+        self.pos_z = None
+        self.mx = None
+        self.my = None
+        self.mz = None
+        self.sld_n = None
+        self.vol_pix = None
+        self.output = None
+        self.omfdata = None
+    
+    def set_data(self, omfdata, shape='rectangular'):
+        """
+        Set all data
+        """
+        self.omfdata = omfdata
+        length = int(omfdata.xnodes * omfdata.ynodes * omfdata.znodes)
+        pos_x = numpy.arange(omfdata.xmin, 
+                             omfdata.xnodes*omfdata.xstepsize + omfdata.xmin, 
+                             omfdata.xstepsize)
+        pos_y = numpy.arange(omfdata.ymin,  
+                             omfdata.ynodes*omfdata.ystepsize + omfdata.ymin, 
+                             omfdata.ystepsize)
+        pos_z = numpy.arange(omfdata.zmin, 
+                             omfdata.znodes*omfdata.zstepsize + omfdata.zmin, 
+                             omfdata.zstepsize)
+        self.pos_x = numpy.tile(pos_x, int(omfdata.ynodes * omfdata.znodes))
+        self.pos_y = pos_y.repeat(int(omfdata.xnodes))
+        self.pos_y = numpy.tile(self.pos_y, int(omfdata.znodes))
+        self.pos_z = pos_z.repeat(int(omfdata.xnodes * omfdata.ynodes))
+        self.mx = omfdata.mx
+        self.my = omfdata.my
+        self.mz = omfdata.mz
+        self.sld_n = numpy.zeros(length)
+            
+        if omfdata.mx == None:
+            self.mx = numpy.zeros(length)
+        if omfdata.my == None:
+            self.my = numpy.zeros(length)
+        if omfdata.mz == None:
+            self.mz = numpy.zeros(length)
+        
+        self._check_data_length(length)
+        self.remove_null_points(False, False)
+        mask = numpy.ones(len(self.sld_n), dtype=bool)
+        if shape.lower() == 'ellipsoid':
+            try:
+                # Pixel (step) size included
+                x_c = max(self.pos_x) + min(self.pos_x)
+                y_c = max(self.pos_y) + min(self.pos_y)
+                z_c = max(self.pos_z) + min(self.pos_z)
+                x_d = max(self.pos_x) - min(self.pos_x)
+                y_d = max(self.pos_y) - min(self.pos_y)
+                z_d = max(self.pos_z) - min(self.pos_z)
+                x_r = (x_d + omfdata.xstepsize) / 2.0
+                y_r = (y_d + omfdata.ystepsize) / 2.0
+                z_r = (z_d + omfdata.zstepsize) / 2.0
+                x_dir2 = ((self.pos_x - x_c / 2.0) / x_r)
+                x_dir2 *= x_dir2
+                y_dir2 = ((self.pos_y - y_c / 2.0) / y_r)
+                y_dir2 *= y_dir2
+                z_dir2 = ((self.pos_z - z_c / 2.0) / z_r)
+                z_dir2 *= z_dir2
+                mask = (x_dir2 + y_dir2 + z_dir2) <= 1.0
+            except:
+                pass
+        self.output = MagSLD(self.pos_x[mask], self.pos_y[mask], 
+                             self.pos_z[mask], self.sld_n[mask], 
+                             self.mx[mask], self.my[mask], self.mz[mask])
+        self.output.set_pix_type('pixel')
+        self.output.set_pixel_symbols('pixel')
+        
+    def get_omfdata(self):
+        """
+        Return all data
+        """
+        return self.omfdata
+    
+    def get_output(self):
+        """
+        Return output
+        """
+        return self.output
+    
+    def _check_data_length(self, length):
+        """
+        Check if the data lengths are consistent
+        :Params length: data length
+        """
+        msg = "Error: Inconsistent data length."
+        if len(self.pos_x) != length:
+            raise ValueError, msg
+        if len(self.pos_y) != length:
+            raise ValueError, msg
+        if len(self.pos_z) != length:
+            raise ValueError, msg
+        if len(self.mx) != length:
+            raise ValueError, msg
+        if len(self.my) != length:
+            raise ValueError, msg
+        if len(self.mz) != length:
+            raise ValueError, msg
+        
+    def remove_null_points(self, remove=False, recenter=False):
+        """
+        Removes any mx, my, and mz = 0 points
+        """
+        if remove:
+            is_nonzero = (numpy.fabs(self.mx) + numpy.fabs(self.my) + 
+                          numpy.fabs(self.mz)).nonzero()  
+            if len(is_nonzero[0]) > 0: 
+                self.pos_x = self.pos_x[is_nonzero]
+                self.pos_y = self.pos_y[is_nonzero]
+                self.pos_z = self.pos_z[is_nonzero]
+                self.sld_n = self.sld_n[is_nonzero]
+                self.mx = self.mx[is_nonzero]
+                self.my = self.my[is_nonzero]
+                self.mz = self.mz[is_nonzero]
+        if recenter:
+            self.pos_x -= (min(self.pos_x) + max(self.pos_x)) / 2.0
+            self.pos_y -= (min(self.pos_y) + max(self.pos_y)) / 2.0
+            self.pos_z -= (min(self.pos_z) + max(self.pos_z)) / 2.0
+ 
+    def get_magsld(self):
+        """
+        return MagSLD
+        """
+        return self.output
+    
+        
+class OMFReader:
+    """
+    Class to load omf/ascii files (3 columns w/header).
+    """
+    ## File type
+    type_name = "OMF ASCII"
+    
+    ## Wildcards
+    type = ["OMF files (*.OMF, *.omf)|*.omf"]
+    ## List of allowed extensions
+    ext = ['.omf', '.OMF']
+        
+    def read(self, path):
+        """
+        Load data file
+        :param path: file path
+        :return: x, y, z, sld_n, sld_mx, sld_my, sld_mz
+        """
+        #data_conv_m = None
+        desc = ""
+        mx = numpy.zeros(0)
+        my = numpy.zeros(0)
+        mz = numpy.zeros(0)
+        try:
+            data_conv_val = None
+            data_conv_mesh = None
+            input_f = open(path, 'rb')
+            buff = input_f.read()
+            lines = buff.split('\n')
+            input_f.close()
+            output = OMFData()
+            valueunit = None
+            for line in lines:
+                toks = line.split()
+                # Read data
+                try:
+                    _mx = float(toks[0])
+                    _my = float(toks[1])
+                    _mz = float(toks[2])
+                    _mx = mag2sld(_mx, valueunit)
+                    _my = mag2sld(_my, valueunit)
+                    _mz = mag2sld(_mz, valueunit)
+                    mx = numpy.append(mx, _mx)
+                    my = numpy.append(my, _my)
+                    mz = numpy.append(mz, _mz)
+                except:
+                    # Skip non-data lines
+                    pass
+                #Reading Header; Segment count ignored
+                s_line = line.split(":", 1)
+                if s_line[0].lower().count("oommf") > 0:
+                    oommf = s_line[1].lstrip()
+                if s_line[0].lower().count("title") > 0:
+                    title = s_line[1].lstrip()
+                if s_line[0].lower().count("desc") > 0:
+                    desc += s_line[1].lstrip()
+                    desc += '\n'
+                if s_line[0].lower().count("meshtype") > 0:
+                    meshtype = s_line[1].lstrip()
+                if s_line[0].lower().count("meshunit") > 0:
+                    meshunit = s_line[1].lstrip()
+                    if meshunit.count("m") < 1:
+                        msg = "Error: \n"
+                        msg += "We accept only m as meshunit"
+                        raise ValueError, msg
+                if s_line[0].lower().count("xbase") > 0:
+                    xbase = s_line[1].lstrip()
+                if s_line[0].lower().count("ybase") > 0:
+                    ybase = s_line[1].lstrip()
+                if s_line[0].lower().count("zbase") > 0:
+                    zbase = s_line[1].lstrip()
+                if s_line[0].lower().count("xstepsize") > 0:
+                    xstepsize = s_line[1].lstrip()
+                if s_line[0].lower().count("ystepsize") > 0:
+                    ystepsize = s_line[1].lstrip()
+                if s_line[0].lower().count("zstepsize") > 0:
+                    zstepsize = s_line[1].lstrip()
+                if s_line[0].lower().count("xnodes") > 0:
+                    xnodes = s_line[1].lstrip()
+                if s_line[0].lower().count("ynodes") > 0:
+                    ynodes = s_line[1].lstrip()
+                if s_line[0].lower().count("znodes") > 0:
+                    znodes = s_line[1].lstrip()
+                if s_line[0].lower().count("xmin") > 0:
+                    xmin = s_line[1].lstrip()
+                if s_line[0].lower().count("ymin") > 0:
+                    ymin = s_line[1].lstrip()
+                if s_line[0].lower().count("zmin") > 0:
+                    zmin = s_line[1].lstrip()
+                if s_line[0].lower().count("xmax") > 0:
+                    xmax = s_line[1].lstrip()
+                if s_line[0].lower().count("ymax") > 0:
+                    ymax = s_line[1].lstrip()
+                if s_line[0].lower().count("zmax") > 0:
+                    zmax = s_line[1].lstrip()
+                if s_line[0].lower().count("valueunit") > 0:
+                    valueunit = s_line[1].lstrip().rstrip()
+                if s_line[0].lower().count("valuemultiplier") > 0:
+                    valuemultiplier = s_line[1].lstrip()
+                if s_line[0].lower().count("valuerangeminmag") > 0:
+                    valuerangeminmag = s_line[1].lstrip()
+                if s_line[0].lower().count("valuerangemaxmag") > 0:
+                    valuerangemaxmag = s_line[1].lstrip()
+                if s_line[0].lower().count("end") > 0:
+                    #output.set_sldms(mx, my, mz)    
+                    output.filename = os.path.basename(path)
+                    output.oommf = oommf
+                    output.title = title
+                    output.desc = desc
+                    output.meshtype = meshtype
+                    output.xbase = float(xbase) * METER2ANG
+                    output.ybase = float(ybase) * METER2ANG
+                    output.zbase = float(zbase) * METER2ANG
+                    output.xstepsize = float(xstepsize) * METER2ANG
+                    output.ystepsize = float(ystepsize) * METER2ANG
+                    output.zstepsize = float(zstepsize) * METER2ANG
+                    output.xnodes = float(xnodes)
+                    output.ynodes = float(ynodes)
+                    output.znodes = float(znodes)
+                    output.xmin = float(xmin) * METER2ANG
+                    output.ymin = float(ymin) * METER2ANG
+                    output.zmin = float(zmin) * METER2ANG
+                    output.xmax = float(xmax) * METER2ANG
+                    output.ymax = float(ymax) * METER2ANG
+                    output.zmax = float(zmax) * METER2ANG
+                    output.valuemultiplier = valuemultiplier
+                    output.valuerangeminmag = mag2sld(float(valuerangeminmag), \
+                                                      valueunit)
+                    output.valuerangemaxmag = mag2sld(float(valuerangemaxmag), \
+                                                      valueunit)
+            output.set_m(mx, my, mz)
+            return output
+        except:
+            msg = "%s is not supported: \n" % path
+            msg += "We accept only Text format OMF file."
+            raise RuntimeError, msg
+
+class PDBReader:
+    """
+    PDB reader class: limited for reading the lines starting with 'ATOM'
+    """
+    type_name = "PDB"
+    ## Wildcards
+    type = ["pdb files (*.PDB, *.pdb)|*.pdb"]
+    ## List of allowed extensions
+    ext = ['.pdb', '.PDB']   
+    
+    def read(self, path):
+        """
+        Load data file
+        
+        :param path: file path
+        
+        :return: MagSLD
+        
+        :raise RuntimeError: when the file can't be opened
+        """
+        pos_x = numpy.zeros(0)
+        pos_y = numpy.zeros(0)
+        pos_z = numpy.zeros(0)
+        sld_n = numpy.zeros(0)
+        sld_mx = numpy.zeros(0)
+        sld_my = numpy.zeros(0)
+        sld_mz = numpy.zeros(0)
+        vol_pix = numpy.zeros(0)
+        pix_symbol = numpy.zeros(0)
+        x_line = []
+        y_line = []
+        z_line = []
+        x_lines = []
+        y_lines = []
+        z_lines = []        
+        try:
+            input_f = open(path, 'rb')
+            buff = input_f.read()
+            lines = buff.split('\n')
+            input_f.close()
+            pre_num = 0
+            num = 0
+            for line in lines:
+                try:
+                    # check if line starts with "ATOM"
+                    if line[0:6].strip().count('ATM') > 0 or \
+                                line[0:6].strip() == 'ATOM':
+                        # define fields of interest
+                        atom_id = line[6:11].strip()
+                        atom_name = line[12:16].strip()
+                        try:
+                            float(line[12])
+                            atom_name = atom_name[1].upper()
+                        except:
+                            if len(atom_name) == 4:
+                                atom_name = atom_name[0].upper()
+                            elif line[12] != ' ': 
+                                atom_name = atom_name[0].upper() + \
+                                        atom_name[1].lower() 
+                            else:
+                                atom_name = atom_name[0].upper()
+                        #res_name = line[17:20].strip()
+                        #chain_name = line[21:22].strip()
+                        _pos_x = float(line[30:38].strip())
+                        _pos_y = float(line[38:46].strip())
+                        _pos_z = float(line[46:54].strip())
+                        
+                        pos_x = numpy.append(pos_x, _pos_x)
+                        pos_y = numpy.append(pos_y, _pos_y)
+                        pos_z = numpy.append(pos_z, _pos_z)
+                        try:
+                            # sld in Ang unit (from fm)
+                            #val = formula(atom_name).atoms.keys()[0].neutron.b_c
+                            #val *= 1.0e-5
+                            val = nsf.neutron_sld(atom_name)[0]
+                            # sld in Ang^-2 unit
+                            val *= 1.0e-6
+                            sld_n = numpy.append(sld_n, val)
+                            atom = formula(atom_name)
+                            # cm to A units
+                            vol = 1.0e+24 * atom.mass / atom.density / NA
+                            vol_pix = numpy.append(vol_pix, vol)
+                        except:
+                            print "Error: set the sld of %s to zero"% atom_name
+                            sld_n = numpy.append(sld_n,  0.0)                     
+                        sld_mx = numpy.append(sld_mx, 0)
+                        sld_my = numpy.append(sld_my, 0)
+                        sld_mz = numpy.append(sld_mz, 0)
+                        pix_symbol = numpy.append(pix_symbol, atom_name)
+                    elif line[0:6].strip().count('CONECT') > 0 :
+                        toks = line.split()
+                        num = int(toks[1]) - 1  
+                        val_list = [] 
+                        for val in toks[2:]:
+                            try:
+                                int_val = int(val)
+                            except:
+                                break
+                            if int_val == 0:
+                                break
+                            val_list.append(int_val)
+                        #need val_list ordered      
+                        for val in val_list:
+                            index = val - 1
+                            if (pos_x[index], pos_x[num]) in x_line and \
+                               (pos_y[index], pos_y[num]) in y_line and \
+                               (pos_z[index], pos_z[num]) in z_line:
+                                continue
+                            x_line.append((pos_x[num], pos_x[index]))
+                            y_line.append((pos_y[num], pos_y[index]))
+                            z_line.append((pos_z[num], pos_z[index]))
+                    if len(x_line) > 0:
+                        x_lines.append(x_line) 
+                        y_lines.append(y_line)
+                        z_lines.append(z_line)            
+                except:
+                    pass
+            #re-centering
+            #pos_x -= (min(pos_x) + max(pos_x)) / 2.0
+            #pos_y -= (min(pos_y) + max(pos_y)) / 2.0
+            #pos_z -= (min(pos_z) + max(pos_z)) / 2.0
+            
+            output = MagSLD(pos_x, pos_y, pos_z, sld_n, sld_mx, sld_my, sld_mz)
+            output.set_conect_lines(x_line, y_line, z_line)
+            output.filename = os.path.basename(path)
+            output.set_pix_type('atom')
+            output.set_pixel_symbols(pix_symbol)
+            output.set_nodes()
+            output.set_pixel_volumes(vol_pix)
+            output.sld_unit = '1/A^(2)'
+            return output
+        except:
+            RuntimeError, "%s is not a sld file" % path
+
+    def write(self, path, data):
+        """
+        Write
+        """
+        #Not implemented 
+        print "Not implemented... "
+
+class SLDReader:
+    """
+    Class to load ascii files (7 columns).
+    """
+    ## File type
+    type_name = "SLD ASCII"
+    
+    ## Wildcards
+    type = ["sld files (*.SLD, *.sld)|*.sld",
+            "txt files (*.TXT, *.txt)|*.txt",
+            "all files (*.*)|*.*"]
+    ## List of allowed extensions
+    ext = ['.sld', '.SLD', '.txt', '.TXT', '.*']
+    
+    def read(self, path):
+        """
+        Load data file
+        
+        :param path: file path
+        
+        :return MagSLD: x, y, z, sld_n, sld_mx, sld_my, sld_mz
+        
+        :raise RuntimeError: when the file can't be opened
+        :raise ValueError: when the length of the data vectors are inconsistent
+        """
+        try:
+            pos_x = numpy.zeros(0)
+            pos_y = numpy.zeros(0)
+            pos_z = numpy.zeros(0)
+            sld_n = numpy.zeros(0)
+            sld_mx = numpy.zeros(0)
+            sld_my = numpy.zeros(0)
+            sld_mz = numpy.zeros(0)
+            try:
+                # Use numpy to speed up loading
+                input_f = numpy.loadtxt(path, dtype='float', skiprows=1, 
+                                        ndmin=1, unpack=True)
+                pos_x = numpy.array(input_f[0])
+                pos_y = numpy.array(input_f[1])
+                pos_z = numpy.array(input_f[2])
+                sld_n = numpy.array(input_f[3])
+                sld_mx = numpy.array(input_f[4])
+                sld_my = numpy.array(input_f[5])
+                sld_mz = numpy.array(input_f[6])
+                ncols = len(input_f)
+                if ncols == 8:
+                    vol_pix = numpy.array(input_f[7])
+                elif ncols == 7:
+                     vol_pix = None
+            except:
+                # For older version of numpy
+                input_f = open(path, 'rb')
+                buff = input_f.read()
+                lines = buff.split('\n')
+                input_f.close()
+                for line in lines:
+                    toks = line.split()
+                    try:
+                        _pos_x = float(toks[0])
+                        _pos_y = float(toks[1])
+                        _pos_z = float(toks[2])
+                        _sld_n = float(toks[3])
+                        _sld_mx = float(toks[4])
+                        _sld_my = float(toks[5])
+                        _sld_mz = float(toks[6])
+    
+                        pos_x = numpy.append(pos_x, _pos_x)
+                        pos_y = numpy.append(pos_y, _pos_y)
+                        pos_z = numpy.append(pos_z, _pos_z)
+                        sld_n = numpy.append(sld_n, _sld_n)
+                        sld_mx = numpy.append(sld_mx, _sld_mx)
+                        sld_my = numpy.append(sld_my, _sld_my)
+                        sld_mz = numpy.append(sld_mz, _sld_mz)
+                        try:
+                            _vol_pix =  float(toks[7])
+                            vol_pix = numpy.append(vol_pix, _vol_pix)
+                        except:
+                            vol_pix = None
+                    except:
+                        # Skip non-data lines
+                        pass
+            
+            # re-center     
+            #pos_x -= (min(pos_x) + max(pos_x)) / 2.0
+            #pos_y -= (min(pos_y) + max(pos_y)) / 2.0
+            #pos_z -= (min(pos_z) + max(pos_z)) / 2.0
+
+            output = MagSLD(pos_x, pos_y, pos_z, sld_n, 
+                            sld_mx, sld_my, sld_mz)
+
+            output.filename = os.path.basename(path)
+            output.set_pix_type('pixel')
+            output.set_pixel_symbols('pixel')
+            if vol_pix != None:
+                output.set_pixel_volumes(vol_pix)
+            return output
+        except:
+            RuntimeError, "%s is not a sld file" % path
+        
+    def write(self, path, data):
+        """
+        Write sld file
+        
+        :Param path: file path 
+        :Param data: MagSLD data object
+        """
+        if path == None:
+            raise ValueError, "Missing the file path."
+        if data == None:
+            raise ValueError, "Missing the data to save."
+        
+        x_val = data.pos_x
+        y_val = data.pos_y
+        z_val = data.pos_z
+        vol_pix = data.vol_pix
+        
+        length = len(x_val)
+        
+        sld_n = data.sld_n
+        if sld_n == None:
+            sld_n = numpy.zerros(length)
+            
+        sld_mx = data.sld_mx
+        if sld_mx == None:
+            sld_mx = numpy.zerros(length)
+            sld_my = numpy.zerros(length)
+            sld_mz = numpy.zerros(length)
+        else:
+            sld_my = data.sld_my
+            sld_mz = data.sld_mz
+            
+        out = open(path, 'w')
+        # First Line: Column names
+        out.write("X  Y  Z  SLDN SLDMx  SLDMy  SLDMz VOLUMEpix")
+        for ind in range(length):
+            out.write("\n%g  %g  %g  %g  %g  %g  %g %g" % (x_val[ind], y_val[ind], 
+                                                    z_val[ind], sld_n[ind], 
+                                                    sld_mx[ind], sld_my[ind], 
+                                                    sld_mz[ind], vol_pix[ind]))  
+        out.close()       
+            
+            
+class OMFData:
+    """
+    OMF Data.
+    """
+    _meshunit = "A"
+    _valueunit = "A^(-2)"
+    def __init__(self):
+        """
+        Init for mag SLD
+        """
+        self.filename = 'default'
+        self.oommf = ''
+        self.title = ''
+        self.desc = ''
+        self.meshtype = ''
+        self.meshunit = self._meshunit
+        self.valueunit = self._valueunit
+        self.xbase = 0.0
+        self.ybase = 0.0
+        self.zbase = 0.0
+        self.xstepsize = 6.0
+        self.ystepsize = 6.0
+        self.zstepsize = 6.0
+        self.xnodes = 10.0
+        self.ynodes = 10.0
+        self.znodes = 10.0
+        self.xmin = 0.0
+        self.ymin = 0.0
+        self.zmin = 0.0
+        self.xmax = 60.0
+        self.ymax = 60.0
+        self.zmax = 60.0
+        self.mx = None
+        self.my = None
+        self.mz = None
+        self.valuemultiplier = 1.
+        self.valuerangeminmag = 0
+        self.valuerangemaxmag = 0
+        
+    def __str__(self):
+        """
+        doc strings
+        """
+        _str =  "Type:            %s\n" % self.__class__.__name__
+        _str += "File:            %s\n" % self.filename
+        _str += "OOMMF:           %s\n" % self.oommf
+        _str += "Title:           %s\n" % self.title
+        _str += "Desc:            %s\n" % self.desc
+        _str += "meshtype:        %s\n" % self.meshtype
+        _str += "meshunit:        %s\n" % str(self.meshunit)
+        _str += "xbase:           %s [%s]\n" % (str(self.xbase), self.meshunit)
+        _str += "ybase:           %s [%s]\n" % (str(self.ybase), self.meshunit)
+        _str += "zbase:           %s [%s]\n" % (str(self.zbase), self.meshunit)
+        _str += "xstepsize:       %s [%s]\n" % (str(self.xstepsize), 
+                                                self.meshunit)
+        _str += "ystepsize:       %s [%s]\n" % (str(self.ystepsize), 
+                                                self.meshunit)
+        _str += "zstepsize:       %s [%s]\n" % (str(self.zstepsize), 
+                                                self.meshunit)
+        _str += "xnodes:          %s\n" % str(self.xnodes)
+        _str += "ynodes:          %s\n" % str(self.ynodes)
+        _str += "znodes:          %s\n" % str(self.znodes)
+        _str += "xmin:            %s [%s]\n" % (str(self.xmin), self.meshunit)
+        _str += "ymin:            %s [%s]\n" % (str(self.ymin), self.meshunit)
+        _str += "zmin:            %s [%s]\n" % (str(self.zmin), self.meshunit)
+        _str += "xmax:            %s [%s]\n" % (str(self.xmax), self.meshunit)
+        _str += "ymax:            %s [%s]\n" % (str(self.ymax), self.meshunit)
+        _str += "zmax:            %s [%s]\n" % (str(self.zmax), self.meshunit)
+        _str += "valueunit:       %s\n" % self.valueunit
+        _str += "valuemultiplier: %s\n" % str(self.valuemultiplier)
+        _str += "ValueRangeMinMag:%s [%s]\n" % (str(self.valuerangeminmag), 
+                                                 self.valueunit)
+        _str += "ValueRangeMaxMag:%s [%s]\n" % (str(self.valuerangemaxmag), 
+                                                 self.valueunit)
+        return _str
+    
+    def set_m(self, mx, my, mz):
+        """
+        Set the Mx, My, Mz values
+        """
+        self.mx = mx
+        self.my = my
+        self.mz = mz
+               
+class MagSLD:
+    """
+    Magnetic SLD.
+    """
+    pos_x = None
+    pos_y = None
+    pos_z = None
+    sld_n = None
+    sld_mx = None
+    sld_my = None
+    sld_mz = None
+    # Units
+    _pos_unit = 'A'
+    _sld_unit = '1/A^(2)'
+    _pix_type = 'pixel'
+    
+    def __init__(self, pos_x, pos_y, pos_z, sld_n=None, 
+                 sld_mx=None, sld_my=None, sld_mz=None, vol_pix=None):
+        """
+        Init for mag SLD
+        :params : All should be numpy 1D array
+        """
+        self.is_data = True
+        self.filename = ''
+        self.xstepsize = 6.0
+        self.ystepsize = 6.0
+        self.zstepsize = 6.0
+        self.xnodes = 10.0
+        self.ynodes = 10.0
+        self.znodes = 10.0
+        self.has_stepsize = False
+        self.has_conect = False
+        self.pos_unit = self._pos_unit
+        self.sld_unit = self._sld_unit
+        self.pix_type = 'pixel'
+        self.pos_x = pos_x
+        self.pos_y = pos_y
+        self.pos_z = pos_z
+        self.sld_n = sld_n
+        self.line_x = None
+        self.line_y = None
+        self.line_z = None
+        self.sld_mx = sld_mx
+        self.sld_my = sld_my
+        self.sld_mz = sld_mz
+        self.vol_pix = vol_pix
+        self.sld_m = None
+        self.sld_phi = None
+        self.sld_theta = None
+        self.pix_symbol = None
+        if sld_mx != None and sld_my != None and sld_mz != None:
+            self.set_sldms(sld_mx, sld_my, sld_mz)
+        self.set_nodes()
+                   
+    def __str__(self):
+        """
+        doc strings
+        """
+        _str =  "Type:       %s\n" % self.__class__.__name__
+        _str += "File:       %s\n" % self.filename
+        _str += "Axis_unit:  %s\n" % self.pos_unit
+        _str += "SLD_unit:   %s\n" % self.sld_unit
+        return _str
+    
+    def set_pix_type(self, pix_type):
+        """
+        Set pixel type
+        :Param pix_type: string, 'pixel' or 'atom'
+        """
+        self.pix_type = pix_type
+        
+    def set_sldn(self, sld_n):
+        """
+        Sets neutron SLD
+        """
+        if sld_n.__class__.__name__ == 'float':
+            if self.is_data:
+                # For data, put the value to only the pixels w non-zero M 
+                is_nonzero = (numpy.fabs(self.sld_mx) + 
+                                  numpy.fabs(self.sld_my) + 
+                                  numpy.fabs(self.sld_mz)).nonzero() 
+                self.sld_n = numpy.zeros(len(self.pos_x))
+                if len(self.sld_n[is_nonzero]) > 0:
+                    self.sld_n[is_nonzero] = sld_n
+                else:
+                    self.sld_n.fill(sld_n)
+            else:
+                # For non-data, put the value to all the pixels
+                self.sld_n = numpy.ones(len(self.pos_x)) * sld_n
+        else:
+            self.sld_n = sld_n
+           
+    def set_sldms(self, sld_mx, sld_my, sld_mz):
+        """
+        Sets (\|m\|, m_theta, m_phi)
+        """
+        if sld_mx.__class__.__name__ == 'float':
+            self.sld_mx = numpy.ones(len(self.pos_x)) * sld_mx
+        else:
+            self.sld_mx = sld_mx
+        if sld_my.__class__.__name__ == 'float':
+            self.sld_my = numpy.ones(len(self.pos_x)) * sld_my
+        else:
+            self.sld_my = sld_my
+        if sld_mz.__class__.__name__ == 'float':
+            self.sld_mz = numpy.ones(len(self.pos_x)) * sld_mz
+        else:
+            self.sld_mz = sld_mz
+
+        sld_m = numpy.sqrt(sld_mx * sld_mx + sld_my * sld_my + \
+                                sld_mz * sld_mz)  
+        self.sld_m = sld_m
+    
+    def set_pixel_symbols(self, symbol='pixel'):  
+        """
+        Set pixel
+        :Params pixel: str; pixel or atomic symbol, or array of strings
+        """
+        if self.sld_n == None:
+            return
+        if symbol.__class__.__name__ == 'str':
+            self.pix_symbol = numpy.repeat(symbol, len(self.sld_n))
+        else:
+            self.pix_symbol = symbol
+            
+    def set_pixel_volumes(self, vol):  
+        """
+        Set pixel volumes
+        :Params pixel: str; pixel or atomic symbol, or array of strings
+        """
+        if self.sld_n == None:
+            return
+        if vol.__class__.__name__ == 'ndarray':
+            self.vol_pix = vol
+        elif vol.__class__.__name__.count('float') > 0:
+            self.vol_pix = numpy.repeat(vol, len(self.sld_n))
+        else:
+            self.vol_pix = None
+
+    def get_sldn(self):
+        """
+        Returns nuclear sld
+        """
+        return self.sld_n
+    
+    def get_sld_mxyz(self):
+        """
+        Returns (sld_mx, sldmy, sld_mz)
+        """
+        return (self.sld_mx, self.sldmy, self.sld_mz)
+    
+    def get_sld_m(self):
+        """
+        Returns (sldm, sld_theta, sld_phi)
+        """
+        return (self.sldm, self.sld_theta, self.sld_phi)
+    
+    def set_nodes(self):
+        """
+        Set xnodes, ynodes, and znodes
+        """
+        self.set_stepsize()
+        if self.pix_type == 'pixel':
+            try:
+                xdist = (max(self.pos_x) - min(self.pos_x)) / self.xstepsize
+                ydist = (max(self.pos_y) - min(self.pos_y)) / self.ystepsize
+                zdist = (max(self.pos_z) - min(self.pos_z)) / self.zstepsize
+                self.xnodes = int(xdist) + 1
+                self.ynodes = int(ydist) + 1
+                self.znodes = int(zdist) + 1
+            except:
+                self.xnodes = None
+                self.ynodes = None
+                self.znodes = None
+        else:
+            self.xnodes = None
+            self.ynodes = None
+            self.znodes = None
+      
+    def set_stepsize(self):
+        """
+        Set xtepsize, ystepsize, and zstepsize
+        """
+        if self.pix_type == 'pixel':
+            try:
+                xpos_pre = self.pos_x[0]
+                ypos_pre = self.pos_y[0]
+                zpos_pre = self.pos_z[0]
+                for x_pos in self.pos_x:
+                    if xpos_pre != x_pos:
+                        self.xstepsize = numpy.fabs(x_pos - xpos_pre)
+                        break
+                for y_pos in self.pos_y:
+                    if ypos_pre != y_pos:
+                        self.ystepsize = numpy.fabs(y_pos - ypos_pre)
+                        break
+                for z_pos in self.pos_z:
+                    if zpos_pre != z_pos:
+                        self.zstepsize = numpy.fabs(z_pos - zpos_pre)
+                        break
+                #default pix volume
+                self.vol_pix = numpy.ones(len(self.pos_x))
+                vol = self.xstepsize * self.ystepsize * self.zstepsize
+                self.set_pixel_volumes(vol)
+                self.has_stepsize = True
+            except:
+                self.xstepsize = None
+                self.ystepsize = None
+                self.zstepsize = None
+                self.vol_pix = None
+                self.has_stepsize = False
+        else:
+            self.xstepsize = None
+            self.ystepsize = None
+            self.zstepsize = None
+            self.has_stepsize = True
+        return self.xstepsize, self.ystepsize, self.zstepsize
+
+    def set_conect_lines(self, line_x, line_y, line_z):
+        """
+        Set bonding line data if taken from pdb
+        """
+        if line_x.__class__.__name__ != 'list' or len(line_x) < 1:
+            return
+        if line_y.__class__.__name__ != 'list' or len(line_y) < 1:
+            return
+        if line_z.__class__.__name__ != 'list' or len(line_z) < 1:
+            return
+        self.has_conect = True
+        self.line_x = line_x 
+        self.line_y = line_y 
+        self.line_z = line_z
+        
+
+def test_load():
+    from sas.plottools.arrow3d import Arrow3D
+    import os
+    dir = os.path.abspath(os.path.curdir)
+    print dir
+    for i in range(6):
+        dir, _ = os.path.split(dir)
+        tfile = os.path.join(dir, "test", "CoreXY_ShellZ.txt")
+        ofile = os.path.join(dir, "test", "A_Raw_Example-1.omf")
+        if os.path.isfile(tfile):
+            tfpath = tfile
+            ofpath = ofile
+            break
+    reader = SLDReader()
+    oreader = OMFReader()
+    output = reader.read(tfpath)
+    ooutput = oreader.read(ofpath)
+    foutput = OMF2SLD()
+    foutput.set_data(ooutput)
+
+    import matplotlib.pyplot as plt
+    from mpl_toolkits.mplot3d import Axes3D
+    fig = plt.figure()
+    ax = fig.gca(projection='3d')
+    ax.plot(output.pos_x, output.pos_y, output.pos_z, '.', c="g", 
+            alpha = 0.7, markeredgecolor='gray',rasterized=True)
+    gap = 7
+    max_mx = max(output.sld_mx)
+    max_my = max(output.sld_my)
+    max_mz = max(output.sld_mz)
+    max_m = max(max_mx,max_my,max_mz)
+    x2 = output.pos_x+output.sld_mx/max_m * gap
+    y2 = output.pos_y+output.sld_my/max_m * gap
+    z2 = output.pos_z+output.sld_mz/max_m * gap
+    x_arrow = numpy.column_stack((output.pos_x,x2))
+    y_arrow = numpy.column_stack((output.pos_y,y2))
+    z_arrow = numpy.column_stack((output.pos_z,z2))
+    unit_x2 = output.sld_mx / max_m
+    unit_y2 = output.sld_my / max_m
+    unit_z2 = output.sld_mz / max_m
+    color_x = numpy.fabs(unit_x2 * 0.8)
+    color_y = numpy.fabs(unit_y2 * 0.8)
+    color_z = numpy.fabs(unit_z2 * 0.8)
+    colors =  numpy.column_stack((color_x, color_y, color_z))
+    a = Arrow3D(None, x_arrow,y_arrow,z_arrow, colors, mutation_scale=10, lw=1, 
+                arrowstyle="->", color="y", alpha = 0.5)
+
+    ax.add_artist(a)
+    plt.show()
+    
+def test():
+    import os
+    dir = os.path.abspath(os.path.curdir)
+    for i in range(3):
+        dir, _ = os.path.split(dir)
+        #tfile = os.path.join(dir, "test", "C_Example_Converted.txt")
+        ofile = os.path.join(dir, "test", "A_Raw_Example-1.omf")
+        if os.path.isfile(ofile):
+            #tfpath = tfile
+            ofpath = ofile
+            break
+    #reader = SLDReader()
+    oreader = OMFReader()
+    #output = reader.read(tfpath)
+    ooutput = oreader.read(ofpath)
+    foutput = OMF2SLD() 
+    foutput.set_data(ooutput)  
+    writer =  SLDReader() 
+    writer.write(os.path.join(os.path.dirname(ofpath), "out.txt"), 
+                 foutput.output)
+    model = GenSAS()
+    model.set_sld_data(foutput.output) 
+    x = numpy.arange(1000)/10000. + 1e-5
+    y = numpy.arange(1000)/10000. + 1e-5
+    #z = numpy.arange(1000)/10000. + 1e-5
+    i = numpy.zeros(1000)
+    out = model.runXY([x,y,i])
+        
+if __name__ == "__main__": 
+    test()
+    test_load()
Index: src/sas/dataloader/readers/associations.py
===================================================================
--- src/sas/dataloader/readers/associations.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/dataloader/readers/associations.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -22,5 +22,5 @@
 
 ## Format version for the XML settings file
-VERSION = 'sansloader/1.0'
+VERSION = 'sasloader/1.0'
 
 
@@ -54,5 +54,5 @@
         
         # Read in the file extension associations
-        entry_list = root.xpath('/ns:SansLoader/ns:FileType',
+        entry_list = root.xpath('/ns:SasLoader/ns:FileType',
                                  namespaces={'ns': VERSION})
 
Index: src/sas/dataloader/readers/danse_reader.py
===================================================================
--- src/sas/dataloader/readers/danse_reader.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/dataloader/readers/danse_reader.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -35,7 +35,7 @@
     type_name = "DANSE"
     ## Wildcards
-    type = ["DANSE files (*.sas)|*.sas"]
+    type = ["DANSE files (*.sans)|*.sans"]
     ## Extension
-    ext  = ['.sas', '.SANS']
+    ext  = ['.sans', '.SANS']
         
     def read(self, filename=None):
Index: src/sas/dataloader/readers/defaults.xml
===================================================================
--- src/sas/dataloader/readers/defaults.xml	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/dataloader/readers/defaults.xml	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -1,5 +1,5 @@
 <?xml version="1.0"?>
-<SansLoader version="1.0"
-    xmlns="sansloader/1.0"
+<SasLoader version="1.0"
+    xmlns="sasloader/1.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     >
@@ -18,4 +18,4 @@
 	<FileType extension='.nxs' reader='nexus_reader'/>
     
-</SansLoader>
+</SasLoader>
 
Index: src/sas/fit/AbstractFitEngine.py
===================================================================
--- src/sas/fit/AbstractFitEngine.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/fit/AbstractFitEngine.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -65,14 +65,14 @@
 class Model:
     """
-    Fit wrapper for SANS models.
-    """
-    def __init__(self, sans_model, sans_data=None, **kw):
-        """
-        :param sans_model: the sas model to wrap using park interface
-
-        """
-        self.model = sans_model
-        self.name = sans_model.name
-        self.data = sans_data
+    Fit wrapper for SAS models.
+    """
+    def __init__(self, sas_model, sas_data=None, **kw):
+        """
+        :param sas_model: the sas model to wrap using park interface
+
+        """
+        self.model = sas_model
+        self.name = sas_model.name
+        self.data = sas_data
 
     def get_params(self, fitparams):
@@ -128,5 +128,5 @@
 class FitData1D(Data1D):
     """
-        Wrapper class  for SANS data
+        Wrapper class  for SAS data
         FitData1D inherits from DataLoader.data_info.Data1D. Implements
         a way to get residuals from data.
@@ -155,5 +155,5 @@
         Data1D.__init__(self, x=x, y=y, dx=dx, dy=dy)
         self.num_points = len(x)
-        self.sans_data = data
+        self.sas_data = data
         self.smearer = smearer
         self._first_unsmeared_bin = None
@@ -265,7 +265,7 @@
 class FitData2D(Data2D):
     """
-        Wrapper class  for SANS data
-    """
-    def __init__(self, sans_data2d, data=None, err_data=None):
+        Wrapper class  for SAS data
+    """
+    def __init__(self, sas_data2d, data=None, err_data=None):
         Data2D.__init__(self, data=data, err_data=err_data)
         # Data can be initialized with a sas plottable or with vectors.
@@ -278,19 +278,19 @@
         self.radius = 0
         self.res_err_data = []
-        self.sans_data = sans_data2d
-        self.set_data(sans_data2d)
-
-    def set_data(self, sans_data2d, qmin=None, qmax=None):
+        self.sas_data = sas_data2d
+        self.set_data(sas_data2d)
+
+    def set_data(self, sas_data2d, qmin=None, qmax=None):
         """
             Determine the correct qx_data and qy_data within range to fit
         """
-        self.data = sans_data2d.data
-        self.err_data = sans_data2d.err_data
-        self.qx_data = sans_data2d.qx_data
-        self.qy_data = sans_data2d.qy_data
-        self.mask = sans_data2d.mask
-
-        x_max = max(math.fabs(sans_data2d.xmin), math.fabs(sans_data2d.xmax))
-        y_max = max(math.fabs(sans_data2d.ymin), math.fabs(sans_data2d.ymax))
+        self.data = sas_data2d.data
+        self.err_data = sas_data2d.err_data
+        self.qx_data = sas_data2d.qx_data
+        self.qy_data = sas_data2d.qy_data
+        self.mask = sas_data2d.mask
+
+        x_max = max(math.fabs(sas_data2d.xmin), math.fabs(sas_data2d.xmax))
+        y_max = max(math.fabs(sas_data2d.ymin), math.fabs(sas_data2d.ymax))
         
         ## fitting range
@@ -453,10 +453,10 @@
         """
         if data.__class__.__name__ == 'Data2D':
-            fitdata = FitData2D(sans_data2d=data, data=data.data,
+            fitdata = FitData2D(sas_data2d=data, data=data.data,
                                  err_data=data.err_data)
         else:
             fitdata = FitData1D(x=data.x, y=data.y,
                                  dx=data.dx, dy=data.dy, smearer=smearer)
-        fitdata.sans_data = data
+        fitdata.sas_data = data
        
         fitdata.set_fit_range(qmin=qmin, qmax=qmax)
Index: src/sas/fit/BumpsFitting.py
===================================================================
--- src/sas/fit/BumpsFitting.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/fit/BumpsFitting.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -12,7 +12,7 @@
 from bumps.fitproblem import FitProblem
 
-from sas import FitEngine
-from sas import FResult
-from sas import compile_constraints
+from sas.fit.AbstractFitEngine import FitEngine
+from sas.fit.AbstractFitEngine import FResult
+from sas.fit.expression import compile_constraints
 
 class Progress(object):
@@ -91,5 +91,5 @@
 # The disadvantage of this technique is that we need to copy every parameter
 # back into the model each time the function is evaluated.  We could instead
-# define reference parameters for each sans parameter, but then we would not
+# define reference parameters for each sas parameter, but then we would not
 # be able to express constraints using python expressions in the usual way
 # from bumps, and would instead need to use string expressions.
Index: src/sas/fit/ParkFitting.py
===================================================================
--- src/sas/fit/ParkFitting.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/fit/ParkFitting.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -3,5 +3,5 @@
 
 """
-ParkFitting module contains SansParameter,Model,Data
+ParkFitting module contains SasParameter,Model,Data
 FitArrange, ParkFit,Parameter classes.All listed classes work together
 to perform a simple fit with park optimizer.
@@ -25,9 +25,9 @@
 from sas.fit.AbstractFitEngine import FResult
 
-class SansParameter(park.Parameter):
-    """
-    SANS model parameters for use in the PARK fitting service.
+class SasParameter(park.Parameter):
+    """
+    SAS model parameters for use in the PARK fitting service.
     The parameter attribute value is redirected to the underlying
-    parameter value in the SANS model.
+    parameter value in the SAS model.
     """
     def __init__(self, name, model, data):
@@ -100,21 +100,21 @@
 class ParkModel(park.Model):
     """
-    PARK wrapper for SANS models.
-    """
-    def __init__(self, sans_model, sans_data=None, **kw):
-        """
-        :param sans_model: the sas model to wrap using park interface
+    PARK wrapper for SAS models.
+    """
+    def __init__(self, sas_model, sas_data=None, **kw):
+        """
+        :param sas_model: the sas model to wrap using park interface
 
         """
         park.Model.__init__(self, **kw)
-        self.model = sans_model
-        self.name = sans_model.name
-        self.data = sans_data
+        self.model = sas_model
+        self.name = sas_model.name
+        self.data = sas_data
         #list of parameters names
-        self.sansp = sans_model.getParamList()
+        self.sasp = sas_model.getParamList()
         #list of park parameter
-        self.parkp = [SansParameter(p, sans_model, sans_data) for p in self.sansp]
+        self.parkp = [SasParameter(p, sas_model, sas_data) for p in self.sasp]
         #list of parameter set
-        self.parameterset = park.ParameterSet(sans_model.name, pars=self.parkp)
+        self.parameterset = park.ParameterSet(sas_model.name, pars=self.parkp)
         self.pars = []
 
@@ -176,5 +176,5 @@
 
 
-class SansFitResult(fitresult.FitResult):
+class SasFitResult(fitresult.FitResult):
     def __init__(self, *args, **kwrds):
         fitresult.FitResult.__init__(self, *args, **kwrds)
@@ -182,5 +182,5 @@
         self.inputs = []
         
-class SansFitSimplex(FitSimplex):
+class SasFitSimplex(FitSimplex):
     """
     Local minimizer using Nelder-Mead simplex algorithm.
@@ -216,7 +216,7 @@
         # Need to make our own copy of the fit results so that the
         # values don't get stomped on by the next fit iteration.
-        fitpars = [SansFitParameter(pars[i].name,pars[i].range,v, pars[i].model, pars[i].data)
+        fitpars = [SasFitParameter(pars[i].name,pars[i].range,v, pars[i].model, pars[i].data)
                    for i,v in enumerate(result.x)]
-        res = SansFitResult(fitpars, result.calls, result.fx)
+        res = SasFitResult(fitpars, result.calls, result.fx)
         res.inputs = [(pars[i].model, pars[i].data) for i,v in enumerate(result.x)]
         # Compute the parameter uncertainties from the jacobian
@@ -224,5 +224,5 @@
         return res
       
-class SansFitter(Fitter):
+class SasFitter(Fitter):
     """
     """
@@ -243,5 +243,5 @@
         handler.done = False
         self.handler = handler
-        fitpars = [SansFitParameter(pars[i].name, pars[i].range, v,
+        fitpars = [SasFitParameter(pars[i].name, pars[i].range, v,
                                      pars[i].model, pars[i].data)
                    for i,v in enumerate(x0)]
@@ -252,5 +252,5 @@
         self._fit(fitness, x0, bounds)
         
-class SansFitMC(SansFitter):
+class SasFitMC(SasFitter):
     """
     Monte Carlo optimizer.
@@ -258,5 +258,5 @@
     This implements `park.fit.Fitter`.
     """
-    localfit = SansFitSimplex()
+    localfit = SasFitSimplex()
     start_points = 10
     def __init__(self, localfit, start_points=10):
@@ -276,5 +276,5 @@
             raise ValueError, "Fit did not converge.\n"
         
-class SansPart(Part):
+class SasPart(Part):
     """
     Part of a fitting assembly.  Part holds the model itself and
@@ -318,5 +318,5 @@
         self.model, self.data = fitness[0], fitness[1]
 
-class SansFitParameter(FitParameter):
+class SasFitParameter(FitParameter):
     """
     Fit result for an individual parameter.
@@ -363,5 +363,5 @@
         self.parts = []
         for m in models:
-            self.parts.append(SansPart(m))
+            self.parts.append(SasPart(m))
         self.curr_thread = curr_thread
         self.chisq = None
@@ -390,5 +390,5 @@
         # Convert to fitparameter a object
         
-        fitpars = [SansFitParameter(p.path,p.range,p.value, p.model, p.data)
+        fitpars = [SasFitParameter(p.path,p.range,p.value, p.model, p.data)
                    for p in self._fitparameters]
         #print "fitpars", fitpars
@@ -399,5 +399,5 @@
         Extend result from the fit with the calculated parameters.
         """
-        calcpars = [SansFitParameter(p.path,p.range,p.value, p.model, p.data)
+        calcpars = [SasFitParameter(p.path,p.range,p.value, p.model, p.data)
                     for p in self.parameterset.computed]
         result.parameters += calcpars
@@ -493,5 +493,5 @@
     def create_assembly(self, curr_thread, reset_flag=False):
         """
-        Extract sansmodel and sansdata from 
+        Extract sasmodel and sasdata from 
         self.FitArrangelist ={Uid:FitArrange}
         Create parkmodel and park data ,form a list couple of parkmodel 
@@ -562,10 +562,10 @@
         """
         self.create_assembly(curr_thread=curr_thread, reset_flag=reset_flag)
-        localfit = SansFitSimplex()
+        localfit = SasFitSimplex()
         localfit.ftol = ftol
         localfit.xtol = 1e-6
 
         # See `park.fitresult.FitHandler` for details.
-        fitter = SansFitMC(localfit=localfit, start_points=1)
+        fitter = SasFitMC(localfit=localfit, start_points=1)
         if handler == None:
             handler = fitresult.ConsoleUpdate(improvement_delta=0.1)
@@ -584,5 +584,5 @@
         for m in self.problem.parts:
             residuals, theory = m.fitness.residuals()
-            small_result = FResult(model=m.model, data=m.data.sans_data)
+            small_result = FResult(model=m.model, data=m.data.sas_data)
             small_result.fitter_id = self.fitter_id
             small_result.theory = theory
Index: src/sas/fit/ScipyFitting.py
===================================================================
--- src/sas/fit/ScipyFitting.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/fit/ScipyFitting.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -14,7 +14,7 @@
 _SMALLVALUE = 1.0e-10
 
-class SansAssembly:
-    """
-    Sans Assembly class a class wrapper to be call in optimizer.leastsq method
+class SasAssembly:
+    """
+    Sas Assembly class a class wrapper to be call in optimizer.leastsq method
     """
     def __init__(self, paramlist, model=None, data=None, fitresult=None,
@@ -212,5 +212,5 @@
         if handler is not None:
             handler.set_result(result=result)
-        functor = SansAssembly(paramlist=pars,
+        functor = SasAssembly(paramlist=pars,
                                model=model,
                                data=data,
Index: src/sas/guiframe/CategoryInstaller.py
===================================================================
--- src/sas/guiframe/CategoryInstaller.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/guiframe/CategoryInstaller.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -33,5 +33,5 @@
         returns the dir where installed_models.txt should be
         """
-import sas.dataloader.readers
+        import sas.dataloader.readers
         return sas.dataloader.readers.get_data_path()
 
@@ -41,5 +41,5 @@
         returns the dir where models.py should be
         """
-import sas.perspectives.fitting.models
+        import sas.perspectives.fitting.models
         return sas.perspectives.fitting.models.get_model_python_path()
     
@@ -52,9 +52,9 @@
         # when deploying using py2app (it will be in Contents/Resources), or
         # py2exe (it will be in the exec dir).
-import sas.sansview
+        import sas.sasview
         cat_file = "default_categories.json"
         
         possible_cat_file_paths = [
-            os.path.join(os.path.split(sas.sansview.__file__)[0], cat_file),           # Source
+            os.path.join(os.path.split(sas.sasview.__file__)[0], cat_file),           # Source
             os.path.join(os.path.dirname(sys.executable), '..', 'Resources', cat_file), # Mac
             os.path.join(os.path.dirname(sys.executable), cat_file)                     # Windows
@@ -70,5 +70,5 @@
     def _get_home_dir():
         """
-        returns the users sansview config dir
+        returns the users sasview config dir
         """
         return os.path.join(os.path.expanduser("~"), ".sasview")
Index: src/sas/guiframe/config.py
===================================================================
--- src/sas/guiframe/config.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/guiframe/config.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -11,5 +11,5 @@
 __download_page__ = 'http://sourceforge.net/projects/sasview/files/'
 __update_URL__ = ['svn.code.sf.net', 
-                  '/p/sasview/code/trunk/sansview.latestversion']
+                  '/p/sasview/code/trunk/sasview.latestversion']
 
 
@@ -60,5 +60,5 @@
 _copyright = "(c) 2008, University of Tennessee"
 #edit the lists below of file state your plugin can read
-#for sansview this how you can edit these lists
+#for sasview this how you can edit these lists
 #PLUGIN_STATE_EXTENSIONS = ['.prv','.fitv', '.inv']
 #APPLICATION_STATE_EXTENSION = '.svs'
@@ -66,5 +66,5 @@
 #                  'Fitting files (*.fitv)|*.fitv',
 #                  'Invariant files (*.inv)|*.inv']
-#APPLICATION_WLIST = 'SansView files (*.svs)|*.svs'
+#APPLICATION_WLIST = 'SasView files (*.svs)|*.svs'
 APPLICATION_WLIST = ''
 APPLICATION_STATE_EXTENSION = None
Index: src/sas/guiframe/dummyapp.py
===================================================================
--- src/sas/guiframe/dummyapp.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/guiframe/dummyapp.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -101,5 +101,5 @@
                  "self._on_context_do_something"]]   
 
-class SansView():
+class SasView():
     
     def __init__(self):
@@ -124,3 +124,3 @@
     from multiprocessing import freeze_support
     freeze_support()
-    sansview = SansView()
+    sasview = SasView()
Index: src/sas/models/DisperseModel.py
===================================================================
--- src/sas/models/DisperseModel.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/DisperseModel.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -3,5 +3,5 @@
 """
 from sas.models.BaseComponent import BaseComponent
-from sans_extension.c_models import Disperser
+from sas_extension.c_models import Disperser
     
 class DisperseModel(Disperser, BaseComponent):
Index: src/sas/models/__init__.py
===================================================================
--- src/sas/models/__init__.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/__init__.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -1,4 +1,4 @@
 """
-    1D Modeling for SANS
+    1D Modeling for SAS
 """
 #from sas.models import *
Index: src/sas/models/c_extension/Doxyfile
===================================================================
--- src/sas/models/c_extension/Doxyfile	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/Doxyfile	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -4,5 +4,5 @@
 # Project related configuration options
 #---------------------------------------------------------------------------
-PROJECT_NAME           = sansmodeling
+PROJECT_NAME           = sasmodeling
 PROJECT_NUMBER         = 
 OUTPUT_DIRECTORY       = ../doc
@@ -114,8 +114,8 @@
 EXCLUDE                = build \
                          dist \
-                         sans/models/test \
+                         sas/models/test \
                          libigor \
                          igor_wrapper \
-                         sans/models/prototypes
+                         sas/models/prototypes
 EXCLUDE_SYMLINKS       = NO
 EXCLUDE_PATTERNS       = 
Index: src/sas/models/c_extension/c_models/c_models.cpp.template
===================================================================
--- src/sas/models/c_extension/c_models/c_models.cpp.template	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/c_models/c_models.cpp.template	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -1,5 +1,5 @@
 /** c_models
  *
- * Module containing all SANS model extensions
+ * Module containing all SAS model extensions
  *
  * @author   M.Doucet / UTK
@@ -7,5 +7,5 @@
 #include <Python.h>
 #include <parameters.hh>
-#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
+#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sas
 #include "arrayobject.h"
 
@@ -191,5 +191,5 @@
 
   m = Py_InitModule3("c_models", module_methods,
-      "C extension module for SANS scattering models.");
+      "C extension module for SAS scattering models.");
   import_array();
 
Index: src/sas/models/c_extension/libigor/GaussWeights.c
===================================================================
--- src/sas/models/c_extension/libigor/GaussWeights.c	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/libigor/GaussWeights.c	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -1,5 +1,5 @@
 /*
  *  GaussWeights.c
- *  SANSAnalysis
+ *  SASAnalysis
  *
  *  Created by Andrew Jackson on 4/23/07.
Index: src/sas/models/c_extension/libigor/GaussWeights.h
===================================================================
--- src/sas/models/c_extension/libigor/GaussWeights.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/libigor/GaussWeights.h	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -3,5 +3,5 @@
 /*
  *  GaussWeights.h
- *  SANSAnalysis
+ *  SASAnalysis
  *
  *  Created by Andrew Jackson on 4/23/07.
Index: src/sas/models/c_extension/libigor/StandardHeaders.h
===================================================================
--- src/sas/models/c_extension/libigor/StandardHeaders.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/libigor/StandardHeaders.h	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -1,5 +1,5 @@
 /*
  *  StandardHeaders.h
- *  SANSAnalysis
+ *  SASAnalysis
  *
  *  Created by Andrew Jackson on 4/23/07.
Index: src/sas/models/c_extension/libigor/libSANSAnalysis.h
===================================================================
--- src/sas/models/c_extension/libigor/libSANSAnalysis.h	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ 	(revision )
@@ -1,194 +1,0 @@
-/*
- *  libSANSAnalysis.h
- *  SANSAnalysis
- *
- *  Created by Andrew Jackson on 4/24/07.
- *  Copyright 2007 __MyCompanyName__. All rights reserved.
- *
- */
-
-#include "libCylinder.h"
-#include "libSphere.h"
-#include "libStructureFactor.h"
-#include "libTwoPhase.h"
-
-/*This should not be necessary AJJ May 09*/
-/* IGOR Fit Functions */
-/*
-double CylinderForm(double dp[], double q);
-double EllipCyl76(double dp[], double q);
-double EllipCyl20(double dp[], double q);
-double TriaxialEllipsoid(double dp[], double q);
-double Parallelepiped(double dp[], double q);
-double HollowCylinder(double dp[], double q);
-double EllipsoidForm(double dp[], double q);
-double Cyl_PolyRadius(double dp[], double q);
-double Cyl_PolyLength(double dp[], double q);
-double CoreShellCylinder(double dp[], double q);
-double OblateForm(double dp[], double q);
-double ProlateForm(double dp[], double q);
-double FlexExclVolCyl(double dp[], double q);
-double FlexCyl_PolyLen(double dp[], double q);
-double FlexCyl_PolyRad(double dp[], double q);
-double FlexCyl_Ellip(double dp[], double q);
-double PolyCoShCylinder(double dp[], double q);
-double StackedDiscs(double dp[], double q);
-double LamellarFF(double dp[], double q);
-double LamellarFF_HG(double dp[], double q);
-double LamellarPS(double dp[], double q);
-double LamellarPS_HG(double dp[], double q);
-//
-double Lamellar_ParaCrystal(double dp[], double q);
-double Spherocylinder(double dp[], double q);
-double ConvexLens(double dp[], double q);
-double Dumbbell(double dp[], double q);
-double CappedCylinder(double dp[], double q);
-double Barbell(double dp[], double q);
-double PolyCoreBicelle(double dp[], double q);
-*/
-
-/* internal functions */
-/*
-double CylKernel(double qq, double rr,double h, double theta);
-double NR_BessJ1(double x);
-double EllipCylKernel(double qq, double ra,double nu, double theta);
-double TriaxialKernel(double q, double aa, double bb, double cc, double dx, double dy);
-double PPKernel(double aa, double mu, double uu);
-double HolCylKernel(double qq, double rcore, double rshell, double length, double dum);
-double EllipsoidKernel(double qq, double a, double va, double dum);
-double Cyl_PolyRadKernel(double q, double radius, double length, double zz, double delrho, double dumRad);
-double SchulzPoint_cpr(double dumRad, double radius, double zz);
-double Cyl_PolyLenKernel(double q, double radius, double len_avg, double zz, double delrho, double dumLen);
-double CoreShellCylKernel(double qq, double rcore, double thick, double rhoc, double rhos, double rhosolv, double length, double dum);
-double gfn4(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
-double gfn2(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
-double FlePolyLen_kernel(double q, double radius, double length, double lb, double zz, double delrho, double zi);
-double FlePolyRad_kernel(double q, double ravg, double Lc, double Lb, double zz, double delrho, double zi);
-double EllipticalCross_fn(double qq, double a, double b);
-double CScyl(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length, double dum);
-double CSCylIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length);
-double Stackdisc_kern(double qq, double rcore, double rhoc, double rhol, double rhosolv, double length, double thick, double dum, double gsd, double d, double N);
-double BicelleKernel(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length, double dum);
-double BicelleIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length);
-*/
-
-
-//
-/* IGOR Fit Functions */
-/*
-double MultiShell(double dp[], double q);
-double PolyMultiShell(double dp[], double q);
-double SphereForm(double dp[], double q);
-double CoreShellForm(double dp[], double q);
-double PolyCoreForm(double dp[], double q);
-double PolyCoreShellRatio(double dp[], double q);
-double VesicleForm(double dp[], double q);
-double SchulzSpheres(double dp[], double q);
-double PolyRectSpheres(double dp[], double q);
-double PolyHardSphereIntensity(double dp[], double q);
-double BimodalSchulzSpheres(double dp[], double q);
-double GaussPolySphere(double dp[], double q);
-double LogNormalPolySphere(double dp[], double q);
-double BinaryHS(double dp[], double q);
-double BinaryHS_PSF11(double dp[], double q);
-double BinaryHS_PSF12(double dp[], double q);
-double BinaryHS_PSF22(double dp[], double q);
-//
-double OneShell(double dp[], double q);
-double TwoShell(double dp[], double q);
-double ThreeShell(double dp[], double q);
-double FourShell(double dp[], double q);
-double PolyOneShell(double dp[], double q);
-double PolyTwoShell(double dp[], double q);
-double PolyThreeShell(double dp[], double q);
-double PolyFourShell(double dp[], double q);
-double BCC_ParaCrystal(double dp[], double q);
-double FCC_ParaCrystal(double dp[], double q);
-double SC_ParaCrystal(double dp[], double q);
-
-//function prototypes
-double F_func(double qr);
-double MultiShellGuts(double q,double rcore,double ts,double tw,double rhocore,double rhoshel,int num);
-double fnt2(double yy, double zz);
-double fnt3(double yy, double pp, double zz);
-double SchulzSphere_Fn(double scale, double ravg, double pd, double rho, double rhos, double x);
-int ashcroft(double qval, double r2, double nf2, double aa, double phi, double *s11, double *s22, double *s12);
-
-
-////
-double HardSphereStruct(double dp[], double q);
-double SquareWellStruct(double dp[], double q);
-double StickyHS_Struct(double dp[], double q);
-double HayterPenfoldMSA(double dp[], double q);
-double DiamCyl(double a, double b);
-double DiamEllip(double a, double b);
-double sqhcal(double qq);
-int sqfun(int ix, int ir);
-int sqcoef(int ir);
-*/
-////
-/* IGOR Fit Functions */
-/*
-double TeubnerStreyModel(double dp[], double q);
-double Power_Law_Model(double dp[], double q);
-double Peak_Lorentz_Model(double dp[], double q);
-double Peak_Gauss_Model(double dp[], double q);
-double Lorentz_Model(double dp[], double q);
-double Fractal(double dp[], double q);
-double DAB_Model(double dp[], double q);
-double OneLevel(double dp[], double q);
-double TwoLevel(double dp[], double q);
-double ThreeLevel(double dp[], double q);
-double FourLevel(double dp[], double q);
-//
-double BroadPeak(double dp[], double q);
-double CorrLength(double dp[], double q);
-double TwoLorentzian(double dp[], double q);
-double TwoPowerLaw(double dp[], double q);
-double PolyGaussCoil(double dp[], double q);
-double GaussLorentzGel(double dp[], double q);
-double GaussianShell(double dp[], double q);
-*/
-
-// since the XOP and the library are separate chunks of compiled code
-// it is imperative to set ALL the structure alignments to be two-byte
-// rather than leave it to the whim of the compiler
-/* SRK08
-#include "XOPStructureAlignmentTwoByte.h"
-
-typedef struct {
-    double scale;
-    double radius;
-    double length;
-    double contrast;
-	double background;    
-    double cyl_theta;
-    double cyl_phi;    
-} CylinderParameters;
-
-typedef struct {
-    double scale;
-    double radius;
-    double length;
-    double contrast;
-	double background;
-    double cyl_theta;
-    double cyl_phi; 
-    double sigma_theta;
-    double sigma_phi;
-    double sigma_radius;
-} SmearCylinderParameters;
-
-#include "XOPStructureAlignmentReset.h"
-
-/// 1D scattering function
-double cylinder_analytical_1D(CylinderParameters *pars, double q);
-/// 2D scattering function
-double cylinder_analytical_2D(CylinderParameters *pars, double q, double phi);
-/// 1D scattering function
-double smeared_cylinder_analytical_1D(SmearCylinderParameters *pars, double q);
-/// 2D scattering function
-double dist_cylinder_2D(double pars[], double q, double phi);
-double smeared_cylinder_analytical_2D(SmearCylinderParameters *pars, double q, double phi);
-double smeared_cylinder_dist( double x, double mean, double sigma );
-*/
Index: src/sas/models/c_extension/libigor/libSASAnalysis.h
===================================================================
--- src/sas/models/c_extension/libigor/libSASAnalysis.h	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
+++ src/sas/models/c_extension/libigor/libSASAnalysis.h	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -0,0 +1,194 @@
+/*
+ *  libSASAnalysis.h
+ *  SASAnalysis
+ *
+ *  Created by Andrew Jackson on 4/24/07.
+ *  Copyright 2007 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "libCylinder.h"
+#include "libSphere.h"
+#include "libStructureFactor.h"
+#include "libTwoPhase.h"
+
+/*This should not be necessary AJJ May 09*/
+/* IGOR Fit Functions */
+/*
+double CylinderForm(double dp[], double q);
+double EllipCyl76(double dp[], double q);
+double EllipCyl20(double dp[], double q);
+double TriaxialEllipsoid(double dp[], double q);
+double Parallelepiped(double dp[], double q);
+double HollowCylinder(double dp[], double q);
+double EllipsoidForm(double dp[], double q);
+double Cyl_PolyRadius(double dp[], double q);
+double Cyl_PolyLength(double dp[], double q);
+double CoreShellCylinder(double dp[], double q);
+double OblateForm(double dp[], double q);
+double ProlateForm(double dp[], double q);
+double FlexExclVolCyl(double dp[], double q);
+double FlexCyl_PolyLen(double dp[], double q);
+double FlexCyl_PolyRad(double dp[], double q);
+double FlexCyl_Ellip(double dp[], double q);
+double PolyCoShCylinder(double dp[], double q);
+double StackedDiscs(double dp[], double q);
+double LamellarFF(double dp[], double q);
+double LamellarFF_HG(double dp[], double q);
+double LamellarPS(double dp[], double q);
+double LamellarPS_HG(double dp[], double q);
+//
+double Lamellar_ParaCrystal(double dp[], double q);
+double Spherocylinder(double dp[], double q);
+double ConvexLens(double dp[], double q);
+double Dumbbell(double dp[], double q);
+double CappedCylinder(double dp[], double q);
+double Barbell(double dp[], double q);
+double PolyCoreBicelle(double dp[], double q);
+*/
+
+/* internal functions */
+/*
+double CylKernel(double qq, double rr,double h, double theta);
+double NR_BessJ1(double x);
+double EllipCylKernel(double qq, double ra,double nu, double theta);
+double TriaxialKernel(double q, double aa, double bb, double cc, double dx, double dy);
+double PPKernel(double aa, double mu, double uu);
+double HolCylKernel(double qq, double rcore, double rshell, double length, double dum);
+double EllipsoidKernel(double qq, double a, double va, double dum);
+double Cyl_PolyRadKernel(double q, double radius, double length, double zz, double delrho, double dumRad);
+double SchulzPoint_cpr(double dumRad, double radius, double zz);
+double Cyl_PolyLenKernel(double q, double radius, double len_avg, double zz, double delrho, double dumLen);
+double CoreShellCylKernel(double qq, double rcore, double thick, double rhoc, double rhos, double rhosolv, double length, double dum);
+double gfn4(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
+double gfn2(double xx, double crmaj, double crmin, double trmaj, double trmin, double delpc, double delps, double qq);
+double FlePolyLen_kernel(double q, double radius, double length, double lb, double zz, double delrho, double zi);
+double FlePolyRad_kernel(double q, double ravg, double Lc, double Lb, double zz, double delrho, double zi);
+double EllipticalCross_fn(double qq, double a, double b);
+double CScyl(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length, double dum);
+double CSCylIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhos, double rhosolv, double length);
+double Stackdisc_kern(double qq, double rcore, double rhoc, double rhol, double rhosolv, double length, double thick, double dum, double gsd, double d, double N);
+double BicelleKernel(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length, double dum);
+double BicelleIntegration(double qq, double rad, double radthick, double facthick, double rhoc, double rhoh, double rhor, double rhosolv, double length);
+*/
+
+
+//
+/* IGOR Fit Functions */
+/*
+double MultiShell(double dp[], double q);
+double PolyMultiShell(double dp[], double q);
+double SphereForm(double dp[], double q);
+double CoreShellForm(double dp[], double q);
+double PolyCoreForm(double dp[], double q);
+double PolyCoreShellRatio(double dp[], double q);
+double VesicleForm(double dp[], double q);
+double SchulzSpheres(double dp[], double q);
+double PolyRectSpheres(double dp[], double q);
+double PolyHardSphereIntensity(double dp[], double q);
+double BimodalSchulzSpheres(double dp[], double q);
+double GaussPolySphere(double dp[], double q);
+double LogNormalPolySphere(double dp[], double q);
+double BinaryHS(double dp[], double q);
+double BinaryHS_PSF11(double dp[], double q);
+double BinaryHS_PSF12(double dp[], double q);
+double BinaryHS_PSF22(double dp[], double q);
+//
+double OneShell(double dp[], double q);
+double TwoShell(double dp[], double q);
+double ThreeShell(double dp[], double q);
+double FourShell(double dp[], double q);
+double PolyOneShell(double dp[], double q);
+double PolyTwoShell(double dp[], double q);
+double PolyThreeShell(double dp[], double q);
+double PolyFourShell(double dp[], double q);
+double BCC_ParaCrystal(double dp[], double q);
+double FCC_ParaCrystal(double dp[], double q);
+double SC_ParaCrystal(double dp[], double q);
+
+//function prototypes
+double F_func(double qr);
+double MultiShellGuts(double q,double rcore,double ts,double tw,double rhocore,double rhoshel,int num);
+double fnt2(double yy, double zz);
+double fnt3(double yy, double pp, double zz);
+double SchulzSphere_Fn(double scale, double ravg, double pd, double rho, double rhos, double x);
+int ashcroft(double qval, double r2, double nf2, double aa, double phi, double *s11, double *s22, double *s12);
+
+
+////
+double HardSphereStruct(double dp[], double q);
+double SquareWellStruct(double dp[], double q);
+double StickyHS_Struct(double dp[], double q);
+double HayterPenfoldMSA(double dp[], double q);
+double DiamCyl(double a, double b);
+double DiamEllip(double a, double b);
+double sqhcal(double qq);
+int sqfun(int ix, int ir);
+int sqcoef(int ir);
+*/
+////
+/* IGOR Fit Functions */
+/*
+double TeubnerStreyModel(double dp[], double q);
+double Power_Law_Model(double dp[], double q);
+double Peak_Lorentz_Model(double dp[], double q);
+double Peak_Gauss_Model(double dp[], double q);
+double Lorentz_Model(double dp[], double q);
+double Fractal(double dp[], double q);
+double DAB_Model(double dp[], double q);
+double OneLevel(double dp[], double q);
+double TwoLevel(double dp[], double q);
+double ThreeLevel(double dp[], double q);
+double FourLevel(double dp[], double q);
+//
+double BroadPeak(double dp[], double q);
+double CorrLength(double dp[], double q);
+double TwoLorentzian(double dp[], double q);
+double TwoPowerLaw(double dp[], double q);
+double PolyGaussCoil(double dp[], double q);
+double GaussLorentzGel(double dp[], double q);
+double GaussianShell(double dp[], double q);
+*/
+
+// since the XOP and the library are separate chunks of compiled code
+// it is imperative to set ALL the structure alignments to be two-byte
+// rather than leave it to the whim of the compiler
+/* SRK08
+#include "XOPStructureAlignmentTwoByte.h"
+
+typedef struct {
+    double scale;
+    double radius;
+    double length;
+    double contrast;
+	double background;    
+    double cyl_theta;
+    double cyl_phi;    
+} CylinderParameters;
+
+typedef struct {
+    double scale;
+    double radius;
+    double length;
+    double contrast;
+	double background;
+    double cyl_theta;
+    double cyl_phi; 
+    double sigma_theta;
+    double sigma_phi;
+    double sigma_radius;
+} SmearCylinderParameters;
+
+#include "XOPStructureAlignmentReset.h"
+
+/// 1D scattering function
+double cylinder_analytical_1D(CylinderParameters *pars, double q);
+/// 2D scattering function
+double cylinder_analytical_2D(CylinderParameters *pars, double q, double phi);
+/// 1D scattering function
+double smeared_cylinder_analytical_1D(SmearCylinderParameters *pars, double q);
+/// 2D scattering function
+double dist_cylinder_2D(double pars[], double q, double phi);
+double smeared_cylinder_analytical_2D(SmearCylinderParameters *pars, double q, double phi);
+double smeared_cylinder_dist( double x, double mean, double sigma );
+*/
Index: src/sas/models/c_extension/python_wrapper/WrapperGenerator.py
===================================================================
--- src/sas/models/c_extension/python_wrapper/WrapperGenerator.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/python_wrapper/WrapperGenerator.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -19,9 +19,9 @@
         
         where my_model must be replaced by the name of the
-        class that you want to import from sans.models.
+        class that you want to import from sas.models.
         (example: [PYTHONCLASS] = MyModel
-          will create a class MyModel in sans.models.MyModel.
+          will create a class MyModel in sas.models.MyModel.
           It will also create a class CMyModel in 
-          sans_extension.c_models.)
+          sas_extension.c_models.)
           
         Also in comments, each parameter of the params 
Index: src/sas/models/c_extension/python_wrapper/classTemplate.txt
===================================================================
--- src/sas/models/c_extension/python_wrapper/classTemplate.txt	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/python_wrapper/classTemplate.txt	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -23,5 +23,5 @@
  */
 #define NO_IMPORT_ARRAY
-#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sans
+#define PY_ARRAY_UNIQUE_SYMBOL PyArray_API_sas
  
 extern "C" {
Index: src/sas/models/c_extension/python_wrapper/modelTemplate.txt
===================================================================
--- src/sas/models/c_extension/python_wrapper/modelTemplate.txt	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/python_wrapper/modelTemplate.txt	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -24,6 +24,6 @@
 """
 
-from sans.models.BaseComponent import BaseComponent
-from sans.models.sans_extension.c_models import [CPYTHONCLASS]
+from sas.models.BaseComponent import BaseComponent
+from sas.models.sas_extension.c_models import [CPYTHONCLASS]
 
 def create_[PYTHONCLASS]():
Index: src/sas/models/c_extension/python_wrapper/wrapping.py
===================================================================
--- src/sas/models/c_extension/python_wrapper/wrapping.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/python_wrapper/wrapping.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -24,10 +24,10 @@
 
 def write_c_models(model_list):
-    # simultaneously generates 'sansmodels/installed_models.txt'
-    # and 'sansmodels/src/c_models/c_models.cpp'
+    # simultaneously generates 'sasmodels/installed_models.txt'
+    # and 'sasmodels/src/c_models/c_models.cpp'
     
 
-    template_file = open(os.path.join("src", "sans", "models","c_extension","c_models","c_models.cpp.template"),"r")
-    write_file = open(os.path.join("src", "sans",  "models","c_extension","c_models","c_models.cpp"),"w")
+    template_file = open(os.path.join("src", "sas", "models","c_extension","c_models","c_models.cpp.template"),"r")
+    write_file = open(os.path.join("src", "sas",  "models","c_extension","c_models","c_models.cpp"),"w")
     buf = template_file.read()
     lines = buf.split('\n')
@@ -63,5 +63,5 @@
 if __name__ == '__main__':
     header_dir = os.path.join('..', 'include')
-    generate_wrappers(header_dir, output_dir="../sans/models/", c_wrapper_dir='.')
+    generate_wrappers(header_dir, output_dir="../sas/models/", c_wrapper_dir='.')
 
 
Index: src/sas/models/c_extension/release_notes.txt
===================================================================
--- src/sas/models/c_extension/release_notes.txt	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/c_extension/release_notes.txt	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -2,5 +2,5 @@
 =============
 
-SANS Models version 0.4.3
+SAS Models version 0.4.3
 
 Package name: sans.models 
Index: src/sas/models/dispersion_models.py
===================================================================
--- src/sas/models/dispersion_models.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/dispersion_models.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -22,5 +22,5 @@
 
 Usage:
-These classes can be used to set the dispersion model of a SANS model
+These classes can be used to set the dispersion model of a SAS model
 parameter:
 
@@ -43,5 +43,5 @@
     
 """
-import sans_extension.c_models as c_models 
+import sas_extension.c_models as c_models 
 
 
Index: src/sas/models/media/pd_help.html
===================================================================
--- src/sas/models/media/pd_help.html	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/media/pd_help.html	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -56,5 +56,5 @@
 <p>This distribution is to be given
 by users as a txt file where the array should be defined by two columns in the
-order of x and f(x) values. The f(x) will be normalized by SansView during the
+order of x and f(x) values. The f(x) will be normalized by SasView during the
 computation.</p>
 
Index: src/sas/models/media/smear_computation.html
===================================================================
--- src/sas/models/media/smear_computation.html	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/media/smear_computation.html	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -27,5 +27,5 @@
 
 <p class=MsoNormal><span style='font-family:"Times New Roman","serif"'>The sit
-smeared scattering intensity for SANS is defined by</span></p>
+smeared scattering intensity for SAS is defined by</span></p>
 
 <p class=MsoNormal><img 
@@ -155,6 +155,6 @@
 number of iteration, say at least 10000 by 10000 for each element of the matrix
 W, which will take minutes and minutes to finish the calculation for a set of
-typical SANS data. An alternative way which is correct for slit width &lt;&lt;
-slit hight, is used in the SANSView:  This method is a mixed method that
+typical SAS data. An alternative way which is correct for slit width &lt;&lt;
+slit hight, is used in the SASView:  This method is a mixed method that
 combines the method 1) with the numerical integration for the slit width.</span></p>
 
@@ -272,5 +272,5 @@
 
 <p class=MsoNormal><span style='font-family:"Times New Roman","serif"'>Here, the
-current version of the SANSVIEW uses the Eq. (11) for 2D smearing assuming that
+current version of the SASVIEW uses the Eq. (11) for 2D smearing assuming that
 all the Gaussian weighting functions are aligned in the polar coordinate. </span></p>
 <p> In the control panel, the higher accuracy indicates more and finer binnng points 
Index: src/sas/models/qsmearing.py
===================================================================
--- src/sas/models/qsmearing.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/qsmearing.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -34,5 +34,5 @@
     :param model: sas.model instance
     """
-    # Sanity check. If we are not dealing with a SANS Data1D
+    # Sanity check. If we are not dealing with a SAS Data1D
     # object, just return None
     if  data1D.__class__.__name__ not in ['Data1D', 'Theory1D']:
@@ -343,5 +343,5 @@
 class SlitSmearer(_SlitSmearer):
     """
-    Adaptor for slit smearing class and SANS data
+    Adaptor for slit smearing class and SAS data
     """
     def __init__(self, data1D, model = None):
@@ -461,5 +461,5 @@
 class QSmearer(_QSmearer):
     """
-    Adaptor for Gaussian Q smearing class and SANS data
+    Adaptor for Gaussian Q smearing class and SAS data
     """
     def __init__(self, data1D, model = None):
Index: src/sas/models/smearing_2d.py
===================================================================
--- src/sas/models/smearing_2d.py	(revision 794922220f2fb3b23dd08c648aabf87b4850596c)
+++ src/sas/models/smearing_2d.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -19,5 +19,5 @@
 class Smearer2D:
     """
-    Gaussian Q smearing class for SANS 2d data
+    Gaussian Q smearing class for SAS 2d data
     """
      
@@ -152,5 +152,5 @@
         if self._engine == 'c' and self.coords == 'polar':
             try:
-import sas.models.sas_extension.smearer2d_helper as smearer2dc
+                import sas.models.sas_extension.smearer2d_helper as smearer2dc
                 smearc = smearer2dc.new_Smearer_helper(self.qx_data, 
                                               self.qy_data,
Index: src/sas/perspectives/fitting/fitting.py
===================================================================
--- src/sas/perspectives/fitting/fitting.py	(revision b9a5f0eb8e8cbff8f8d934bbfa4ea18168141e13)
+++ src/sas/perspectives/fitting/fitting.py	(revision fd5ac0db8089df5bd882587f157d4bf317cfcf67)
@@ -51,5 +51,5 @@
 
 MAX_NBR_DATA = 4
-SANS_F_TOL = 5e-05
+SAS_F_TOL = 5e-05
 
 (PageInfoEvent, EVT_PAGE_INFO) = wx.lib.newevent.NewEvent()
@@ -94,5 +94,5 @@
         self._gui_engine = None
         ## Relative error desired in the sum of squares (float); scipy only
-        self.ftol = SANS_F_TOL
+        self.ftol = SAS_F_TOL
         self.batch_reset_flag = True
         #List of selected data
@@ -291,5 +291,5 @@
                 msg += "Please manually remove the files (.py, .pyc) "
                 msg += "in the 'plugin_models' folder \n"
-                msg += "inside of the SansView application, "
+                msg += "inside of the SasView application, "
                 msg += "and try it again."
                 wx.MessageBox(msg, 'Info')
@@ -817,5 +817,5 @@
         except:
             # default
-            f_tol = SANS_F_TOL
+            f_tol = SAS_F_TOL
             
         self.ftol = f_tol
@@ -1373,6 +1373,6 @@
                 if model is not None and hasattr(model, "model"):
                     model = model.model
-                if data is not None and hasattr(data, "sans_data"):
-                    data = data.sans_data
+                if data is not None and hasattr(data, "sas_data"):
+                    data = data.sas_data
                 
                 is_data2d = issubclass(data.__class__, Data2D)
