Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington,...

73
Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier

Transcript of Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington,...

Page 1: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Biological and Biomedical Modeling Using CompuCell3D

Tutorial

Indiana University

Bloomington, IndianaMaciej Swat, James Glazier

Page 2: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Tutorial Goals

• Introduce Glazier Graner Hogeweg Model (GGH) aka Cellular Potts Model (CPM) and its potential applications

• Introduce CompuCell3D – GGH based Modeling Environment

• Teach how to design, build and run GGH models using CompuCell3D

Recommended but not required:

Laptop computer with MS Windows, OS X or latest Ubuntu/Debian Linux

Page 3: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Timeline

• GGH model introduction – 30 minutes

• Introduction to CompuCell3D – 40 minutes

• Demo of CompuCell models - 30 minutes

• Hands on tutorials – 120 minutes

Page 4: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Demo Simulations

Page 5: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Somitogenesis

In most animal species, the anteroposterior (AP) body axis is generated by the formation of repeated structures: segments. The brain, thorax and limbs are formed through segmentation.

In vertebrates segmentation, mesodermal structures called somites gives rises to the skeletal muscles, occipital bone, vertebrae, ribs, some dermis and vascular endothelium.

Page 6: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Dictyostelium morphogenesis Slug Formation

(from Nick Savill)

Page 7: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Contact Inhibition of Motility

“Context-dependent” effect of VEGF-A (Vascular-endothelial growth-factor A: stimulates vasculogenesis)

• VE-Cadherin clusters at adherens junctions between endothelial cells

• VE-Cadherin-binding → dephosporylation of VEGFR-2

• VEGF-A signaling:

– in presence of VE-Cadherin: AKT/PKB ↑

• cell survival

– In absence of VE-Cadherin: ERK/MAPK ↑• Actin polymerization: cell motility / filopodia

In model: suppress chemotaxis at cell interfaces

Page 8: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

VasculogenesisRoeland Merks, Abbas Shirinifard

Page 9: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Vascular System Development in 3D Abbas Shirinifard

Page 10: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

GGH Model - an Introduction

Context

• How does the pattern of gene expression act through physical and chemical mechanisms to result in the structures we observe? Genetics is just the beginning.

• Same mechanisms occur repeatedly in different developmental examples.

• Begin by using phenomenological descriptions. In many cases very complex pathways have fairly simple effects under conditions of interest.

Page 11: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Main Processes in Development

• Cell Differentiation

• Cell Polarization

• Cell Movement

• Cell Proliferation and Death

• Cellular Secretion and Absorption

Page 12: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Key Questions Concerning Differentiation

• What are the types of cells in a given process?• What signals cause cells to change types?

– Due to diffusible substances?– Due to Cell-Cell Contacts?– Due to Cell History?– Due to Cell-Extracellular Matrix Contact?

• What are the thresholds for these transitions?• How do these signals interact?• What are the rates or probabilities of these

transitions?

Page 13: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cell Movement and Adhesion•Cells Move Long Distances During Development.

•Move by Protruding and Retracting Filopodia or Lamellipodia (Leading Edge)

•Shape Changes During Movement May be Random or Directed.

•Move By Sticking Selectively to Other Cells (Differential Adhesion)

•Move By Sticking to Extracellular Material (Haptotaxis)

•Move By Following External Chemical Gradients (Chemotaxis)

•Can also have Bulk Movement:

• Secretion of ECM

• Differential Cell Division

• Oriented Cell Division

Chemotaxis:

Play Movies

Page 14: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

• Cells of a given type have characteristic adhesion strengths to cells of the same or different types.

• The cells comprising an aggregate are motile.

• The equilibrium configuration of cells minimizes their interfacial energy summed over all the adhesive contacts in the aggregate.

Cells Adhesion

Page 15: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Key Questions

• How strongly do cells of one type adhere to cells of another type?

• How strongly do cells of a given type adhere to ECM?

• How does cell adhesion change in time?

