1
|
|
|
"""! |
2
|
|
|
|
3
|
|
|
@brief CCORE Wrapper for Hodgkin-Huxley oscillatory network for image segmentation. |
4
|
|
|
|
5
|
|
|
@authors Andrei Novikov ([email protected]) |
6
|
|
|
@date 2014-2018 |
7
|
|
|
@copyright GNU Public License |
8
|
|
|
|
9
|
|
|
@cond GNU_PUBLIC_LICENSE |
10
|
|
|
PyClustering is free software: you can redistribute it and/or modify |
11
|
|
|
it under the terms of the GNU General Public License as published by |
12
|
|
|
the Free Software Foundation, either version 3 of the License, or |
13
|
|
|
(at your option) any later version. |
14
|
|
|
|
15
|
|
|
PyClustering is distributed in the hope that it will be useful, |
16
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
17
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18
|
|
|
GNU General Public License for more details. |
19
|
|
|
|
20
|
|
|
You should have received a copy of the GNU General Public License |
21
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
22
|
|
|
@endcond |
23
|
|
|
|
24
|
|
|
""" |
25
|
|
|
|
26
|
|
|
from pyclustering.core.wrapper import *; |
|
|
|
|
27
|
|
|
from pyclustering.core.pyclustering_package import pyclustering_package, package_extractor, package_builder; |
28
|
|
|
|
29
|
|
|
|
30
|
|
|
class c_hhn_params(Structure): |
31
|
|
|
_fields_ = [ |
32
|
|
|
("nu", c_double), |
33
|
|
|
("gNa", c_double), |
34
|
|
|
("gK", c_double), |
35
|
|
|
("gL", c_double), |
36
|
|
|
("vNa", c_double), |
37
|
|
|
("vK", c_double), |
38
|
|
|
("vL", c_double), |
39
|
|
|
("vRest", c_double), |
40
|
|
|
("Icn1", c_double), |
41
|
|
|
("Icn2", c_double), |
42
|
|
|
("Vsyninh", c_double), |
43
|
|
|
("Vsynexc", c_double), |
44
|
|
|
("alfa_inhibitory", c_double), |
45
|
|
|
("betta_inhibitory", c_double), |
46
|
|
|
("alfa_excitatory", c_double), |
47
|
|
|
("betta_excitatory", c_double), |
48
|
|
|
("w1", c_double), |
49
|
|
|
("w2", c_double), |
50
|
|
|
("w3", c_double), |
51
|
|
|
("deltah", c_double), |
52
|
|
|
("threshold", c_double), |
53
|
|
|
("eps", c_double), |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
def hhn_create(size, params): |
58
|
|
|
c_params = c_hhn_params(); |
59
|
|
|
|
60
|
|
|
c_params.nu = params.nu; |
61
|
|
|
c_params.gNa = params.gNa; |
62
|
|
|
c_params.gK = params.gK; |
63
|
|
|
c_params.gL = params.gL; |
64
|
|
|
c_params.vNa = params.vNa; |
65
|
|
|
c_params.vK = params.vK; |
66
|
|
|
c_params.vL = params.vL; |
67
|
|
|
c_params.vRest = params.vRest; |
68
|
|
|
c_params.Icn1 = params.Icn1; |
69
|
|
|
c_params.Icn2 = params.Icn2; |
70
|
|
|
c_params.Vsyninh = params.Vsyninh; |
71
|
|
|
c_params.Vsynexc = params.Vsynexc; |
72
|
|
|
c_params.alfa_inhibitory = params.alfa_inhibitory; |
73
|
|
|
c_params.betta_inhibitory = params.betta_inhibitory; |
74
|
|
|
c_params.alfa_excitatory = params.alfa_excitatory; |
75
|
|
|
c_params.betta_excitatory = params.betta_excitatory; |
76
|
|
|
c_params.w1 = params.w1; |
77
|
|
|
c_params.w2 = params.w2; |
78
|
|
|
c_params.w3 = params.w3; |
79
|
|
|
c_params.deltah = params.deltah; |
80
|
|
|
c_params.threshold = params.threshold; |
81
|
|
|
c_params.eps = params.eps; |
82
|
|
|
|
83
|
|
|
ccore = ccore_library.get(); |
84
|
|
|
|
85
|
|
|
ccore.hhn_create.restype = POINTER(c_void_p); |
86
|
|
|
hhn_network_pointer = ccore.hhn_create(c_size_t(size), pointer(c_params)); |
87
|
|
|
return hhn_network_pointer; |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
def hhn_destroy(hhn_network_pointer): |
91
|
|
|
ccore = ccore_library.get(); |
92
|
|
|
ccore.hhn_destroy(hhn_network_pointer); |
93
|
|
|
|
94
|
|
|
|
95
|
|
|
def hhn_dynamic_create(collect_membrane, collect_active_cond_sodium, collect_inactive_cond_sodium, collect_active_cond_potassium): |
96
|
|
|
ccore = ccore_library.get(); |
97
|
|
|
|
98
|
|
|
ccore.hhn_dynamic_create.restype = POINTER(c_void_p); |
99
|
|
|
hhn_dynamic_pointer = ccore.hhn_dynamic_create(c_bool(collect_membrane), |
100
|
|
|
c_bool(collect_active_cond_sodium), |
101
|
|
|
c_bool(collect_inactive_cond_sodium), |
102
|
|
|
c_bool(collect_active_cond_potassium)); |
103
|
|
|
return hhn_dynamic_pointer; |
104
|
|
|
|
105
|
|
|
|
106
|
|
|
def hhn_dynamic_destroy(hhn_dynamic_pointer): |
107
|
|
|
ccore = ccore_library.get(); |
108
|
|
|
ccore.hhn_dynamic_destroy(hhn_dynamic_pointer); |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
def hhn_simulate(hhn_network_pointer, steps, time, solution, stimulus, ccore_hhn_dynamic_pointer): |
112
|
|
|
ccore = ccore_library.get(); |
113
|
|
|
|
114
|
|
|
c_stimulus = package_builder(stimulus, c_double).create(); |
115
|
|
|
ccore.hhn_simulate(hhn_network_pointer, |
116
|
|
|
c_size_t(steps), |
117
|
|
|
c_double(time), |
118
|
|
|
c_size_t(solution), |
119
|
|
|
c_stimulus, |
120
|
|
|
ccore_hhn_dynamic_pointer); |
121
|
|
|
|
122
|
|
|
|
123
|
|
|
def hhn_dynamic_get_peripheral_evolution(ccore_hhn_dynamic_pointer, index_collection): |
124
|
|
|
ccore = ccore_library.get(); |
125
|
|
|
|
126
|
|
|
ccore.hhn_dynamic_get_peripheral_evolution.restype = POINTER(pyclustering_package); |
127
|
|
|
dynamic_package = ccore.hhn_dynamic_get_peripheral_evolution(ccore_hhn_dynamic_pointer, c_size_t(index_collection)); |
128
|
|
|
|
129
|
|
|
result = package_extractor(dynamic_package).extract(); |
130
|
|
|
ccore.free_pyclustering_package(dynamic_package); |
131
|
|
|
|
132
|
|
|
return result; |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
def hhn_dynamic_get_central_evolution(ccore_hhn_dynamic_pointer, index_collection): |
136
|
|
|
ccore = ccore_library.get(); |
137
|
|
|
|
138
|
|
|
ccore.hhn_dynamic_get_central_evolution.restype = POINTER(pyclustering_package); |
139
|
|
|
dynamic_package = ccore.hhn_dynamic_get_central_evolution(ccore_hhn_dynamic_pointer, c_size_t(index_collection)); |
140
|
|
|
|
141
|
|
|
result = package_extractor(dynamic_package).extract(); |
142
|
|
|
ccore.free_pyclustering_package(dynamic_package); |
143
|
|
|
|
144
|
|
|
return result; |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
def hhn_dynamic_get_time(ccore_hhn_dynamic_pointer): |
148
|
|
|
ccore = ccore_library.get(); |
149
|
|
|
|
150
|
|
|
ccore.hhn_dynamic_get_time.restype = POINTER(pyclustering_package); |
151
|
|
|
dynamic_package = ccore.hhn_dynamic_get_time(ccore_hhn_dynamic_pointer); |
152
|
|
|
|
153
|
|
|
result = package_extractor(dynamic_package).extract(); |
154
|
|
|
ccore.free_pyclustering_package(dynamic_package); |
155
|
|
|
|
156
|
|
|
return result; |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
def hhn_dynamic_write(ccore_hhn_dynamic_pointer, filename): |
160
|
|
|
ccore = ccore_library.get(); |
161
|
|
|
|
162
|
|
|
byte_filename = filename.encode('utf-8'); |
163
|
|
|
ccore.hhn_dynamic_write(ccore_hhn_dynamic_pointer, c_char_p(byte_filename)); |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
def hhn_dynamic_read(filename): |
167
|
|
|
ccore = ccore_library.get(); |
168
|
|
|
|
169
|
|
|
byte_filename = filename.encode('utf-8'); |
170
|
|
|
|
171
|
|
|
ccore.hhn_dynamic_read.restype = POINTER(c_void_p); |
172
|
|
|
hhn_dynamic_pointer = ccore.hhn_dynamic_read(byte_filename); |
173
|
|
|
|
174
|
|
|
return hhn_dynamic_pointer; |