Skip to content

Commit a82972f

Browse files
authored
Merge pull request #23 from virtualcell/sysbio-course-4
more usability improvements
2 parents 9b62653 + b67c061 commit a82972f

21 files changed

+313
-530
lines changed

examples/notebooks/fielddata_trame.ipynb

Lines changed: 151 additions & 162 deletions
Large diffs are not rendered by default.

examples/scripts/_internal_combined_fvsolver_data.py

Lines changed: 0 additions & 188 deletions
This file was deleted.

examples/scripts/_internal_data_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# ## extract the vcell simulation dataset from the tarball (compressed to save space)
1515

1616

17-
test_data_dir = Path(os.getcwd()) / "solver_output"
17+
test_data_dir = Path(os.getcwd()).parent / "solver_output"
1818

1919

2020
# ## read vcell simulation results metadata

examples/scripts/_internal_fvsolver_demo.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

examples/scripts/fielddata_from_image_workflow.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
import numpy as np
66

7+
import pyvcell.vcml as vc
78
from pyvcell._internal.simdata.mesh import CartesianMesh
89
from pyvcell.sim_results.var_types import NDArray3D, NDArray4D
9-
from pyvcell.vcml import VcmlReader
10-
from pyvcell.vcml.field import Field
11-
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation as Solver
1210

1311

