Skip to content

Commit

Permalink
Merge pull request #107 from NeuroML/experimental
Browse files Browse the repository at this point in the history
Update to use of units in mod files
  • Loading branch information
pgleeson authored Sep 12, 2023
2 parents 910c33d + 0e27fff commit ac1b521
Show file tree
Hide file tree
Showing 9 changed files with 177 additions and 80 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ jobs:

name: Test on Java ${{ matrix.Java }} on ${{ matrix.runs-on }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up JDK ${{ matrix.Java }}
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.Java }}
distribution: 'temurin'
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: nelonoel/[email protected]

- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: 11
java-package: jdk

- name: Set up Python 3.9
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: 3.9

Expand All @@ -33,29 +33,29 @@ jobs:
pip install ghp-import
- name: Checkout NeuroML2
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: NeuroML/NeuroML2
ref: development
path: NeuroML2

- name: Checkout org.lemsml
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: LEMS/jLEMS
ref: development
path: jLEMS


- name: Checkout org.neuroml.model.injectingplugin
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: NeuroML/org.neuroml.model.injectingplugin
ref: development
path: org.neuroml.model.injectingplugin

- name: Checkout org.neuroml.model
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
repository: NeuroML/org.neuroml.model
ref: development
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/org/lemsml/export/sedml/SEDMLWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.neuroml.export.utils.support.ModelFeature;
import org.neuroml.model.util.NeuroMLException;
import org.neuroml.export.utils.support.SupportLevelInfo;
import org.neuroml.export.sbml.SBMLWriter;

