def _generate_neuron_files_from_neuroml(network, verbose=False, dir_for_mod_files = None):
print_v("<STR_LIT>" % (network.id, dir_for_mod_files))<EOL>nml_src_files = []<EOL>from neuroml import NeuroMLDocument<EOL>import neuroml.writers as writers<EOL>temp_nml_doc = NeuroMLDocument(id="<STR_LIT>")<EOL>dirs_for_mod_files = []<EOL>if dir_for_mod_files!=None:<EOL><INDENT>dirs_for_mod_files.append(os.path.abspath(dir_for_mod_files))<EOL><DEDENT>for c in network.cells:<EOL><INDENT>if c.neuroml2_source_file:<EOL><INDENT>nml_src_files.append(c.neuroml2_source_file)<EOL>dir_for_mod = os.path.dirname(os.path.abspath(c.neuroml2_source_file))<EOL>if not dir_for_mod in dirs_for_mod_files: dirs_for_mod_files.append(dir_for_mod)<EOL><DEDENT><DEDENT>for s in network.synapses:<EOL><INDENT>if s.neuroml2_source_file:<EOL><INDENT>nml_src_files.append(s.neuroml2_source_file)<EOL>dir_for_mod = os.path.dirname(os.path.abspath(s.neuroml2_source_file))<EOL>if not dir_for_mod in dirs_for_mod_files: dirs_for_mod_files.append(dir_for_mod)<EOL><DEDENT><DEDENT>for i in network.input_sources:<EOL><INDENT>if i.neuroml2_source_file:<EOL><INDENT>nml_src_files.append(i.neuroml2_source_file)<EOL>dir_for_mod = os.path.dirname(os.path.abspath(i.neuroml2_source_file))<EOL>if not dir_for_mod in dirs_for_mod_files: dirs_for_mod_files.append(dir_for_mod)<EOL><DEDENT><DEDENT>temp_nml_doc = _extract_pynn_components_to_neuroml(network)<EOL>summary = temp_nml_doc.summary()<EOL>if '<STR_LIT>' in summary: <EOL><INDENT>import tempfile<EOL>temp_nml_file = tempfile.NamedTemporaryFile(delete=False, suffix='<STR_LIT>', dir=dir_for_mod_files)<EOL>print_v("<STR_LIT>"%temp_nml_file.name)<EOL>print_v(summary)<EOL>writers.NeuroMLWriter.write(temp_nml_doc, temp_nml_file.name)<EOL>nml_src_files.append(temp_nml_file.name)<EOL><DEDENT>for f in nml_src_files:<EOL><INDENT>from pyneuroml import pynml<EOL>print_v("<STR_LIT>"%f)<EOL>pynml.run_lems_with_jneuroml_neuron(f, <EOL>nogui=True, <EOL>only_generate_scripts=True,<EOL>compile_mods=True,<EOL>verbose=False)<EOL><DEDENT>for dir_for_mod_files in dirs_for_mod_files:<EOL><INDENT>if not dir_for_mod_files in locations_mods_loaded_from:<EOL><INDENT>print_v("<STR_LIT>" % (dir_for_mod_files,os.getcwd(),locations_mods_loaded_from))<EOL>try:<EOL><INDENT>from neuron import load_mechanisms<EOL>if os.getcwd()==dir_for_mod_files:<EOL><INDENT>print_v("<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>load_mechanisms(dir_for_mod_files)<EOL><DEDENT>locations_mods_loaded_from.append(dir_for_mod_files)<EOL><DEDENT>except:<EOL><INDENT>print_v("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>print_v("<STR_LIT>" % (dir_for_mod_files,locations_mods_loaded_from))<EOL><DEDENT><DEDENT>
Generate NEURON hoc/mod files from the NeuroML files which are marked as 
included in the NeuroMLlite description; also compiles the mod files