Пример #1
0
    def __init__(self, bkg, name, dq, threads, quad_order):
        self.name = name
        self.threads = threads
        self.quad_order = quad_order
        self._bkg = possibly_create_parameter(bkg, name='bkg')

        # we can optimize the resolution (but this is always overridden by
        # x_err if supplied. There is therefore possibly no dependence on it.
        self._dq = possibly_create_parameter(dq, name='dq - resolution')
Пример #2
0
    def __init__(self, gamma, vf, dz, polymer_sld, name='',
                 left_slabs=(), right_slabs=(),
                 interpolator=Pchip, zgrad=True, monotonic_penalty=0,
                 microslab_max_thickness=1):
        self.name = name

        self.gamma = (
            possibly_create_parameter(gamma,
                                      name='%s - adsorbed amount' % name))

        if isinstance(polymer_sld, SLD):
            self.polymer_sld = polymer_sld
        else:
            self.polymer_sld = SLD(polymer_sld)

        # left and right slabs are other areas where the same polymer can
        # reside
        self.left_slabs = [slab for slab in left_slabs if
                           isinstance(slab, Slab)]
        self.right_slabs = [slab for slab in right_slabs if
                            isinstance(slab, Slab)]

        self.microslab_max_thickness = microslab_max_thickness

        # dz are the spatial spacings of the spline knots
        self.dz = Parameters(name='dz - spline')
        for i, z in enumerate(dz):
            p = possibly_create_parameter(
                z,
                name='%s - spline dz[%d]' % (name, i))
            p.range(0, 1)
            self.dz.append(p)

        # vf are the volume fraction values of each of the spline knots
        self.vf = Parameters(name='vf - spline')
        for i, v in enumerate(vf):
            p = possibly_create_parameter(
                v,
                name='%s - spline vf[%d]' % (name, i))
            p.range(0, 2.)
            self.vf.append(p)

        if len(self.vf) != len(self.dz):
            raise ValueError("dz and vs must have same number of entries")

        self.monotonic_penalty = monotonic_penalty
        self.zgrad = zgrad
        self.interpolator = interpolator

        self.__cached_interpolator = {'zeds': np.array([]),
                                      'vf': np.array([]),
                                      'interp': None}
Пример #3
0
    def __init__(self, value=None, A=None, B=0, C=0, name=""):
        if (type(value) is str
                and name == ""):  # if there is no name get it from the path
            name = os.path.basename(value).split(".")[0]

        super(RI, self).__init__(name=name)

        assert np.logical_xor(
            value is None,
            A is None), "Supply either values or cauchy parameters"

        if value is not None:
            if type(value) is str:

                try:
                    self._wav, self._RI, self._EC = np.loadtxt(
                        value, skiprows=1, delimiter=",", encoding="utf8").T
                except ValueError:
                    self._wav, self._RI = np.loadtxt(
                        value,
                        skiprows=1,
                        delimiter=",",
                        usecols=[0, 1],
                        encoding="utf8",
                    ).T
                    self._EC = np.zeros_like(self._wav)

            elif len(value) == 2:
                self._RI, self._EC = value
                self._wav = None
            elif len(value) == 3:
                self._wav, self._RI, self._EC = value
            else:
                raise TypeError("format not recognised")
            # convert wavelength from um to nm
            self._wav = self._wav * 1000
        else:
            self._wav = None
            self._RI = None
            self._EC = None

        self.model = None
        self.set_wav = None
        self._default_wav = 658
        self._parameters = Parameters(name=name)

        if A is not None:
            self.A = possibly_create_parameter(A, name=f"{name} - cauchy A")
            self.B = possibly_create_parameter(B, name=f"{name} - cauchy B")
            self.C = possibly_create_parameter(C, name=f"{name} - cauchy C")
            self._parameters.extend([self.A, self.B, self.C])
Пример #4
0
    def __init__(self,
                 apm,
                 b_heads,
                 vm_heads,
                 thickness_heads,
                 b_tails,
                 vm_tails,
                 thickness_tails,
                 rough_head_tail,
                 rough_preceding_mono,
                 water_vm,
                 waters_per_head,
                 waters_per_tail,
                 b_mscl,
                 vm_mscl,
                 PLRatio,
                 head_solvent=None,
                 tail_solvent=None,
                 reverse_monolayer=False,
                 name=''):

        super(LipidLeafletWithProtien,
              self).__init__(apm, b_heads, vm_heads, thickness_heads, b_tails,
                             vm_tails, thickness_tails, rough_head_tail,
                             rough_preceding_mono, head_solvent, tail_solvent,
                             reverse_monolayer, name)

        if isinstance(b_mscl, complex):
            self.b_mscl_real = possibly_create_parameter(
                b_mscl.real, name='%s - b_mscl_real' % name)
            self.b_mscl_imag = possibly_create_parameter(
                b_mscl.imag, name='%s - b_mscl_imag' % name)
        elif isinstance(b_mscl, SLD):
            self.b_mscl_real = b_mscl.real
            self.b_mscl_imag = b_mscl.imag
        else:
            self.b_mscl_real = possibly_create_parameter(
                b_mscl, name='%s - b_mscl_real' % name)
            self.b_mscl_imag = possibly_create_parameter(
                0, name='%s - b_mscl_imag' % name)

        self.vm_mscl = possibly_create_parameter(
            vm_mscl, name='%s - vm_mscl, protien volume' % name)

        self.PLRatio = possibly_create_parameter(
            PLRatio, name='%s - PLRatio, protien lipid ratio' % name)

        self.water_vm = possibly_create_parameter(water_vm,
                                                  name='%s - water_vm' % name)

        self.waters_per_head = possibly_create_parameter(
            waters_per_head, name='%s - waters_per_head' % name)

        self.waters_per_tail = possibly_create_parameter(
            waters_per_tail, name='%s - waters_per_tail' % name)
