Search in sources :

Example 1 with NameMap

use of gov.sandia.n2a.backend.neuroml.PartMap.NameMap in project n2a by frothga.

the class ImportJob method ionChannel.

public void ionChannel(Node node) {
    String id = getAttribute(node, "id");
    String type = getAttribute(node, "type");
    String species = getAttribute(node, "species");
    String inherit;
    if (type.isEmpty())
        inherit = node.getNodeName();
    else
        inherit = type;
    NameMap nameMap = partMap.importMap(inherit);
    inherit = nameMap.internal;
    // Expect to always create this part rather than fetch an existing child.
    MNode part = models.childOrCreate(modelName, id);
    part.set("$inherit", "\"" + inherit + "\"");
    addDependency(part, inherit);
    if (!species.isEmpty())
        part.set("$metadata", "species", species);
    addAttributes(node, part, nameMap, "id", "type", "species");
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.ELEMENT_NODE)
            continue;
        String name = child.getNodeName();
        if (name.startsWith("q10"))
            q10(child, part);
        else if (name.startsWith("gate"))
            gate(child, part);
        else
            genericPart(child, part);
    }
}
Also used : Node(org.w3c.dom.Node) MNode(gov.sandia.n2a.db.MNode) NameMap(gov.sandia.n2a.backend.neuroml.PartMap.NameMap) MNode(gov.sandia.n2a.db.MNode)

Example 2 with NameMap

use of gov.sandia.n2a.backend.neuroml.PartMap.NameMap in project n2a by frothga.

the class ImportJob method transition.

public void transition(Node node, MNode container) {
    String id = getAttribute(node, "id");
    MNode part = container.set(id, "");
    NameMap nameMap = partMap.importMap(node.getNodeName());
    part.set("$inherit", "\"" + nameMap.internal + "\"");
    addAttributes(node, part, nameMap, "id");
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE)
            rate(child, part, true, false);
    }
}
Also used : Node(org.w3c.dom.Node) MNode(gov.sandia.n2a.db.MNode) NameMap(gov.sandia.n2a.backend.neuroml.PartMap.NameMap) MNode(gov.sandia.n2a.db.MNode)

Example 3 with NameMap

use of gov.sandia.n2a.backend.neuroml.PartMap.NameMap in project n2a by frothga.

the class ImportJob method spikingSynapse.

/**
 *        Create a spike generator, which may be associated with its intended synapse.
 */
public void spikingSynapse(Node node) {
    String id = getAttribute(node, "id");
    String synapse = getAttribute(node, "synapse");
    // "spikeTarget" appears to be redundant with "synapse". Probably exists due to some oddity in LEMS.
    MNode part = models.childOrCreate(modelName, id);
    String inherit = node.getNodeName();
    NameMap nameMap = partMap.importMap(inherit);
    inherit = nameMap.internal;
    if (!inherit.isEmpty()) {
        part.set("$inherit", inherit);
        addDependency(part, inherit);
    }
    // "spikeArray" does not have an associated synapse.
    if (!synapse.isEmpty())
        part.set("$metadata", "backend.lems.synapse", synapse);
    addAttributes(node, part, nameMap, "id", "synapse", "spikeTarget");
    Map<Double, String> sorted = new TreeMap<Double, String>();
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE && child.getNodeName().equals("spike")) {
            String time = biophysicalUnits(getAttribute(child, "time"));
            sorted.put(Scalar.convert(time), time);
        }
    }
    if (// generate spikeArray-like code
    sorted.size() > 0) {
        String times = "";
        for (String s : sorted.values()) times += ";" + s;
        // This shuts down spiking after last specified time.
        times += ";∞";
        times = "[" + times.substring(1) + "]";
        part.set("times", times);
    }
}
Also used : Node(org.w3c.dom.Node) MNode(gov.sandia.n2a.db.MNode) NameMap(gov.sandia.n2a.backend.neuroml.PartMap.NameMap) TreeMap(java.util.TreeMap) MNode(gov.sandia.n2a.db.MNode)

Example 4 with NameMap

use of gov.sandia.n2a.backend.neuroml.PartMap.NameMap in project n2a by frothga.

the class ImportJob method channel.

public void channel(Node node, MNode part, boolean doDependency) {
    String name = node.getNodeName();
    String number = part.get("number");
    String ionChannel = part.get("ionChannel");
    part.clear("ionChannel");
    // There is only one internal part for all ion-channel-related components in NeuroML. It includes both individual channels and populations/densities.
    NameMap nameMap = partMap.importMap("ionChannel");
    remap(part, nameMap);
    // multiple inheritance, combining the ion channel with the given mix-in
    String potential = "";
    if (name.contains("Nernst"))
        potential = "Potential Nernst";
    else if (name.contains("GHK2"))
        potential = "Potential GHK 2";
    else if (name.contains("GHK"))
        potential = "Potential GHK";
    if (potential.isEmpty()) {
        part.set("$inherit", "\"" + ionChannel + "\"");
    } else {
        // For now, assume that ion channel is already defined
        String species = "ca";
        if (name.contains("Ca2"))
            species = "ca2";
        species = models.getOrDefault(modelName, ionChannel, "$metadata", "species", species);
        // connect to species/concentration model, which the user is responsible to create
        part.set("c", species);
        part.set("$inherit", "\"" + potential + "\",\"" + ionChannel + "\"");
        if (doDependency)
            addDependency(part, potential);
    }
    if (doDependency)
        addDependency(part, ionChannel);
    if (!number.isEmpty()) {
        // The default is Gdensity*surfaceArea
        part.set("Gall", "G1*population");
    }
}
Also used : NameMap(gov.sandia.n2a.backend.neuroml.PartMap.NameMap)

Example 5 with NameMap

use of gov.sandia.n2a.backend.neuroml.PartMap.NameMap in project n2a by frothga.

the class ExportJob method input.

public String input(MPart source, List<Element> parentElements, Synapse synapse) {
    String type = source.get("$metadata", "backend.lems.part");
    List<Element> inputElements = new ArrayList<Element>();
    List<String> skip = new ArrayList<String>();
    for (MNode c : source) {
        MPart p = (MPart) c;
        if (p.isPart()) {
            skip.add(p.key());
            input(p, inputElements, null);
        } else if (p.key().equals("times")) {
            skip.add("times");
            String[] pieces = p.get().split("\\[", 2)[1].split("]", 2)[0].split(";");
            for (int i = 0; i < pieces.length; i++) {
                if (Scalar.convert(pieces[i]) == Double.POSITIVE_INFINITY)
                    continue;
                Element spike = addElement("spike", inputElements);
                spike.setAttribute("id", String.valueOf(i));
                spike.setAttribute("time", biophysicalUnits(pieces[i]));
            }
        }
    }
    if (// decide between them
    type.contains("ramp") && type.contains("pulse")) {
        NameMap nameMap = partMap.importMap("rampGenerator");
        EquationSet sourceEquations = getEquations(source);
        Variable high1 = sourceEquations.find(new Variable(nameMap.importName("startAmplitude"), 0));
        Variable high2 = sourceEquations.find(new Variable(nameMap.importName("finishAmplitude"), 0));
        try {
            double value1 = ((Scalar) high1.eval(context)).value;
            double value2 = ((Scalar) high2.eval(context)).value;
            if (value1 == value2)
                type = "pulseGenerator";
            else
                type = "rampGenerator";
        } catch (// eval can fail if eqset contains fatal errors
        Exception e) {
            if (source.get("high2").equals("high1"))
                type = "pulseGenerator";
            else
                type = "rampGenerator";
        }
    } else if (// more action is needed
    type.contains(",")) {
        if (synapse != null) {
            String[] types = type.split(",");
            for (String t : types) {
                if (// prefix of both "Synapse" and "Synaptic"
                t.contains("Synap")) {
                    type = t;
                    break;
                }
            }
        }
        // remove any remaining ambiguity
        type = type.split(",")[0];
    }
    Element input = addElement(type, parentElements);
    String id;
    if (synapse == null) {
        id = source.get("$metadata", "backend.lems.id");
        if (id.isEmpty())
            id = source.key();
    } else {
        id = synapse.id;
        input.setAttribute("synapse", synapse.chainID);
        input.setAttribute("spikeTarget", "./" + synapse.chainID);
    }
    input.setAttribute("id", id);
    standalone(source, input, inputElements);
    genericPart(source, input, skip.toArray(new String[] {}));
    sequencer.append(input, inputElements);
    return id;
}
Also used : EquationSet(gov.sandia.n2a.eqset.EquationSet) MPart(gov.sandia.n2a.eqset.MPart) AccessVariable(gov.sandia.n2a.language.AccessVariable) Variable(gov.sandia.n2a.eqset.Variable) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) NameMap(gov.sandia.n2a.backend.neuroml.PartMap.NameMap) MNode(gov.sandia.n2a.db.MNode) IncommensurableException(javax.measure.IncommensurableException) UnconvertibleException(javax.measure.UnconvertibleException) ParseException(gov.sandia.n2a.language.ParseException) Scalar(gov.sandia.n2a.language.type.Scalar)

Aggregations

NameMap (gov.sandia.n2a.backend.neuroml.PartMap.NameMap)10 MNode (gov.sandia.n2a.db.MNode)9 Node (org.w3c.dom.Node)7 NamedNodeMap (org.w3c.dom.NamedNodeMap)2 EquationSet (gov.sandia.n2a.eqset.EquationSet)1 MPart (gov.sandia.n2a.eqset.MPart)1 Variable (gov.sandia.n2a.eqset.Variable)1 AccessVariable (gov.sandia.n2a.language.AccessVariable)1 ParseException (gov.sandia.n2a.language.ParseException)1 Scalar (gov.sandia.n2a.language.type.Scalar)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1 IncommensurableException (javax.measure.IncommensurableException)1 UnconvertibleException (javax.measure.UnconvertibleException)1 Element (org.w3c.dom.Element)1