Skip to content

Commit

Permalink
Better way of fixing hh.mod issue
Browse files Browse the repository at this point in the history
  • Loading branch information
JCGoran committed Dec 18, 2024
1 parent 8dfe5a3 commit 1acfb21
Show file tree
Hide file tree
Showing 39 changed files with 188 additions and 32 deletions.
24 changes: 0 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -789,30 +789,6 @@ add_custom_target(
COMMENT "Format only files modified with respect to master branch."
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})

# =============================================================================
# ~~~
# Update hh.mod for CoreNEURON compatibility
# - Replace GLOBAL variable by RANGE
# - Comment out TABLE
# ~~~
# =============================================================================
if(NRN_ENABLE_CORENEURON OR NRN_ENABLE_MOD_COMPATIBILITY)
set(GLOBAL_VAR_TOGGLE_COMMAND "'s/ GLOBAL minf/ RANGE minf/'")
else()
set(GLOBAL_VAR_TOGGLE_COMMAND "'s/ RANGE minf/ GLOBAL minf/'")
endif()
separate_arguments(GLOBAL_VAR_TOGGLE_COMMAND UNIX_COMMAND "${GLOBAL_VAR_TOGGLE_COMMAND}")
add_custom_target(
hh_update
COMMAND sed ${GLOBAL_VAR_TOGGLE_COMMAND} ${CMAKE_SOURCE_DIR}/src/nrnoc/hh.mod >
${CMAKE_BINARY_DIR}/hh.mod.1
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/hh.mod.1
${CMAKE_SOURCE_DIR}/src/nrnoc/hh.mod
COMMAND ${CMAKE_COMMAND} -E remove ${CMAKE_BINARY_DIR}/hh.mod.1
COMMENT "Update hh.mod for CoreNEURON compatibility"
VERBATIM)
add_dependencies(nrniv_lib hh_update)

# =============================================================================
# Generate help_data.dat
# =============================================================================
Expand Down
38 changes: 32 additions & 6 deletions cmake/MacroHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ endmacro()
# =============================================================================
# Run nocmodl to convert NMODL to C
# =============================================================================
macro(nocmodl_mod_to_cpp modfile_basename)
macro(nocmodl_mod_to_cpp modfile_basename modfile_subdir)
set(NOCMODL_SED_EXPR "s/_reg()/_reg_()/")
if(NOT MSVC)
set(NOCMODL_SED_EXPR "'${NOCMODL_SED_EXPR}'")
Expand All @@ -153,18 +153,44 @@ macro(nocmodl_mod_to_cpp modfile_basename)
if(CMAKE_VERSION VERSION_LESS "3.17")
set(REMOVE_CMAKE_COMMAND "remove")
endif()
get_filename_component(modfile_output_dir ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod DIRECTORY)
string(REPLACE "/" ";" path_parts "${modfile_basename}")

# Create a variable to hold the base path (all but the last part)
set(base_path "")
list(LENGTH path_parts path_length)
math(EXPR last_index "${path_length} - 1")

# Append all parts except the last one to base_path
foreach(i RANGE 0 ${last_index})
list(GET path_parts ${i} part)
if(${i} LESS ${last_index})
if(base_path STREQUAL "")
set(base_path "${part}")
else()
set(base_path "${base_path}/${part}")
endif()
endif()
endforeach()

# Append the custom part and the last part
list(GET path_parts ${last_index} last_part)
set(modfile_basename_real "${base_path}/${modfile_subdir}/${last_part}")
message(WARNING ${modfile_basename_real})