Пример #5
0
    def __init__(self,
                 apm,
                 b_heads,
                 vm_heads,
                 thickness_heads,
                 b_tails,
                 vm_tails,
                 thickness_tails,
                 rough_head_tail,
                 rough_preceding_mono,
                 water_vm,
                 waters_per_head,
                 waters_per_tail,
                 vm_mscl,
                 PLRatio,
                 head_solvent=None,
                 tail_solvent=None,
                 reverse_monolayer=False,
                 name=''):

        super(LipidLeafletWithProtien,
              self).__init__(apm, b_heads, vm_heads, thickness_heads, b_tails,
                             vm_tails, thickness_tails, rough_head_tail,
                             rough_preceding_mono, water_vm, waters_per_head,
                             waters_per_tail, head_solvent, tail_solvent,
                             reverse_monolayer, name)

        #         if isinstance(b_mscl, complex):
        #             self.b_mscl_real = possibly_create_parameter(
        #                 b_mscl.real,
        #                 name='%s - b_mscl_real' % name)
        #             self.b_mscl_imag = possibly_create_parameter(
        #                 b_mscl.imag,
        #                 name='%s - b_mscl_imag' % name)
        #         elif isinstance(b_mscl, SLD):
        #             self.b_mscl_real = b_mscl.real
        #             self.b_mscl_imag = b_mscl.imag
        #         else:
        #             self.b_mscl_real = possibly_create_parameter(
        #                 b_mscl,
        #                 name='%s - b_mscl_real' % name)
        #             self.b_mscl_imag = possibly_create_parameter(
        #                 0,
        #                 name='%s - b_mscl_imag' % name)

        self.vm_mscl = possibly_create_parameter(
            vm_mscl, name='%s - vm_mscl, protien volume' % name)

        self.PLRatio = possibly_create_parameter(
            PLRatio, name='%s - PLRatio, fraction lipid to protein' % name)
Пример #6
0
    def __init__(self,
                 extent,
                 vs,
                 dz,
                 left,
                 right,
                 solvent,
                 name='',
                 interpolator=Pchip,
                 zgrad=True,
                 microslab_max_thickness=1):
        self.name = name
        self.left_slab = left
        self.right_slab = right
        self.solvent = solvent
        self.microslab_max_thickness = microslab_max_thickness

        self.extent = (possibly_create_parameter(extent,
                                                 name='%s - spline extent' %
                                                 name))

        self.dz = Parameters(name='dz - spline')
        for i, z in enumerate(dz):
            p = possibly_create_parameter(z,
                                          name='%s - spline dz[%d]' %
                                          (name, i))
            p.range(0, 1)
            self.dz.append(p)

        self.vs = Parameters(name='vs - spline')
        for i, v in enumerate(vs):
            p = possibly_create_parameter(v,
                                          name='%s - spline vs[%d]' %
                                          (name, i))
            self.vs.append(p)

        if len(self.vs) != len(self.dz):
            raise ValueError("dz and vs must have same number of entries")

        self.zgrad = zgrad
        self.interpolator = interpolator

        self.__cached_interpolator = {
            'zeds': np.array([]),
            'vs': np.array([]),
            'interp': None,
            'extent': -1
        }
Пример #7
0
    def __init__(self, models, scales, add_params=None, bkg=1e-7, name='',
                 dq=5, threads=-1, quad_order=17):
        super().__init__(bkg=1e-7, name='', dq=5, threads=-1, quad_order=17)

        self.models = models

        if scales is not None and len(models) == len(scales):
            tscales = scales
        elif scales is not None and len(models) != len(scales):
            raise ValueError("You need to supply scale factor for each"
                             " structure")
        else:
            tscales = [1 / len(models)] * len(models)

        pscales = []
        for scale_num, scale in enumerate(tscales):
            p_scale = possibly_create_parameter(scale, name='scale %d'%scale_num)
            pscales.append(p_scale)

        self._scales = pscales

        if add_params is not None:
            self.additional_params = []
            for param in add_params:
                self.additional_params.append(param)
Пример #8
0
    def __init__(
        self,
        model,
        data,
        lnsigma=None,
        use_weights=True,
        transform=None,
        logp_extra=None,
        name=None,
    ):
        self.model = model
        # should be a DataSE instance
        if type(data) is DataSE:
            self.data = data
        else:
            print("bad")
            self.data = DataSE(data=data)

        self.lnsigma = lnsigma
        if lnsigma is not None:
            self.lnsigma = possibly_create_parameter(lnsigma, "lnsigma")

        self._use_weights = use_weights
        self.transform = transform
        self.logp_extra = logp_extra
        self.name = name
        if name is None:
            self.name = id(self)

        self.model._flip_delta = self.data._delta_flipped
Пример #9
0
    def __init__(
        self,
        model,
        data,
        lnsigma=None,
        use_weights=True,
        transform=None,
        logp_extra=None,
        name=None,
    ):
        self.model = model
        # should be a Data1D instance
        if isinstance(data, Data1D):
            self.data = data
        else:
            self.data = Data1D(data=data)

        self.lnsigma = lnsigma
        if lnsigma is not None:
            self.lnsigma = possibly_create_parameter(lnsigma, "lnsigma")

        self._use_weights = use_weights
        self.transform = transform
        self.logp_extra = logp_extra
        self.name = name
        if name is None:
            self.name = id(self)
