Skip to content

Commit

Permalink
Using latest jar
Browse files Browse the repository at this point in the history
  • Loading branch information
pgleeson committed Oct 31, 2017
1 parent 4859034 commit b50d03a
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 1,823 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/src/main/java/META-INF/MANIFEST.MF
72 changes: 39 additions & 33 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,50 +1,56 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>NeuroML2 model lite</name>
<url>https://neuroml.org/</url>
<packaging>bundle</packaging>
<groupId>org.neuroml.neuroml2modelLite</groupId>
<artifactId>neuroml2modelLite</artifactId>
<version>0.0.6</version>

<dependencies>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>NeuroML2 model lite</name>
<url>https://neuroml.org/</url>
<packaging>bundle</packaging>
<groupId>org.neuroml.neuroml2modelLite</groupId>
<artifactId>neuroml2modelLite</artifactId>
<version>0.0.6</version>

<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>

<dependency>
<groupId>org.neuroml.export</groupId>
<artifactId>org.neuroml.export</artifactId>
<version>1.5.3</version>
</dependency>

</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<manifestLocation>src/main/java/META-INF</manifestLocation>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
</instructions>
</configuration>
</plugin>
</dependencies>


<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<manifestLocation>src/main/java/META-INF</manifestLocation>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
<supportedProjectType>bundle</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
</instructions>
</configuration>
</plugin>
</plugins>





</build>
</build>


</project>
30 changes: 30 additions & 0 deletions regen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
set -e

cd ../expr-parser

git pull
mvn clean install

cd ../org.lemsml.model

git pull
mvn clean install

cd ../lems-domogen-maven-plugin/

git pull
mvn clean install

cd ../neuroml2model

git pull
mvn clean install

cd ../neuroml2modelLite

rm -f src/main/resources/*
cp ../neuroml2model/target/org.neuroml.neuroml2-model-*-jar-with-dependencies.jar src/main/resources/

mvn clean install


11 changes: 0 additions & 11 deletions src/main/java/META-INF/MANIFEST.MF

This file was deleted.

163 changes: 155 additions & 8 deletions src/main/java/org/neuroml2/modellite/NeuroML2ModelReader.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,45 @@
package org.neuroml2.modellite;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.LinkedHashMap;
import org.neuroml.export.info.model.ExpressionNode;
import org.neuroml.export.info.model.InfoNode;
import org.neuroml.model.ComponentType;
import org.neuroml.model.NeuroMLDocument;
import org.neuroml.model.Standalone;
import org.neuroml.model.util.NeuroMLConverter;
import org.neuroml.model.util.NeuroMLException;

public class NeuroML2ModelReader
{

public static String extractExpressions(File nml2File) throws IOException, InterruptedException
private static String localCopyJar = null;

public static InfoNode extractExpressions(File nml2File) throws IOException, InterruptedException, NeuroMLException
{
String nml2jar = "src/main/resources/org.neuroml.neuroml2-model-0.0.6-jar-with-dependencies.jar";
InfoNode info = new InfoNode();

/*
* This is clearly not the best way to access this functionality...
* There is an incompatibility between some of the dependencies used in Geppetto and the new LEMS2/NeuroML2 model
* packages. When that is solved, this can be replaced with a direct call to extractInfo() in NeuroML2ModelReader
* in https://github.com/NeuroML/neuroml2model.
*/
if (localCopyJar == null)
{
String nml2jar = "org.neuroml.neuroml2-model-0.0.7-jar-with-dependencies.jar";
File f = getLocalFile(nml2jar);

localCopyJar = f.getCanonicalPath();
}

System.out.println("Extracting expressions from: " + nml2File.getCanonicalPath());

Process proc = Runtime.getRuntime().exec("java -jar " + nml2jar + " " + nml2File.getCanonicalPath());
Process proc = Runtime.getRuntime().exec("java -jar " + localCopyJar + " " + nml2File.getCanonicalPath());

proc.waitFor();

Expand All @@ -26,16 +53,132 @@ public static String extractExpressions(File nml2File) throws IOException, Inter

byte c[] = new byte[err.available()];
err.read(c, 0, c.length);
//System.out.println(new String(c));
String strerr = new String(c);

if (proc.exitValue() != 0)
{
throw new NeuroMLException("Problem loading: " + nml2File + ":\n" + strerr);
}

String[] lines = strin.split("\\n");
for (String line : lines)
{
if (line.indexOf("=") > 0)
{
System.out.println("Parsing: " + line);
String tag = line.split(" = ")[0].trim();
String val = line.split(" = ")[1].trim();
String[] pre = tag.split(":");
if (info.get(pre[0]) == null)
{
info.put(pre[0], new InfoNode());
}
InfoNode l2 = (InfoNode) info.get(pre[0]);
if (l2.get(pre[1]) == null)
{
l2.put(pre[1], new InfoNode());
}
InfoNode l3 = (InfoNode) l2.get(pre[1]);

if (pre[1].indexOf("gate") >= 0)
{
if (pre[2].indexOf("instances") >= 0)
{
l3.put(pre[2], Integer.parseInt(val));
}
else
{
String expr = val;
String ex = pre[2];

String title = pre[0] + " - " + pre[1] + " - " + pre[2];

double dv = 0.0025;
l3.put(ex, new ExpressionNode(expr, title, "V", "ms-1", -0.1, 0.1 + dv, dv));

}
}
else
{
l3.put(pre[2], val);
}

}

}

