Search in sources :

Example 6 with NameMap

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

the class ImportJob method q10.

public void q10(Node node, MNode container) {
    String id = "Q10Parameters";
    int suffix = 2;
    // This seems pointless, but the NeuroML XSD says the number of elements is unbounded.
    while (container.child(id) != null) id = "Q10Parameters" + suffix++;
    MNode part = container.set(id, "");
    // This isn't the correct name for use with ion channel, but it will still work.
    NameMap nameMap = partMap.importMap("baseQ10Settings");
    String inherit = nameMap.internal;
    part.set("$inherit", "\"" + inherit + "\"");
    addDependency(part, inherit);
    NamedNodeMap attributes = node.getAttributes();
    int count = attributes.getLength();
    for (int i = 0; i < count; i++) {
        Node a = attributes.item(i);
        String name = a.getNodeName();
        // probably switches between fixed and exponential, but there is no example/guidance on its use
        if (name.equals("type"))
            continue;
        String value = biophysicalUnits(a.getNodeValue());
        if (name.equals("fixedQ10"))
            value = "*" + value;
        name = nameMap.importName(name);
        part.set(name, value);
    }
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) 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 7 with NameMap

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

the class ImportJob method rate.

public void rate(Node node, MNode container, boolean KS, boolean instantaneous) {
    String name = node.getNodeName();
    String inherit = getAttribute(node, "type");
    MNode part = container.set(name, "");
    NameMap nameMap = partMap.importMap(inherit);
    inherit = nameMap.internal;
    part.set("$inherit", "\"" + inherit + "\"");
    addDependency(part, inherit);
    addAttributes(node, part, nameMap, "type");
    // add appropriate "$up.var=x" statement
    String up = "";
    if (name.equals("forwardRate")) {
        if (KS)
            up = "$up.forward";
        else
            up = "$up.α";
    } else if (name.equals("reverseRate")) {
        if (KS)
            up = "$up.reverse";
        else
            up = "$up.β";
    } else if (name.equals("steadyState")) {
        if (// Because the Gate model is written so that inf only initializes q once, while "instantaneous" requires continually changing q.
        instantaneous)
            // Because the Gate model is written so that inf only initializes q once, while "instantaneous" requires continually changing q.
            up = "$up.q";
        else
            up = "$up.inf";
    } else if (name.equals("timeCourse")) {
        up = "$up.τUnscaled";
    }
    if (!up.isEmpty())
        part.set(up, "x");
}
Also used : NameMap(gov.sandia.n2a.backend.neuroml.PartMap.NameMap) MNode(gov.sandia.n2a.db.MNode)

Example 8 with NameMap

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

the class ImportJob method genericPart.

/**
 *        Handles elements in a generic manner, including metadata elements.
 *        Generic elements get processed into parts under the given container.
 *        Metadata elements get added to the $metadata node of the given container.
 */
public MNode genericPart(Node node, MNode container) {
    String nodeName = node.getNodeName();
    if (nodeName.equals("notes")) {
        container.set("$metadata", "notes", getText(node));
        return container.child("$metadata", "notes");
    }
    if (nodeName.equals("property")) {
        String tag = getAttribute(node, "tag");
        String value = getAttribute(node, "value");
        container.set("$metadata", tag, value);
        return container.child("$metadata", tag);
    }
    // TODO: process annotations
    if (nodeName.equals("annotation"))
        return null;
    String id = getAttribute(node, "id", nodeName);
    String stem = id;
    int suffix = 2;
    while (container.child(id) != null) id = stem + suffix++;
    MNode part = container.childOrCreate(id);
    nodeName = getAttribute(node, "type", nodeName);
    List<MNode> parents = collectParents(container);
    String inherit = typeFor(nodeName, parents);
    NameMap nameMap;
    if (inherit.isEmpty()) {
        nameMap = partMap.importMap(nodeName);
        inherit = nameMap.internal;
    } else {
        // Because typeFor() finds internal names, we need to retrieve a map from the opposite direction.
        // It will still map parameter names correctly for import.
        nameMap = partMap.exportMap(inherit);
    }
    part.set("$inherit", "\"" + inherit + "\"");
    addDependency(part, inherit);
    // Now we follow our own inheritance chain, not our container's.
    parents = collectParents(part);
    NamedNodeMap attributes = node.getAttributes();
    int count = attributes.getLength();
    for (int i = 0; i < count; i++) {
        Node a = attributes.item(i);
        String name = a.getNodeName();
        String value = a.getNodeValue();
        if (name.equals("id"))
            continue;
        if (name.equals("type"))
            continue;
        if (name.equals("neuroLexId")) {
            part.set("$metadata", "neuroLexID", value);
            continue;
        }
        name = nameMap.importName(name);
        if (isPart(name, parents)) {
            inherit = value;
            part.set(name, "$inherit", "\"" + inherit + "\"");
            addDependency(part.child(name), inherit);
            addAlias(inherit, name);
        } else {
            String defaultUnit = nameMap.defaultUnit(name);
            part.set(name, biophysicalUnits(value, defaultUnit));
        }
    }
    // Thus, we add hacks here to detect these special cases and do the extra processing.
    if (nodeName.startsWith("channel"))
        channel(node, part, true);
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() == Node.ELEMENT_NODE)
            genericPart(child, part);
    }
    return part;
}
Also used : NamedNodeMap(org.w3c.dom.NamedNodeMap) 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 9 with NameMap

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

the class ImportJob method blockingPlasticSynapse.

public void blockingPlasticSynapse(Node node) {
    String id = getAttribute(node, "id");
    MNode part = models.childOrCreate(modelName, 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)
            continue;
        MNode c = genericPart(child, part);
        String name = child.getNodeName();
        if (// This handles both block and plasticity mechanisms.
        name.endsWith("Mechanism")) {
            String species = c.get("species");
            c.clear("species");
            if (!species.isEmpty())
                c.set("$metadata", "species", species);
        }
    }
}
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 10 with NameMap

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

the class ImportJob method gate.

public void gate(Node node, MNode container) {
    String id = getAttribute(node, "id");
    String type = getAttribute(node, "type");
    boolean instantaneous = type.contains("Instantaneous");
    String inherit;
    if (type.isEmpty())
        inherit = node.getNodeName();
    else
        inherit = type;
    NameMap nameMap = partMap.importMap(inherit);
    inherit = nameMap.internal;
    MNode part = container.set(id, "");
    part.set("$inherit", "\"" + inherit + "\"");
    addDependency(part, inherit);
    addAttributes(node, part, nameMap, "id", "type");
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.ELEMENT_NODE)
            continue;
        String name = child.getNodeName();
        switch(name) {
            case "subGate":
                gate(child, part);
                break;
            case "notes":
                part.set("$metadata", "notes", getText(child));
                break;
            case "q10Settings":
                q10(child, part);
                break;
            case "openState":
            case "closedState":
                id = getAttribute(child, "id");
                part.set(id, "$inherit", "\"Kinetic State\"");
                part.set(id, "relativeConductance", name.equals("openState") ? "1" : "0");
                break;
            case "forwardTransition":
            case "reverseTransition":
            case "tauInfTransition":
            case "vHalfTransition":
                transition(child, part);
                break;
            default:
                rate(child, part, false, instantaneous);
        }
    }
}
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)

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