Пример #10
0
    def remove_structure(self, row):
        # don't remove the last structure
        if row < STRUCT_OFFSET or len(self.structures) < 2:
            return

        # you have to be a mixedreflectmodel because there's more than one
        # structure
        data_object_node = find_data_object(self.index)
        data_object = data_object_node.data_object
        orig_model = data_object.model
        structures = orig_model.structures
        scales = orig_model.scales

        # going down to a single reflectmodel
        if len(structures) == 2:
            self._model.beginRemoveRows(self.index, row, row)
            # remove all dependent parameters (either in this dataset or
            # elsewhere)
            # do this before the Structure is popped.
            self._model.unlink_dependent_parameters(self.child(row))

            structures.pop(row - STRUCT_OFFSET)
            scales.pop(row - STRUCT_OFFSET)
            sf = possibly_create_parameter(scales[0], name="scale")
            new_model = ReflectModel(structures[0],
                                     scale=sf,
                                     bkg=orig_model.bkg,
                                     dq=orig_model.dq)
            data_object.model = new_model
            self.popChild(row)
            self._model.endRemoveRows()
            n = ParNode(sf, self._model, self)
            self._model.beginInsertRows(self.index, 0, 0)
            self.insertChild(0, n)
            self._model.endInsertRows()
            self._model.beginRemoveRows(self.index, 1, 1)
            self.popChild(1)
            self._model.endRemoveRows()
            # data_object_node.set_reflect_model(new_model)
            return

        # you're not down to a single structure, so there must have been more
        # than 2 structures
        self._model.beginRemoveRows(self.index, row, row)

        # remove all dependent parameters (either in this dataset or elsewhere)
        # do this before the Structure is popped.
        self._model.unlink_dependent_parameters(self.child(row))

        # pop the structure and scale factor nodes
        self.popChild(row)
        structures.pop(row - STRUCT_OFFSET)
        scales.pop(row - STRUCT_OFFSET)
        self._model.endRemoveRows()

        self._model.beginRemoveRows(
            self.child(0).index, row - STRUCT_OFFSET, row - STRUCT_OFFSET)
        self.child(0).popChild(row - STRUCT_OFFSET)
        self._model.endRemoveRows()
Пример #11
0
    def __init__(
        self,
        structures,
        scales=None,
        bkg=1e-7,
        name="",
        dq=5.0,
        threads=-1,
        quad_order=17,
        dq_type="pointwise",
        q_offset=0.0,
    ):
        self.name = name
        self._parameters = None
        self.threads = threads
        self.quad_order = quad_order

        # all reflectometry models need a scale factor and background. Set
        # them all to 1 by default.
        pscales = Parameters(name="scale factors")

        if scales is not None and len(structures) == len(scales):
            tscales = scales
        elif scales is not None and len(structures) != len(scales):
            raise ValueError("You need to supply scale factor for each"
                             " structure")
        else:
            tscales = [1 / len(structures)] * len(structures)

        for scale in tscales:
            p_scale = possibly_create_parameter(scale, name="scale")
            pscales.append(p_scale)

        self._scales = pscales
        self._bkg = possibly_create_parameter(bkg, name="bkg")

        # we can optimize the resolution (but this is always overridden by
        # x_err if supplied. There is therefore possibly no dependence on it.
        self._dq = possibly_create_parameter(dq, name="dq - resolution")
        self.dq_type = dq_type

        self._q_offset = possibly_create_parameter(q_offset,
                                                   name="q_offset",
                                                   units="Å**-1")

        self._structures = structures
Пример #12
0
    def __init__(
        self,
        extent,
        vs,
        dz,
        name="",
        interpolator=Pchip,
        zgrad=True,
        microslab_max_thickness=1,
    ):
        super(Spline, self).__init__()
        self.name = name
        self.microslab_max_thickness = microslab_max_thickness

        self.extent = possibly_create_parameter(extent,
                                                name="%s - spline extent" %
                                                name)

        self.dz = Parameters(name="dz - spline")
        for i, z in enumerate(dz):
            p = possibly_create_parameter(z,
                                          name="%s - spline dz[%d]" %
                                          (name, i))
            p.range(0, 1)
            self.dz.append(p)

        self.vs = Parameters(name="vs - spline")
        for i, v in enumerate(vs):
            p = possibly_create_parameter(v,
                                          name="%s - spline vs[%d]" %
                                          (name, i))
            self.vs.append(p)

        if len(self.vs) != len(self.dz):
            raise ValueError("dz and vs must have same number of entries")

        self.zgrad = zgrad
        self.interpolator = interpolator

        self.__cached_interpolator = {
            "zeds": np.array([]),
            "vs": np.array([]),
            "interp": None,
            "extent": -1,
        }
Пример #13
0
    def __init__(self, extent, decay, rough, left_component, right_component,
                 name='', reverse=False, microslab_max_thickness=1):
        super(FunctionalForm, self).__init__(name=name)

        self.left_component = left_component
        self.right_component = right_component
        self.reverse = reverse

        self.microslab_max_thickness = microslab_max_thickness

        self.extent = (
            possibly_create_parameter(extent,
                                      name='%s - functional extent' % name))
        self.decay = (
            possibly_create_parameter(decay, name='%s - decay length' % name))

        self.rough = (
            possibly_create_parameter(rough, name='%s - rough' % name))
Пример #14
0
    def __init__(self,
                 thick,
                 rough,
                 vol_protein,
                 PLratio,
                 solventSLD,
                 name='',
                 vfsolv=0,
                 interface=None,
                 sld=None):
        if sld == None:
            sld = 0
        super(Protrusion, self).__init__(thick, sld, rough, name, vfsolv,
                                         interface)
        self.vol_protein = possibly_create_parameter(
            vol_protein, name='%s - vm_mscl, protien volume' % name)

        self.PLratio = possibly_create_parameter(
            PLratio, name='%s - PLratio, protien lipid ratio' % name)

        if isinstance(solventSLD, SLD):
            self.solventSLD = solventSLD
        elif isinstance(solventSLD, complex):
            self.solventSLD = SLD(solventSLD)
        else:
            self.solventSLD = possibly_create_parameter(
                solventSLD, name='%s - solventSLD' % name)

        bo = 0.5804e-4  #Oxygen
        bh = -0.3741e-4  #Hydrogen
        bd = 0.6671e-4  #Deuterium
        D2O = (2 * bd) + (1 * bo)
        H2O = (2 * bh) + (1 * bo)
        self.D2O = float(D2O)
        self.H2O = float(H2O)

        bc = 0.6646e-4  #Carbon
        # bo = 0.5804e-4  #Oxygen
        # bh = -0.3739e-4 #Hydrogen
        #bp = 0.513e-4   #Phosphorus
        bn = 0.936e-4  #Nitrogen
        bs = 2.847e-4  #Sulphur
        self.b_protein_part = float(2745 * bc + 675 * bn + 641 * bo + 25 * bs +
                                    (4374.5 - 822.5 * 0.9) * bh)
Пример #15
0
    def __init__(self, thick, sld, rough, name='', vfsolv=0, interface=None):
        super(Slab, self).__init__(name=name)
        self.thick = possibly_create_parameter(thick, name='%s - thick' % name)
        if isinstance(sld, SLD):
            self.sld = sld
        else:
            self.sld = SLD(sld)
        self.rough = possibly_create_parameter(rough, name='%s - rough' % name)
        self.vfsolv = (possibly_create_parameter(vfsolv,
                                                 name='%s - volfrac solvent' %
                                                 name))

        p = Parameters(name=self.name)
        p.extend([
            self.thick, self.sld.real, self.sld.imag, self.rough, self.vfsolv
        ])

        self._parameters = p
        self.interfaces = interface
Пример #16
0
    def __init__(self,
                 apm,
                 b_heads,
                 vm_heads,
                 thickness_heads,
                 b_tails,
                 vm_tails,
                 thickness_tails,
                 rough_head_tail,
                 rough_preceding_mono,
                 water_vm,
                 waters_per_head,
                 waters_per_tail,
                 head_solvent=None,
                 tail_solvent=None,
                 reverse_monolayer=False,
                 name=''):

        super(LipidLeafletWithWaterPer,
              self).__init__(apm, b_heads, vm_heads, thickness_heads, b_tails,
                             vm_tails, thickness_tails, rough_head_tail,
                             rough_preceding_mono, head_solvent, tail_solvent,
                             reverse_monolayer, name)

        self.water_vm = possibly_create_parameter(water_vm,
                                                  name='%s - water_vm' % name)

        self.waters_per_head = possibly_create_parameter(
            waters_per_head, name='%s - waters_per_head' % name)

        self.waters_per_tail = possibly_create_parameter(
            waters_per_tail, name='%s - waters_per_tail' % name)

        bo = 0.5804e-4  #Oxygen
        bh = -0.3741e-4  #Hydrogen
        bd = 0.6671e-4  #Deuterium
        D2O = (2 * bd) + (1 * bo)
        H2O = (2 * bh) + (1 * bo)
        self.D2O = float(D2O)
        self.H2O = float(H2O)
Пример #17
0
    def __init__ (self, structure, loc_in_struct, param_name='Thickness',
                  pdf=None, pdf_kwargs=None, num_structs=11, scale=1, bkg=1e-7,
                  name='', dq=5, threads=-1, quad_order=17):

        self.name = name
        self._parameters = None
        self.threads = threads
        self.quad_order = quad_order
        self.master_structure = structure
        self.loc_in_struct = loc_in_struct
        self.param_name = param_name.lower()
        self.num_structs = num_structs
        self._scale = scale

        if pdf is None:
            self.pdf = norm.pdf

            if pdf_kwargs is None:
                self.pdf_params = []
                self.pdf_params.append(possibly_create_parameter(value=10, name='loc'))
                self.pdf_params.append(possibly_create_parameter(value=1, name='scale'))
            else:
                print ('Warning: You have provided pdf_kwargs without providing a pdf')
        else:
            assert pdf_kwargs is not None, 'You must supply pdf_kwargs'
            self.pdf = pdf
            self.pdf_params = []
            for kw in pdf_kwargs:
                self.pdf_params.append(possibly_create_parameter(pdf_kwargs[kw], name=kw))

        self._structures = self.create_structures()
        self._scales = np.ones(self.num_structs)/self.num_structs
        self._bkg = possibly_create_parameter(bkg, name='bkg')

        # we can optimize the resolution (but this is always overridden by
        # x_err if supplied. There is therefore possibly no dependence on it.
        self._dq = possibly_create_parameter(dq, name='dq - resolution')

        self.generate_thicknesses()
Пример #18
0
 def __init__(self, name, bs, thicks, roughs, totalThickness):
     super(NLayerModel, self).__init__()
     self.Nlayers = len(bs)
     self.bs = []
     self.thicks = []
     self.roughs = []
     self.name = name
     for i in range(self.Nlayers):
         self.bs.append(
             possibly_create_parameter(bs[i],
                                       name='%s - layer %d b_real' %
                                       (name, i)))
         self.thicks.append(
             possibly_create_parameter(thicks[i],
                                       name='%s - thickness %d thickness' %
                                       (name, i)))
         self.roughs.append(
             possibly_create_parameter(roughs[i],
                                       name='%s - layer %d roughness' %
                                       (name, i)))
     self.totalThickness = possibly_create_parameter(
         totalThickness, name='%s - total thickness' % (name))
Пример #19
0
    def __init__(self,
                 polymer_sld,
                 phi_0,
                 gamma,
                 alpha,
                 delta,
                 rough,
                 name='',
                 microslab_max_thickness=1):
        super(ParabolicBrush, self).__init__(name=name)

        self.polymer_sld = SLD(polymer_sld)
        self.gamma = possibly_create_parameter(gamma, name='%s - gamma' % name)
        self.microslab_max_thickness = microslab_max_thickness

        self.alpha = (possibly_create_parameter(alpha,
                                                name='%s - alpha' % name))
        self.delta = (possibly_create_parameter(delta,
                                                name='%s - delta' % name))
        self.phi_0 = (possibly_create_parameter(phi_0,
                                                name='%s - phi_0' % name))
        self.rough = (possibly_create_parameter(rough,
                                                name='%s - rough' % name))
