Tutorial 1 (Species Basics)

This is a tutorial for E-Cell4. Here, we introduce how to use Species.

Import the core library, first:


In [1]:
from ecell4.core import *

This enables Species class.


In [2]:
print(Species("A") == Species("B"), Species("A") == Species("A"))


False True

A Species can be translated into an unique string, named "serial":


In [3]:
print(Species("A").serial(), Species("B").serial())


A B

A Species can have attributes as a pair of strings.


In [4]:
sp = Species("A")
sp.set_attribute("radius", "0.0025")
sp.set_attribute("D", "1.0")
print(sp.has_attribute("radius"), sp.has_attribute("spam"))
print(sp.get_attribute("radius"), sp.get_attribute("D"))
sp.remove_attribute("radius")
print(sp.has_attribute("radius"))
del sp


True False
0.0025 1.0
False

Tips: Especially for "radius" and "D", A Species accepts these attributes at the instantiation:


In [5]:
sp = Species("A", "0.0025", "1")
print(sp.get_attribute("radius"), sp.get_attribute("D"))
del sp


0.0025 1

A Species consists of one or more UnitSpecies.


In [6]:
sp = Species()
usp = UnitSpecies("C")
print(usp.serial())
sp.add_unit(usp)
sp.add_unit(UnitSpecies("A"))
sp.add_unit(UnitSpecies("B"))
print(sp.serial(), sp.num_units())
del usp, sp


C
C.A.B 3

A Species can be reproduced from serial. In the serial, all serials of UnitSpecies are joined with the separator, ".". The comparison between Species matters the oder of UnitSpecies in each Species.


In [7]:
sp = Species("C.A.B")
print(sp.serial())
print(Species("A.B.C") == Species("C.A.B"))
print(Species("A.B.C") == Species("A.B.C"))
del sp


C.A.B
False
True

An UnitSpecies can have sites. Sites are sorted automatically in the UnitSpecies. Sites are given as a triplet of a name, state and bond.


In [8]:
usp = UnitSpecies("A")
usp.add_site("us", "u", "")
usp.add_site("ps", "p", "_")
usp.add_site("bs", "", "_")
print(usp.name(), usp.serial())
del usp


A A(bs^_,ps=p^_,us=u)

An UnitSpecies can be reproduced from its serial. Please be careful with the order of sites where sites with a state must be placed after sites with no state specification.


In [9]:
usp = UnitSpecies()
usp.deserialize("A(bs^_, us=u, ps=p^_)")
print(usp.serial())
del usp


A(bs^_,ps=p^_,us=u)

Of course, a site of UnitSpecies is available even in a Species' serial.


In [10]:
sp = Species("A(bs^1, ps=u).A(bs, ps=p^1)")
print(sp.serial(), sp.num_units())
del sp


A(bs^1,ps=u).A(bs,ps=p^1) 2

In [10]: