Page 1 of 1

BioPhysical properties of imported morphology in Python

Posted: Tue Mar 05, 2019 9:16 am
by sohaib786
Greetings,
I am trying to define biophysical properties for simulation. I tried doing it with two methods.
1) I imported morphology, set parameters using GUI. Then to simulate I tried to import it's hoc file to python using the instruction https://www.neuron.yale.edu/neuron/stat ... essing-hoc, but it shows an error.
AttributeError: module 'neuron' has no attribute '_has_rxd'
0 /usr/local/nrn/x86_64/bin/nrniv: can't open ca3fin.hoc
2) I also imported the morphology file directly to python environment successfully using the code from viewtopic.php?t=3874 and then tried to add biophysical parameters. But wasn't successful in adding the desired values. I looked up in the examples from https://neuron.yale.edu/neuron/static/c ... amples.zip but to no avail.
I am not able to link the loaded cell data and function/methods to assign values.
It would be great if anyone could shed some light or provide a link to some project/code which easily explains.

Thanks for your time.

Re: BioPhysical properties of imported morphology in Python

Posted: Tue Mar 05, 2019 10:14 am
by ted
What is ca3fin.hoc? Is that a file that already existed in the same directory as the morphological data that you imported?

The message

Code: Select all

AttributeError: module 'neuron' has no attribute '_has_rxd'
only means that the instance of NEURON that you are using was compiled without the ability to use RxD.
I imported morphology, set parameters using GUI. Then to simulate I tried to import it's hoc file to python
Assuming that you have a CellBuilder that contains the imported morphology of a cell, and specifies whatever biophysical properties you want your model cell to have, then I will also assume that you used that CellBuilder to write a hoc file that contains statements that will create a model cell with the corresponding anatomical and biophysical properties. At this point, all you need to do is start Python, import h, and use h to execute the hoc file. Assuming that your hoc file is called mycell.hoc, these two lines of Python will do the trick:

Code: Select all

from neuron import h
h.load_file('mycell.hoc')
and Python shouldn't generate any messages about ca3fin.hoc.

Re: BioPhysical properties of imported morphology in Python

Posted: Fri Mar 08, 2019 2:15 am
by sohaib786
Apologies for not specifying properly. ca3fin was the hoc file created after importing morphology & adding biophysical properties.

Also, using this it imported successfully (without .hoc extension)
h.load_file('/home/sohaib/neuron/mycell')
. The unusual part is that on the first attempt of running the code line it says
0.0
. However, again executing the same command loads the file with output
1.0
. (I am using jupyter environment in Linux)

To access various segments of the loaded cell. I referred to the Aside 5 in https://neuron.yale.edu/neuron/static/d ... nto-python .
Eg-
vrec.record(mycell(0.5)._ref_v)
, it generates an error
name 'mycell' is not defined
. How do we define mycell after loading it.

Thanks for your time.

Re: BioPhysical properties of imported morphology in Python

Posted: Sun Mar 10, 2019 11:54 pm
by ted
h.load_file('/home/sohaib/neuron/mycell')
In writing
Assuming that your hoc file is called mycell.hoc . . .
I wasn't telling you to literally try to load mycell.hoc. I was just providing an example of how to use load_file to read a hoc file, so I needed a name for a hoc file and I just made one up. If the file that contains the hoc specification of your model cell is called ca3fin.hoc, execute
h.load_file("ca3fin.hoc")
By the way, I am assuming that your current working directory is the one that contains ca3fin.hoc. If it isn't, do whatever you need to do to via jupyter make sure that it is. Your workflow will be much easier if your working directory is the one that holds your model's source code.
The unusual part is that on the first attempt of running the code line it says
Ignore that. It's not a useful clue to what you should do.
I referred to the Aside 5
Forget about mycell. I'm sorry I mentioned it. In all of these examples it is merely a metasyntactic variable or placeholder, akin to foo or bar.

Re: BioPhysical properties of imported morphology in Python

Posted: Mon Mar 11, 2019 3:49 am
by sohaib786
I wasn't telling you to literally try to load mycell.hoc. I was just providing an example of how to use load_file to read a hoc file, so I needed a name for a hoc file and I just made one up
I understood that, so I renamed my file as mycell just to maintain coherency.

Thanks anyways.

Re: BioPhysical properties of imported morphology in Python

Posted: Mon Mar 11, 2019 3:22 pm
by ted
Yes, it is important to be coherent. In the interests of which, let me now ask: what happens if you execute this two line Python program (assuming that mycell.hoc is the name of the file that contains the specification of the anatomical properties of your model cell):

from neuron import h
h.load_file("mycell.hoc")

Does it succeed, and if not, what is the error message?

Re: BioPhysical properties of imported morphology in Python

Posted: Mon Mar 11, 2019 3:40 pm
by sohaib786
This particular command generates the following error.
from neuron import h
h.load_file("/home/sohaib/neuron/mycell.hoc")
Couldn't find: /home/sohaib/neuron/mycell.hoc
near line 0
objref hoc_obj_[2]
However, running this command twice does it.
from neuron import h
h.load_file('/home/sohaib/neuron/mycell')
h.load_file('/home/sohaib/neuron/mycell')

Re: BioPhysical properties of imported morphology in Python

Posted: Mon Mar 11, 2019 6:33 pm
by ted
running this command twice does it.

Code: Select all

    from neuron import h
    h.load_file('/home/sohaib/neuron/mycell')
    h.load_file('/home/sohaib/neuron/mycell')
No it doesn't. Read the Programmer's Reference documentation of load_file and you'll understand why. (for those who are allergic to reading documentation,
load_file("foo")
tries to read foo only the first time it is executed; after that, it doesn't even try).

The error message
Couldn't find: /home/sohaib/neuron/mycell.hoc
means that /home/sohaib/neuron/mycell.hoc doesn't exist.

Suggest you do the following:
1. cd to a working directory of your choice.
2. In that directory create a file called hello.hoc that contains this statement:
print "hello"
3. In that same directory create a file called test.py that contains these statements:
from neuron import h
h.load_file("hello.hoc")
4. In that directory execute
python test.py
and tell me what output is printed to the terminal.

Re: BioPhysical properties of imported morphology in Python

Posted: Tue Mar 12, 2019 2:29 am
by sohaib786
No it doesn't.
It does seem to load the hoc file. I accessed details like h.soma.Ra which it reported the value I had put in earlier. I also ran a simulation placing an I clamp at a different dendritic positions and it generated spike perfectly.
Read the Programmer's Reference documentation of load_file and you'll understand why
Thanks for pointing out. I have been a bit lousy about that.
Suggest you do the following:
It printed hello every time the command is run.

Code: Select all

python test.py

Re: BioPhysical properties of imported morphology in Python

Posted: Tue Mar 12, 2019 10:57 am
by ted
No it doesn't.
It does seem to load the hoc file. I accessed details like h.soma.Ra which it reported the value I had put in earlier.
Exit python. In a directory that contains only two files--mycell.hoc, which contains statements that create sections, and a file called test.py, which contains these statements

Code: Select all

from neuron import h
h.load_file('/home/sohaib/neuron/mycell')
h.load_file('/home/sohaib/neuron/mycell')
--execute
python test.py

You should get an error message that says "Couldn't find: mycell"

Now at the >>> prompt, execute
h('forall print secname()')

You won't see any section names.