|
2 | 2 |
|
3 | 3 | import sys |
4 | 4 |
|
5 | | -from pyneuroml import pynml |
6 | | -from pyneuroml.utils import extract_position_info |
7 | | -from neuroml import Cell |
8 | | - |
9 | | - |
10 | | -pl = pv.Plotter() |
11 | | - |
12 | | -filename = sys.argv[1] if len(sys.argv) == 2 else "c302_D_Full.net.nml" |
13 | | - |
14 | | -nml_doc = pynml.read_neuroml2_file(filename, include_includes=True) |
15 | | - |
16 | | -print("Loaded NeuroML file: %s" % filename) |
17 | | - |
18 | | - |
19 | | -( |
20 | | - cell_id_vs_cell, |
21 | | - pop_id_vs_cell, |
22 | | - positions, |
23 | | - pop_id_vs_color, |
24 | | - pop_id_vs_radii, |
25 | | -) = extract_position_info(nml_doc, False) |
26 | | - |
27 | | -factor = 0.2 |
28 | | - |
29 | | -while pop_id_vs_cell: |
30 | | - pop_id, cell = pop_id_vs_cell.popitem() |
31 | | - pos_pop = positions[pop_id] # type: typing.Dict[typing.Any, typing.List[float]] |
32 | | - |
33 | | - print("Pop: %s has %i of component %s" % (pop_id, len(pos_pop), cell.id)) |
34 | | - |
35 | | - radius = pop_id_vs_radii[pop_id] if pop_id in pop_id_vs_radii else 10 |
36 | | - color = pop_id_vs_color[pop_id] if pop_id in pop_id_vs_color else "r" |
37 | | - |
38 | | - if type(cell) is Cell: |
39 | | - print("Loading a cell with %i segments" % len(cell.morphology.segments)) |
40 | | - |
41 | | - cell_meshes = pv.MultiBlock() |
42 | | - |
43 | | - for seg in cell.morphology.segments: |
44 | | - p = cell.get_actual_proximal(seg.id) |
45 | | - d = seg.distal |
46 | | - width = (p.diameter + d.diameter) / 4 |
47 | | - # print("Creating %s" % (seg)) |
48 | | - |
49 | | - if cell.get_segment_length(seg.id) == 0: |
50 | | - seg_mesh = pv.Sphere( |
51 | | - center=(p.x * factor, p.z * factor, -1 * p.y * factor), |
52 | | - radius=p.diameter * factor / 2, |
53 | | - ) |
54 | | - |
55 | | - pl.add_mesh(seg_mesh, color=color) |
56 | | - else: |
57 | | - seg_mesh = pv.Tube( |
58 | | - pointa=(p.x * factor, p.z * factor, -1 * p.y * factor), |
59 | | - pointb=(d.x * factor, d.z * factor, -1 * d.y * factor), |
60 | | - resolution=1, |
61 | | - radius=width * factor, |
62 | | - n_sides=15, |
63 | | - ) |
64 | | - |
65 | | - cell_meshes.append(seg_mesh) |
66 | | - |
67 | | - while pos_pop: |
68 | | - cell_index, pos = pos_pop.popitem() |
69 | | - pp = [pos[0] * factor, pos[2] * factor, -1 * pos[1] * factor] |
70 | | - print("Plotting %s(%i) at %s, %s" % (cell.id, cell_index, pos, pp)) |
71 | | - cell_mesh = cell_meshes.copy() |
72 | | - for i in range(len(cell_mesh)): |
73 | | - cell_mesh[i].translate(pp, inplace=True) |
74 | | - pl.add_mesh(cell_mesh, color=color, smooth_shading=True) |
75 | | - |
76 | | - else: |
77 | | - sphere = pv.Sphere(center=(pos[0], pos[1], pos[2]), radius=radius) |
78 | | - |
79 | | - pl.add_mesh(sphere, color=color) |
80 | 5 |
|
81 | 6 | ''' |
82 | 7 |
|
@@ -237,8 +162,15 @@ def create_mesh(step): |
237 | 162 |
|
238 | 163 | ''' |
239 | 164 |
|
240 | | -pl.set_background("white") |
241 | | -pl.add_axes() |
242 | 165 |
|
| 166 | +if __name__ == "__main__": |
| 167 | + pl = pv.Plotter() |
| 168 | + |
| 169 | + from neuromlmodel import add_neuroml_model |
| 170 | + |
| 171 | + add_neuroml_model(pl) |
| 172 | + pl.set_background("white") |
| 173 | + pl.add_axes() |
243 | 174 |
|
244 | | -pl.show() |
| 175 | + if "-nogui" not in sys.argv: |
| 176 | + pl.show() |
0 commit comments