Page 16: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cells Send and Respond to Signals—Chemotaxis (Haptotaxis)

• Cell moves up (down) a gradient of a diffusible (non-diffusible) chemical.

• Cell senses diffusible chemicals through their receptors on surface.

• Intracellular signal transduction and cytoskeleton rearrangement.

Page 17: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Regular Chemotaxis Gunther Gerisch (JHU)

Page 18: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Key Questions

• How do cells move in response to chemical signals in their environment?

• How do cells change type in response to these signals?

Page 19: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cell Growth and Death

• What signals cause cells to grow?

• What signals cause cells to die?

(In many cases very little cell growth or death during a given developmental phase)

Page 20: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Secretion and Absorption

• What chemicals do cells secrete and absorb?

• If they diffuse, how rapidly do these chemicals diffuse?

• If they do not diffuse, what are their mechanical properties?

• How stable are they (what is their decay rate)?

Page 21: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Feedback Loops

• Not Simply: SignalDifferentiationPattern (Known as Prepatterning).

• Cells Create Their Own Environment, by Moving and Secreting New Signals, so Signaling Feeds Back on Itself.

• Hence Self-Organization and Robustness.

Page 22: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cell-Centered Modeling• Genetics primarily drives the individual cell

– Response to extracellular signals; secretion of signaling agents and extracellular matrix proteins.

• To understand how genetics drive multicellular patterning, distinguish two questions:– How does genetics drive cell

phenomenology?– How does cell phenomenology drive

multicellular patterning?

Page 23: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Why a Cell Level Model?

• Most mammalian cells are fairly limited in their behaviors. They can:– Grow– Divide– Change Shape– Move Spontaneously– Move in Response to External Cues (Chemotaxis, Haptotaxis)– Stick (Cell Adhesion)– Absorb External Chemicals (Fields)– Secrete External Chemicals– Exert Forces– Change their Local Surface Properties– (Send Electrical Signals)

A long list, but not compared to 1010 gene product interactions.Many cells have relatively simple phenomenological behaviors

most of the time.

Page 24: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Physical and Mathematical Background

• The Glazier-Graner-Hogeweg Model (GGH) is a Metropolis-Type Lattice-Based Pseudo-Hamiltonian Model

• Monte Carlo Methods– Metropolis Algorithm (StatisticalKinetic)

• Pseudo-Hamiltonian Lattice-Based Methods– Ising Model

Page 25: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

• Monte Carlo Methods Use Statistical Physics Techniques to Solve Problems that are Difficult or Inconvenient to Solve Deterministically.

• Two Basic Applications:– Evaluation of Complex Multidimensional

Integrals (e.g. in Statistical Mechanics) [1950s]

– Optimization of Problems where the Deterministic Problem is Algorithmically Hard (NP Complete—e.g. the Traveling Salesman Problem) [1970s].

• Both Applications Important in Biology.

Page 26: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

GGH Model Basics

Lattice based model where cells are represented as spatially extended objects occupying several lattice sites

x 20

Experiment Mathematical/Computer Representation

Page 27: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cell Id=20 Type Id=1Cell Id=21 Type Id=2

Cell Id=25 Type Id=4 Cell Id=23 Type Id=3

(x) –denotes id of the cell occupying position x. All pixels pointed by arrow have same cell id , thus they belong to the same cell

((x)) denotes cell type of cell with id (x). In the picture above blue and yellow cells have different cell types and different cell id. Arrows mark different cell types

Page 28: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cell motility – GGH dynamics

GGH is Monte Carlo algorithm where cells randomly are trying to extend their boundaries by overwriting neighboring pixels. This results in volume increase of expanding cell and volume decrease for cell whose pixel is being overwritten

Spin copy “blue” pixel (newCell) replaces “yellow” pixel (oldCell)

Change pixel

Page 29: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Not All Pixel Copy Attempts Are Created Equal – Energy of Cellular System

