예제 #1
0
    def profile(self, extra=False):
        """
        Calculates the volume fraction profile

        Returns
        -------
        z, vfp : np.ndarray
            Distance from the interface, volume fraction profile
        """
        s = Structure()
        s |= SLD(0)

        m = SLD(1.)

        for i, slab in enumerate(self.left_slabs):
            layer = m(slab.thick.value, slab.rough.value)
            if not i:
                layer.rough.value = 0
            layer.vfsolv.value = slab.vfsolv.value
            s |= layer

        polymer_slabs = self.slabs()
        offset = np.sum(s.slabs()[:, 0])

        if polymer_slabs is not None:
            for i in range(np.size(polymer_slabs, 0)):
                layer = m(polymer_slabs[i, 0], polymer_slabs[i, 3])
                layer.vfsolv.value = polymer_slabs[i, -1]
                s |= layer

        for i, slab in enumerate(self.right_slabs):
            layer = m(slab.thick.value, slab.rough.value)
            layer.vfsolv.value = 1 - slab.vfsolv.value
            s |= layer

        s |= SLD(0, 0)

        # now calculate the VFP.
        total_thickness = np.sum(s.slabs()[:, 0])
        zed = np.linspace(0, total_thickness, total_thickness + 1)
        # SLD profile puts a very small roughness on the interfaces with zero
        # roughness.
        zed[0] = 0.01
        z, s = s.sld_profile(z=zed)
        s[0] = s[1]

        # perhaps you'd like to plot the knot locations
        zeds = np.cumsum(self.dz)
        if np.sum(self.dz) > 1:
            zeds /= np.sum(self.dz)
            zeds = np.clip(zeds, 0, 1)

        zed_knots = zeds * float(self.extent) + offset

        if extra:
            return z, s, zed_knots, np.array(self.vf)
        else:
            return z, s
예제 #2
0
def phase_problem_plot(flag):
    if flag != "SLD" and flag != "ACF":
        raise Exception("Invalid flag to plot")

    qvals = np.linspace(0,0.2,1025)[1:]
    sld1 = SLD(0, 0)
    sld3 = SLD(2.074, 0)

    layer1 = sld1(0, 0)
    layer3 = sld3(0, 0)

    fig = plt.figure(figsize=(15, 10))
    gs = gridspec.GridSpec(2, 2)
    ax1 = plt.subplot(gs[0,0])
    ax2 = plt.subplot(gs[1,0])
    for i, style in zip([0,1.0], ['k-', 'r:']):
        sld20 = SLD(6.335 - i, 0)
        sld21 = SLD(6.335 + i, 0)
        layer20 = sld20(100, 0)
        layer21 = sld21(100, 0)
        structure = Structure(layer1 | layer20 | layer21 | layer3)
        z, rho = structure.sld_profile()
        drho = (rho[1:] - rho[:-1]) / (z[1:] - z[:-1])
        z_ = 0.5 * (z[:-1] + z[1:])
        acf = autocorr(drho)
        z_acf = z_ - z_.min()
        z_acf = np.hstack((-np.flip(z_acf)[:-1], z_acf))

        if flag == 'SLD':
            ax1.plot(z, rho, style)
            ax2.semilogy(qvals, ReflectModel(structure, dq=0.0).model(qvals), style)

        else:
            ax1.stem(z_,   drho, style, markerfmt=' ', basefmt=style, use_line_collection=True)
            ax2.stem(z_acf, acf, style, markerfmt=' ', basefmt=style, use_line_collection=True)


    if flag == 'SLD':
        ax1.set_xlabel(r'$z$/Å')
        ax1.set_ylabel(r'$\rho(z)$/Å$^{-2}$')

        ax2.set_xlabel(r'$q$/Å')
        ax2.set_ylabel(r'$R(q)$')

    else:
        ax1.set_xlabel(r'$z$/Å')
        ax1.set_ylabel(r'$\rho\'(z)$/Å$^{-3}$')

        ax2.set_xlabel(r'$z$/Å')
        ax2.set_ylabel("$ \\rm{ACF}_{\\rho'}(z)/ \\AA^{-5}$")

    plt.tight_layout()
    figfilename = f"phase_problem_{flag}.pdf"
    plt.savefig(figfilename)
    print(f"Figure saved as {figfilename}")
    plt.close()
예제 #3
0
def roughness():
    sld1 = SLD(0, 0)
    sld2 = SLD(6.335, 0)
    sld3 = SLD(2.074, 0)

    layer1 = sld1(0, 0)
    layer3 = sld3(10, 0)

    fig = plt.figure(figsize=(10, 7.5 / 2))
    gs = gridspec.GridSpec(1, 3)
    ax1 = plt.subplot(gs[0:2])
    ax2 = plt.subplot(gs[2])
    for i in range(3, 9, 2):
        layer2 = sld2(10, i)
        structure = Structure(layer1 | layer2 | layer3)

        ax1.plot(*structure.sld_profile())
        ax2.plot(*structure.sld_profile())
    ax2.set_ylim(1.6, 2.6)
    ax2.set_xlim(5, 15)
    ax1.axhline(sld3.real, color='k', alpha=0.3)
    ax2.axhline(sld3.real, color='k', alpha=0.3)
    ax1.set_xlabel(r'$z$/Å')
    ax1.set_ylabel(r'$\rho(z)$/Å$^{-2}$')
    ax1.text(0.025,
             0.95,
             '(a)',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax1.transAxes)
    ax2.set_xlabel(r'$z$/Å')
    ax2.set_ylabel(r'$\rho(z)$/Å$^{-2}$')
    ax2.text(0.025,
             0.95,
             '(b)',
             horizontalalignment='left',
             verticalalignment='top',
             transform=ax2.transAxes)
    plt.tight_layout()
    plt.savefig("roughness.pdf")
    plt.close()