return info;
}

public static InfoNode extractExpressions(NeuroMLDocument nmlDoc0) throws NeuroMLException
{
NeuroMLConverter nmlc = new NeuroMLConverter();
NeuroMLDocument nmlDoc = new NeuroMLDocument();
nmlDoc.setId(nmlDoc0.getId());

return strin;
LinkedHashMap<String, Standalone> saes = nmlc.getAllStandaloneElements(nmlDoc0);
for (Standalone sae : saes.values())
{
if (!(sae.getClass().getName().equals("org.neuroml.model.Network")
|| sae.getClass().getName().equals("org.neuroml.model.Cell")
|| sae.getClass().getName().equals("org.neuroml.model.PoissonFiringSynapse")))
{
System.out.println("-- Including " + sae.getClass().getName());
NeuroMLConverter.addElementToDocument(nmlDoc, sae);
}
}

for (ComponentType ct : nmlDoc0.getComponentType())
{
nmlDoc.getComponentType().add(ct);
}

try
{
File f = File.createTempFile("NeuroML_", ".tmp");
System.out.println("Written temp file to: " + f.getCanonicalPath());
nmlc.neuroml2ToXml(nmlDoc, f.getAbsolutePath());
return extractExpressions(f);
}
catch (IOException i)
{
throw new NeuroMLException(i);
}
catch (InterruptedException i)
{
throw new NeuroMLException(i);
}
}

public static void main(String[] args) throws IOException, InterruptedException
private static File getLocalFile(String name) throws IOException
{
String ionChannelFile = "src/test/resources/Ca_LVAst.channel.nml";
File f;

String path = NeuroML2ModelReader.class.getClassLoader().getResource(name).toExternalForm();

InputStream input = NeuroML2ModelReader.class.getClassLoader().getResourceAsStream(name);
f = File.createTempFile(name.replaceAll("/", "_"), ".tmp");
System.out.println("Creating " + f.getCanonicalPath() + " from " + path);
OutputStream out = new FileOutputStream(f);
int read;
byte[] bytes = new byte[1024];
while ((read = input.read(bytes)) != -1)
{
out.write(bytes, 0, read);
}
f.deleteOnExit();

return f;
}

public static void main(String[] args) throws IOException, InterruptedException, NeuroMLException
{
String ionChannelFile = "src/test/resources/NML2_SingleCompHHCell.nml";
//ionChannelFile = "src/test/resources/kdr.channel.nml";
//ionChannelFile = "../../geppetto/org.geppetto.model.neuroml/src/test/resources/traub/k2.channel.nml";
//ionChannelFile = "../../geppetto/org.geppetto.model.neuroml/src/test/resources/hhcell/NML2_SingleCompHHCell.nml";
//ionChannelFile = "/tmp/NeuroML_3644588102506634724.tmp";
//ionChannelFile = "../../neuroConstruct/osb/cerebral_cortex/networks/Thalamocortical/NeuroML2/pythonScripts/netbuild/TestL23.net.nml";
if (args.length == 1)
{
ionChannelFile = args[0];
Expand All @@ -45,8 +188,12 @@ public static void main(String[] args) throws IOException, InterruptedException
NeuroML2ModelReader nmlr;

System.out.println("Opening file: " + nmlFile.getCanonicalPath());

System.out.println(NeuroML2ModelReader.extractExpressions(nmlFile));
NeuroMLConverter nmlc = new NeuroMLConverter();
NeuroMLDocument nmlDoc = nmlc.loadNeuroML(nmlFile, true);

System.out.println(NeuroML2ModelReader.extractExpressions(nmlDoc).toDetailString("> "));

}

Expand Down
Binary file not shown.
Binary file not shown.
9 changes: 8 additions & 1 deletion src/test/java/org/neuroml2/modellite/AllTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.File;
import org.junit.Before;
import org.junit.Test;
import org.neuroml.model.NeuroMLDocument;
import org.neuroml.model.util.NeuroMLConverter;



Expand All @@ -17,13 +19,18 @@ public void setUp() throws Throwable {
@Test
public void testChannels() throws Throwable {

String[] nmlFiles = {"Ca_LVAst.channel.nml","Ih.channel.nml"};
String[] nmlFiles = {"kdr.channel.nml", "SK_E2.channel.nml","SKv3_1.channel.nml","NML2_SingleCompHHCell.nml"};
for (String n: nmlFiles)
{
File f = new File("src/test/resources/"+n);
System.out.println("===============================\nTesting: "+f.getCanonicalPath());
System.out.println(NeuroML2ModelReader.extractExpressions(f));

System.out.println("-----------------");
NeuroMLConverter nmlc = new NeuroMLConverter();
NeuroMLDocument nmlDoc = nmlc.loadNeuroML(f, true);
System.out.println(NeuroML2ModelReader.extractExpressions(nmlDoc).toDetailString(" "));

}
}

Expand Down
Loading

0 comments on commit b50d03a

Please sign in to comment.