get_filename_component(modfile_output_dir ${PROJECT_SOURCE_DIR}/${modfile_basename_real}.mod
DIRECTORY)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/${modfile_basename}.cpp
COMMAND
${CMAKE_COMMAND} -E env "MODLUNIT=${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib"
${NRN_NOCMODL_SANITIZER_ENVIRONMENT} $<TARGET_FILE:${NRN_CODEGENERATOR_TARGET}>
${PROJECT_SOURCE_DIR}/${modfile_basename}.mod ${NRN_NMODL_--neuron} -o ${modfile_output_dir}
COMMAND sed ${NOCMODL_SED_EXPR} ${PROJECT_SOURCE_DIR}/${modfile_basename}.cpp >
${PROJECT_SOURCE_DIR}/${modfile_basename_real}.mod ${NRN_NMODL_--neuron} -o
${modfile_output_dir}
COMMAND sed ${NOCMODL_SED_EXPR} ${PROJECT_SOURCE_DIR}/${modfile_basename_real}.cpp >
${PROJECT_BINARY_DIR}/${modfile_basename}.cpp
COMMAND ${CMAKE_COMMAND} -E ${REMOVE_CMAKE_COMMAND}
${PROJECT_SOURCE_DIR}/${modfile_basename}.cpp
DEPENDS ${NRN_CODEGENERATOR_TARGET} ${PROJECT_SOURCE_DIR}/${modfile_basename}.mod
${PROJECT_SOURCE_DIR}/${modfile_basename_real}.cpp
DEPENDS ${NRN_CODEGENERATOR_TARGET} ${PROJECT_SOURCE_DIR}/${modfile_basename_real}.mod
${PROJECT_BINARY_DIR}/share/nrn/lib/nrnunits.lib
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/src/nrniv)
endmacro()
Expand Down
12 changes: 11 additions & 1 deletion src/nrniv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@ endif()
# Translate all MOD files to C and mark them generated
# =============================================================================
foreach(modfile ${NRN_MODFILE_BASE_NAMES})
nocmodl_mod_to_cpp(${modfile})
# =============================================================================
# ~~~
# Set the correct supported keyword for CoreNEURON compatibility
# - Replace GLOBAL variable by RANGE
# ~~~
# =============================================================================
if(NRN_ENABLE_CORENEURON OR NRN_ENABLE_MOD_COMPATIBILITY)
nocmodl_mod_to_cpp(${modfile} "modfiles/coreneuron")
else()
nocmodl_mod_to_cpp(${modfile} "modfiles/neuron")
endif()
list(APPEND NRN_MODFILE_CPP ${PROJECT_BINARY_DIR}/${modfile}.cpp)
endforeach()
set_property(
Expand Down
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/apcount.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/exp2syn.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/expsyn.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/feature.mod
128 changes: 128 additions & 0 deletions src/nrnoc/modfiles/coreneuron/hh.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
TITLE hh.mod squid sodium, potassium, and leak channels

COMMENT
This is the original Hodgkin-Huxley treatment for the set of sodium,
potassium, and leakage channels found in the squid giant axon membrane.
("A quantitative description of membrane current and its application
conduction and excitation in nerve" J.Physiol. (Lond.) 117:500-544 (1952).)
Membrane voltage is in absolute mV and has been reversed in polarity
from the original HH convention and shifted to reflect a resting potential
of -65 mV.
Remember to set a squid-appropriate temperature
(e.g. in HOC: "celsius=6.3" or in Python: "h.celsius=6.3").
See squid.hoc for an example of a simulation using this model.
SW Jaslove 6 March, 1992
ENDCOMMENT

UNITS {
(mA) = (milliamp)
(mV) = (millivolt)
(S) = (siemens)
}

? interface
NEURON {
SUFFIX hh
REPRESENTS NCIT:C17145 : sodium channel
REPRESENTS NCIT:C17008 : potassium channel
USEION na READ ena WRITE ina REPRESENTS CHEBI:29101
USEION k READ ek WRITE ik REPRESENTS CHEBI:29103
NONSPECIFIC_CURRENT il
RANGE gnabar, gkbar, gl, el, gna, gk
RANGE minf, hinf, ninf, mtau, htau, ntau
THREADSAFE : assigned GLOBALs will be per thread
}

PARAMETER {
gnabar = .12 (S/cm2) <0,1e9>
gkbar = .036 (S/cm2) <0,1e9>
gl = .0003 (S/cm2) <0,1e9>
el = -54.3 (mV)
}

STATE {
m h n
}

ASSIGNED {
v (mV)
celsius (degC)
ena (mV)
ek (mV)

gna (S/cm2)
gk (S/cm2)
ina (mA/cm2)
ik (mA/cm2)
il (mA/cm2)
minf hinf ninf
mtau (ms) htau (ms) ntau (ms)
}

? currents
BREAKPOINT {
SOLVE states METHOD cnexp
gna = gnabar*m*m*m*h
ina = gna*(v - ena)
gk = gkbar*n*n*n*n
ik = gk*(v - ek)
il = gl*(v - el)
}


INITIAL {
rates(v)
m = minf
h = hinf
n = ninf
}

? states
DERIVATIVE states {
rates(v)
m' = (minf-m)/mtau
h' = (hinf-h)/htau
n' = (ninf-n)/ntau
}

:LOCAL q10


? rates
PROCEDURE rates(v(mV)) { :Computes rate and other constants at current v.
:Call once from HOC to initialize inf at resting v.
LOCAL alpha, beta, sum, q10
: `TABLE minf` will be replaced with `:TABLE minf` if CoreNEURON enabled)
TABLE minf, mtau, hinf, htau, ninf, ntau DEPEND celsius FROM -100 TO 100 WITH 200

UNITSOFF
q10 = 3^((celsius - 6.3)/10)
:"m" sodium activation system
alpha = .1 * vtrap(-(v+40),10)
beta = 4 * exp(-(v+65)/18)
sum = alpha + beta
mtau = 1/(q10*sum)
minf = alpha/sum
:"h" sodium inactivation system
alpha = .07 * exp(-(v+65)/20)
beta = 1 / (exp(-(v+35)/10) + 1)
sum = alpha + beta
htau = 1/(q10*sum)
hinf = alpha/sum
:"n" potassium activation system
alpha = .01*vtrap(-(v+55),10)
beta = .125*exp(-(v+65)/80)
sum = alpha + beta
ntau = 1/(q10*sum)
ninf = alpha/sum
}

FUNCTION vtrap(x,y) { :Traps for 0 in denominator of rate eqns.
if (fabs(x/y) < 1e-6) {
vtrap = y*(1 - x/y/2)
}else{
vtrap = x/(exp(x/y) - 1)
}
}

UNITSON
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/intfire1.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/intfire2.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/intfire4.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/netstim.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/oclmp.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/passive.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/pattern.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/ppmark.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/stim.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/svclmp.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/syn.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/vclmp.mod
1 change: 1 addition & 0 deletions src/nrnoc/modfiles/coreneuron/xmech.mod
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/nrnoc/hh.mod → src/nrnoc/modfiles/neuron/hh.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ NEURON {
USEION k READ ek WRITE ik REPRESENTS CHEBI:29103
NONSPECIFIC_CURRENT il
RANGE gnabar, gkbar, gl, el, gna, gk
: `GLOBAL minf` will be replaced with `RANGE minf` if CoreNEURON enabled
GLOBAL minf, hinf, ninf, mtau, htau, ntau
THREADSAFE : assigned GLOBALs will be per thread
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 1acfb21

Please sign in to comment.