cellmorph2nml.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python3
  2. """
  3. Convert cell morphology to NeuroML.
  4. We only export morphologies here. We add the biophysics manually.
  5. File: NeuroML2/scripts/cell2nml.py
  6. Copyright 2022 Ankur Sinha
  7. Author: Ankur Sinha <sanjay DOT ankur AT gmail DOT com>
  8. """
  9. import os
  10. import sys
  11. import pyneuroml
  12. from pyneuroml.neuron import export_to_neuroml2
  13. from neuron import h
  14. def main(acell):
  15. """Main runner method.
  16. :param acell: name of cell
  17. :returns: None
  18. """
  19. loader_hoc_file = f"{acell}_loader.hoc"
  20. loader_hoc_file_txt = f"""
  21. /*load_file("nrngui.hoc")*/
  22. load_file("stdrun.hoc")
  23. //=================== creating cell object ===========================
  24. load_file("import3d.hoc")
  25. objref newcell
  26. strdef morphology_file
  27. morphology_file = "../L23Net/morphologies/{acell}.swc"
  28. load_file("../L23Net/models/NeuronTemplate.hoc")
  29. newcell = new NeuronTemplate(morphology_file)
  30. define_shape()
  31. """
  32. with open(loader_hoc_file, 'w') as f:
  33. print(loader_hoc_file_txt, file=f)
  34. export_to_neuroml2(loader_hoc_file, f"{acell}.morph.cell.nml",
  35. includeBiophysicalProperties=False, validate=False)
  36. os.remove(loader_hoc_file)
  37. if __name__ == "__main__":
  38. if len(sys.argv) != 2:
  39. print("This script only accepts one argument.")
  40. sys.exit(1)
  41. main(sys.argv[1])