Search in sources :

Example 56 with MNode

use of gov.sandia.n2a.db.MNode 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 57 with MNode

use of gov.sandia.n2a.db.MNode 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 58 with MNode

use of gov.sandia.n2a.db.MNode in project n2a by frothga.

the class ImportJob method postprocess.

/**
 *        Perform data manipulations that must wait until all nodes are read.
 */
public void postprocess() {
    for (Entry<String, ComponentType> e : components.entrySet()) e.getValue().finish1();
    for (Entry<String, ComponentType> e : components.entrySet()) e.getValue().finish2();
    for (Entry<String, Cell> e : cells.entrySet()) e.getValue().finish();
    for (Entry<String, Network> e : networks.entrySet()) e.getValue().finish1();
    for (Entry<String, Network> e : networks.entrySet()) e.getValue().finish2();
    // (Obscure case) Find spike sources that reference a target synapse but did not get used.
    // Need to construct fused parts so they are functional on their own.
    List<String> kill = new ArrayList<String>();
    for (MNode spikeSource : models.child(modelName)) {
        String synapseName = spikeSource.get("$metadata", "backend.lems.synapse");
        // not a spike source
        if (synapseName.isEmpty())
            continue;
        // this memo is no longer needed
        spikeSource.clear("$metadata", "backend.lems.synapse");
        // It got used somewhere, so we're done.
        if (spikeSource.getInt("$count") > 0)
            continue;
        MNode synapse = models.child(modelName, synapseName);
        if (synapse == null)
            continue;
        MNode fused = new MVolatile();
        // Leave the original synapse part alone. Just duplicate it.
        fused.merge(synapse);
        fused.set("$metadata", "backend.lems.id", synapseName);
        MNode A = fused.set("A", "");
        A.merge(spikeSource);
        A.set("$metadata", "backend.lems.id", spikeSource.key());
        removeDependency(spikeSource, spikeSource.get("$inherit").replace("\"", ""));
        spikeSource.clear();
        spikeSource.merge(fused);
        addDependency(spikeSource, spikeSource.get("$inherit").replace("\"", ""));
        A = spikeSource.child("A");
        // Don't do "FromConnection", because we've already injected the part.
        addDependency(A, A.get("$inherit").replace("\"", ""));
        if (synapse.getInt("$count") == 0 && synapse.child("$lems") == null)
            kill.add(synapseName);
    }
    for (String k : kill) models.clear(modelName, k);
    // Select the prime model
    if (primaryModel.isEmpty()) {
        if (networks.size() == 1)
            primaryModel = networks.entrySet().iterator().next().getValue().id;
    // Otherwise there is no prime model. Could pick one arbitrarily (with preference for higher-level parts).
    // It may be cleaner to keep them all bundled as subparts and let the user pull them out as needed.
    }
    // System.out.println (models);  // Most useful for debugging structure.
    while (dependents.size() > 0) resolve(dependents.iterator().next());
    // Move heavy-weight parts into separate models
    Iterator<MNode> it = models.child(modelName).iterator();
    while (it.hasNext()) {
        MNode part = it.next();
        String key = part.key();
        int count = part.getInt("$count");
        boolean lems = part.child("$lems") != null;
        boolean proxyFound = part.get("$proxy").equals("found");
        part.clear("$count");
        part.clear("$connected");
        part.clear("$lems");
        part.clear("$lemsUses");
        part.clear("$proxy");
        if (count == 0 && lems && !key.equals(primaryModel))
            count = -3;
        if (count < 0) {
            if (count == -3 && !proxyFound) {
                MNode model = models.childOrCreate(modelName + " " + key);
                model.merge(part);
            }
            if (count > -4)
                it.remove();
        }
    }
    // Move primary model up to top level
    if (!primaryModel.isEmpty()) {
        MNode source = models.child(modelName, primaryModel);
        if (source == null)
            return;
        models.clear(modelName, primaryModel);
        for (MNode p : source) {
            MNode dest = models.childOrCreate(modelName, p.key());
            dest.merge(p);
        }
        models.set(modelName, "$metadata", "backend.lems.id", primaryModel);
    }
    if (models.child(modelName).size() == 0)
        models.clear(modelName);
    ExpressionParser.namedUnits = null;
}
Also used : ArrayList(java.util.ArrayList) MNode(gov.sandia.n2a.db.MNode) MVolatile(gov.sandia.n2a.db.MVolatile)

Example 59 with MNode

use of gov.sandia.n2a.db.MNode in project n2a by frothga.

the class ImportJob method findBasePart.

/**
 *        Locate the first parent in the inheritance hierarchy that resides in the models database rather than
 *        the current import.
 */
public MNode findBasePart(MNode part) {
    String inherit = part.get("$inherit").replace("\"", "");
    MNode result = models.child(modelName, inherit);
    // Prevent infinite loop on proxies.
    if (result == part)
        result = null;
    if (result != null)
        return findBasePart(result);
    // could be null
    return AppData.models.child(inherit);
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Example 60 with MNode

use of gov.sandia.n2a.db.MNode 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)

Aggregations

MNode (gov.sandia.n2a.db.MNode)63 Node (org.w3c.dom.Node)11 NameMap (gov.sandia.n2a.backend.neuroml.PartMap.NameMap)9 MVolatile (gov.sandia.n2a.db.MVolatile)5 MPart (gov.sandia.n2a.eqset.MPart)5 ArrayList (java.util.ArrayList)5 PanelModel (gov.sandia.n2a.ui.eq.PanelModel)4 MPersistent (gov.sandia.n2a.db.MPersistent)3 EquationSet (gov.sandia.n2a.eqset.EquationSet)3 Variable (gov.sandia.n2a.eqset.Variable)3 AccessVariable (gov.sandia.n2a.language.AccessVariable)3 PanelReference (gov.sandia.n2a.ui.ref.PanelReference)3 Element (org.w3c.dom.Element)3 NamedNodeMap (org.w3c.dom.NamedNodeMap)3 MDoc (gov.sandia.n2a.db.MDoc)2 ParseException (gov.sandia.n2a.language.ParseException)2 AddDoc (gov.sandia.n2a.ui.eq.undo.AddDoc)2 IOException (java.io.IOException)2 TreeMap (java.util.TreeMap)2 IncommensurableException (javax.measure.IncommensurableException)2