( ( )), ( ( ')) ( ), ( '), '

2 2

(1 )

( ) ( )

...

x x x xx x

s v

chem hapt

E J

s S v V

E E

•Metropolis algorithm: probability of configuration change

GGH Model is based on energy minimization using Metropolis algorithm. Most biological interactions between cells are encapsulated in the Effective Energy, E.

•H is generally the sum of many separate terms.

•Each term in H encapsulates a single biological mechanism.

•Additional Cell Properties described as Constraints.

Page 30: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

•The key to the GGH is its use of an Effective Energy or Hamiltonian, H, and Modified Metropolis Dynamics to provide the Cell Lattice Dynamics.•This Dynamics means that cells fluctuate, with an Intrinsic Motility T, representing their cytoskeletally-induced motility.•The Cell Lattice evolves at any time to gradually reduce the Effective Energy with a velocity proportional to the gradient of the Energy (Perfect Damping).

acceptance

1 if

if H Y

T

H YP H

e H Y

Y is a Dissipation Threshold.

Also introduce concept of Copy or Protrusion Direction , which May Affect the Acceptance Probability.

For a given H, the Acceptance Probability is:

( ( )), ( ( ')) ( ), ( '), '

(1 )x x x xx x

H J

Page 31: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

invalid attempt valid attempt accept

valid attempt accept

valid attempt accept

valid attempt

reject

Page 32: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Constraints

• Most Important Constraints:– Cell Volume– Cell Surface Area

• Additional Examples:– Cell Elongation– Viscous Drag

Page 33: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Volume Constraints

• Most Cells (except Generalized Cells representing fluid media) have defined volumes.

• Provides an easy way to implement Cell growth:

• And Cell Death:

2targetvolumevolume VVH

state) cell state, system(

dttarget f

dV

0target V

Page 34: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Surface Constraints• Many Cells also have defined membrane areas.

• The ratio: (d=dimension)

controls the Cell’s general shape:

• Small R means the Cell is floppy (underinflated basketball)

• Large R means the Cell is spherical and rigid.

2targetsurfacesurface SSH

1

1

1

target

target

d

d

S

VR

Page 35: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cell sorting2

( ( )), ( ( ')) ( ), ( '), '

(1 ) ( )x x x x vx x

E J v V

Page 36: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Field Equations• Most Fields evolve via diffusion, secretion and

absorption and cells and by decay.

• Sometimes we couple two or more Fields via Reaction-Diffusion Equations of Form:

iAiSiCiCDt

iCcccc

2

Diffusion Decay Secretion Absorption

iAiSiCiCDCCgt

iC

iAiSiCiCDCCft

iC

cccc

cccc

2222

1111

222

212

112

211

),(

),(

Page 37: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

In GGH we can couple evolving fields to cell properties/behaviors

•Chemotaxis/Haptotaxis

•Chemical Concentration Dependent Cell Growth rate - mitosis

•Chemical Concentration Dependent Cell Differentiation

Page 38: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Chemotaxis Term – Most Basic Form

))()(( sourcendestinatiochem xcxcE

If concentration at the spin-copy destination pixel (c(xdestination)) is higher than concentration at the spin-copy source (c(xsource)) AND is positive then E is negative and such spin copy will be accepted. The cell chemotacts up the concentration gradient

x

C(x)

Lower concentrationHigher concentration

Chemorepulsion can be obtained by making negative

Page 39: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Chemotaxis – Example CompuCell3D simulation

Page 40: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

What Is CompuCell3D?

1. CompuCell3D is a modeling environment used to build, test, run and visualize GGH-based simulations

2. CompuCell3D has built-in scripting language (Python) that allows users to quite easily write extension modules that are essential for building sophisticated biological models.

3. CompuCell3D thus is NOT a specialized software

4. Running CompuCell3D simulations DOES NOT require recompilation

5. CompuCell3D model is described using CompuCell3D XML syntax and in the case of using Python language , a Python script(s)

6. CompuCell3D platform is distributed with a GUI front end – CompuCell Player or simply Player. The Player provides 2- and 3-D visualization capabilities.

7. Models developed by one CompuCell3D user can be “replayed” by another user regardless the operating system/hardware on which CompuCell is installed.

8. CompuCell3D is a cross platform application that runs on Linux/Unix, Windows, Mac OSX

Page 41: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Why Use CompuCell3D? What Are the Alternatives?

1. CompuCell3D allows users to set up and run their simulations within minutes, maybe hours. A typical development of a specialized GGH code takes orders of magnitudes longer time.

2. CompuCell3D simulations DO NOT need to be recompiled. If you want to change parameters (in XML or Python scripts) or logic (in Python scripts) you just make the changes and re-run the simulation. With hand-compiled simulations there is much more to do. Recompilation of every simulation is also error prone and often limits users to those who have significant programming background.

3. CompuCell3D is actively developed , maintained and supported. On www.compucell3d.org website users can download manuals, tutorials and developer documentation. CompuCell3D has approx. 10 releases each year – some of which are bug-fix releases and some are major

4. CompuCell3D has many users around the world. This makes it easier to collaborate or exchange modules and results saving time spent on developing new model.

5. The Biocomplexity Institute organizes training workshops and mentorship programs. Those are great opportunities to visit Bloomington and learn biological modeling using CompuCell3D. For more info see www.compucell3d.org

Page 42: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Demo Simulations

Page 43: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

CompuCell3D Architecture

KernelRuns Metropolis Algorithm

PluginsCalculate change

in energy

PDE Solvers

Python InterpreterBiologo Code Generator

Visualization, Steering,User Interface

Lattice monitoring

Object oriented implementation in C++ and Python

Page 44: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

CompuCellPlayer

CompuCell3D Kernel

Plugins

Python

Typical “Run-Time” Architecture of CompuCell

CompuCell can be run in a variety of ways:

•Through the Player with or without Python interpreter

•As a Python script

•As a stand alone computational kernel+plugins

Page 45: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

CompuCell3D terminology

1. Pixel-copy attempt is an event where program randomly picks a lattice site in an attempt to copy its value to a neighboring lattice site.

2. Monte Carlo Step (MCS) consists of series pixel-copy attempts. Usually the number of pixel copy-attempts in single MCS is equal to the number of lattice sites, but this is can be customized

3. CompuCell3D Plugin is a software module that either calculates an energy term in a Hamiltonian or implements action in response to pixel copy (lattice monitors). Note that not all spin-copy attempts will trigger lattice monitors to run.

4. Steppables are CompuCell3D modules that are run every MCS after all pixel-copy attempts for a given MCS have been exhausted. Most of Steppables are implemented in Python. Most cell behavior alterations are done in steppables

5. Steppers are modules that are run for those pixel-copy attempts that actually resulted in energy calculation. They are run regardless whether actual pixel-copy occurred or not. For example cell mitosis is implemented in the form of stepper.

6. Fixed Steppers are modules that are run every pixel-copy attempt.

Page 46: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Pixel copy - “blue” pixel (newCell) replaces “yellow” pixel (oldCell)

Change pixel

MCS 21

10000 pixel-copy attempts

MCS 22 MCS 23 MCS 24

10000 pixel-copy attempts

10000 pixel-copy attempts

10000 pixel-copy attempts

Run

Steppables

Run

Steppables

Run

Steppables

100x100x1 square lattice = 10000 lattice sites (pixels)

CompuCell3D Terminology – Visual Guide

Page 47: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Nearest neighbors in 2D and their Euclidian distances from the central pixel

1

1

1

1

2

22

2

3

3

3

3

4

4

4

4 4

4

4

41

1

11

1

1

2 2

2

22

2

3

3

3

3

3

3

4

4

444

4

4

4

44 4

4

2D Square Lattice 2D Hexagonal Lattice

Neighbor Order

Number of Neighbors

Euclidian Distance

Number of Neighbors

Euclidian Distance

1 4 1 6

2 4 6

3 4 2 6

4 8 12

3/2

2 3/6

3/8

14 / 35

Page 48: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Your First CompuCell3D Simulation – Cell Sorting

• Users can describe their simulations using XML, Python, or both XML and Python

• Most recent version (development version) of CompuCell3D has Java interface => support of many scripting languages through Java ScriptEngine

2( ( )), ( ( ')) ( ), ( ')

, '

(1 ) ( )x x x x vx x

E J v V

Page 49: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

def configureSimulation(sim): import CompuCell import CompuCellSetup ppd=CompuCell.PottsParseData() ppd.Steps(20000) ppd.Temperature(5) ppd.NeighborOrder(2) ppd.Dimensions(CompuCell.Dim3D(100,100,1))

ctpd=CompuCell.CellTypeParseData() ctpd.CellType("Medium",0) ctpd.CellType("Condensing",1) ctpd.CellType("NonCondensing",2) cpd=CompuCell.ContactParseData() cpd.Energy("Medium","Medium",0) cpd.Energy("NonCondensing","NonCondensing",16) cpd.Energy("Condensing","Condensing",2) cpd.Energy("NonCondensing","Condensing",11) cpd.Energy("NonCondensing","Medium",16) cpd.Energy("Condensing","Medium",16)

vpd=CompuCell.VolumeParseData() vpd.TargetVolume(25.0) vpd.LambdaVolume(1.0)

Configure lattice and general simulation parameters

Tell Compucell3D what cell types you will use. Remember to list Medium with type id 0

...)1(...',

)'(),())'(()),(( xx

xxxxJE

Type NameType Id

...)(... 2 VvE v

acceptance

1 if

if H Y

T

H YP H

e H Y

Page 50: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

bipd=CompuCell.BlobInitializerParseData() region=bipd.Region() region.Center(CompuCell.Point3D(50,50,0)) region.Radius(40) region.Types("Condensing") region.Types("NonCondensing") region.Width(5)

#remember to register ParseData

CompuCellSetup.registerPotts(sim,ppd)

CompuCellSetup.registerPlugin(sim,ctpd) CompuCellSetup.registerPlugin(sim,cpd) CompuCellSetup.registerPlugin(sim,vpd)

CompuCellSetup.registerSteppable(sim,bipd)

Register lattice configuration section

Register energy functions and cell type specification

Register initial configuration steppable

Width of a single cell

Cell types use to fill region

Specifying initial configuration of cells

Register ParseData objects

Page 51: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

def configureSimulation(sim): import CompuCell import CompuCellSetup ppd=CompuCell.PottsParseData() ppd.Steps(20000) ppd.Temperature(5) ppd.NeighborOrder(2) ppd.Dimensions(CompuCell.Dim3D(100,100,1))

ctpd=CompuCell.CellTypeParseData() ctpd.CellType("Medium",0) ctpd.CellType("Condensing",1) ctpd.CellType("NonCondensing",2) cpd=CompuCell.ContactParseData() cpd.Energy("Medium","Medium",0) cpd.Energy("NonCondensing","NonCondensing",16) cpd.Energy("Condensing","Condensing",2) cpd.Energy("NonCondensing","Condensing",11) cpd.Energy("NonCondensing","Medium",16) cpd.Energy("Condensing","Medium",16)

vpd=CompuCell.VolumeParseData() vpd.LambdaVolume(1.0) vpd.TargetVolume(25.0) bipd=CompuCell.BlobInitializerParseData() region=bipd.Region() region.Center(CompuCell.Point3D(50,50,0)) region.Radius(40) region.Types("Condensing") region.Types("NonCondensing") region.Width(5)

#remember to register ParseData

CompuCellSetup.registerPotts(sim,ppd) CompuCellSetup.registerPlugin(sim,ctpd) CompuCellSetup.registerPlugin(sim,cpd) CompuCellSetup.registerPlugin(sim,vpd) CompuCellSetup.registerSteppable(sim,bipd)

Complete listing

35 lines of straightforward code vs at least 1000 lines of C++/Java/Fortran code

Page 52: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

import sysfrom os import environimport stringsys.path.append(environ["PYTHON_MODULE_PATH"]) import CompuCellSetup

sim,simthread = CompuCellSetup.getCoreSimulationObjects()

configureSimulation(sim)

CompuCellSetup.initializeSimulationObjects(sim,simthread)

from PySteppables import SteppableRegistrysteppableRegistry=SteppableRegistry()

CompuCellSetup.mainLoop(sim,simthread,steppableRegistry)

To finish the simulation code - reuse boiler-plate code from CompuCell3D examples

Page 53: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Opening a Python-based simulation in the Player

Go to File->Open Simulation ; Click Python script “Browse…” button to select python script. Do not forget to check “ Run Python script” check-box!

Page 54: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Cell-sorting in XML - cellsort_2D.xml

<CompuCell3D> <Potts> <Dimensions x="100" y="100" z="1"/> <Steps>10000</Steps> <Temperature>2</Temperature></Potts>

<Plugin Name="CellType"> <CellType TypeName="Medium" TypeId="0"/> <CellType TypeName=“Light" TypeId="1"/> <CellType TypeName=“Dark" ="2"/> </Plugin>

<Plugin Name="Volume"> <TargetVolume>25</TargetVolume> <LambdaVolume>1.0</LambdaVolume></Plugin>

<Plugin Name="Surface"> <TargetSurface>21</TargetSurface> <LambdaSurface>0.5</LambdaSurface> </Plugin>

<Plugin Name="Contact"> <Energy Type1="Medium" Type2="Medium">0 </Energy> <Energy Type1="Light" Type2="Medium">16 </Energy> <Energy Type1="Dark" Type2="Medium">16 </Energy> <Energy Type1="Light" Type2="Light">16 </Energy> <Energy Type1="Dark" Type2="Dark">2.0 </Energy> <Energy Type1="Light" Type2="Dark">11 </Energy> </Plugin>

<Steppable Type="BlobInitializer"> <Region> <Radius>30</Radius> <Center x="40" y="40" z="0"/> <Gap>0</Gap> <Width>5</Width> <Types>Dark,Light</Types> </Region></Steppable>

</CompuCell3D>

Coding the same simulation in C/C++/Java/Fortran would take you at least 1000 lines of code…

Page 55: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Exercise 1

• Modify simulation so that cells produce checkerboard pattern

Page 56: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Crawling Neutrophil Chasing Bacterium

Richard Firtel (UCSD)

Page 57: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Simulation Building Blocks in CompuCell3D

• Four Cell Types: Bacterium, Macrophage, Wall, Red Blood Cells

• Assumption 1:Bacterium secretes chemoattractant (call it ATTR) which diffuses and Macrophage responds to the ATTR gradient

• Assumption 2: Macrophage secretes chemorepellant (REPL) which affects Bacterium

Page 58: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Initial configuration

Page 59: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

ppd=CompuCell.PottsParseData() ppd.Steps(20000) ppd.Temperature(15) ppd.Flip2DimRatio(1.0) ppd.Dimensions(CompuCell.Dim3D(100,100,1)) ctpd=CompuCell.CellTypeParseData() ctpd.CellType("Medium",0) ctpd.CellType("Bacterium",1) ctpd.CellType("Macrophage",2) ctpd.CellType("Wall",3,True) cpd=CompuCell.ContactParseData() cpd.Energy("Medium","Medium",0) cpd.Energy("Macrophage","Macrophage",15) cpd.Energy("Macrophage","Medium",8) cpd.Energy("Bacterium","Bacterium",15) cpd.Energy("Bacterium","Macrophage",15) cpd.Energy("Bacterium","Medium",8) cpd.Energy("Wall","Wall",0) cpd.Energy("Wall","Medium",0) cpd.Energy("Wall","Bacterium",50) cpd.Energy("Wall","Macrophage",50) cpd.NeighborOrder(2)

vpd=CompuCell.VolumeParseData() vpd.LambdaVolume(15.0) vpd.TargetVolume(25.0) spd=CompuCell.SurfaceParseData() spd.LambdaSurface(4.0) spd.TargetSurface(20.0)

Make Wall cells frozen

Page 60: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

chpd=CompuCell.ChemotaxisParseData() chfield=chpd.ChemicalField() chfield.Source("FastDiffusionSolver2DFE") chfield.Name("ATTR") chbt=chfield.ChemotaxisByType() chbt.Type("Macrophage") chbt.Lambda(2.0)

fdspd=CompuCell.FastDiffusionSolver2DFEParseData() df=fdspd.DiffusionField() diffData=df.DiffusionData() secrData=df.SecretionData() diffData.DiffusionConstant(0.1) diffData.DecayConstant(0.001) diffData.FieldName("ATTR") diffData.DoNotDiffuseTo("Wall") secrData.Secretion("Bacterium",200) pifpd=CompuCell.PIFInitializerParseData() pifpd.PIFName("bacterium_macrophage_2D_wall.pif")

CompuCellSetup.registerPotts(sim,ppd) CompuCellSetup.registerPlugin(sim,ctpd) CompuCellSetup.registerPlugin(sim,vpd) CompuCellSetup.registerPlugin(sim,spd) CompuCellSetup.registerPlugin(sim,chpd) CompuCellSetup.registerSteppable(sim,pifpd) CompuCellSetup.registerSteppable(sim,fdspd)

Diffusion field ATTR

Diffusion and decay constants

Preventting ATTR from entering Wall cels

Bacterium secretion constant

Chemotaxis: choosing PDE solver and chemical field name

Setting chemotacting type and chemotaxis strength

Page 61: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Exercise 2 - Making simulation look more realistic

• Introduce moving Red Blood Cells instead of rigid walls

• Make Bacterium small and Macrophage large

• Introduce few Macrophages and Bacteria

• Introduce new chemorepellant (REP) secreted by Macrophage and afecting bacterium (Exercise 2a)

Page 62: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Simulation Screenshots

Page 63: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Using PIFInitilizer

Use PIFInitializer to create sophisticated initial conditions. PIF file allows you to compose cells from single pixels or from larger rectangular blocks

The syntax of the PIF file is given below:

Cell_id Cell_type x_low x_high y_low y_high z_low z_high

Example (file: amoebae_2D_workshop.pif):

0 amoeba 10 15 10 15 0 0

This will create rectangular cell with x-coordinates ranging from 10 to 15 (inclusive), y coordinates ranging from 10 to 15 (inclusive) and z coordinates ranging from 0 to 0 inclusive.

Python syntax:

pifpd=CompuCell.PIFInitializerParseData() pifpd.PIFName(“amoebae_2D_workshop.pif")

0,0

Page 64: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Let’s add another cell:

Example (file: amoebae_2D_workshop.pif):

0 Amoeba 10 15 10 15 0 01 Bacteria 35 40 35 40 0 0

Notice that new cell has different cell_id (1) and different type (Bacterium)

Let’s add pixels and blocks to the two cells from previous example:

Example (file: amoebae_2D_workshop.pif):

0 Amoeba 10 15 10 15 0 01 Bacteria 35 40 35 40 0 00 Amoeba 16 16 15 15 0 01 Bacteria 35 37 41 45 0 0

To add pixels, start new pif line with existing cell_id (0 or 1 here ) and specify pixels.

Page 65: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

This is what happens when you do not reuse cell_id

Example (file: amoebae_2D_workshop.pif):

0 Amoeba 10 15 10 15 0 01 Bacteria 35 40 35 40 0 00 Amoeba 16 16 15 15 0 02 Bacteria 35 37 41 45 0 0

Introducing new cell_id (2) creates new cell.

PIF files allow users to specify arbitrarily complex cell shapes and cell arrangements. The drawback is, that typing PIF file is quite tedious task and , not recommended. Typically PIF files are created using scripts.

In the future release of CompuCell3D users will be able to draw on the screen cells or regions filled with cells using GUI tools. Such graphical initialization tools will greatly simplify the process of setting up new simulations. This project has high priority on our TO DO list.

Page 66: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

PIFDumper - yet another way to create initial condition

PIFDumper is typically used to output cell lattice every predefined number of MCS. It is useful because, you may start with rectangular cells, “round them up” by running CompuCell3D , output cell lattice using PIF dumper and reload newly created PIF file using PIFInitializer.

pifpd=CompuCell.PIFDumperParseData() pifpd.PIFName(“amoebae.100.pif") pifpd.frequency=100

Above syntax tells CompuCell3D to store cell lattice as a PIF file every 100 MCS.

The files will be named amoebae.100.pif , amoebae.200.pif etc…

pifpd=CompuCell.PIFInitializerParseData() pifpd.PIFName(“amoebae.100.pif")

To reload file , say amoebae.100.pif use already familiar syntax:

Page 67: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Writing Python Extension Modules for CompuCell3D

• Most of CompuCell3D simulations will require certain level of customization.

• Using “traditional” approach , this would be done in C++/Java/Fortran and would require recompilation

• CompuCell3D allows users to conveniently develop their own extension modules using Python that DO NOT NEED to be recompiled

• Typically users develop steppable modules (called every MCS) which alter cellular behavior as simulation progresses.

Page 68: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

class InfoPrinterSteppable(SteppablePy):   def __init__(self,_simulator,_frequency=10):      SteppablePy.__init__(self,_frequency)      self.simulator=_simulator      self.inventory=self.simulator.getPotts().getCellInventory() self.cellList=CellList(self.inventory)

 def step(self,mcs): for cell in self.cellList:         print "CELL ID=",cell.id, " CELL TYPE=",\ cell.type," volume=",cell.volume

Printing information about all the cells present in the simulation

Class constructor – used to initialize Steppable object.

Creating iterable cell inventory

Iterating through cell inventory and printing basic cell information

Code of the constructor is a boiler-plate code and typically is reused without any alterations in many steppables.

Page 69: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

class InfoPrinterSteppable(SteppablePy)………… #include earlier codedef configureSimulation(sim)……………………….. #include earlier code

#import useful modulesimport sysfrom os import environfrom os import getcwdimport string#setup search patthssys.path.append(environ["PYTHON_MODULE_PATH"])sys.path.append(getcwd()+"/demo") #add search path import CompuCellSetup

sim,simthread = CompuCellSetup.getCoreSimulationObjects()

CompuCellSetup.initializeSimulationObjects(sim,simthread)

#Add Python steppables heresteppableRegistry=CompuCellSetup.getSteppableRegistry()

infoPrinterSteppable=InfoPrinterSteppable(_simulator=sim,_frequency=10)steppableRegistry.registerSteppable(infoPrinterSteppable)

CompuCellSetup.mainLoop(sim,simthread,steppableRegistry)

Page 70: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Info Printer results

Page 71: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Exercise 3

• Enhance cell-sorting simulation by writing a Python steppable that at the beginning of the simulation assigns Type ID=1 to cells in the upper half of the lattice and Type ID=2 to cells in the lower half of the lattice.

Hint: you have to includecompd=CompuCell.CenterOfMassParseData()To ensure that CompuCell3D updates COM position for each cell:centerOfMassX = cell.xCM / float(cell.volume)

Page 72: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Exercise 4

• For cell-sorting simulation, write Python Steppable that every 100 MCS switches cell types 2 -> 1 and 1->2

Page 73: Biological and Biomedical Modeling Using CompuCell3D Tutorial Indiana University Bloomington, Indiana Maciej Swat, James Glazier.

Summary

• CompuCell3D is indeed environment rather than specialized program

• It can be extended by writing modules in Python, C++, Java.

• Actively developed and supported

• Annual Training Workshops in Bloomington, Indiana

• www.compucell3d.org