Skip to content

Instantly share code, notes, and snippets.

@0ncorhynchus
Last active November 10, 2015 10:11
Show Gist options
  • Save 0ncorhynchus/e3c48722ebc0a93845b6 to your computer and use it in GitHub Desktop.
Save 0ncorhynchus/e3c48722ebc0a93845b6 to your computer and use it in GitHub Desktop.
lattice hdf5 load
$ python test.py 2> /dev/null
update: 1.04434204102 [sec]
save: 0.781103849411 [sec]
load: 0.143770933151 [sec]
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from ecell4 import *
with species_attributes():
cytoplasm | {'radius': '1e-8', 'D': '0'}
MinDatp | MinDadp | {'radius': '1e-8', 'D': '16e-12', 'location': 'cytoplasm'}
MinEE_C | {'radius': '1e-8', 'D': '10e-12', 'location': 'cytoplasm'}
membrane | {'radius': '1e-8', 'D': '0', 'location': 'cytoplasm'}
MinD | MinEE_M | MinDEE | MinDEED | {'radius': '1e-8', 'D': '0.02e-12', 'location': 'membrane'}
with reaction_rules():
membrane + MinDatp > MinD | 2.2e-8
MinD + MinDatp > MinD + MinD | 3e-20
MinD + MinEE_C > MinDEE | 5e-19
MinDEE > MinEE_M + MinDadp | 1
MinDadp > MinDatp | 5
MinDEE + MinD > MinDEED | 5e-15
MinDEED > MinDEE + MinDadp | 1
MinEE_M > MinEE_C | 0.83
m = get_model()
f = lattice.LatticeFactory(1e-8)
w = f.create_world(Real3(4.6e-6, 1.1e-6, 1.1e-6))
w.bind_to(m)
start = time.time()
rod = Rod(3.5e-6, 0.51e-6, w.edge_lengths()*0.5)
w.add_structure(Species('cytoplasm'), rod)
w.add_structure(Species('membrane'), rod.surface())
w.add_molecules(Species('MinDadp'), 1300)
w.add_molecules(Species('MinDEE'), 700)
elapsed_time = time.time() - start
print "update: {0} [sec]".format(elapsed_time)
start = time.time()
w.save("data.h5")
elapsed_time = time.time() - start
print "save: {0} [sec]".format(elapsed_time)
start = time.time()
w2 = lattice.LatticeWorld()
w2.load("data.h5")
elapsed_time = time.time() - start
print "load: {0} [sec]".format(elapsed_time)
assert(w.num_particles() == w2.num_particles())
assert(w.num_voxels() == w2.num_voxels())
assert(w.t() == w2.t())
assert(w.size() == w2.size())
assert(w.voxel_radius() == w2.voxel_radius())
assert(w.num_voxels(Species('cytoplasm')) == w2.num_voxels(Species('cytoplasm')))
assert(w.num_voxels(Species('membrane')) == w2.num_voxels(Species('membrane')))
assert(w.num_voxels(Species('MinDadp')) == w2.num_voxels(Species('MinDadp')))
assert(w.num_voxels(Species('MinDEE')) == w2.num_voxels(Species('MinDEE')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment