Skip to content

Commit d4c65d6

Browse files
committed
added fvsolver_demo.ipynb notebook and run_notebook.sh script
1 parent 02aafa5 commit d4c65d6

File tree

5 files changed

+259
-50
lines changed

5 files changed

+259
-50
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,7 @@ test_output_1/
173173
.python-version
174174

175175
**/.DS_Store
176+
/.venv_jupyter/
177+
178+
examples/test_output/SimID_*
179+

examples/fvsolver_demo.ipynb

Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
{
2+
"cells": [
3+
{
4+
"metadata": {
5+
"collapsed": false,
6+
"ExecuteTime": {
7+
"end_time": "2025-01-23T23:01:54.750649Z",
8+
"start_time": "2025-01-23T23:01:53.532205Z"
9+
}
10+
},
11+
"cell_type": "code",
12+
"source": [
13+
"import tempfile\n",
14+
"import os\n",
15+
"import requests\n",
16+
"import tarfile\n",
17+
"\n",
18+
"temp_dir = tempfile.mkdtemp(prefix='pyvcell_test_data_')\n",
19+
"filename = os.path.join(temp_dir, 'SimID_946368938_simdata.tgz')\n",
20+
"url = 'https://github.com/virtualcell/pyvcell/blob/main/tests/test_data/SimID_946368938_simdata.tgz?raw=true'\n",
21+
"response = requests.get(url)\n",
22+
"\n",
23+
"with open(filename, 'wb') as f:\n",
24+
" f.write(response.content)\n",
25+
"\n",
26+
"with tarfile.open(filename, 'r:gz') as tar:\n",
27+
" tar.extractall(temp_dir)\n",
28+
"print(f\"Files extracted to {temp_dir}\")"
29+
],
30+
"id": "5e183b4a68315dfe",
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"Files extracted to /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/pyvcell_test_data_i35r8_br\n"
37+
]
38+
}
39+
],
40+
"execution_count": 1
41+
},
42+
{
43+
"cell_type": "code",
44+
"source": [
45+
"import shutil\n",
46+
"from pathlib import Path\n",
47+
"\n",
48+
"test_data_dir = Path(temp_dir)\n",
49+
"fv_input_file = test_data_dir / \"SimID_946368938_0_.fvinput\"\n",
50+
"vcg_file = test_data_dir / \"SimID_946368938_0_.vcg\"\n",
51+
"functions_file = test_data_dir / \"SimID_946368938_0_.functions\"\n",
52+
"test_output_dir = Path(os.getcwd()) / \"test_output\"\n",
53+
"\n",
54+
"shutil.copy(functions_file, test_output_dir)\n",
55+
"\n",
56+
"from pyvcell.solvers.fvsolver import solve\n",
57+
"try:\n",
58+
" ret_code = solve(input_file=fv_input_file, vcg_file=vcg_file, output_dir=test_output_dir)\n",
59+
" print(f\"Return code: {ret_code}\")\n",
60+
"except ValueError as e:\n",
61+
" print(f\"Error: {e}\")\n",
62+
"\n"
63+
],
64+
"metadata": {
65+
"collapsed": false,
66+
"ExecuteTime": {
67+
"end_time": "2025-01-23T23:19:41.486252Z",
68+
"start_time": "2025-01-23T23:19:40.386826Z"
69+
}
70+
},
71+
"id": "902c6d3a8dc70af",
72+
"outputs": [
73+
{
74+
"name": "stdout",
75+
"output_type": "stream",
76+
"text": [
77+
"initializing mesh\n",
78+
"Return code: 0\n"
79+
]
80+
},
81+
{
82+
"name": "stderr",
83+
"output_type": "stream",
84+
"text": [
85+
"Simulation Complete in Main() ... \n"
86+
]
87+
},
88+
{
89+
"name": "stdout",
90+
"output_type": "stream",
91+
"text": [
92+
"numVolume=126025\n",
93+
"\n",
94+
"CartesianMesh::computeNormalsFromNeighbors(), compute normals from neighbors\n",
95+
"Membrane Elements -> N=7817\n",
96+
"==============================================\n",
97+
"--------Num of points that have zero neighbors 0\n",
98+
"--------Num Neighbors before symmetrize 46161\n",
99+
"--------Num Neighbors after symmetrize 51016\n",
100+
"Total volume=5824.650822\n",
101+
"Total FluxArea =36.79383373\n",
102+
"Total FluxAreaXM =0\n",
103+
"Total FluxAreaXP =0\n",
104+
"Total FluxAreaYM =21.43445916\n",
105+
"Total FluxAreaYP =15.35937457\n",
106+
"Total FluxAreaZM =0\n",
107+
"Total FluxAreaZP =0\n",
108+
"mesh initialized\n",
109+
"preprocessing finished\n",
110+
"pdeCount=4, odeCount=0\n",
111+
"error opening log file </Users/jimschaff/Documents/workspace/pyvcell/examples/test_output/SimID_946368938_0_.log>\n",
112+
"simulation [SimID_946368938_0_] started\n",
113+
"temporary directory used is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/\n",
114+
"sim file name is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/SimID_946368938_0_0000.sim\n",
115+
"**This is a little endian machine.**\n",
116+
"[[[data:0]]]\n",
117+
"numVolRegions=6\n",
118+
"Region 0: size=110800, offset=0\n",
119+
"Region 1: size=12207, offset=110800\n",
120+
"Region 2: size=1, offset=123007\n",
121+
"Region 3: size=1, offset=123008\n",
122+
"Region 4: size=1, offset=123009\n",
123+
"Region 5: size=3015, offset=123010\n",
124+
"# of active points = 126025\n",
125+
"Constant diffusion/advection in region cytosol1\n",
126+
"Constant diffusion/advection in region cytosol2\n",
127+
"Constant diffusion/advection in region cytosol3\n",
128+
"Constant diffusion/advection in region cytosol4\n",
129+
"Constant diffusion/advection in region Nucleus5\n",
130+
"numUnknowns = 39645\n",
131+
"\n",
132+
"****** using Sundials CVode with PREC_LEFT, relTol=1e-07, absTol=1e-09, maxStep=0.1\n",
133+
"\n",
134+
"----------------------------------\n",
135+
"sundials pde solver is starting from time 0\n",
136+
"----------------------------------\n",
137+
"temporary directory used is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/\n",
138+
"sim file name is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/SimID_946368938_0_0001.sim\n",
139+
"[[[data:0.25]]]temporary directory used is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/\n",
140+
"sim file name is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/SimID_946368938_0_0002.sim\n",
141+
"[[[data:0.5]]]temporary directory used is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/\n",
142+
"sim file name is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/SimID_946368938_0_0003.sim\n",
143+
"[[[data:0.75]]]\n",
144+
"Final Statistics.. \n",
145+
"\n",
146+
"lenrw = 396539 leniw = 50\n",
147+
"lenrwLS = 396496 leniwLS = 10\n",
148+
"nst = 63\n",
149+
"nfe = 76 nfeLS = 87\n",
150+
"nni = 72 nli = 87\n",
151+
"nsetups = 22 netf = 0\n",
152+
"npe = 2 nps = 147\n",
153+
"ncfn = 0 ncfl = 0\n",
154+
"last step = 0.017509\n",
155+
"\n",
156+
"temporary directory used is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/\n",
157+
"sim file name is /var/folders/zz/gcfcvgtd5v1cdgj2sw4bjzdr0000gr/T/SimID_946368938_0_0004.sim\n",
158+
"[[[data:1]]][[[progress:100%]]]"
159+
]
160+
}
161+
],
162+
"execution_count": 4
163+
},
164+
{
165+
"cell_type": "code",
166+
"id": "ed266f9194abb748",
167+
"metadata": {
168+
"collapsed": false,
169+
"ExecuteTime": {
170+
"end_time": "2025-01-23T23:22:08.523252Z",
171+
"start_time": "2025-01-23T23:22:08.520883Z"
172+
}
173+
},
174+
"source": [
175+
"import os\n",
176+
"with os.scandir(test_output_dir) as entries:\n",
177+
" for entry in entries:\n",
178+
" print(entry.name)"
179+
],
180+
"outputs": [
181+
{
182+
"name": "stdout",
183+
"output_type": "stream",
184+
"text": [
185+
".placeholder\n",
186+
"SimID_946368938_0_.hdf5\n",
187+
"SimID_946368938_0_.mesh\n",
188+
"SimID_946368938_0_.log\n",
189+
"SimID_946368938_0_.meshmetrics\n",
190+
"SimID_946368938_0_00.zip\n",
191+
"SimID_946368938_0_.functions\n"
192+
]
193+
}
194+
],
195+
"execution_count": 7
196+
}
197+
],
198+
"metadata": {
199+
"kernelspec": {
200+
"display_name": "Python 3 (ipykernel)",
201+
"language": "python",
202+
"name": "python3"
203+
},
204+
"language_info": {
205+
"codemirror_mode": {
206+
"name": "ipython",
207+
"version": 3
208+
},
209+
"file_extension": ".py",
210+
"mimetype": "text/x-python",
211+
"name": "python",
212+
"nbconvert_exporter": "python",
213+
"pygments_lexer": "ipython3",
214+
"version": "3.12.2"
215+
}
216+
},
217+
"nbformat": 4,
218+
"nbformat_minor": 5
219+
}