public class SEDMLWriter extends AXMLWriter
{
Expand Down Expand Up @@ -274,24 +275,31 @@ public static void main(String[] args) throws Exception, ModelFeatureSupportExce
ArrayList<File> lemsFiles = new ArrayList<File>();


lemsFiles.add(new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/LEMS_TwoCell.xml"));
//lemsFiles.add(new File("../neuroConstruct/osb/cerebral_cortex/networks/ACnet2/neuroConstruct/generatedNeuroML2/LEMS_TwoCell.xml"));
//lemsFiles.add(new File("../OpenCortex/examples/LEMS_ACNet.xml"));

//lemsFiles.add(new File("../OpenCortex/examples/LEMS_SpikingNet.xml"));
//lemsFiles.add(new File("../OpenCortex/examples/LEMS_SimpleNet.xml"));
lemsFiles.add(new File("../neuroConstruct/osb/showcase/SBMLShowcase/NeuroML2/LEMS_NML2_Ex9_FN.xml"));
lemsFiles.add(new File("../neuroConstruct/osb/generic/HindmarshRose1984/NeuroML2/LEMS_Regular_HindmarshRose.xml"));


SEDMLWriter nw;
for(File lemsFile : lemsFiles)
{
Lems lems = Utils.readLemsNeuroMLFile(lemsFile.getAbsoluteFile()).getLems();
nw = new SEDMLWriter(lems, lemsFile.getParentFile(), lemsFile.getName().replaceAll(".xml", ".sedml"), lemsFile.getName(), Format.SBML);

SBMLWriter sbmlw = new SBMLWriter(lems, lemsFile.getParentFile(), lemsFile.getName().replaceAll(".xml", ".sbml"));
for(File genFile : sbmlw.convert())
{
System.out.println("Generated SBML: " + genFile.getAbsolutePath());
}

nw = new SEDMLWriter(lems, lemsFile.getParentFile(), lemsFile.getName().replaceAll(".xml", ".sedml"), lemsFile.getName(), Format.SBML);
List<File> ff = nw.convert();
for(File f : ff)
{
System.out.println("Generated sed-ml: " + f.getCanonicalPath());
System.out.println("Generated SED-ML: " + f.getCanonicalPath());
}

}
Expand Down
50 changes: 34 additions & 16 deletions src/main/java/org/neuroml/export/neuron/NRNUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class NRNUtils implements UnitConverter
final static String V_CURRENT_SUFFIX = "_I";
final static String RATE_PREFIX = "rate_";
final static String REGIME_PREFIX = "regime_";
final static String V_COPY_PREFIX = "copy_";
//final static String V_COPY_PREFIX = "copy_";

final static String[] NON_NRN_STATE_VARS
= new String[]{"weightFactor","isi","nextIsi","lastSpikeTime","nextSpikeTemp","nextSpike"};
Expand All @@ -51,18 +51,24 @@ public class NRNUtils implements UnitConverter

static final int commentOffset = 40;

static final String LEN_UNIT = "cm";
static final float LEN_CONVERSION = 1e2f;


static final String generalUnits = "\n(nA) = (nanoamp)\n"
+ "(uA) = (microamp)\n"
+ "(mA) = (milliamp)\n"
+ "(A) = (amp)\n"
+ "(mV) = (millivolt)\n"
+ "(mS) = (millisiemens)\n"
+ "(uS) = (microsiemens)\n"
+ "(nF) = (nanofarad)\n"
+ "(molar) = (1/liter)\n"
+ "(kHz) = (kilohertz)\n"
+ "(mM) = (millimolar)\n"
+ "(um) = (micrometer)\n"
+ "(umol) = (micromole)\n"
+ "(pC) = (picocoulomb)\n"
+ "(S) = (siemens)\n";

static final String ghkUnits = ": bypass nrn default faraday const\n" + "FARADAY = 96485.3 (coulomb)\n" + "R = (k-mole) (joule/degC)\n";
Expand Down Expand Up @@ -342,7 +348,7 @@ else if (dimensionName.equals("conductance"))
}
else if (dimensionName.equals("capacitance"))
{
return "(microfarads)";
return "(nF)";
}
else if (dimensionName.equals("specificCapacitance"))
{
Expand All @@ -362,27 +368,31 @@ else if (dimensionName.equals("current"))
}
else if (dimensionName.equals("currentDensity"))
{
return "(mA / cm2)";
return "(nA / cm2)";
}
else if (dimensionName.equals("current_per_time"))
{
return "(nA / ms)";
}
else if (dimensionName.equals("conductanceDensity"))
{
return "(uS / cm2)";
}
else if (dimensionName.equals("conductanceDensity_hoc"))
{
return "(S / cm2)";
}
else if (dimensionName.equals("length"))
{
return "(um)";
return "("+LEN_UNIT+")";
}
else if (dimensionName.equals("area"))
{
return "(um2)";
return "("+LEN_UNIT+"2)";
}
else if (dimensionName.equals("volume"))
{
return "(um3)";
return "("+LEN_UNIT+"3)";
}
else if (dimensionName.equals("resistivity"))
{
Expand All @@ -398,19 +408,19 @@ else if (dimensionName.equals("concentration"))
}
else if (dimensionName.equals("charge_per_mole"))
{
return "(C / umol)";
return "(pC / umol)";
}
else if (dimensionName.equals("temperature"))
{
return "(K)";
}
else if (dimensionName.equals("idealGasConstantDims"))
{
return "(millijoule / K / umol)";
return "(femtojoule / K / umol)";
}
else if (dimensionName.equals("rho_factor"))
{
return "(mM m2 /A /s)";
return "(umol / cm / nA / ms)";
}
else if (dimensionName.equals("conductance_per_voltage"))
{
Expand Down Expand Up @@ -474,7 +484,7 @@ else if (dimensionName.equals("conductance"))
}
else if (dimensionName.equals("capacitance"))
{
return 1e6f;
return 1e9f;
}
else if (dimensionName.equals("specificCapacitance"))
{
Expand All @@ -497,6 +507,10 @@ else if (dimensionName.equals("current_per_time"))
return 1e6f;
}
else if (dimensionName.equals("conductanceDensity"))
{
return 1e2f;
}
else if (dimensionName.equals("conductanceDensity_hoc"))
{
return 1e-4f;
}
Expand All @@ -506,15 +520,15 @@ else if (dimensionName.equals("time"))
}
else if (dimensionName.equals("length"))
{
return 1000000f;
return LEN_CONVERSION;
}
else if (dimensionName.equals("area"))
{
return 1e12f;
return LEN_CONVERSION * LEN_CONVERSION;
}
else if (dimensionName.equals("volume"))
{
return 1e18f;
return LEN_CONVERSION * LEN_CONVERSION * LEN_CONVERSION;
}
else if (dimensionName.equals("resistance"))
{
Expand All @@ -530,15 +544,15 @@ else if (dimensionName.equals("concentration"))
}
else if (dimensionName.equals("charge_per_mole"))
{
return 1e-6f;
return 1e6f;
}
else if (dimensionName.equals("idealGasConstantDims"))
{
return 0.001f;
return 1e9f;
}
else if (dimensionName.equals("rho_factor"))
{
return 1f;
return 1e-8f;
}
else if (dimensionName.equals("conductance_per_voltage"))
{
Expand All @@ -561,6 +575,10 @@ protected static String getDerivativeUnit(String dimensionName)
{
return "(/ms)";
}
if (dimensionName.equals("voltage")) // special case... for rate to calculate neuron voltage/current from abstract cell
{
return "(mV/ms)";
}
else
{
return unit.replaceAll("\\)", "/ms)");
Expand Down
Loading

0 comments on commit ac1b521

Please sign in to comment.