Demo Notebook¶

This notebook demonstrates the basic use of the ModelBuilder class. It includes the following steps:

  1. Initializing the ModelBuilder with a model name.
  2. Adding objects and processes to the model.
  3. Connecting objects and processes.
  4. Validating the model.
  5. Saving the model to a JSON file.
  6. Visualizing the model as a graph.
In [1]:
# import the ModelBuilder
from multicell_utils.builder import ModelBuilder
In [2]:
# Build a template model programmatically
demo_model = ModelBuilder(model_name='demo')
demo_model.add_object(name='environment',
                      object_type='Universe',
                      contained_objects=['cell field', 'chemical field'])
demo_model.add_object(name='chemical field', object_type='Field')
demo_model.add_object(name='cell field', object_type='CellField', contained_objects=['cell1', 'cell2'])
demo_model.add_object(name='cell1', object_type='Cell')
demo_model.add_object(name='cell2', object_type='Cell')
demo_model.add_process(name='growth1', process_type='CellGrowth', participating_objects='cell1')
demo_model.add_process(name='growth2', process_type='CellGrowth', participating_objects='cell2')
demo_model.add_process(name='diffusion', process_type='Diffusion', participating_objects='chemical field')
demo_model.add_process(name='volume exclusion', process_type='VolumeExclusion', participating_objects=['cell1', 'cell2'])
In [3]:
# validate and save
demo_model.validate()
demo_model.save('demo_model.json')
Model saved to models/demo_model.json
In [4]:
# visualize the model as a graph
demo_model.graph()
Out[4]:
No description has been provided for this image
In [5]:
# print the current configuration
demo_model
Out[5]:
ModelBuilder({ 'id': 'model_000018',
  'name': 'demo',
  'objects': { 'cell field': { 'attributes': {},
                               'boundary_conditions': {},
                               'contained_objects': ['cell1', 'cell2'],
                               'type': 'CellField'},
               'cell1': { 'attributes': {},
                          'boundary_conditions': {},
                          'contained_objects': [],
                          'type': 'Cell'},
               'cell2': { 'attributes': {},
                          'boundary_conditions': {},
                          'contained_objects': [],
                          'type': 'Cell'},
               'chemical field': { 'attributes': {},
                                   'boundary_conditions': {},
                                   'contained_objects': [],
                                   'type': 'Field'},
               'environment': { 'attributes': {},
                                'boundary_conditions': {},
                                'contained_objects': [ 'cell field',
                                                       'chemical field'],
                                'type': 'Universe'}},
  'processes': { 'diffusion': { 'attributes': {},
                                'participating_objects': ['chemical field'],
                                'type': 'Diffusion'},
                 'growth1': { 'attributes': {},
                              'participating_objects': ['cell1'],
                              'type': 'CellGrowth'},
                 'growth2': { 'attributes': {},
                              'participating_objects': ['cell2'],
                              'type': 'CellGrowth'},
                 'volume exclusion': { 'attributes': {},
                                       'participating_objects': [ 'cell1',
                                                                  'cell2'],
                                       'type': 'VolumeExclusion'}}})
In [ ]: