morphforge - biophysical simulation in python · morphforge biophysical simulation in python mike...

44
morphforge Biophysical simulation in Python Mike Hull ([email protected]) University of Edinburgh University of Bristol FACETS Code Jam #4 Marseille 22-24 June 2010

Upload: others

Post on 20-May-2020

24 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

morphforgeBiophysical simulation in Python

Mike Hull ([email protected])University of Edinburgh

University of Bristol

FACETS Code Jam #4Marseille 22-24 June 2010

Page 2: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Outline

Introduction I My researchI MotivationI What is morphforge?

Morphforge I MorphologiesI SimulationsI Sweeps

From Here I WishlistI Collaborations

Page 3: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

About Me & My Work

I Collaboration with Alan Robert’s experimental lab

I Locomotive networks in Xenopus laevis tadpolesI Modelling:

I Small Networks ( 2000 neurons)I Hodgekin-Huxley type models of different neuron classesI Morphology of neurons important due to electrical coupling

Page 4: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

About Me & My Work

I Collaboration with Alan Robert’s experimental lab

I Locomotive networks in Xenopus laevis tadpoles

I Modelling:

I Small Networks ( 2000 neurons)I Hodgekin-Huxley type models of different neuron classesI Morphology of neurons important due to electrical coupling

Page 5: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

About Me & My Work

I Collaboration with Alan Robert’s experimental lab

I Locomotive networks in Xenopus laevis tadpolesI Modelling:

I Small Networks ( 2000 neurons)

I Hodgekin-Huxley type models of different neuron classesI Morphology of neurons important due to electrical coupling

Page 6: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

About Me & My Work

I Collaboration with Alan Robert’s experimental lab

I Locomotive networks in Xenopus laevis tadpolesI Modelling:

I Small Networks ( 2000 neurons)I Hodgekin-Huxley type models of different neuron classes

I Morphology of neurons important due to electrical coupling

Page 7: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

About Me & My Work

I Collaboration with Alan Robert’s experimental lab

I Locomotive networks in Xenopus laevis tadpolesI Modelling:

I Small Networks ( 2000 neurons)I Hodgekin-Huxley type models of different neuron classesI Morphology of neurons important due to electrical coupling

Page 8: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Previous Workflow (MSc Project)

I Initial channel modellingHandwritten .hoc & .mod files (NEURON)

I Effects of changing parametersCheetah generated .hoc & .mod files, scripts for building,re-import data as CSV for plotting

I · · · months passed · · ·I Network modelling

2 x YAML + XML files converted into another XML neuroncontaining network & output specification =⇒ cheetahgenerated .hoc & .mod files, Makefiles for building, re-importdata from csv as for plotting, caching of results in a directory.

I Time for a rethink ?!?!?

Page 9: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Previous Workflow (MSc Project)

I Initial channel modellingHandwritten .hoc & .mod files (NEURON)

I Effects of changing parametersCheetah generated .hoc & .mod files, scripts for building,re-import data as CSV for plotting

I · · · months passed · · ·I Network modelling

2 x YAML + XML files converted into another XML neuroncontaining network & output specification =⇒ cheetahgenerated .hoc & .mod files, Makefiles for building, re-importdata from csv as for plotting, caching of results in a directory.

I Time for a rethink ?!?!?

Page 10: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Previous Workflow (MSc Project)

I Initial channel modellingHandwritten .hoc & .mod files (NEURON)

I Effects of changing parametersCheetah generated .hoc & .mod files, scripts for building,re-import data as CSV for plotting

I · · · months passed · · ·

I Network modelling2 x YAML + XML files converted into another XML neuroncontaining network & output specification =⇒ cheetahgenerated .hoc & .mod files, Makefiles for building, re-importdata from csv as for plotting, caching of results in a directory.

I Time for a rethink ?!?!?

Page 11: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Previous Workflow (MSc Project)

I Initial channel modellingHandwritten .hoc & .mod files (NEURON)

I Effects of changing parametersCheetah generated .hoc & .mod files, scripts for building,re-import data as CSV for plotting

I · · · months passed · · ·

I Network modelling2 x YAML + XML files converted into another XML neuroncontaining network & output specification =⇒ cheetahgenerated .hoc & .mod files, Makefiles for building, re-importdata from csv as for plotting, caching of results in a directory.

I Time for a rethink ?!?!?

Page 12: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Previous Workflow (MSc Project)

I Initial channel modellingHandwritten .hoc & .mod files (NEURON)

I Effects of changing parametersCheetah generated .hoc & .mod files, scripts for building,re-import data as CSV for plotting

I · · · months passed · · ·I Network modelling

2 x YAML + XML files converted into another XML neuroncontaining network & output specification =⇒ cheetahgenerated .hoc & .mod files, Makefiles for building, re-importdata from csv as for plotting, caching of results in a directory.

I Time for a rethink ?!?!?

Page 13: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Motivation

Morphology I FACETS Code Jam ’09 - Phillip RautenbergI Morphology Reconstructions in BristolI DIADEM Project

Simulation I Large Parameter Sweeps

Page 14: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

What is morphforge?

Python Libraries for:

I Handling neural morphologies

I Defining & running biophysical simulations

I Analysing & storing simulation results

I Simplifying parameter sweeps

Page 15: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

What is morphforge?

Python Libraries for:

I Handling neural morphologies

I Defining & running biophysical simulations

I Analysing & storing simulation results

I Simplifying parameter sweeps

Page 16: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

What is morphforge?

Python Libraries for:

I Handling neural morphologies

I Defining & running biophysical simulations

I Analysing & storing simulation results

I Simplifying parameter sweeps

Page 17: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

What is morphforge?

Python Libraries for:

I Handling neural morphologies

I Defining & running biophysical simulations

I Analysing & storing simulation results

I Simplifying parameter sweeps

Page 18: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Morphologies

Page 19: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Morphologies

I Represent morphologies as a tree of cylinders

I Cylinders can be assigned regions and/or id’s.

Page 20: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Import/Export & Visualisation

I Create morphologies in Python

I Load and save .swc files.

I Load MorphML files

I Morphologies can be visualised using:I 2D projections in matplotlibI 3D visualisation in MayaVi

Page 21: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Import/Export & Visualisation

I Create morphologies in Python

I Load and save .swc files.

I Load MorphML files

I Morphologies can be visualised using:I 2D projections in matplotlibI 3D visualisation in MayaVi

Page 22: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Analysis & Manipulation

I General purpose data structure

I Minimal classes + loose coupling =⇒ Visitor pattern

I (Example of straightening tadpole)

Page 23: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Examples

Page 24: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Simulations

Page 25: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Simulation Overview

I Simulator Agnostic Description of:I NeuronsI Active membrane channels (HH-style)I Passive membrane propertiesI Voltage & current clampsI Recording electrodes (voltages, currents & membrane

properties)

I Handles units

I Simplification of plotting

I Basic trace analysis

I Caching simulation results

Page 26: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Simulation Overview

I Simulator Agnostic Description of:I NeuronsI Active membrane channels (HH-style)I Passive membrane propertiesI Voltage & current clampsI Recording electrodes (voltages, currents & membrane

properties)

I Handles units

I Simplification of plotting

I Basic trace analysis

I Caching simulation results

Page 27: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Simulation Overview

I Simulator Agnostic Description of:I NeuronsI Active membrane channels (HH-style)I Passive membrane propertiesI Voltage & current clampsI Recording electrodes (voltages, currents & membrane

properties)

I Handles units

I Simplification of plotting

I Basic trace analysis

I Caching simulation results

Page 28: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Simulation Overview

I Simulator Agnostic Description of:I NeuronsI Active membrane channels (HH-style)I Passive membrane propertiesI Voltage & current clampsI Recording electrodes (voltages, currents & membrane

properties)

I Handles units

I Simplification of plotting

I Basic trace analysis

I Caching simulation results

Page 29: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Simulation Overview

I Simulator Agnostic Description of:I NeuronsI Active membrane channels (HH-style)I Passive membrane propertiesI Voltage & current clampsI Recording electrodes (voltages, currents & membrane

properties)

I Handles units

I Simplification of plotting

I Basic trace analysis

I Caching simulation results

Page 30: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Neuron Specific

I Uses python-neuron interface

I Use existing .mod files directlyI Behind the scenes:

I Generate .hoc and .mod filesI Compiles .mod filesI Registers .mod files into neuron-instance

Page 31: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Simulation Examples

Page 32: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Sweeps & Bundles

Page 33: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Bundles

A wrapper around Simulation objects, in order to:

I Attach pre/post-simulation functors

I Encapsulate serialisation

Page 34: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Execute Pre-Sim Actions

Run Simulation::Simulate()

Execute Post-Sim Actions

Bundle::execute()

Bundledef load(...):def save(...):

def addPreFunctor(...):def addPostSimFunctor(...):

def execute(...):

Simulationdef addNeuron(...): def addCurrentClamp(...):def addVoltageClamp(...):

def recordVoltage(...):def recordCurrent(...):

def Simulate(...):

A 'Bundle' wraps

a 'Simulation'

Page 35: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Parameter Sweeps

A simple mechanism for distributing simulations over XML-RPChas been written; comprising a BundleServer and BundleClient;

I the user needs to write a function returning a list ofsimulation-bundles to run, for the BundleServer.

I for example, this could have a post-sim functor that analysesthe output voltage traces and writes a row to a DB somewhere.

I The BundleServer is started on a single machine and acts as adaemon, keeping a track of which bundles have been handedout to which clients.

I The BundleClient can be started on many clients. Each clientcontacts the server, requests n Bundles, runs them, notifiesthe server about whether bundles ran successfully or not, thenrequests more bundles....

Page 36: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Parameter Sweeps

A simple mechanism for distributing simulations over XML-RPChas been written; comprising a BundleServer and BundleClient;

I the user needs to write a function returning a list ofsimulation-bundles to run, for the BundleServer.

I for example, this could have a post-sim functor that analysesthe output voltage traces and writes a row to a DB somewhere.

I The BundleServer is started on a single machine and acts as adaemon, keeping a track of which bundles have been handedout to which clients.

I The BundleClient can be started on many clients. Each clientcontacts the server, requests n Bundles, runs them, notifiesthe server about whether bundles ran successfully or not, thenrequests more bundles....

Page 37: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Parameter Sweeps

A simple mechanism for distributing simulations over XML-RPChas been written; comprising a BundleServer and BundleClient;

I the user needs to write a function returning a list ofsimulation-bundles to run, for the BundleServer.

I for example, this could have a post-sim functor that analysesthe output voltage traces and writes a row to a DB somewhere.

I The BundleServer is started on a single machine and acts as adaemon, keeping a track of which bundles have been handedout to which clients.

I The BundleClient can be started on many clients. Each clientcontacts the server, requests n Bundles, runs them, notifiesthe server about whether bundles ran successfully or not, thenrequests more bundles....

Page 38: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Parameter Sweeps

A simple mechanism for distributing simulations over XML-RPChas been written; comprising a BundleServer and BundleClient;

I the user needs to write a function returning a list ofsimulation-bundles to run, for the BundleServer.

I for example, this could have a post-sim functor that analysesthe output voltage traces and writes a row to a DB somewhere.

I The BundleServer is started on a single machine and acts as adaemon, keeping a track of which bundles have been handedout to which clients.

I The BundleClient can be started on many clients. Each clientcontacts the server, requests n Bundles, runs them, notifiesthe server about whether bundles ran successfully or not, thenrequests more bundles....

Page 39: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Parameter Sweeps Results Examples

I Modelling the effects of conductances on firing behaviour

I Na, Ca, Kf, Ks, Lk channels + injected current

I 110,000 simulations run in a night over 30 computers

Page 40: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Parameter Sweeps Results Examples

Single Spiking Neurons

Multiple Spiking Neurons

Ambiguous Neurons

Non-Repolarising Neurons

Overly Excitable Neurons

Kf Conductance Density Multiplier

Ks C

onducta

nce D

ensit

y M

ult

iplier

1.0

2.0

0.0

1.00.0 2.0

Page 41: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

From Here

Page 42: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

WishList

High Priority I Interface for neural connectivityI Documentation & testing

Low Priority I Summary pdfs/tex outputI Loading *ML formats

Page 43: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Collaboration

I Code is in a mercurial repository - [email protected]

I To be made public (advice on open licenses)

I Is this useful to other people?

I Integration with other open-source tools

I Keen to find collaboration.....

Page 44: morphforge - Biophysical simulation in Python · morphforge Biophysical simulation in Python Mike Hull (s0897465@sms.ed.ac.uk) University of Edinburgh University of Bristol FACETS

Acknowledgements

I Juan Reyero (Magnitude Units Package)

I Enthought (MayaVi Package)

I Everyone working on scientific python libraries!

I NEURON & Python Interface

I Organisers of Code Jams

I Supervisors: Alan Roberts & David Willshaw

Thankyou!