Пример #20
0
    def __init__(self,
                 structure,
                 scale=1,
                 bkg=1e-7,
                 name='',
                 dq=5.,
                 threads=0,
                 quad_order=17):
        self.name = name
        self._parameters = None
        self.threads = threads
        self.quad_order = quad_order

        # all reflectometry models need a scale factor and background
        self._scale = possibly_create_parameter(scale, name='scale')
        self._bkg = possibly_create_parameter(bkg, name='bkg')

        # we can optimize the resolution (but this is always overridden by
        # x_err if supplied. There is therefore possibly no dependence on it.
        self._dq = possibly_create_parameter(dq, name='dq - resolution')

        self._structure = None
        self.structure = structure
Пример #21
0
    def __init__(self,
                 structures,
                 scales=None,
                 bkg=1e-7,
                 name='',
                 dq=5.,
                 threads=-1,
                 quad_order=17):
        self.name = name
        self._parameters = None
        self.threads = threads
        self.quad_order = quad_order

        # all reflectometry models need a scale factor and background. Set
        # them all to 1 by default.
        pscales = Parameters('scale factors')

        if scales is not None and len(structures) == len(scales):
            tscales = scales
        elif scales is not None and len(structures) != len(scales):
            raise ValueError("You need to supply scale factor for each"
                             " structure")
        else:
            tscales = [1 / len(structures)] * len(structures)

        for scale in tscales:
            p_scale = possibly_create_parameter(scale, name='scale')
            pscales.append(p_scale)

        self._scales = pscales
        self._bkg = possibly_create_parameter(bkg, name='bkg')

        # we can optimize the resolution (but this is always overridden by
        # x_err if supplied. There is therefore possibly no dependence on it.
        self._dq = possibly_create_parameter(dq, name='dq - resolution')

        self._structures = structures
Пример #22
0
    def __init__(self, components=(), name='', repeats=1):
        Component.__init__(self, name=name)
        UserList.__init__(self)  # explicit calls without super

        self.repeats = possibly_create_parameter(repeats, 'repeats')
        self.repeats.bounds.lb = 1

        # if you provide a list of components to start with, then initialise
        # the Stack from that
        for c in components:
            if isinstance(c, Component):
                self.data.append(c)
            else:
                raise ValueError("You can only initialise a Stack with"
                                 " Components")
Пример #23
0
 def __init__(self,
              i_as=11.1,
              sig_as=0.1,
              i_ap=24.1,
              th_p=25.1,
              i_ps=24.1,
              n_w=500.1,
              d_sld=2.01,
              a=13,
              b=16.5,
              c=27.5):
     #interface air solvent, interface width air solvent, interface air protien, interface protien solvent, number of water molecules, sld of deuterated protein
     super(bsla_thesis).__init__()
     name = 'bsla'
     self.name = name
     self.interface_air_protein = possibly_create_parameter(
         0.0, name='%s - interface_air_protein' % name)
     self.interface_protein_solvent = possibly_create_parameter(
         11.1, name='%s - interface_protein_solvent' % name)
     self.protein_length = possibly_create_parameter(
         25.1, name='%s - protein_length' % name)
     self.number_of_water_molecules = possibly_create_parameter(
         500.1, name='%s - number_of_water_molecules' % name)
     self.interface_width_air_solvent = possibly_create_parameter(
         15, name='%s - interface_width_air_solvent' % name)
     #self.interface_width_protein_solvent = possibly_create_parameter(0.1,
     #        name='%s - interface_width_protein_solvent' % name)
     self.sld_of_protein = possibly_create_parameter(
         3.23,  #*(10**(-6))
         name='%s - sld_of_protein' % name)
     self.d2o_to_h2o_ratio = possibly_create_parameter(
         1.0, name='%s - d2o_h2o_ratio' % name)
     #         self.semi_axis_a = possibly_create_parameter(a,
     #                 name='%s - semi_axis_a' % name)
     #         self.semi_axis_b = possibly_create_parameter(b,
     #                 name='%s - semi_axis_b' % name)
     #         self.semi_axis_c = possibly_create_parameter(c,
     #                 name='%s - semi_axis_c' % name)
     self.a = 13
     self.b = 16.5
     self.c = 27.5
     self.volume_of_water_molecule = 30
     self.major_axis_length = 55
     self.d = (self.c - self.a) / self.volume_of_water_molecule
Пример #24
0
    def insert_structure(self, row, structure):
        n = StructureNode(structure, self._model, self)

        data_object_node = find_data_object(self.index)
        data_object = data_object_node.data_object
        orig_model = data_object.model

        if len(self.structures) == 1:
            self._model.beginInsertRows(self.index, row, row)
            new_structures = [self.structures[0], structure]
            new_model = MixedReflectModel(new_structures,
                                          bkg=orig_model.bkg,
                                          dq=orig_model.dq)
            data_object.model = new_model
            data_object_node.set_reflect_model(new_model,
                                               constdq_q=self.constantdq_q)
            return

        # already a mixed model
        # we can't insert at a lower place than the 4rd row
        row = max(row, 4)
        self._model.beginInsertRows(self.index, row, row)

        # insert the structure
        orig_model.structures.insert(row - STRUCT_OFFSET, structure)
        v = 1 / len(orig_model.structures)
        sf = possibly_create_parameter(v, name="scale")
        orig_model.scales.insert(row - STRUCT_OFFSET, sf)

        self.insertChild(row, n)
        self._model.endInsertRows()

        # insert a scale factor
        self._model.beginInsertRows(
            self.child(0).index, row - STRUCT_OFFSET, row - STRUCT_OFFSET)
        # add a scale factor
        n = ParNode(sf, self._model, self.child(0))
        self.child(0).insertChild(row - STRUCT_OFFSET, n)
        self._model.endInsertRows()
