1 #include <../../nrnconf.h>
13 #define NSingleIndex 0
14 #if defined(__MWERKS__) && !defined(_MSC_VER)
16 #define strdup _strdup
30 #define nt_dt nrn_threads->_dt
33 if (
o->ctemplate->sym != s) {
38 if (!
o->u.this_pointer) {
120 c->map(ieq,
pv, pvdot,
p, pd, atol);
172 c->nsingle(pp, (
int)
chkarg(1, 1, 1e9));
174 return (
double)
c->nsingle(pp);
225 return (
double) ks->
ngate_;
306 bool use = ((int)
chkarg(1, 0, 1)) ?
true :
false;
351 const char* lig =
NULL;
408 return (
const char**) ps;
418 return (
const char**) ps;
425 return (
const char**) ps;
459 *ps = (
char*) kss->
string();
460 return (
const char**) ps;
476 return (
double) ksg->
power_;
488 return (
double) ksg->
index_;
512 return (
double) kst->
index_;
528 return (
double) kst->
type_;
535 if ((
int)
chkarg(1, 0, 1) == 0) {
541 return (
double) f->
type();
596 if ((
int)
chkarg(1, 0, 1) == 0) {
604 if (f->
type() == 7) {
623 if (kst->
type_ >= 2) {
625 s[strlen(s) - 4] = (kst->
type_ == 3) ?
'i' :
'o';
626 s[strlen(s) - 3] =
'\0';
630 return (
const char**) ps;
646 Printf(
"name=%s is_point_=%s ion_=%s cond_model_=%d\n",
648 (ks->
is_point() ?
"true" :
"false"),
651 Printf(
" ngate=%d nstate=%d nhhstate=%d nligand=%d ntrans=%d ivkstrans=%d iligtrans=%d\n",
661 Printf(
" gate %d index=%d nstate=%d power=%d\n",
673 Printf(
" f0 type=%d f1 type=%d\n",
679 Printf(
" trans %d src=%d target=%d type=%d ligindex=%d\n",
685 Printf(
" f0 type=%d f1 type=%d\n",
689 Printf(
" state names and fractional conductance\n");
780 isp = ((int)
chkarg(1, 0, 1)) != 0;
793 hoc_execerror(
"Cannot create a KSState except through KSChan", 0);
798 hoc_execerror(
"Cannot create a KSGate except through KSChan", 0);
803 hoc_execerror(
"Cannot create a KSTransition except through KSChan", 0);
822 static const char*
m_kschan_pat[] = {
"0",
"kschan",
"gmax", 0,
"g",
"i", 0, 0, 0};
888 ion_ =
"NonSpecific";
906 if (strcmp(
ion_.
string(),
"NonSpecific") != 0) {
943 for (
i = 0;
i < 9; ++
i)
966 char old_suffix[100];
992 int nbase = cp - sp->
name;
993 int n = nbase + strlen(
suffix) + 2;
996 strncpy(s1, sp->
name, nbase);
1010 if (strcmp(
state_[
i].
string(), s) == 0) {
1032 "KSChan single channel mode implemented only for single ks gating complex to first "
1081 if (is <
gc_[
i].sindex_) {
1137 sym =
installsym(
"Nsingle", RANGEVAR, searchsym);
1158 for (
j =
soffset_,
i = old_soffset;
i < old_svarn; ++
i, ++
j) {
1160 ppsym[
j]->
u.
rng.index =
j;
1176 if (strlen(s) == 0) {
1177 ion_ =
"NonSpecific";
1184 if (strcmp(
ion_.
string(),
"NonSpecific") == 0) {
1186 printf(
"switch from useion to non-specific\n");
1189 for (
i = 0;
i <= io; ++
i) {
1205 ppsym[1 + io]->
u.
rng.index = 1 + io;
1208 ppsym[
i]->
u.
rng.index += 1;
1222 if (!sym || sym->
type != MECHANISM ||
1224 Printf(
"%s is not an ion mechanism", sym->
name);
1240 for (
i = 0;
i <= io; ++
i) {
1246 ppsym[
i]->
u.
rng.index -= 1;
1369 if (s->
type != MECHANISM ||
1384 if (type < 2 && t->type_ < 2) {
1392 if (
t->type_ >= 2) {
1393 iligold =
t->ligand_index_;
1400 if (
trans_[
i].ligand_index_ == iligold && iligold !=
i) {
1421 if (
trans_[
i].ligand_index_ > iligold) {
1433 t->ligand_index_ = -1;
1436 t->obj_->u.this_pointer =
t;
1455 strcpy(
buf + strlen(
buf) - 1,
"_ion");
1463 if (s->
type != MECHANISM ||
1475 bool add2list =
true;
1477 if (
t->type_ >= 2) {
1480 if (
trans_[
i].ligand_index_ == iligold &&
t->index_ !=
i) {
1506 t->ligand_index_ = ilig;
1511 if (iligold < 0 && ilig >= 0) {
1513 printf(
"old transition order\n");
1515 printf(
"i=%d index=%d type=%d ligand_index=%d %s<->%s\n",
i,
1536 t->obj_->u.this_pointer =
t;
1542 printf(
"new transition order\n");
1544 printf(
"i=%d index=%d type=%d ligand_index=%d %s<->%s %s\n",
i,
1664 if (is ==
gc_[
i].sindex_) {
1672 if (
gc_[
i].sindex_ > is) {
1730 if (
trans_[
i].ligand_index_ != -1) {
1731 printf(
"trans_ %d ligand_index_=%d\n",
i,
trans_[
i].ligand_index_);
1932 int i,
j, ii, idx, ns;
1935 for (
i=0;
i < vec->size(); ++
i) {
1936 printf(
"%d %g\n",
i, vec->elem(
i));
1948 ngate_ = (int) vec->elem(
j++);
1971 if (
i < nstate_old) {
1980 for (
i = 0;
i < nstate_old; ++
i) {
1995 for (ii = 0; ii < ns; ++ii) {
2044 for (
i = 0;
i < nnew; ++
i) {
2048 snew[
i]->
name[0] =
'\0';
2055 snew[
i]->
u.
rng.index =
i;
2059 for (
i = nnew;
i < nold; ++
i) {
2067 char buf[100], buf1[100];
2074 nrn_assert(snprintf(
buf, 100,
"%s%s", buf1, unsuffix) < 100);
2078 if (strlen(buf1) > 0) {
2087 if (top->
type != TEMPLATE) {
2202 double dt1 = -1. /
dt;
2296 for (
p = nd->
prop;
p;
p =
p->next) {
2297 if (
p->type ==
type) {
2308 for (
p = pm;
p;
p =
p->next) {
2309 if (
p->next == pion) {
2310 p->next =
p->next->next;
2339 for (
i = 0;
i <
sec->nnode; ++
i) {
2342 for (
p = nd->
prop;
p;
p =
p->next) {
2343 if (
p->type == mtype) {
2380 p->dparam[poff + 2 *
j].pval = pion->
param + 2;
2381 p->dparam[poff + 2 *
j + 1].pval = pion->
param + 1;
2394 for (
i = 0;
i <
sec->nnode; ++
i) {
2397 for (
p = nd->
prop;
p;
p =
p->next) {
2398 if (
p->type == mtype) {
2399 if (
p->param_size != ns) {
2401 double* oldp =
p->param;
2402 p->param = (
double*)
erealloc(oldp, ns *
sizeof(
double));
2403 if (oldp !=
p->param || shift != 0) {
2409 for (
j = ns - 1;
j > 0; --
j) {
2410 p->param[
j] =
p->param[
j - 1];
2413 }
else if (shift == -1) {
2414 for (
j = 1;
j < ns; ++
j) {
2415 p->param[
j - 1] =
p->param[
j];
2444 if (pnt && pnt->
prop) {
2453 for (
i = 0;
i <
n; ++
i) {
2492 for (
i = 0;
i <
n; ++
i) {
2510 s[
j] += (inf - s[
j]) * tau;
2515 s[
j] += (inf - s[
j]) * tau;
2520 s[
j] += (inf - s[
j]) * tau;
2528 s[
j] += (inf - s[
j]) * tau;
2546 for (
i = 0;
i <
n; ++
i) {
2564 s[
j] += (inf - s[
j]) * tau;
2569 s[
j] += (inf - s[
j]) * tau;
2574 s[
j] += (inf - s[
j]) * tau;
2582 s[
j] += (inf - s[
j]) * tau;
2598 for (
i = 0;
i <
n; ++
i) {
2609 for (
i = 0;
i <
n; ++
i) {
2621 for (
i = 0;
i <
n; ++
i) {
2629 for (
i = 0;
i <
n; ++
i) {
2647 *pd[2].
pval +=
p[1];
2663 double i1, ci, co, didv;
2667 didv = (i1 -
p[2]) * 1000.;
2668 *pd[2].
pval += didv;
2685 double afac = 1.e2 / (*pd[0].
pval);
2698 double afac = 1.e2 / (*pd[0].
pval);
2700 double g =
p[1] * afac;
2706 double afac = 1.e2 / (*pd[0].
pval);
2720 double afac = 1.e2 / (*pd[0].
pval);
2722 double i1, ci, co, didv;
2725 i1 =
p[1] *
nrn_ghk(
v + .001, ci, co,
z) * 1e6;
2726 didv = (i1 -
p[2]) * 1000.;
2728 *pd[2].
pval += didv;
2733 double afac = 1.e2 / (*pd[0].
pval);
2742 double afac = 1.e2 / (*pd[0].
pval);
2796 }
else if (
type_ == 3) {
2818 int i,
n =
v->size();
2822 for (
i = 0;
i <
n; ++
i) {
2823 a->elem(
i) =
f0->
f(
v->elem(
i));
2827 for (
i = 0;
i <
n; ++
i) {
2828 a->elem(
i) =
f0->
f(
v->elem(
i));
2829 b->elem(
i) =
f1->
f(
v->elem(
i));
2833 for (
i = 0;
i <
n; ++
i) {
2834 double t = a->elem(
i);
2835 a->elem(
i) =
t / b->elem(
i);
2836 b->elem(
i) = (1. -
t) / b->elem(
i);
2849 double t = 1. / (a + b);
2856 int i,
n =
v->size();
2860 for (
i = 0;
i <
n; ++
i) {
2861 a->elem(
i) =
f0->
f(
v->elem(
i));
2865 for (
i = 0;
i <
n; ++
i) {
2866 a->elem(
i) =
f0->
f(
v->elem(
i));
2867 b->elem(
i) =
f1->
f(
v->elem(
i));
2871 for (
i = 0;
i <
n; ++
i) {
2872 double t = 1. / (a->elem(
i) + b->elem(
i));
2873 a->elem(
i) = a->elem(
i) *
t;
2883 return x *
f0->
c(0);
2885 return x * x *
f0->
c(0);
2887 return x * x * x *
f0->
c(0);
2890 return x * x *
f0->
c(0);
2913 g += s[
i] * st[
i].
f_;
2955 for (
i = 0;
i <
n; ++
i) {
2972 p2[
j] = (inf - p1[
j]) / tau;
2989 for (
i = 0;
i <
n; ++
i) {
2998 p2[
j] /= (1 + nt->
_dt / tau);
3013 for (
i = 0;
i <
n; ++
i) {
3077 x =
c(
gp_->size() - 1);
3082 x =
c(
i) + (
c(
i + 1) -
c(
i)) * x;
3090 if (size < 1 || vmin >= vmax || size -
size1_ != 1) {
3108 for (
i = 0;
i < size; ++
i) {
3134 if (tml->index ==
type) {
int nrn_get_mechtype(const char *mechname)
static double Exp(double x)
static KSChanFunction * new_function(int type, Vect *, double, double)
virtual ~KSChanFunction()
virtual double f(double v)
int trans_index(const char *src, const char *target)
void add_channel(const char **)
void ligand_consist(int, int, Prop *, Node *)
void alloc_schan_node_data()
void mulmat(double *, double *)
virtual void alloc(Prop *)
void set_single(bool, bool update=true)
virtual void state(int, Node **, double **, Datum **, NrnThread *)
void fillmat(double v, Datum *pd)
double conductance(double gmax, double *state)
void usetable(bool, int size, double vmin, double vmax)
void delete_schan_node_data()
KSState * add_hhstate(const char *)
KSGateComplex * gate_insert(int ig, int is, int power)
KSState * state_insert(int i, const char *name, double frac)
void setname(const char *)
virtual void jacob(int, Node **, double **, Datum **)
virtual void spec(int, Node **, double **, Datum **)
virtual void map(int, double **, double **, double *, Datum *, double *)
void check_table_thread(NrnThread *)
KSChan(Object *, bool is_point=false)
void setstructure(Vect *)
void state_consist(int shift=0)
Prop * needion(Symbol *, Node *, Prop *)
void power(KSGateComplex *, int)
void destroy_pnt(Point_process *)
KSTransition * add_transition(int src, int target, const char *ligand)
void remove_transition(int)
void setion(const char *)
virtual void cv_sc_update(int, Node **, double **, Datum **, NrnThread *)
KSTransition * trans_insert(int i, int src, int target)
Symbol * installsym(const char *, int, Symbol *tmplt=NULL)
virtual void cur(int, Node **, double **, Datum **)
void setsname(int, const char *)
KSState * add_ksstate(int igate, const char *)
void freesym(Symbol *, Symbol *tmplt=NULL)
virtual void matsol(int, Node **, double **, Datum **, NrnThread *)
void mat_dt(double dt, double *p)
void setligand(int i, const char *)
virtual void init(int, Node **, double **, Datum **, NrnThread *)
int gate_index(int state_index)
void settype(KSTransition *, int type, const char *)
Symbol * looksym(const char *, Symbol *tmplt=NULL)
KSChanTable(Vect *, double vmin, double vmax)
virtual double f(double v)
double conductance(double *state, KSState *st)
virtual double cur(double g, double *p, Datum *pd, double v)
virtual double jacob(double *p, Datum *pd, double v)
virtual double cur(double g, double *p, Datum *pd, double v)
virtual double jacob(double *p, Datum *pd, double v)
virtual double cur(double g, double *p, Datum *pd, double v)
virtual double jacob(double *p, Datum *pd, double v)
virtual double cur(double g, double *p, Datum *pd, double v)
virtual double jacob(double *p, Datum *pd, double v)
virtual double jacob(double *p, Datum *pd, double v)
virtual double cur(double g, double *p, Datum *pd, double v)
virtual double jacob(double *p, Datum *pd, double v)
virtual double cur(double g, double *p, Datum *pd, double v)
void alloc(Prop *, int sindex)
void init(double v, double *s, KSSingleNodeData *snd, NrnThread *)
void state(Node *, double *, Datum *, NrnThread *)
void cv_update(Node *, double *, Datum *, NrnThread *)
static unsigned int idum_
void inftau_hh_table(int i, double &inf, double &tau)
void ab(double v, double &a, double &b)
void inftau(double v, double &inf, double &tau)
void hh_table_make(double dt, int size=200, double vmin=-100., double vmax=50.)
void setf(int direction, int type, Vect *vec, double vmin, double vmax)
const char * string() const
Symbol * hoc_table_lookup(const char *, Symlist *)
Datum * nrn_prop_datum_alloc(int type, int count, Prop *p)
double * nrn_prop_data_alloc(int type, int count, Prop *p)
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
double chkarg(int, double low, double high)
void register_mech(const char **, Pvmp, Pvmi, Pvmi, Pvmi, Pvmi, int, int)
void nrn_promote(Prop *p, int conc, int rev)
void ion_reg(const char *name, double valence)
static void update(NrnThread *)
void hoc_execerror(const char *, const char *)
Object ** hoc_temp_objvar(Symbol *symtemp, void *v)
void notify_freed_val_array(double *p, size_t size)
Symbol * hoc_install(const char *, int, double, Symlist **)
void hoc_warning(const char *, const char *)
int hoc_is_double_arg(int narg)
char ** hoc_temp_charptr(void)
void hoc_obj_ref(Object *obj)
char * hoc_object_name(Object *ob)
Symbol * hoc_lookup(const char *)
int hoc_is_pdouble_arg(int narg)
double * hoc_pgetarg(int narg)
void hoc_obj_unref(Object *obj)
void * erealloc(void *ptr, size_t n)
void hoc_unlink_symbol(Symbol *, Symlist *)
Object ** hoc_objgetarg(int)
Symlist * hoc_top_level_symlist
Symlist * hoc_built_in_symlist
Object ** vector_temp_objvar(Vect *v)
static double ks_gmax(void *v)
static double ks_setstructure(void *v)
static const char ** ks_ion(void *v)
static void nrn_init(NrnThread *nt, Memb_list *ml, int type)
static double kst_set_f(void *v)
static double hoc_nsingle(void *v)
static Symbol * ksgate_sym
static void nrn_cur(NrnThread *nt, Memb_list *ml, int type)
static void nrn_jacob(NrnThread *nt, Memb_list *ml, int type)
static double ks_ngate(void *v)
static double ks_remove_transition(void *v)
static double ksg_nstate(void *v)
static void * kst_cons(Object *o)
static Object ** ks_state(void *v)
static Object ** ks_add_hhstate(void *v)
static double kst_index(void *v)
static double kst_ftype(void *v)
static int ode_count(int type)
static Object ** kst_src(void *v)
static double kst_inftau(void *v)
static const char * m_kschan[9]
static double ks_rseed(void *v)
static Member_ret_obj_func kst_omem[]
static Member_ret_str_func ksg_smem[]
static double ks_single(void *v)
static double ks_remove_state(void *v)
static Member_ret_str_func kst_smem[]
static void ksg_destruct(void *)
static double hoc_has_loc(void *v)
static Member_ret_obj_func ksg_omem[]
static void nrn_state(NrnThread *nt, Memb_list *ml, int type)
static double hoc_get_loc_pnt(void *v)
static Object ** kst_target(void *v)
static double kss_index(void *v)
static double ks_erev(void *v)
static Object ** kss_gate(void *v)
static void ks_destruct(void *)
static Object ** ks_gate(void *v)
std::vector< KSChan * > KSChanList
static double kst_stoichiometry(void *v)
static Member_ret_str_func kss_smem[]
static double ks_usetable(void *v)
static Member_func kst_dmem[]
static Object ** ks_add_ksstate(void *v)
static void * ks_cons(Object *o)
static void hoc_destroy_pnt(void *v)
static Symbol * ksstate_sym
static double kst_f(void *v)
static double ksg_power(void *v)
char * hoc_symbol_units(Symbol *, const char *)
static void check_table_thread_(double *p, Datum *ppvar, Datum *thread, NrnThread *vnt, int type)
static void * kss_cons(Object *o)
static double ksg_sindex(void *v)
static double ks_is_point(void *v)
static Member_func ks_dmem[]
static void ode_spec(NrnThread *, Memb_list *ml, int type)
static const char ** kss_name(void *v)
static double ksg_index(void *v)
static double kst_ab(void *v)
static Object ** kst_parm(void *v)
static double ks_vres(void *v)
static double ks_nligand(void *v)
static const char * m_kschan_pat[]
static double hoc_loc_pnt(void *v)
static void check_objtype(Object *o, Symbol *s)
static int ksusing(int type)
void nrn_mk_table_check()
static double ks_nstate(void *v)
static void singchan(NrnThread *nt, Memb_list *ml, int type)
static Member_func kss_dmem[]
static Object ** temp_objvar(const char *name, void *v, Object **obp)
static double kss_frac(void *v)
static double kst_type(void *v)
static Object ** ks_add_transition(void *v)
static void * hoc_create_pnt(Object *ho)
static void chkobj(void *v)
spREAL * spGetElement(char *, int, int)
static void unref(Object *obj)
static void nrn_alloc(Prop *prop)
static Object ** ks_trans(void *v)
static void kst_destruct(void *)
static const char ** ks_ligand(void *v)
static double ks_pr(void *v)
static KSChanList * channels
static void * ksg_cons(Object *o)
static Member_func ksg_dmem[]
static void ode_matsol(NrnThread *nt, Memb_list *ml, int type)
void kschan_cvode_single_update()
static Member_ret_str_func ks_smem[]
static double ks_iv_type(void *v)
static void ode_map(int ieq, double **pv, double **pvdot, double *p, Datum *pd, double *atol, int type)
static const char ** kst_ligand(void *v)
static const char ** ks_name(void *v)
static Symbol * kstrans_sym
static Member_ret_obj_func kss_omem[]
static Member_func member_func[]
static double ks_ntrans(void *v)
static Member_ret_obj_func ks_omem[]
static void kss_destruct(void *)
Object ** hoc_temp_objptr(Object *)
#define ITERATE(itm, lst)
Prop * prop_alloc(Prop **, int, Node *)
double nrn_ion_charge(Symbol *)
int const size_t const size_t n
void destroy_point_process(void *)
double loc_point_process(int, void *)
double has_loc_point(void *)
void * create_point_process(int, Object *)
double get_loc_point_process(void *)
Prop * need_memb(Symbol *)
void * hoc_Emalloc(size_t size)
void hoc_register_cvode(int i, nrn_ode_count_t cnt, nrn_ode_map_t map, Pvmi spec, Pvmi matsol)
int point_register_mech(const char **m, Pvmp alloc, Pvmi cur, Pvmi jacob, Pvmi stat, Pvmi initialize, int nrnpointerindex, int vectorized, void *(*constructor)(Object *), void(*destructor)(void *), Member_func *fmember)
void class2oc(const char *, void *(*cons)(Object *), void(*destruct)(void *), Member_func *, int(*checkpoint)(void **), Member_ret_obj_func *, Member_ret_str_func *)
static philox4x32_key_t k
static void * vmin(NrnThread *nt)
static double remove(void *v)
void(* thread_table_check_)(double *, Datum *, Datum *, NrnThread *, int)
Represent main neuron object computed by single thread.
short cpublic
Note: public is a reserved keyword.
HocStruct Symbol ** ppsym
struct Symbol::@37::@38 rng
HocStruct cTemplate * ctemplate
char * strstr(char *cs, char *ct)