1412
def create_sinusoid(
@@ -34,7 +32,7 @@ def create_sinusoid(
3432

3533
# ---- read in VCML file
3634
model_path = Path(os.getcwd()).parent / "models" / "SmallSpatialProject_3D.vcml"
37-
bio_model = VcmlReader.biomodel_from_file(vcml_path=model_path)
35+
bio_model = vc.load_vcml_file(model_path)
3836

3937
# ---- get the species mappings for species "s0" and "s1"
4038
app = bio_model.applications[0]
@@ -46,7 +44,7 @@ def create_sinusoid(
4644
s1_mapping.init_conc = "vcField('checkerboard', 'v', 0.0, 'Volume')"
4745

4846
sim = app.add_sim(name="new_sim", duration=10.0, output_time_step=0.1, mesh_size=(20, 20, 20))
49-
fields = Field.create_fields(bio_model=bio_model, sim=sim)
47+
fields = vc.Field.create_fields(bio_model=bio_model, sim=sim)
5048
print(fields)
5149

5250
shape = fields[0].data_nD.shape
@@ -58,7 +56,7 @@ def create_sinusoid(
5856

5957
# ---- add field data to the simulation
6058

61-
sim1_result = Solver(bio_model=bio_model, out_dir=sim_dir, fields=fields).run(sim.name)
59+
sim1_result = vc.simulate(biomodel=bio_model, simulation=sim, fields=fields)
6260
print([c.label for c in sim1_result.channel_data])
6361
print(sim1_result.time_points[::11])
6462
sim1_result.plotter.plot_slice_3d(time_index=0, channel_id="s0")

examples/scripts/fielddata_from_sim_workflow.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import tempfile
44
from pathlib import Path
55

6-
from pyvcell.vcml import VcmlReader
7-
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation as Solver
6+
import pyvcell.vcml as vc
87

98
with tempfile.TemporaryDirectory() as temp_dir_name, Path(temp_dir_name) as temp_dir:
109
# ----- make a workspace
@@ -18,7 +17,7 @@
1817

1918
# ---- read in VCML file
2019
model_fp = Path(os.getcwd()).parent / "models" / "SmallSpatialProject_3D.vcml"
21-
bio_model1 = VcmlReader.biomodel_from_file(model_fp)
20+
bio_model1 = vc.load_vcml_file(model_fp)
2221

2322
# ---- get the application and the species mappings for species "s0" and "s1"
2423
app = bio_model1.applications[0]
@@ -34,19 +33,23 @@
3433

3534
# ---- run simulation, store in sim1_dir, and plot results
3635
# >>>>> This forms the data for the "Field Data" identified by 'sim1_dir' <<<<<<
37-
sim1_result = Solver(bio_model=bio_model1, out_dir=sim1_dir).run(sim.name)
36+
sim1_result = vc.simulate(biomodel=bio_model1, simulation=sim.name)
3837
print([c.label for c in sim1_result.channel_data])
3938
print(sim1_result.time_points[::11])
4039
sim1_result.plotter.plot_slice_3d(time_index=0, channel_id="s0")
4140
sim1_result.plotter.plot_slice_3d(time_index=0, channel_id="s1")
4241
sim1_result.plotter.plot_concentrations()
42+
sim1_result_dirname = sim1_result.solver_output_dir.name
4343

4444
# ----- use field data from sim1_dir to set initial concentration of species "s0"
45-
s0_mapping.init_conc = "vcField('sim1_dir','s0',0.0,'Volume') * vcField('sim1_dir','s1',0.0,'Volume')"
45+
s0_mapping.init_conc = (
46+
f"vcField('{sim1_result_dirname}','s0',0.0,'Volume') * vcField('{sim1_result_dirname}','s1',0.0,'Volume')"
47+
)
4648
s1_mapping.init_conc = "5.0"
4749
# ---- re-run simulation and store in sim2_dir
4850
# note that the solution of s0 draws from the data from sim1_dir
49-
sim2_result = Solver(bio_model=bio_model1, out_dir=sim2_dir).run(sim.name)
51+
sim2_result = vc.simulate(biomodel=bio_model1, simulation=sim.name)
5052
sim2_result.plotter.plot_slice_3d(time_index=0, channel_id="s0")
5153
sim2_result.plotter.plot_slice_3d(time_index=0, channel_id="s1")
5254
sim2_result.plotter.plot_concentrations()
55+
sim2_result.cleanup()

examples/scripts/sysbio_class.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from pathlib import Path
22

3-
import pyvcell.vcml as vcml
4-
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation as VCSolver
3+
import pyvcell.vcml as vc
54

65
WORKSPACE_DIR = Path(__file__).parent.resolve()
76

@@ -17,20 +16,21 @@
1716
A = 10
1817
"""
1918

20-
biomodel = vcml.load_antimony_str(antimony_str)
19+
biomodel = vc.load_antimony_str(antimony_str)
2120

2221
# create a 3D geometry
23-
geo = vcml.Geometry(name="geo", origin=(0, 0, 0), extent=(10, 10, 10), dim=3)
22+
geo = vc.Geometry(name="geo", origin=(0, 0, 0), extent=(10, 10, 10), dim=3)
2423
# cell = geo.add_sphere(name="cell", radius=4, center=(5,5,5))
2524
medium = geo.add_background(name="background")
2625

2726
# add an application to the biomodel
2827
app = biomodel.add_application("app1", geometry=geo)
2928
app.map_compartment(compartment=biomodel.model.get_compartment("cell"), domain=medium) # type: ignore[union-attr]
3029
app.species_mappings = [
31-
vcml.SpeciesMapping(species_name="A", init_conc="sin(x)"),
32-
vcml.SpeciesMapping(species_name="B", init_conc="cos(x+y+z)"),
30+
vc.SpeciesMapping(species_name="A", init_conc="sin(x)"),
31+
vc.SpeciesMapping(species_name="B", init_conc="cos(x+y+z)"),
3332
]
34-
sim = app.add_sim(name="sim1", duration=10.0, output_time_step=0.5, mesh_size=(50, 50, 50))
35-
results = VCSolver(bio_model=biomodel, out_dir=WORKSPACE_DIR / "sim1").run(simulation_name="sim1")
33+
sim = app.add_sim(name="sim1", duration=2.0, output_time_step=0.5, mesh_size=(50, 50, 50))
34+
results = vc.simulate(biomodel=biomodel, simulation="sim1")
3635
results.plotter.plot_concentrations()
36+
results.cleanup()
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import os
22
from pathlib import Path
33

4-
from pyvcell.vcml import VcmlReader
5-
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation
4+
import pyvcell.vcml as vc
65

76
model_fp = Path(os.getcwd()).parent / "models" / "Bunny.vcml"
87

9-
bio_model = VcmlReader.biomodel_from_file(model_fp)
8+
bio_model = vc.load_vcml_file(model_fp)
109
sims = [sim for app in bio_model.applications for sim in app.simulations]
1110

1211
# define editable spatial model and simulation instances
13-
simulation = VcmlSpatialSimulation(bio_model=bio_model)
14-
result = simulation.run(sims[0].name)
12+
result = vc.simulate(biomodel=bio_model, simulation=sims[0].name)
1513

1614
print([c.label for c in result.channel_data])
1715
result.plotter.plot_slice_2d(time_index=3, channel_name="s_in", z_index=result.zarr_dataset.shape[3] // 2)
1816
result.plotter.plot_slice_3d(time_index=3, channel_id="s_in")
1917
result.plotter.plot_concentrations()
20-
simulation.cleanup()
18+
result.cleanup()

0 commit comments

Comments
 (0)