Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 151 additions & 162 deletions examples/notebooks/fielddata_trame.ipynb

Large diffs are not rendered by default.

188 changes: 0 additions & 188 deletions examples/scripts/_internal_combined_fvsolver_data.py

This file was deleted.

2 changes: 1 addition & 1 deletion examples/scripts/_internal_data_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# ## extract the vcell simulation dataset from the tarball (compressed to save space)


test_data_dir = Path(os.getcwd()) / "solver_output"
test_data_dir = Path(os.getcwd()).parent / "solver_output"


# ## read vcell simulation results metadata
Expand Down
32 changes: 0 additions & 32 deletions examples/scripts/_internal_fvsolver_demo.py

This file was deleted.

10 changes: 4 additions & 6 deletions examples/scripts/fielddata_from_image_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

import numpy as np

import pyvcell.vcml as vc
from pyvcell._internal.simdata.mesh import CartesianMesh
from pyvcell.sim_results.var_types import NDArray3D, NDArray4D
from pyvcell.vcml import VcmlReader
from pyvcell.vcml.field import Field
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation as Solver


def create_sinusoid(
Expand All @@ -34,7 +32,7 @@ def create_sinusoid(

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

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

sim = app.add_sim(name="new_sim", duration=10.0, output_time_step=0.1, mesh_size=(20, 20, 20))
fields = Field.create_fields(bio_model=bio_model, sim=sim)
fields = vc.Field.create_fields(bio_model=bio_model, sim=sim)
print(fields)

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

# ---- add field data to the simulation

sim1_result = Solver(bio_model=bio_model, out_dir=sim_dir, fields=fields).run(sim.name)
sim1_result = vc.simulate(biomodel=bio_model, simulation=sim, fields=fields)
print([c.label for c in sim1_result.channel_data])
print(sim1_result.time_points[::11])
sim1_result.plotter.plot_slice_3d(time_index=0, channel_id="s0")
Expand Down
15 changes: 9 additions & 6 deletions examples/scripts/fielddata_from_sim_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
import tempfile
from pathlib import Path

from pyvcell.vcml import VcmlReader
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation as Solver
import pyvcell.vcml as vc

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

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

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

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

# ----- use field data from sim1_dir to set initial concentration of species "s0"
s0_mapping.init_conc = "vcField('sim1_dir','s0',0.0,'Volume') * vcField('sim1_dir','s1',0.0,'Volume')"
s0_mapping.init_conc = (
f"vcField('{sim1_result_dirname}','s0',0.0,'Volume') * vcField('{sim1_result_dirname}','s1',0.0,'Volume')"
)
s1_mapping.init_conc = "5.0"
# ---- re-run simulation and store in sim2_dir
# note that the solution of s0 draws from the data from sim1_dir
sim2_result = Solver(bio_model=bio_model1, out_dir=sim2_dir).run(sim.name)
sim2_result = vc.simulate(biomodel=bio_model1, simulation=sim.name)
sim2_result.plotter.plot_slice_3d(time_index=0, channel_id="s0")
sim2_result.plotter.plot_slice_3d(time_index=0, channel_id="s1")
sim2_result.plotter.plot_concentrations()
sim2_result.cleanup()
16 changes: 8 additions & 8 deletions examples/scripts/sysbio_class.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from pathlib import Path

import pyvcell.vcml as vcml
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation as VCSolver
import pyvcell.vcml as vc

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

Expand All @@ -17,20 +16,21 @@
A = 10
"""

biomodel = vcml.load_antimony_str(antimony_str)
biomodel = vc.load_antimony_str(antimony_str)

# create a 3D geometry
geo = vcml.Geometry(name="geo", origin=(0, 0, 0), extent=(10, 10, 10), dim=3)
geo = vc.Geometry(name="geo", origin=(0, 0, 0), extent=(10, 10, 10), dim=3)
# cell = geo.add_sphere(name="cell", radius=4, center=(5,5,5))
medium = geo.add_background(name="background")

# add an application to the biomodel
app = biomodel.add_application("app1", geometry=geo)
app.map_compartment(compartment=biomodel.model.get_compartment("cell"), domain=medium) # type: ignore[union-attr]
app.species_mappings = [
vcml.SpeciesMapping(species_name="A", init_conc="sin(x)"),
vcml.SpeciesMapping(species_name="B", init_conc="cos(x+y+z)"),
vc.SpeciesMapping(species_name="A", init_conc="sin(x)"),
vc.SpeciesMapping(species_name="B", init_conc="cos(x+y+z)"),
]
sim = app.add_sim(name="sim1", duration=10.0, output_time_step=0.5, mesh_size=(50, 50, 50))
results = VCSolver(bio_model=biomodel, out_dir=WORKSPACE_DIR / "sim1").run(simulation_name="sim1")
sim = app.add_sim(name="sim1", duration=2.0, output_time_step=0.5, mesh_size=(50, 50, 50))
results = vc.simulate(biomodel=biomodel, simulation="sim1")
results.plotter.plot_concentrations()
results.cleanup()
10 changes: 4 additions & 6 deletions examples/scripts/vcml_bunny_workflow.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import os
from pathlib import Path

from pyvcell.vcml import VcmlReader
from pyvcell.vcml.vcml_simulation import VcmlSpatialSimulation
import pyvcell.vcml as vc

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

bio_model = VcmlReader.biomodel_from_file(model_fp)
bio_model = vc.load_vcml_file(model_fp)
sims = [sim for app in bio_model.applications for sim in app.simulations]

# define editable spatial model and simulation instances
simulation = VcmlSpatialSimulation(bio_model=bio_model)
result = simulation.run(sims[0].name)
result = vc.simulate(biomodel=bio_model, simulation=sims[0].name)

print([c.label for c in result.channel_data])
result.plotter.plot_slice_2d(time_index=3, channel_name="s_in", z_index=result.zarr_dataset.shape[3] // 2)
result.plotter.plot_slice_3d(time_index=3, channel_id="s_in")
result.plotter.plot_concentrations()
simulation.cleanup()
result.cleanup()
Loading