|
2 | 2 | import sys |
3 | 3 | import logging |
4 | 4 | from netpyne.specs import simConfig |
| 5 | +from packaging import version |
5 | 6 |
|
| 7 | +import pyneuroml |
6 | 8 | from pyneuroml import pynml |
7 | 9 | from pyneuroml.lems import generate_lems_file_for_neuroml |
8 | 10 | from pyneuroml.pynml import read_neuroml2_file |
|
13 | 15 | def convertLEMSSimulation(lemsFileName, compileMod=True): |
14 | 16 | """Converts a LEMS Simulation file |
15 | 17 |
|
16 | | - Converts a LEMS Simulation file (https://docs.neuroml.org/Userdocs/LEMSSimulation.html) |
17 | | - pointing to a NeuroML 2 file into the equivalent in NetPyNE |
| 18 | + Converts a LEMS Simulation file |
| 19 | + (https://docs.neuroml.org/Userdocs/LEMSSimulation.html) pointing to a |
| 20 | + NeuroML 2 file into the equivalent in NetPyNE |
| 21 | +
|
18 | 22 | Returns: |
19 | 23 | simConfig, netParams for the model in NetPyNE |
20 | 24 | """ |
21 | 25 | current_path = os.getcwd() |
22 | 26 | try: |
23 | | - |
| 27 | + |
24 | 28 | fullLemsFileName = os.path.abspath(lemsFileName) |
25 | | - tmp_path = os.path.dirname(fullLemsFileName) |
| 29 | + tmp_path = os.path.dirname(fullLemsFileName) |
26 | 30 | if tmp_path: |
27 | 31 | os.chdir(tmp_path) |
28 | 32 | logging.info( |
29 | 33 | "Importing LEMSSimulation with NeuroML 2 network from: %s" |
30 | 34 | % fullLemsFileName |
31 | 35 | ) |
32 | 36 |
|
33 | | - result = pynml.run_lems_with_jneuroml_netpyne( |
34 | | - lemsFileName, only_generate_json=True, exit_on_fail=False) |
35 | | - |
36 | | - if result == False: |
37 | | - raise Exception("Error loading lems file") |
| 37 | + # feature to return output added in 1.0.9 |
| 38 | + if version.parse(pyneuroml.__version__) >= version.parse("1.0.9"): |
| 39 | + result, output_msg = pynml.run_lems_with_jneuroml_netpyne( |
| 40 | + lemsFileName, only_generate_json=True, exit_on_fail=False, |
| 41 | + return_string=True, max_memory="1G") |
| 42 | + |
| 43 | + if result is False: |
| 44 | + raise Exception(f"Error loading lems file: {output_msg}") |
| 45 | + else: |
| 46 | + result = pynml.run_lems_with_jneuroml_netpyne( |
| 47 | + lemsFileName, only_generate_json=True, exit_on_fail=False, |
| 48 | + max_memory="1G") |
| 49 | + |
| 50 | + if result is False: |
| 51 | + raise Exception("Error loading lems file") |
| 52 | + |
38 | 53 | lems = pynml.read_lems_file(lemsFileName) |
39 | 54 |
|
40 | 55 | np_json_fname = fullLemsFileName.replace('.xml','_netpyne_data.json') |
41 | | - |
| 56 | + |
42 | 57 | return np_json_fname |
43 | 58 | finally: |
44 | 59 | os.chdir(current_path) |
45 | 60 |
|
46 | 61 |
|
47 | | - |
48 | | - |
49 | 62 | def convertNeuroML2(nml2FileName, compileMod=True): |
50 | 63 | """Loads a NeuroML 2 file into NetPyNE |
51 | 64 | Loads a NeuroML 2 file into NetPyNE by creating a new LEMS Simulation |
52 | | - file (https://docs.neuroml.org/Userdocs/LEMSSimulation.html) and using jNeuroML |
53 | | - to convert it. |
| 65 | + file (https://docs.neuroml.org/Userdocs/LEMSSimulation.html) and using |
| 66 | + jNeuroML to convert it. |
54 | 67 |
|
55 | 68 | Returns: |
56 | 69 | simConfig, netParams for the model in NetPyNE |
57 | 70 | """ |
58 | 71 | current_path = os.getcwd() |
59 | 72 | try: |
60 | 73 | fullNmlFileName = os.path.abspath(nml2FileName) |
61 | | - work_path = os.path.dirname(fullNmlFileName) |
| 74 | + work_path = os.path.dirname(fullNmlFileName) |
62 | 75 | if not os.path.exists(work_path): |
63 | 76 | os.makedirs(work_path) |
64 | 77 | os.chdir(work_path) |
65 | 78 | sys.path.append(work_path) |
66 | | - |
67 | 79 |
|
68 | 80 | logging.info( |
69 | 81 | "Importing NeuroML 2 network from: %s" |
|
0 commit comments