Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diffusion Example Improvements (and a bit of clean-up) #1914

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions mechanisms/default/decay.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
NEURON {
SUFFIX decay
USEION x WRITE xd, ix
USEION x WRITE xd
RANGE F, tau
}

PARAMETER { tau = 5 }

INITIAL { F = xd }

STATE { F }
Expand All @@ -14,5 +17,5 @@ BREAKPOINT {

DERIVATIVE dF {
F = xd
F' = -5*F
F' = -tau*F
}
2 changes: 1 addition & 1 deletion mechanisms/default/inject.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
NEURON {
POINT_PROCESS inject
USEION x WRITE xd, ix
USEION x WRITE xd
RANGE alpha, beta
}

Expand Down
28 changes: 19 additions & 9 deletions python/example/diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,18 @@ def probes(self, gid):
def global_properties(self, kind):
return self.the_props

def event_generators(self, gid):
return [A.event_generator("Zap", 0.005, A.explicit_schedule([0.0]))]


tree = A.segment_tree()
s = tree.append(A.mnpos, A.mpoint(-3, 0, 0, 3), A.mpoint(3, 0, 0, 3), tag=1)
_ = tree.append(s, A.mpoint(3, 0, 0, 1), A.mpoint(33, 0, 0, 1), tag=3)

dec = A.decor()
dec.set_property(Vm=-40)
# dec.paint('(tag 1)', A.density('hh'))
dec.set_ion("na", int_con=0.0, diff=0.005)
dec.place("(location 0 0.5)", A.synapse("inject/x=na", {"alpha": 200.0}), "Zap")
dec.paint("(all)", A.density("decay/x=na"))
dec.discretization(A.cv_policy("(max-extent 5)"))

# Set up ion diffusion
Expand All @@ -47,9 +51,7 @@ def global_properties(self, kind):
]
cel = A.cable_cell(tree, A.label_dict(), dec)
rec = recipe(cel, prb)
ctx = A.context()
dom = A.partition_load_balance(rec, ctx)
sim = A.simulation(rec, dom, ctx)
sim = A.simulation(rec)
hdl = (sim.sample((0, 0), A.regular_schedule(0.1)),)

sim.run(tfinal=0.5)
Expand All @@ -58,10 +60,18 @@ def global_properties(self, kind):
fg, ax = plt.subplots()
for h in hdl:
for d, m in sim.samples(h):
xs = d[:, 0]
# Plot
for lbl, ix in zip(m, range(1, d.shape[1])):
ys = d[:, ix]
print(lbl, ys.min(), ys.max())
ax.plot(xs, ys, label=lbl)
ax.plot(d[:, 0], d[:, ix], label=lbl)
# Table
print("Sodium concentration (NaD/mM)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use pandas/sth else to pretty print the table?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory yes, but the code is usually neither more comprehensible nor shorter. You would be looking for
DataFrame::to_string(buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, sparsify=None, index_names=True, justify=None, max_rows=None, max_cols=None, show_dimensions=False, decimal='.', line_width=None, min_rows=None, max_colwidth=None, encoding=None) .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something else = pip install tabulate, but I am not going to add a dependency for that

print("|-" + "-+-".join("-" * 20 for _ in range(d.shape[1])) + "-|")
print(
"| Time (ms) | " + " | ".join(f"{str(l):<20}" for l in m) + " |"
)
print("|-" + "-+-".join("-" * 20 for _ in range(d.shape[1])) + "-|")
for ix in range(d.shape[0]):
print("| " + " | ".join(f"{v:>20.3f}" for v in d[ix, :]) + " |")
print("|-" + "-+-".join("-" * 20 for _ in range(d.shape[1])) + "-|")
ax.legend()
fg.savefig("results.pdf")
1 change: 1 addition & 0 deletions scripts/run_python_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ $PREFIX python python/example/single_cell_recipe.py
$PREFIX python python/example/single_cell_stdp.py
$PREFIX python python/example/single_cell_swc.py python/example/single_cell_detailed.swc
$PREFIX python python/example/two_cell_gap_junctions.py
$PREFIX python python/example/diffusion.py