docs: def get_neuroml_from_sonata(sonata_filename, id, generate_lems = True, format='xml'):
      """
      Return a NeuroMLDocument with (most of) the contents of the Sonata model 
      """
      
      from neuroml.hdf5.NetworkBuilder import NetworkBuilder
      neuroml_handler = NetworkBuilder()
      
      sr = SonataReader(filename=sonata_filename, id=id)
                        
      sr.parse(neuroml_handler)  
      
      nml_doc = neuroml_handler.get_nml_doc()
      
      sr.add_neuroml_components(nml_doc)
      
      if format == 'xml':
          nml_file_name = '%s.net.nml'%id
          from neuroml.writers import NeuroMLWriter
          NeuroMLWriter.write(nml_doc, nml_file_name)
          
      elif format == 'hdf5':
          nml_file_name = '%s.net.nml.h5'%id
          from neuroml.writers import NeuroMLHdf5Writer
          NeuroMLHdf5Writer.write(nml_doc, nml_file_name)
      
      print_v('Written to: %s'%nml_file_name)  
      
      if generate_lems:
          lems_file_name = sr.generate_lems_file(nml_file_name, nml_doc)
          
          return sr, lems_file_name, nml_file_name, nml_doc
      
      return nml_doc