#!/usr/bin/env python3 """ Convert cell morphology to NeuroML. We only export morphologies here. We add the biophysics manually. File: NeuroML2/scripts/cell2nml.py Copyright 2022 Ankur Sinha Author: Ankur Sinha """ import os import sys import pyneuroml from pyneuroml.neuron import export_to_neuroml2 from neuron import h def main(acell): """Main runner method. :param acell: name of cell :returns: None """ loader_hoc_file = f"{acell}_loader.hoc" loader_hoc_file_txt = f""" /*load_file("nrngui.hoc")*/ load_file("stdrun.hoc") //=================== creating cell object =========================== load_file("import3d.hoc") objref newcell strdef morphology_file morphology_file = "../L23Net/morphologies/{acell}.swc" load_file("../L23Net/models/NeuronTemplate.hoc") newcell = new NeuronTemplate(morphology_file) define_shape() """ with open(loader_hoc_file, 'w') as f: print(loader_hoc_file_txt, file=f) export_to_neuroml2(loader_hoc_file, f"{acell}.morph.cell.nml", includeBiophysicalProperties=False, validate=False) os.remove(loader_hoc_file) if __name__ == "__main__": if len(sys.argv) != 2: print("This script only accepts one argument.") sys.exit(1) main(sys.argv[1])