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"))
A Species can be translated into an unique string, named "serial":
In [3]:
print(Species("A").serial(), Species("B").serial())
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
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
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
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
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
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
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
In [10]: