3 #include <structmember.h>
9 #define M_PI (3.14159265358979323846)
27 extern PyObject*
nrn_ptr_richcmp(
void* self_ptr,
void* other_ptr,
int op);
107 extern PyObject*
nrnpy_forall(PyObject*
self, PyObject* args);
126 extern char* (*nrnpy_pysec_name_p_)(
Section*);
136 PyErr_SetString(PyExc_ReferenceError,
"can't access a deleted section");
140 static char buf[512];
144 char* cp =
buf + strlen(
buf);
158 PyObject* cell_weakref =
161 PyObject*
cell = PyWeakref_GetObject(cell_weakref);
165 }
else if (
cell != Py_None) {
177 if (!PyObject_HasAttrString(obj,
"sec")) {
181 obj_sec = PyObject_GetAttrString(obj,
"sec");
183 result = PyObject_RichCompareBool(
sec, obj_sec, Py_EQ);
190 PyObject* cell_weakref =
193 PyObject*
cell = PyWeakref_GetObject(cell_weakref);
210 delete[]
self->name_;
212 Py_XDECREF(self->cell_weakref_);
213 if (self->sec_->prop) {
216 if (self->sec_->prop && !self->sec_->prop->dparam[0].sym) {
217 sec_free(self->sec_->prop->dparam[8].itm);
222 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
227 Py_XDECREF(self->pysec_);
228 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
233 Py_XDECREF(self->pysec_);
234 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
239 Py_XDECREF(self->pysec_);
240 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
245 Py_XDECREF(self->pymech_);
246 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
251 Py_XDECREF(self->pyseg_);
252 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
257 Py_XDECREF(self->pyseg_);
258 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
263 Py_XDECREF(self->pymech_);
264 ((PyObject*)
self)->ob_type->tp_free((PyObject*)
self);
279 static const char* kwlist[] = {
"name",
"cell",
NULL};
280 if (
self !=
NULL && !self->sec_) {
282 delete[]
self->name_;
285 self->cell_weakref_ = 0;
290 if (!PyArg_ParseTupleAndKeywords(args, kwds,
"|sO", (
char**) kwlist, &
name, &
cell)) {
294 self->cell_weakref_ = PyWeakref_NewRef(
cell,
NULL);
295 if (!self->cell_weakref_) {
302 size_t n = strlen(
name) + 1;
309 Py_XDECREF(self->cell_weakref_);
315 str.
set_pyerr(PyExc_TypeError,
"cell name contains non ascii character");
318 char* cp = str.
c_str();
320 self->name_ =
new char[
n];
323 self->name_ =
new char[
n];
324 strcpy(self->name_,
name);
336 if (
self !=
NULL && !self->pysec_) {
340 self->allseg_iter_ = 0;
341 self->pysec_ = pysec;
357 return (PyObject*)
self;
370 return (PyObject*)
self;
380 if (!PyArg_ParseTuple(args,
"O!d",
psection_type, &pysec, &x)) {
383 if (x > 1.0 && x < 1.0001) {
386 if (x < 0. || x > 1.0) {
387 PyErr_SetString(PyExc_ValueError,
"segment position range is 0 <= x <= 1");
394 self->pysec_ = pysec;
396 Py_INCREF(self->pysec_);
398 return (PyObject*)
self;
411 self->pyseg_ = pyseg;
412 Py_INCREF(self->pyseg_);
414 return (PyObject*)
self;
421 self->pymech_ =
NULL;
424 self->attr_from_sec_ = 0;
426 return (PyObject*)
self;
433 if (!PyArg_ParseTuple(args,
"O!d",
psection_type, &pysec, &x)) {
436 if (x > 1.0 && x < 1.0001) {
439 if (x < 0. || x > 1.0) {
440 PyErr_SetString(PyExc_ValueError,
"segment position range is 0 <= x <= 1");
445 Py_DECREF(self->pysec_);
447 self->pysec_ = pysec;
485 if (!(*psec)->prop) {
486 hoc_execerr_ext(
"nrn.Segment associated with deleted internal Section");
493 bool free_po =
false;
495 hoc_execerror(
"not a Python nrn.Segment, rxd.node, or other with a segment property", 0);
499 if (PyList_Check(po)) {
500 if (PyList_Size(po) != 1) {
501 hoc_execerror(
"If a list is supplied, it must be of length 1", 0);
503 PyObject* old_po = po;
505 po = PyList_GetItem(po, 0);
510 if (!PyObject_HasAttrString(po,
"segment")) {
514 hoc_execerror(
"not a Python nrn.Segment, rxd.node, or other with a segment property",
519 po = PyObject_GetAttrString(obj,
"segment");
533 if (!(*psec)->prop) {
534 hoc_execerr_ext(
"nrn.Segment associated with deleted internal Section");
546 Py_XDECREF(self->pyseg_);
547 self->pyseg_ = pyseg;
570 if (!PyArg_ParseTuple(args,
"i", &i0)) {
573 if (i0 < 0 || i0 >=
sec->npt3d) {
574 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
586 Py_ssize_t
narg = PyTuple_GET_SIZE(args);
588 if (!PyArg_ParseTuple(args,
"i", &req)) {
593 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
604 double x, y, z, diam;
605 Py_ssize_t
narg = PyTuple_GET_SIZE(args);
607 if (!PyArg_ParseTuple(args,
"id", &
i, &diam)) {
610 if (i < 0 || i >=
sec->npt3d) {
611 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
615 }
else if (
narg == 5) {
616 if (!PyArg_ParseTuple(args,
"idddd", &
i, &x, &y, &z, &diam)) {
619 if (i < 0 || i >=
sec->npt3d) {
620 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
625 PyErr_SetString(PyExc_Exception,
"Wrong number of arguments\n");
636 if (!PyArg_ParseTuple(args,
"idddd", &
i, &x, &y, &z, &d)) {
639 if (i < 0 || i >
sec->npt3d) {
640 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
652 if (!PyArg_ParseTuple(args,
"dddd", &x, &y, &z, &d)) {
664 Py_ssize_t
narg = PyTuple_GET_SIZE(args);
668 if (!PyArg_ParseTuple(args,
"i", &style)) {
672 PyErr_SetString(PyExc_AttributeError,
"If exactly one argument, it must be 0.");
676 }
else if (
narg == 4) {
679 if (!PyArg_ParseTuple(args,
"iddd", &style, &x, &y, &z)) {
685 PyErr_SetString(PyExc_Exception,
"Wrong number of arguments.");
690 if (
sec->logical_connection) {
701 if (!PyArg_ParseTuple(args,
"i", &
i)) {
705 if (i < 0 || i >
n) {
706 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
709 return PyFloat_FromDouble((
double)
sec->pt3d[
i].x);
717 if (!PyArg_ParseTuple(args,
"i", &
i)) {
721 if (i < 0 || i >
n) {
722 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
725 return PyFloat_FromDouble((
double)
sec->pt3d[
i].y);
733 if (!PyArg_ParseTuple(args,
"i", &
i)) {
737 if (i < 0 || i >
n) {
738 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
741 return PyFloat_FromDouble((
double)
sec->pt3d[
i].z);
750 if (!PyArg_ParseTuple(args,
"i", &
i)) {
754 if (i < 0 || i >
n) {
755 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
758 return PyFloat_FromDouble((
double)
sec->pt3d[
i].arc);
766 if (!PyArg_ParseTuple(args,
"i", &
i)) {
770 if (i < 0 || i >
n) {
771 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
774 return PyFloat_FromDouble((
double)
fabs(
sec->pt3d[
i].d));
783 if (!PyArg_ParseTuple(args,
"i", &
i)) {
787 if (i < 0 || i >
n) {
788 PyErr_SetString(PyExc_Exception,
"Arg out of range\n");
791 if (
sec->pt3d[
i].d < 0) {
809 char*
name =
new char[strlen(sname) + 100];
829 if (!PyArg_ParseTuple(args,
"O", &po)) {
832 if (PyCallable_Check(po) == 0) {
833 PyErr_SetString(PyExc_TypeError,
"argument must be a callable");
848 PyObject* arglist = Py_BuildValue(
"(O)",
self);
859 if (self->sec_->prop && self->sec_->prop->dparam[
PROP_PY_INDEX]._pvoid) {
891 return (PyObject*) seg;
916 for (psec =
sec->parentsec; psec; psec = psec->
parentsec) {
939 return Py_BuildValue(
"d", x);
947 if (PyList_Append(
sl, item) != 0) {
955 for (
Section* s =
sec->child; s; s = s->sibling) {
966 PyObject*
const result = PyList_New(0);
977 for (
Section* s =
sec->child; s; s = s->sibling) {
988 PyObject*
const result = PyList_New(0);
999 PyObject*
result = PyList_New(0);
1010 if (self->cell_weakref_) {
1011 result = PyWeakref_GET_OBJECT(self->cell_weakref_);
1013 }
else if (self->sec_->prop && self->sec_->prop->dparam[6].obj) {
1036 void* other_ptr = (
void*) other;
1047 void* self_ptr = (
void*) (self->sec_);
1048 void* other_ptr = (
void*) other;
1050 void* self_ptr = (
void*) (self->sec_);
1051 other_ptr = (
void*) (((
NPySecObj*) other)->sec_);
1058 Py_INCREF(Py_NotImplemented);
1059 return Py_NotImplemented;
1064 if (PyArg_ParseTuple(args,
"O", &pysec)) {
1066 if (((
NPySecObj*) pysec)->sec_ == self->sec_) {
1085 if (self->prop_ &&
nrn_is_ion(self->prop_->type)) {
1095 result = (PyObject*) (self->pyseg_);
1122 PyErr_SetString(PyExc_ReferenceError,
"no Symbol");
1130 if (self->pymech_) {
1131 result = (PyObject*) self->pymech_;
1141 double parentx, childend;
1144 if (!PyArg_ParseTuple(args,
"O|dd", &
p, &parentx, &childend)) {
1149 if (parentx == -1000.) {
1154 if (parentx != -1000.) {
1159 PyErr_SetString(PyExc_TypeError,
"first arg not a nrn.Section or nrn.Segment");
1165 if (parentx > 1. || parentx < 0.) {
1166 PyErr_SetString(PyExc_ValueError,
"out of range 0 <= parentx <= 1.");
1169 if (childend != 0. && childend != 1.) {
1170 PyErr_SetString(PyExc_ValueError,
"child connection end must be 0 or 1");
1179 return (PyObject*)
self;
1185 PyObject *tpyobj, *tpyobj2;
1186 if (!PyArg_ParseTuple(args,
"s", &tname)) {
1189 if (PyArg_ParseTuple(args,
"O", &tpyobj)) {
1191 Py_INCREF((PyObject*)
self);
1192 tpyobj2 = PyObject_CallMethod(tpyobj,
"insert",
"O", (PyObject*)
self);
1194 if (tpyobj2 ==
NULL) {
1195 Py_DECREF((PyObject*)
self);
1199 "insert argument must be either a string or an object with an insert method");
1203 return (PyObject*)
self;
1206 PyErr_SetString(PyExc_TypeError,
"insert takes a single positional argument");
1209 PyObject* otype = PyDict_GetItemString(
pmech_types, tname);
1216 PyErr_SetString(PyExc_ValueError,
"argument not a density mechanism name.");
1224 return (PyObject*)
self;
1230 if (!PyArg_ParseTuple(args,
"s", &tname)) {
1233 PyObject* otype = PyDict_GetItemString(
pmech_types, tname);
1240 PyErr_SetString(PyExc_ValueError,
"argument not a density mechanism name.");
1248 return (PyObject*)
self;
1253 char* mechanism_name;
1255 if (!PyArg_ParseTuple(args,
"s", &mechanism_name)) {
1275 return (PyObject*)
self;
1283 if (segiter ==
NULL) {
1290 return (PyObject*) segiter;
1300 return (PyObject*) ai;
1305 self->allseg_iter_ = -1;
1306 return (PyObject*)
self;
1312 if (self->allseg_iter_ > n1) {
1321 seg->
pysec_ =
self->pysec_;
1322 Py_INCREF(self->pysec_);
1323 if (self->allseg_iter_ == -1) {
1325 }
else if (self->allseg_iter_ == n1) {
1328 seg->
x_ = (double(self->allseg_iter_) + 0.5) / ((
double) n1);
1330 ++
self->allseg_iter_;
1331 return (PyObject*) seg;
1337 if (self->seg_iter_ >= n1) {
1346 seg->
pysec_ =
self->pysec_;
1347 Py_INCREF(self->pysec_);
1348 seg->
x_ = (double(self->seg_iter_) + 0.5) / ((
double) n1);
1350 return (PyObject*) seg;
1357 PyObject*
result = PyList_New(0);
1362 int err = PyList_Append(
result, item);
1381 if (
sec->recalc_area_) {
1384 double x =
self->x_;
1386 if (x > 0. && x < 1.) {
1390 PyObject*
result = Py_BuildValue(
"d", a);
1396 return length * (d0 * d0 + d0 * d1 + d1 * d1);
1399 static inline double interpolate(
double x0,
double x1,
double y0,
double y1,
double xnew) {
1406 return y0 + (y1 - y0) * (xnew - x0) / (x1 - x0);
1417 if (
sec->pt3d[mid].arc < x) {
1430 if (
sec->recalc_area_) {
1433 double x =
self->x_;
1436 if (x > 0. && x < 1.) {
1438 int nseg =
sec->nnode - 1;
1440 int iseg = x * nseg;
1441 double seg_left_arc = iseg * length;
1442 double seg_right_arc = (iseg + 1) * length;
1443 if (
sec->npt3d > 1) {
1445 double left_diam =
fabs(
sec->pt3d[i_left].d);
1446 double right_diam =
fabs(
sec->pt3d[i_left + 1].d);
1447 double left_arc = seg_left_arc;
1449 sec->pt3d[i_left].arc,
sec->pt3d[i_left + 1].arc, left_diam, right_diam, left_arc);
1451 for (
i = i_left + 1;
i <
sec->npt3d &&
sec->pt3d[
i].arc < seg_right_arc;
i++) {
1454 left_arc =
sec->pt3d[
i].arc;
1455 left_diam = right_diam;
1457 if (i < sec->npt3d) {
1459 left_arc,
sec->pt3d[
i].arc, left_diam,
fabs(
sec->pt3d[
i].d), seg_right_arc);
1470 double diam =
p->param[0];
1471 a =
M_PI * diam * diam / 4 * length;
1477 PyObject*
result = Py_BuildValue(
"d", a);
1485 if (
sec->recalc_area_) {
1493 PyObject*
result = Py_BuildValue(
"d",
ri);
1517 PyErr_SetString(PyExc_ReferenceError,
"nrn.Segment can't access a deleted section");
1527 return (PyObject*) m;
1572 }
else if (err == 1) {
1577 PyErr_SetString(PyExc_AttributeError,
buf);
1599 char*
n =
name.c_str();
1601 name.set_pyerr(PyExc_TypeError,
"attribute name must be a string");
1607 if (strcmp(
n,
"L") == 0) {
1609 }
else if (strcmp(
n,
"Ra") == 0) {
1611 }
else if (strcmp(
n,
"nseg") == 0) {
1612 result = Py_BuildValue(
"i",
sec->nnode - 1);
1628 result = Py_BuildValue(
"d", *d);
1631 }
else if (strcmp(
n,
"rallbranch") == 0) {
1632 result = Py_BuildValue(
"d",
sec->prop->dparam[4].val);
1633 }
else if (strcmp(
n,
"__dict__") == 0) {
1635 int err = PyDict_SetItemString(
result,
"L", Py_None);
1637 err = PyDict_SetItemString(
result,
"Ra", Py_None);
1639 err = PyDict_SetItemString(
result,
"nseg", Py_None);
1641 err = PyDict_SetItemString(
result,
"rallbranch", Py_None);
1644 result = PyObject_GenericGetAttr((PyObject*)
self, pyname);
1653 PyErr_SetString(PyExc_ReferenceError,
"can't access a deleted section");
1660 char*
n =
name.c_str();
1662 name.set_pyerr(PyExc_TypeError,
"attribute name must be a string");
1667 if (strcmp(
n,
"L") == 0) {
1669 if (PyArg_Parse(
value,
"d", &x) == 1 && x > 0.) {
1671 sec->prop->dparam[2].val = x;
1674 sec->recalc_area_ = 1;
1677 PyErr_SetString(PyExc_ValueError,
"L must be > 0.");
1680 }
else if (strcmp(
n,
"Ra") == 0) {
1682 if (PyArg_Parse(
value,
"d", &x) == 1 && x > 0.) {
1683 sec->prop->dparam[7].val = x;
1685 sec->recalc_area_ = 1;
1687 PyErr_SetString(PyExc_ValueError,
"Ra must be > 0.");
1690 }
else if (strcmp(
n,
"nseg") == 0) {
1692 if (PyArg_Parse(
value,
"i", &nseg) == 1 && nseg > 0 && nseg <= 32767) {
1695 PyErr_SetString(PyExc_ValueError,
"nseg must be an integer in range 1 to 32767");
1703 PyErr_SetString(PyExc_IndexError,
"missing index");
1711 }
else if (!PyArg_Parse(
value,
"d", d)) {
1712 PyErr_SetString(PyExc_ValueError,
"bad value");
1719 }
else if (strcmp(
n,
"rallbranch") == 0) {
1721 if (PyArg_Parse(
value,
"d", &x) == 1 && x > 0.) {
1722 sec->prop->dparam[4].val = x;
1724 sec->recalc_area_ = 1;
1726 PyErr_SetString(PyExc_ValueError,
"rallbranch must be > 0");
1730 err = PyObject_GenericSetAttr((PyObject*)
self, pyname,
value);
1746 m->
pyseg_ =
self->pyseg_;
1749 self->prop_ =
p->next;
1750 return (PyObject*) m;
1756 PyErr_SetString(PyExc_ReferenceError,
"nrn.Mechanism can't access a deleted section");
1769 return (PyObject*) vmi;
1773 if (self->i_ >= self->msym_->s_varn) {
1785 return (PyObject*) r;
1791 PyErr_SetString(PyExc_ReferenceError,
"nrn.Segment can't access a deleted section");
1797 char*
n =
name.c_str();
1799 name.set_pyerr(PyExc_TypeError,
"attribute name must be a string");
1805 PyObject* otype =
NULL;
1806 PyObject* rv =
NULL;
1807 if (strcmp(
n,
"v") == 0) {
1850 result = Py_BuildValue(
"d", *d);
1853 }
else if (strncmp(
n,
"_ref_", 5) == 0) {
1854 if (strcmp(
n + 5,
"v") == 0) {
1858 sym->
type == RANGEVAR) {
1882 }
else if (strcmp(
n,
"__dict__") == 0) {
1885 int err = PyDict_SetItemString(
result,
"v", Py_None);
1887 PyDict_SetItemString(
result,
"diam", Py_None);
1889 PyDict_SetItemString(
result,
"cm", Py_None);
1894 err = PyDict_SetItemString(
result, pn, Py_None);
1899 result = PyObject_GenericGetAttr((PyObject*)
self, pyname);
1909 double** ppd = &
prop->dparam[sym->
u.
rng.index].pval;
1914 PyErr_SetString(PyExc_ValueError,
"must be a hoc pointer");
1918 PyErr_SetString(PyExc_AttributeError,
1919 " For assignment, only POINTER var can have a _ref_ prefix");
1928 PyErr_SetString(PyExc_ReferenceError,
"nrn.Segment can't access a deleted section");
1936 char*
n =
name.c_str();
1938 name.set_pyerr(PyExc_TypeError,
"attribute name must be a string");
1943 if (strcmp(
n,
"x") == 0) {
1946 if (PyArg_Parse(
value,
"d", &x) == 1 && x > 0. && x <= 1.) {
1949 }
else if (x > 1. - 1
e-9) {
1955 PyErr_SetString(PyExc_ValueError,
"x must be in range 0. to 1.");
1962 sprintf(s,
"%s needs an index for assignment", sym->
name);
1963 PyErr_SetString(PyExc_IndexError, s);
1973 if (!PyArg_Parse(
value,
"d", d)) {
1974 PyErr_SetString(PyExc_ValueError,
"bad value");
1979 sec->recalc_area_ = 1;
1981 }
else if (sym->
u.
rng.type == EXTRACELL && sym->
u.
rng.index == 0) {
1986 }
else if (strncmp(
n,
"_ref_", 5) == 0) {
1988 if (rvsym && rvsym->
type == RANGEVAR) {
1995 err = PyObject_GenericSetAttr((PyObject*)
self, pyname,
value);
1998 err = PyObject_GenericSetAttr((PyObject*)
self, pyname,
value);
2005 int nlen = strlen(
n);
2006 int mlen = strlen(m);
2007 int u = nlen - mlen - 1;
2008 if (u > 0 &&
n[u] ==
'_') {
2009 if (strcmp(
n + (u + 1), m) != 0) {
2012 strncpy(
buf,
n, sz);
2022 PyErr_SetString(PyExc_ReferenceError,
"nrn.Mechanism can't access a deleted section");
2028 char*
n =
name.c_str();
2030 name.set_pyerr(PyExc_TypeError,
"attribute name must be a string");
2037 int isptr = (strncmp(
n,
"_ref_", 5) == 0);
2039 int mnamelen = strlen(mname);
2040 int bufsz = strlen(
n) + mnamelen + 2;
2041 char*
buf =
new char[bufsz];
2043 strcpy(
buf, isptr ?
n + 5 :
n);
2054 Py_INCREF(self->pyseg_);
2066 result = Py_BuildValue(
"d", *px);
2069 }
else if (strcmp(
n,
"__dict__") == 0) {
2073 strcpy(
buf, s->name);
2075 int err = PyDict_SetItemString(
result,
buf, Py_None);
2079 result = PyObject_GenericGetAttr((PyObject*)
self, pyname);
2089 PyErr_SetString(PyExc_ReferenceError,
"nrn.Mechanism can't access a deleted section");
2096 char*
n =
name.c_str();
2098 name.set_pyerr(PyExc_TypeError,
"attribute name must be a string");
2104 int isptr = (strncmp(
n,
"_ref_", 5) == 0);
2106 int mnamelen = strlen(mname);
2107 int bufsz = strlen(
n) + mnamelen + 2;
2108 char*
buf =
new char[bufsz];
2110 strcpy(
buf, isptr ?
n + 5 :
n);
2123 if (PyArg_Parse(
value,
"d", &x) == 1) {
2126 PyErr_SetString(PyExc_ValueError,
"must be a double");
2135 err = PyObject_GenericSetAttr((PyObject*)
self, pyname,
value);
2149 char*
n =
name.c_str();
2164 PyArg_ParseTuple(args,
"|d", &x);
2165 PyObject* segargs = Py_BuildValue(
"(O,d)",
self, x);
2184 PyErr_SetString(PyExc_ReferenceError,
"nrn.RangeVar can't access a deleted section");
2189 if (ix < 0 || ix >=
rv_len(
self)) {
2190 PyErr_SetString(PyExc_IndexError, r->
sym_->
name);
2203 result = Py_BuildValue(
"d", *d);
2211 PyErr_SetString(PyExc_ReferenceError,
"nrn.RangeVar can't access a deleted section");
2215 if (ix < 0 || ix >=
rv_len(
self)) {
2216 PyErr_SetString(PyExc_IndexError, r->
sym_->
name);
2229 if (!PyArg_Parse(
value,
"d", &x)) {
2230 PyErr_SetString(PyExc_ValueError,
"bad value");
2237 if (!PyArg_Parse(
value,
"d", d)) {
2238 PyErr_SetString(PyExc_ValueError,
"bad value");
2249 {
"name", (PyCFunction)
NPySecObj_name, METH_NOARGS,
"Section name (same as hoc secname())"},
2250 {
"hname", (PyCFunction)
NPySecObj_name, METH_NOARGS,
"Section name (same as hoc secname())"},
2254 "Returns True if the section's membrane has this density mechanism.\nThis "
2255 "is not for point processes."},
2259 "childSection.connect(parentSection, [parentX], [childEnd]) "
2260 "or\nchildSection.connect(parentSegment, [childEnd])"},
2264 "section.insert(densityMechanismName) e.g. soma.insert('hh')"},
2268 "section.uninsert(densityMechanismName) e.g. soma.insert('hh')"},
2272 "section.push() makes it the currently accessed section. Should end with "
2273 "a corresponding hoc.pop_section()"},
2277 "iterate over segments. Includes x=0 and x=1 zero-area nodes in the "
2282 "Return the object that owns the Section. Possibly None."},
2286 "sec1.same(sec2) returns True if sec1 and sec2 wrap the same NEURON "
2288 {
"hoc_internal_name",
2291 "Hoc accepts this name wherever a section is syntactically valid."},
2295 "disconnect from the parent section."},
2299 "Return the nrn.Segment specified by the connect method. Possibly None."},
2303 "Return the nrn.Segment this section connects to which is closer to the "
2304 "root. Possibly None. (same as parentseg unless parentseg.x == "
2305 "parentseg.sec.orientation()"},
2309 "Returns 0.0 or 1.0 depending on the x value closest to parent."},
2313 "Return list of child sections. Possibly an empty list"},
2317 "Return list of sections in the subtree rooted at this section (including this section)."},
2321 "Return list of all sections with a path to this section (including this section). The list "
2322 "has the important property that sections are in root to leaf order, depth-first traversal."},
2323 {
"n3d", (PyCFunction)
NPySecObj_n3d, METH_NOARGS,
"Returns the number of 3D points."},
2327 "Returns the x coordinate of the ith 3D point."},
2331 "Returns the y coordinate of the ith 3D point."},
2335 "Returns the z coordinate of the ith 3D point."},
2339 "Returns the arc position of the ith 3D point."},
2343 "Returns the diam of the ith 3D point."},
2347 "Returns True or False depending on whether a spine exists at the ith 3D point."},
2352 "Clears all 3D points. Optionally takes a buffer size."},
2356 "Insert the point (so it becomes the i'th point) to section. If i is equal to sec.n3d(), the "
2357 "point is appended (equivalent to sec.pt3dadd())"},
2361 "Change the i'th 3-d point info. If only two args then the second arg is the diameter and the "
2362 "location is unchanged."},
2366 "Add the 3d location and diameter point (or points in the second form) at the end of the "
2367 "current pt3d list. Assume that successive additions increase the arc length monotonically."},
2371 "Returns True if using a logical connection point, else False. With first arg 0 sets to no "
2372 "logical connection point. With first arg 1 and x, y, z arguments, sets the logical "
2373 "connection point. Return value includes the result of any setting."},
2377 "Returns True if Section created from Python, False if created from HOC."},
2381 "Returns dict of info about Section contents."},
2388 "seg.point_processes() returns list of POINT_PROCESS instances in the "
2393 "seg.node_index() returns index of v, rhs, etc. in the _actual arrays of "
2394 "the appropriate NrnThread."},
2398 "Segment area (um2) (same as h.area(sec(x), sec=sec))"},
2402 "Segment resistance to parent segment (Megohms) (same as h.ri(sec(x), "
2404 {
"volume", (PyCFunction)
seg_volume, METH_NOARGS,
"Segment volume (um3)"},
2413 char* s2 =
new char[strlen(s) + 1];
2422 cpstr(
"location in the section (segment containing x)")},
2430 "Mechanism name (same as hoc suffix for density mechanism)"},
2431 {
"is_ion", (PyCFunction)
NPyMechObj_is_ion, METH_NOARGS,
"Returns True if an ion mechanism"},
2435 "Returns the segment of the Mechanism instance"},
2439 {
"name", (PyCFunction)
NPyRangeVar_name, METH_NOARGS,
"Range variable name name"},
2443 "Returns nrn.Mechanism of the RangeVariable instance"},
2451 PyErr_SetString(PyExc_TypeError,
"Section access unspecified");
2459 {
"cas",
nrnpy_cas, METH_VARARGS,
"Return the currently accessed section."},
2460 {
"allsec",
nrnpy_forall, METH_VARARGS,
"Return iterator over all sections."},
2464 "Specify the nrn.Section.psection callback."},
2486 PyObject* modules = PyImport_GetModuleDict();
2487 if ((m = PyDict_GetItemString(modules,
"nrn")) !=
NULL && PyModule_Check(m)) {
2526 PyModule_AddObject(m,
"Section", (PyObject*)
psection_type);
2527 PyModule_AddObject(m,
"Segment", (PyObject*)
psegment_type);
2529 err = PyDict_SetItemString(modules,
"_neuron_section", m);
2534 PyModule_AddObject(m,
"Section", (PyObject*)
psection_type);
2535 PyModule_AddObject(m,
"Segment", (PyObject*)
psegment_type);
2566 err = PyDict_SetItemString(modules,
"nrn", m);
double nrn_section_orientation(Section *sec)
const char * secname(Section *sec)
void nrn_rangeconst(Section *sec, Symbol *s, double *pd, int op)
void nrn_pushsec(Section *sec)
double nrn_arc_position(Section *sec, Node *node)
Prop * nrn_mechanism(int type, Node *nd)
double nrn_connection_position(Section *sec)
void nrn_disconnect(Section *sec)
Node * node_exact(Section *sec, double x)
int nrn_at_beginning(Section *sec)
int prop_index(const Symbol *) const
Symbol * find(const char *rangevar)
double * prop_pval(const Symbol *, int arrayindex=0) const
void set_pyerr(PyObject *type, const char *message)
Symbol * hoc_table_lookup(const char *, Symlist *)
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)
void hoc_execerror(const char *, const char *)
void hoc_execerr_ext(const char *fmt,...)
printf style specification of hoc_execerror message.
Symbol * hoc_install(const char *, int, double, Symlist **)
Object ** hoc_temp_objptr(Object *)
void section_ref(Section *)
void section_unref(Section *)
int const size_t const size_t n
static PyTypeObject * pseg_of_sec_iter_type
static void nrnpy_unreg_mech(int)
Section *(* nrnpy_o2sec_p_)(Object *)
static PyObject * NPySecObj_pt3dstyle(NPySecObj *self, PyObject *args)
static PyObject * NPySecObj_pt3dinsert(NPySecObj *self, PyObject *args)
Object *(* nrnpy_pysec_cell_p_)(Section *)
void stor_pt3d(Section *sec, double x, double y, double z, double d)
static PyObject * pysec_wholetree(NPySecObj *const self)
PyObject * nrnpy_cas(PyObject *self, PyObject *args)
void nrn_pt3dremove(Section *sec, int i0)
static PyObject * NPySecObj_pt3dremove(NPySecObj *self, PyObject *args)
static PyObject * pysec_richcmp(NPySecObj *self, PyObject *other, int op)
short * nrn_is_artificial_
static PyObject * nrnmodule_
static void o2loc2(Object *o, Section **psec, double *px)
static PyObject * nrnpy_set_psection(PyObject *self, PyObject *args)
static PyObject * var_of_mech_next(NPyVarOfMechIter *self)
static PyObject * seg_of_section_iter(NPySecObj *self)
static PyTypeObject * pmech_of_seg_iter_generic_type
static PyObject * pysec_subtree1(PyObject *const sl, Section *const sec)
static PyTypeObject * pmech_generic_type
static PyObject * pysec_orientation(NPySecObj *self)
static PyObject * pysec_trueparentseg(NPySecObj *self)
void nrn_pt3dinsert(Section *sec, int i0, double x, double y, double z, double d)
Object * nrnpy_pyobject_in_obj(PyObject *)
static void NPySecObj_dealloc(NPySecObj *self)
static PyMethodDef NPySegObj_methods[]
static PyObject * pysec_same(NPySecObj *self, PyObject *args)
static Object * seg_from_sec_x(Section *, double x)
Object * nrnpy_po2ho(PyObject *)
static PyObject * NPySecObj_insert(NPySecObj *self, PyObject *args)
static PyObject * pysec_parentseg(NPySecObj *self)
PyTypeObject * psection_type
static PyObject * mech_of_segment_iter(NPySegObj *self)
static PyObject * NPySecObj_spine3d(NPySecObj *self, PyObject *args)
static PyObject * NPyMechObj_name(NPyMechObj *self)
static bool lappendsec(PyObject *const sl, Section *const s)
double * nrnpy_rangepointer(Section *, Symbol *, double, int *)
static PyObject * pysec_children(NPySecObj *const self)
static PyObject * NPySecObj_push(NPySecObj *self, PyObject *args)
static PyObject * NPySecObj_uninsert(NPySecObj *self, PyObject *args)
static PyObject * section_getattro(NPySecObj *self, PyObject *pyname)
void(* nrnpy_o2loc2_p_)(Object *, Section **, double *)
static void o2loc(Object *, Section **, double *)
Symbol * nrnpy_pyobj_sym_
static PyObject * NPySecObj_pt3dchange(NPySecObj *self, PyObject *args)
Section * nrn_noerr_access()
static PyObject * pyseg_repr(PyObject *p)
static PyObject * NPySecObj_connect(NPySecObj *self, PyObject *args)
static int NPySegObj_init(NPySegObj *self, PyObject *args, PyObject *kwds)
static Py_ssize_t rv_len(PyObject *self)
static int NPyAllSegOfSecIter_init(NPyAllSegOfSecIter *self, PyObject *args, PyObject *kwds)
static int NPyMechObj_init(NPyMechObj *self, PyObject *args, PyObject *kwds)
PyObject * nrnpy_hoc2pyobject(Object *)
static PyObject * pysec_subtree(NPySecObj *const self)
static PyObject * nrnpy_psection
static PyObject * pysec2cell(NPySecObj *)
static int section_setattro(NPySecObj *self, PyObject *pyname, PyObject *value)
static int segment_setattro(NPySegObj *self, PyObject *pyname, PyObject *value)
Object *(* nrnpy_seg_from_sec_x)(Section *, double x)
static PyObject * pysec_disconnect(NPySecObj *self)
void nrn_area_ri(Section *sec)
static bool striptrail(char *buf, int sz, const char *n, const char *m)
static PyObject * pysec_repr(PyObject *p)
static PyObject * NPySecObj_pt3dadd(NPySecObj *self, PyObject *args)
static void remake_pmech_types()
static PyObject * rv_getitem(PyObject *self, Py_ssize_t ix)
static PyObject * newpyseghelp(Section *sec, double x)
void simpleconnectsection()
void(* nrnpy_o2loc_p_)(Object *, Section **, double *)
cTemplate ** nrn_pnt_template_
static PyMemberDef NPyMechObj_members[]
static PyObject * NPySecObj_arc3d(NPySecObj *self, PyObject *args)
static PyTypeObject * pallseg_of_sec_iter_type
static PyTypeObject * psegment_type
static Section * o2sec(Object *)
void mech_insert1(Section *, int)
void nrn_pt3dchange2(Section *sec, int i, double x, double y, double z, double diam)
static PyObject * is_pysec(NPySecObj *self)
static double interpolate(double x0, double x1, double y0, double y1, double xnew)
static Object ** pp_get_segment(void *vptr)
static Prop * mech_of_segment_prop(Prop *p)
static PyMethodDef NPyMechObj_methods[]
static void NPySegObj_dealloc(NPySegObj *self)
static PyObject * NPyMechObj_segment(NPyMechObj *self)
static NPyRangeVar * rvnew(Symbol *sym, NPySecObj *sec, double x)
static PyObject * pyseg_richcmp(NPySegObj *self, PyObject *other, int op)
static PyObject * segment_getattro(NPySegObj *self, PyObject *pyname)
static PyObject * NPySecObj_call(NPySecObj *self, PyObject *args)
double ** nrnpy_setpointer_helper(PyObject *pyname, PyObject *mech)
PyObject * nrnpy_ho2po(Object *)
void nrn_pt3dstyle1(Section *sec, double x, double y, double z)
static void NPySegOfSecIter_dealloc(NPySegOfSecIter *self)
static PyObject * pymech_repr(PyObject *p)
static PyObject * seg_area(NPySegObj *self)
int(* nrnpy_pysec_cell_equals_p_)(Section *, Object *)
void mech_uninsert1(Section *, Symbol *)
int nrn_pointer_assign(Prop *prop, Symbol *sym, PyObject *value)
PyObject * nrnpy_newsecobj(PyObject *self, PyObject *args, PyObject *kwds)
static PyObject * hoc_internal_name(NPySecObj *self)
void nrn_pt3dchange1(Section *sec, int i, double d)
static PyMethodDef NPySecObj_methods[]
static PyObject * NPySecObj_has_membrane(NPySecObj *self, PyObject *args)
PyObject * nrnpy_nrn(void)
PyObject * NPyAllSegOfSecIter_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void NPyAllSegOfSecIter_dealloc(NPyAllSegOfSecIter *self)
static PyObject * NPySecObj_psection(NPySecObj *self)
static PyMemberDef NPySegObj_members[]
static PyObject * NPySecObj_name(NPySecObj *self)
static PyObject * seg_point_processes(NPySegObj *self)
static PyObject * NPySecObj_diam3d(NPySecObj *self, PyObject *args)
static PyObject * NPySegObj_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject * seg_of_sec_next(NPySegOfSecIter *self)
static PyObject * NPySecObj_n3d(NPySecObj *self)
PyObject * nrnpy_forall(PyObject *self, PyObject *args)
int can_change_morph(Section *)
static void NPyMechOfSegIter_dealloc(NPyMechOfSegIter *self)
static int pysec_cell_equals(Section *, Object *)
static int ob_is_seg(Object *)
void nrn_pt3dclear(Section *sec, int req)
static void NPyRangeVar_dealloc(NPyRangeVar *self)
static PyObject * seg_ri(NPySegObj *self)
static int mech_setattro(NPyMechObj *self, PyObject *pyname, PyObject *value)
static void NPyMechObj_dealloc(NPyMechObj *self)
void sec_free(hoc_Item *)
static char * pysec_name(Section *)
void nrn_diam_change(Section *)
int nrn_is_hocobj_ptr(PyObject *, double *&)
static PyObject * NPySecObj_x3d(NPySecObj *self, PyObject *args)
double section_length(Section *)
PyObject * nrnpy_pushsec(PyObject *sec)
static void NPyVarOfMechIter_dealloc(NPyVarOfMechIter *self)
static long pysec_hash(PyObject *self)
int nrnpy_ho_eq_po(Object *, PyObject *)
static PyTypeObject * pvar_of_mech_iter_generic_type
static int NPyRangeVar_init(NPyRangeVar *self, PyObject *args, PyObject *kwds)
static int rv_setitem(PyObject *self, Py_ssize_t ix, PyObject *value)
static void rv_noexist(Section *sec, const char *n, double x, int err)
static PyObject * NPyMechObj_is_ion(NPyMechObj *self)
static void rangevars_add(Symbol *sym)
void nrn_length_change(Section *, double)
static double scaled_frustum_volume(double length, double d0, double d1)
static PyMethodDef nrnpy_methods[]
Section * nrnpy_newsection(NPySecObj *)
static PyObject * NPySecObj_z3d(NPySecObj *self, PyObject *args)
static PyObject * node_index1(NPySegObj *self)
static PyObject * mech_getattro(NPyMechObj *self, PyObject *pyname)
char *(* nrnpy_pysec_name_p_)(Section *)
static int NPySecObj_init(NPySecObj *self, PyObject *args, PyObject *kwds)
static PyObject * mech_of_seg_next(NPyMechOfSegIter *self)
static PyObject * NPySecObj_y3d(NPySecObj *self, PyObject *args)
static void nrnpy_reg_mech(int)
static PyObject * seg_volume(NPySegObj *self)
void nrn_pt3dstyle0(Section *sec)
int(* nrnpy_ob_is_seg)(Object *)
static PyObject * NPyRangeVar_name(NPyRangeVar *self)
void(* nrnpy_reg_mech_p_)(int)
static PyObject * allseg_of_sec_iter(NPyAllSegOfSecIter *self)
Symlist * hoc_built_in_symlist
static PyObject * NPySecObj_pt3dclear(NPySecObj *self, PyObject *args)
static int NPySecObj_contains(PyObject *sec, PyObject *obj)
PyObject * nrn_ptr_richcmp(void *self_ptr, void *other_ptr, int op)
PyObject * nrn_hocobj_ptr(double *)
static PyObject * var_of_mech_iter(NPyMechObj *self)
PyTypeObject * hocobject_type
static long pyseg_hash(PyObject *self)
static char * cpstr(const char *s)
void nrn_change_nseg(Section *, int)
static PyObject * NPyMechObj_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int arg_bisect_arc3d(Section *sec, int npt3d, double x)
PyObject * NPySecObj_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyMethodDef NPyRangeVar_methods[]
int has_membrane(char *, Section *)
static PyObject * NPyRangeVar_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static PyObject * allseg(NPySecObj *self)
static PyTypeObject * range_type
NPySecObj * newpysechelp(Section *sec)
static Object * pysec_cell(Section *)
static PyObject * pysec_children1(PyObject *const sl, Section *const sec)
static PyObject * NPyRangeVar_mech(NPyRangeVar *self)
static PyObject * allseg_of_sec_next(NPyAllSegOfSecIter *self)
static PyType_Spec nrnpy_MechOfSegIterType_spec
static PyType_Spec nrnpy_VarOfMechIterType_spec
static PyType_Spec nrnpy_AllSegOfSecIterType_spec
static PyType_Spec nrnpy_SectionType_spec
static PyType_Spec nrnpy_SegOfSecIterType_spec
static struct PyModuleDef nrnsectionmodule
static PyType_Spec nrnpy_MechanismType_spec
static PyType_Spec nrnpy_RangeType_spec
static struct PyModuleDef nrnmodule
static PyType_Spec nrnpy_SegmentType_spec
#define CHECK_SEC_INVALID(sec)
#define PyString_FromString
static double cell(void *v)
void nrnpy_pysecname2sec_add(Section *sec)
void nrnpy_pysecname2sec_remove(Section *sec)
PyObject_HEAD NPySecObj * pysec_
PyObject_HEAD NPySegObj * pyseg_
PyObject_HEAD NPySegObj * pyseg_
PyObject_HEAD NPyMechObj * pymech_
PyObject_HEAD NPyMechObj * pymech_
PyObject_HEAD Section * sec_
PyObject_HEAD NPySecObj * pysec_
PyObject_HEAD NPySecObj * pysec_
PyObject_HEAD NPyMechObj * pymech_
struct Section * parentsec
short cpublic
Note: public is a reserved keyword.
HocStruct Symbol ** ppsym
struct Symbol::@37::@38 rng