def process_celldir(inputs): """Process cell directory""" count, cell_dir, nml2_cell_dir, total_count = inputs local_nml2_cell_dir = os.path.join("..", nml2_cell_dir) print( '\n\n************************************************************\n\n' 'Parsing %s (cell %i/%i)\n' % (cell_dir, count, total_count)) if os.path.isdir(cell_dir): old_cwd = os.getcwd() os.chdir(cell_dir) else: old_cwd = os.getcwd() os.chdir('../' + cell_dir) if make_zips: nml2_cell_dir = '%s/%s' % (zips_dir, cell_dir) if not os.path.isdir(nml2_cell_dir): os.mkdir(nml2_cell_dir) print("Generating into %s" % nml2_cell_dir) bbp_ref = None template_file = open('template.hoc', 'r') for line in template_file: if line.startswith('begintemplate '): bbp_ref = line.split(' ')[1].strip() print( ' > Assuming cell in directory %s is in a template named %s' % (cell_dir, bbp_ref)) load_cell_file = 'loadcell.hoc' variables = {} variables['cell'] = bbp_ref variables['groups_info_file'] = groups_info_file template = """ /////////////////////////////////////////////////////////////////////////////// // // NOTE: This file is not part of the original BBP cell model distribution // It has been generated by ../ParseAll.py to facilitate loading of the cell // into NEURON for exporting the model morphology to NeuroML2 // ////////////////////////////////////////////////////////////////////////////// load_file("stdrun.hoc") objref cvode cvode = new CVode() cvode.active(1) //======================== settings =================================== v_init = -80 hyp_amp = -0.062866 step_amp = 0.3112968 tstop = 3000 //=================== creating cell object =========================== load_file("import3d.hoc") objref cell // Using 1 to force loading of the file, in case file with same name was loaded // before... load_file(1, "constants.hoc") load_file(1, "morphology.hoc") load_file(1, "biophysics.hoc") print "Loaded morphology and biophysics..." load_file(1, "synapses/synapses.hoc") load_file(1, "template.hoc") print "Loaded template..." load_file(1, "createsimulation.hoc") create_cell(0) print "Created new cell using loadcell.hoc: {{ cell }}" define_shape() wopen("{{ groups_info_file }}") fprint("//Saving information on groups in this cell...\\n") fprint("- somatic\\n") forsec {{ cell }}[0].somatic { fprint("%s\\n",secname()) } fprint("- basal\\n") forsec {{ cell }}[0].basal { fprint("%s\\n",secname()) } fprint("- axonal\\n") forsec {{ cell }}[0].axonal { fprint("%s\\n",secname()) } fprint("- apical\\n") forsec {{ cell }}[0].apical { fprint("%s\\n",secname()) } wopen() """ t = Template(template) contents = t.render(variables) load_cell = open(load_cell_file, 'w') load_cell.write(contents) load_cell.close() print(' > Written %s' % load_cell_file) if os.path.isfile(load_cell_file): cell_info = parse_cell_info_file(cell_dir) nml_file_name = "%s.net.nml" % bbp_ref nml_net_loc = "%s/%s" % (local_nml2_cell_dir, nml_file_name) nml_cell_file = "%s_0_0.cell.nml" % bbp_ref nml_cell_loc = "%s/%s" % (local_nml2_cell_dir, nml_cell_file) print(' > Loading %s and exporting to %s' % (load_cell_file, nml_net_loc)) export_to_neuroml2(load_cell_file, nml_net_loc, separateCellFiles=True, includeBiophysicalProperties=False) print(' > Exported to: %s and %s using %s' % (nml_net_loc, nml_cell_loc, load_cell_file)) nml_doc = pynml.read_neuroml2_file(nml_cell_loc) cell = nml_doc.cells[0] print(' > Adding groups from: %s' % groups_info_file) groups = {} current_group = None for line in open(groups_info_file): if not line.startswith('//'): if line.startswith('- '): current_group = line[2:-1] print(' > Adding group: [%s]' % current_group) groups[current_group] = [] else: section = line.split('.')[1].strip() segment_group = section.replace('[', '_').replace(']', '') groups[current_group].append(segment_group) for g in groups.keys(): new_seg_group = neuroml.SegmentGroup(id=g) cell.morphology.segment_groups.append(new_seg_group) for sg in groups[g]: new_seg_group.includes.append(neuroml.Include(sg)) if g in ['basal', 'apical']: new_seg_group.inhomogeneous_parameters.append( neuroml.InhomogeneousParameter( id="PathLengthOver_" + g, variable="p", metric="Path Length from root", proximal=neuroml.ProximalDetails( translation_start="0"))) ignore_chans = [ 'Ih', 'Ca_HVA', 'Ca_LVAst', 'Ca', "SKv3_1", "SK_E2", "CaDynamics_E2", "Nap_Et2", "Im", "K_Tst", "NaTa_t", "K_Pst", "NaTs2_t" ] # ignore_chans=['StochKv','StochKv_deterministic'] ignore_chans = [] bp, incl_chans = get_biophysical_properties( cell_info['e-type'], ignore_chans=ignore_chans, templates_json="../templates.json") cell.biophysical_properties = bp print("Set biophysical properties") notes = '' notes += \ "\n\nExport of a cell model obtained from the BBP Neocortical" \ "Microcircuit Collaboration Portal into NeuroML2" \ "\n\n******************************************************\n*" \ " This export to NeuroML2 has not yet been fully validated!!" \ "\n* Use with caution!!\n***********************************" \ "*******************\n\n" if len(ignore_chans) > 0: notes += "Ignored channels = %s\n\n" % ignore_chans notes += "For more information on this cell model see: " \ "https://bbp.epfl.ch/nmc-portal/microcircuit#/metype/%s/" \ "details\n\n" % cell_info['me-type'] cell.notes = notes for channel in incl_chans: nml_doc.includes.append(neuroml.IncludeType(href="%s" % channel)) if make_zips: print("Copying %s to zip folder" % channel) shutil.copyfile('../../NeuroML2/%s' % channel, '%s/%s' % (local_nml2_cell_dir, channel)) pynml.write_neuroml2_file(nml_doc, nml_cell_loc) stim_ref = 'stepcurrent3' stim_ref_hyp = '%s_hyp' % stim_ref stim_sim_duration = 3000 stim_hyp_amp, stim_amp = get_stimulus_amplitudes(bbp_ref) stim_del = '700ms' stim_dur = '2000ms' new_net_loc = "%s/%s.%s.net.nml" % (local_nml2_cell_dir, bbp_ref, stim_ref) new_net_doc = pynml.read_neuroml2_file(nml_net_loc) new_net_doc.notes = notes stim_hyp = neuroml.PulseGenerator(id=stim_ref_hyp, delay="0ms", duration="%sms" % stim_sim_duration, amplitude=stim_hyp_amp) new_net_doc.pulse_generators.append(stim_hyp) stim = neuroml.PulseGenerator(id=stim_ref, delay=stim_del, duration=stim_dur, amplitude=stim_amp) new_net_doc.pulse_generators.append(stim) new_net = new_net_doc.networks[0] pop_id = new_net.populations[0].id pop_comp = new_net.populations[0].component input_list = neuroml.InputList(id="%s_input" % stim_ref_hyp, component=stim_ref_hyp, populations=pop_id) syn_input = neuroml.Input(id=0, target="../%s/0/%s" % (pop_id, pop_comp), destination="synapses") input_list.input.append(syn_input) new_net.input_lists.append(input_list) input_list = neuroml.InputList(id="%s_input" % stim_ref, component=stim_ref, populations=pop_id) syn_input = neuroml.Input(id=0, target="../%s/0/%s" % (pop_id, pop_comp), destination="synapses") input_list.input.append(syn_input) new_net.input_lists.append(input_list) pynml.write_neuroml2_file(new_net_doc, new_net_loc) generate_lems_file_for_neuroml(cell_dir, new_net_loc, "network", stim_sim_duration, 0.025, "LEMS_%s.xml" % cell_dir, local_nml2_cell_dir, copy_neuroml=False, seed=1234) pynml.nml2_to_svg(nml_net_loc) clear_neuron() pop = neuroml.Population(id="Pop_%s" % bbp_ref, component=bbp_ref + '_0_0', type="populationList") inst = neuroml.Instance(id="0") pop.instances.append(inst) width = 6 X = count % width Z = (count - X) / width inst.location = neuroml.Location(x=300 * X, y=0, z=300 * Z) count += 1 if make_zips: zip_file = "%s/%s.zip" % (zips_dir, cell_dir) print("Creating zip file: %s" % zip_file) with zipfile.ZipFile(zip_file, 'w') as myzip: for next_file in os.listdir(local_nml2_cell_dir): next_file = '%s/%s' % (local_nml2_cell_dir, next_file) arcname = next_file[len(zips_dir):] print("Adding : %s as %s" % (next_file, arcname)) myzip.write(next_file, arcname) os.chdir(old_cwd) return nml_cell_file, pop
def process_celldir(inputs): """Process cell directory""" count, cell_dir, nml2_cell_dir, total_count = inputs local_nml2_cell_dir = os.path.join("..", nml2_cell_dir) print( "\n\n************************************************************\n\n" "Parsing %s (cell %i/%i)\n" % (cell_dir, count, total_count) ) if os.path.isdir(cell_dir): old_cwd = os.getcwd() os.chdir(cell_dir) else: old_cwd = os.getcwd() os.chdir("../" + cell_dir) if make_zips: nml2_cell_dir = "%s/%s" % (zips_dir, cell_dir) if not os.path.isdir(nml2_cell_dir): os.mkdir(nml2_cell_dir) print("Generating into %s" % nml2_cell_dir) bbp_ref = None template_file = open("template.hoc", "r") for line in template_file: if line.startswith("begintemplate "): bbp_ref = line.split(" ")[1].strip() print(" > Assuming cell in directory %s is in a template named %s" % (cell_dir, bbp_ref)) load_cell_file = "loadcell.hoc" variables = {} variables["cell"] = bbp_ref variables["groups_info_file"] = groups_info_file template = """ /////////////////////////////////////////////////////////////////////////////// // // NOTE: This file is not part of the original BBP cell model distribution // It has been generated by ../ParseAll.py to facilitate loading of the cell // into NEURON for exporting the model morphology to NeuroML2 // ////////////////////////////////////////////////////////////////////////////// load_file("stdrun.hoc") objref cvode cvode = new CVode() cvode.active(1) //======================== settings =================================== v_init = -80 hyp_amp = -0.062866 step_amp = 0.3112968 tstop = 3000 //=================== creating cell object =========================== load_file("import3d.hoc") objref cell // Using 1 to force loading of the file, in case file with same name was loaded // before... load_file(1, "constants.hoc") load_file(1, "morphology.hoc") load_file(1, "biophysics.hoc") print "Loaded morphology and biophysics..." load_file(1, "synapses/synapses.hoc") load_file(1, "template.hoc") print "Loaded template..." load_file(1, "createsimulation.hoc") create_cell(0) print "Created new cell using loadcell.hoc: {{ cell }}" define_shape() wopen("{{ groups_info_file }}") fprint("//Saving information on groups in this cell...\\n") fprint("- somatic\\n") forsec {{ cell }}[0].somatic { fprint("%s\\n",secname()) } fprint("- basal\\n") forsec {{ cell }}[0].basal { fprint("%s\\n",secname()) } fprint("- axonal\\n") forsec {{ cell }}[0].axonal { fprint("%s\\n",secname()) } fprint("- apical\\n") forsec {{ cell }}[0].apical { fprint("%s\\n",secname()) } wopen() """ t = Template(template) contents = t.render(variables) load_cell = open(load_cell_file, "w") load_cell.write(contents) load_cell.close() print(" > Written %s" % load_cell_file) if os.path.isfile(load_cell_file): cell_info = parse_cell_info_file(cell_dir) nml_file_name = "%s.net.nml" % bbp_ref nml_net_loc = "%s/%s" % (local_nml2_cell_dir, nml_file_name) nml_cell_file = "%s_0_0.cell.nml" % bbp_ref nml_cell_loc = "%s/%s" % (local_nml2_cell_dir, nml_cell_file) print(" > Loading %s and exporting to %s" % (load_cell_file, nml_net_loc)) export_to_neuroml2(load_cell_file, nml_net_loc, separateCellFiles=True, includeBiophysicalProperties=False) print(" > Exported to: %s and %s using %s" % (nml_net_loc, nml_cell_loc, load_cell_file)) nml_doc = pynml.read_neuroml2_file(nml_cell_loc) cell = nml_doc.cells[0] print(" > Adding groups from: %s" % groups_info_file) groups = {} current_group = None for line in open(groups_info_file): if not line.startswith("//"): if line.startswith("- "): current_group = line[2:-1] print(" > Adding group: [%s]" % current_group) groups[current_group] = [] else: section = line.split(".")[1].strip() segment_group = section.replace("[", "_").replace("]", "") groups[current_group].append(segment_group) for g in groups.keys(): new_seg_group = neuroml.SegmentGroup(id=g) cell.morphology.segment_groups.append(new_seg_group) for sg in groups[g]: new_seg_group.includes.append(neuroml.Include(sg)) if g in ["basal", "apical"]: new_seg_group.inhomogeneous_parameters.append( neuroml.InhomogeneousParameter( id="PathLengthOver_" + g, variable="p", metric="Path Length from root", proximal=neuroml.ProximalDetails(translation_start="0"), ) ) ignore_chans = [ "Ih", "Ca_HVA", "Ca_LVAst", "Ca", "SKv3_1", "SK_E2", "CaDynamics_E2", "Nap_Et2", "Im", "K_Tst", "NaTa_t", "K_Pst", "NaTs2_t", ] # ignore_chans=['StochKv','StochKv_deterministic'] ignore_chans = [] bp, incl_chans = get_biophysical_properties( cell_info["e-type"], ignore_chans=ignore_chans, templates_json="../templates.json" ) cell.biophysical_properties = bp print("Set biophysical properties") notes = "" notes += ( "\n\nExport of a cell model obtained from the BBP Neocortical" "Microcircuit Collaboration Portal into NeuroML2" "\n\n******************************************************\n*" " This export to NeuroML2 has not yet been fully validated!!" "\n* Use with caution!!\n***********************************" "*******************\n\n" ) if len(ignore_chans) > 0: notes += "Ignored channels = %s\n\n" % ignore_chans notes += ( "For more information on this cell model see: " "https://bbp.epfl.ch/nmc-portal/microcircuit#/metype/%s/" "details\n\n" % cell_info["me-type"] ) cell.notes = notes for channel in incl_chans: nml_doc.includes.append(neuroml.IncludeType(href="%s" % channel)) if make_zips: print("Copying %s to zip folder" % channel) shutil.copyfile("../../NeuroML2/%s" % channel, "%s/%s" % (local_nml2_cell_dir, channel)) pynml.write_neuroml2_file(nml_doc, nml_cell_loc) stim_ref = "stepcurrent3" stim_ref_hyp = "%s_hyp" % stim_ref stim_sim_duration = 3000 stim_hyp_amp, stim_amp = get_stimulus_amplitudes(bbp_ref) stim_del = "700ms" stim_dur = "2000ms" new_net_loc = "%s/%s.%s.net.nml" % (local_nml2_cell_dir, bbp_ref, stim_ref) new_net_doc = pynml.read_neuroml2_file(nml_net_loc) new_net_doc.notes = notes stim_hyp = neuroml.PulseGenerator( id=stim_ref_hyp, delay="0ms", duration="%sms" % stim_sim_duration, amplitude=stim_hyp_amp ) new_net_doc.pulse_generators.append(stim_hyp) stim = neuroml.PulseGenerator(id=stim_ref, delay=stim_del, duration=stim_dur, amplitude=stim_amp) new_net_doc.pulse_generators.append(stim) new_net = new_net_doc.networks[0] pop_id = new_net.populations[0].id pop_comp = new_net.populations[0].component input_list = neuroml.InputList(id="%s_input" % stim_ref_hyp, component=stim_ref_hyp, populations=pop_id) syn_input = neuroml.Input(id=0, target="../%s/0/%s" % (pop_id, pop_comp), destination="synapses") input_list.input.append(syn_input) new_net.input_lists.append(input_list) input_list = neuroml.InputList(id="%s_input" % stim_ref, component=stim_ref, populations=pop_id) syn_input = neuroml.Input(id=0, target="../%s/0/%s" % (pop_id, pop_comp), destination="synapses") input_list.input.append(syn_input) new_net.input_lists.append(input_list) pynml.write_neuroml2_file(new_net_doc, new_net_loc) generate_lems_file_for_neuroml( cell_dir, new_net_loc, "network", stim_sim_duration, 0.025, "LEMS_%s.xml" % cell_dir, local_nml2_cell_dir, copy_neuroml=False, seed=1234, ) pynml.nml2_to_svg(nml_net_loc) clear_neuron() pop = neuroml.Population(id="Pop_%s" % bbp_ref, component=bbp_ref + "_0_0", type="populationList") inst = neuroml.Instance(id="0") pop.instances.append(inst) width = 6 X = count % width Z = (count - X) / width inst.location = neuroml.Location(x=300 * X, y=0, z=300 * Z) count += 1 if make_zips: zip_file = "%s/%s.zip" % (zips_dir, cell_dir) print("Creating zip file: %s" % zip_file) with zipfile.ZipFile(zip_file, "w") as myzip: for next_file in os.listdir(local_nml2_cell_dir): next_file = "%s/%s" % (local_nml2_cell_dir, next_file) arcname = next_file[len(zips_dir) :] print("Adding : %s as %s" % (next_file, arcname)) myzip.write(next_file, arcname) os.chdir(old_cwd) return nml_cell_file, pop
from pyneuroml.neuron import export_to_neuroml2 export_to_neuroml2("test.hoc", "test.morphonly.cell.nml", includeBiophysicalProperties=False) export_to_neuroml2("test.hoc", "test.biophys.cell.nml", includeBiophysicalProperties=True)
from pyneuroml.neuron import export_to_neuroml2 # from pyneuroml.neuron.nrn_export_utils import clear_neuron export_to_neuroml2("../NEURON/tester.hoc", "test.cell.nml", includeBiophysicalProperties=True, known_rev_potentials={'Ih':-32.9, 'cal':0, 'cat':0, 'kca':-95, 'Ika':-95, 'IM':-95, 'Ikdrf':-95, 'Ikdrs':-95, 'passsd':-70, 'Ikdrfaxon':-95, 'Ikdrsaxon':-95, 'passaxon':-70})
def __main__(): num_cells_to_export = 1 cells = [] for mgid in range(num_cells_to_export): print mgid cells.append(mkmitral(mgid)) nml_net_file = "../NeuroML2/MitralCells/Exported/PartialBulb_%iMTCells.net.nml" % num_cells_to_export export_to_neuroml2(None, nml_net_file, includeBiophysicalProperties=False, separateCellFiles=True) for i in range(num_cells_to_export): print("Processing cell %i out of %i"%(i, num_cells_to_export)) nml_cell_file = "../NeuroML2/MitralCells/Exported/Mitral_0_%i.cell.nml" % i nml_doc = pynml.read_neuroml2_file(nml_cell_file) cell = nml_doc.cells[0] import pydevd pydevd.settrace('10.211.55.3', port=4200, stdoutToServer=True, stderrToServer=True, suspend=True) # Set root to id=0 and increment others exportHelper.resetRoot(cell) somaSeg = [seg for seg in cell.morphology.segments if seg.name == "Seg0_soma"][0] initialSeg = [seg for seg in cell.morphology.segments if seg.name == "Seg0_initialseg"][0] hillockSeg = [seg for seg in cell.morphology.segments if seg.name == "Seg0_hillock"][0] # Fix initial and hillock segs by moving them to the soma hillockSeg.proximal = pointMovedByOffset(hillockSeg.proximal, somaSeg.distal) hillockSeg.distal = pointMovedByOffset(hillockSeg.distal, somaSeg.distal) initialSeg.proximal = pointMovedByOffset(initialSeg.proximal, somaSeg.distal) initialSeg.distal = pointMovedByOffset(initialSeg.distal, somaSeg.distal) # Move everything back to the origin originOffset = type("", (), dict(x = -somaSeg.proximal.x, y = -somaSeg.proximal.y, z = -somaSeg.proximal.z ))() for seg in cell.morphology.segments: seg.proximal = pointMovedByOffset(seg.proximal, originOffset) seg.distal = pointMovedByOffset(seg.distal, originOffset) # Replace ModelViewParmSubset_N groups with all, axon, soma, dendrite groups buildStandardSegmentGroups(cell) # Add channel placeholders nml_doc.includes.append(neuroml.IncludeType(href="channelIncludesPLACEHOLDER")) cell.biophysical_properties = neuroml.BiophysicalProperties(id="biophysPLACEHOLDER") # Save the new NML pynml.write_neuroml2_file(nml_doc, nml_cell_file) # Replace placeholders with contents from MitralCell...xml files replaceChannelPlaceholders(nml_cell_file) print("COMPLETED: " + nml_cell_file) print("DONE")
from pyneuroml.neuron import export_to_neuroml2 export_to_neuroml2("test.hoc", "test.morphonly.nml", includeBiophysicalProperties=False) #export_to_neuroml2("test.hoc", "test.biophys.nml", includeBiophysicalProperties=True)
from pyneuroml.neuron import export_to_neuroml2 # from pyneuroml.neuron.nrn_export_utils import clear_neuron export_to_neuroml2("../NEURON/test/test_Poirazi2003.hoc", "poirazi.cell.nml", includeBiophysicalProperties=True, known_rev_potentials={'cal':-1, 'calH':140, 'can':140, 'car':140, 'cat':-1})
from pyneuroml.neuron import export_to_neuroml2 cells = ['axoaxonic', 'bistratified', 'cck', 'cutsuridis', 'ivy', 'ngf', 'olm', 'poolosyn', 'pvbasket', 'sca'] for cell in cells: export_to_neuroml2("%s.hoc"%cell, "cells/%s.cell.nml"%cell, includeBiophysicalProperties=True, known_rev_potentials={'ch_CavL':-1, 'ch_CavN':-1, 'ch_HCNolm':-30}) print "##### %s done #####"%cell
from pyneuroml.neuron import export_to_neuroml2 # from pyneuroml.neuron.nrn_export_utils import clear_neuron export_to_neuroml2("../NEURON/test/test_Poirazi2003.hoc", "poirazi.cell.nml", includeBiophysicalProperties=True, known_rev_potentials={ 'cal': -1, 'calH': 140, 'can': 140, 'car': 140, 'cat': -1 })
from pyneuroml.neuron import export_to_neuroml2 # from pyneuroml.neuron.nrn_export_utils import clear_neuron export_to_neuroml2("../NEURON/test_granulecell.hoc", "granule.cell.nml", includeBiophysicalProperties=True, known_rev_potentials={'ichan2':0})
from pyneuroml.neuron import export_to_neuroml2 from pyneuroml.neuron.nrn_export_utils import clear_neuron export_to_neuroml2("../NEURON/tester_Case2.hoc", "SaragaOLM_Case2.cell.nml", includeBiophysicalProperties=True, known_rev_potentials={'IA':-100, 'Ih':-32.9})
def exportToNML(cells): nml_net_file = "../NeuroML2/GranuleCells/Exported/GCnet%iG.net.nml" % len(cells) export_to_neuroml2(None, nml_net_file, includeBiophysicalProperties=False, separateCellFiles=True) # Rename files so their cell GIDs are preserved for gcid in cells.keys(): fileId = cells[gcid]['index'] oldFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml' % fileId newFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml_TEMP' % gcid # Using TEMP files to avoid naming conflicts os.rename(oldFile, newFile) # Remove temp files after all have been renamed for gcid in cells.keys(): oldFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml_TEMP' % gcid newFile = '../NeuroML2/GranuleCells/Exported/Granule_0_%i.cell.nml' % gcid os.rename(oldFile, newFile) for gcid in cells.keys(): cell, nml_doc, nml_cell_file = readGCnml(gcid) print("Loaded GC cell %i with %i segments"%(gcid, len(cell.morphology.segments))) # Change cell ID to preserve GCID cell.id = "Granule_0_%i" % gcid # Change segment ids to start at 0 and increment exportHelper.resetRoot(cell) # Replace ModelViewParmSubset_N groups with all, axon, soma, dendrite groups buildStandardSegmentGroups(cell) # Add channel placeholders nml_doc.includes.append(neuroml.IncludeType(href="channelIncludesPLACEHOLDER")) cell.biophysical_properties = neuroml.BiophysicalProperties(id="biophysPLACEHOLDER") cell.morphology.segments.append(neuroml.Segment(id="spinePLACEHOLDER")) # Save the new NML pynml.write_neuroml2_file(nml_doc, nml_cell_file) # Replace placeholders with contents from GranuleCell...xml files replaceChannelPlaceholders(nml_cell_file) cell, nml_doc, nml_cell_file = readGCnml(gcid) # Fix the fractionAlong parent segment bug ( https://github.com/NeuroML/org.neuroml.export/issues/46 ) exportHelper.splitSegmentAlongFraction(cell, "Seg0_priden", "priden", 0.8, "Seg0_priden2_0") # Orient cell along the versor versor = granules.granule_position_orientation(gcid)[1] for seg in cell.morphology.segments: segLength = seg.length if seg.parent is not None: parentDistal = [parent for parent in cell.morphology.segments if parent.id == seg.parent.segments][0].distal seg.proximal.x = parentDistal.x seg.proximal.y = parentDistal.y seg.proximal.z = parentDistal.z seg.distal = setAlongVersor(seg.distal, versor, seg.proximal, segLength) # Make sure spine is in the all group [group for group in cell.morphology.segment_groups if group.id == 'all'][0]\ .includes\ .append(neuroml.Include(segment_groups='spine_group'))\ # and Dendrite group [group for group in cell.morphology.segment_groups if group.id == 'dendrite_group'][0]\ .includes\ .append(neuroml.Include(segment_groups='spine_group')) # Save orientation pynml.write_neuroml2_file(nml_doc, nml_cell_file) print(nml_cell_file)
from pyneuroml.neuron import export_to_neuroml2 #export_to_neuroml2("load_bc6.hoc", "BC6.cell.nml", includeBiophysicalProperties=False) export_to_neuroml2("load_bc2.hoc", "BC2.cell.nml", includeBiophysicalProperties=False)
if os.path.isfile(load_cell_file): cell_info = parse_cell_info_file(cell_dir) nml_file_name = "%s.net.nml"%bbp_ref nml_net_loc = "%s/%s"%(nml2_cell_dir,nml_file_name) nml_cell_file = "%s_0_0.cell.nml"%bbp_ref nml_cell_loc = "%s/%s"%(nml2_cell_dir,nml_cell_file) print(' > Loading %s and exporting to %s'%(load_cell_file,nml_net_loc)) export_to_neuroml2(load_cell_file, nml_net_loc, separateCellFiles=True, includeBiophysicalProperties=False) print(' > Exported to: %s and %s using %s'%(nml_net_loc, nml_cell_loc, load_cell_file)) nml_doc = pynml.read_neuroml2_file(nml_cell_loc) cell = nml_doc.cells[0] print(' > Adding groups from: %s'%groups_info_file) groups = {} current_group = None for line in open(groups_info_file): if not line.startswith('//'): if line.startswith('- '): current_group = line[2:-1]
from pyneuroml.neuron import export_to_neuroml2 export_to_neuroml2("091008A2.hoc", "../NeuroML2/dLGN.cell.nml", includeBiophysicalProperties=False) #export_to_neuroml2("test.hoc", "test.biophys.nml", includeBiophysicalProperties=True)
h.finitialize() h.psection() nml_file_name = "%s.net.nml"%model_id nml_net_loc = "%s/%s"%(nml2_cell_dir,nml_file_name) nml_cell_file0 = "Cell0.cell.nml" nml_cell_loc0 = "%s/%s"%(nml2_cell_dir,nml_cell_file0) nml_cell_file = "Cell_%s.cell.nml"%model_id nml_cell_loc = "%s/%s"%(nml2_cell_dir,nml_cell_file) print(' > Exporting to %s'%(nml_net_loc)) export_to_neuroml2(None, nml_net_loc, separateCellFiles=True, includeBiophysicalProperties=False) print(' > Exported to: %s and %s'%(nml_net_loc, nml_cell_loc)) clear_neuron() nml_doc = pynml.read_neuroml2_file(nml_cell_loc0) cell = nml_doc.cells[0] cell.id = 'Cell_%s'%model_id notes = '' notes+="\n\nExport of a cell model (%s) obtained from the Allen Institute Cell Types Database into NeuroML2"%model_id + \
def export(num_cells_to_export=5): cells = [] for mgid in range(num_cells_to_export): print mgid cells.append(mkmitral(mgid)) nml_net_file = "../NeuroML2/MitralCells/Exported/PartialBulb_%iMTCells.net.nml" % num_cells_to_export export_to_neuroml2(None, nml_net_file, includeBiophysicalProperties=False, separateCellFiles=True) for i in range(num_cells_to_export): print("Processing cell %i out of %i" % (i, num_cells_to_export)) nml_cell_file = "../NeuroML2/MitralCells/Exported/Mitral_0_%i.cell.nml" % i nml_doc = pynml.read_neuroml2_file(nml_cell_file) cell = nml_doc.cells[0] soma_seg = next(seg for seg in cell.morphology.segments if seg.name == "Seg0_soma") initial_seg = next(seg for seg in cell.morphology.segments if seg.name == "Seg0_initialseg") hillock_seg = next(seg for seg in cell.morphology.segments if seg.name == "Seg0_hillock") # Ensure hillock parent is soma hillock_seg.parent.segments = soma_seg.id # Fix initial and hillock segs by moving them to the soma hillock_seg.proximal = pointMovedByOffset(hillock_seg.proximal, soma_seg.distal) hillock_seg.distal = pointMovedByOffset(hillock_seg.distal, soma_seg.distal) initial_seg.proximal = pointMovedByOffset(initial_seg.proximal, soma_seg.distal) initial_seg.distal = pointMovedByOffset(initial_seg.distal, soma_seg.distal) # Set root to id=0 and increment others exportHelper.resetRoot(cell) # TODO: cell.position(x,y,z) used for cell positioning in networks does not work as expected # See: https://github.com/NeuroML/jNeuroML/issues/55 # Skipping the translation for now # # Move everything back to the origin # originOffset = type("", (), dict(x = -soma_seg.proximal.x, y = -soma_seg.proximal.y, z = -soma_seg.proximal.z ))() # # for seg in cell.morphology.segments: # seg.proximal = pointMovedByOffset(seg.proximal, originOffset) # seg.distal = pointMovedByOffset(seg.distal, originOffset) # Replace ModelViewParmSubset_N groups with all, axon, soma, dendrite groups buildStandardSegmentGroups(cell) # Add channel placeholders nml_doc.includes.append( neuroml.IncludeType(href="channelIncludesPLACEHOLDER")) cell.biophysical_properties = neuroml.BiophysicalProperties( id="biophysPLACEHOLDER") # Save the new NML pynml.write_neuroml2_file(nml_doc, nml_cell_file) # Replace placeholders with contents from MitralCell...xml files replaceChannelPlaceholders(nml_cell_file) print("COMPLETED: " + nml_cell_file) print("DONE")
from pyneuroml.neuron import export_to_neuroml2 import sys import os os.chdir("../NEURON/test") sys.path.append(".") export_to_neuroml2("load_model2.hoc", "../../NeuroML2/L5_model2.cell.nml", includeBiophysicalProperties=False, known_rev_potentials={ "na": 60, "k": -90, "ca": 140 })
from pyneuroml.neuron import export_to_neuroml2 from pyneuroml.neuron.nrn_export_utils import clear_neuron export_to_neuroml2("../NEURON/initFig9BCase2", "OLM_Fig9BCase2_morph.cell.nml", includeBiophysicalProperties=False) ''' clear_neuron() os.chdir('../NeuroML2') export_to_neuroml2("create_cell.hoc", "../NeuroML2/OLM_Fig9BCase2.cell.nml", includeBiophysicalProperties=True) '''