├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ ├── ci.yml │ ├── python-publish.yml │ └── regenerate.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── AUTHORS ├── CONTRIBUTING.md ├── LICENSE ├── MANIFEST.in ├── README.md ├── doc ├── Makefile ├── _static │ └── neuroml_logo.png ├── component-list.json ├── conf.py ├── devdocs │ ├── 2012_06_26_neuroml_with_pymoose.pdf │ ├── how_to_contribute.rst │ ├── implementation_of_bindings.rst │ ├── index.rst │ ├── meeting_june_2012.rst │ ├── nodes_segments_sections.rst │ └── regenerate_docs.rst ├── helpers │ └── nml-core-docs.py ├── index.rst ├── make.bat ├── refs.bib └── userdocs │ ├── Cells_list.rst │ ├── Channels_list.rst │ ├── Inputs_list.rst │ ├── Networks_list.rst │ ├── NeuroMLCoreCompTypes_list.rst │ ├── NeuroMLCoreDimensions_list.rst │ ├── Other_list.rst │ ├── PyNN_list.rst │ ├── Simulation_list.rst │ ├── Synapses_list.rst │ ├── api.rst │ ├── arraymorph.rst │ ├── bibliography.rst │ ├── coreclasses.rst │ ├── examples.rst │ ├── index.rst │ ├── install.rst │ ├── introduction.rst │ ├── loaders.rst │ ├── utils.rst │ └── writers.rst ├── neuroml ├── __init__.py ├── __version__.py ├── arraymorph.py ├── arraymorph_load_time_benchmark.py ├── benchmarks │ └── arraymorph_benchmarks.py ├── build_time_validation.py ├── examples │ ├── arraymorph_generation.py │ ├── build_3D_network.py │ ├── build_complete.py │ ├── build_network.py │ ├── build_network2.py │ ├── ion_channel_generation.py │ ├── loading_modifying_writing.py │ ├── loading_modifying_writing_large.py │ ├── morphology_generation.py │ ├── run_all.py │ ├── single_izhikevich_reader.py │ ├── single_izhikevich_writer.py │ ├── test_files │ │ ├── AMPA_syn.synapse.nml │ │ ├── AMPA_syn_inh.synapse.nml │ │ ├── CA1.nml │ │ ├── Ca_conc.nml │ │ ├── Ca_pyr.channel.nml │ │ ├── EC2-609291-4.CNG.nml │ │ ├── GABA_syn.synapse.nml │ │ ├── GABA_syn_inh.synapse.nml │ │ ├── Kahp_pyr.channel.nml │ │ ├── Kdr_bask.channel.nml │ │ ├── Kdr_pyr.channel.nml │ │ ├── LEMS_TestComplete.xml │ │ ├── LeakConductance_bask.channel.nml │ │ ├── LeakConductance_pyr.channel.nml │ │ ├── MediumNet.net.nml │ │ ├── Na_bask.channel.nml │ │ ├── Na_pyr.channel.nml │ │ ├── Purk2M9s.nml │ │ ├── Purk2M9s_v1x.nml1 │ │ ├── SingleIzhikevich.nml │ │ ├── bask.cell.nml │ │ ├── complete.nml │ │ ├── complete.nml.h5 │ │ ├── pas_nml.channel.nml │ │ ├── pyr_4_sym.cell.nml │ │ ├── sbml-example.xml │ │ ├── simplenet.nml │ │ ├── testh5.nml │ │ └── tmp2.swc │ ├── tmp │ │ └── README │ ├── write_pynn.py │ └── write_syns.py ├── hdf5 │ ├── DefaultNetworkHandler.py │ ├── NetworkBuilder.py │ ├── NetworkContainer.py │ ├── NeuroMLHdf5Parser.py │ ├── NeuroMLXMLParser.py │ └── __init__.py ├── loaders.py ├── neuro_lex_ids.py ├── nml │ ├── NeuroML_v2.0.xsd │ ├── NeuroML_v2.1.xsd │ ├── NeuroML_v2.2.xsd │ ├── NeuroML_v2.3.1.xsd │ ├── NeuroML_v2.3.xsd │ ├── NeuroML_v2beta1.xsd │ ├── NeuroML_v2beta2.xsd │ ├── NeuroML_v2beta3.xsd │ ├── NeuroML_v2beta4.xsd │ ├── NeuroML_v2beta5.xsd │ ├── Purk2M9s.nml │ ├── README.md │ ├── __init__.py │ ├── annotate_nml.py │ ├── changed_names.csv │ ├── config.py │ ├── gds_imports-template.py │ ├── generateds_config.py │ ├── generatedscollector.py │ ├── generatedssupersuper.py │ ├── helper_methods.py │ ├── name_table.csv │ ├── nml.py │ └── regenerate-nml.sh ├── test │ ├── README │ ├── __init__.py │ ├── misc_tests.py │ ├── test_arraymorph.py │ ├── test_cell.py │ ├── test_global_validation.py │ ├── test_hdf5_optimized.py │ ├── test_hdf5_parser.py │ ├── test_integration.py │ ├── test_loaders.py │ ├── test_morphology.py │ ├── test_nml.py │ ├── test_segment.py │ ├── test_utils.py │ ├── test_writers.py │ └── test_xml_parser.py ├── utils.py └── writers.py ├── notebooks ├── CellMorphology.ipynb └── HDF5Serialisation.ipynb ├── pyproject.toml ├── pytest.ini └── setup.cfg /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[Bug]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior, for example the command you used. 15 | 16 | **Expected behavior** 17 | A clear and concise description of what you expected to happen. 18 | 19 | **Observed behavior** 20 | 21 | **System information:** 22 | - OS: [e.g. iOS] 23 | - Python version (`python --version`) 24 | - Version of tools in use (Output of `python -c 'import neuroml; print(neuroml.__version__)'`): 25 | 26 | 27 | **Additional context** 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ master, development, experimental ] 6 | pull_request: 7 | branches: [ master, development, experimental ] 8 | 9 | jobs: 10 | build: 11 | 12 | name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }} 13 | runs-on: ${{ matrix.runs-on }} 14 | strategy: 15 | fail-fast: false 16 | matrix: 17 | python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] 18 | runs-on: [ubuntu-latest, windows-latest, macos-latest] 19 | exclude: 20 | - runs-on: macos-latest 21 | python-version: "3.8" 22 | - runs-on: macos-latest 23 | python-version: "3.9" 24 | 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - name: Set up Python ${{ matrix.python-version }} 29 | uses: actions/setup-python@v5 30 | with: 31 | python-version: ${{ matrix.python-version }} 32 | 33 | - name: Install dependencies 34 | run: | 35 | #sudo apt-get install libhdf5-serial-dev liblzo2-dev libgraphviz-dev -y 36 | python -m pip install --upgrade pip 37 | 38 | - name: Install HDF5 for pytables on macos-latest 39 | if: ${{ matrix.runs-on == 'macos-latest' }} 40 | run: | 41 | brew install hdf5 42 | 43 | - name: Build package 44 | run: | 45 | pip install .[full] 46 | 47 | - name: Test with pytest 48 | if: ${{ matrix.runs-on == 'ubuntu-latest' }} 49 | run: | 50 | # Just test on linux for now... 51 | pytest -vs 52 | 53 | - name: Run examples 54 | run: | 55 | cd neuroml/examples 56 | python run_all.py 57 | 58 | - name: Final version info 59 | run: | 60 | pip list 61 | 62 | - name: Lint with flake8 63 | if: ${{ matrix.runs-on == 'ubuntu-latest' }} 64 | run: | 65 | # stop the build if there are Python syntax errors or undefined names 66 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 67 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 68 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 69 | -------------------------------------------------------------------------------- /.github/workflows/python-publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will upload a Python Package using Twine when a release is created 2 | # For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries 3 | 4 | # This workflow uses actions that are not certified by GitHub. 5 | # They are provided by a third-party and are governed by 6 | # separate terms of service, privacy policy, and support 7 | # documentation. 8 | 9 | name: Upload Python Package 10 | 11 | on: 12 | release: 13 | types: [published] 14 | 15 | jobs: 16 | deploy: 17 | 18 | runs-on: ubuntu-latest 19 | 20 | steps: 21 | - uses: actions/checkout@v3 22 | - name: Set up Python 23 | uses: actions/setup-python@v4 24 | with: 25 | python-version: '3.x' 26 | - name: Install dependencies 27 | run: | 28 | python -m pip install --upgrade pip 29 | pip install build 30 | - name: Build package 31 | run: python -m build 32 | - name: Publish package 33 | uses: pypa/gh-action-pypi-publish@release/v1 34 | with: 35 | user: __token__ 36 | password: ${{ secrets.PYPI_API_TOKEN }} 37 | -------------------------------------------------------------------------------- /.github/workflows/regenerate.yml: -------------------------------------------------------------------------------- 1 | name: Regenerate nml.py 2 | 3 | on: 4 | push: 5 | branches: [ master, development, experimental ] 6 | pull_request: 7 | branches: [ master, development, experimental ] 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | strategy: 14 | matrix: 15 | python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | 20 | - name: Set up Python ${{ matrix.python-version }} 21 | uses: actions/setup-python@v5 22 | with: 23 | python-version: ${{ matrix.python-version }} 24 | 25 | - name: Install dependencies 26 | run: | 27 | sudo apt-get update -y 28 | sudo apt-get install libhdf5-serial-dev liblzo2-dev libgraphviz-dev -y 29 | python -m pip install --upgrade pip 30 | pip install .[dev] 31 | 32 | - name: Rebuild nml.py 33 | run: | 34 | cd neuroml/nml && rm -f nml.py && ./regenerate-nml.sh -a 35 | 36 | - name: Build package 37 | run: | 38 | pip install .[full] 39 | 40 | - name: Test with pytest 41 | run: | 42 | pytest 43 | 44 | - name: Run examples 45 | run: | 46 | cd ./neuroml/examples && python run_all.py 47 | 48 | - name: Lint with flake8 49 | run: | 50 | # stop the build if there are Python syntax errors or undefined names 51 | flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics 52 | # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide 53 | flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics 54 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /neuroml/nml/regenit.sh 2 | /neuroml/nml/generatedsuper.py2 3 | /test3.sh 4 | /test2.sh 5 | /neuroml/nml/nml.py.bak 6 | /neuroml/test/tmpfile 7 | # All the python compiled 8 | *.pyc 9 | *.py~ 10 | *.*~ 11 | *.*# 12 | *~ 13 | *.csv 14 | 15 | .project 16 | .pydevproject 17 | .idea 18 | *.egg-info 19 | MANIFEST 20 | dist/* 21 | build 22 | 23 | #Sphinx built website. 24 | doc/_build 25 | 26 | #Padraig ignores.. 27 | ideas/padraig/generatedFromV2Schema/build 28 | ideas/padraig/generatedFromV2Schema/*.xml 29 | ideas/padraig/hdf5tests/*.hdf 30 | 31 | #hhExample ignores 32 | hhExample/*.xml 33 | hhExample/*.dat 34 | 35 | neuroml/examples/*.xml 36 | neuroml/examples/tmp/*.xml 37 | neuroml/examples/tmp/*.nml 38 | 39 | neuroml/test/*.h5 40 | *tmp* 41 | *#* 42 | /neuroml/nml/generateds_config2.py 43 | /release 44 | /private/cache 45 | /nb-configuration.xml 46 | /neuroml/examples/report.txt 47 | /neuroml/examples/test_files/report.txt 48 | /tests.log 49 | /notebooks/.ipynb_checkpoints 50 | /mongoo 51 | 52 | .venv 53 | /data 54 | .mypy_cache/ 55 | 56 | sed-script.txt 57 | /test.sh 58 | /*ken.sh 59 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | # See https://pre-commit.com for more information 2 | # See https://pre-commit.com/hooks.html for more hooks 3 | repos: 4 | - repo: https://github.com/pre-commit/pre-commit-hooks 5 | rev: v4.4.0 6 | hooks: 7 | - id: trailing-whitespace 8 | exclude: NeuroML.*xsd 9 | - id: end-of-file-fixer 10 | exclude: NeuroML.*xsd 11 | - id: check-added-large-files 12 | - repo: https://github.com/astral-sh/ruff-pre-commit 13 | rev: v0.4.1 14 | hooks: 15 | - id: ruff 16 | args: [ "--select", "I", "--fix" ] 17 | - id: ruff-format 18 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | 3 | build: 4 | os: ubuntu-22.04 5 | tools: 6 | python: "3.11" 7 | 8 | 9 | sphinx: 10 | configuration: doc/conf.py 11 | 12 | 13 | python: 14 | install: 15 | - method: pip 16 | path: . 17 | extra_requirements: 18 | - doc 19 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Contributions to the Python libNeuroML package: 2 | 3 | Andrew Davison [1] 4 | Michele Mattioni [2] 5 | Padraig Gleeson [3] 6 | Mike Vella [4] 7 | Mike Hull [5] 8 | Ankur Sinha [3] 9 | 10 | [1] UNIC, CNRS, Gif sur Yvette 11 | [2] EBI 12 | [3] UCL 13 | [4] Cambridge University 14 | [5] University of Bristol 15 | 16 | If you contribute code, please add your name and affiliation to this file. 17 | 18 | Please see also: 19 | 20 | - https://github.com/NeuralEnsemble/libNeuroML/graphs/contributors 21 | - https://docs.neuroml.org/NeuroMLOrg/Contributors.html 22 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please open issues to discuss enhancements and bugs that you may encounter with 4 | libNeuroML. Pull requests with enhancements and bug fixes are welcome. 5 | 6 | ## Virtual environments and editable installs 7 | 8 | It is best to use [virtual environments](https://docs.python.org/3/tutorial/venv.html) when developing Python packages. 9 | This ensures that one uses a clean environment that includes the necessary 10 | dependencies and does not affect the overall system installation. 11 | 12 | For quick development, consider using [editable installs](https://setuptools.pypa.io/en/latest/userguide/development_mode.html). 13 | The dependencies are broken down in the `setup.cfg` file. To get a complete development environment, one can run: 14 | 15 | 16 | pip install -e .[dev] # an editable install with all development dependecies installed 17 | 18 | 19 | ## Code style 20 | 21 | 1. The source code uses spaces, and each tab is equivalent to 4 spaces. 22 | 23 | 2. We use the [reStructuredText (reST) 24 | format](https://stackoverflow.com/a/24385103/375067) for Python docstrings. 25 | Please document your code when opening pull requests. 26 | All methods/functions/modules *must* include docstrings that explain the parameters. 27 | 28 | 3. We use [ruff](https://pypi.org/project/ruff/) to format and lint our code. (See the section on pre-commit below.) 29 | 30 | 4. Please use [type hints](https://docs.python.org/3/library/typing.html) wherever applicable. 31 | You can set up type checkers such as [mypy](https://mypy.readthedocs.io/) to use type hints in your development environment/IDE. 32 | 33 | 34 | pip install mypy 35 | 36 | 37 | ### Pre-commit 38 | 39 | A number of [pre-commit](https://pre-commit.com/) hooks are used to improve code-quality. 40 | Please run the following code to set up the pre-commit hooks: 41 | 42 | $ pre-commit install 43 | 44 | The hooks will be run at each `git commit`. 45 | Please see `.pre-commit-config.yaml` for information on what hooks we run. 46 | 47 | 48 | ### Commit messages 49 | 50 | Writing good commit messages makes things easy to follow. 51 | Please see these posts: 52 | 53 | - [How to write a Git commit message](https://cbea.ms/git-commit/) 54 | - While not compulsory, we prefer [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) 55 | 56 | 57 | ## Tests 58 | 59 | Bug fixes and new features should include unit tests to test for correctness. 60 | One can base new tests off the current ones included in the `tests/` directory. 61 | To see how tests are run, please see the [GitHub Actions configuration file](https://github.com/NeuralEnsemble/libNeuroML/blob/development/.github/workflows/ci.yml). 62 | 63 | We use [pytest](https://docs.pytest.org/) for unit testing. 64 | One can run it from the root of the repository: 65 | 66 | pytest 67 | 68 | 69 | To run specific tests, one can use the `-k` flag: 70 | 71 | 72 | pytest -k "..." 73 | 74 | 75 | ## Pull Request Process 76 | 77 | 1. Please contribute pull requests against the `development` branch. 78 | 2. Please ensure that the automated build for your pull request passes. 79 | 3. Please write good commit messages (see the section above). 80 | 81 | ### Updating your pull request branch 82 | 83 | Over time, as pull requests are reviewed, the `development` branch continues to move on with other changes. 84 | Sometimes, it can be useful/necessary to pull in these changes to the pull request branch, using the following steps. 85 | 86 | Add the upstream libNeuroML repository as a remote: 87 | 88 | 89 | git remote add upstream https://github.com/NeuralEnsemble/libNeuroML.git 90 | 91 | 92 | Update your local copy of the `development` branch, and the remote copy in your fork: 93 | 94 | 95 | git checkout development 96 | git pull upstream development 97 | git push 98 | 99 | 100 | Pull in changes from development to your branch: 101 | 102 | 103 | git checkout 104 | git merge development 105 | 106 | 107 | If there are merge conflicts, you will need to [resolve these](https://git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging#_basic_merge_conflicts), since merging the feature branch in the pull request will also result in these. 108 | After any merge conflicts have been resolved (or if there aren't any), you can 109 | push your branch to your fork to update the pull request: 110 | 111 | 112 | git push 113 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012, libNeuroML authors and contributors 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 8 | Neither the names of the copyright holders nor the names of the contributors may be used to endorse or promote products derived from this software without specific prior written permission. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 11 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include README.md 2 | include requirements.txt 3 | include AUTHORS 4 | include LICENSE 5 | include doc/*.txt 6 | include doc/Makefile 7 | include doc/conf.py 8 | include doc/*.png 9 | include neuroml/nml/README 10 | include neuroml/test/* 11 | include neuroml/examples 12 | recursive-include *.nml 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Introduction 2 | 3 | [![GH Build](https://github.com/NeuralEnsemble/libNeuroML/actions/workflows/ci.yml/badge.svg)](https://github.com/NeuralEnsemble/libNeuroML/actions/workflows/ci.yml) 4 | [![Documentation Status](https://readthedocs.org/projects/libneuroml/badge/?version=latest)](https://libneuroml.readthedocs.io/en/latest/?badge=latest) 5 | [![PyPI](https://img.shields.io/pypi/v/libNeuroML)](https://pypi.org/project/libNeuroML/) 6 | [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/libNeuroML)](https://pypi.org/project/libNeuroML/) 7 | [![GitHub](https://img.shields.io/github/license/NeuralEnsemble/libNeuroML)](https://github.com/NeuralEnsemble/libNeuroML/blob/master/LICENSE) 8 | [![GitHub pull requests](https://img.shields.io/github/issues-pr/NeuralEnsemble/libNeuroML)](https://github.com/NeuralEnsemble/libNeuroML/pulls) 9 | [![GitHub issues](https://img.shields.io/github/issues/NeuralEnsemble/libNeuroML)](https://github.com/NeuralEnsemble/libNeuroML/issues) 10 | [![GitHub Org's stars](https://img.shields.io/github/stars/NeuralEnsemble?style=social)](https://github.com/NeuralEnsemble) 11 | [![Twitter Follow](https://img.shields.io/twitter/follow/NeuroML?style=social)](https://twitter.com/NeuroML) 12 | [![Gitter](https://badges.gitter.im/NeuroML/community.svg)](https://gitter.im/NeuroML/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) 13 | 14 | This package provides Python libNeuroML, for working with neuronal models specified in [NeuroML 2](http://neuroml.org/neuromlv2). 15 | 16 | For more about libNeuroML see: 17 | 18 | Michael Vella, Robert C. Cannon, Sharon Crook, Andrew P. Davison, Gautham Ganapathy, Hugh P. C. Robinson, R. Angus Silver and Padraig Gleeson, 19 | **libNeuroML and PyLEMS: using Python to combine procedural and declarative modeling approaches in computational neuroscience** 20 | [Frontiers in Neuroinformatics 2014](http://journal.frontiersin.org/Journal/10.3389/fninf.2014.00038/abstract), doi: 10.3389/fninf.2014.00038 21 | 22 | _**PLEASE CITE THE PAPER ABOVE IF YOU USE libNeuroML!**_ 23 | 24 | Documentation is available at http://readthedocs.org/docs/libneuroml/en/latest/ 25 | 26 | For installation instructions, see http://readthedocs.org/docs/libneuroml/en/latest/install.html 27 | 28 | For an overview of all NeuroML related libraries/documentation/publications see https://docs.neuroml.org 29 | 30 | ## pyNeuroML 31 | 32 | A related package, **[pyNeuroML](https://github.com/NeuroML/pyNeuroML)** builds on this and provides functionality, scripts and modules for reading, writing, **simulating** and analysing NeuroML2/LEMS models. 33 | 34 | pyNeuroML builds on: [libNeuroML](https://github.com/NeuralEnsemble/libNeuroML) & [PyLEMS](https://github.com/LEMS/pylems) and wraps functionality from [jNeuroML](https://github.com/NeuroML/jNeuroML). 35 | 36 | ## Development process for libNeuroML 37 | 38 | Most of the work happens in the [development branch](https://github.com/NeuralEnsemble/libNeuroML/tree/development). 39 | That branch is kept up to date with the development branches for [NeuroML 2](https://github.com/NeuroML/NeuroML2/tree/development) and related libraries. 40 | See https://docs.neuroml.org/ for an overview of the various NeuroML libraries. 41 | 42 | ## Changelog 43 | 44 | See also https://github.com/NeuralEnsemble/libNeuroML/releases. 45 | 46 | ### version 0.5.8 47 | 48 | - drop py3.7, add py3,12 49 | - fix loader to check for given path and fall back to relative path 50 | - extend `get_segment_groups_from_substring` to also include an `unbranched` filter 51 | - more type hint/doc fixes 52 | 53 | ### version 0.5.7 54 | 55 | - more documentation for writes/loaders 56 | 57 | ### version 0.5.6 58 | 59 | - documentation fixes to writer modules 60 | 61 | ### version 0.5.5 62 | 63 | - update schema, changes for NML 2.3 release 64 | 65 | ### version 0.5.4 66 | 67 | - use natsort to improve sorting of segments/groups when optimising 68 | 69 | ### version 0.5.3 70 | 71 | - add links to schema documentation 72 | - move from legacy setup.py to pyproject.toml build system 73 | 74 | ### version 0.5.2 75 | 76 | - explicitly depend on numpy 77 | 78 | ### version 0.5.1 79 | 80 | - updates to GHA 81 | 82 | ### version 0.5.0 83 | 84 | - enable CI on py3.11 85 | - fix to loaders 86 | - format code with black 87 | - add graph representation for morphology, and methods to calculate distances b/w segments 88 | 89 | ### version 0.4.1 90 | 91 | - add multiple cell builder utility functions 92 | - performance improvements in generic helper functions 93 | - documentation fixes/improvements 94 | - add type annotations to all nml classes to aid users 95 | - add level 1 validation method 96 | - add generic component inspection methods 97 | 98 | ### version 0.4.0 99 | 100 | - update to use schema version 2.3 101 | - drop python 2 support 102 | 103 | ### version 0.3.1 104 | 105 | - include schema documentation in generated `nml.py` API 106 | - introduce generic methods to add child/children elements to components 107 | 108 | ### version 0.2.58 109 | 110 | - multiple documentation fixes 111 | 112 | ### version 0.2.57 113 | 114 | - Enable Python 3.10 support 115 | - Regenerate nml.py with generateDS using Python 3 116 | - Add generic `add` method to all NeuroML ComponentType classes that allows users to easily construct their NeuroML documents. 117 | - Improve unit tests 118 | - DEPRECATION notice: `append_to_element` will be deprecated in future releases, please use the `add` method instead 119 | 120 | ### version 0.2.56 121 | 122 | - Documentation updates for RTD and other minor fixes. 123 | 124 | ### version 0.2.55 125 | 126 | - Patch release with minor changes under the hood. 127 | - Use PyTest for testing. 128 | - Enable CI on GitHub Actions 129 | 130 | ### version 0.2.54 131 | 132 | - Using Schema for NeuroML v2.1. Better compatibility with Python 3 133 | 134 | ### version 0.2.50 135 | 136 | - Updated to use the final stable Schema for NeuroML v2.0 137 | 138 | ### version 0.2.47 139 | 140 | - Updated to use the final stable Schema for NeuroML v2beta5 141 | 142 | ### version 0.2.18 143 | 144 | - Updated to use the final stable Schema for NeuroML v2beta4 145 | - Tested with Python 3 146 | 147 | ### version 0.2.4 148 | 149 | - Updated to use the Schema for NeuroML v2beta4 150 | 151 | ### version 0.2.2 152 | 153 | - Updated to use the Schema for NeuroML v2beta3 154 | - Ensures numpy & pytables are only required when using non-XML loaders/writers 155 | 156 | ### version 0.2.0 157 | 158 | - Updated to use the Schema for NeuroML v2beta2 159 | 160 | ### version 0.1.9 161 | 162 | - Minor release: Update to latest schema 163 | 164 | ### version 0.1.8 165 | 166 | - Several Bug fixes and small enhamcements 167 | - Support for latest NeuroML schema (see change outline) 168 | - JSON serialization 169 | - MongoDB backend 170 | - HDF5 serialization 171 | - Improved installation process 172 | - All usage examples are now run on the Travis-CI continuous integration server to confirm that that they do not error. 173 | - Schema validation utility 174 | - Improved documentation and documentation new look 175 | 176 | :copyright: Copyright 2023 by the libNeuroML team, see [AUTHORS](AUTHORS). Modified BSD License, see [LICENSE](LICENSE) for details. 177 | -------------------------------------------------------------------------------- /doc/Makefile: -------------------------------------------------------------------------------- 1 | # Makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | PAPER = 8 | BUILDDIR = _build 9 | 10 | # Internal variables. 11 | PAPEROPT_a4 = -D latex_paper_size=a4 12 | PAPEROPT_letter = -D latex_paper_size=letter 13 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 14 | # the i18n builder cannot share the environment and doctrees with the others 15 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) . 16 | 17 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext classlist 18 | 19 | help: classlist 20 | @echo "Please use \`make ' where is one of" 21 | @echo " classlist to regenerate the nml core classlist" 22 | @echo " html to make standalone HTML files" 23 | @echo " dirhtml to make HTML files named index.html in directories" 24 | @echo " singlehtml to make a single large HTML file" 25 | @echo " pickle to make pickle files" 26 | @echo " json to make JSON files" 27 | @echo " htmlhelp to make HTML files and a HTML help project" 28 | @echo " qthelp to make HTML files and a qthelp project" 29 | @echo " devhelp to make HTML files and a Devhelp project" 30 | @echo " epub to make an epub" 31 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter" 32 | @echo " latexpdf to make LaTeX files and run them through pdflatex" 33 | @echo " text to make text files" 34 | @echo " man to make manual pages" 35 | @echo " texinfo to make Texinfo files" 36 | @echo " info to make Texinfo files and run them through makeinfo" 37 | @echo " gettext to make PO message catalogs" 38 | @echo " changes to make an overview of all changed/added/deprecated items" 39 | @echo " linkcheck to check all external links for integrity" 40 | @echo " doctest to run all doctests embedded in the documentation (if enabled)" 41 | 42 | clean: classlist 43 | -rm -rf $(BUILDDIR)/* 44 | 45 | classlist: classlist 46 | pushd userdocs && python ../helpers/nml-core-docs.py && popd 47 | 48 | html: classlist 49 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html 50 | @echo 51 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html." 52 | 53 | dirhtml: classlist 54 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml 55 | @echo 56 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml." 57 | 58 | singlehtml: classlist 59 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml 60 | @echo 61 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml." 62 | 63 | pickle: classlist 64 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle 65 | @echo 66 | @echo "Build finished; now you can process the pickle files." 67 | 68 | json: classlist 69 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json 70 | @echo 71 | @echo "Build finished; now you can process the JSON files." 72 | 73 | htmlhelp: classlist 74 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp 75 | @echo 76 | @echo "Build finished; now you can run HTML Help Workshop with the" \ 77 | ".hhp project file in $(BUILDDIR)/htmlhelp." 78 | 79 | qthelp: classlist 80 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp 81 | @echo 82 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \ 83 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:" 84 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/libNeuroML.qhcp" 85 | @echo "To view the help file:" 86 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/libNeuroML.qhc" 87 | 88 | devhelp: classlist 89 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp 90 | @echo 91 | @echo "Build finished." 92 | @echo "To view the help file:" 93 | @echo "# mkdir -p $$HOME/.local/share/devhelp/libNeuroML" 94 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/libNeuroML" 95 | @echo "# devhelp" 96 | 97 | epub: classlist 98 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub 99 | @echo 100 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub." 101 | 102 | latex: classlist 103 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 104 | @echo 105 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex." 106 | @echo "Run \`make' in that directory to run these through (pdf)latex" \ 107 | "(use \`make latexpdf' here to do that automatically)." 108 | 109 | latexpdf: classlist 110 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex 111 | @echo "Running LaTeX files through pdflatex..." 112 | $(MAKE) -C $(BUILDDIR)/latex all-pdf 113 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex." 114 | 115 | text: classlist 116 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text 117 | @echo 118 | @echo "Build finished. The text files are in $(BUILDDIR)/text." 119 | 120 | man: classlist 121 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man 122 | @echo 123 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man." 124 | 125 | texinfo: classlist 126 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 127 | @echo 128 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo." 129 | @echo "Run \`make' in that directory to run these through makeinfo" \ 130 | "(use \`make info' here to do that automatically)." 131 | 132 | info: classlist 133 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo 134 | @echo "Running Texinfo files through makeinfo..." 135 | make -C $(BUILDDIR)/texinfo info 136 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo." 137 | 138 | gettext: classlist 139 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale 140 | @echo 141 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale." 142 | 143 | changes: classlist 144 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes 145 | @echo 146 | @echo "The overview file is in $(BUILDDIR)/changes." 147 | 148 | linkcheck: classlist 149 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck 150 | @echo 151 | @echo "Link check complete; look for any errors in the above output " \ 152 | "or in $(BUILDDIR)/linkcheck/output.txt." 153 | 154 | doctest: classlist 155 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest 156 | @echo "Testing of doctests in the sources finished, look at the " \ 157 | "results in $(BUILDDIR)/doctest/output.txt." 158 | -------------------------------------------------------------------------------- /doc/_static/neuroml_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuralEnsemble/libNeuroML/09be14e32778d8d590cacb5fc65c3a90b42ed0ea/doc/_static/neuroml_logo.png -------------------------------------------------------------------------------- /doc/component-list.json: -------------------------------------------------------------------------------- 1 | {"Cells": ["baseCell", "baseSpikingCell", "baseCellMembPot", "baseCellMembPotDL", "baseChannelPopulation", "channelPopulation", "channelPopulationNernst", "baseChannelDensity", "baseChannelDensityCond", "variableParameter", "inhomogeneousValue", "channelDensityNonUniform", "channelDensityNonUniformNernst", "channelDensityNonUniformGHK", "channelDensity", "channelDensityVShift", "channelDensityNernst", "channelDensityNernstCa2", "channelDensityGHK", "channelDensityGHK2", "pointCellCondBased", "pointCellCondBasedCa", "distal", "proximal", "parent", "segment", "segmentGroup", "member", "from", "to", "include", "path", "subTree", "inhomogeneousParameter", "proximalDetails", "distalDetails", "morphology", "specificCapacitance", "initMembPotential", "spikeThresh", "membraneProperties", "membraneProperties2CaPools", "biophysicalProperties", "biophysicalProperties2CaPools", "intracellularProperties", "intracellularProperties2CaPools", "resistivity", "concentrationModel", "decayingPoolConcentrationModel", "fixedFactorConcentrationModel", "fixedFactorConcentrationModelTraub", "species", "cell", "cell2CaPools", "baseCellMembPotCap", "baseIaf", "iafTauCell", "iafTauRefCell", "baseIafCapCell", "iafCell", "iafRefCell", "izhikevichCell", "izhikevich2007Cell", "adExIaFCell", "fitzHughNagumoCell", "pinskyRinzelCA3Cell", "hindmarshRose1984Cell"], "Synapses": ["baseSynapse", "baseVoltageDepSynapse", "baseSynapseDL", "baseCurrentBasedSynapse", "alphaCurrentSynapse", "baseConductanceBasedSynapse", "baseConductanceBasedSynapseTwo", "expOneSynapse", "alphaSynapse", "expTwoSynapse", "expThreeSynapse", "baseBlockMechanism", "voltageConcDepBlockMechanism", "basePlasticityMechanism", "tsodyksMarkramDepMechanism", "tsodyksMarkramDepFacMechanism", "blockingPlasticSynapse", "doubleSynapse", "stdpSynapse", "gapJunction", "baseGradedSynapse", "silentSynapse", "linearGradedSynapse", "gradedSynapse"], "Channels": ["baseVoltageDepRate", "baseVoltageConcDepRate", "baseHHRate", "HHExpRate", "HHSigmoidRate", "HHExpLinearRate", "baseVoltageDepVariable", "baseVoltageConcDepVariable", "baseHHVariable", "HHExpVariable", "HHSigmoidVariable", "HHExpLinearVariable", "baseVoltageDepTime", "baseVoltageConcDepTime", "fixedTimeCourse", "baseQ10Settings", "q10Fixed", "q10ExpTemp", "baseConductanceScaling", "q10ConductanceScaling", "baseConductanceScalingCaDependent", "baseGate", "gate", "gateHHrates", "gateHHtauInf", "gateHHInstantaneous", "gateHHratesTau", "gateHHratesInf", "gateHHratesTauInf", "gateFractional", "subGate", "baseIonChannel", "ionChannelPassive", "ionChannelHH", "ionChannel", "ionChannelVShift", "KSState", "closedState", "openState", "ionChannelKS", "KSTransition", "forwardTransition", "reverseTransition", "vHalfTransition", "tauInfTransition", "gateKS"], "Inputs": ["basePointCurrent", "baseVoltageDepPointCurrent", "baseVoltageDepPointCurrentSpiking", "basePointCurrentDL", "baseVoltageDepPointCurrentDL", "baseSpikeSource", "spikeGenerator", "spikeGeneratorRandom", "spikeGeneratorPoisson", "spikeGeneratorRefPoisson", "poissonFiringSynapse", "transientPoissonFiringSynapse", "timedSynapticInput", "spikeArray", "spike", "pulseGenerator", "compoundInput", "compoundInputDL", "pulseGeneratorDL", "sineGenerator", "sineGeneratorDL", "rampGenerator", "rampGeneratorDL", "voltageClamp", "voltageClampTriple"], "Networks": ["network", "networkWithTemperature", "basePopulation", "population", "populationList", "instance", "location", "region", "rectangularExtent", "projection", "explicitConnection", "connection", "synapticConnection", "synapticConnectionWD", "connectionWD", "electricalConnection", "electricalConnectionInstance", "electricalConnectionInstanceW", "electricalProjection", "continuousConnection", "continuousConnectionInstance", "continuousConnectionInstanceW", "continuousProjection", "explicitInput", "inputList", "input", "inputW"], "PyNN": ["basePyNNCell", "basePyNNIaFCell", "basePyNNIaFCondCell", "IF_curr_alpha", "IF_curr_exp", "IF_cond_alpha", "IF_cond_exp", "EIF_cond_exp_isfa_ista", "EIF_cond_alpha_isfa_ista", "HH_cond_exp", "basePynnSynapse", "expCondSynapse", "expCurrSynapse", "alphaCondSynapse", "alphaCurrSynapse", "SpikeSourcePoisson"], "NeuroMLCoreDimensions": [], "NeuroMLCoreCompTypes": ["notes", "annotation", "property", "baseStandalone", "rdf_RDF", "rdf_Description", "baseBqbiol", "bqbiol_encodes", "bqbiol_hasPart", "bqbiol_hasProperty", "bqbiol_hasVersion", "bqbiol_is", "bqbiol_isDescribedBy", "bqbiol_isEncodedBy", "bqbiol_isHomologTo", "bqbiol_isPartOf", "bqbiol_isPropertyOf", "bqbiol_isVersionOf", "bqbiol_occursIn", "bqbiol_hasTaxon", "bqmodel_is", "bqmodel_isDescribedBy", "bqmodel_isDerivedFrom", "rdf_Bag", "rdf:li", "point3DWithDiam"], "Simulation": ["Simulation", "Display", "Line", "OutputFile", "OutputColumn", "EventOutputFile", "EventSelection", "Meta"]} 2 | -------------------------------------------------------------------------------- /doc/devdocs/2012_06_26_neuroml_with_pymoose.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuralEnsemble/libNeuroML/09be14e32778d8d590cacb5fc65c3a90b42ed0ea/doc/devdocs/2012_06_26_neuroml_with_pymoose.pdf -------------------------------------------------------------------------------- /doc/devdocs/how_to_contribute.rst: -------------------------------------------------------------------------------- 1 | How to contribute 2 | ================= 3 | 4 | libNeuroML development happens on GitHub, so you will need a GitHub account to contribute to the repository. 5 | Contributions are made using the standard `Pull Request`_ workflow. 6 | 7 | Setting up 8 | ---------- 9 | 10 | Please take a look at the GitHub documentation here: http://help.github.com/fork-a-repo/ 11 | 12 | To begin, please fork the repo on the GitHub website. 13 | You should now have a libNeuroML under you username. 14 | Next, we clone our fork to get a local copy on our computer: 15 | 16 | :: 17 | 18 | git clone git@github.com:_username_/libNeuroML.git 19 | 20 | While not necessary, it is good practice to add the upstream repository as a remote that you will follow: 21 | 22 | :: 23 | 24 | cd libNeuroML 25 | git remote add upstream https://github.com/NeuralEnsemble/libNeuroML.git 26 | git fetch upstream 27 | 28 | 29 | You can check which branch are you following doing: 30 | 31 | :: 32 | 33 | git branch -a 34 | 35 | You should have something like: 36 | 37 | :: 38 | 39 | git branch -a 40 | * master 41 | remotes/origin/HEAD -> origin/master 42 | remotes/origin/master 43 | remotes/upstream/master 44 | 45 | 46 | Sync with upstream 47 | ------------------ 48 | 49 | Before starting to do some work, please check to see that you have the latest copy of the sources in your local repository: 50 | 51 | :: 52 | 53 | git fetch upstream 54 | git checkout development 55 | git merge upstream/development 56 | 57 | Working locally on a dedicated branch 58 | ------------------------------------- 59 | 60 | Now that we have a fork, we can start making our changes to the source code. 61 | The best way to do it is to create a branch with a descriptive name to indicate what are you working on. 62 | Generally, your will branch off from the upstream `development` branch, which will contain the latest code. 63 | 64 | For example, just for the sake of this guide, I'm going to work on issue #2. 65 | 66 | :: 67 | 68 | git checkout development 69 | git checkout -b fix-2 70 | 71 | 72 | We can work in this branch, and make as many commits as we need to: 73 | 74 | :: 75 | 76 | # hack hack hack 77 | git commit -am "some decent commit message here" 78 | 79 | 80 | Once we have finished working, we can push the branch online to our fork: 81 | 82 | :: 83 | 84 | git push origin fix-2 85 | 86 | 87 | We can then open a pull-request to merge our ``fix-2`` branch into ``upstream/development``. 88 | If your code is not ready to be included, you can update the code on your branch and any more commits you add there will be added to the Pull Request. 89 | Members of the libNeuroML development team will then discuss your changes with you, perhaps suggest tweaks, and then merge it when ready. 90 | 91 | Continuous integration 92 | ----------------------- 93 | 94 | libNeuroML uses continuous integration (`Wikipedia `_). 95 | Each commit to the master or development branches is tested, along with all commits to pull requests. 96 | The latest status of the continuous integration tests can be seen `here on GitHub Actions `_. 97 | 98 | Release process 99 | --------------- 100 | 101 | libNeuroML is part of the official NeuroML release cycle. 102 | When a new libNeuroML release is ready the following needs to happen: 103 | 104 | - Update version number in setup.cfg 105 | - update version number in doc/conf.py 106 | - update release number in doc/conf.py (same as version number) 107 | - update changelog in README.md 108 | - merge development branch with master (This should happen via pull request - do not do the merge yourself even if you are an owner of the repository. 109 | - push latest release to PyPi 110 | 111 | More information on the NeuroML release process can be found on the `NeuroML documentation page `_. 112 | 113 | .. _Pull Request: http://help.github.com/send-pull-requests/ 114 | -------------------------------------------------------------------------------- /doc/devdocs/implementation_of_bindings.rst: -------------------------------------------------------------------------------- 1 | Implementation of XML bindings for libNeuroML 2 | ============================================= 3 | 4 | The GenerateDS Python package is used to automatically generate the NeuroML XML-bindings in libNeuroML from the NeuroML Schema. This technique can be utilized for any XML Schema and is outlined in this section. The addition of helper methods and enforcement of correct naming conventions is also described. For more detail on how Python bindings for XML are generated, the reader is directed to the GenerateDS and libNeuroML documentation. In the following subsections it is assumed that all commands are executed in a top level directory nml and that GenerateDS is installed. It should be noted that enforcement of naming conventions and addition of helper methods are not required by GenerateDS and default values may be used. 5 | 6 | Correct naming conventions 7 | -------------------------- 8 | A module named generateds_config.py is placed in the nml directory. 9 | This module contains a Python dictionary called NameTable which maps 10 | the original names specified in the XML Schema to user-specified ones. 11 | The NameTable dictionary can be defined explicitly or generated 12 | programmatically, for example using regular expressions. 13 | 14 | Addition of helper methods 15 | -------------------------- 16 | 17 | Helper methods associated with a class can be added to a Python module as string objects. In the case of libNeuroML the module is called helper_methods.py. The precise implementation details are esoteric and the user is referred to the GenerateDS documentation for details of how this functionality is implemented. 18 | 19 | Generation of bindings 20 | ---------------------- 21 | Once generateds_config.py and a helper methods module are present in the nml directory a valid XML Schema is required by GenerateDS. The following command generates the nml.py module which contains the XML-bindings: 22 | 23 | :: 24 | 25 | $ generateDS.py -o nml.py --use-getter-setter=none --user-methods=helper_methods NeuroML_v2beta1.xsd 26 | 27 | The -o flag sets the file which the module containing the bindings is to be written to. The --use-getter-setter=none option disables getters and setters for class attributes. The --user-methods flag indicates the name of the helper methods module (See section “Addition of helper methods”). The final parameter (NeuroML_v2beta1.xsd) is the name of the XML Schema used for generating the bindings. 28 | -------------------------------------------------------------------------------- /doc/devdocs/index.rst: -------------------------------------------------------------------------------- 1 | Contributing 2 | ************ 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | how_to_contribute 8 | regenerate_docs 9 | implementation_of_bindings 10 | meeting_june_2012 11 | nodes_segments_sections 12 | -------------------------------------------------------------------------------- /doc/devdocs/nodes_segments_sections.rst: -------------------------------------------------------------------------------- 1 | Nodes, Segments and Sections 2 | ============================ 3 | 4 | An attempt to clarify these interrelated terms used in describing morphologies. Names in **bold type** are used for elements of the 5 | NeuroML object model. 6 | 7 | Nodes 8 | ------- 9 | 10 | A node is a 3D point with diameter information which forms the basis for 3D morphological reconstructions. 11 | 12 | These nodes (or points) are the fundamental building blocks in the SWC and Neurolucida formats. This method of description 13 | is based on the assumption that each node is physically connected to another node. 14 | 15 | 16 | 17 | Segments 18 | -------------- 19 | 20 | A **segment** (according to NeuroML v1&2) is a part of a neuronal tree between two 3D points with diameters (**proximal** & **distal**). 21 | The term node isn't used in NeuroML but the above description describes perfectly well the **proximal** & **distal** points. 22 | Cell **morphology** elements consist of lists of **segments** (each with unique integer id, and optional name). 23 | 24 | All segments, apart from the root segment, have a **parent** segment. If the **proximal** point of the segment is not specified, 25 | the **distal** point of the parent segment is used for the **proximal** point of the child. 26 | 27 | A special case is defined where **proximal** == **distal**, and the **segment** is assumed to be a sphere at that location 28 | with the specified diameter. 29 | 30 | Segments can be grouped into **segmentGroups** in NeuroML v2.0. These can be used to specify "apical_dendrites", "axon_group", 31 | etc., which in turn can be used for placing channels on the cell. 32 | 33 | An example of a NeuroML v2.0 cell is `here `_. 34 | 35 | libNeuroML will allow low level access to create and modify morphologies by handling nodes. Segments will also be top 36 | level objects in the API. The XML serialisation will only specify **segments** with **proximal** & **distal** points, but 37 | the HDF5 version may have an efficient serialisation of nodes & segments. 38 | 39 | 40 | Sections 41 | -------- 42 | 43 | The concept of section is fundamentally important in NEURON. A section in this simulator is an unbranched cable which can have multiple 44 | 3D points outlining the structure of a neurite in 3D. These points are used to determine the surface area along the section. NEURON 45 | can vary the spatial discretisation of the neurite by varying the "nseg" value of the section, e.g. a section with 20 3D 46 | points and nseg =4 will be split into 4 parts of equal length for simulating (as isopotential compartments), with the surface area (and so total channel 47 | conductance) of each determined by the set of 3D points in that part. 48 | 49 | There was a similar concept to this in NeuroML v1.x, the **cable**. Each **segment** had an attribute for the cable id, and these were used for mapping 50 | to and from NEURON. Cables were unbranched, and so all segments after the first in the cable only had distal points, see 51 | `this example `_. 52 | 53 | The cable concept was removed in NeuroML v2.0, as this is was seen as imposing concepts from compartmental modelling 54 | on the basic morphological descriptions of cells. There is only a **segmentGroup** element for grouping segments, though 55 | a **segment** can belong to multiple **segmentGroups**, which don't need to be unbranched (unlike **cables**). There may need to be a 56 | new attribute in **segmentGroup** (e.g. primary or unbranched or cable="true") which defines a nonoverlapping set of 57 | unbranched segmentGroups, which can be used as the basis for sections in any parsing application which is interested 58 | in them, or be ignored by any other application. 59 | 60 | In libNeuroML, a section-like concept can be added at API level, to facilitate building cells, to facilitate import/export 61 | to/from simulators supporting this concept, and to serve as a basis for recompartmentalisation of cells. 62 | 63 | 64 | 65 | Issues 66 | ------ 67 | 68 | Dendrites in space 69 | ~~~~~~~~~~~~~~~~~~ 70 | 71 | One major issue to address is that in many neuronal reconstructions, the soma is not included (or perhaps just an outline 72 | of the soma is given), only the dendrites are. These dendrites' 3D start points are on the edge of the soma membrane "floating in space". 73 | Normal procedure for a modeller in this case is to create a spherical soma at this central point and electrically attach the 74 | dendrites to the centre of this. 75 | 76 | In this case (and many others) the physical location of the start of the child segments do not correspond to the electrical (or logical) 77 | connection point on the parent. This has advantages and disadvantages: 78 | 79 | (+) It allows the real 3D points of the neuronal reconstruction to be retained (useful for visualisation) 80 | 81 | (-) This is not unambiguously captured in the simplest morphological formats like SWC, which assume physical connectivity between nodes/points 82 | 83 | This scenario is supported in NeuroML v1&2, where a child **segment** has the option to redefine its start point (by adding a **proximal**) 84 | with the child <-> parent relationship defining the electrical connection. This allows lossless import & export from NEURON and 85 | removes the ambiguity of more compact formats like SWC and Neurolucida. 86 | 87 | Connections mid segment 88 | ~~~~~~~~~~~~~~~~~~~~~~~ 89 | 90 | Another option for electrical connections (also influences by NEURON sections) is the ability for **segments** to 91 | (electrically/logically) connect to a point inside a **segment**. This is specified by adding a fractionAlong attribute 92 | to the **parent** element, i.e. 93 | 94 | :: 95 | 96 | 97 | 98 | This is not possible in a node based format, but represents a logically consistent description of what the modeller 99 | wants. 100 | 101 | 102 | What to do? 103 | ~~~~~~~~~~~ 104 | 105 | Two options are available then for a serialisation format or API: should it try to support all of these scenarios, or try to 106 | enforce "best practice"? 107 | 108 | PG: I'd argue for the first approach, as it retains as much as possible of what the original reconstructor/simulator specified. 109 | An API which enforces a policy when it encounters a non optimal morphology (e.g. moving all dendrites to connection points, 110 | inserting new nodes) will alter the original data in perhaps unintended ways, and that information will be lost by subsequent readers. 111 | It should be up to each parsing application to decide what to do with the extra information when it reads in a file. 112 | -------------------------------------------------------------------------------- /doc/devdocs/regenerate_docs.rst: -------------------------------------------------------------------------------- 1 | Regenerating documentation 2 | ========================== 3 | 4 | Please create a virtual environment and use the `requirements.txt` file to install the necessary bits. 5 | 6 | In most cases, running `make html` should be sufficient to regenerate the documentation. 7 | However, if any changes to `nml.py` have been made, the `nml-core-docs.py` file in the `helpers` directory will also need to be run. 8 | This script manually adds each class from `nml.py` to the documentation as a sub-section using the `autoclass` sphinx directive instead of the `automodule` directive which does not allow us to do this. 9 | -------------------------------------------------------------------------------- /doc/helpers/nml-core-docs.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Generate sphinx sources for the libNeuroML nml.py classes 4 | 5 | File: helpers/nml-core-docs.py 6 | 7 | Copyright 2023 NeuroML authors 8 | """ 9 | 10 | import json 11 | import textwrap 12 | 13 | print("Generating list of nml classes") 14 | 15 | component_type_list = None 16 | with open("../component-list.json", "r") as f: 17 | component_type_list = json.load(f) 18 | 19 | component_type_list["Other"] = [] 20 | 21 | output_files = {} 22 | comp_num_dict = {} 23 | 24 | for ctype in component_type_list.keys(): 25 | fwrite = open(f"../userdocs/{ctype}_list.rst", "w") 26 | output_files[ctype] = fwrite 27 | print(ctype, file=fwrite) 28 | print("#" * len(ctype), file=fwrite) 29 | print("\n", file=fwrite) 30 | print("\n", file=fwrite) 31 | print( 32 | f"This documentation is auto-generated from the `NeuroML schema `__.", 33 | file=fwrite, 34 | ) 35 | print("\n", file=fwrite) 36 | print("\n", file=fwrite) 37 | print(".. Generated using nml-core-docs.py", file=fwrite) 38 | 39 | comp_num_dict[ctype] = 0 40 | 41 | comp_to_file_map = {} 42 | for file, ctypes in component_type_list.items(): 43 | for ctype in ctypes: 44 | comp_to_file_map[ctype[0].capitalize() + ctype[1:]] = file 45 | 46 | classes = {} 47 | files = { 48 | "generatedssupersuper.py": [], 49 | "generatedscollector.py": [], 50 | "nml.py": [ 51 | "GDSParseError", 52 | "MixedContainer", 53 | "MemberSpec_", 54 | "BlockTypes", 55 | "Metric", 56 | "PlasticityTypes", 57 | "ZeroOrOne", 58 | "allowedSpaces", 59 | "_FixedOffsetTZ", 60 | "GdsCollector_", 61 | "GeneratedsSuperSuper", 62 | ], 63 | } 64 | 65 | for f, excluded_classes in files.items(): 66 | classlist = [] 67 | with open("../../neuroml/nml/" + f, "r") as file: 68 | lines = file.readlines() 69 | for line in lines: 70 | line = line.strip() 71 | if line.startswith("class "): 72 | # get the class signature 73 | aclass = line[len("class ") :] 74 | # for classes that are of form class A(): 75 | aclass = aclass.split("(")[0] 76 | # for classes that are of form class A: 77 | aclass = aclass.split(":")[0] 78 | if aclass not in excluded_classes: 79 | classlist.append(aclass) 80 | classlist.sort() 81 | classes[f] = classlist 82 | 83 | 84 | total_classes = 0 85 | for module, clist in classes.items(): 86 | total_classes += len(clist) 87 | f = module.split(".")[0] 88 | for aclass in clist: 89 | # do not print all the internal methods in GeneratedsSuper 90 | if aclass == "GeneratedsSuper": 91 | towrite = textwrap.dedent( 92 | """ 93 | {} 94 | {} 95 | 96 | .. autoclass:: neuroml.nml.{}.{} 97 | :show-inheritance: 98 | 99 | """.format( 100 | aclass, 101 | "^" * len(aclass), 102 | f, 103 | aclass, 104 | ) 105 | ) 106 | else: 107 | towrite = textwrap.dedent( 108 | """ 109 | {} 110 | {} 111 | 112 | .. autoclass:: neuroml.nml.{}.{} 113 | :members: 114 | :undoc-members: 115 | :show-inheritance: 116 | :inherited-members: 117 | 118 | """.format( 119 | aclass, 120 | "^" * len(aclass), 121 | f, 122 | aclass, 123 | ) 124 | ) 125 | try: 126 | category = comp_to_file_map[aclass] 127 | except KeyError: 128 | if "cell" in aclass.lower(): 129 | category = "Cells" 130 | elif "gate" in aclass.lower(): 131 | category = "Channels" 132 | elif "hh" in aclass.lower(): 133 | category = "Channels" 134 | elif "q10" in aclass.lower(): 135 | category = "Channels" 136 | elif "channel" in aclass.lower(): 137 | category = "Channels" 138 | elif "network" in aclass.lower(): 139 | category = "Networks" 140 | elif "population" in aclass.lower(): 141 | category = "Networks" 142 | else: 143 | print(f"{aclass} fits nowhere, putting in Other") 144 | category = "Other" 145 | finally: 146 | comp_num_dict[category] += 1 147 | fwrite = output_files[category] 148 | print(towrite, file=fwrite) 149 | 150 | print("Done") 151 | print(comp_num_dict) 152 | 153 | print(f"Total classes read from libNeuroML: {total_classes}") 154 | 155 | for comp, num in comp_num_dict.items(): 156 | output_files[comp].close() 157 | -------------------------------------------------------------------------------- /doc/index.rst: -------------------------------------------------------------------------------- 1 | libNeuroML: documentation 2 | ========================== 3 | 4 | Welcome to the libNeuroML documentation. 5 | Here you will find information on installing, using, and contributing to libNeuroML. 6 | For more information on NeuroML standard, other tools in the NeuroML eco-system, the NeuroML community and how to get in touch with us, please see the documentation at https://docs.neuroml.org. 7 | 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | 12 | userdocs/index 13 | devdocs/index 14 | 15 | Indices and tables 16 | ******************* 17 | 18 | * :ref:`genindex` 19 | * :ref:`modindex` 20 | * :ref:`search` 21 | -------------------------------------------------------------------------------- /doc/make.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | REM Command file for Sphinx documentation 4 | 5 | if "%SPHINXBUILD%" == "" ( 6 | set SPHINXBUILD=sphinx-build 7 | ) 8 | set BUILDDIR=_build 9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% . 10 | set I18NSPHINXOPTS=%SPHINXOPTS% . 11 | if NOT "%PAPER%" == "" ( 12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS% 13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS% 14 | ) 15 | 16 | if "%1" == "" goto help 17 | 18 | if "%1" == "help" ( 19 | :help 20 | echo.Please use `make ^` where ^ is one of 21 | echo. html to make standalone HTML files 22 | echo. dirhtml to make HTML files named index.html in directories 23 | echo. singlehtml to make a single large HTML file 24 | echo. pickle to make pickle files 25 | echo. json to make JSON files 26 | echo. htmlhelp to make HTML files and a HTML help project 27 | echo. qthelp to make HTML files and a qthelp project 28 | echo. devhelp to make HTML files and a Devhelp project 29 | echo. epub to make an epub 30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter 31 | echo. text to make text files 32 | echo. man to make manual pages 33 | echo. texinfo to make Texinfo files 34 | echo. gettext to make PO message catalogs 35 | echo. changes to make an overview over all changed/added/deprecated items 36 | echo. linkcheck to check all external links for integrity 37 | echo. doctest to run all doctests embedded in the documentation if enabled 38 | goto end 39 | ) 40 | 41 | if "%1" == "clean" ( 42 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i 43 | del /q /s %BUILDDIR%\* 44 | goto end 45 | ) 46 | 47 | if "%1" == "html" ( 48 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html 49 | if errorlevel 1 exit /b 1 50 | echo. 51 | echo.Build finished. The HTML pages are in %BUILDDIR%/html. 52 | goto end 53 | ) 54 | 55 | if "%1" == "dirhtml" ( 56 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml 57 | if errorlevel 1 exit /b 1 58 | echo. 59 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml. 60 | goto end 61 | ) 62 | 63 | if "%1" == "singlehtml" ( 64 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml 65 | if errorlevel 1 exit /b 1 66 | echo. 67 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml. 68 | goto end 69 | ) 70 | 71 | if "%1" == "pickle" ( 72 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle 73 | if errorlevel 1 exit /b 1 74 | echo. 75 | echo.Build finished; now you can process the pickle files. 76 | goto end 77 | ) 78 | 79 | if "%1" == "json" ( 80 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json 81 | if errorlevel 1 exit /b 1 82 | echo. 83 | echo.Build finished; now you can process the JSON files. 84 | goto end 85 | ) 86 | 87 | if "%1" == "htmlhelp" ( 88 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp 89 | if errorlevel 1 exit /b 1 90 | echo. 91 | echo.Build finished; now you can run HTML Help Workshop with the ^ 92 | .hhp project file in %BUILDDIR%/htmlhelp. 93 | goto end 94 | ) 95 | 96 | if "%1" == "qthelp" ( 97 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp 98 | if errorlevel 1 exit /b 1 99 | echo. 100 | echo.Build finished; now you can run "qcollectiongenerator" with the ^ 101 | .qhcp project file in %BUILDDIR%/qthelp, like this: 102 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\libNeuroML.qhcp 103 | echo.To view the help file: 104 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\libNeuroML.ghc 105 | goto end 106 | ) 107 | 108 | if "%1" == "devhelp" ( 109 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp 110 | if errorlevel 1 exit /b 1 111 | echo. 112 | echo.Build finished. 113 | goto end 114 | ) 115 | 116 | if "%1" == "epub" ( 117 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub 118 | if errorlevel 1 exit /b 1 119 | echo. 120 | echo.Build finished. The epub file is in %BUILDDIR%/epub. 121 | goto end 122 | ) 123 | 124 | if "%1" == "latex" ( 125 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex 126 | if errorlevel 1 exit /b 1 127 | echo. 128 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex. 129 | goto end 130 | ) 131 | 132 | if "%1" == "text" ( 133 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text 134 | if errorlevel 1 exit /b 1 135 | echo. 136 | echo.Build finished. The text files are in %BUILDDIR%/text. 137 | goto end 138 | ) 139 | 140 | if "%1" == "man" ( 141 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man 142 | if errorlevel 1 exit /b 1 143 | echo. 144 | echo.Build finished. The manual pages are in %BUILDDIR%/man. 145 | goto end 146 | ) 147 | 148 | if "%1" == "texinfo" ( 149 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo 150 | if errorlevel 1 exit /b 1 151 | echo. 152 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo. 153 | goto end 154 | ) 155 | 156 | if "%1" == "gettext" ( 157 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale 158 | if errorlevel 1 exit /b 1 159 | echo. 160 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale. 161 | goto end 162 | ) 163 | 164 | if "%1" == "changes" ( 165 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes 166 | if errorlevel 1 exit /b 1 167 | echo. 168 | echo.The overview file is in %BUILDDIR%/changes. 169 | goto end 170 | ) 171 | 172 | if "%1" == "linkcheck" ( 173 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck 174 | if errorlevel 1 exit /b 1 175 | echo. 176 | echo.Link check complete; look for any errors in the above output ^ 177 | or in %BUILDDIR%/linkcheck/output.txt. 178 | goto end 179 | ) 180 | 181 | if "%1" == "doctest" ( 182 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest 183 | if errorlevel 1 exit /b 1 184 | echo. 185 | echo.Testing of doctests in the sources finished, look at the ^ 186 | results in %BUILDDIR%/doctest/output.txt. 187 | goto end 188 | ) 189 | 190 | :end 191 | -------------------------------------------------------------------------------- /doc/refs.bib: -------------------------------------------------------------------------------- 1 | @Article{Vella2014, 2 | author = {Vella, Michael and Cannon, Robert C. and Crook, Sharon and Davison, Andrew P. and Ganapathy, Gautham and Robinson, Hugh P. C. and Silver, R. Angus and Gleeson, Padraig}, 3 | title = {libNeuroML and PyLEMS: using Python to combine procedural and declarative modeling approaches in computational neuroscience.}, 4 | doi = {10.3389/fninf.2014.00038}, 5 | issn = {1662-5196}, 6 | pages = {38}, 7 | volume = {8}, 8 | abstract = {NeuroML is an XML-based model description language, which provides a powerful common data format for defining and exchanging models of neurons and neuronal networks. In the latest version of NeuroML, the structure and behavior of ion channel, synapse, cell, and network model descriptions are based on underlying definitions provided in LEMS, a domain-independent language for expressing hierarchical mathematical models of physical entities. While declarative approaches for describing models have led to greater exchange of model elements among software tools in computational neuroscience, a frequent criticism of XML-based languages is that they are difficult to work with directly. Here we describe two Application Programming Interfaces (APIs) written in Python (http://www.python.org), which simplify the process of developing and modifying models expressed in NeuroML and LEMS. The libNeuroML API provides a Python object model with a direct mapping to all NeuroML concepts defined by the NeuroML Schema, which facilitates reading and writing the XML equivalents. In addition, it offers a memory-efficient, array-based internal representation, which is useful for handling large-scale connectomics data. The libNeuroML API also includes support for performing common operations that are required when working with NeuroML documents. Access to the LEMS data model is provided by the PyLEMS API, which provides a Python implementation of the LEMS language, including the ability to simulate most models expressed in LEMS. Together, libNeuroML and PyLEMS provide a comprehensive solution for interacting with NeuroML models in a Python environment.}, 9 | country = {Switzerland}, 10 | issn-linking = {1662-5196}, 11 | journal = {Frontiers in neuroinformatics}, 12 | keywords = {API; LEMS; NeuroML; Python; SWC; model specification; modeling; standardization}, 13 | nlm-id = {101477957}, 14 | owner = {NLM}, 15 | pmc = {PMC4005938}, 16 | pmid = {24795618}, 17 | pubmodel = {Electronic-eCollection}, 18 | pubstatus = {epublish}, 19 | revised = {2018-11-13}, 20 | timestamp = {2019-02-20}, 21 | year = {2014}, 22 | } 23 | -------------------------------------------------------------------------------- /doc/userdocs/Channels_list.rst: -------------------------------------------------------------------------------- 1 | Channels 2 | ######## 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | 14 | ClosedState 15 | ^^^^^^^^^^^ 16 | 17 | .. autoclass:: neuroml.nml.nml.ClosedState 18 | :members: 19 | :undoc-members: 20 | :show-inheritance: 21 | :inherited-members: 22 | 23 | 24 | 25 | ForwardTransition 26 | ^^^^^^^^^^^^^^^^^ 27 | 28 | .. autoclass:: neuroml.nml.nml.ForwardTransition 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | :inherited-members: 33 | 34 | 35 | 36 | GateFractional 37 | ^^^^^^^^^^^^^^ 38 | 39 | .. autoclass:: neuroml.nml.nml.GateFractional 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | :inherited-members: 44 | 45 | 46 | 47 | GateFractionalSubgate 48 | ^^^^^^^^^^^^^^^^^^^^^ 49 | 50 | .. autoclass:: neuroml.nml.nml.GateFractionalSubgate 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | :inherited-members: 55 | 56 | 57 | 58 | GateHHInstantaneous 59 | ^^^^^^^^^^^^^^^^^^^ 60 | 61 | .. autoclass:: neuroml.nml.nml.GateHHInstantaneous 62 | :members: 63 | :undoc-members: 64 | :show-inheritance: 65 | :inherited-members: 66 | 67 | 68 | 69 | GateHHRates 70 | ^^^^^^^^^^^ 71 | 72 | .. autoclass:: neuroml.nml.nml.GateHHRates 73 | :members: 74 | :undoc-members: 75 | :show-inheritance: 76 | :inherited-members: 77 | 78 | 79 | 80 | GateHHRatesInf 81 | ^^^^^^^^^^^^^^ 82 | 83 | .. autoclass:: neuroml.nml.nml.GateHHRatesInf 84 | :members: 85 | :undoc-members: 86 | :show-inheritance: 87 | :inherited-members: 88 | 89 | 90 | 91 | GateHHRatesTau 92 | ^^^^^^^^^^^^^^ 93 | 94 | .. autoclass:: neuroml.nml.nml.GateHHRatesTau 95 | :members: 96 | :undoc-members: 97 | :show-inheritance: 98 | :inherited-members: 99 | 100 | 101 | 102 | GateHHRatesTauInf 103 | ^^^^^^^^^^^^^^^^^ 104 | 105 | .. autoclass:: neuroml.nml.nml.GateHHRatesTauInf 106 | :members: 107 | :undoc-members: 108 | :show-inheritance: 109 | :inherited-members: 110 | 111 | 112 | 113 | GateHHTauInf 114 | ^^^^^^^^^^^^ 115 | 116 | .. autoclass:: neuroml.nml.nml.GateHHTauInf 117 | :members: 118 | :undoc-members: 119 | :show-inheritance: 120 | :inherited-members: 121 | 122 | 123 | 124 | GateHHUndetermined 125 | ^^^^^^^^^^^^^^^^^^ 126 | 127 | .. autoclass:: neuroml.nml.nml.GateHHUndetermined 128 | :members: 129 | :undoc-members: 130 | :show-inheritance: 131 | :inherited-members: 132 | 133 | 134 | 135 | GateKS 136 | ^^^^^^ 137 | 138 | .. autoclass:: neuroml.nml.nml.GateKS 139 | :members: 140 | :undoc-members: 141 | :show-inheritance: 142 | :inherited-members: 143 | 144 | 145 | 146 | HHRate 147 | ^^^^^^ 148 | 149 | .. autoclass:: neuroml.nml.nml.HHRate 150 | :members: 151 | :undoc-members: 152 | :show-inheritance: 153 | :inherited-members: 154 | 155 | 156 | 157 | HHTime 158 | ^^^^^^ 159 | 160 | .. autoclass:: neuroml.nml.nml.HHTime 161 | :members: 162 | :undoc-members: 163 | :show-inheritance: 164 | :inherited-members: 165 | 166 | 167 | 168 | HHVariable 169 | ^^^^^^^^^^ 170 | 171 | .. autoclass:: neuroml.nml.nml.HHVariable 172 | :members: 173 | :undoc-members: 174 | :show-inheritance: 175 | :inherited-members: 176 | 177 | 178 | 179 | IonChannel 180 | ^^^^^^^^^^ 181 | 182 | .. autoclass:: neuroml.nml.nml.IonChannel 183 | :members: 184 | :undoc-members: 185 | :show-inheritance: 186 | :inherited-members: 187 | 188 | 189 | 190 | IonChannelHH 191 | ^^^^^^^^^^^^ 192 | 193 | .. autoclass:: neuroml.nml.nml.IonChannelHH 194 | :members: 195 | :undoc-members: 196 | :show-inheritance: 197 | :inherited-members: 198 | 199 | 200 | 201 | IonChannelKS 202 | ^^^^^^^^^^^^ 203 | 204 | .. autoclass:: neuroml.nml.nml.IonChannelKS 205 | :members: 206 | :undoc-members: 207 | :show-inheritance: 208 | :inherited-members: 209 | 210 | 211 | 212 | IonChannelScalable 213 | ^^^^^^^^^^^^^^^^^^ 214 | 215 | .. autoclass:: neuroml.nml.nml.IonChannelScalable 216 | :members: 217 | :undoc-members: 218 | :show-inheritance: 219 | :inherited-members: 220 | 221 | 222 | 223 | IonChannelVShift 224 | ^^^^^^^^^^^^^^^^ 225 | 226 | .. autoclass:: neuroml.nml.nml.IonChannelVShift 227 | :members: 228 | :undoc-members: 229 | :show-inheritance: 230 | :inherited-members: 231 | 232 | 233 | 234 | OpenState 235 | ^^^^^^^^^ 236 | 237 | .. autoclass:: neuroml.nml.nml.OpenState 238 | :members: 239 | :undoc-members: 240 | :show-inheritance: 241 | :inherited-members: 242 | 243 | 244 | 245 | Q10ConductanceScaling 246 | ^^^^^^^^^^^^^^^^^^^^^ 247 | 248 | .. autoclass:: neuroml.nml.nml.Q10ConductanceScaling 249 | :members: 250 | :undoc-members: 251 | :show-inheritance: 252 | :inherited-members: 253 | 254 | 255 | 256 | Q10Settings 257 | ^^^^^^^^^^^ 258 | 259 | .. autoclass:: neuroml.nml.nml.Q10Settings 260 | :members: 261 | :undoc-members: 262 | :show-inheritance: 263 | :inherited-members: 264 | 265 | 266 | 267 | ReverseTransition 268 | ^^^^^^^^^^^^^^^^^ 269 | 270 | .. autoclass:: neuroml.nml.nml.ReverseTransition 271 | :members: 272 | :undoc-members: 273 | :show-inheritance: 274 | :inherited-members: 275 | 276 | 277 | 278 | TauInfTransition 279 | ^^^^^^^^^^^^^^^^ 280 | 281 | .. autoclass:: neuroml.nml.nml.TauInfTransition 282 | :members: 283 | :undoc-members: 284 | :show-inheritance: 285 | :inherited-members: 286 | 287 | 288 | 289 | channelTypes 290 | ^^^^^^^^^^^^ 291 | 292 | .. autoclass:: neuroml.nml.nml.channelTypes 293 | :members: 294 | :undoc-members: 295 | :show-inheritance: 296 | :inherited-members: 297 | 298 | 299 | 300 | gateTypes 301 | ^^^^^^^^^ 302 | 303 | .. autoclass:: neuroml.nml.nml.gateTypes 304 | :members: 305 | :undoc-members: 306 | :show-inheritance: 307 | :inherited-members: 308 | -------------------------------------------------------------------------------- /doc/userdocs/Inputs_list.rst: -------------------------------------------------------------------------------- 1 | Inputs 2 | ###### 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | 14 | CompoundInput 15 | ^^^^^^^^^^^^^ 16 | 17 | .. autoclass:: neuroml.nml.nml.CompoundInput 18 | :members: 19 | :undoc-members: 20 | :show-inheritance: 21 | :inherited-members: 22 | 23 | 24 | 25 | CompoundInputDL 26 | ^^^^^^^^^^^^^^^ 27 | 28 | .. autoclass:: neuroml.nml.nml.CompoundInputDL 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | :inherited-members: 33 | 34 | 35 | 36 | PoissonFiringSynapse 37 | ^^^^^^^^^^^^^^^^^^^^ 38 | 39 | .. autoclass:: neuroml.nml.nml.PoissonFiringSynapse 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | :inherited-members: 44 | 45 | 46 | 47 | PulseGenerator 48 | ^^^^^^^^^^^^^^ 49 | 50 | .. autoclass:: neuroml.nml.nml.PulseGenerator 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | :inherited-members: 55 | 56 | 57 | 58 | PulseGeneratorDL 59 | ^^^^^^^^^^^^^^^^ 60 | 61 | .. autoclass:: neuroml.nml.nml.PulseGeneratorDL 62 | :members: 63 | :undoc-members: 64 | :show-inheritance: 65 | :inherited-members: 66 | 67 | 68 | 69 | RampGenerator 70 | ^^^^^^^^^^^^^ 71 | 72 | .. autoclass:: neuroml.nml.nml.RampGenerator 73 | :members: 74 | :undoc-members: 75 | :show-inheritance: 76 | :inherited-members: 77 | 78 | 79 | 80 | RampGeneratorDL 81 | ^^^^^^^^^^^^^^^ 82 | 83 | .. autoclass:: neuroml.nml.nml.RampGeneratorDL 84 | :members: 85 | :undoc-members: 86 | :show-inheritance: 87 | :inherited-members: 88 | 89 | 90 | 91 | SineGenerator 92 | ^^^^^^^^^^^^^ 93 | 94 | .. autoclass:: neuroml.nml.nml.SineGenerator 95 | :members: 96 | :undoc-members: 97 | :show-inheritance: 98 | :inherited-members: 99 | 100 | 101 | 102 | SineGeneratorDL 103 | ^^^^^^^^^^^^^^^ 104 | 105 | .. autoclass:: neuroml.nml.nml.SineGeneratorDL 106 | :members: 107 | :undoc-members: 108 | :show-inheritance: 109 | :inherited-members: 110 | 111 | 112 | 113 | Spike 114 | ^^^^^ 115 | 116 | .. autoclass:: neuroml.nml.nml.Spike 117 | :members: 118 | :undoc-members: 119 | :show-inheritance: 120 | :inherited-members: 121 | 122 | 123 | 124 | SpikeArray 125 | ^^^^^^^^^^ 126 | 127 | .. autoclass:: neuroml.nml.nml.SpikeArray 128 | :members: 129 | :undoc-members: 130 | :show-inheritance: 131 | :inherited-members: 132 | 133 | 134 | 135 | SpikeGenerator 136 | ^^^^^^^^^^^^^^ 137 | 138 | .. autoclass:: neuroml.nml.nml.SpikeGenerator 139 | :members: 140 | :undoc-members: 141 | :show-inheritance: 142 | :inherited-members: 143 | 144 | 145 | 146 | SpikeGeneratorPoisson 147 | ^^^^^^^^^^^^^^^^^^^^^ 148 | 149 | .. autoclass:: neuroml.nml.nml.SpikeGeneratorPoisson 150 | :members: 151 | :undoc-members: 152 | :show-inheritance: 153 | :inherited-members: 154 | 155 | 156 | 157 | SpikeGeneratorRandom 158 | ^^^^^^^^^^^^^^^^^^^^ 159 | 160 | .. autoclass:: neuroml.nml.nml.SpikeGeneratorRandom 161 | :members: 162 | :undoc-members: 163 | :show-inheritance: 164 | :inherited-members: 165 | 166 | 167 | 168 | SpikeGeneratorRefPoisson 169 | ^^^^^^^^^^^^^^^^^^^^^^^^ 170 | 171 | .. autoclass:: neuroml.nml.nml.SpikeGeneratorRefPoisson 172 | :members: 173 | :undoc-members: 174 | :show-inheritance: 175 | :inherited-members: 176 | 177 | 178 | 179 | TimedSynapticInput 180 | ^^^^^^^^^^^^^^^^^^ 181 | 182 | .. autoclass:: neuroml.nml.nml.TimedSynapticInput 183 | :members: 184 | :undoc-members: 185 | :show-inheritance: 186 | :inherited-members: 187 | 188 | 189 | 190 | TransientPoissonFiringSynapse 191 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 192 | 193 | .. autoclass:: neuroml.nml.nml.TransientPoissonFiringSynapse 194 | :members: 195 | :undoc-members: 196 | :show-inheritance: 197 | :inherited-members: 198 | 199 | 200 | 201 | VoltageClamp 202 | ^^^^^^^^^^^^ 203 | 204 | .. autoclass:: neuroml.nml.nml.VoltageClamp 205 | :members: 206 | :undoc-members: 207 | :show-inheritance: 208 | :inherited-members: 209 | 210 | 211 | 212 | VoltageClampTriple 213 | ^^^^^^^^^^^^^^^^^^ 214 | 215 | .. autoclass:: neuroml.nml.nml.VoltageClampTriple 216 | :members: 217 | :undoc-members: 218 | :show-inheritance: 219 | :inherited-members: 220 | -------------------------------------------------------------------------------- /doc/userdocs/Networks_list.rst: -------------------------------------------------------------------------------- 1 | Networks 2 | ######## 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | 14 | Connection 15 | ^^^^^^^^^^ 16 | 17 | .. autoclass:: neuroml.nml.nml.Connection 18 | :members: 19 | :undoc-members: 20 | :show-inheritance: 21 | :inherited-members: 22 | 23 | 24 | 25 | ConnectionWD 26 | ^^^^^^^^^^^^ 27 | 28 | .. autoclass:: neuroml.nml.nml.ConnectionWD 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | :inherited-members: 33 | 34 | 35 | 36 | ContinuousConnection 37 | ^^^^^^^^^^^^^^^^^^^^ 38 | 39 | .. autoclass:: neuroml.nml.nml.ContinuousConnection 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | :inherited-members: 44 | 45 | 46 | 47 | ContinuousConnectionInstance 48 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 49 | 50 | .. autoclass:: neuroml.nml.nml.ContinuousConnectionInstance 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | :inherited-members: 55 | 56 | 57 | 58 | ContinuousConnectionInstanceW 59 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 60 | 61 | .. autoclass:: neuroml.nml.nml.ContinuousConnectionInstanceW 62 | :members: 63 | :undoc-members: 64 | :show-inheritance: 65 | :inherited-members: 66 | 67 | 68 | 69 | ContinuousProjection 70 | ^^^^^^^^^^^^^^^^^^^^ 71 | 72 | .. autoclass:: neuroml.nml.nml.ContinuousProjection 73 | :members: 74 | :undoc-members: 75 | :show-inheritance: 76 | :inherited-members: 77 | 78 | 79 | 80 | ElectricalConnection 81 | ^^^^^^^^^^^^^^^^^^^^ 82 | 83 | .. autoclass:: neuroml.nml.nml.ElectricalConnection 84 | :members: 85 | :undoc-members: 86 | :show-inheritance: 87 | :inherited-members: 88 | 89 | 90 | 91 | ElectricalConnectionInstance 92 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 93 | 94 | .. autoclass:: neuroml.nml.nml.ElectricalConnectionInstance 95 | :members: 96 | :undoc-members: 97 | :show-inheritance: 98 | :inherited-members: 99 | 100 | 101 | 102 | ElectricalConnectionInstanceW 103 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 104 | 105 | .. autoclass:: neuroml.nml.nml.ElectricalConnectionInstanceW 106 | :members: 107 | :undoc-members: 108 | :show-inheritance: 109 | :inherited-members: 110 | 111 | 112 | 113 | ElectricalProjection 114 | ^^^^^^^^^^^^^^^^^^^^ 115 | 116 | .. autoclass:: neuroml.nml.nml.ElectricalProjection 117 | :members: 118 | :undoc-members: 119 | :show-inheritance: 120 | :inherited-members: 121 | 122 | 123 | 124 | ExplicitInput 125 | ^^^^^^^^^^^^^ 126 | 127 | .. autoclass:: neuroml.nml.nml.ExplicitInput 128 | :members: 129 | :undoc-members: 130 | :show-inheritance: 131 | :inherited-members: 132 | 133 | 134 | 135 | Input 136 | ^^^^^ 137 | 138 | .. autoclass:: neuroml.nml.nml.Input 139 | :members: 140 | :undoc-members: 141 | :show-inheritance: 142 | :inherited-members: 143 | 144 | 145 | 146 | InputList 147 | ^^^^^^^^^ 148 | 149 | .. autoclass:: neuroml.nml.nml.InputList 150 | :members: 151 | :undoc-members: 152 | :show-inheritance: 153 | :inherited-members: 154 | 155 | 156 | 157 | InputW 158 | ^^^^^^ 159 | 160 | .. autoclass:: neuroml.nml.nml.InputW 161 | :members: 162 | :undoc-members: 163 | :show-inheritance: 164 | :inherited-members: 165 | 166 | 167 | 168 | Instance 169 | ^^^^^^^^ 170 | 171 | .. autoclass:: neuroml.nml.nml.Instance 172 | :members: 173 | :undoc-members: 174 | :show-inheritance: 175 | :inherited-members: 176 | 177 | 178 | 179 | Location 180 | ^^^^^^^^ 181 | 182 | .. autoclass:: neuroml.nml.nml.Location 183 | :members: 184 | :undoc-members: 185 | :show-inheritance: 186 | :inherited-members: 187 | 188 | 189 | 190 | Network 191 | ^^^^^^^ 192 | 193 | .. autoclass:: neuroml.nml.nml.Network 194 | :members: 195 | :undoc-members: 196 | :show-inheritance: 197 | :inherited-members: 198 | 199 | 200 | 201 | Population 202 | ^^^^^^^^^^ 203 | 204 | .. autoclass:: neuroml.nml.nml.Population 205 | :members: 206 | :undoc-members: 207 | :show-inheritance: 208 | :inherited-members: 209 | 210 | 211 | 212 | Projection 213 | ^^^^^^^^^^ 214 | 215 | .. autoclass:: neuroml.nml.nml.Projection 216 | :members: 217 | :undoc-members: 218 | :show-inheritance: 219 | :inherited-members: 220 | 221 | 222 | 223 | Region 224 | ^^^^^^ 225 | 226 | .. autoclass:: neuroml.nml.nml.Region 227 | :members: 228 | :undoc-members: 229 | :show-inheritance: 230 | :inherited-members: 231 | 232 | 233 | 234 | SynapticConnection 235 | ^^^^^^^^^^^^^^^^^^ 236 | 237 | .. autoclass:: neuroml.nml.nml.SynapticConnection 238 | :members: 239 | :undoc-members: 240 | :show-inheritance: 241 | :inherited-members: 242 | 243 | 244 | 245 | networkTypes 246 | ^^^^^^^^^^^^ 247 | 248 | .. autoclass:: neuroml.nml.nml.networkTypes 249 | :members: 250 | :undoc-members: 251 | :show-inheritance: 252 | :inherited-members: 253 | 254 | 255 | 256 | populationTypes 257 | ^^^^^^^^^^^^^^^ 258 | 259 | .. autoclass:: neuroml.nml.nml.populationTypes 260 | :members: 261 | :undoc-members: 262 | :show-inheritance: 263 | :inherited-members: 264 | -------------------------------------------------------------------------------- /doc/userdocs/NeuroMLCoreCompTypes_list.rst: -------------------------------------------------------------------------------- 1 | NeuroMLCoreCompTypes 2 | #################### 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | 14 | Annotation 15 | ^^^^^^^^^^ 16 | 17 | .. autoclass:: neuroml.nml.nml.Annotation 18 | :members: 19 | :undoc-members: 20 | :show-inheritance: 21 | :inherited-members: 22 | 23 | 24 | 25 | Point3DWithDiam 26 | ^^^^^^^^^^^^^^^ 27 | 28 | .. autoclass:: neuroml.nml.nml.Point3DWithDiam 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | :inherited-members: 33 | 34 | 35 | 36 | Property 37 | ^^^^^^^^ 38 | 39 | .. autoclass:: neuroml.nml.nml.Property 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | :inherited-members: 44 | -------------------------------------------------------------------------------- /doc/userdocs/NeuroMLCoreDimensions_list.rst: -------------------------------------------------------------------------------- 1 | NeuroMLCoreDimensions 2 | ##################### 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | -------------------------------------------------------------------------------- /doc/userdocs/PyNN_list.rst: -------------------------------------------------------------------------------- 1 | PyNN 2 | #### 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | 14 | AlphaCondSynapse 15 | ^^^^^^^^^^^^^^^^ 16 | 17 | .. autoclass:: neuroml.nml.nml.AlphaCondSynapse 18 | :members: 19 | :undoc-members: 20 | :show-inheritance: 21 | :inherited-members: 22 | 23 | 24 | 25 | AlphaCurrSynapse 26 | ^^^^^^^^^^^^^^^^ 27 | 28 | .. autoclass:: neuroml.nml.nml.AlphaCurrSynapse 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | :inherited-members: 33 | 34 | 35 | 36 | BasePynnSynapse 37 | ^^^^^^^^^^^^^^^ 38 | 39 | .. autoclass:: neuroml.nml.nml.BasePynnSynapse 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | :inherited-members: 44 | 45 | 46 | 47 | EIF_cond_alpha_isfa_ista 48 | ^^^^^^^^^^^^^^^^^^^^^^^^ 49 | 50 | .. autoclass:: neuroml.nml.nml.EIF_cond_alpha_isfa_ista 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | :inherited-members: 55 | 56 | 57 | 58 | EIF_cond_exp_isfa_ista 59 | ^^^^^^^^^^^^^^^^^^^^^^ 60 | 61 | .. autoclass:: neuroml.nml.nml.EIF_cond_exp_isfa_ista 62 | :members: 63 | :undoc-members: 64 | :show-inheritance: 65 | :inherited-members: 66 | 67 | 68 | 69 | ExpCondSynapse 70 | ^^^^^^^^^^^^^^ 71 | 72 | .. autoclass:: neuroml.nml.nml.ExpCondSynapse 73 | :members: 74 | :undoc-members: 75 | :show-inheritance: 76 | :inherited-members: 77 | 78 | 79 | 80 | ExpCurrSynapse 81 | ^^^^^^^^^^^^^^ 82 | 83 | .. autoclass:: neuroml.nml.nml.ExpCurrSynapse 84 | :members: 85 | :undoc-members: 86 | :show-inheritance: 87 | :inherited-members: 88 | 89 | 90 | 91 | HH_cond_exp 92 | ^^^^^^^^^^^ 93 | 94 | .. autoclass:: neuroml.nml.nml.HH_cond_exp 95 | :members: 96 | :undoc-members: 97 | :show-inheritance: 98 | :inherited-members: 99 | 100 | 101 | 102 | IF_cond_alpha 103 | ^^^^^^^^^^^^^ 104 | 105 | .. autoclass:: neuroml.nml.nml.IF_cond_alpha 106 | :members: 107 | :undoc-members: 108 | :show-inheritance: 109 | :inherited-members: 110 | 111 | 112 | 113 | IF_cond_exp 114 | ^^^^^^^^^^^ 115 | 116 | .. autoclass:: neuroml.nml.nml.IF_cond_exp 117 | :members: 118 | :undoc-members: 119 | :show-inheritance: 120 | :inherited-members: 121 | 122 | 123 | 124 | IF_curr_alpha 125 | ^^^^^^^^^^^^^ 126 | 127 | .. autoclass:: neuroml.nml.nml.IF_curr_alpha 128 | :members: 129 | :undoc-members: 130 | :show-inheritance: 131 | :inherited-members: 132 | 133 | 134 | 135 | IF_curr_exp 136 | ^^^^^^^^^^^ 137 | 138 | .. autoclass:: neuroml.nml.nml.IF_curr_exp 139 | :members: 140 | :undoc-members: 141 | :show-inheritance: 142 | :inherited-members: 143 | 144 | 145 | 146 | SpikeSourcePoisson 147 | ^^^^^^^^^^^^^^^^^^ 148 | 149 | .. autoclass:: neuroml.nml.nml.SpikeSourcePoisson 150 | :members: 151 | :undoc-members: 152 | :show-inheritance: 153 | :inherited-members: 154 | -------------------------------------------------------------------------------- /doc/userdocs/Simulation_list.rst: -------------------------------------------------------------------------------- 1 | Simulation 2 | ########## 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | -------------------------------------------------------------------------------- /doc/userdocs/Synapses_list.rst: -------------------------------------------------------------------------------- 1 | Synapses 2 | ######## 3 | 4 | 5 | 6 | 7 | This documentation is auto-generated from the `NeuroML schema `__. 8 | 9 | 10 | 11 | 12 | .. Generated using nml-core-docs.py 13 | 14 | AlphaCurrentSynapse 15 | ^^^^^^^^^^^^^^^^^^^ 16 | 17 | .. autoclass:: neuroml.nml.nml.AlphaCurrentSynapse 18 | :members: 19 | :undoc-members: 20 | :show-inheritance: 21 | :inherited-members: 22 | 23 | 24 | 25 | AlphaSynapse 26 | ^^^^^^^^^^^^ 27 | 28 | .. autoclass:: neuroml.nml.nml.AlphaSynapse 29 | :members: 30 | :undoc-members: 31 | :show-inheritance: 32 | :inherited-members: 33 | 34 | 35 | 36 | BaseConductanceBasedSynapse 37 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ 38 | 39 | .. autoclass:: neuroml.nml.nml.BaseConductanceBasedSynapse 40 | :members: 41 | :undoc-members: 42 | :show-inheritance: 43 | :inherited-members: 44 | 45 | 46 | 47 | BaseConductanceBasedSynapseTwo 48 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 49 | 50 | .. autoclass:: neuroml.nml.nml.BaseConductanceBasedSynapseTwo 51 | :members: 52 | :undoc-members: 53 | :show-inheritance: 54 | :inherited-members: 55 | 56 | 57 | 58 | BaseCurrentBasedSynapse 59 | ^^^^^^^^^^^^^^^^^^^^^^^ 60 | 61 | .. autoclass:: neuroml.nml.nml.BaseCurrentBasedSynapse 62 | :members: 63 | :undoc-members: 64 | :show-inheritance: 65 | :inherited-members: 66 | 67 | 68 | 69 | BaseSynapse 70 | ^^^^^^^^^^^ 71 | 72 | .. autoclass:: neuroml.nml.nml.BaseSynapse 73 | :members: 74 | :undoc-members: 75 | :show-inheritance: 76 | :inherited-members: 77 | 78 | 79 | 80 | BaseVoltageDepSynapse 81 | ^^^^^^^^^^^^^^^^^^^^^ 82 | 83 | .. autoclass:: neuroml.nml.nml.BaseVoltageDepSynapse 84 | :members: 85 | :undoc-members: 86 | :show-inheritance: 87 | :inherited-members: 88 | 89 | 90 | 91 | BlockingPlasticSynapse 92 | ^^^^^^^^^^^^^^^^^^^^^^ 93 | 94 | .. autoclass:: neuroml.nml.nml.BlockingPlasticSynapse 95 | :members: 96 | :undoc-members: 97 | :show-inheritance: 98 | :inherited-members: 99 | 100 | 101 | 102 | DoubleSynapse 103 | ^^^^^^^^^^^^^ 104 | 105 | .. autoclass:: neuroml.nml.nml.DoubleSynapse 106 | :members: 107 | :undoc-members: 108 | :show-inheritance: 109 | :inherited-members: 110 | 111 | 112 | 113 | ExpOneSynapse 114 | ^^^^^^^^^^^^^ 115 | 116 | .. autoclass:: neuroml.nml.nml.ExpOneSynapse 117 | :members: 118 | :undoc-members: 119 | :show-inheritance: 120 | :inherited-members: 121 | 122 | 123 | 124 | ExpThreeSynapse 125 | ^^^^^^^^^^^^^^^ 126 | 127 | .. autoclass:: neuroml.nml.nml.ExpThreeSynapse 128 | :members: 129 | :undoc-members: 130 | :show-inheritance: 131 | :inherited-members: 132 | 133 | 134 | 135 | ExpTwoSynapse 136 | ^^^^^^^^^^^^^ 137 | 138 | .. autoclass:: neuroml.nml.nml.ExpTwoSynapse 139 | :members: 140 | :undoc-members: 141 | :show-inheritance: 142 | :inherited-members: 143 | 144 | 145 | 146 | GapJunction 147 | ^^^^^^^^^^^ 148 | 149 | .. autoclass:: neuroml.nml.nml.GapJunction 150 | :members: 151 | :undoc-members: 152 | :show-inheritance: 153 | :inherited-members: 154 | 155 | 156 | 157 | GradedSynapse 158 | ^^^^^^^^^^^^^ 159 | 160 | .. autoclass:: neuroml.nml.nml.GradedSynapse 161 | :members: 162 | :undoc-members: 163 | :show-inheritance: 164 | :inherited-members: 165 | 166 | 167 | 168 | LinearGradedSynapse 169 | ^^^^^^^^^^^^^^^^^^^ 170 | 171 | .. autoclass:: neuroml.nml.nml.LinearGradedSynapse 172 | :members: 173 | :undoc-members: 174 | :show-inheritance: 175 | :inherited-members: 176 | 177 | 178 | 179 | SilentSynapse 180 | ^^^^^^^^^^^^^ 181 | 182 | .. autoclass:: neuroml.nml.nml.SilentSynapse 183 | :members: 184 | :undoc-members: 185 | :show-inheritance: 186 | :inherited-members: 187 | -------------------------------------------------------------------------------- /doc/userdocs/api.rst: -------------------------------------------------------------------------------- 1 | API documentation 2 | ================= 3 | 4 | The libNeuroML API includes the core NeuroML classes and various utilities. 5 | You can find information on these in the pages below. 6 | 7 | .. toctree:: 8 | :maxdepth: 2 9 | 10 | coreclasses 11 | loaders 12 | writers 13 | utils 14 | arraymorph 15 | -------------------------------------------------------------------------------- /doc/userdocs/arraymorph.rst: -------------------------------------------------------------------------------- 1 | 2 | :mod:`arraymorph` Module 3 | ------------------------ 4 | 5 | .. automodule:: neuroml.arraymorph 6 | :members: 7 | :undoc-members: 8 | :show-inheritance: 9 | -------------------------------------------------------------------------------- /doc/userdocs/bibliography.rst: -------------------------------------------------------------------------------- 1 | References 2 | ========== 3 | 4 | .. bibliography:: 5 | :all: 6 | -------------------------------------------------------------------------------- /doc/userdocs/coreclasses.rst: -------------------------------------------------------------------------------- 1 | :mod:`nml` Module (NeuroML Core classes) 2 | ----------------------------------------- 3 | 4 | These NeuroML core classes are Python representations of the Component Types defined in the `NeuroML standard `__ . 5 | These can be used to build NeuroML models in Python, and these models can then be exported to the standard XML NeuroML representation. 6 | These core classes also contain some utility functions to make it easier for users to carry out common tasks. 7 | 8 | Each NeuroML Component Type is represented here as a Python class. 9 | Due to implementation limitations, whereas NeuroML Component Types use `lower camel case naming `_, the Python classes here use `upper camel case naming `__. 10 | So, for example, the :code:`adExIaFCell` Component Type in the NeuroML schema becomes the :code:`AdExIaFCell` class here, and :code:`expTwoSynapse` becomes the :code:`ExpTwoSynapse` class. 11 | 12 | The :code:`child` and :code:`children` elements that NeuroML Component Types can have are represented in the Python classes as variables. 13 | The variable names, to distinguish them from class names, use `snake case `__. 14 | So for example, the :code:`cell` NeuroML Component Type has a corresponding :code:`Cell` Python class here. 15 | The :code:`biophysicalProperties` child Component Type in :code:`cell` is represented as the :code:`biophysical_properties` list variable in the :code:`Cell` Python class. 16 | The class signatures list all the child/children elements and text fields that the corresponding Component Type possesses. 17 | To again use the :code:`Cell` class as an example, the construction signature is this: 18 | 19 | :: 20 | 21 | class neuroml.nml.nml.Cell(neuro_lex_id=None, id=None, metaid=None, notes=None, properties=None, annotation=None, morphology_attr=None, biophysical_properties_attr=None, morphology=None, biophysical_properties=None, extensiontype_=None, **kwargs_) 22 | 23 | As can be seen here, it includes both the :code:`biophysical_properties` and :code:`morphology` child elements as variables. 24 | 25 | Please see the examples in the `NeuroML documentation `__ to see usage examples of libNeuroML. 26 | Please also note that this module is also included in the top level of the `neuroml` package, so you can use these classes by importing neuroml: 27 | 28 | :: 29 | 30 | from neuroml import AdExIaFCell 31 | 32 | .. 33 | To get the list of all the validate* methods and members to add to the exlude list, use this: 34 | grep -Eo "def[[:space:]]*validate([[:alnum:]]|_)*|validate([[:alnum:]]|_)*patterns_" nml.py | sed -e 's/^.*def validate/validate/' | sort -h | uniq | tr '\n' ',' 35 | 36 | 37 | 38 | List of Component classes 39 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ 40 | 41 | This documentation is auto-generated from the `NeuroML schema `__. 42 | In case of issues, please refer to the schema documentation for clarifications. 43 | If the schema documentation does not resolve the issue, please `contact us `__. 44 | 45 | .. toctree:: 46 | :maxdepth: 1 47 | 48 | Cells_list 49 | Synapses_list 50 | Channels_list 51 | Inputs_list 52 | Networks_list 53 | PyNN_list 54 | NeuroMLCoreCompTypes_list 55 | Other_list 56 | -------------------------------------------------------------------------------- /doc/userdocs/examples.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Examples 3 | ======== 4 | 5 | The examples in this section are intended to give in depth overviews of how to accomplish 6 | specific tasks with libNeuroML. 7 | 8 | These examples are located in the neuroml/examples directory and can 9 | be tested to confirm they work by running the run_all.py script. 10 | 11 | .. contents:: Examples 12 | 13 | Creating a NeuroML morphology 14 | ----------------------------- 15 | 16 | .. literalinclude:: ../../neuroml/examples/morphology_generation.py 17 | 18 | Loading and modifying a file 19 | ---------------------------- 20 | 21 | .. literalinclude:: ../../neuroml/examples/loading_modifying_writing.py 22 | 23 | 24 | Building a network 25 | ------------------ 26 | 27 | .. literalinclude:: ../../neuroml/examples/build_network.py 28 | 29 | Building a 3D network 30 | --------------------- 31 | 32 | .. literalinclude:: ../../neuroml/examples/build_3D_network.py 33 | 34 | Ion channels 35 | ------------ 36 | 37 | .. literalinclude:: ../../neuroml/examples/ion_channel_generation.py 38 | 39 | PyNN models 40 | ----------- 41 | 42 | .. literalinclude:: ../../neuroml/examples/write_pynn.py 43 | 44 | Synapses 45 | -------- 46 | 47 | .. literalinclude:: ../../neuroml/examples/write_syns.py 48 | 49 | 50 | Working with arraymorphs 51 | ------------------------ 52 | 53 | .. literalinclude:: ../../neuroml/examples/arraymorph_generation.py 54 | 55 | Working with Izhikevich Cells 56 | ----------------------------- 57 | 58 | These examples were kindly contributed by Steve Marsh 59 | 60 | .. literalinclude:: ../../neuroml/examples/single_izhikevich_reader.py 61 | .. literalinclude:: ../../neuroml/examples/single_izhikevich_writer.py 62 | -------------------------------------------------------------------------------- /doc/userdocs/index.rst: -------------------------------------------------------------------------------- 1 | User guide 2 | ********** 3 | 4 | .. toctree:: 5 | :maxdepth: 2 6 | 7 | introduction 8 | install 9 | api 10 | examples 11 | bibliography 12 | -------------------------------------------------------------------------------- /doc/userdocs/install.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Using Pip 5 | ---------- 6 | 7 | On most systems with a Python installation, libNeuroML can be installed using the default Python package manager, Pip: 8 | 9 | :: 10 | 11 | pip install libNeuroML 12 | 13 | It is recommended to use a `virtual environment `_ when installing Python packages using `pip` to prevent these from conflicting with other system libraries. 14 | 15 | This will support the default XML serialization. 16 | Note that you may be required to install libhdf5 using your package manager because PyTables' wheels for python 3.7+ depend on the system libhdf5 to build. 17 | 18 | :: 19 | 20 | # On Ubuntu based systems 21 | sudo apt-get install libhdf5-dev 22 | pip install libNeuroML 23 | 24 | 25 | On Fedora based systems 26 | ------------------------ 27 | 28 | On `Fedora `_ Linux systems, the `NeuroFedora `_ community provides libNeuroML in the `standard Fedora repos `_ and can be installed using the following commands: 29 | 30 | :: 31 | 32 | sudo dnf install python3-libNeuroML 33 | 34 | 35 | Install from source 36 | -------------------- 37 | 38 | You can clone the `GitHub repository `_ and also build libNeuroML from the sources. 39 | For this, you will need `git`_: 40 | 41 | :: 42 | 43 | git clone git://github.com/NeuralEnsemble/libNeuroML.git 44 | cd libNeuroML 45 | 46 | 47 | More details about the git repository and making your own branch/fork are `here `_. 48 | To build and install libNeuroML, you can use the standard install method for Python packages (preferably in a virtual environment): 49 | 50 | :: 51 | 52 | pip install . 53 | 54 | To use the **latest development version of libNeuroML**, switch to the development branch: 55 | 56 | :: 57 | 58 | git checkout development 59 | pip install . 60 | 61 | 62 | To install developer dependencies and other extras, use the extras declared in the `setup.cfg` file. E.g.: 63 | 64 | :: 65 | 66 | pip install .[dev] 67 | pip install .[test] 68 | pip install .[doc] 69 | 70 | 71 | Run an example 72 | -------------- 73 | 74 | Some sample scripts are included in `neuroml/examples`, e.g. : 75 | 76 | :: 77 | 78 | cd neuroml/examples 79 | python build_network.py 80 | 81 | The standard examples can also be found :doc:`examples`. 82 | 83 | Unit tests 84 | ---------- 85 | 86 | To run unit tests cd to the directory `neuroml/test` and use the Python unittest module discover method: 87 | 88 | :: 89 | 90 | cd neuroml/test/ 91 | python -m unittest discover 92 | 93 | If all tests passed correctly, your output should look something like this: 94 | 95 | :: 96 | 97 | ....... 98 | ---------------------------------------------------------------------- 99 | Ran 55 tests in 40.1s 100 | 101 | OK 102 | 103 | You can also use PyTest to run tests. 104 | 105 | :: 106 | 107 | pip install pytest 108 | pytest -v --strict -W all 109 | 110 | 111 | .. _Git: https://git-scm.com 112 | -------------------------------------------------------------------------------- /doc/userdocs/introduction.rst: -------------------------------------------------------------------------------- 1 | Introduction 2 | ============ 3 | 4 | This package provides Python libNeuroML, for working with neuronal models specified in `NeuroML 2 `_. 5 | 6 | .. warning:: **libNeuroML targets NeuroML v2.0** 7 | 8 | libNeuroML targets `NeuroML v2.0`_, which is described in `Cannon et al, 2014 `_). 9 | NeuroML v1.8.1 (`Gleeson et al. 2010 `_) is now deprecated and not supported by libNeuroML. 10 | 11 | For a detailed description of libNeuroML see :cite:t:`Vella2014`. 12 | *Please cite the paper if you use libNeuroML.* 13 | 14 | NeuroML 15 | ------- 16 | 17 | NeuroML provides an object model for describing neuronal morphologies, ion channels, synapses and 3D network structure. 18 | For more information on NeuroML 2 and LEMS please see the `NeuroML documentation `_. 19 | 20 | 21 | Serialisations 22 | -------------- 23 | 24 | The XML serialisation will be the "natural" serialisation and will follow closely the NeuroML object model. 25 | The format of the XML will be specified by the XML Schema definition (XSD file). 26 | 27 | Other serialisations have also been developed (HDF5, SWC). 28 | Please see :cite:t:`Vella2014` for more details. 29 | 30 | 31 | .. _NeuroML v2.0: http://docs.neuroml.org 32 | .. _LEMS: http://lems.github.io/LEMS/ 33 | .. _NeuroHDF: http://neurohdf.readthedocs.org/en/latest/ 34 | -------------------------------------------------------------------------------- /doc/userdocs/loaders.rst: -------------------------------------------------------------------------------- 1 | :mod:`loaders` Module 2 | --------------------- 3 | 4 | .. automodule:: neuroml.loaders 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/userdocs/utils.rst: -------------------------------------------------------------------------------- 1 | :mod:`utils` Module 2 | --------------------- 3 | 4 | .. automodule:: neuroml.utils 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /doc/userdocs/writers.rst: -------------------------------------------------------------------------------- 1 | :mod:`writers` Module 2 | --------------------- 3 | 4 | .. automodule:: neuroml.writers 5 | :members: 6 | :undoc-members: 7 | :show-inheritance: 8 | -------------------------------------------------------------------------------- /neuroml/__init__.py: -------------------------------------------------------------------------------- 1 | import logging 2 | 3 | from . import build_time_validation 4 | from .__version__ import __version__ as __version__ 5 | from .__version__ import __version_info__ as __version__info__ 6 | from .__version__ import current_neuroml_version as current_neuroml_version 7 | from .nml.nml import * # allows importation of all neuroml classes 8 | 9 | logging.basicConfig( 10 | format="libNeuroML >>> %(levelname)s - %(message)s", 11 | level=logging.WARN, 12 | ) 13 | 14 | logger = logging.getLogger(__name__) 15 | logger.setLevel(logging.INFO) 16 | 17 | 18 | def print_(text, verbose=True): 19 | if verbose: 20 | prefix = "libNeuroML >>> " 21 | # if not isinstance(text, str): text = text.decode('ascii') 22 | if verbose: 23 | print("%s%s" % (prefix, text.replace("\n", "\n" + prefix))) 24 | 25 | 26 | def disable_build_time_validation(): 27 | """Disable build time validation. 28 | 29 | This will disable the validation of components when they are being created 30 | using the factory functions, such as component_factory, and add. 31 | 32 | This is useful for certain cases where a new component cannot necessarily 33 | be created in a valid state from the beginning. For example, a population 34 | is usually created after a network, but a network without a population 35 | would not be valid. 36 | 37 | This switch provides a convenient way to disable this check. 38 | 39 | Please note that this should only be used sparingly, and not abused to turn 40 | off build time validation completely. 41 | 42 | .. versionadded:: 0.6.0 43 | """ 44 | build_time_validation.ENABLED = False 45 | logger.warning("Build time validation has been disabled.") 46 | 47 | 48 | def enable_build_time_validation(): 49 | """Enable build time validation 50 | 51 | .. versionadded:: 0.6.0 52 | """ 53 | build_time_validation.ENABLED = True 54 | logger.info("Build time validation has been enabled.") 55 | 56 | 57 | def get_build_time_validation() -> bool: 58 | """Get build time validation 59 | 60 | .. versionadded:: 0.6.0 61 | 62 | :returns: state of build time validation 63 | :rtype: bool 64 | """ 65 | return build_time_validation.ENABLED 66 | -------------------------------------------------------------------------------- /neuroml/__version__.py: -------------------------------------------------------------------------------- 1 | """ 2 | libNeuroML version information 3 | 4 | File: neuroml/__version__.py 5 | 6 | Copyright 2023 NeuroML contributors 7 | """ 8 | 9 | try: 10 | import importlib.metadata 11 | 12 | __version__ = importlib.metadata.version("libNeuroML") 13 | except ImportError: 14 | import importlib_metadata 15 | 16 | __version__ = importlib_metadata.version("libNeuroML") 17 | 18 | __version_info__: tuple = tuple(int(i) for i in __version__.split(".")) 19 | 20 | 21 | current_neuroml_version: str = "v2.3.1" 22 | -------------------------------------------------------------------------------- /neuroml/arraymorph_load_time_benchmark.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | 3 | import neuroml 4 | import neuroml.arraymorph as am 5 | 6 | 7 | class Benchmark: 8 | def __init__(self, num_segments): 9 | self.num_segments = num_segments 10 | 11 | def set_up(self): 12 | num_segments = int(1e4) # Per cell 13 | num_vertices = num_segments + 1 14 | 15 | x = np.linspace(0, 10, num_vertices) 16 | y = np.zeros(num_vertices) 17 | z = np.zeros(num_vertices) 18 | d = np.linspace(1, 0.01, num_vertices) 19 | 20 | vertices = np.array([x, y, z, d]).T 21 | 22 | connectivity = range(-1, num_segments) 23 | 24 | big_arraymorph = am.ArrayMorphology( 25 | vertices=vertices, connectivity=connectivity 26 | ) 27 | transposed_x = x + 10 28 | transposed_vertices = np.array([transposed_x, y, z, d]).T 29 | 30 | transposed_arraymorph = am.ArrayMorphology( 31 | vertices=transposed_vertices, connectivity=connectivity 32 | ) 33 | 34 | bigger_d = d + 0.5 35 | fatter_vertices = np.array([x, y, z, bigger_d]).T 36 | 37 | fatter_arraymorph = am.ArrayMorphology( 38 | vertices=fatter_vertices, connectivity=connectivity 39 | ) 40 | 41 | neuroml_cell = neuroml.Cell(id="cell_4") 42 | neuroml_morphology = neuroml.Morphology(id="my_morph") 43 | neuroml_cell.morphology = neuroml_morphology 44 | 45 | self.transposed_arraymorph = transposed_arraymorph 46 | self.fatter_arraymorph = fatter_arraymorph 47 | self.big_arraymorph = big_arraymorph 48 | 49 | self.cell_1 = neuroml.Cell(id="cell_1") 50 | self.cell_2 = neuroml.Cell(id="cell_2") 51 | self.cell_3 = neuroml.Cell(id="cell_3") 52 | 53 | self.cell_1.morphology = transposed_arraymorph 54 | self.cell_2.morphology = fatter_arraymorph 55 | self.cell_3.morphology = big_arraymorph 56 | 57 | self.test_doc = neuroml.NeuroMLDocument(id="TestDocument") 58 | 59 | self.test_doc.cells.append(self.cell_1) 60 | self.test_doc.cells.append(self.cell_2) 61 | self.test_doc.cells.append(self.cell_3) 62 | self.test_doc.cells.append(neuroml_cell) 63 | -------------------------------------------------------------------------------- /neuroml/build_time_validation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Module handling the current state of the build time validation. 3 | 4 | Setting ENABLED to False will disable build time validation when using the 5 | `component_factory` and `add` functions. This setting overrides the `validate` 6 | parameter of the two functions also. 7 | 8 | Disabling build time validation is useful for certain cases where a new 9 | component cannot necessarily be created in a valid state from the beginning. 10 | For example, a population is usually created after a network, but a network 11 | without a population would not be valid. 12 | 13 | Please note that this should only be used sparingly, and not abused to turn 14 | off build time validation completely. 15 | 16 | Split out into a separate module so that all the parts of the code can 17 | access/modify it without the creation of circular dependencies. 18 | 19 | .. versionadded:: 0.6.0 20 | 21 | File: build_time_validation.py 22 | 23 | Copyright 2024 NeuroML contributors 24 | """ 25 | 26 | ENABLED = True 27 | -------------------------------------------------------------------------------- /neuroml/examples/arraymorph_generation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example of connecting segments together to create a 3 | multicompartmental model of a cell. 4 | 5 | In this case ArrayMorphology will be used rather than 6 | Morphology - demonstrating its similarity and 7 | ability to save in HDF5 format 8 | """ 9 | 10 | import neuroml 11 | import neuroml.arraymorph as am 12 | import neuroml.writers as writers 13 | 14 | p = neuroml.Point3DWithDiam(x=0, y=0, z=0, diameter=50) 15 | d = neuroml.Point3DWithDiam(x=50, y=0, z=0, diameter=50) 16 | soma = neuroml.Segment(proximal=p, distal=d) 17 | soma.name = "Soma" 18 | soma.id = 0 19 | 20 | # now make an axon with 100 compartments: 21 | 22 | parent = neuroml.SegmentParent(segments=soma.id) 23 | parent_segment = soma 24 | axon_segments = [] 25 | seg_id = 1 26 | for i in range(100): 27 | p = neuroml.Point3DWithDiam( 28 | x=parent_segment.distal.x, 29 | y=parent_segment.distal.y, 30 | z=parent_segment.distal.z, 31 | diameter=0.1, 32 | ) 33 | 34 | d = neuroml.Point3DWithDiam( 35 | x=parent_segment.distal.x + 10, 36 | y=parent_segment.distal.y, 37 | z=parent_segment.distal.z, 38 | diameter=0.1, 39 | ) 40 | 41 | axon_segment = neuroml.Segment(proximal=p, distal=d, parent=parent) 42 | 43 | axon_segment.id = seg_id 44 | 45 | axon_segment.name = "axon_segment_" + str(axon_segment.id) 46 | 47 | # now reset everything: 48 | parent = neuroml.SegmentParent(segments=axon_segment.id) 49 | parent_segment = axon_segment 50 | seg_id += 1 51 | 52 | axon_segments.append(axon_segment) 53 | 54 | test_morphology = am.ArrayMorphology() 55 | test_morphology.segments.append(soma) 56 | test_morphology.segments += axon_segments 57 | test_morphology.id = "TestMorphology" 58 | 59 | cell = neuroml.Cell() 60 | cell.name = "TestCell" 61 | cell.id = "TestCell" 62 | cell.morphology = test_morphology 63 | 64 | 65 | doc = neuroml.NeuroMLDocument() 66 | # doc.name = "Test neuroML document" 67 | 68 | doc.cells.append(cell) 69 | doc.id = "TestNeuroMLDocument" 70 | 71 | nml_file = "tmp/arraymorph.nml" 72 | 73 | writers.NeuroMLWriter.write(doc, nml_file) 74 | 75 | print("Written morphology file to: " + nml_file) 76 | 77 | ###### Validate the NeuroML ###### 78 | 79 | from neuroml.utils import validate_neuroml2 80 | 81 | validate_neuroml2(nml_file) 82 | -------------------------------------------------------------------------------- /neuroml/examples/build_3D_network.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Example to build a full spiking IaF network throught libNeuroML & save it as XML & validate it 4 | 5 | """ 6 | 7 | from random import random 8 | 9 | import neuroml.writers as writers 10 | from neuroml import ( 11 | Cell, 12 | Connection, 13 | ExpOneSynapse, 14 | Instance, 15 | Location, 16 | Morphology, 17 | Network, 18 | NeuroMLDocument, 19 | Point3DWithDiam, 20 | Population, 21 | Projection, 22 | Property, 23 | Segment, 24 | SegmentParent, 25 | ) 26 | 27 | soma_diam = 10 28 | soma_len = 10 29 | dend_diam = 2 30 | dend_len = 10 31 | dend_num = 10 32 | 33 | 34 | def generateRandomMorphology(): 35 | morphology = Morphology() 36 | 37 | p = Point3DWithDiam(x=0, y=0, z=0, diameter=soma_diam) 38 | d = Point3DWithDiam(x=soma_len, y=0, z=0, diameter=soma_diam) 39 | soma = Segment(proximal=p, distal=d, name="Soma", id=0) 40 | 41 | morphology.segments.append(soma) 42 | parent_seg = soma 43 | 44 | for dend_id in range(0, dend_num): 45 | p = Point3DWithDiam(x=d.x, y=d.y, z=d.z, diameter=dend_diam) 46 | d = Point3DWithDiam(x=p.x, y=p.y + dend_len, z=p.z, diameter=dend_diam) 47 | dend = Segment(proximal=p, distal=d, name="Dend_%i" % dend_id, id=1 + dend_id) 48 | dend.parent = SegmentParent(segments=parent_seg.id) 49 | parent_seg = dend 50 | 51 | morphology.segments.append(dend) 52 | 53 | morphology.id = "TestMorphology" 54 | 55 | return morphology 56 | 57 | 58 | def run(): 59 | cell_num = 10 60 | x_size = 500 61 | y_size = 500 62 | z_size = 500 63 | 64 | nml_doc = NeuroMLDocument(id="Net3DExample") 65 | 66 | syn0 = ExpOneSynapse(id="syn0", gbase="65nS", erev="0mV", tau_decay="3ms") 67 | nml_doc.exp_one_synapses.append(syn0) 68 | 69 | net = Network(id="Net3D") 70 | nml_doc.networks.append(net) 71 | 72 | proj_count = 0 73 | # conn_count = 0 74 | 75 | for cell_id in range(0, cell_num): 76 | cell = Cell(id="Cell_%i" % cell_id) 77 | 78 | cell.morphology = generateRandomMorphology() 79 | 80 | nml_doc.cells.append(cell) 81 | 82 | pop = Population( 83 | id="Pop_%i" % cell_id, component=cell.id, type="populationList" 84 | ) 85 | net.populations.append(pop) 86 | pop.properties.append(Property(tag="color", value="1 0 0")) 87 | 88 | inst = Instance(id="0") 89 | pop.instances.append(inst) 90 | 91 | inst.location = Location( 92 | x=str(x_size * random()), y=str(y_size * random()), z=str(z_size * random()) 93 | ) 94 | 95 | prob_connection = 0.5 96 | for post in range(0, cell_num): 97 | if post is not cell_id and random() <= prob_connection: 98 | from_pop = "Pop_%i" % cell_id 99 | to_pop = "Pop_%i" % post 100 | 101 | pre_seg_id = 0 102 | post_seg_id = 1 103 | 104 | projection = Projection( 105 | id="Proj_%i" % proj_count, 106 | presynaptic_population=from_pop, 107 | postsynaptic_population=to_pop, 108 | synapse=syn0.id, 109 | ) 110 | net.projections.append(projection) 111 | connection = Connection( 112 | id=proj_count, 113 | pre_cell_id="%s[%i]" % (from_pop, 0), 114 | pre_segment_id=pre_seg_id, 115 | pre_fraction_along=random(), 116 | post_cell_id="%s[%i]" % (to_pop, 0), 117 | post_segment_id=post_seg_id, 118 | post_fraction_along=random(), 119 | ) 120 | 121 | projection.connections.append(connection) 122 | proj_count += 1 123 | # net.synaptic_connections.append(SynapticConnection(from_="%s[%i]"%(from_pop,0), to="%s[%i]"%(to_pop,0))) 124 | 125 | ####### Write to file ###### 126 | 127 | nml_file = "tmp/net3d.nml" 128 | writers.NeuroMLWriter.write(nml_doc, nml_file) 129 | 130 | print("Written network file to: " + nml_file) 131 | 132 | ###### Validate the NeuroML ###### 133 | 134 | from neuroml.utils import validate_neuroml2 135 | 136 | validate_neuroml2(nml_file) 137 | 138 | 139 | run() 140 | -------------------------------------------------------------------------------- /neuroml/examples/build_network.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Example to build a full spiking IaF network 4 | through libNeuroML, save it as XML and validate it 5 | 6 | """ 7 | 8 | from random import random 9 | 10 | import neuroml.writers as writers 11 | from neuroml import ( 12 | ExplicitInput, 13 | ExpOneSynapse, 14 | IafCell, 15 | Network, 16 | NeuroMLDocument, 17 | Population, 18 | PulseGenerator, 19 | SynapticConnection, 20 | ) 21 | 22 | nml_doc = NeuroMLDocument(id="IafNet") 23 | 24 | IafCell0 = IafCell( 25 | id="iaf0", 26 | C="1.0 nF", 27 | thresh="-50mV", 28 | reset="-65mV", 29 | leak_conductance="10 nS", 30 | leak_reversal="-65mV", 31 | ) 32 | 33 | nml_doc.iaf_cells.append(IafCell0) 34 | 35 | IafCell1 = IafCell( 36 | id="iaf1", 37 | C="1.0 nF", 38 | thresh="-50mV", 39 | reset="-65mV", 40 | leak_conductance="20 nS", 41 | leak_reversal="-65mV", 42 | ) 43 | 44 | nml_doc.iaf_cells.append(IafCell1) 45 | 46 | syn0 = ExpOneSynapse(id="syn0", gbase="65nS", erev="0mV", tau_decay="3ms") 47 | 48 | nml_doc.exp_one_synapses.append(syn0) 49 | 50 | net = Network(id="IafNet") 51 | 52 | nml_doc.networks.append(net) 53 | 54 | size0 = 5 55 | pop0 = Population(id="IafPop0", component=IafCell0.id, size=size0) 56 | 57 | net.populations.append(pop0) 58 | 59 | size1 = 5 60 | pop1 = Population(id="IafPop1", component=IafCell0.id, size=size1) 61 | 62 | net.populations.append(pop1) 63 | 64 | prob_connection = 0.5 65 | 66 | for pre in range(0, size0): 67 | pg = PulseGenerator( 68 | id="pulseGen_%i" % pre, 69 | delay="0ms", 70 | duration="100ms", 71 | amplitude="%f nA" % (0.1 * random()), 72 | ) 73 | 74 | nml_doc.pulse_generators.append(pg) 75 | 76 | exp_input = ExplicitInput(target="%s[%i]" % (pop0.id, pre), input=pg.id) 77 | 78 | net.explicit_inputs.append(exp_input) 79 | 80 | for post in range(0, size1): 81 | # fromxx is used since from is Python keyword 82 | if random() <= prob_connection: 83 | syn = SynapticConnection( 84 | from_="%s[%i]" % (pop0.id, pre), 85 | synapse=syn0.id, 86 | to="%s[%i]" % (pop1.id, post), 87 | ) 88 | net.synaptic_connections.append(syn) 89 | 90 | nml_file = "tmp/testnet.nml" 91 | writers.NeuroMLWriter.write(nml_doc, nml_file) 92 | 93 | 94 | print("Written network file to: " + nml_file) 95 | 96 | 97 | ###### Validate the NeuroML ###### 98 | 99 | from neuroml.utils import validate_neuroml2 100 | 101 | validate_neuroml2(nml_file) 102 | -------------------------------------------------------------------------------- /neuroml/examples/build_network2.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Example to build a full spiking IaF network 4 | through libNeuroML, save it as XML and validate it 5 | 6 | """ 7 | 8 | import random 9 | 10 | import neuroml.writers as writers 11 | from neuroml import ( 12 | ConnectionWD, 13 | ElectricalConnection, 14 | ElectricalConnectionInstance, 15 | ElectricalProjection, 16 | ExpOneSynapse, 17 | GapJunction, 18 | IafCell, 19 | Input, 20 | InputList, 21 | Instance, 22 | Location, 23 | Network, 24 | NeuroMLDocument, 25 | PoissonFiringSynapse, 26 | Population, 27 | Projection, 28 | Property, 29 | ) 30 | 31 | random.seed(123) 32 | 33 | scale = 2 34 | 35 | nml_doc = NeuroMLDocument(id="IafNet") 36 | 37 | nml_doc.notes = "Root notes" 38 | 39 | IafCell0 = IafCell( 40 | id="iaf0", 41 | C="1.0 nF", 42 | thresh="-50mV", 43 | reset="-65mV", 44 | leak_conductance="10 nS", 45 | leak_reversal="-65mV", 46 | ) 47 | 48 | nml_doc.iaf_cells.append(IafCell0) 49 | 50 | IafCell1 = IafCell( 51 | id="iaf1", 52 | C="1.0 nF", 53 | thresh="-50mV", 54 | reset="-65mV", 55 | leak_conductance="20 nS", 56 | leak_reversal="-65mV", 57 | ) 58 | 59 | nml_doc.iaf_cells.append(IafCell1) 60 | 61 | syn0 = ExpOneSynapse(id="syn0", gbase="65nS", erev="0mV", tau_decay="3ms") 62 | 63 | nml_doc.exp_one_synapses.append(syn0) 64 | 65 | 66 | gj = GapJunction(id="gj1", conductance="10pS") 67 | 68 | nml_doc.gap_junctions.append(gj) 69 | 70 | 71 | pfs = PoissonFiringSynapse( 72 | id="pfs", average_rate="50Hz", synapse=syn0.id, spike_target="./%s" % syn0.id 73 | ) 74 | 75 | nml_doc.poisson_firing_synapses.append(pfs) 76 | 77 | net = Network(id="IafNet") 78 | 79 | net.notes = "Netw notes" 80 | 81 | nml_doc.networks.append(net) 82 | 83 | size0 = int(5 * scale) 84 | pop0 = Population(id="IafPop0", component=IafCell0.id, size=size0) 85 | 86 | net.populations.append(pop0) 87 | 88 | size1 = int(5 * scale) 89 | pop1 = Population(id="IafPop1", component=IafCell1.id, size=size1) 90 | 91 | net.populations.append(pop1) 92 | 93 | 94 | cell_num = int(4 * scale) 95 | pop = Population( 96 | id="Pop_x", component=IafCell0.id, type="populationList", size=cell_num 97 | ) 98 | net.populations.append(pop) 99 | pop.properties.append(Property(tag="color", value="1 0 0")) 100 | 101 | x_size = 500 102 | y_size = 500 103 | z_size = 500 104 | 105 | for i in range(cell_num): 106 | inst = Instance(id=i) 107 | pop.instances.append(inst) 108 | 109 | inst.location = Location( 110 | x=str(x_size * random.random()), 111 | y=str(y_size * random.random()), 112 | z=str(z_size * random.random()), 113 | ) 114 | 115 | prob_connection = 0.5 116 | proj_count = 0 117 | 118 | 119 | from_pop = "Pop_x" 120 | to_pop = "Pop_x" 121 | projection = Projection( 122 | id="Proj", 123 | presynaptic_population=from_pop, 124 | postsynaptic_population=to_pop, 125 | synapse=syn0.id, 126 | ) 127 | electricalProjection = ElectricalProjection( 128 | id="ElectProj", presynaptic_population=from_pop, postsynaptic_population=to_pop 129 | ) 130 | 131 | net.projections.append(projection) 132 | net.electrical_projections.append(electricalProjection) 133 | 134 | 135 | input_list = InputList(id="il", component=pfs.id, populations=from_pop) 136 | 137 | net.input_lists.append(input_list) 138 | 139 | for pre_index in range(0, cell_num): 140 | for post_index in range(0, cell_num): 141 | if pre_index != post_index and random.random() <= prob_connection: 142 | pre_seg_id = 0 143 | post_seg_id = 0 144 | 145 | connection = ConnectionWD( 146 | id=proj_count, 147 | pre_cell_id="../%s/%i/%s" % (from_pop, pre_index, IafCell0.id), 148 | pre_segment_id=pre_seg_id, 149 | pre_fraction_along=random.random(), 150 | post_cell_id="../%s/%i/%s" % (to_pop, post_index, IafCell0.id), 151 | post_segment_id=post_seg_id, 152 | post_fraction_along=random.random(), 153 | weight=random.random(), 154 | delay="%sms" % (random.random() * 10), 155 | ) 156 | 157 | projection.connection_wds.append(connection) 158 | 159 | electricalConnection = ElectricalConnectionInstance( 160 | id=proj_count, 161 | pre_cell="../%s/%i/%s" % (from_pop, pre_index, IafCell0.id), 162 | pre_segment=pre_seg_id, 163 | pre_fraction_along=random.random(), 164 | post_cell="../%s/%i/%s" % (to_pop, post_index, IafCell0.id), 165 | post_segment=post_seg_id, 166 | post_fraction_along=random.random(), 167 | synapse=gj.id, 168 | ) 169 | 170 | electricalProjection.electrical_connection_instances.append( 171 | electricalConnection 172 | ) 173 | 174 | proj_count += 1 175 | 176 | input = Input( 177 | id=pre_index, 178 | target="../%s/%i/%s" % (from_pop, pre_index, pop.component), 179 | destination="synapses", 180 | ) 181 | input_list.input.append(input) 182 | 183 | 184 | proj_count = 0 185 | 186 | from_pop = pop0.id 187 | to_pop = pop1.id 188 | electricalProjection = ElectricalProjection( 189 | id="ElectProj0", presynaptic_population=from_pop, postsynaptic_population=to_pop 190 | ) 191 | net.electrical_projections.append(electricalProjection) 192 | 193 | for pre_index in range(0, size0): 194 | for post_index in range(0, size1): 195 | if pre_index != post_index and random.random() <= prob_connection: 196 | pre_seg_id = 0 197 | post_seg_id = 0 198 | 199 | electricalConnection = ElectricalConnection( 200 | id=proj_count, 201 | pre_cell="%s" % (pre_index), 202 | pre_segment=pre_seg_id, 203 | pre_fraction_along=random.random(), 204 | post_cell="%s" % (post_index), 205 | post_segment=post_seg_id, 206 | post_fraction_along=random.random(), 207 | synapse=gj.id, 208 | ) 209 | 210 | electricalProjection.electrical_connections.append(electricalConnection) 211 | 212 | proj_count += 1 213 | 214 | nml_file = "test_files/testh5.nml" 215 | writers.NeuroMLWriter.write(nml_doc, nml_file) 216 | 217 | 218 | print("Created:\n" + nml_doc.summary()) 219 | print("Written network file to: " + nml_file) 220 | 221 | nml_h5_file = "tmp/testh5.nml.h5" 222 | writers.NeuroMLHdf5Writer.write(nml_doc, nml_h5_file) 223 | 224 | 225 | print("Written H5 network file to: " + nml_h5_file) 226 | 227 | 228 | ###### Validate the NeuroML ###### 229 | 230 | from neuroml.utils import validate_neuroml2 231 | 232 | validate_neuroml2(nml_file) 233 | -------------------------------------------------------------------------------- /neuroml/examples/ion_channel_generation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Generating a Hodgkin-Huxley Ion Channel and writing it to NeuroML 3 | """ 4 | 5 | import neuroml 6 | import neuroml.writers as writers 7 | 8 | chan = neuroml.IonChannelHH( 9 | id="na", 10 | conductance="10pS", 11 | species="na", 12 | notes="This is an example voltage-gated Na channel", 13 | ) 14 | 15 | m_gate = neuroml.GateHHRates(id="m", instances="3") 16 | h_gate = neuroml.GateHHRates(id="h", instances="1") 17 | 18 | m_gate.forward_rate = neuroml.HHRate( 19 | type="HHExpRate", rate="0.07per_ms", midpoint="-65mV", scale="-20mV" 20 | ) 21 | 22 | m_gate.reverse_rate = neuroml.HHRate( 23 | type="HHSigmoidRate", rate="1per_ms", midpoint="-35mV", scale="10mV" 24 | ) 25 | 26 | h_gate.forward_rate = neuroml.HHRate( 27 | type="HHExpLinearRate", rate="0.1per_ms", midpoint="-55mV", scale="10mV" 28 | ) 29 | 30 | h_gate.reverse_rate = neuroml.HHRate( 31 | type="HHExpRate", rate="0.125per_ms", midpoint="-65mV", scale="-80mV" 32 | ) 33 | 34 | chan.gate_hh_rates.append(m_gate) 35 | chan.gate_hh_rates.append(h_gate) 36 | 37 | doc = neuroml.NeuroMLDocument() 38 | doc.ion_channel_hhs.append(chan) 39 | 40 | doc.id = "ChannelMLDemo" 41 | 42 | nml_file = "./tmp/ionChannelTest.xml" 43 | writers.NeuroMLWriter.write(doc, nml_file) 44 | 45 | print("Written channel file to: " + nml_file) 46 | 47 | 48 | ###### Validate the NeuroML ###### 49 | 50 | from neuroml.utils import validate_neuroml2 51 | 52 | validate_neuroml2(nml_file) 53 | -------------------------------------------------------------------------------- /neuroml/examples/loading_modifying_writing.py: -------------------------------------------------------------------------------- 1 | """ 2 | In this example an axon is built, a morphology is loaded, the axon is 3 | then connected to the loadeed morphology. 4 | """ 5 | 6 | import neuroml 7 | import neuroml.loaders as loaders 8 | import neuroml.writers as writers 9 | 10 | fn = "./test_files/Purk2M9s.nml" 11 | doc = loaders.NeuroMLLoader.load(fn) 12 | print("Loaded morphology file from: " + fn) 13 | 14 | # get the parent segment: 15 | parent_segment = doc.cells[0].morphology.segments[0] 16 | 17 | parent = neuroml.SegmentParent(segments=parent_segment.id) 18 | 19 | # make an axon: 20 | seg_id = 5000 # need a way to get a unique id from a morphology 21 | axon_segments = [] 22 | for i in range(10): 23 | p = neuroml.Point3DWithDiam( 24 | x=parent_segment.distal.x, 25 | y=parent_segment.distal.y, 26 | z=parent_segment.distal.z, 27 | diameter=0.1, 28 | ) 29 | 30 | d = neuroml.Point3DWithDiam( 31 | x=parent_segment.distal.x + 10, 32 | y=parent_segment.distal.y, 33 | z=parent_segment.distal.z, 34 | diameter=0.1, 35 | ) 36 | 37 | axon_segment = neuroml.Segment(proximal=p, distal=d, parent=parent) 38 | 39 | axon_segment.id = seg_id 40 | 41 | axon_segment.name = "axon_segment_" + str(axon_segment.id) 42 | 43 | # now reset everything: 44 | parent = neuroml.SegmentParent(segments=axon_segment.id) 45 | parent_segment = axon_segment 46 | seg_id += 1 47 | 48 | axon_segments.append(axon_segment) 49 | 50 | doc.cells[0].morphology.segments += axon_segments 51 | 52 | nml_file = "./tmp/modified_morphology.nml" 53 | 54 | writers.NeuroMLWriter.write(doc, nml_file) 55 | 56 | print("Saved modified morphology file to: " + nml_file) 57 | 58 | 59 | ###### Validate the NeuroML ###### 60 | 61 | from neuroml.utils import validate_neuroml2 62 | 63 | validate_neuroml2(nml_file) 64 | -------------------------------------------------------------------------------- /neuroml/examples/loading_modifying_writing_large.py: -------------------------------------------------------------------------------- 1 | """ 2 | In this example an axon is built, a morphology is loaded, the axon is 3 | then connected to the loadeed morphology. 4 | """ 5 | 6 | from guppy import hpy 7 | 8 | import neuroml 9 | import neuroml.loaders as loaders 10 | import neuroml.writers as writers 11 | 12 | h = hpy() 13 | 14 | 15 | fn = "./test_files/EC2-609291-4.CNG.nml" 16 | # fn = './test_files/Purk2M9s.nml' 17 | 18 | cells = [] 19 | 20 | numCells = 1 21 | 22 | for n in range(numCells): 23 | doc = loaders.NeuroMLLoader.load(fn) 24 | cells.append(doc.cells[0]) 25 | print("Loaded morphology file from: " + fn) 26 | 27 | # get the parent segment: 28 | parent_segment = doc.cells[0].morphology.segments[0] 29 | 30 | print("Cell %i has %i segments" % (n, len(doc.cells[0].morphology.segments))) 31 | print(h.heap()) 32 | 33 | parent = neuroml.SegmentParent(segments=parent_segment.id) 34 | 35 | # make an axon: 36 | seg_id = 5000 # need a way to get a unique id from a morphology 37 | axon_segments = [] 38 | for i in range(10): 39 | p = neuroml.Point3DWithDiam( 40 | x=parent_segment.distal.x, 41 | y=parent_segment.distal.y, 42 | z=parent_segment.distal.z, 43 | diameter=0.1, 44 | ) 45 | 46 | d = neuroml.Point3DWithDiam( 47 | x=parent_segment.distal.x + 10, 48 | y=parent_segment.distal.y, 49 | z=parent_segment.distal.z, 50 | diameter=0.1, 51 | ) 52 | 53 | axon_segment = neuroml.Segment(proximal=p, distal=d, parent=parent) 54 | 55 | axon_segment.id = seg_id 56 | 57 | axon_segment.name = "axon_segment_" + str(axon_segment.id) 58 | 59 | # now reset everything: 60 | parent = neuroml.SegmentParent(segments=axon_segment.id) 61 | parent_segment = axon_segment 62 | seg_id += 1 63 | 64 | axon_segments.append(axon_segment) 65 | 66 | doc.cells[0].morphology.segments += axon_segments 67 | 68 | 69 | fn = "./tmp/modified_morphology2.nml" 70 | 71 | writers.NeuroMLWriter.write(doc, fn) 72 | 73 | print("Saved modified morphology file to: " + fn) 74 | 75 | 76 | print("Done") 77 | -------------------------------------------------------------------------------- /neuroml/examples/morphology_generation.py: -------------------------------------------------------------------------------- 1 | """ 2 | Example of connecting segments together to create a 3 | multicompartmental model of a cell. 4 | """ 5 | 6 | import neuroml 7 | import neuroml.writers as writers 8 | 9 | p = neuroml.Point3DWithDiam(x=0, y=0, z=0, diameter=50) 10 | d = neuroml.Point3DWithDiam(x=50, y=0, z=0, diameter=50) 11 | soma = neuroml.Segment(proximal=p, distal=d) 12 | soma.name = "Soma" 13 | soma.id = 0 14 | 15 | # Make an axon with 100 compartments: 16 | 17 | parent = neuroml.SegmentParent(segments=soma.id) 18 | parent_segment = soma 19 | axon_segments = [] 20 | seg_id = 1 21 | 22 | for i in range(100): 23 | p = neuroml.Point3DWithDiam( 24 | x=parent_segment.distal.x, 25 | y=parent_segment.distal.y, 26 | z=parent_segment.distal.z, 27 | diameter=0.1, 28 | ) 29 | 30 | d = neuroml.Point3DWithDiam( 31 | x=parent_segment.distal.x + 10, 32 | y=parent_segment.distal.y, 33 | z=parent_segment.distal.z, 34 | diameter=0.1, 35 | ) 36 | 37 | axon_segment = neuroml.Segment(proximal=p, distal=d, parent=parent) 38 | 39 | axon_segment.id = seg_id 40 | 41 | axon_segment.name = "axon_segment_" + str(axon_segment.id) 42 | 43 | # now reset everything: 44 | parent = neuroml.SegmentParent(segments=axon_segment.id) 45 | parent_segment = axon_segment 46 | seg_id += 1 47 | 48 | axon_segments.append(axon_segment) 49 | 50 | test_morphology = neuroml.Morphology() 51 | test_morphology.segments.append(soma) 52 | test_morphology.segments += axon_segments 53 | test_morphology.id = "TestMorphology" 54 | 55 | cell = neuroml.Cell() 56 | cell.name = "TestCell" 57 | cell.id = "TestCell" 58 | cell.morphology = test_morphology 59 | 60 | 61 | doc = neuroml.NeuroMLDocument(id="TestNeuroMLDocument") 62 | 63 | doc.cells.append(cell) 64 | 65 | nml_file = "tmp/testmorphwrite.nml" 66 | 67 | writers.NeuroMLWriter.write(doc, nml_file) 68 | 69 | print("Written morphology file to: " + nml_file) 70 | 71 | ###### Validate the NeuroML ###### 72 | 73 | from neuroml.utils import validate_neuroml2 74 | 75 | validate_neuroml2(nml_file) 76 | -------------------------------------------------------------------------------- /neuroml/examples/run_all.py: -------------------------------------------------------------------------------- 1 | print("Running all examples...") 2 | 3 | 4 | def run_example(ex_file): 5 | print("-------------------------------------\nRunning %s" % ex_file) 6 | exec("import %s" % ex_file[:-3]) 7 | print("-------------------------------------\nCompleted: %s" % ex_file) 8 | 9 | 10 | run_example("arraymorph_generation.py") 11 | run_example("build_3D_network.py") 12 | run_example("build_network.py") 13 | run_example("build_network2.py") 14 | run_example("build_complete.py") 15 | run_example("ion_channel_generation.py") 16 | run_example("loading_modifying_writing.py") 17 | # This next one takes a while to run but all of its functionality is covered in loading_modifying_writing.py 18 | # run_example("loading_modifying_writing_large.py") 19 | run_example("morphology_generation.py") 20 | run_example("write_pynn.py") 21 | run_example("write_syns.py") 22 | run_example("single_izhikevich_reader.py") 23 | run_example("single_izhikevich_writer.py") 24 | -------------------------------------------------------------------------------- /neuroml/examples/single_izhikevich_reader.py: -------------------------------------------------------------------------------- 1 | # from neuroml import NeuroMLDocument 2 | from neuroml import IzhikevichCell 3 | from neuroml.loaders import NeuroMLLoader 4 | from neuroml.utils import validate_neuroml2 5 | 6 | 7 | def load_izhikevich(filename="./test_files/SingleIzhikevich.nml"): 8 | nml_filename = filename 9 | validate_neuroml2(nml_filename) 10 | nml_doc = NeuroMLLoader.load(nml_filename) 11 | 12 | iz_cells = nml_doc.izhikevich_cells 13 | for i, iz in enumerate(iz_cells): 14 | if isinstance(iz, IzhikevichCell): 15 | neuron_string = "%d %s %s %s %s %s (%s)" % ( 16 | i, 17 | iz.v0, 18 | iz.a, 19 | iz.b, 20 | iz.c, 21 | iz.d, 22 | iz.id, 23 | ) 24 | print(neuron_string) 25 | else: 26 | print("Error: Cell %d is not an IzhikevichCell" % i) 27 | 28 | 29 | load_izhikevich() 30 | -------------------------------------------------------------------------------- /neuroml/examples/single_izhikevich_writer.py: -------------------------------------------------------------------------------- 1 | from neuroml import IzhikevichCell, NeuroMLDocument 2 | from neuroml.utils import validate_neuroml2 3 | from neuroml.writers import NeuroMLWriter 4 | 5 | 6 | def write_izhikevich(filename="./tmp/SingleIzhikevich_test.nml"): 7 | nml_doc = NeuroMLDocument(id="SingleIzhikevich") 8 | nml_filename = filename 9 | 10 | iz0 = IzhikevichCell( 11 | id="iz0", v0="-70mV", thresh="30mV", a="0.02", b="0.2", c="-65.0", d="6" 12 | ) 13 | 14 | nml_doc.izhikevich_cells.append(iz0) 15 | 16 | NeuroMLWriter.write(nml_doc, nml_filename) 17 | validate_neuroml2(nml_filename) 18 | 19 | 20 | write_izhikevich() 21 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/AMPA_syn.synapse.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file describing a single synaptic mechanism 5 | 6 | 7 | 8 | Simple example of a synaptic mechanism, which consists of a postsynaptic conductance which changes as a double exponential function of time. Mappings exist for NEURON and GENESIS. 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/AMPA_syn_inh.synapse.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file describing a single synaptic mechanism 5 | 6 | 7 | 8 | 9 | Simple example of a synaptic mechanism, which consists of a postsynaptic conductance which changes as a double exponential function of time. Mappings exist for NEURON and GENESIS. 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/Ca_conc.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file describing intracellular Calcium dynamics, from the Hippocampal CA3 neuron model presented in Traub et al., 1991. 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/Ca_pyr.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Calcium Channel description, from the Hippocampal CA3 neuron model presented in Traub et al., 1991. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Traub, R. D., Wong, R. K., Miles, R., and Michelson, H. (1991). A model of a CA3 hippocampal pyramidal neuron incorporating voltage-clamp data on intrinsic conductances. Journal of neurophysiology, 66(2), 635-50. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Ca channels 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/GABA_syn.synapse.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file describing a single synaptic mechanism 5 | 6 | 7 | 8 | Simple example of a synaptic mechanism, which consists of a postsynaptic conductance which changes as a double exponential function of time. Mappings exist for NEURON and GENESIS. 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/GABA_syn_inh.synapse.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file describing a single synaptic mechanism 5 | 6 | 7 | 8 | NOTE: zero conductance as per ACnet2-main.g 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/Kahp_pyr.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Calcium-dependent Potassium Channel description, from the Hippocampal CA3 neuron model presented in Traub et al., 1991. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Traub, R. D., Wong, R. K., Miles, R., and Michelson, H. (1991). A model of a CA3 hippocampal pyramidal neuron incorporating voltage-clamp data on intrinsic conductances. Journal of neurophysiology, 66(2), 635-50. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | K channels 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/Kdr_bask.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Potassium Channel description, from the book Neuronal Networks of the Hippocampus, Traub and Miles 1991 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Traub, R. D., & Miles, R. (1991). Neuronal Networks of the Hippocampus. Cambridge University Press. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | K channels 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/Kdr_pyr.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Potassium Channel description, from the Hippocampal CA3 neuron model presented in Traub et al., 1991. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Traub, R. D., Wong, R. K., Miles, R., and Michelson, H. (1991). A model of a CA3 hippocampal pyramidal neuron incorporating voltage-clamp data on intrinsic conductances. Journal of neurophysiology, 66(2), 635-50. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | K channels 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/LEMS_TestComplete.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/LeakConductance_bask.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Channel description 5 | 6 | 7 | 8 | Simple example of a leak/passive conductance. Note: for GENESIS cells with a single leak conductance, 9 | it is better to use the Rm and Em variables for a passive current. 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/LeakConductance_pyr.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Channel description 5 | 6 | 7 | 8 | Simple example of a leak/passive conductance. Note: for GENESIS cells with a single leak conductance, 9 | it is better to use the Rm and Em variables for a passive current. 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/Na_bask.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Sodium Channel description, from the book Neuronal Networks of the Hippocampus, Traub and Miles 1991 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Traub, R. D., & Miles, R. (1991). Neuronal Networks of the Hippocampus. Cambridge University Press. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Na channels 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/Na_pyr.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ChannelML file containing a single Sodium Channel description, from the Hippocampal CA3 neuron model presented in Traub et al., 1991. 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Traub, R. D., Wong, R. K., Miles, R., and Michelson, H. (1991). A model of a CA3 hippocampal pyramidal neuron incorporating voltage-clamp data on intrinsic conductances. Journal of neurophysiology, 66(2), 635-50. 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | Na channels 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/SingleIzhikevich.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/bask.cell.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | A simplified basket cell model with 2 compartments 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 31 | 32 | 33 | 34 | 35 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/complete.nml.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuralEnsemble/libNeuroML/09be14e32778d8d590cacb5fc65c3a90b42ed0ea/neuroml/examples/test_files/complete.nml.h5 -------------------------------------------------------------------------------- /neuroml/examples/test_files/pas_nml.channel.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Simple example of a leak/passive conductance. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/simplenet.nml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /neuroml/examples/test_files/tmp2.swc: -------------------------------------------------------------------------------- 1 | # Original neuron tracing performed in Neuromantic 2 | # which was programmed by Darren Myatt (d.r.myatt@reading.ac.uk) 3 | # See homepage at http://www.rdg.ac.uk/Neuromantic 4 | # 5 | # NEUROMANTIC V1.6.3 (20/05/2012 17:58:33): Saved to tmp.swc 6 | # NEUROMANTIC V1.6.3 (20/05/2012 18:03:22): Saved to tmp2.swc 7 | 1 1 95.167 557.17 25 9.3608 -1 8 | 2 1 94.625 547.38 25 4.8766 1 9 | 3 1 95.875 543.88 25 3.1474 2 10 | 4 2 94.875 524.38 25 1.1319 3 11 | 5 2 99.75 503.5 25 1.25 4 12 | 6 2 102.58 467.25 26 0.75462 5 13 | 7 2 103.25 442.83 26 0.58334 6 14 | 8 2 103.88 417.69 26 0.7526 7 15 | 9 2 106 409.56 26 0.77308 8 16 | 10 2 103.31 392 27 0.61555 9 17 | 11 2 103.58 351.5 27 0.91667 10 18 | 12 2 105.08 338.67 27 0.58333 11 19 | 13 2 112 320.75 27 0.75 12 20 | 14 2 112.13 311.25 27 0.875 13 21 | 15 2 116.88 306 27 0.80039 14 22 | 16 2 118.75 296 27 1 15 23 | 17 2 121.13 284.25 27 0.91001 16 24 | 18 2 123.38 267.88 27 0.88388 17 25 | 19 2 123.67 240.67 27 1 18 26 | 20 2 123 222.67 27 1 19 27 | 21 2 129.17 186.67 26 1.5 20 28 | 22 2 131.83 157.67 26 0.89753 21 29 | 23 1 101.83 575.08 25 3.5795 1 30 | 24 4 106.25 583.5 25 1.75 23 31 | 25 4 105.75 602.25 25 1.7678 24 32 | 26 4 104.13 622.31 25 1.0915 25 33 | 27 4 100.94 651.69 25 1.1075 26 34 | 28 4 99.667 671.83 25 1.8634 27 35 | 29 4 101.83 709.83 25 1.9003 28 36 | 30 4 102.33 736.33 25 1.7951 29 37 | 31 4 101 749.83 26 1.74 30 38 | 32 4 112.33 764.5 26 1.7401 31 39 | 33 4 139.33 783.5 26 0.83333 32 40 | 34 4 147.17 793.67 26 1.3437 33 41 | 35 4 106.33 783.33 26 1.3744 32 42 | 36 4 78.313 781.81 30 1.6129 31 43 | 37 4 67.667 801 30 2.2361 36 44 | 38 4 58.333 829.33 34 1.8028 37 45 | 39 1 82.333 553.25 25 1.7179 1 46 | 40 3 70.333 550.83 25 1 39 47 | -------------------------------------------------------------------------------- /neuroml/examples/tmp/README: -------------------------------------------------------------------------------- 1 | Temp folder for generated files 2 | -------------------------------------------------------------------------------- /neuroml/examples/write_pynn.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Example to build a PyNN based network 4 | 5 | """ 6 | 7 | from random import random 8 | 9 | import neuroml.writers as writers 10 | from neuroml import * 11 | from neuroml import NeuroMLDocument 12 | 13 | ######################## Build the network #################################### 14 | 15 | nml_doc = NeuroMLDocument(id="IafNet") 16 | 17 | 18 | pynn0 = IF_curr_alpha( 19 | id="IF_curr_alpha_pop_IF_curr_alpha", 20 | cm="1.0", 21 | i_offset="0.9", 22 | tau_m="20.0", 23 | tau_refrac="10.0", 24 | tau_syn_E="0.5", 25 | tau_syn_I="0.5", 26 | v_init="-65", 27 | v_reset="-62.0", 28 | v_rest="-65.0", 29 | v_thresh="-52.0", 30 | ) 31 | nml_doc.IF_curr_alpha.append(pynn0) 32 | 33 | pynn1 = HH_cond_exp( 34 | id="HH_cond_exp_pop_HH_cond_exp", 35 | cm="0.2", 36 | e_rev_E="0.0", 37 | e_rev_I="-80.0", 38 | e_rev_K="-90.0", 39 | e_rev_Na="50.0", 40 | e_rev_leak="-65.0", 41 | g_leak="0.01", 42 | gbar_K="6.0", 43 | gbar_Na="20.0", 44 | i_offset="0.2", 45 | tau_syn_E="0.2", 46 | tau_syn_I="2.0", 47 | v_init="-65", 48 | v_offset="-63.0", 49 | ) 50 | nml_doc.HH_cond_exp.append(pynn1) 51 | 52 | pynnSynn0 = ExpCondSynapse(id="ps1", tau_syn="5", e_rev="0") 53 | nml_doc.exp_cond_synapses.append(pynnSynn0) 54 | 55 | nml_file = "tmp/pynn_network.xml" 56 | writers.NeuroMLWriter.write(nml_doc, nml_file) 57 | print("Saved to: " + nml_file) 58 | 59 | 60 | ###### Validate the NeuroML ###### 61 | 62 | from neuroml.utils import validate_neuroml2 63 | 64 | validate_neuroml2(nml_file) 65 | -------------------------------------------------------------------------------- /neuroml/examples/write_syns.py: -------------------------------------------------------------------------------- 1 | """ 2 | 3 | Example to create a file with multiple synapse types 4 | 5 | """ 6 | 7 | from random import random 8 | 9 | import neuroml.writers as writers 10 | from neuroml import * 11 | from neuroml import NeuroMLDocument 12 | 13 | nml_doc = NeuroMLDocument(id="SomeSynapses") 14 | 15 | expOneSyn0 = ExpOneSynapse(id="ampa", tau_decay="5ms", gbase="1nS", erev="0mV") 16 | nml_doc.exp_one_synapses.append(expOneSyn0) 17 | 18 | expTwoSyn0 = ExpTwoSynapse( 19 | id="gaba", tau_decay="12ms", tau_rise="3ms", gbase="1nS", erev="-70mV" 20 | ) 21 | nml_doc.exp_two_synapses.append(expTwoSyn0) 22 | 23 | bpSyn = BlockingPlasticSynapse( 24 | id="blockStpSynDep", gbase="1nS", erev="0mV", tau_rise="0.1ms", tau_decay="2ms" 25 | ) 26 | bpSyn.notes = "This is a note" 27 | bpSyn.plasticity_mechanism = PlasticityMechanism( 28 | type="tsodyksMarkramDepMechanism", init_release_prob="0.5", tau_rec="120 ms" 29 | ) 30 | bpSyn.block_mechanism = BlockMechanism( 31 | type="voltageConcDepBlockMechanism", 32 | species="mg", 33 | block_concentration="1.2 mM", 34 | scaling_conc="1.920544 mM", 35 | scaling_volt="16.129 mV", 36 | ) 37 | 38 | nml_doc.blocking_plastic_synapses.append(bpSyn) 39 | 40 | 41 | nml_file = "tmp/synapses.xml" 42 | writers.NeuroMLWriter.write(nml_doc, nml_file) 43 | print("Saved to: " + nml_file) 44 | 45 | 46 | ###### Validate the NeuroML ###### 47 | 48 | from neuroml.utils import validate_neuroml2 49 | 50 | validate_neuroml2(nml_file) 51 | -------------------------------------------------------------------------------- /neuroml/hdf5/__init__.py: -------------------------------------------------------------------------------- 1 | import numpy 2 | 3 | 4 | def get_str_attribute_group(group, name): 5 | if not hasattr(group._v_attrs, name): 6 | return None 7 | 8 | for attrName in group._v_attrs._v_attrnames: 9 | if attrName == name: 10 | val = group._v_attrs[name] 11 | 12 | if isinstance(val, numpy.ndarray): 13 | val = val[0] 14 | elif isinstance(val, numpy.bytes_): 15 | val = val.decode("UTF-8") 16 | else: 17 | val = str(val) 18 | 19 | # print("- Found [%s] in [%s]: %s = [%s] %s"%(attrName, group, name,val,type(val))) 20 | return val 21 | return None 22 | -------------------------------------------------------------------------------- /neuroml/neuro_lex_ids.py: -------------------------------------------------------------------------------- 1 | """ 2 | NeuroLex Ids 3 | 4 | File: neuroml/neuro_lex_ids.py 5 | 6 | Copyright 2023 NeuroML contributors 7 | """ 8 | 9 | neuro_lex_ids = { 10 | # https://scicrunch.org/scicrunch/interlex/view/ilx_0101043?searchTerm=GO:0030424 11 | "axon": "GO:0030424", 12 | # https://scicrunch.org/scicrunch/interlex/view/ilx_0103021?searchTerm=GO:0030425 13 | "dend": "GO:0030425", 14 | # https://scicrunch.org/scicrunch/interlex/view/ilx_0107514?searchTerm=GO:0043025 15 | "soma": "GO:0043025", 16 | # https://scicrunch.org/scicrunch/interlex/view/ilx_0109858?searchTerm=sao864921383 17 | "section": "sao864921383", 18 | } 19 | -------------------------------------------------------------------------------- /neuroml/nml/README.md: -------------------------------------------------------------------------------- 1 | ## Autogeneration of API, using generateds_config.py to ensure correct naming conventions. 2 | 3 | Please regenerate nml.py in a new branch and open a pull request against the `development` branch. 4 | 5 | Please **do not** regenerate nml.py and push directly to the `master` branch because regeneration of `nml.py` may change the libNeuroML API, and so this could be a backwards incompatible change which must not be pushed to master without a corresponding release and sufficient testing. 6 | 7 | ### Requirements 8 | 9 | - the Schema (XSD) file 10 | - `generateds_config.py`: this includes the correct naming conventions 11 | - `helper_methods.py`: this includes additional helper methods that we want to add to the API 12 | 13 | The following packages are required. 14 | 15 | - generateds 16 | - ruff 17 | 18 | They can be installed with using the dev option in the root directory: 19 | 20 | ``` 21 | pip install .[dev] 22 | ``` 23 | 24 | ### Regenerating nml.py 25 | 26 | - Run the `regenerate-nml.sh` script in the `neuroml/nml` folder. 27 | - This will use the API version defined in `neuroml/__init__.py` to find the right schema XSD file and run generateds to regenerate the `nml.py` file. 28 | - It will also run `ruff` on the newly generated file to reformat it. 29 | 30 | The generateDS command that is invoked is of this form: 31 | 32 | generateDS.py -o nml.py --use-getter-setter=none --silence --user-methods=helper_methods.py NeuroML_v2.2.xsd 33 | 34 | You will need to add the current folder to your PYTHONPATH so that the required files can be imported by generateDS. 35 | 36 | export PYTHONPATH=$PYTHONPATH:. 37 | 38 | 39 | Your output should include lines of the form: 40 | 41 | generateds_config.py is being processed 42 | Saving NameTable to csv file: name_table.csv 43 | Saving name changes table to csv file: changed_names.csv 44 | 45 | 46 | If these are not included in the output, generateDS has not run correctly, and the generated nml.py file will be incorrect. 47 | 48 | ### Testing 49 | 50 | Please remember to: 51 | 52 | - rebuild libNeuroML after regenerating `nml.py` 53 | - run all unit tests 54 | - run all examples 55 | 56 | The CI on GitHub will always run these. 57 | 58 | ### Changelog 59 | 60 | #### August 26, 2021 61 | 62 | Author: @sanjayankur31 63 | 64 | Generate with Python 3.9, generateDS version 2.39.9 65 | 66 | - all tests pass 67 | - `--use-getter-setter=none`, which causes test failures because of probable generateDS bug. See: https://sourceforge.net/p/generateds/tickets/20/ 68 | - also requires us to manually patch one or two conversions to work around https://sourceforge.net/p/generateds/tickets/13/ 69 | 70 | #### March 26, 2020 71 | 72 | Author: @sanjayankur31 73 | 74 | Resort to using Python 2.7 and generateDS.py 2.30.11 for the time being. 75 | 76 | - all tests and examples pass 77 | 78 | #### March 26, 2020 79 | 80 | Author: @sanjayankur31 81 | 82 | Generation attempt using Python 3.9 for NeuroMLv2.1.xsd using generateDS.py 2.38.3: 83 | 84 | - generation requires updating of the generateds_config.py file 85 | - generated nml.py seems to contain issues: https://sourceforge.net/p/generateds/tickets/13/ 86 | - after tweaking nml.py, json serialization example still fails. 87 | 88 | 89 | #### February 2020 90 | 91 | Author: @pgleeson 92 | 93 | Retested & regenerated using Python 2.7 with generateDS.py v2.30.11- currently fails when generated with Python 3. 94 | -------------------------------------------------------------------------------- /neuroml/nml/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuralEnsemble/libNeuroML/09be14e32778d8d590cacb5fc65c3a90b42ed0ea/neuroml/nml/__init__.py -------------------------------------------------------------------------------- /neuroml/nml/annotate_nml.py: -------------------------------------------------------------------------------- 1 | """ 2 | Gets type information from nml.py and generates a file of sed commands to be 3 | used to modify nml.py to add some information about the types of all variables 4 | in component type class constructors. 5 | 6 | This must be run from the project root for all the imports to work correctly: 7 | 8 | python -m neuroml.nml.annotate_nml 9 | 10 | File: annotate_nml.py 11 | 12 | Copyright 2023 NeuroML contributors 13 | """ 14 | 15 | import inspect 16 | 17 | from . import nml 18 | 19 | ignorelist = [ 20 | "GeneratedsSuper", 21 | "GeneratedsSuperSuper", 22 | ] 23 | 24 | 25 | def pred(c): 26 | return inspect.isclass(c) and (c.__name__ not in ignorelist) 27 | 28 | 29 | classes = inspect.getmembers(nml, pred) 30 | 31 | with open("sed-script.txt", "w") as f: 32 | for aclass, atype in classes: 33 | # print(f"Processing {aclass}") 34 | member_types = {} 35 | if getattr(atype, "_get_members", False): 36 | members = atype()._get_members() 37 | for amember in members: 38 | dtype = amember.get_data_type().replace("xs:", "") 39 | dname = amember.get_name() 40 | dreq = "optional" if amember.get_optional() else "required" 41 | 42 | regexstart = f"^class {aclass}" 43 | regexend = f"# end class {aclass}" 44 | 45 | # We add annotations as strings, just to help users better 46 | # understand what needs to be used. 47 | 48 | # must be run on unblacked file because we are relying on all 49 | # arguments to be in the same line as init 50 | if amember.get_container() == 0: 51 | print( 52 | f"""/{regexstart}/,/{regexend}/ s/\\(def __init__.* {dname}\\)=\\([[:alnum:]\\._ ']*\\),/\\1: "a {dtype} ({dreq})" = \\2,/""", 53 | file=f, 54 | ) 55 | else: 56 | print( 57 | f"""/{regexstart}/,/{regexend}/ s/\\(def __init__.* {dname}\\)=\\([[:alnum:]\\._ ']*\\),/\\1: "list of {dtype}(s) ({dreq})" = \\2,/""", 58 | file=f, 59 | ) 60 | -------------------------------------------------------------------------------- /neuroml/nml/config.py: -------------------------------------------------------------------------------- 1 | variables = {"schema_name": "NeuroML_v2.2.xsd"} 2 | -------------------------------------------------------------------------------- /neuroml/nml/gds_imports-template.py: -------------------------------------------------------------------------------- 1 | import inspect 2 | import math 3 | import typing 4 | from math import pi, sqrt 5 | from operator import attrgetter 6 | 7 | import natsort 8 | import networkx as nx 9 | import numpy 10 | 11 | import neuroml 12 | import neuroml.neuro_lex_ids 13 | -------------------------------------------------------------------------------- /neuroml/nml/generateds_config.py: -------------------------------------------------------------------------------- 1 | # Maps from NeuroML element space (Key) to python object space (value) 2 | # The class names are essentially correct, the instance names need converting 3 | # also attributes need fixing 4 | 5 | import csv 6 | import re 7 | import sys 8 | 9 | import lxml 10 | import process_includes 11 | from lxml import objectify 12 | 13 | # In Python 3, it's io 14 | try: 15 | from StringIO import StringIO 16 | except ImportError: 17 | from io import StringIO 18 | from config import variables 19 | 20 | sys.setrecursionlimit(10000) 21 | 22 | 23 | def remove_curlies(string): 24 | return re.sub("{.*}", "", string) 25 | 26 | 27 | def to_lowercase_with_underscores(string): 28 | s1 = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", string) 29 | return re.sub("([a-z0-9])([A-Z])", r"\1_\2", s1).lower() 30 | 31 | 32 | def to_camelback(string): 33 | string_list = list(string) 34 | i = 0 35 | for m in re.finditer("_", string): 36 | underscore_index = m.end() 37 | string_list[underscore_index - i] = string_list[ 38 | underscore_index - i 39 | ].capitalize() 40 | string_list.pop(underscore_index - (1 + i)) 41 | i += 1 42 | string = "".join(string_list) 43 | 44 | return str(string) 45 | 46 | 47 | def traverse_doc(queue, rename): 48 | """Recursive function to traverse the nodes of a tree in 49 | breadth-first order. 50 | 51 | The first argument should be the tree root; children 52 | should be a function taking as argument a tree node and 53 | returning an iterator of the node's children. 54 | """ 55 | if len(queue) > 0: 56 | node = queue.pop() 57 | children = node.getchildren() 58 | rename(node) 59 | queue = queue + children 60 | traverse_doc(queue, rename) 61 | else: 62 | return None 63 | 64 | 65 | def pluralize(noun): 66 | if re.search("[sxz]$", noun): 67 | return re.sub("$", "es", noun) 68 | elif re.search("[^aeioudgkprt]h$", noun): 69 | return re.sub("$", "es", noun) 70 | elif re.search("[^aeiou]y$", noun): 71 | return re.sub("y$", "ies", noun) 72 | else: 73 | return noun + "s" 74 | 75 | 76 | def _node_to_python(node): 77 | pluralize_flag = "maxOccurs" in node.attrib 78 | 79 | for attribute in node.attrib: 80 | nml_attribute = node.attrib.pop(attribute) 81 | if nml_attribute[0].islower(): 82 | renamed_attribute = to_lowercase_with_underscores(nml_attribute) 83 | if pluralize_flag: 84 | renamed_attribute = pluralize(renamed_attribute) 85 | NameTable[nml_attribute] = renamed_attribute 86 | 87 | 88 | filename = variables["schema_name"] 89 | 90 | outfile = StringIO() 91 | infile = open(filename, "r") 92 | 93 | process_includes.process_include_files(infile, outfile, inpath=filename) 94 | infile.close() 95 | outfile.seek(0) 96 | doc = objectify.parse(outfile) 97 | root = doc.getroot() 98 | queue = [root] 99 | 100 | NameTable = {} 101 | 102 | traverse_doc(queue, _node_to_python) 103 | 104 | # filtering routine, need to get a better way to extract these, asked on Stack Overflow 105 | import keyword 106 | 107 | disallowed_keywords = keyword.kwlist 108 | for keyword in disallowed_keywords: 109 | try: 110 | NameTable.pop(keyword) 111 | except: 112 | pass 113 | 114 | NameTable["morphology"] = "morphology" # overriding change to 115 | # "morphologies" because it only applies outside of a cell - not a very 116 | # elegant solution 117 | NameTable["gateHHtauInf"] = "gate_hh_tau_infs" 118 | NameTable["ionChannelHH"] = "ion_channel_hh" 119 | NameTable["gateHHrates"] = "gate_hh_rates" 120 | NameTable["gateHHtauInf"] = "gate_hh_tau_infs" 121 | 122 | NameTable["ionChannel"] = "ion_channel" 123 | NameTable["ionChannelHH"] = "ion_channel_hhs" 124 | 125 | 126 | NameTable["basePyNNCell"] = "basePyNNCell" 127 | NameTable["basePyNNIaFCell"] = "basePyNNIaFCell" 128 | NameTable["basePyNNIaFCondCell"] = "basePyNNIaFCondCell" 129 | NameTable["tau_syn_E"] = "tau_syn_E" 130 | NameTable["tau_syn_I"] = "tau_syn_I" 131 | 132 | NameTable["e_rev_E"] = "e_rev_E" 133 | NameTable["e_rev_I"] = "e_rev_I" 134 | NameTable["e_rev_Na"] = "e_rev_Na" 135 | NameTable["e_rev_K"] = "e_rev_K" 136 | 137 | NameTable["gbar_K"] = "gbar_K" 138 | NameTable["gbar_Na"] = "gbar_Na" 139 | 140 | NameTable["delta_T"] = "delta_T" 141 | 142 | NameTable["IF_curr_alpha"] = "IF_curr_alpha" 143 | NameTable["IF_curr_exp"] = "IF_curr_exp" 144 | NameTable["IF_cond_alpha"] = "IF_cond_alpha" 145 | NameTable["IF_cond_exp"] = "IF_cond_exp" 146 | 147 | NameTable["extracellularProperties"] = "extracellular_properties" 148 | NameTable["intracellularProperties"] = "intracellular_properties" 149 | NameTable["biophysicalProperties"] = "biophysical_properties" 150 | 151 | print("NameTable is as follows:") 152 | print(NameTable) 153 | 154 | print("Saving NameTable to csv file") 155 | writer = csv.writer(open("name_table.csv", "w")) 156 | for key, value in NameTable.items(): 157 | writer.writerow([key, value]) 158 | 159 | print("Saving name changes table to csv file") 160 | changes_writer = csv.writer(open("changed_names.csv", "w")) 161 | for key in NameTable: 162 | value = NameTable[key] 163 | if key != value: 164 | changes_writer.writerow([key, value]) 165 | -------------------------------------------------------------------------------- /neuroml/nml/generatedscollector.py: -------------------------------------------------------------------------------- 1 | """ 2 | Implementation of generateds collector. 3 | 4 | This has been split out from nml.py so that the collector can be used in 5 | generatedssupersuper.py 6 | 7 | File: neuroml/nml.py/generatedscollector.py 8 | 9 | Copyright 2023 Ankur Sinha 10 | Author: Ankur Sinha 11 | """ 12 | 13 | import inspect 14 | 15 | 16 | class GdsCollector(object): 17 | def __init__(self, messages=None): 18 | if messages is None: 19 | self.messages = [] 20 | else: 21 | self.messages = messages 22 | 23 | def add_message(self, msg): 24 | caller = inspect.stack()[1].frame.f_locals["self"] 25 | try: 26 | caller_id_str = f" ({caller.id})" 27 | except AttributeError: 28 | caller_id_str = "" 29 | self.messages.append(f"{caller.__class__.__name__}{caller_id_str}: {msg}") 30 | 31 | def get_messages(self): 32 | return self.messages 33 | 34 | def clear_messages(self): 35 | self.messages = [] 36 | 37 | def print_messages(self): 38 | for msg in self.messages: 39 | print("Warning: {}".format(msg)) 40 | 41 | def write_messages(self, outstream): 42 | for msg in self.messages: 43 | outstream.write("Warning: {}\n".format(msg)) 44 | -------------------------------------------------------------------------------- /neuroml/nml/regenerate-nml.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2023 NeuroML contributors 4 | # File : regenerate-nml.sh 5 | # Regenerate nml.py from the current schema version 6 | 7 | 8 | echo "Note(1): Please remember to update the schema from the NeuroML2 repository" 9 | echo "Note(2): Must be run in neuroml/nml/" 10 | NEUROML_VERSION=$(grep -E 'current_neuroml_version.*' ../__version__.py | cut -d '=' -f 2 | tr -d '"' | tr -d ' ') 11 | SCHEMA_FILE=NeuroML_${NEUROML_VERSION}.xsd 12 | PYTHON_VERSION=$(python3 --version 2>&1) 13 | 14 | regenerate () { 15 | if command -v generateDS > /dev/null 2>&1 16 | then 17 | echo "Rebuilding nml.py from ${SCHEMA_FILE} (Version: ${NEUROML_VERSION})" 18 | echo "generateds version:" 19 | generateDS --version 20 | echo "Python version: $PYTHON_VERSION" 21 | 22 | rm -f nml.py 23 | 24 | 25 | PYTHONPATH="$PYTHONPATH:." generateDS -o nml.py --use-getter-setter=none --user-methods=helper_methods.py --export="write validate" --custom-imports-template=gds_imports-template.py $SCHEMA_FILE 26 | # correct path to generatedssupersuper module file 27 | sed -i 's/from generatedssupersuper/from .generatedssupersuper/' nml.py 28 | sed -i 's/from generatedscollector/from .generatedscollector/' nml.py 29 | 30 | # replace default arguments (None) with some hint of what's expected 31 | # must be run from top level because of all the imports we 32 | # have---otherwise it errors 33 | echo "Modifying default arguments using annotate_nml and sed" 34 | pushd ../../ 35 | # generates the sed-script.txt file 36 | python3 -m neuroml.nml.annotate_nml 37 | echo "Generated sed script" 38 | sed_lines=$(wc -l sed-script.txt | cut -f1 -d " ") 39 | if [ $sed_lines -eq 0 ] 40 | then 41 | echo "Something went wrong. No lines in sed script." 42 | else 43 | echo "${sed_lines} lines in sed script" 44 | fi 45 | popd 46 | # apply the sed transformations 47 | sleep 1 && sed -i -f ../../sed-script.txt nml.py 48 | else 49 | echo "GenerateDS not installed" 50 | echo "Run: pip install generateds" 51 | exit 1 52 | fi 53 | } 54 | 55 | reformat () { 56 | if command -v ruff > /dev/null 2>&1 57 | then 58 | echo "Formatting new nml.py with ruff" 59 | ruff format nml.py 60 | else 61 | echo "ruff is not installed" 62 | echo "Run: pip install ruff" 63 | fi 64 | } 65 | 66 | usage () { 67 | echo "$0: Regenerate and reformat nml.py from the XSD schema file" 68 | echo 69 | echo "Usage: $0 [-arfh]" 70 | echo 71 | echo "-r: regenerate" 72 | echo "-f: reformat" 73 | echo "-a: regenerate and reformat" 74 | echo "-h: print this help text and exit" 75 | } 76 | 77 | if [ $# -lt 1 ] 78 | then 79 | usage 80 | exit 1 81 | fi 82 | 83 | # parse options 84 | while getopts "arfh" OPTION 85 | do 86 | case $OPTION in 87 | r) 88 | regenerate 89 | exit 0 90 | ;; 91 | f) 92 | reformat 93 | exit 0 94 | ;; 95 | a) 96 | regenerate && reformat 97 | exit 0 98 | ;; 99 | h) 100 | usage 101 | exit 0 102 | ;; 103 | ?) 104 | usage 105 | exit 1 106 | ;; 107 | esac 108 | done 109 | -------------------------------------------------------------------------------- /neuroml/test/README: -------------------------------------------------------------------------------- 1 | To run tests: 2 | 3 | python -m unittest discover 4 | 5 | or: 6 | 7 | pytest 8 | -------------------------------------------------------------------------------- /neuroml/test/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/NeuralEnsemble/libNeuroML/09be14e32778d8d590cacb5fc65c3a90b42ed0ea/neuroml/test/__init__.py -------------------------------------------------------------------------------- /neuroml/test/misc_tests.py: -------------------------------------------------------------------------------- 1 | """ 2 | Miscelaneous unit tests 3 | 4 | """ 5 | 6 | import inspect 7 | import sys 8 | 9 | import neuroml 10 | 11 | try: 12 | import unittest2 as unittest 13 | except ImportError: 14 | import unittest 15 | 16 | 17 | class TestCommonProperties(unittest.TestCase): 18 | def test_instatiation(self): 19 | """ 20 | Since classes are auto-generated, need to test that they correctly instantiate 21 | """ 22 | 23 | for name, test_class in inspect.getmembers(sys.modules[neuroml.__name__]): 24 | if sys.version_info >= (2, 7): 25 | print(sys.version_info) 26 | if inspect.isclass(test_class): 27 | ob = test_class() 28 | self.assertIsInstance(ob, test_class) 29 | else: 30 | print("Warning - Python<2.7 does not support this test") 31 | pass 32 | -------------------------------------------------------------------------------- /neuroml/test/test_global_validation.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Test global validation toggles 4 | 5 | File: test_global_validation.py 6 | 7 | Copyright 2024 Ankur Sinha 8 | Author: Ankur Sinha 9 | """ 10 | 11 | try: 12 | import unittest2 as unittest 13 | except ImportError: 14 | import unittest 15 | 16 | import neuroml 17 | from neuroml import ( 18 | disable_build_time_validation, 19 | enable_build_time_validation, 20 | get_build_time_validation, 21 | ) 22 | from neuroml.utils import component_factory 23 | 24 | 25 | class TestGlobalValidationToggle(unittest.TestCase): 26 | def test_global_validation_toggle(self): 27 | """Test enabling and disabling build time validation""" 28 | self.assertTrue(get_build_time_validation()) 29 | with self.assertRaises(ValueError): 30 | anet = component_factory(neuroml.Network, id="anet") 31 | 32 | disable_build_time_validation() 33 | self.assertFalse(get_build_time_validation()) 34 | anet = component_factory(neuroml.Network, id="anet") 35 | 36 | enable_build_time_validation() 37 | with self.assertRaises(ValueError): 38 | anet = component_factory(neuroml.Network, id="anet") 39 | -------------------------------------------------------------------------------- /neuroml/test/test_hdf5_optimized.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for loaders 3 | 4 | """ 5 | 6 | import os 7 | 8 | import neuroml.writers as writers 9 | from neuroml import loaders 10 | from neuroml.test.test_xml_parser import compare 11 | 12 | try: 13 | import unittest2 as unittest 14 | except ImportError: 15 | import unittest 16 | 17 | 18 | class TestNeuroMLHDF5Optimized(unittest.TestCase): 19 | base_dir = os.path.dirname(__file__) 20 | # base_dir = '.' 21 | 22 | def runTest(self): 23 | print("Running tests in TestNeuroMLHDF5Optimized") 24 | 25 | def test_write_load(self): 26 | # for f in []: 27 | # for f in ['complete.nml']: 28 | # for f in ['simplenet.nml','testh5.nml','MediumNet.net.nml','complete.nml']: 29 | 30 | for f in ["simplenet.nml", "MediumNet.net.nml"]: 31 | file_name = "%s/../examples/test_files/%s" % (self.base_dir, f) 32 | 33 | print("Loading %s" % file_name) 34 | 35 | nml_doc0 = loaders.read_neuroml2_file(file_name, include_includes=True) 36 | summary0 = nml_doc0.summary() 37 | 38 | print(summary0) 39 | 40 | nml_h5_file = "%s/../examples/tmp/%s__1.h5" % (self.base_dir, f) 41 | writers.NeuroMLHdf5Writer.write(nml_doc0, nml_h5_file) 42 | print("Written to: %s" % nml_h5_file) 43 | 44 | nml_doc1 = loaders.read_neuroml2_file( 45 | nml_h5_file, include_includes=True, optimized=True 46 | ) 47 | 48 | summary1 = nml_doc1.summary().replace(" (optimized)", "") 49 | print("\n" + summary1) 50 | 51 | compare(summary0, summary1) 52 | 53 | nml_h5_file_2 = "%s/../examples/tmp/%s__2.h5" % (self.base_dir, f) 54 | writers.NeuroMLHdf5Writer.write(nml_doc1, nml_h5_file_2) 55 | print("Written to: %s" % nml_h5_file_2) 56 | # exit() 57 | nml_doc2 = loaders.read_neuroml2_file(nml_h5_file_2, include_includes=True) 58 | 59 | summary2 = nml_doc2.summary() 60 | print("Reloaded: %s" % nml_h5_file_2) 61 | print("\n" + summary2) 62 | 63 | compare(summary0, summary2) 64 | 65 | nml_h5_file_3 = "%s/../examples/tmp/%s__3.nml" % (self.base_dir, f) 66 | writers.NeuroMLWriter.write(nml_doc1, nml_h5_file_3) 67 | print("Written to: %s" % nml_h5_file_3) 68 | 69 | nml_doc3 = loaders.read_neuroml2_file(nml_h5_file_3, include_includes=True) 70 | 71 | summary3 = nml_doc3.summary() 72 | print("Reloaded: %s" % nml_h5_file_3) 73 | print("\n" + summary3) 74 | 75 | compare(summary0, summary3) 76 | 77 | 78 | if __name__ == "__main__": 79 | tnxp = TestNeuroMLHDF5Optimized() 80 | tnxp.test_write_load() 81 | -------------------------------------------------------------------------------- /neuroml/test/test_hdf5_parser.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for loaders 3 | 4 | """ 5 | 6 | import os 7 | 8 | import neuroml.writers as writers 9 | from neuroml import loaders 10 | from neuroml.test.test_xml_parser import compare 11 | 12 | try: 13 | import unittest2 as unittest 14 | except ImportError: 15 | import unittest 16 | 17 | 18 | class TestNeuroMLHDF5Parser(unittest.TestCase): 19 | base_dir = os.path.dirname(__file__) 20 | # base_dir = '.' 21 | 22 | def test_write_load_hdf5(self): 23 | # for f in []: 24 | # for f in ['MediumNet.net.nml']: 25 | for f in ["simplenet.nml", "testh5.nml", "MediumNet.net.nml", "complete.nml"]: 26 | file_name = "%s/../examples/test_files/%s" % (self.base_dir, f) 27 | 28 | print("Loading %s" % file_name) 29 | 30 | nml_doc0 = loaders.read_neuroml2_file(file_name, include_includes=True) 31 | summary0 = nml_doc0.summary() 32 | 33 | print(summary0) 34 | 35 | nml_h5_file = "%s/../examples/tmp/%s.h5" % (self.base_dir, f) 36 | writers.NeuroMLHdf5Writer.write(nml_doc0, nml_h5_file) 37 | print("Written to: %s" % nml_h5_file) 38 | 39 | nml_doc2 = loaders.NeuroMLHdf5Loader.load(nml_h5_file) 40 | 41 | summary1 = nml_doc2.summary() 42 | print("\n" + summary1) 43 | 44 | compare(summary0, summary1) 45 | 46 | def test_parse(self): 47 | file_name = self.base_dir + "/../examples/test_files/testh5.nml" 48 | 49 | nml_doc0 = loaders.NeuroMLLoader.load(file_name) 50 | summary0 = nml_doc0.summary(show_includes=False, show_non_network=False) 51 | print("\n" + summary0) 52 | 53 | print("-------------------------------\n\n") 54 | 55 | nml_h5_file = self.base_dir + "/../examples/tmp/testh5a.nml.h5" 56 | writers.NeuroMLHdf5Writer.write(nml_doc0, nml_h5_file) 57 | 58 | print("Written H5 network file to: " + nml_h5_file) 59 | 60 | nml_doc2 = loaders.NeuroMLHdf5Loader.load(nml_h5_file) 61 | 62 | summary1 = nml_doc2.summary(show_includes=False, show_non_network=False) 63 | print("\n" + summary1) 64 | 65 | compare(summary0, summary1) 66 | 67 | def runTest(self): 68 | print("Running tests in TestNeuroMLHDF5Parser") 69 | 70 | 71 | if __name__ == "__main__": 72 | tnxp = TestNeuroMLHDF5Parser() 73 | tnxp.test_write_load_hdf5() 74 | -------------------------------------------------------------------------------- /neuroml/test/test_integration.py: -------------------------------------------------------------------------------- 1 | import neuroml 2 | import neuroml.arraymorph as am 3 | import neuroml.writers as writers 4 | 5 | try: 6 | import unittest2 as unittest 7 | except ImportError: 8 | import unittest 9 | 10 | 11 | class TestIntegration(unittest.TestCase): 12 | def setUp(self): 13 | """ 14 | Make an optimized morphology, add a couple of segments, save it 15 | and then load it back 16 | """ 17 | 18 | vertices = [[0, 0, 0, 0.1], [1, 0, 0, 0.2], [2, 0, 0, 0.3], [3, 0, 0, 0.4]] 19 | connectivity = [-1, 0, 1, 2] 20 | 21 | self.optimized_morphology = am.ArrayMorphology( 22 | vertices=vertices, connectivity=connectivity, id="arraymorph_test" 23 | ) 24 | 25 | seg = neuroml.Segment() 26 | 27 | # TODO: 28 | # self.optimized_morphology.segments.append(seg) 29 | 30 | doc = neuroml.NeuroMLDocument() 31 | 32 | cell = neuroml.Cell() 33 | 34 | def test_to_neuroml_morphology_and_write(self): 35 | neuroml_morphology = self.optimized_morphology.to_neuroml_morphology(id="Test") 36 | self.assertEqual(neuroml_morphology.id, "Test") 37 | self.assertEqual(len(neuroml_morphology.segments), 3) 38 | self.assertIsNone(writers.NeuroMLWriter.write(neuroml_morphology, "/dev/null")) 39 | 40 | def test_arraymorph_properties(self): 41 | self.assertEqual(self.optimized_morphology.id, "arraymorph_test") 42 | 43 | def test_arraymorph_write(self): 44 | writers.NeuroMLWriter.write(self.optimized_morphology, "/dev/null") 45 | -------------------------------------------------------------------------------- /neuroml/test/test_loaders.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for loaders 3 | 4 | """ 5 | 6 | import os 7 | 8 | import neuroml 9 | from neuroml import loaders 10 | 11 | try: 12 | import unittest2 as unittest 13 | except ImportError: 14 | import unittest 15 | 16 | 17 | class TestNeuroMLLoader(unittest.TestCase): 18 | def test_load_neuroml(self): 19 | root_dir = os.path.dirname(neuroml.__file__) 20 | print("root dir is: " + root_dir) 21 | test_file_path = os.path.join(root_dir, "examples/test_files/Purk2M9s.nml") 22 | print("test fi le path is: " + test_file_path) 23 | 24 | f = open(test_file_path, "r") 25 | # print(f.read()) 26 | doc = loaders.NeuroMLLoader.load(test_file_path) 27 | self.assertEqual(doc.id, "Purk2M9s") 28 | f.close() 29 | print("Finished test") 30 | 31 | def test_read_neuroml2_file(self): 32 | """Test the `read_neuroml2_file` method""" 33 | root_dir = os.path.dirname(neuroml.__file__) 34 | test_file_path = os.path.join(root_dir, "examples/test_files/MediumNet.net.nml") 35 | doc = loaders.read_neuroml2_file(test_file_path, include_includes=True) 36 | doc_info = doc.info(show_contents=True, return_format="dict") 37 | doc2 = loaders.read_neuroml2_file(test_file_path, include_includes=True) 38 | doc2_info = doc2.info(show_contents=True, return_format="dict") 39 | 40 | # check that the ids of the two are the same 41 | self.assertEqual(doc_info["id"], doc2_info["id"]) 42 | 43 | def test_non_neuroml_file(self): 44 | """Test an non-NeuroML document.""" 45 | root_dir = os.path.dirname(neuroml.__file__) 46 | test_file_path = os.path.join(root_dir, "examples/test_files/sbml-example.xml") 47 | print("test file path is: " + test_file_path) 48 | 49 | try: 50 | loaders.NeuroMLLoader.load(test_file_path) 51 | except TypeError: 52 | print("Exception raised. Test passes.") 53 | 54 | 55 | if __name__ == "__main__": 56 | t = TestNeuroMLLoader() 57 | t.test_load_neuroml() 58 | -------------------------------------------------------------------------------- /neuroml/test/test_morphology.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for the Morphology class 3 | 4 | """ 5 | 6 | import neuroml 7 | 8 | try: 9 | import unittest2 as unittest 10 | except ImportError: 11 | import unittest 12 | 13 | 14 | class TestSingleMorphology(unittest.TestCase): 15 | def setUp(self): 16 | self.test_morphology = neuroml.Morphology() 17 | self.test_morphology.id = "TestMorph" 18 | 19 | for i in range(10): 20 | self.test_morphology.segments.append(neuroml.Segment()) 21 | 22 | def test_id(self): 23 | """ 24 | Test if Morphology instantiation and id assignment is working 25 | """ 26 | self.assertEqual(self.test_morphology.id, "TestMorph") 27 | 28 | def test_num_segments(self): 29 | self.assertEqual(self.test_morphology.num_segments, 10) 30 | -------------------------------------------------------------------------------- /neuroml/test/test_utils.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | """ 3 | Test utilities 4 | 5 | File: neuroml/test/test_utils.py 6 | 7 | Copyright 2023 NeuroML contributors 8 | """ 9 | 10 | import os 11 | import unittest 12 | 13 | import neuroml 14 | from neuroml.utils import ( 15 | component_factory, 16 | fix_external_morphs_biophys_in_cell, 17 | get_relative_component_path, 18 | print_hierarchy, 19 | ) 20 | from neuroml.writers import NeuroMLWriter 21 | 22 | 23 | class UtilsTestCase(unittest.TestCase): 24 | """Test the Utils module""" 25 | 26 | def test_component_factory(self): 27 | "Test the component factory." 28 | 29 | nml_doc = component_factory("NeuroMLDocument", id="emptydocument") 30 | self.assertIsInstance(nml_doc, neuroml.NeuroMLDocument) 31 | 32 | iaf_cell = component_factory( 33 | "IafCell", 34 | id="test_cell", 35 | leak_reversal="-50 mV", 36 | thresh="-55mV", 37 | reset="-70 mV", 38 | C="0.2nF", 39 | leak_conductance="0.01uS", 40 | ) 41 | self.assertIsInstance(iaf_cell, neuroml.IafCell) 42 | 43 | @unittest.expectedFailure 44 | def test_component_factory_should_fail(self): 45 | "Test the component factory." 46 | 47 | iaf_cell = component_factory( 48 | "IafCell", 49 | id="test_cell", 50 | ) 51 | 52 | def test_networkx_hier_graph(self): 53 | """Test constructing a networkx graph of a hierarchy""" 54 | hier = neuroml.NeuroMLDocument.get_class_hierarchy() 55 | self.assertIsNotNone(hier) 56 | print_hierarchy(hier) 57 | 58 | path, graph = get_relative_component_path("Input", "Instance") 59 | self.assertIsNotNone(graph) 60 | self.assertEqual(path, "../Population/Instance") 61 | 62 | def test_fix_external_morphs_biophys_in_cell(self): 63 | """Test fix_external_morphs_biophys_in_cell function""" 64 | # document that includes cell and morphology with cell referring to 65 | # morphology 66 | nml_doc = component_factory("NeuroMLDocument", id="testdoc") 67 | nml_doc.add("Morphology", id="test_morph_1", validate=False) 68 | test_cell_1 = nml_doc.add( 69 | "Cell", id="test_cell_1", morphology_attr="test_morph_1" 70 | ) 71 | test_cell_1.morphology = None 72 | 73 | fix_external_morphs_biophys_in_cell(nml_doc) 74 | self.assertIsNotNone(nml_doc.cells[0].morphology) 75 | self.assertIsNone(nml_doc.cells[0].morphology_attr) 76 | self.assertEqual(nml_doc.cells[0].morphology.id, "test_morph_1") 77 | print(nml_doc) 78 | 79 | # check that a key error is raised if the referenced morph cannot be 80 | # found 81 | nml_doc_2 = component_factory("NeuroMLDocument", id="testdoc") 82 | nml_doc_2.add("Morphology", id="test_morph_5", validate=False) 83 | test_cell_2 = nml_doc_2.add( 84 | "Cell", id="test_cell_1", morphology_attr="test_morph_1" 85 | ) 86 | test_cell_2.morphology = None 87 | 88 | with self.assertRaises(KeyError): 89 | fix_external_morphs_biophys_in_cell(nml_doc_2) 90 | print(nml_doc_2) 91 | 92 | def test_fix_external_morphs_biophys_in_cell_2(self): 93 | """Test fix_external_morphs_biophys_in_cell function""" 94 | # document that includes cell and biophysical properties with cell 95 | # referring to biophysical properties 96 | nml_doc = component_factory("NeuroMLDocument", id="testdoc") 97 | nml_doc.add("BiophysicalProperties", id="test_biophys_1", validate=False) 98 | test_cell_1 = nml_doc.add( 99 | "Cell", id="test_cell_1", biophysical_properties_attr="test_biophys_1" 100 | ) 101 | test_cell_1.biophysical_properties = None 102 | 103 | fix_external_morphs_biophys_in_cell(nml_doc) 104 | self.assertIsNotNone(nml_doc.cells[0].biophysical_properties) 105 | self.assertIsNone(nml_doc.cells[0].biophysical_properties_attr) 106 | self.assertEqual(nml_doc.cells[0].biophysical_properties.id, "test_biophys_1") 107 | print(nml_doc) 108 | 109 | # check that a key error is raised if the referenced biophysical 110 | # property cannot be found 111 | nml_doc_2 = component_factory("NeuroMLDocument", id="testdoc") 112 | nml_doc_2.add("BiophysicalProperties", id="test_biophys_5", validate=False) 113 | test_cell_2 = nml_doc_2.add( 114 | "Cell", id="test_cell_1", biophysical_properties_attr="test_biophys_1" 115 | ) 116 | test_cell_2.biophysical_properties = None 117 | print(nml_doc_2) 118 | 119 | with self.assertRaises(KeyError): 120 | fix_external_morphs_biophys_in_cell(nml_doc_2) 121 | 122 | def test_fix_external_morphs_biophys_in_cell_3(self): 123 | """Test fix_external_morphs_biophys_in_cell function""" 124 | filename = "nml_morph_doc.nml" 125 | nml_doc = component_factory("NeuroMLDocument", id="testdoc") 126 | nml_doc.add("Morphology", id="test_morph_1", validate=False) 127 | NeuroMLWriter.write(nml_doc, file=filename) 128 | 129 | # doc that includes 130 | nml_doc_2 = component_factory("NeuroMLDocument", id="testdoc") 131 | nml_doc_2.add("IncludeType", href=filename) 132 | test_cell_1 = nml_doc_2.add( 133 | "Cell", id="test_cell_1", morphology_attr="test_morph_1" 134 | ) 135 | test_cell_1.morphology = None 136 | 137 | fix_external_morphs_biophys_in_cell(nml_doc_2) 138 | self.assertIsNotNone(nml_doc_2.cells[0].morphology) 139 | self.assertIsNone(nml_doc_2.cells[0].morphology_attr) 140 | self.assertEqual(nml_doc_2.cells[0].morphology.id, "test_morph_1") 141 | print(nml_doc_2) 142 | os.unlink(filename) 143 | 144 | # doc that does not include, and should fail 145 | nml_doc_3 = component_factory("NeuroMLDocument", id="testdoc") 146 | test_cell_2 = nml_doc_3.add( 147 | "Cell", id="test_cell_1", morphology_attr="test_morph_1" 148 | ) 149 | test_cell_2.morphology = None 150 | print(nml_doc_3) 151 | with self.assertRaises(KeyError): 152 | fix_external_morphs_biophys_in_cell(nml_doc_3) 153 | 154 | def test_fix_external_morphs_biophys_in_cell_4(self): 155 | """Test fix_external_morphs_biophys_in_cell function""" 156 | # document that includes cell and biophysical properties with cell 157 | # referring to biophysical properties 158 | filename = "nml_biophys_doc.nml" 159 | nml_doc = component_factory("NeuroMLDocument", id="testdoc") 160 | nml_doc.add("BiophysicalProperties", id="test_biophys_1", validate=False) 161 | NeuroMLWriter.write(nml_doc, file=filename) 162 | 163 | # doc that includes 164 | nml_doc_2 = component_factory("NeuroMLDocument", id="testdoc") 165 | nml_doc_2.add("IncludeType", href=filename) 166 | test_cell_1 = nml_doc_2.add( 167 | "Cell", id="test_cell_1", biophysical_properties_attr="test_biophys_1" 168 | ) 169 | test_cell_1.biophysical_properties = None 170 | 171 | fix_external_morphs_biophys_in_cell(nml_doc_2) 172 | self.assertIsNotNone(nml_doc_2.cells[0].biophysical_properties) 173 | self.assertIsNone(nml_doc_2.cells[0].biophysical_properties_attr) 174 | self.assertEqual(nml_doc_2.cells[0].biophysical_properties.id, "test_biophys_1") 175 | print(nml_doc_2) 176 | os.unlink(filename) 177 | 178 | # doc that does not include, and should fail 179 | nml_doc_3 = component_factory("NeuroMLDocument", id="testdoc") 180 | test_cell_2 = nml_doc_3.add( 181 | "Cell", id="test_cell_1", biophysical_properties_attr="test_biophys_1" 182 | ) 183 | test_cell_2.biophysical_properties = None 184 | print(nml_doc_3) 185 | with self.assertRaises(KeyError): 186 | fix_external_morphs_biophys_in_cell(nml_doc_3) 187 | -------------------------------------------------------------------------------- /neuroml/test/test_writers.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for writers 3 | 4 | """ 5 | 6 | import tempfile 7 | 8 | import numpy as np 9 | 10 | import neuroml 11 | from neuroml import arraymorph as am 12 | 13 | try: 14 | import unittest2 as unittest 15 | except ImportError: 16 | import unittest 17 | 18 | 19 | class TestNeuroMLWriter(unittest.TestCase): 20 | def test_write_nonsense(self): 21 | """ 22 | Should Throw an attribute error as integers do not have an export method 23 | """ 24 | 25 | a = 6 # not NeuroML-writeable 26 | writer_method = neuroml.writers.NeuroMLWriter.write 27 | self.assertRaises(AttributeError, writer_method, a, "tmpfile") 28 | 29 | 30 | class TestArrayMorphWriter(unittest.TestCase): 31 | def setUp(self): 32 | num_segments = int(1e6) 33 | num_vertices = num_segments + 1 34 | 35 | x = np.linspace(0, 10, num_vertices) 36 | y = np.zeros(num_vertices) 37 | z = np.zeros(num_vertices) 38 | d = np.linspace(1, 0.01, num_vertices) 39 | 40 | vertices = np.array([x, y, z, d]).T 41 | 42 | connectivity = range(-1, num_segments) 43 | 44 | big_arraymorph = am.ArrayMorphology( 45 | vertices=vertices, connectivity=connectivity 46 | ) 47 | transposed_x = x + 10 48 | transposed_vertices = np.array([transposed_x, y, z, d]).T 49 | 50 | transposed_arraymorph = am.ArrayMorphology( 51 | vertices=transposed_vertices, connectivity=connectivity 52 | ) 53 | 54 | bigger_d = d + 0.5 55 | fatter_vertices = np.array([x, y, z, bigger_d]).T 56 | 57 | fatter_arraymorph = am.ArrayMorphology( 58 | vertices=fatter_vertices, connectivity=connectivity 59 | ) 60 | 61 | self.transposed_arraymorph = transposed_arraymorph 62 | self.fatter_arraymorph = fatter_arraymorph 63 | self.big_arraymorph = big_arraymorph 64 | 65 | self.cell_1 = neuroml.Cell(id="cell_1") 66 | self.cell_2 = neuroml.Cell(id="cell_2") 67 | self.cell_3 = neuroml.Cell(id="cell_3") 68 | 69 | self.cell_1.morphology = transposed_arraymorph 70 | self.cell_2.morphology = fatter_arraymorph 71 | self.cell_3.morphology = big_arraymorph 72 | 73 | self.test_doc = neuroml.NeuroMLDocument(id="TestDocument") 74 | 75 | self.test_doc.cells.append(self.cell_1) 76 | self.test_doc.cells.append(self.cell_2) 77 | self.test_doc.cells.append(self.cell_3) 78 | 79 | def test_write_big_arraymorph(self): 80 | writer_method = neuroml.writers.ArrayMorphWriter.write 81 | filename = tempfile.mkstemp()[1] 82 | 83 | try: 84 | writer_method(self.test_doc, filename) 85 | except: 86 | self.fail("Exception raised!") 87 | 88 | def test_write_expected(self): 89 | """ 90 | More of an integration test, write a file and confirm the contents are 91 | as expected. 92 | """ 93 | 94 | filename = tempfile.mkstemp()[1] 95 | 96 | writer_method = neuroml.writers.ArrayMorphWriter.write 97 | writer_method(self.big_arraymorph, filename) 98 | 99 | loader_method = neuroml.loaders.ArrayMorphLoader.load 100 | doc = loader_method(filename) 101 | array_morph = doc.morphology[0] 102 | 103 | connectivity_equal = np.testing.assert_array_equal( 104 | array_morph.connectivity, self.big_arraymorph.connectivity 105 | ) 106 | physical_masks_equal = np.testing.assert_array_equal( 107 | array_morph.physical_mask, self.big_arraymorph.physical_mask 108 | ) 109 | vertices_equal = np.testing.assert_array_equal( 110 | array_morph.vertices, self.big_arraymorph.vertices 111 | ) 112 | 113 | self.assertEqual(connectivity_equal, None) # None when equal 114 | self.assertEqual(physical_masks_equal, None) # None when equal 115 | self.assertEqual(vertices_equal, None) # None when equal 116 | 117 | def test_write_multiple_morphologies(self): 118 | filename = tempfile.mkstemp()[1] 119 | 120 | writer_method = neuroml.writers.ArrayMorphWriter.write 121 | try: 122 | writer_method(self.test_doc, filename) 123 | except: 124 | self.fail("Exception raised!") 125 | 126 | def test_write_multiple_morphologies(self): 127 | filename = tempfile.mkstemp()[1] 128 | writer_method = neuroml.writers.ArrayMorphWriter.write 129 | writer_method(self.test_doc, filename) 130 | 131 | loader_method = neuroml.loaders.ArrayMorphLoader.load 132 | document = loader_method(filename) 133 | 134 | self.assertIsInstance(document, neuroml.NeuroMLDocument) 135 | -------------------------------------------------------------------------------- /neuroml/test/test_xml_parser.py: -------------------------------------------------------------------------------- 1 | """ 2 | Unit tests for loaders 3 | 4 | """ 5 | 6 | import os 7 | 8 | import pytest 9 | 10 | import neuroml.writers as writers 11 | from neuroml import loaders 12 | from neuroml.hdf5.DefaultNetworkHandler import DefaultNetworkHandler 13 | from neuroml.hdf5.NetworkBuilder import NetworkBuilder 14 | from neuroml.hdf5.NeuroMLXMLParser import NeuroMLXMLParser 15 | 16 | 17 | @pytest.mark.parametrize( 18 | "f", 19 | [ 20 | "simplenet.nml", 21 | "testh5.nml", 22 | "pyr_4_sym.cell.nml", 23 | "MediumNet.net.nml", 24 | "complete.nml", 25 | ], 26 | ) 27 | class TestNeuroMLXMLParser: 28 | def test_parse(self, f): 29 | base_dir = os.path.dirname(__file__) 30 | file_name = base_dir + "/../examples/test_files/" + f 31 | print("---- Testing {}".format(file_name)) 32 | 33 | nml_doc0 = loaders.read_neuroml2_file( 34 | file_name, include_includes=True, verbose=True 35 | ) 36 | 37 | summary0 = nml_doc0.summary(show_includes=False, show_non_network=False) 38 | # print("\n" + summary0) 39 | 40 | nmlHandler = DefaultNetworkHandler() 41 | currParser = NeuroMLXMLParser(nmlHandler) 42 | currParser.parse(file_name) 43 | 44 | print("-------------------------------\n\n") 45 | 46 | nmlHandler_new = NetworkBuilder() 47 | currParser_new = NeuroMLXMLParser(nmlHandler_new) 48 | currParser_new.parse(file_name) 49 | nml_doc_new = nmlHandler_new.get_nml_doc() 50 | 51 | summary = nml_doc_new.summary(show_includes=False, show_non_network=False) 52 | # print(summary) 53 | 54 | compare(summary, summary0) 55 | 56 | nml_file_new = base_dir + "/../examples/tmp/EXP_" + f 57 | 58 | writers.NeuroMLWriter.write(nml_doc_new, nml_file_new) 59 | print("Written network file to: " + nml_file_new) 60 | 61 | 62 | def compare(s1, s2): 63 | if s1 == s2: 64 | print("Same!") 65 | return 66 | 67 | l1 = s1.split("\n") 68 | l2 = s2.split("\n") 69 | 70 | for i in range(min(len(l1), len(l2))): 71 | if not l1[i] == l2[i]: 72 | print("Mismatch at line %i:\n>>> %s\n<<< %s" % (i, l1[i], l2[i])) 73 | if len(l1) != len(l2): 74 | print("Different number of lines!") 75 | 76 | assert s1 == s2 77 | 78 | 79 | if __name__ == "__main__": 80 | tnxp = TestNeuroMLXMLParser() 81 | tnxp.test_parse() 82 | -------------------------------------------------------------------------------- /notebooks/HDF5Serialisation.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Use of NeuroML HDF5 serialisation format\n", 8 | "\n", 9 | "\n", 10 | "The main serialisation format for NeuroML 2 is XML, but a serialisation form based on HDF5 is also supported.\n", 11 | "\n", 12 | "The main advantages of this are:\n", 13 | " \n", 14 | "- Models can be built with libNeuroML and saved automatically in this format ([code](https://github.com/NeuralEnsemble/libNeuroML/tree/master/neuroml/hdf5))\n", 15 | "- An identical format is used in the Java based libraries ([code](https://github.com/NeuroML/org.neuroml.model/tree/master/src/main/java/org/neuroml/model/util/hdf5))\n", 16 | "\n", 17 | "Note though:\n", 18 | "\n", 19 | "- Documentation at this time is minimal\n", 20 | "- The serialisation concentrates on efficient storage of network properties (cell positions, connections), rather than morphologies (this is not an issue if populations with multiple identical cells are used)\n", 21 | "\n" 22 | ] 23 | }, 24 | { 25 | "cell_type": "markdown", 26 | "metadata": {}, 27 | "source": [ 28 | "## Writing to the format\n", 29 | "\n", 30 | "To write a model constructed in/loaded into libNeuroML to HDF5 format, use the NeuroMLHdf5Writer class (e.g. see [build_complete.py](https://github.com/NeuralEnsemble/libNeuroML/blob/master/neuroml/examples/build_complete.py))\n", 31 | "\n", 32 | "```\n", 33 | "import neuroml.writers as writers\n", 34 | "\n", 35 | "nml_doc = ...\n", 36 | "\n", 37 | "writers.NeuroMLHdf5Writer.write(nml_doc, 'complete.nml.h5')\n", 38 | "```\n" 39 | ] 40 | }, 41 | { 42 | "cell_type": "markdown", 43 | "metadata": {}, 44 | "source": [ 45 | "## Loading the HDF5 format\n", 46 | "\n", 47 | "You can use NeuroMLHdf5Loader:\n", 48 | "\n", 49 | "```\n", 50 | "from neuroml import loaders\n", 51 | "\n", 52 | "nml_doc2 = loaders.NeuroMLHdf5Loader.load('complete.nml.h5')\n", 53 | "```\n", 54 | "\n", 55 | "or **even better** use read_neuroml2_file, so that the included files (cells, channels) will be loaded into memory too:\n", 56 | "\n", 57 | "```\n", 58 | "nml_doc2 = loaders.read_neuroml2_file(nml_h5_file, include_includes=True)\n", 59 | "```\n", 60 | "\n", 61 | "See a test example [here](https://github.com/NeuralEnsemble/libNeuroML/blob/master/neuroml/test/test_hdf5_parser.py) for writing/reading the format.\n" 62 | ] 63 | }, 64 | { 65 | "cell_type": "markdown", 66 | "metadata": {}, 67 | "source": [ 68 | "## Loading as \"optimized\" format\n", 69 | "\n", 70 | "It is also possible to load the HDF5 files as \"optimized\" format. This means:\n", 71 | "\n", 72 | "- Instead of constructing the tree of classes in memory for instances/connections etc. it just stores the datasets for the positions and connections in memory as HDF5 datasets and uses these when info about positions/connections are requested.\n", 73 | "\n", 74 | "The rest of the NeuroML (cells, channels) are loaded in the normal way.\n", 75 | "\n", 76 | "```\n", 77 | "from neuroml import loaders\n", 78 | "\n", 79 | "nml_doc2 = loaders.read_neuroml2_file(nml_h5_file,\n", 80 | " include_includes=True,\n", 81 | " optimized=True)\n", 82 | "```" 83 | ] 84 | }, 85 | { 86 | "cell_type": "code", 87 | "execution_count": null, 88 | "metadata": {}, 89 | "outputs": [], 90 | "source": [] 91 | } 92 | ], 93 | "metadata": { 94 | "kernelspec": { 95 | "display_name": "Python 3", 96 | "language": "python", 97 | "name": "python3" 98 | }, 99 | "language_info": { 100 | "codemirror_mode": { 101 | "name": "ipython", 102 | "version": 3 103 | }, 104 | "file_extension": ".py", 105 | "mimetype": "text/x-python", 106 | "name": "python", 107 | "nbconvert_exporter": "python", 108 | "pygments_lexer": "ipython3", 109 | "version": "3.7.7" 110 | } 111 | }, 112 | "nbformat": 4, 113 | "nbformat_minor": 4 114 | } 115 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = ["setuptools"] 3 | build-backend = "setuptools.build_meta" 4 | -------------------------------------------------------------------------------- /pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | addopts = --ignore-glob=doc/* 3 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = libNeuroML 3 | version = 0.6.3 4 | author_email = vellamike@gmail.com, p.gleeson@gmail.com 5 | author = libNeuroML authors and contributors 6 | description = A Python library for working with NeuroML descriptions of neuronal models 7 | long_description = file: README.md 8 | long_description_content_type=text/markdown 9 | url = http://libneuroml.readthedocs.org/en/latest/ 10 | license = BSD-2-Clause 11 | classifiers = 12 | Intended Audience :: Science/Research 13 | License :: OSI Approved :: BSD License 14 | Natural Language :: English 15 | Operating System :: OS Independent 16 | Development Status :: 5 - Production/Stable 17 | Programming Language :: Python :: 3 18 | Programming Language :: Python :: 3.8 19 | Programming Language :: Python :: 3.9 20 | Programming Language :: Python :: 3.10 21 | Programming Language :: Python :: 3.11 22 | Programming Language :: Python :: 3.12 23 | Topic :: Scientific/Engineering :: Bio-Informatics 24 | Topic :: Scientific/Engineering 25 | 26 | [options] 27 | install_requires = 28 | lxml 29 | six 30 | networkx 31 | numpy<2.0.0 32 | tables>=3.3.0 33 | typing; python_version<"3.5" 34 | natsort 35 | 36 | packages = find: 37 | 38 | [options.packages.find] 39 | where = . 40 | include = neuroml* 41 | exclude = neuroml.test* 42 | 43 | [options.package_data] 44 | neuroml.nml = 45 | *.xsd 46 | 47 | 48 | [options.extras_require] 49 | test = 50 | pytest 51 | 52 | dev = 53 | wheel 54 | generateds >= 2.20a; python_version >= '3.0' 55 | cython 56 | numpy<2.0.0 57 | networkx 58 | flake8 59 | pytest 60 | ruff 61 | natsort 62 | pre-commit 63 | 64 | doc = 65 | sphinxcontrib-bibtex 66 | pydata-sphinx-theme 67 | natsort 68 | 69 | full = 70 | libNeuroML[test] 71 | libNeuroML[dev] 72 | libNeuroML[doc] 73 | 74 | [flake8] 75 | # ignore: 76 | # spacing around operators, comment blocks, in argument lists 77 | # lines too long 78 | ignore = E501,E502,F403,F405,E231,E228,E225,E226,E265,E261 79 | exclude = 80 | neuroml/nml/nml.py, 81 | neuroml/nml/helper_methods.py, 82 | doc, 83 | build 84 | 85 | [mypy] 86 | ignore_missing_imports = True 87 | follow_imports = silent 88 | exclude = (nml\.py|doc/|build/|helper_methods\.py|generateds_config\.py|examples/) 89 | --------------------------------------------------------------------------------