NeuroML / NeuroML2

This repository hosts the NeuroML 2 Schema, the ComponentType definitions in LEMS and the core documentation of NeuroML2.
https://docs.neuroml.org
GNU Lesser General Public License v3.0
50 stars 24 forks source link

Create Matlab API/Toolbox for NeuroML #103

Open pgleeson opened 7 years ago

pgleeson commented 7 years ago

Matlab API/Toolbox for reading/editing/writing NeuroML2

Priorities will be:

An initial version of this be worked on by @jonc125 under https://github.com/NeuroML/NeuroMLToolbox

Is there an existing XSD -> Matlab code generation option?

The best option may be to use JAXB and access the Java classes from Matlab

jonc125 commented 7 years ago

Following documentation at http://uk.mathworks.com/help/matlab/matlab_external/static-path.html I've created a javaclasspath.txt file in my prefdir containing /full/path/to/jNeuroMLJar/jNeuroML-0.7.7-jar-with-dependencies.jar.

Following http://uk.mathworks.com/help/matlab/matlab_external/accessing-your-own-java-classes.html I can do some very simple test calls:

jonc125 commented 7 years ago

Running

validator = org.neuroml.model.util.NeuroML2Validator();
file = java.io.File('/Users/jonc/projects/OpenSourceBrain/NeuroML_API/test/samples/Purk2M9s.nml');
validator.validateWithTests(file);
disp(validator.getValidity());

yields Valid against schema and all tests

Similarly

file = java.io.File('/Users/jonc/projects/OpenSourceBrain/neuroml2_matlab/dev/jLEMS/src/test/resources/hhmodels.xml');
org.neuroml.export.utils.Utils.runLemsFile(file, false);

gives

Mar 20, 2017 3:23:06 PM org.lemsml.jlems.core.logging.MinimalMessageHandler msg
INFO:  (INFO) Loading LEMS file from: /Users/jonc/projects/OpenSourceBrain/neuroml2_matlab/dev/jLEMS/src/test/resources/example1.xml at: org.lemsml.jlems.viz.datadisplay.ControlPanel.initialise(ControlPanel.java:135)
Mar 20, 2017 3:23:06 PM org.lemsml.jlems.core.logging.MinimalMessageHandler msg
INFO:  (INFO) Reading from: /Users/jonc/projects/OpenSourceBrain/neuroml2_matlab/dev/jLEMS/src/test/resources/example1.xml at: org.neuroml.export.utils.Utils.readLemsNeuroMLFile(Utils.java:238)
Mar 20, 2017 3:23:06 PM org.lemsml.jlems.core.logging.MinimalMessageHandler msg
WARNING:  (WARNING) Unused attribute in Component(id=p1-p3 type=EventConnectivity): XMLAttribute(source, p1)  at: org.lemsml.jlems.core.type.Component.resolve(Component.java:538)
Mar 20, 2017 3:23:06 PM org.lemsml.jlems.core.logging.MinimalMessageHandler msg
WARNING:  (WARNING) Unused attribute in Component(id=p1-p3 type=EventConnectivity): XMLAttribute(target, p3)  at: 
Mar 20, 2017 3:23:07 PM org.lemsml.jlems.core.logging.MinimalMessageHandler msg
INFO:  (INFO) Finished 8000 steps in 0.862 seconds (sim duration: 80.0ms; dt: 0.01ms) at: org.lemsml.jlems.core.sim.Sim.run(Sim.java:332)
Mar 20, 2017 3:23:07 PM org.lemsml.jlems.core.logging.MinimalMessageHandler msg
INFO:  (INFO) Finished reading, building, running and displaying LEMS model at: org.neuroml.export.utils.Utils.loadLemsFile(Utils.java:393)

So it does look like this approach will let us do everything that the Java API can do.

jonc125 commented 7 years ago

Things to look into further:

Places to look at for inspiration:

jonc125 commented 7 years ago

I've made a start on documentation and a few examples. Some issues making this hard:

Running without the GUI helps somewhat with this - the results folder is resolved relative to the current dir and Matlab doesn't quit when the simulation finishes / GUI exits. But there's still the issue of figuring out what the results were.

jonc125 commented 7 years ago

Of course, another approach would be to access the Python API from Matlab, as we're doing for NWB...

This would mean a bit more conversion between Python & Matlab types than seems to happen with Java APIs, but if the Python API is nicer to work with, particularly for creating models, and is going to be better supported in the future, that may well be the better option.

pgleeson commented 7 years ago

I've tested this locally and some NML files validate correctly, others, incl ones in the examples folder here, don't with a strange error:

Apr 12, 2017 11:57:16 AM com.sun.xml.bind.v2.util.XmlFactory createTransformerFactory
SEVERE: null
javax.xml.transform.TransformerConfigurationException: Unsupported feature: http://javax.xml.XMLConstants/feature/secure-processing
    at com.icl.saxon.TransformerFactoryImpl.setFeature(TransformerFactoryImpl.java:373)
    at com.sun.xml.bind.v2.util.XmlFactory.createTransformerFactory(XmlFactory.java:176)

Will investigate further.

Also, the closing of Matlab on an error in jNeuroML is annoying, i'll purge the code of these exit(1) calls, and maybe set an option to close on exit.

There could certainly be a map returned with the filenames and names of variables when Utils.runLemsFile() is called. Will add this..