def _extract_pynn_components_to_neuroml(nl_model, nml_doc=None):
if nml_doc == None:<EOL><INDENT>from neuroml import NeuroMLDocument<EOL>nml_doc = NeuroMLDocument(id="<STR_LIT>")<EOL><DEDENT>for c in nl_model.cells:<EOL><INDENT>if c.pynn_cell:<EOL><INDENT>if nml_doc.get_by_id(c.id) == None:<EOL><INDENT>import pyNN.neuroml<EOL>cell_params = c.parameters if c.parameters else {}<EOL>for p in cell_params:<EOL><INDENT>cell_params[p] = evaluate(cell_params[p], nl_model.parameters)<EOL><DEDENT>for proj in nl_model.projections:<EOL><INDENT>synapse = nl_model.get_child(proj.synapse, '<STR_LIT>')<EOL>post_pop = nl_model.get_child(proj.postsynaptic, '<STR_LIT>')<EOL>if post_pop.component == c.id:<EOL><INDENT>if synapse.pynn_receptor_type == '<STR_LIT>':<EOL><INDENT>post = '<STR_LIT>'<EOL><DEDENT>elif synapse.pynn_receptor_type == '<STR_LIT>':<EOL><INDENT>post = '<STR_LIT>'<EOL><DEDENT>for p in synapse.parameters:<EOL><INDENT>cell_params['<STR_LIT>' % (p, post)] = synapse.parameters[p]<EOL><DEDENT><DEDENT><DEDENT>temp_cell = eval('<STR_LIT>' % c.pynn_cell)<EOL>if c.pynn_cell != '<STR_LIT>':<EOL><INDENT>temp_cell.default_initial_values['<STR_LIT:v>'] = temp_cell.parameter_space['<STR_LIT>'].base_value<EOL><DEDENT>cell_id = temp_cell.add_to_nml_doc(nml_doc, None)<EOL>cell = nml_doc.get_by_id(cell_id)<EOL>cell.id = c.id<EOL><DEDENT><DEDENT><DEDENT>for s in nl_model.synapses:<EOL><INDENT>if nml_doc.get_by_id(s.id) == None:<EOL><INDENT>if s.pynn_synapse_type and s.pynn_receptor_type:<EOL><INDENT>import neuroml<EOL>if s.pynn_synapse_type == '<STR_LIT>':<EOL><INDENT>syn = neuroml.ExpCondSynapse(id=s.id, tau_syn=s.parameters['<STR_LIT>'], e_rev=s.parameters['<STR_LIT>'])<EOL>nml_doc.exp_cond_synapses.append(syn)<EOL><DEDENT>elif s.pynn_synapse_type == '<STR_LIT>':<EOL><INDENT>syn = neuroml.AlphaCondSynapse(id=s.id, tau_syn=s.parameters['<STR_LIT>'], e_rev=s.parameters['<STR_LIT>'])<EOL>nml_doc.alpha_cond_synapses.append(syn)<EOL><DEDENT>elif s.pynn_synapse_type == '<STR_LIT>':<EOL><INDENT>syn = neuroml.ExpCurrSynapse(id=s.id, tau_syn=s.parameters['<STR_LIT>'])<EOL>nml_doc.exp_curr_synapses.append(syn)<EOL><DEDENT>elif s.pynn_synapse_type == '<STR_LIT>':<EOL><INDENT>syn = neuroml.AlphaCurrSynapse(id=s.id, tau_syn=s.parameters['<STR_LIT>'])<EOL>nml_doc.alpha_curr_synapses.append(syn)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>for i in nl_model.input_sources:<EOL><INDENT>if i.pynn_input:<EOL><INDENT>import pyNN.neuroml<EOL>input_params = i.parameters if i.parameters else {}<EOL>exec('<STR_LIT>' % (i.id, i.pynn_input))<EOL>exec('<STR_LIT>' % i.id)<EOL>pg_id = temp_input.add_to_nml_doc(nml_doc, None)<EOL>pg = nml_doc.get_by_id(pg_id)<EOL>pg.id = i.id<EOL><DEDENT><DEDENT>return nml_doc<EOL>
Parse the NeuroMLlite description for cell, synapses and inputs described as 
PyNN elements (e.g. IF_cond_alpha, DCSource) and parameters, and convert 
these to the equivalent elements in a NeuroMLDocument