{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/justas/anaconda2/envs/p27/lib/python2.7/site-packages/h5py/__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n", " from ._conv import register_converters as _register_converters\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Could not load NEURONBackend\n" ] } ], "source": [ "from neuronunit.tests.druckmann2013 import AP1AmplitudeTest, AP1DelayMeanStrongStimTest\n", "from neuronunit.models.neuron_cell import NeuronCellModel\n", "import os\n", "import requests\n", "import quantities as pq" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def download_extract_compile_model(nmldb_modelid):\n", " # Get info about the model from NMLDB API\n", " model_info_url = \"https://neuroml-db.org/api/model?id=\"+nmldb_modelid\n", " model_info = requests.get(model_info_url).json()\n", "\n", " # Download model from NMLDB\n", " os.system('wget -O model.zip \"https://neuroml-db.org/GetModelZip?modelID='+nmldb_modelid+'&version=NeuroML\"')\n", "\n", " # Unzip the model to sub dir\n", " os.system(\"unzip -o model.zip -d \" + nmldb_modelid)\n", "\n", " # Change the CWD to the model dir\n", " os.chdir(nmldb_modelid)\n", "\n", " # Convert NML to NEURON using jNeuroML\n", " cell_file_name = model_info[\"model\"][\"File_Name\"]\n", "\n", " os.system(\"jnml \"+cell_file_name+\" -neuron -nogui\")\n", "\n", " # Compile any .mod files\n", " os.system(\"nrnivmodl\")\n", " \n", " return model_info\n", "\n", "\n", "def get_hoc_files():\n", " return [f for f in os.listdir('.') if f.endswith(\".hoc\")]\n", "\n", "def get_mod_files():\n", " return [f for f in os.listdir('.') if f.endswith(\".mod\")]\n", " \n", "def is_abstract_cell():\n", " return len(get_hoc_files()) == 0 and len(get_mod_files()) == 1\n", "\n", "def get_abstract_cell(h):\n", " cell_mod_file = get_mod_files()[0]\n", " cell_mod_name = cell_mod_file.replace(\".mod\", \"\")\n", "\n", " soma = h.Section()\n", " soma.L = 10\n", " soma.diam = 10\n", " soma.cm = 318.31927 # Magic number, see: https://github.com/NeuroML/org.neuroml.export/issues/60\n", "\n", " mod = getattr(h, cell_mod_name)(0.5, sec=soma)\n", "\n", " return soma, mod\n", "\n", "def get_cell_with_morphology(h):\n", " cell_hoc_file = get_hoc_files()[0]\n", " cell_template = cell_hoc_file.replace(\".hoc\", \"\")\n", " h.load_file(cell_hoc_file)\n", " cell = getattr(h, cell_template)()\n", " return cell\n", "\n", "def get_soma(h):\n", " # Get the root sections and try to find the soma\n", " roots = h.SectionList()\n", " roots.allroots()\n", " roots = [s for s in roots]\n", " somas = [sec for sec in roots if \"soma\" in sec.name().lower()]\n", " if len(somas) == 1:\n", " return somas[0]\n", " elif len(somas) == 0 and len(roots) == 1:\n", " return roots[0]\n", " else:\n", " raise Exception(\"Problem finding the soma section\")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "# 29 is mitral cell, 28 granule. For more see: https://neuroml-db.org/search_model?q=olfactory\n", "model_info = download_extract_compile_model(nmldb_modelid = 'NMLCL001128') " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\t1 \n" ] }, { "data": { "text/plain": [ "1.0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Load model in NEURON\n", "from neuron import h,gui\n", "\n", "if is_abstract_cell():\n", " cell, mod = get_abstract_cell(h)\n", "else:\n", " cell = get_cell_with_morphology(h)\n", "\n", "soma = get_soma(h)\n", "\n", "h.cvode_active(1)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Create a NeuronUnit model from the NEURON model\n", "name = model_info[\"model\"][\"Name\"]\n", "temp = model_info[\"publication\"][\"record\"][\"Temperature\"]\n", "\n", "cell_model = NeuronCellModel(soma(0.5), name=name)\n", "cell_model.set_stop_time(3000*pq.ms)\n", "cell_model.set_temperature(temp)\n", "\n", "h.newPlotV() # optional" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "#Get the Druckmann2013 \"standard\" and \"strong\" currents\n", "rheobase = model_info[\"model\"][\"Rheobase_High\"] * pq.nA\n", "\n", "standard = rheobase * 1.5\n", "strong = rheobase * 3.0\n", "\n", "temp = model_info[\"publication\"][\"record\"][\"Temperature\"]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\t-55.325344 \n" ] }, { "data": { "text/plain": [ "{'mean': array([50.6126289]) * mV, 'n': 1, 'std': 0}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Druckmann standard current test\n", "test = AP1AmplitudeTest(current_amplitude=standard, observation={\"mean\":30*pq.mV,\"std\":5*pq.mV, \"n\":1})\n", "test.generate_prediction(cell_model)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{'mean': array(8.) * ms, 'n': 1, 'std': 0}" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Another test using the strong current\n", "test = AP1DelayMeanStrongStimTest(current_amplitude=strong, observation={\"mean\":100*pq.ms,\"std\":5*pq.ms, \"n\":1})\n", "test.params[\"repetitions\"] = 1\n", "\n", "test.generate_prediction(cell_model)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.14" }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }