"""
How to load morphologies of certain cells from the database.
"""
#this is an expected failure right now, as morphology is not implemented
from __future__ import absolute_import
from __future__ import print_function
import PyOpenWorm as P
from PyOpenWorm.context import Context
from PyOpenWorm.worm import Worm

from six import StringIO

#Connect to database.
with P.connect('default.conf') as conn:
    ctx = Context(ident="http://openworm.org/data", conf=conn.conf).stored

    #Create a new Cell object to work with.
    aval = ctx(Worm)().get_neuron_network().aneuron('AVAL')

    #Get the morphology associated with the Cell. Returns a neuroml.Morphology object.
    morph = aval._morphology()
    out = StringIO()
    morph.export(out, 0) # we're printing it here, but we would normally do something else with the morphology object.
    print(str(out.read()))

[((14, 5, 14, 30), 'PyOpenWorm.connect', 'P.connect', ({(14, 15, 14, 29): '"""default.conf"""'}, {}), "('default.conf')", True, 'import PyOpenWorm as P\n'), ((22, 10, 22, 20), 'six.StringIO', 'StringIO', ({}, {}), '()', False, 'from six import StringIO\n'), ((15, 10, 15, 67), 'PyOpenWorm.context.Context', 'Context', (), '', False, 'from PyOpenWorm.context import Context\n')]