def slabs(self, structure=None): layers = super(LipidLeafletTest, self).slabs(structure=structure) if self.reverse_monolayer: layers = np.flipud(layers) layers[:, 3] = layers[::-1, 3] # tail region volfrac = self.vm_tails.value / (self.apm.value * self.thickness_tails.value) layers[0, 4] = 1 - volfrac if self.head_solvent is not None: # we do the solvation here, not in Structure.slabs layers[0] = Structure.overall_sld(layers[0], self.head_solvent) layers[0, 4] = 0 # tail region volfrac = self.vm_tails.value / (self.apm.value * self.thickness_tails.value) layers[1, 4] = 1 - volfrac if self.tail_solvent is not None: # we do the solvation here, not in Structure.slabs layers[1] = Structure.overall_sld(layers[1], self.tail_solvent) layers[1, 4] = 0 if self.reverse_monolayer: layers = np.flipud(layers) layers[:, 3] = layers[::-1, 3]
def slabs(self, structure=None): """ Slab representation of monolayer, as an array Parameters ---------- structure : refnx.reflect.Structure The Structure hosting this Component """ layers = np.zeros((2, 5)) # thicknesses layers[0, 0] = float(self.thickness_heads) layers[1, 0] = float(self.thickness_tails) # real and imag SLD's head_sld_real, tail_sld_real = self.sld_( self.b_heads_real, #real self.b_tails_real, self.b_mscl_real) head_sld_imag, tail_sld_imag = self.sld_( self.b_heads_imag, #imaginary self.b_tails_imag, self.b_mscl_imag) layers[0, 1] = head_sld_real layers[0, 2] = head_sld_imag layers[1, 1] = tail_sld_real layers[1, 2] = tail_sld_imag # roughnesses layers[0, 3] = float(self.rough_preceding_mono) layers[1, 3] = float(self.rough_head_tail) # volume fractions # head region volfrac = self.vm_head() / (self.apm.value * self.thickness_heads.value) layers[0, 4] = 1 - volfrac if self.head_solvent is not None: # we do the solvation here, not in Structure.slabs layers[0] = Structure.overall_sld(layers[0], self.head_solvent) layers[0, 4] = 0 # tail region volfrac = self.vm_tail() / (self.apm.value * self.thickness_tails.value) layers[1, 4] = 1 - volfrac if self.tail_solvent is not None: # we do the solvation here, not in Structure.slabs layers[1] = Structure.overall_sld(layers[1], self.tail_solvent) layers[1, 4] = 0 if self.reverse_monolayer: layers = np.flipud(layers) layers[:, 3] = layers[::-1, 3] return layers
def test_left_right_influence(self): # make sure that if the left and right components change, so does the # spline a = Spline(100, [2], [0.5], zgrad=False, microslab_max_thickness=1) s = self.left | a | self.right | self.solvent # change the SLD of the left component, spline should respond self.left.sld.real.value = 2.0 assert_almost_equal(a(0, s), 2) # check that the spline responds if it's a vfsolv that changes self.left.vfsolv.value = 0.5 assert_almost_equal( Structure.overall_sld(self.left.slabs(), self.solvent)[0, 1], 6.0) assert_almost_equal(a(0, s), 6.0) # check that the right side responds. self.right.sld.real.value = 5.0 assert_almost_equal(a(100, s), 5.0) # the spline should respond if the knot SLD's are changed a.vs[0].value = 3.0 assert_almost_equal(a(50, s), 3.0) # spline responds if the interval knot spacing is changed a.dz[0].value = 0.9 assert_almost_equal(a(90, s), 3.0)
def slabs(self, structure=None): """ Slab representation of monolayer, as an array Parameters ---------- structure : refnx.reflect.Structure The Structure hosting this Component """ layers = super(LipidLeafletWithProtien, self).slabs(structure=structure) if self.reverse_monolayer: layers = np.flipud(layers) layers[:, 3] = layers[::-1, 3] # volume fractions # head region # volfrac = self.vm_heads.value / (self.apm.value * # self.thickness_heads.value) layers[0, 4] = (1 - self.PLRatio.value ) * self.thickness_heads.value / self.total_thickness() if self.protein_head_SLD() is not None: # we do the solvation here, not in Structure.slabs layers[0] = Structure.overall_sld(layers[0], self.protein_head_SLD()) layers[0, 4] = 0 # tail region # volfrac = self.vm_tails.value / (self.apm.value * # self.thickness_tails.value) layers[1, 4] = (1 - self.PLRatio.value ) * self.thickness_heads.value / self.total_thickness() if self.protein_tail_SLD() is not None: # we do the solvation here, not in Structure.slabs layers[1] = Structure.overall_sld(layers[1], self.protein_tail_SLD()) layers[1, 4] = 0 if self.reverse_monolayer: layers = np.flipud(layers) layers[:, 3] = layers[::-1, 3] return layers
def slabs(self): """ Slab representation of monolayer, as an array """ layers = np.zeros((2, 5)) # thicknesses layers[0, 0] = float(self.thickness_heads) layers[1, 0] = float(self.thickness_tails) # real and imag SLD's layers[0, 1] = float(self.b_heads_real) / float(self.vm_heads) * 1.e6 layers[0, 2] = float(self.b_heads_imag) / float(self.vm_heads) * 1.e6 layers[1, 1] = float(self.b_tails_real) / float(self.vm_tails) * 1.e6 layers[1, 2] = float(self.b_tails_imag) / float(self.vm_tails) * 1.e6 # roughnesses layers[0, 3] = float(self.rough_preceding_mono) layers[1, 3] = float(self.rough_head_tail) # volume fractions # head region volfrac = self.vm_heads.value / (self.apm.value * self.thickness_heads.value) layers[0, 4] = 1 - volfrac if self.head_solvent is not None: # we do the solvation here, not in Structure.slabs layers[0] = Structure.overall_sld(layers[0], self.head_solvent) layers[0, 4] = 0 # tail region volfrac = self.vm_tails.value / (self.apm.value * self.thickness_tails.value) layers[1, 4] = 1 - volfrac if self.tail_solvent is not None: # we do the solvation here, not in Structure.slabs layers[1] = Structure.overall_sld(layers[1], self.tail_solvent) layers[1, 4] = 0 if self.reverse_monolayer: layers = np.flipud(layers) layers[:, 3] = layers[::-1, 3] return layers
def _interpolator(self): dz = np.array(self.dz) zeds = np.cumsum(dz) # if dz's sum to more than 1, then normalise to unit interval. if zeds[-1] > 1: zeds /= zeds[-1] zeds = np.clip(zeds, 0, 1) vs = np.array(self.vs) left_sld = Structure.overall_sld( np.atleast_2d(self.left_slab.slabs[-1]), self.solvent)[..., 1] right_sld = Structure.overall_sld( np.atleast_2d(self.right_slab.slabs[0]), self.solvent)[..., 1] if self.zgrad: zeds = np.concatenate([[-1.1, 0 - EPS], zeds, [1 + EPS, 2.1]]) vs = np.concatenate([left_sld, left_sld, vs, right_sld, right_sld]) else: zeds = np.concatenate([[0 - EPS], zeds, [1 + EPS]]) vs = np.concatenate([left_sld, vs, right_sld]) # cache the interpolator cache_zeds = self.__cached_interpolator['zeds'] cache_vs = self.__cached_interpolator['vs'] cache_extent = self.__cached_interpolator['extent'] # you don't need to recreate the interpolator if (np.array_equal(zeds, cache_zeds) and np.array_equal(vs, cache_vs) and np.equal(self.extent, cache_extent)): return self.__cached_interpolator['interp'] else: self.__cached_interpolator['zeds'] = zeds self.__cached_interpolator['vs'] = vs self.__cached_interpolator['extent'] = float(self.extent) # TODO make vfp zero for z > self.extent interpolator = self.interpolator(zeds, vs) self.__cached_interpolator['interp'] = interpolator return interpolator
def slabs(self, structure=None): """ Slab representation of monolayer, as an array Parameters ---------- structure : refnx.reflect.Structure The Structure hosting this Component """ layers = np.zeros((2, 5)) # thicknesses layers[0, 0] = float(self.thickness_heads) layers[1, 0] = float(self.thickness_tails) # real and imag SLD's head_sld_r, tail_sld_r = self.sld_r() head_sld_i, tail_sld_i = self.sld_i() layers[0, 1] = head_sld_r layers[0, 2] = head_sld_i layers[1, 1] = tail_sld_r layers[1, 2] = tail_sld_i # roughnesses layers[0, 3] = float(self.rough_preceding_mono) layers[1, 3] = float(self.rough_head_tail) # volume fractions # head region apm = self.total_vm()/self.total_thickness() self.apm.value = apm volfrac = self.vm_head() / (self.apm.value * self.thickness_heads.value) layers[0, 4] = 1 - volfrac # print("volfrac h", volfrac) # print(layers[0]) if self.head_solvent is not None: # we do the solvation here, not in Structure.slabs layers[0] = Structure.overall_sld(layers[0], self.head_solvent_true()) layers[0, 4] = 0 # print(layers[0]) # tail region volfrac = self.vm_tail() / (self.apm.value * self.thickness_tails.value) layers[1, 4] = 1 - volfrac # print("volfrac t", volfrac) if self.tail_solvent is not None: # we do the solvation here, not in Structure.slabs layers[1] = Structure.overall_sld(layers[1], self.tail_solvent_true()) layers[1, 4] = 0 if self.reverse_monolayer: layers = np.flipud(layers) layers[:, 3] = layers[::-1, 3] # print("layers",layers) return layers
def _interpolator(self, structure): dz = np.array(self.dz) zeds = np.cumsum(dz) # if dz's sum to more than 1, then normalise to unit interval. if len(zeds) and zeds[-1] > 1: # there may be no knots zeds /= zeds[-1] zeds = np.clip(zeds, 0, 1) # note - this means you shouldn't use the same Spline more than once in # a Component, because only the first use will be detected. try: loc = structure.index(self) # figure out SLDs for the bracketing Components. # note the use of the modulus operator. This means that if the # Spline is at the end, then the right most Component will be # assumed to be the first Component. This is to aid the use of # Spline in a Stack. left_component = structure[loc - 1] right_component = structure[(loc + 1) % len(structure)] except ValueError: raise ValueError("Spline didn't appear to be part of a super" " Structure") if (isinstance(left_component, Spline) or isinstance(right_component, Spline)): raise ValueError("Spline must be bracketed by Components that" " aren't Splines.") vs = np.array(self.vs) left_sld = Structure.overall_sld( np.atleast_2d(left_component.slabs(structure)[-1]), structure.solvent)[..., 1] right_sld = Structure.overall_sld( np.atleast_2d(right_component.slabs(structure)[0]), structure.solvent)[..., 1] if self.zgrad: zeds = np.concatenate([[-1.1, 0 - EPS], zeds, [1 + EPS, 2.1]]) vs = np.concatenate([left_sld, left_sld, vs, right_sld, right_sld]) else: zeds = np.concatenate([[0 - EPS], zeds, [1 + EPS]]) vs = np.concatenate([left_sld, vs, right_sld]) # cache the interpolator cache_zeds = self.__cached_interpolator['zeds'] cache_vs = self.__cached_interpolator['vs'] cache_extent = self.__cached_interpolator['extent'] # you don't need to recreate the interpolator if (np.array_equal(zeds, cache_zeds) and np.array_equal(vs, cache_vs) and np.equal(self.extent, cache_extent)): return self.__cached_interpolator['interp'] else: self.__cached_interpolator['zeds'] = zeds self.__cached_interpolator['vs'] = vs self.__cached_interpolator['extent'] = float(self.extent) # TODO make vfp zero for z > self.extent interpolator = self.interpolator(zeds, vs) self.__cached_interpolator['interp'] = interpolator return interpolator