examples/test_output/.placeholder

Whitespace-only changes.

examples/vcell_publications.ipynb

Lines changed: 23 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
{
44
"cell_type": "code",
55
"source": [
6+
"from IPython.display import display\n",
67
"from pyvcell.api.vcell_client import ApiClient, Configuration, PublicationResourceApi\n",
78
"from pyvcell.api.vcell_client.auth.auth_utils import login_interactive\n",
89
"from pyvcell.api.vcell_client.models import Publication"
910
],
1011
"metadata": {
1112
"collapsed": false,
1213
"ExecuteTime": {
13-
"end_time": "2025-01-23T07:43:37.703710Z",
14-
"start_time": "2025-01-23T07:43:37.701027Z"
14+
"end_time": "2025-01-23T23:24:18.606822Z",
15+
"start_time": "2025-01-23T23:24:17.359245Z"
1516
}
1617
},
1718
"id": "5e183b4a68315dfe",
1819
"outputs": [],
19-
"execution_count": 2
20+
"execution_count": 1
2021
},
2122
{
2223
"cell_type": "markdown",
@@ -50,13 +51,13 @@
5051
"metadata": {
5152
"collapsed": false,
5253
"ExecuteTime": {
53-
"end_time": "2025-01-23T07:43:37.725514Z",
54-
"start_time": "2025-01-23T07:43:37.723335Z"
54+
"end_time": "2025-01-23T23:24:18.612189Z",
55+
"start_time": "2025-01-23T23:24:18.610330Z"
5556
}
5657
},
5758
"id": "902c6d3a8dc70af",
5859
"outputs": [],
59-
"execution_count": 3
60+
"execution_count": 2
6061
},
6162
{
6263
"cell_type": "markdown",
@@ -72,30 +73,22 @@
7273
{
7374
"cell_type": "code",
7475
"source": [
76+
"from IPython.display import display\n",
77+
"\n",
7578
"public_publication_api = PublicationResourceApi(public_client)\n",
7679
"pubs: list[Publication] = public_publication_api.get_publications()\n",
7780
"display(pubs[0])"
7881
],
7982
"metadata": {
8083
"collapsed": false,
8184
"ExecuteTime": {
82-
"end_time": "2025-01-23T07:43:38.028844Z",
83-
"start_time": "2025-01-23T07:43:37.735773Z"
85+
"end_time": "2025-01-23T23:24:19.365418Z",
86+
"start_time": "2025-01-23T23:24:18.663169Z"
8487
}
8588
},
8689
"id": "9ba5b1ac2df17231",
87-
"outputs": [
88-
{
89-
"data": {
90-
"text/plain": [
91-
"Publication(pub_key=279906235, title='A continuum model of mechanosensation based on contractility kit assembly', authors=['Dolgitzer', ' D.', ' Plaza-Rodríguez', ' A. I.', ' Iglesias', ' M. A.', ' Jacob', ' M. A. C.', ' Todd', ' B.', ' Robinson', ' D. N.', ' & Iglesias', ' P. A.'], year=2024, citation='Biophys J. 2024 Nov 8:S0006-3495(24)00708-2', pubmedid='39521955', doi='https://doi.org/10.1016/j.bpj.2024.10.020', endnoteid=0, url='url', wittid=0, biomodel_refs=[BiomodelRef(bm_key=279851639, name='Dolgitzer 2025 A Continuum Model of Mechanosensation Based on Contractility Kit Assembly', owner_name='Dolgitzer', owner_key=259537152, version_flag=3)], mathmodel_refs=[], var_date=datetime.date(2024, 11, 26))"
92-
]
93-
},
94-
"metadata": {},
95-
"output_type": "display_data"
96-
}
97-
],
98-
"execution_count": 4
90+
"outputs": [],
91+
"execution_count": 3
9992
},
10093
{
10194
"cell_type": "markdown",
@@ -114,8 +107,8 @@
114107
"metadata": {
115108
"collapsed": false,
116109
"ExecuteTime": {
117-
"end_time": "2025-01-23T07:43:46.823079Z",
118-
"start_time": "2025-01-23T07:43:38.037782Z"
110+
"end_time": "2025-01-23T23:24:20.900935Z",
111+
"start_time": "2025-01-23T23:24:19.375651Z"
119112
}
120113
},
121114
"source": [
@@ -125,18 +118,8 @@
125118
"authenticated_client = login_interactive(api_base_url=api_url, client_id=client_id, issuer_url=issuer_url)\n",
126119
"display(\"may loose focus to the browser window for login, switch back to this notebook after login.\")"
127120
],
128-
"outputs": [
129-
{
130-
"data": {
131-
"text/plain": [
132-
"'may loose focus to the browser window for login, switch back to this notebook after login.'"
133-
]
134-
},
135-
"metadata": {},
136-
"output_type": "display_data"
137-
}
138-
],
139-
"execution_count": 5
121+
"outputs": [],
122+
"execution_count": 4
140123
},
141124
{
142125
"cell_type": "markdown",
@@ -155,36 +138,26 @@
155138
"metadata": {
156139
"collapsed": false,
157140
"ExecuteTime": {
158-
"end_time": "2025-01-23T07:43:47.020349Z",
159-
"start_time": "2025-01-23T07:43:46.852654Z"
141+
"end_time": "2025-01-23T23:24:21.114730Z",
142+
"start_time": "2025-01-23T23:24:20.912950Z"
160143
}
161144
},
162145
"source": [
163146
"publication_api = PublicationResourceApi(authenticated_client)\n",
164147
"pubs: list[Publication] = publication_api.get_publications()\n",
165148
"display(pubs[0])"
166149
],
167-
"outputs": [
168-
{
169-
"data": {
170-
"text/plain": [
171-
"Publication(pub_key=279906235, title='A continuum model of mechanosensation based on contractility kit assembly', authors=['Dolgitzer', ' D.', ' Plaza-Rodríguez', ' A. I.', ' Iglesias', ' M. A.', ' Jacob', ' M. A. C.', ' Todd', ' B.', ' Robinson', ' D. N.', ' & Iglesias', ' P. A.'], year=2024, citation='Biophys J. 2024 Nov 8:S0006-3495(24)00708-2', pubmedid='39521955', doi='https://doi.org/10.1016/j.bpj.2024.10.020', endnoteid=0, url='url', wittid=0, biomodel_refs=[BiomodelRef(bm_key=279851639, name='Dolgitzer 2025 A Continuum Model of Mechanosensation Based on Contractility Kit Assembly', owner_name='Dolgitzer', owner_key=259537152, version_flag=3)], mathmodel_refs=[], var_date=datetime.date(2024, 11, 26))"
172-
]
173-
},
174-
"metadata": {},
175-
"output_type": "display_data"
176-
}
177-
],
178-
"execution_count": 6
150+
"outputs": [],
151+
"execution_count": 5
179152
},
180153
{
181154
"cell_type": "code",
182155
"id": "ed266f9194abb748",
183156
"metadata": {
184157
"collapsed": false,
185158
"ExecuteTime": {
186-
"end_time": "2025-01-23T07:43:47.026801Z",
187-
"start_time": "2025-01-23T07:43:47.025477Z"
159+
"end_time": "2025-01-23T23:24:21.125418Z",
160+
"start_time": "2025-01-23T23:24:21.123871Z"
188161
}
189162
},
190163
"source": [],

scripts/run_notebook.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -ex
4+
5+
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && cd .. && pwd )"
6+
7+
cd ${ROOT_DIR} || (echo "Failed to cd into ${ROOT_DIR}" && exit 1)
8+
9+
python -m venv .venv_jupyter
10+
source .venv_jupyter/bin/activate
11+
pip install jupyter ipython
12+
poetry install
13+
jupyter notebook

0 commit comments

Comments
 (0)