def get_neuroml_from_sonata(sonata_filename, id, generate_lems = True, format='<STR_LIT>'):
from neuroml.hdf5.NetworkBuilder import NetworkBuilder<EOL>neuroml_handler = NetworkBuilder()<EOL>sr = SonataReader(filename=sonata_filename, id=id)<EOL>sr.parse(neuroml_handler)  <EOL>nml_doc = neuroml_handler.get_nml_doc()<EOL>sr.add_neuroml_components(nml_doc)<EOL>if format == '<STR_LIT>':<EOL><INDENT>nml_file_name = '<STR_LIT>'%id<EOL>from neuroml.writers import NeuroMLWriter<EOL>NeuroMLWriter.write(nml_doc, nml_file_name)<EOL><DEDENT>elif format == '<STR_LIT>':<EOL><INDENT>nml_file_name = '<STR_LIT>'%id<EOL>from neuroml.writers import NeuroMLHdf5Writer<EOL>NeuroMLHdf5Writer.write(nml_doc, nml_file_name)<EOL><DEDENT>print_v('<STR_LIT>'%nml_file_name)  <EOL>if generate_lems:<EOL><INDENT>lems_file_name = sr.generate_lems_file(nml_file_name, nml_doc)<EOL>return sr, lems_file_name, nml_file_name, nml_doc<EOL><DEDENT>return nml_doc<EOL>
Return a NeuroMLDocument with (most of) the contents of the Sonata model