-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'development' into dokken/deprecated_unused_functions
Also resolves reviwer comments
- Loading branch information
Showing
14 changed files
with
7,694 additions
and
4,174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
# $ docker run -ti --name stubs --init -p 8080:8888 -v $HOME:/home/fenics/shared stubs:latest | ||
|
||
# Base fenics dev image | ||
FROM quay.io/fenicsproject/dev | ||
FROM ghcr.io/scientificcomputing/fenics:2023-01-16 | ||
|
||
|
||
# ====================================================== | ||
|
@@ -87,8 +87,9 @@ RUN python3 -m pip install tikzplotlib | |
# this is to install just the dependencies so that we can use the local version of stubs | ||
RUN python3 -m pip install fenics-stubs | ||
RUN python3 -m pip uninstall --yes fenics-stubs | ||
# now we add the local repo to the pythonpath | ||
ENV PYTHONPATH "${PYTHONPATH}:$FENICS_HOME/shared/gitrepos/stubs" | ||
# now we add the local repo to the pythonpath | ||
ENV FENICS_HOME "/root" | ||
ENV PYTHONPATH "/root/shared/gitrepos/stubs-dev" | ||
|
||
|
||
# bashrc settings (this appends to the top of the file) | ||
|
@@ -142,13 +143,4 @@ highlight ColorColumn ctermbg=7" >> $FENICS_HOME/.vimrc | |
RUN ["/bin/bash", "-c", "source $FENICS_HOME/.bashrc"] | ||
#RUN cd $FENICS_SRC_DIR/dolfin | ||
#build cmake | ||
#build pybind11 cd $FENICS_SRC_DIR/dolfin | ||
|
||
|
||
|
||
|
||
# dont want my email floating around on the internet | ||
RUN email_name="justinglaughlin" | ||
RUN git config --global user.email "[email protected]" | ||
RUN git config --global user.name "justinlaughlin" | ||
|
||
#build pybind11 cd $FENICS_SRC_DIR/dolfin |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,245 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "f65f18d7", | ||
"metadata": {}, | ||
"source": [ | ||
"# Example for system in Meyers, Craig and Odde 2006\n", | ||
"\n", | ||
"Geometry is divided into 2 domains; one volume and one surface:\n", | ||
"- PM\n", | ||
"- Cytosol\n", | ||
"\n", | ||
"This model has a single species, A, which is phosphorylated at the cell membrane. The unphosphorylated form of A ($A_{dephos}$) can be inferred from mass conservation; everywhere $c_{A_{phos}} + c_{A_{dephos}} = c_{Tot}$, which is a constant in both time and space if the phosphorylated vs. unphosphorylated forms have the same diffusion coefficient.\n", | ||
"\n", | ||
"There are two reactions - one in the PM and other in the cytosol. At the membrane, $A_{dephos}$ is phosphorylated by a first-order reaction with rate $k_{kin}$, and in the cytosolic volume, $A_{phos}$ is dephosphorylated by a first order reaction with rate $k_p$.\n", | ||
"\n", | ||
"Currently, this code includes a dummy variable, kinMem, which represents relative kinase activity at the membrane, currently set as constant at 1 (dimensionless). Without this additional species, the code currently does not solve the system (it seems that there needs to be variables in at least two compartments to solve the monolithic system).\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"id": "cc398816", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"Authorization required, but no authorization protocol specified\n", | ||
"Authorization required, but no authorization protocol specified\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import os\n", | ||
"\n", | ||
"import dolfin as d\n", | ||
"import sympy as sym\n", | ||
"import numpy as np\n", | ||
"\n", | ||
"from stubs import unit, config, common, mesh, model\n", | ||
"from stubs.model_assembly import Compartment, Parameter, Reaction, Species, sbmodel_from_locals" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "95b9d865", | ||
"metadata": {}, | ||
"source": [ | ||
"First, we define the various units for the inputs" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"id": "4f4023cf", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Aliases - base units\n", | ||
"uM = unit.uM\n", | ||
"um = unit.um\n", | ||
"molecule = unit.molecule\n", | ||
"sec = unit.sec\n", | ||
"dimensionless = unit.dimensionless\n", | ||
"# Aliases - units used in model\n", | ||
"D_unit = um**2 / sec\n", | ||
"flux_unit = molecule / (um**2 * sec)\n", | ||
"vol_unit = uM\n", | ||
"surf_unit = molecule / um**2" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "46582d26", | ||
"metadata": {}, | ||
"source": [ | ||
"Next we generate the model." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"id": "09079b17", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def make_model(curRadius):\n", | ||
" # =============================================================================================\n", | ||
" # Species\n", | ||
" # =============================================================================================\n", | ||
" # name, initial concentration, concentration units, diffusion, diffusion units, compartment\n", | ||
" Aphos = Species(\"Aphos\", 0.1, vol_unit, 10.0, D_unit, \"Cyto\")\n", | ||
" kinMem = Species(\"kinMem\", 1.0, dimensionless, 0.0, D_unit, \"PM\") # dummy variable; without this, the current version of SMART throws an error\n", | ||
"\n", | ||
" # =============================================================================================\n", | ||
" # Compartments\n", | ||
" # =============================================================================================\n", | ||
" # name, topological dimensionality, length scale units, marker value\n", | ||
" Cyto = Compartment(\"Cyto\", 3, um, 1)\n", | ||
" PM = Compartment(\"PM\", 2, um, 10)\n", | ||
"\n", | ||
" # =============================================================================================\n", | ||
" # Parameters and Reactions\n", | ||
" # =============================================================================================\n", | ||
" Atot = Parameter(\"Atot\", 1.0, vol_unit)\n", | ||
" # Phosphorylation of Adephos at the PM\n", | ||
" kkin = Parameter(\"kkin\", 50.0, 1/sec) \n", | ||
" VolSA = Parameter(\"VolSA\", curRadius/3, um) # vol to surface area ratio of the cell\n", | ||
" r1 = Reaction(\"r1\", [], [\"Aphos\"], param_map={\"kon\": \"kkin\", \"Atot\": \"Atot\", \"VolSA\": \"VolSA\"},\n", | ||
" eqn_f_str=\"kinMem*kon*VolSA*(Atot - Aphos)\", species_map={\"Aphos\": \"Aphos\",\"kinMem\": \"kinMem\"}, explicit_restriction_to_domain=\"PM\")\n", | ||
" # Dephosphorylation of Aphos in the cytosol\n", | ||
" kp = Parameter(\"kp\", 10.0, 1/sec)\n", | ||
" r2 = Reaction(\"r2\", [\"Aphos\"], [], param_map={\"kon\": \"kp\"},\n", | ||
" eqn_f_str=\"kon*Aphos\", species_map={\"Aphos\": \"Aphos\"})\n", | ||
"\n", | ||
" # =============================================================================================\n", | ||
" # Gather all parameters, species, compartments and reactions\n", | ||
" # =============================================================================================\n", | ||
" return sbmodel_from_locals(locals().values())" | ||
] | ||
}, | ||
{ | ||
"attachments": {}, | ||
"cell_type": "markdown", | ||
"id": "15c35d39", | ||
"metadata": {}, | ||
"source": [ | ||
"We load the model generated above, and load in the mesh we will use in this example, iterating over 10 different values of cell radius, log-spaced between 1 and 10." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"id": "fe56e162", | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"ename": "AttributeError", | ||
"evalue": "module 'stubs.common' has no attribute 'sbmodel_from_locals'", | ||
"output_type": "error", | ||
"traceback": [ | ||
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", | ||
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", | ||
"Cell \u001b[0;32mIn[4], line 4\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(\u001b[39m10\u001b[39m):\n\u001b[1;32m 3\u001b[0m curRadius \u001b[39m=\u001b[39m radiusVec[i]\n\u001b[0;32m----> 4\u001b[0m pc, sc, cc, rc \u001b[39m=\u001b[39m make_model(curRadius)\n\u001b[1;32m 6\u001b[0m \u001b[39m# =============================================================================================\u001b[39;00m\n\u001b[1;32m 7\u001b[0m \u001b[39m# Create/load in mesh\u001b[39;00m\n\u001b[1;32m 8\u001b[0m \u001b[39m# =============================================================================================\u001b[39;00m\n\u001b[1;32m 9\u001b[0m \u001b[39m# Base mesh\u001b[39;00m\n\u001b[1;32m 10\u001b[0m domain, facet_markers, cell_markers \u001b[39m=\u001b[39m common\u001b[39m.\u001b[39mDemoSpheresMesh(curRadius, \u001b[39m0\u001b[39m) \u001b[39m#0 in second argument corresponds to no ER\u001b[39;00m\n", | ||
"Cell \u001b[0;32mIn[3], line 33\u001b[0m, in \u001b[0;36mmake_model\u001b[0;34m(curRadius)\u001b[0m\n\u001b[1;32m 27\u001b[0m r2 \u001b[39m=\u001b[39m Reaction(\u001b[39m\"\u001b[39m\u001b[39mr2\u001b[39m\u001b[39m\"\u001b[39m, [\u001b[39m\"\u001b[39m\u001b[39mAphos\u001b[39m\u001b[39m\"\u001b[39m], [], param_map\u001b[39m=\u001b[39m{\u001b[39m\"\u001b[39m\u001b[39mkon\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mkp\u001b[39m\u001b[39m\"\u001b[39m},\n\u001b[1;32m 28\u001b[0m eqn_f_str\u001b[39m=\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mkon*Aphos\u001b[39m\u001b[39m\"\u001b[39m, species_map\u001b[39m=\u001b[39m{\u001b[39m\"\u001b[39m\u001b[39mAphos\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mAphos\u001b[39m\u001b[39m\"\u001b[39m})\n\u001b[1;32m 30\u001b[0m \u001b[39m# =============================================================================================\u001b[39;00m\n\u001b[1;32m 31\u001b[0m \u001b[39m# Gather all parameters, species, compartments and reactions\u001b[39;00m\n\u001b[1;32m 32\u001b[0m \u001b[39m# =============================================================================================\u001b[39;00m\n\u001b[0;32m---> 33\u001b[0m \u001b[39mreturn\u001b[39;00m common\u001b[39m.\u001b[39;49msbmodel_from_locals(\u001b[39mlocals\u001b[39m()\u001b[39m.\u001b[39mvalues())\n", | ||
"\u001b[0;31mAttributeError\u001b[0m: module 'stubs.common' has no attribute 'sbmodel_from_locals'" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"radiusVec = np.logspace(0,1,num=10) # currently testing 10 radius values\n", | ||
"for i in range(10):\n", | ||
" curRadius = radiusVec[i]\n", | ||
" pc, sc, cc, rc = make_model(curRadius)\n", | ||
"\n", | ||
" # =============================================================================================\n", | ||
" # Create/load in mesh\n", | ||
" # =============================================================================================\n", | ||
" # Base mesh\n", | ||
" domain, facet_markers, cell_markers = common.DemoSpheresMesh(curRadius, 0) #0 in second argument corresponds to no ER\n", | ||
" # Write mesh and meshfunctions to file\n", | ||
" os.makedirs(f\"mesh_{i:03d}\", exist_ok=True)\n", | ||
" common.write_mesh(domain, facet_markers, cell_markers, filename=f\"mesh_{i:03d}/DemoSphere\")\n", | ||
"\n", | ||
" # # Define solvers\n", | ||
" parent_mesh = mesh.ParentMesh(\n", | ||
" mesh_filename=f\"mesh_{i:03d}/DemoSphere.h5\",\n", | ||
" mesh_filetype=\"hdf5\",\n", | ||
" name=\"parent_mesh\",\n", | ||
" )\n", | ||
" configCur = config.Config()\n", | ||
" modelCur = model.Model(pc, sc, cc, rc, configCur, parent_mesh)\n", | ||
" configCur.solver.update(\n", | ||
" {\n", | ||
" \"final_t\": 1,\n", | ||
" \"initial_dt\": 0.01,\n", | ||
" \"time_precision\": 6,\n", | ||
" \"use_snes\": True,\n", | ||
" \"print_assembly\": False,\n", | ||
" }\n", | ||
" )\n", | ||
"\n", | ||
" modelCur.initialize(initialize_solver=False)\n", | ||
" modelCur.initialize_discrete_variational_problem_and_solver()\n", | ||
" # Write initial condition(s) to file\n", | ||
" results = dict()\n", | ||
" os.makedirs(f\"resultsSphere_{i:03d}\", exist_ok=True)\n", | ||
" for species_name, species in modelCur.sc.items:\n", | ||
" results[species_name] = d.XDMFFile(\n", | ||
" modelCur.mpi_comm_world, f\"resultsSphere_{i:03d}/{species_name}.xdmf\"\n", | ||
" )\n", | ||
" results[species_name].parameters[\"flush_output\"] = True\n", | ||
" results[species_name].write(modelCur.sc[species_name].u[\"u\"], modelCur.t)\n", | ||
"\n", | ||
" # Solve\n", | ||
" while True:\n", | ||
" # Solve the system\n", | ||
" modelCur.monolithic_solve()\n", | ||
" # Save results for post processing\n", | ||
" for species_name, species in modelCur.sc.items:\n", | ||
" results[species_name].write(modelCur.sc[species_name].u[\"u\"], modelCur.t)\n", | ||
" # End if we've passed the final time\n", | ||
" if modelCur.t >= modelCur.final_t:\n", | ||
" break" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"jupytext": { | ||
"cell_metadata_filter": "-all", | ||
"main_language": "python", | ||
"notebook_metadata_filter": "-all" | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.10.6" | ||
}, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
Oops, something went wrong.