From f39fa5d37d5470637d22a45169f660e4de9761f9 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Thu, 8 Apr 2021 00:26:42 -0400 Subject: [PATCH 1/6] MAINT: demo what move_to_pos does --- hnn_core/cell.py | 14 -------------- hnn_core/network_builder.py | 1 - 2 files changed, 15 deletions(-) diff --git a/hnn_core/cell.py b/hnn_core/cell.py index 021bc7914..2c9faeae1 100644 --- a/hnn_core/cell.py +++ b/hnn_core/cell.py @@ -301,20 +301,6 @@ def build(self, sec_name_apical=None): f'section of the current cell or None. ' f'Got {sec_name_apical}.') - def move_to_pos(self): - """Move cell to position.""" - x0 = self.sections['soma'].x3d(0) - y0 = self.sections['soma'].y3d(0) - z0 = self.sections['soma'].z3d(0) - dx = self.pos[0] * 100 - x0 - dy = self.pos[2] - y0 - dz = self.pos[1] * 100 - z0 - - for s in list(self.sections.values()): - for i in range(s.n3d()): - h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy, - s.z3d(i) + dz, s.diam3d(i), sec=s) - # two things need to happen here for h: # 1. dipole needs to be inserted into each section # 2. a list needs to be created with a Dipole (Point Process) in each diff --git a/hnn_core/network_builder.py b/hnn_core/network_builder.py index dc2a9a29e..4ab6ac7d5 100644 --- a/hnn_core/network_builder.py +++ b/hnn_core/network_builder.py @@ -318,7 +318,6 @@ def _build(self): self._record_spikes() - self.move_cells_to_pos() # position cells in 2D grid self._connect_celltypes() if _get_rank() == 0: From 5a1a432be7c06d3685cc63de40bccf6669bea302 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Thu, 8 Apr 2021 00:50:32 -0400 Subject: [PATCH 2/6] DOC: update whats new --- doc/whats_new.rst | 2 ++ hnn_core/network_builder.py | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index 28c5697f5..a8542554c 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -27,6 +27,8 @@ Changelog Bug ~~~ +- Remove repositioning of cells which moves x and z coordinates of all sections slightly, by `Mainak Jas`_ in `#314 `_ + API ~~~ - New API for defining cell-cell connections. Custom connections can be added with :func:`~hnn_core.Network.add_connection`, by `Nick Tolley`_ in `#276 `_ diff --git a/hnn_core/network_builder.py b/hnn_core/network_builder.py index 4ab6ac7d5..480c49b97 100644 --- a/hnn_core/network_builder.py +++ b/hnn_core/network_builder.py @@ -317,7 +317,6 @@ def _build(self): self._all_spike_gids = h.Vector() self._record_spikes() - self._connect_celltypes() if _get_rank() == 0: @@ -481,7 +480,6 @@ def _record_spikes(self): if _PC.gid_exists(gid): _PC.spike_record(gid, self._spike_times, self._spike_gids) - # aggregate recording all the somatic voltages for pyr def aggregate_data(self): """Aggregate somatic currents, voltages, and dipoles.""" for cell in self._cells: From 5372338d9d6b35be8b49ccaaac7c6e317c899892 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Fri, 23 Apr 2021 19:30:58 -0400 Subject: [PATCH 3/6] DEMO its numerical precision --- hnn_core/cell.py | 16 ++++++++++++++++ hnn_core/network_builder.py | 1 + 2 files changed, 17 insertions(+) diff --git a/hnn_core/cell.py b/hnn_core/cell.py index 2c9faeae1..594de8bde 100644 --- a/hnn_core/cell.py +++ b/hnn_core/cell.py @@ -301,6 +301,22 @@ def build(self, sec_name_apical=None): f'section of the current cell or None. ' f'Got {sec_name_apical}.') + def move_to_pos(self): + """Move cell to position.""" + x0 = self.soma.x3d(0) + y0 = self.soma.y3d(0) + z0 = self.soma.z3d(0) + dx = self.pos[0] * 100 - x0 + dy = self.pos[2] - y0 + dz = self.pos[1] * 100 - z0 + + for s in self.get_sections(): + for i in range(s.n3d()): + h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy, + s.z3d(i) + dz, s.diam3d(i), sec=s) + h.pt3dchange(i, s.x3d(i) - dx, s.y3d(i) - dy, + s.z3d(i) - dz, s.diam3d(i), sec=s) + # two things need to happen here for h: # 1. dipole needs to be inserted into each section # 2. a list needs to be created with a Dipole (Point Process) in each diff --git a/hnn_core/network_builder.py b/hnn_core/network_builder.py index 480c49b97..957021b0c 100644 --- a/hnn_core/network_builder.py +++ b/hnn_core/network_builder.py @@ -317,6 +317,7 @@ def _build(self): self._all_spike_gids = h.Vector() self._record_spikes() + self.move_cells_to_pos() self._connect_celltypes() if _get_rank() == 0: From 76c1ab286cbe51b98e345cfffa33d2d631108ee0 Mon Sep 17 00:00:00 2001 From: Mainak Jas Date: Tue, 4 May 2021 23:18:03 -0400 Subject: [PATCH 4/6] ENH: dummy comment to demo issue with NEURON 8.0 --- hnn_core/cell.py | 1 + 1 file changed, 1 insertion(+) diff --git a/hnn_core/cell.py b/hnn_core/cell.py index 594de8bde..472baa63d 100644 --- a/hnn_core/cell.py +++ b/hnn_core/cell.py @@ -310,6 +310,7 @@ def move_to_pos(self): dy = self.pos[2] - y0 dz = self.pos[1] * 100 - z0 + # dummy comment for s in self.get_sections(): for i in range(s.n3d()): h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy, From c4186974316fc0efed7ece8daf646eae895fb653 Mon Sep 17 00:00:00 2001 From: rythorpe Date: Mon, 31 May 2021 00:22:28 -0400 Subject: [PATCH 5/6] set position of sections upon creation --- hnn_core/cell.py | 26 ++++++++------------------ hnn_core/network_builder.py | 6 ------ 2 files changed, 8 insertions(+), 24 deletions(-) diff --git a/hnn_core/cell.py b/hnn_core/cell.py index 472baa63d..dfbe74c76 100644 --- a/hnn_core/cell.py +++ b/hnn_core/cell.py @@ -250,13 +250,20 @@ def _create_sections(self, p_secs, topology): for height and xz plane for depth. This is opposite for model as a whole, but convention is followed in this function ease use of gui. """ + # distance from initial to final root postion + dx = self.pos[0] - self.p_secs['soma']['sec_pts'][0][0] + dy = self.pos[2] - self.p_secs['soma']['sec_pts'][0][1] + dz = self.pos[1] - self.p_secs['soma']['sec_pts'][0][2] + for sec_name in p_secs: sec = h.Section(name=f'{self.name}_{sec_name}') self.sections[sec_name] = sec h.pt3dclear(sec=sec) for pt in p_secs[sec_name]['sec_pts']: - h.pt3dadd(pt[0], pt[1], pt[2], 1, sec=sec) + h.pt3dadd(pt[0] + dx, + pt[1] + dy, + pt[2] + dz, 1, sec=sec) sec.L = p_secs[sec_name]['L'] sec.diam = p_secs[sec_name]['diam'] sec.Ra = p_secs[sec_name]['Ra'] @@ -301,23 +308,6 @@ def build(self, sec_name_apical=None): f'section of the current cell or None. ' f'Got {sec_name_apical}.') - def move_to_pos(self): - """Move cell to position.""" - x0 = self.soma.x3d(0) - y0 = self.soma.y3d(0) - z0 = self.soma.z3d(0) - dx = self.pos[0] * 100 - x0 - dy = self.pos[2] - y0 - dz = self.pos[1] * 100 - z0 - - # dummy comment - for s in self.get_sections(): - for i in range(s.n3d()): - h.pt3dchange(i, s.x3d(i) + dx, s.y3d(i) + dy, - s.z3d(i) + dz, s.diam3d(i), sec=s) - h.pt3dchange(i, s.x3d(i) - dx, s.y3d(i) - dy, - s.z3d(i) - dz, s.diam3d(i), sec=s) - # two things need to happen here for h: # 1. dipole needs to be inserted into each section # 2. a list needs to be created with a Dipole (Point Process) in each diff --git a/hnn_core/network_builder.py b/hnn_core/network_builder.py index 957021b0c..074e95be1 100644 --- a/hnn_core/network_builder.py +++ b/hnn_core/network_builder.py @@ -317,7 +317,6 @@ def _build(self): self._all_spike_gids = h.Vector() self._record_spikes() - self.move_cells_to_pos() self._connect_celltypes() if _get_rank() == 0: @@ -514,11 +513,6 @@ def state_init(self): elif cell.name == 'L5Basket': seg.v = -64.9737 - def move_cells_to_pos(self): - """Move cells 3d positions to positions used for wiring.""" - for cell in self._cells: - cell.move_to_pos() - def _clear_neuron_objects(self): """Clear up NEURON internal gid information. From c4fbd81c4c642c3b9b19f2cde21d4b15b1465ef5 Mon Sep 17 00:00:00 2001 From: rythorpe Date: Mon, 31 May 2021 00:38:39 -0400 Subject: [PATCH 6/6] update comment and whats_new.rst --- doc/whats_new.rst | 2 +- hnn_core/cell.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/whats_new.rst b/doc/whats_new.rst index a8542554c..de686b49e 100644 --- a/doc/whats_new.rst +++ b/doc/whats_new.rst @@ -27,7 +27,7 @@ Changelog Bug ~~~ -- Remove repositioning of cells which moves x and z coordinates of all sections slightly, by `Mainak Jas`_ in `#314 `_ +- Remove rounding error caused by repositioning of NEURON cell sections, by `Mainak Jas`_ and `Ryan Thorpe`_ in `#314 `_ API ~~~ diff --git a/hnn_core/cell.py b/hnn_core/cell.py index dfbe74c76..d1d6dff2a 100644 --- a/hnn_core/cell.py +++ b/hnn_core/cell.py @@ -251,6 +251,8 @@ def _create_sections(self, p_secs, topology): whole, but convention is followed in this function ease use of gui. """ # distance from initial to final root postion + # Resolve: y-coordinate here corresponds to the z-coordinate in + # self.pos[2] dx = self.pos[0] - self.p_secs['soma']['sec_pts'][0][0] dy = self.pos[2] - self.p_secs['soma']['sec_pts'][0][1] dz = self.pos[1] - self.p_secs['soma']['sec_pts'][0][2]