예제 #4
0
sld1 = SLD(0, 0)
sld2 = SLD(6.335, 0)
sld3 = SLD(2.074, 0)

layer1 = sld1(0, 0)
layer3 = sld3(10, 0)

fig = plt.figure(figsize=(10, 7.5 / 2))
gs = gridspec.GridSpec(1, 3)
ax1 = plt.subplot(gs[0:2])
ax2 = plt.subplot(gs[2])
for i in range(3, 9, 2):
    layer2 = sld2(10, i)
    structure = Structure(layer1 | layer2 | layer3)

    ax1.plot(*structure.sld_profile())
    ax2.plot(*structure.sld_profile())
ax2.set_ylim(1.6, 2.6)
ax2.set_xlim(5, 15)
ax1.axhline(sld3.real, color='k', alpha=0.3)
ax2.axhline(sld3.real, color='k', alpha=0.3)
ax1.set_xlabel(r'$z$/Å')
ax1.set_ylabel(r'$\rho(z)$/Å$^{-2}$')
ax1.text(0.025,
         0.95,
         '(a)',
         horizontalalignment='left',
         verticalalignment='top',
         transform=ax1.transAxes)
ax2.set_xlabel(r'$z$/Å')
ax2.set_ylabel(r'$\rho(z)$/Å$^{-2}$')
def phase_problem_plot(flag):
    if flag != "SLD" and flag != "ACF":
        raise Exception("Invalid flag to plot")

    qvals = np.linspace(0, 0.2, 1025)[1:]
    sld1 = SLD(0, 0)
    sld3 = SLD(2.074, 0)

    layer1 = sld1(0, 0)
    layer3 = sld3(0, 0)

    fig = plt.figure(figsize=(10, 7.5))
    gs = gridspec.GridSpec(2, 1)
    ax1 = plt.subplot(gs[0, 0])
    ax2 = plt.subplot(gs[1, 0])
    colors = [_fig_params.colors[0], _fig_params.colors[1]]
    ls = ['-', ':']
    for i in [0, 1]:
        sld20 = SLD(6.335 - i, 0)
        sld21 = SLD(6.335 + i, 0)
        layer20 = sld20(100, 0)
        layer21 = sld21(100, 0)
        structure = Structure(layer1 | layer20 | layer21 | layer3)
        z, rho = structure.sld_profile()
        drho = (rho[1:] - rho[:-1]) / (z[1:] - z[:-1])
        z_ = 0.5 * (z[:-1] + z[1:])
        acf = autocorr(drho)
        z_acf = z_ - z_.min()
        z_acf = np.hstack((-np.flip(z_acf)[:-1], z_acf))

        if flag == 'SLD':
            ax1.plot(z, rho, color=colors[i], ls=ls[i])
            ax2.semilogy(qvals,
                         ReflectModel(structure, dq=0.0).model(qvals),
                         color=colors[i],
                         ls=ls[i])

        else:
            ax1.stem(z_,
                     drho,
                     linefmt='C{}'.format(i) + ls[i],
                     basefmt='C{}'.format(i) + ls[i],
                     markerfmt=' ',
                     use_line_collection=True)
            ax2.stem(z_acf,
                     acf,
                     linefmt='C{}'.format(i) + ls[i],
                     basefmt='C{}'.format(i) + ls[i],
                     markerfmt=' ',
                     use_line_collection=True)

    if flag == 'SLD':
        ax1.set_xlabel(r'$z$/Å')
        ax1.set_ylabel(r'$\rho(z)$/Å$^{-2}$')

        ax2.set_xlabel(r'$q$/Å')
        ax2.set_ylabel(r'$R(q)$')
        ax1.text(0.025,
                 0.95,
                 '(a)',
                 horizontalalignment='left',
                 verticalalignment='top',
                 transform=ax1.transAxes)

    else:
        ax1.set_xlabel(r'$z$/Å')
        ax1.set_ylabel(r'$\rho\'(z)$/Å$^{-3}$')

        ax2.set_xlabel(r'$z$/Å')
        ax2.set_ylabel("$ \\rm{ACF}_{\\rho'}(z)/ \\AA^{-5}$")
        ax1.text(0.975,
                 0.95,
                 '(a)',
                 horizontalalignment='right',
                 verticalalignment='top',
                 transform=ax1.transAxes)

    ax2.text(0.975,
             0.95,
             '(b)',
             horizontalalignment='right',
             verticalalignment='top',
             transform=ax2.transAxes)

    plt.tight_layout()
    figfilename = f"phase_problem_{flag}.pdf"
    plt.savefig(figfilename)
    print(f"Figure saved as {figfilename}")
    plt.close()