<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate_lems_file(self, nml_file_name, nml_doc):
 """ Generate a LEMS file to use in simulations of the NeuroML file """

        
        #pp.pprint(self.simulation_config)
        #pp.pprint(self.pop_comp_info)
        #pp.pprint(self.node_set_mappings)
        
        if 'output' in self.simulation_config:
            gen_spike_saves_for_all_somas = True
        
        target = nml_doc.networks[0].id
        sim_id = 'Sim_%s'%target
        
        duration = self.simulation_config['run']['tstop']
        dt = self.simulation_config['run']['dt']
        lems_file_name = 'LEMS_%s.xml'%sim_id
        target_dir = "./"
        gen_saves_for_quantities = {}
        gen_plots_for_quantities = {}
        
        if 'reports' in self.simulation_config:
            if 'membrane_potential' in self.simulation_config['reports']:
                mp = self.simulation_config['reports']['membrane_potential']
                node_set = self.node_set_mappings[mp['cells']]
                for nml_pop in node_set:
                    comp = self.nml_pop_vs_comps[nml_pop]
                    ids = node_set[nml_pop]
                    display = 'Voltages_%s'%nml_pop
                    file_name = '%s.v.dat'%nml_pop
                    
                    for id in ids:
                        quantity = '%s/%i/%s/%s'%(nml_pop,id,comp,'v')
                        if not nml_pop in self.nml_pops_having_locations:
                            quantity = '%s[%i]/%s'%(nml_pop,id,'v')
                            
                        if not display in gen_plots_for_quantities:
                            gen_plots_for_quantities[display] = []
                        gen_plots_for_quantities[display].append(quantity)
                        if not file_name in gen_saves_for_quantities:
                            gen_saves_for_quantities[file_name] = []
                        gen_saves_for_quantities[file_name].append(quantity)
                

        generate_lems_file_for_neuroml(sim_id, 
                                       nml_file_name, 
                                       target, 
                                       duration, 
                                       dt, 
                                       lems_file_name,
                                       target_dir,
                                       include_extra_files = self.nml_includes,
                                       gen_plots_for_all_v = False,
                                       plot_all_segments = False,
                                       gen_plots_for_quantities = gen_plots_for_quantities,   #  Dict with displays vs lists of quantity paths
                                       gen_saves_for_all_v = False,
                                       save_all_segments = False,
                                       gen_saves_for_quantities = gen_saves_for_quantities,  #  List of populations, all pops if = []
                                       gen_spike_saves_for_all_somas = gen_spike_saves_for_all_somas,
                                       report_file_name = REPORT_FILE,
                                       copy_neuroml = True,
                                       verbose=True)
                                       
        return lems_file_name