Page 1 of 1
Saving and loading NeuroML file
Posted: Thu Apr 01, 2010 10:09 am
by mattions
Hello,
I would like to know if there is a way to save and load NeuroML file using python and not the GUI.
Is somewhere on the Programmer's Reference?
Proposed API would be something like:
Code: Select all
h.save_to_NeuroML('filename.xml', level=1) # For saving. Level keyword to choose the NeuroML level
h.load_NeuroML('filename.xml')
A quick example how I would like to use it:
Saving:
Code: Select all
from neuron import h
soma = h.Section()
h.save_to_NeuroML('filename.xml', level=1)
Loading:
Code: Select all
from neuron import h
h.load_NeuroML('filename.xml')
print h.soma.diam
Re: Saving and loading NeuroML file
Posted: Fri Apr 02, 2010 2:01 pm
by hines
neurondemo -python
from neuron import h
h.demo(2)
h.load_file("mview.hoc")
h.ModelViewXML(h.ModelView(0)).xportLevel2('temp.xml')
Re: Saving and loading NeuroML file
Posted: Fri Apr 02, 2010 2:19 pm
by hines
forgot the load example (note that xml import does not work for the demo(2) above since that demo has
inhomogeneities within a section. Try above with demo(3).)
nrngui -python
from neuron import h
h.load_file('celbild.hoc')
cb = h.CellBuild(0)
cb.manage.neuroml('temp.xml')
cb.cexport(1)
Re: Saving and loading NeuroML file
Posted: Fri Apr 02, 2010 9:31 pm
by ted
hines wrote:neurondemo -python
from neuron import h
h.demo(2)
h.load_file("mview.hoc")
h.ModelViewXML(h.ModelView(0)).xportLevel2('temp.xml')
From which is it correct to infer that the hoc way (once a model exists) would be
Code: Select all
load_file("mview.hoc")
objref foo
foo = new ModelView(0)
objref bar
bar = new ModelViewXML(foo)
bar.xportLevel2("temp.xml")
?
The hoc code for xml import seems almost identical to the Python--
Code: Select all
load_file("celbild.hoc")
objref cb
cb = new CellBuild(0)
cb.manage.neuroml("temp.xml")
cb.export(1)
Re: Saving and loading NeuroML file
Posted: Tue Apr 06, 2010 5:40 am
by mattions
Hi, thanks for the answers.
I managed to export a NeuroML file using the python interpreter doing this:
Saving
Code: Select all
from neuron import h
import neuron.gui # To not freeze the GUI
h.load_file('mview.hoc')
# Bunch of sections, just for testing purpose.
sec1 = h.Section()
sec2 = h.Section()
sec2.diam=1000
sec1.connect(sec2)
modelView = h.ModelView(0)
modelXml = h.ModelViewXML(modelView)
modelXml.xportLevel1("temp.xml")
However when I load that file, using the Cellbuilder I get this error:
Code: Select all
NameError: name 'rdxml' is not defined
The whole log:
Code: Select all
mattions@triton:Neuronvisio(local)$ ipython -pylab
Python 2.6.4 (r264:75706, Dec 7 2009, 18:45:15)
Type "copyright", "credits" or "license" for more information.
IPython 0.10 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object'. ?object also works, ?? prints more.
Welcome to pylab, a matplotlib-based Python environment.
For more information, type 'help(pylab)'.
In [1]: import neuron.gui
NEURON -- Release 7.1 (359:7f113b76a94b) 2009-10-26
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2008
See http://www.neuron.yale.edu/credits.html
1
In [2]: ---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in <module>()
----> 1
2
3
4
5
ImportError: No module named rdxml
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
/usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in <module>()
----> 1
2
3
4
5
NameError: name 'rdxml' is not defined
NEURON: No attribute: rdxml
near line 0
{neuroml1()}
^
CellManage[0].neuroml("./exported_neuroml.xml")
CellManage[0].neuroml1()
doNotify()
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python2.6/threading.py", line 525, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.6/dist-packages/neuron/gui.py", line 36, in run
self.fun()
File "/usr/local/lib/python2.6/dist-packages/neuron/gui.py", line 17, in process_events
h.doNotify()
RuntimeError: hoc error
Loading
Re: Saving and loading NeuroML file
Posted: Tue Apr 06, 2010 9:46 am
by ted
The problem occurs with Level 1 NeuroML. Level 2 NeuroML seems to import OK.
Re: Saving and loading NeuroML file
Posted: Tue Apr 06, 2010 10:08 am
by mattions
ted wrote:The problem occurs with Level 1 NeuroML. Level 2 NeuroML seems to import OK.
I'm getting the same error also using Level 2..
Re: Saving and loading NeuroML file
Posted: Tue Apr 06, 2010 4:53 pm
by hines
The xml readers require 3-d points. Before constructing the ModelView in your example you need
h.define_shape()
Then you can write a model which will be readable.
It works in my hands.
for writing
ipython
from neuron import h
import neuron.gui # To not freeze the GUI
h.load_file('mview.hoc')
# Bunch of sections, just for testing purpose.
sec1 = h.Section()
sec2 = h.Section()
sec2.diam=1000
sec1.connect(sec2)
h.define_shape()
modelView = h.ModelView(0)
modelXml = h.ModelViewXML(modelView)
modelXml.xportLevel1("temp.xml")
for reading
ipython
from neuron import h
h.load_file('celbild.hoc')
cb = h.CellBuild(0)
cb.manage.neuroml('temp.xml')
cb.cexport(1)
Re: Saving and loading NeuroML file
Posted: Tue Apr 06, 2010 5:30 pm
by mattions
I guess I have a problem with the CellBuilder:
this is the dir of the neuroml object:
Code: Select all
In [21]: dir(cb.manage.neuroml )
Out[21]:
['Section',
'__call__',
'__class__',
'__delattr__',
'__delitem__',
'__doc__',
'__format__',
'__getattribute__',
'__getitem__',
'__hash__',
'__init__',
'__iter__',
'__len__',
'__new__',
'__nonzero__',
'__reduce__',
'__reduce_ex__',
'__repr__',
'__setattr__',
'__setitem__',
'__sizeof__',
'__str__',
'__subclasshook__',
'allsec',
'baseattr',
'cas',
'classname',
'egeom',
'emem',
'esub',
'etop',
'hocobjptr',
'neuroml',
'next',
'pr',
'ref',
'save_classbody',
'save_data',
'setpointer',
'toplevel',
'update',
'xmlwrite']
There is not rdxml attribute.
Do you have one in your version? (I'm running 7.1, not svn)
Re: Saving and loading NeuroML file
Posted: Thu Apr 08, 2010 5:12 am
by mattions
Dear all,
I think I found the problem.
The rdxml.py file is in the source
http://www.neuron.yale.edu/hg/neuron/nr ... n/rdxml.py but it doesn't get installed in the proper location.
Therefore is not in the PYTHONPATH so when CellBuilder try to read the xml, loading rdxml fails badly because it can't find the module.
Copying the module inside the directory or adding it to the path makes everything working. Both from gui and code.
Thanks,
Michele.
Re: Saving and loading NeuroML file
Posted: Fri Apr 09, 2010 1:13 pm
by hines
Are you sure about that. When I 'make install' I see
<prefix>/share/nrn/lib/python/rdxml.py
and when I launch python and
from neuron import h
I see that path in sys.path (the above path is supposed to be automatically added when
neuron is imported).
Re: Saving and loading NeuroML file
Posted: Fri Apr 09, 2010 1:33 pm
by mattions
I think that maybe there is a nrn directory that should not be there.
I found the file here:
Code: Select all
/usr/local/nrn/share/nrn/lib/python/rdxml.py
instead should be here
Code: Select all
/usr/local/share/nrn/lib/python/rdxml.py
my prefix is the standard:
Re: Saving and loading NeuroML file
Posted: Fri Apr 09, 2010 1:55 pm
by hines
The default prefix is /usr/local/nrn
Do you use an explicit --prefix=/usr/local? That should create a /usr/local/share, /usr/local/include, and /usr/local/i686.
Of course that makes uninstallation via rm -r -f not so easy.
Re: Saving and loading NeuroML file
Posted: Fri Apr 09, 2010 2:27 pm
by mattions
My fault.
Used with classic GNU program I though ./configure would use /usr/local by default not /usr/local/nrn.
I need to update my PYTHONPATH with this location, then should be ok.