Пример #25
0
    def __init__(
            self,
            apm,
            b_heads,
            vm_heads,
            thickness_heads,
            b_tails,
            vm_tails,
            thickness_tails,
            rough_head_tail,
            rough_preceding_mono,

            #  water_vm, waters_per_head, waters_per_tail,
            vm_mscl,
            PLRatio,
            head_solvent=None,
            tail_solvent=None,
            reverse_monolayer=False,
            name=''):

        self.vm_mscl = possibly_create_parameter(
            vm_mscl, name='%s - vm_mscl, protien volume' % name)

        self.PLRatio = possibly_create_parameter(
            PLRatio, name='%s - PLRatio, fraction lipid to protein' % name)

        super(LipidLeafletWithProtien, self).__init__(
            apm,
            b_heads,
            vm_heads,
            thickness_heads,
            b_tails,
            vm_tails,
            thickness_tails,
            rough_head_tail,
            rough_preceding_mono,

            #  water_vm, waters_per_head, waters_per_tail,
            head_solvent,
            tail_solvent,
            reverse_monolayer,
            name)

        #         if isinstance(b_mscl, complex):
        #             self.b_mscl_real = possibly_create_parameter(
        #                 b_mscl.real,
        #                 name='%s - b_mscl_real' % name)
        #             self.b_mscl_imag = possibly_create_parameter(
        #                 b_mscl.imag,
        #                 name='%s - b_mscl_imag' % name)
        #         elif isinstance(b_mscl, SLD):
        #             self.b_mscl_real = b_mscl.real
        #             self.b_mscl_imag = b_mscl.imag
        #         else:
        #             self.b_mscl_real = possibly_create_parameter(
        #                 b_mscl,
        #                 name='%s - b_mscl_real' % name)
        #             self.b_mscl_imag = possibly_create_parameter(
        #                 0,
        #                 name='%s - b_mscl_imag' % name)

        bc = 0.6646e-4  #Carbon
        bo = 0.5804e-4  #Oxygen
        bh = -0.3739e-4  #Hydrogen
        #bp = 0.513e-4   #Phosphorus
        bn = 0.936e-4  #Nitrogen
        #bd = 0.6671e-4  #Deuterium
        bs = 2.847e-4  #Sulphur
        self.b_mscl_base = float(2745 * bc + 675 * bn + 641 * bo + 25 * bs +
                                 (4374.5 - 822.5 * 0.9) * bh)
        # bo = 0.5804e-4     #Oxygen
        # bh = -0.3741e-4    #Hydrogen
        bd = 0.6671e-4  #Deuterium
        D2O = (2 * bd) + (1 * bo)
        H2O = (2 * bh) + (1 * bo)
        self.D2O = float(D2O)
        self.H2O = float(H2O)
Пример #26
0
    def __init__(self, apm, b_heads, vm_heads, thickness_heads,
                 b_tails, vm_tails, thickness_tails, rough_head_tail,
                 rough_preceding_mono, reverse_monolayer=False, name=''):
        """
        Parameters
        ----------
        apm: float or Parameter
            Area per molecule
        b_heads: float, Parameter or complex
            Sum of coherent scattering lengths of head group (Angstrom)
        vm_heads: float or Parameter
            Molecular volume of head group (Angstrom**3)
        thickness_heads: float or Parameter
            Thickness of head group region (Angstrom)
        b_tails: float, Parameter or complex
            Sum of coherent scattering lengths of tail group (Angstrom)
        vm_tails: float or Parameter
            Molecular volume of tail group (Angstrom**3)
        thickness_tails: float or Parameter
            Thickness of head group region (Angstrom)
        reverse_monolayer: bool, optional
            The default is to have heads closer to the fronting medium and
            tails closer to the backing medium. If `reverse_monolayer is True`
            then the tails will be closer to the fronting medium and heads
            closer to the backing medium.
        name: str, optional
            The name for the component
        """
        super(LipidLeaflet, self).__init__()
        self.apm = possibly_create_parameter(apm,
                                             '%s - area_per_molecule' % name)

        if isinstance(b_heads, complex):
            self.b_heads_real = possibly_create_parameter(
                b_heads.real,
                name='%s - b_heads_real' % name)
            self.b_heads_imag = possibly_create_parameter(
                b_heads.imag,
                name='%s - b_heads_imag' % name)
        else:
            self.b_heads_real = possibly_create_parameter(
                b_heads,
                name='%s - b_heads_real' % name)
            self.b_heads_imag = possibly_create_parameter(
                0,
                name='%s - b_heads_imag' % name)

        self.vm_heads = possibly_create_parameter(
            vm_heads,
            name='%s - vm_heads' % name)

        self.thickness_heads = possibly_create_parameter(
            thickness_heads,
            name='%s - thickness_heads' % name)

        if isinstance(b_tails, complex):
            self.b_tails_real = possibly_create_parameter(
                b_tails.real,
                name='%s - b_tails_real' % name)
            self.b_tails_imag = possibly_create_parameter(
                b_tails.imag,
                name='%s - b_tails_imag' % name)
        else:
            self.b_tails_real = possibly_create_parameter(
                b_tails,
                name='%s - b_tails_real' % name)
            self.b_tails_imag = possibly_create_parameter(
                0,
                name='%s - b_tails_imag' % name)

        self.vm_tails = possibly_create_parameter(
            vm_tails,
            name='%s - vm_tails' % name)
        self.thickness_tails = possibly_create_parameter(
            thickness_tails,
            name='%s - thickness_tails' % name)
        self.rough_head_tail = possibly_create_parameter(
            rough_head_tail,
            name='%s - rough_head_tail' % name)
        self.rough_preceding_mono = possibly_create_parameter(
            rough_preceding_mono,
            name='%s - rough_fronting_mono' % name)
        self.reverse_monolayer = reverse_monolayer
        self.name = name
    def __init__(self,
                 apm,
                 b_heads,
                 vm_heads,
                 thickness_heads,
                 b_tails,
                 vm_tails,
                 thickness_tails,
                 roughness,
                 solvfrac=0,
                 head_solvent=None,
                 reverse_monolayer=False,
                 name=''):

        super(monolayer, self).__init__()
        self.apm = possibly_create_parameter(apm, 'area_per_molecule')

        if isinstance(b_heads, complex):
            self.b_heads_real = possibly_create_parameter(b_heads.real,
                                                          name='b_heads_real')
            self.b_heads_imag = possibly_create_parameter(b_heads.imag,
                                                          name='b_heads_imag')
        elif isinstance(b_heads, SLD):
            self.b_heads_real = b_heads.real
            self.b_heads_imag = b_heads.imag
        else:
            self.b_heads_real = possibly_create_parameter(b_heads,
                                                          name='b_heads_real')
            self.b_heads_imag = possibly_create_parameter(0,
                                                          name='b_heads_imag')

        self.vm_heads = possibly_create_parameter(vm_heads, name='vm_heads')

        self.thickness_heads = possibly_create_parameter(
            thickness_heads, name='thickness_heads')

        if isinstance(b_tails, complex):
            self.b_tails_real = possibly_create_parameter(b_tails.real,
                                                          name='b_tails_real')
            self.b_tails_imag = possibly_create_parameter(b_tails.imag,
                                                          name='b_tails_imag')
        elif isinstance(b_tails, SLD):
            self.b_tails_real = b_tails.real
            self.b_tails_imag = b_tails.imag
        else:
            self.b_tails_real = possibly_create_parameter(b_tails,
                                                          name='b_tails_real')
            self.b_tails_imag = possibly_create_parameter(0,
                                                          name='b_tails_imag')

        self.vm_tails = possibly_create_parameter(vm_tails, name='vm_tails')
        self.thickness_tails = possibly_create_parameter(
            thickness_tails, name='thickness_tails')

        self.roughness = possibly_create_parameter(roughness, name='roughness')

        self.head_solvent = None
        if head_solvent == 'd2o':
            self.head_solvent = 6.02316
        else:
            self.head_solvent = 2.3117

        self.solvfrac = possibly_create_parameter(solvfrac, 'solvent fraction')

        self.reverse_monolayer = reverse_monolayer
        self.name = name
Пример #28
0
    def __init__(self,
                 apm,
                 b_heads,
                 vm_heads,
                 thickness_heads,
                 b_tails,
                 vm_tails,
                 thickness_tails,
                 rough_head_tail,
                 rough_preceding_mono,
                 head_solvent=None,
                 tail_solvent=None,
                 reverse_monolayer=False,
                 name=''):
        """
        Parameters
        ----------
        apm: float or Parameter
            Area per molecule
        b_heads: float, Parameter or complex
            Sum of coherent scattering lengths of head group (Angstrom)
        vm_heads: float or Parameter
            Molecular volume of head group (Angstrom**3)
        thickness_heads: float or Parameter
            Thickness of head group region (Angstrom)
        b_tails: float, Parameter or complex
            Sum of coherent scattering lengths of tail group (Angstrom)
        vm_tails: float or Parameter
            Molecular volume of tail group (Angstrom**3)
        thickness_tails: float or Parameter
            Thickness of head group region (Angstrom)
        rough_preceding_mono: float or Parameter
            Roughness between preceding component (in the fronting direction)
            and the monolayer (Angstrom). If `reverse_monolayer is False` then
            this is the roughness between the preceding component and the
            heads, if `reverse_monolayer is True` then this is the roughness
            between the preceding component and the tails.
        head_solvent: None, float, complex, SLD
            Solvent for the head region. If `None`, then solvation will be
            performed by the parent `Structure`, using the `Structure.solvent`
            attribute. Other options are coerced to an `SLD` object using
            `SLD(float | complex)`. A float/complex argument is the SLD of the
            solvent (10**-6 Angstrom**-2).
        tail_solvent: None, float, complex, SLD
            Solvent for the tail region. If `None`, then solvation will be
            performed by the parent `Structure`, using the `Structure.solvent`
            attribute. Other options are coerced to an `SLD` object using
            `SLD(float | complex)`. A float/complex argument is the SLD of the
            solvent (10**-6 Angstrom**-2).
        reverse_monolayer: bool, optional
            The default is to have heads closer to the fronting medium and
            tails closer to the backing medium. If `reverse_monolayer is True`
            then the tails will be closer to the fronting medium and heads
            closer to the backing medium.
        name: str, optional
            The name for the component
        """
        super(LipidLeaflet, self).__init__()
        self.apm = possibly_create_parameter(apm,
                                             '%s - area_per_molecule' % name)

        if isinstance(b_heads, complex):
            self.b_heads_real = possibly_create_parameter(
                b_heads.real, name='%s - b_heads_real' % name)
            self.b_heads_imag = possibly_create_parameter(
                b_heads.imag, name='%s - b_heads_imag' % name)
        else:
            self.b_heads_real = possibly_create_parameter(
                b_heads, name='%s - b_heads_real' % name)
            self.b_heads_imag = possibly_create_parameter(
                0, name='%s - b_heads_imag' % name)

        self.vm_heads = possibly_create_parameter(vm_heads,
                                                  name='%s - vm_heads' % name)

        self.thickness_heads = possibly_create_parameter(
            thickness_heads, name='%s - thickness_heads' % name)

        if isinstance(b_tails, complex):
            self.b_tails_real = possibly_create_parameter(
                b_tails.real, name='%s - b_tails_real' % name)
            self.b_tails_imag = possibly_create_parameter(
                b_tails.imag, name='%s - b_tails_imag' % name)
        else:
            self.b_tails_real = possibly_create_parameter(
                b_tails, name='%s - b_tails_real' % name)
            self.b_tails_imag = possibly_create_parameter(
                0, name='%s - b_tails_imag' % name)

        self.vm_tails = possibly_create_parameter(vm_tails,
                                                  name='%s - vm_tails' % name)
        self.thickness_tails = possibly_create_parameter(
            thickness_tails, name='%s - thickness_tails' % name)
        self.rough_head_tail = possibly_create_parameter(
            rough_head_tail, name='%s - rough_head_tail' % name)
        self.rough_preceding_mono = possibly_create_parameter(
            rough_preceding_mono, name='%s - rough_fronting_mono' % name)

        self.head_solvent = self.tail_solvent = None
        if head_solvent is not None:
            self.head_solvent = SLD(head_solvent)
        if tail_solvent is not None:
            self.tail_solvent = SLD(tail_solvent)

        self.reverse_monolayer = reverse_monolayer
        self.name = name
Пример #29
0
    def __init__(self, bs, name="two_layer"):
        super(TwoLayer, self).__init__()
        if isinstance(bs[0], complex):
            self.b_real_h = possibly_create_parameter(
                bs[0].real, "{} - b_real_head".format(name))
            self.b_imag_h = possibly_create_parameter(
                bs[0].imag, "{} - b_imag_head".format(name))
        else:
            self.b_real_h = possibly_create_parameter(
                bs[0], "{} - b_real_head".format(name))
            self.b_imag_h = possibly_create_parameter(
                0, "{} - b_imag_head".format(name))
        if isinstance(bs[1], complex):
            self.b_real_t = possibly_create_parameter(
                bs[1].real, "{} - b_real_tail".format(name))
            self.b_imag_t = possibly_create_parameter(
                bs[1].imag, "{} - b_imag_tail".format(name))
        else:
            self.b_real_t = possibly_create_parameter(
                bs[1], "{} - b_real_tail".format(name))
            self.b_imag_t = possibly_create_parameter(
                0, "{} - b_imag_tail".format(name))

        self.mol_vol_h = possibly_create_parameter(
            100, "{} - molecular_volume_head".format(name))
        self.mol_vol_t = possibly_create_parameter(
            100, "{} - molecular_volume_tail".format(name))

        self.thick_h = possibly_create_parameter(
            100, "{} - thickness_head".format(name))
        self.thick_t = possibly_create_parameter(
            100, "{} - thickness_tail".format(name))

        self.phi_h = possibly_create_parameter(
            0.5, "{} - solvation_head".format(name))
        self.phi_t = possibly_create_parameter(
            0, "{} - solvation_tail".format(name))

        self.rough_h_t = possibly_create_parameter(
            3.3, "{} - roughness_head_tail".format(name))
        self.rough_t_a = possibly_create_parameter(
            3.3, "{} - roughness_tail_air".format(name))

        self.name = name
Пример #30
0
    def __init__(self, adsorbed_amount, vff, dzf, polymer_sld, name='',
                 left_slabs=(), right_slabs=(),
                 interpolator=Pchip, zgrad=True,
                 microslab_max_thickness=1, profile_cutoff=5000):
        """
        Parameters
        ----------
        Adsorbed Amount : Parameter or float
            The total extent of the spline region
        vff: sequence of Parameter or float
            Volume fraction at each of the spline knots, as a fraction of
            the volume fraction of the rightmost left slab
        dzf : sequence of Parameter or float
            Separation of successive knots, will be normalised to a 0-1 scale.
        polymer_sld : SLD or float
            SLD of polymer
        name : str
            Name of component
        gamma : Parameter
            The dry adsorbed amount of polymer
        left_slabs : sequence of Slab
            Polymer Slabs to the left of the spline
        right_slabs : sequence of Slab
            Polymer Slabs to the right of the spline
        interpolator : scipy interpolator
            The interpolator for the spline
        zgrad : bool, optional
            Set to `True` to force the gradient of the volume fraction to zero
            at each end of the spline.
        microslab_max_thickness : float
            Thickness of microslicing of spline for reflectivity calculation.
        profile_cutoff : float
            maximum extent (thickness) of the freeform profile. The profile is
            'cut off' (VF=0) after this point.
        """
        super(FreeformVFP, self).__init__()

        assert len(vff) + 1 == len(dzf), ("Length of dzf must be one greater"
                                          " than length of vff")

        self.name = name

        if isinstance(polymer_sld, SLD):
            self.polymer_sld = polymer_sld
        else:
            self.polymer_sld = SLD(polymer_sld)

        # left and right slabs are other areas where the same polymer can
        # reside
        self.left_slabs = [slab for slab in left_slabs if
                           isinstance(slab, Slab)]
        self.right_slabs = [slab for slab in right_slabs if
                            isinstance(slab, Slab)]

        # use the volume fraction of the last left_slab as the initial vf of
        # the spline, if not left slabs supplied start at vf 1
        if len(self.left_slabs):
            self.start_vf = 1 - self.left_slabs[-1].vfsolv.value
        else:
            self.start_vf = 1

        # in contrast use a vf = 0 for the last vf of
        # the spline, unless right_slabs is specified
        if len(self.right_slabs):
            self.end_vf = 1 - self.right_slabs[0].vfsolv.value
        else:
            self.end_vf = 0

        self.microslab_max_thickness = microslab_max_thickness

        self.adsorbed_amount = (
            possibly_create_parameter(adsorbed_amount,
                                      name='%s - adsorbed amount' % name))

        # dzf are the spatial gaps between the spline knots
        self.dzf = Parameters(name='dzf - spline')
        for i, z in enumerate(dzf):
            p = possibly_create_parameter(
                z,
                name='%s - spline dzf[%d]' % (name, i))
            p.range(0, 1)
            self.dzf.append(p)

        # vf are the volume fraction values of each of the spline knots
        self.vff = Parameters(name='vff - spline')
        for i, v in enumerate(vff):
            p = possibly_create_parameter(
                v,
                name='%s - spline vff[%d]' % (name, i))
            p.range(0, 1)
            self.vff.append(p)

        self.cutoff = profile_cutoff

        self.zgrad = zgrad
        self.interpolator = interpolator

        self.__cached_interpolator = {'zeds': np.array([]),
                                      'vf': np.array([]),
                                      'interp': None,
                                      'adsorbed amount': -1}