{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "4b988c4a-3a09-4b75-8a87-8ba8402635ba", "metadata": {}, "outputs": [], "source": [ "import pathlib\n", "\n", "import numpy as np\n", "from IPython.display import Code\n", "\n", "import RATapi as RAT\n", "from RATapi.models import Parameter" ] }, { "cell_type": "markdown", "id": "793d9c50-698e-438b-87f7-85e3a9f11d6b", "metadata": {}, "source": [ "# Custom Layers Example for Supported DSPC layer\n", "\n", "Example of using Custom layers to model a DSPC supported bilayer.\n", "Start by making the project and setting it to a custom layers type:" ] }, { "cell_type": "code", "execution_count": 2, "id": "9a60cd45-0e1d-448a-b4bd-4c02bd6a3475", "metadata": {}, "outputs": [], "source": [ "problem = RAT.Project(name=\"Orso lipid example - custom layers\", model=\"custom layers\", geometry=\"substrate/liquid\")" ] }, { "cell_type": "markdown", "id": "9cc56e51-3d52-460a-bbb1-6d68571887c6", "metadata": {}, "source": [ "For a custom layers model, rather than being forced to define our layers as \\[Thick SLD Rough.... etc\\], we can parameterise however we like and then use a function to calculate the \\[d $\\rho$ $\\sigma$\\] arrangement for each layer. So for example, if the volume of lipid tails are known (from the literature), then all we need is the Area per molecule, because then:\n", "\n", "$$\n", "d = \\frac{V}{APM},\n", "$$\n", "where d is the thickness and V is the volume.\n", "\n", "Likewise, the SLD is:\n", "$$\n", "\\rho = \\frac{\\sum_{i}n_{i}b_{i}}{V},\n", "$$\n", "\n", "as usual.\n", "\n", "In this folder there is a pre-prepared Python custom model for a DSPC on a Silicon substrate. We can display it here to see what we mean:" ] }, { "cell_type": "code", "execution_count": 3, "id": "9038b77f-e3fc-4946-87fe-af4addf8ee84", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
import numpy as np\n",
"\n",
"\n",
"def custom_bilayer_DSPC(params, bulk_in, bulk_out, contrast):\n",
" """CUSTOMBILAYER RAT Custom Layer Model File.\n",
"\n",
" This file accepts 3 vectors containing the values for params, bulk in and bulk out.\n",
" The final parameter is an index of the contrast being calculated.\n",
"\n",
" The function should output a matrix of layer values, in the form...\n",
"\n",
" Output = [thick 1, SLD 1, Rough 1, Percent Hydration 1, Hydrate how 1\n",
" ....\n",
" thick n, SLD n, Rough n, Percent Hydration n, Hydration how n]\n",
"\n",
" The "hydrate how" parameter decides if the layer is hydrated with Bulk out or Bulk in phases.\n",
" Set to 1 for Bulk out, zero for Bulk in.\n",
" Alternatively, leave out hydration and just return...\n",
"\n",
" Output = [thick 1, SLD 1, Rough 1,\n",
" ....\n",
" thick n, SLD n, Rough n]\n",
"\n",
" The second output parameter should be the substrate roughness.\n",
" """\n",
" sub_rough = params[0]\n",
" oxide_thick = params[1]\n",
" oxide_hydration = params[2]\n",
" lipidAPM = params[3]\n",
" headHydration = params[4]\n",
" bilayerHydration = params[5]\n",
" bilayerRough = params[6]\n",
" waterThick = params[7]\n",
"\n",
" # We have a constant SLD for the bilayer\n",
" oxide_SLD = 3.41e-6\n",
"\n",
" # Now make the lipid layers\n",
" # Use known lipid volume and compositions to make the layers\n",
"\n",
" # define all the neutron b's.\n",
" bc = 0.6646e-4 # Carbon\n",
" bo = 0.5843e-4 # Oxygen\n",
" bh = -0.3739e-4 # Hydrogen\n",
" bp = 0.513e-4 # Phosphorus\n",
" bn = 0.936e-4 # Nitrogen\n",
"\n",
" # Now make the lipid groups\n",
" COO = (4 * bo) + (2 * bc)\n",
" GLYC = (3 * bc) + (5 * bh)\n",
" CH3 = (2 * bc) + (6 * bh)\n",
" PO4 = (1 * bp) + (4 * bo)\n",
" CH2 = (1 * bc) + (2 * bh)\n",
" CHOL = (5 * bc) + (12 * bh) + (1 * bn)\n",
"\n",
" # Group these into heads and tails:\n",
" Head = CHOL + PO4 + GLYC + COO\n",
" Tails = (34 * CH2) + (2 * CH3)\n",
"\n",
" # We need volumes for each. Use literature values:\n",
" vHead = 319\n",
" vTail = 782\n",
"\n",
" # We use the volumes to calculate the SLDs\n",
" SLDhead = Head / vHead\n",
" SLDtail = Tails / vTail\n",
"\n",
" # We calculate the layer thickness' from the volumes and the APM\n",
" headThick = vHead / lipidAPM\n",
" tailThick = vTail / lipidAPM\n",
"\n",
" # Manually deal with hydration for layers in this example.\n",
" oxSLD = (oxide_hydration * bulk_out[contrast]) + ((1 - oxide_hydration) * oxide_SLD)\n",
" headSLD = (headHydration * bulk_out[contrast]) + ((1 - headHydration) * SLDhead)\n",
" tailSLD = (bilayerHydration * bulk_out[contrast]) + ((1 - bilayerHydration) * SLDtail)\n",
"\n",
" # Make the layers\n",
" oxide = [oxide_thick, oxSLD, sub_rough]\n",
" water = [waterThick, bulk_out[contrast], bilayerRough]\n",
" head = [headThick, headSLD, bilayerRough]\n",
" tail = [tailThick, tailSLD, bilayerRough]\n",
"\n",
" output = np.array([oxide, water, head, tail, tail, head])\n",
"\n",
" return output, sub_rough\n",
"