Search in sources :

Example 21 with MNode

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

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

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

the class ImportJob method removeDependency.

public void removeDependency(MNode part, String inherit) {
    dependents.remove(part);
    MNode component = models.child(modelName, inherit);
    if (component == null)
        return;
    int count = component.getInt("$count") - 1;
    if (count > 0) {
        component.set("$count", count);
    } else {
        component.clear("$count");
        component.clear("$connected");
        component.clear("$lemsUses");
        // This is a proxy part created because a model is missing from the repo.
        if (component.size() == 0)
            models.clear(modelName, inherit);
    }
}
Also used : MNode(gov.sandia.n2a.db.MNode)

Example 24 with MNode

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

the class ImportJob method remap.

public void remap(MNode part, NameMap nameMap) {
    MNode temp = new MVolatile();
    temp.merge(part);
    part.clear();
    for (MNode v : temp) {
        String key = nameMap.importName(v.key());
        part.set(key, v);
    }
}
Also used : MNode(gov.sandia.n2a.db.MNode) MVolatile(gov.sandia.n2a.db.MVolatile)

Example 25 with MNode

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

the class ImportJob method neuroml.

public void neuroml(Node node) {
    File source = sources.getLast();
    if (modelName.isEmpty()) {
        modelName = getAttribute(node, "id");
        if (// then get it from the filename
        modelName.isEmpty()) {
            modelName = source.getName();
            int index = modelName.lastIndexOf('.');
            if (index > 0)
                modelName = modelName.substring(0, index);
        }
        modelName = NodePart.validIdentifierFrom(modelName);
        // Preemptively scan for unique name, so our references to any sibling parts remain valid.
        // IE: a name collision in the main part implies that sibling parts will also have name collisions.
        modelName = AddDoc.uniqueName(modelName);
    }
    MNode model = models.childOrCreate(modelName);
    String description = getAttribute(node, "description");
    if (!description.isEmpty())
        model.set("$metadata", "description", description);
    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {
        if (child.getNodeType() != Node.ELEMENT_NODE)
            continue;
        switch(child.getNodeName()) {
            case // NeuroML include
            "include":
                // TODO: what if href actually references a web document?
                File nextSource = new File(source.getParentFile(), getAttribute(child, "href"));
                process(nextSource);
                break;
            case // LEMS include
            "Include":
                nextSource = new File(source.getParentFile(), getAttribute(child, "file"));
                process(nextSource);
                break;
            // NeuroML ---------------------------------------------------
            case "intracellularProperties":
            case "extracellularProperties":
                properties.put(getAttribute(child, "id"), child);
                break;
            case "morphology":
                morphologies.put(getAttribute(child, "id"), child);
                break;
            case "ionChannel":
            case "ionChannelHH":
            case "ionChannelKS":
                ionChannel(child);
                break;
            case "decayingPoolConcentrationModel":
            case "fixedFactorConcentrationModel":
            case // This tag appears in Cells.xml, but not in NeuroML_v2beta4.xsd
            "fixedFactorConcentrationModelTraub":
                concentrationModel(child);
                break;
            case "blockingPlasticSynapse":
                blockingPlasticSynapse(child);
                break;
            case "biophysicalProperties":
                biophysics.put(getAttribute(child, "id"), child);
                break;
            case "cell":
                Cell cell = new Cell(child);
                cells.put(cell.id, cell);
                break;
            case "fitzHughNagumoCell":
                MNode FN = genericPart(child, model);
                // Force time-scale to match the hard-coded value in LEMS definitions.
                FN.set("TS", "1s");
                break;
            case "poissonFiringSynapse":
            case "transientPoissonFiringSynapse":
            case "spikeArray":
            case "timedSynapticInput":
                spikingSynapse(child);
                break;
            case "compoundInput":
                compoundInput(child);
                break;
            case "network":
                Network network = new Network(child);
                networks.put(network.id, network);
                break;
            // LEMS ------------------------------------------------------
            case "Target":
                target(child);
                break;
            case "Dimension":
                dimension(child);
                break;
            case "Unit":
                unit(child);
                break;
            case "Constant":
                // Create a bogus component to wrap the top level, so we can add a LEMS constant to it.
                new ComponentType(model).genericVariable(child, "");
                break;
            case "ComponentType":
                ComponentType component = new ComponentType(child);
                components.put(component.part.key(), component);
                break;
            case "Simulation":
                simulation(child);
                break;
            case "Component":
            default:
                // Any NeuroML part not specifically processed above will fall through to here.
                genericPart(child, model);
                break;
        }
    }
}
Also used : Node(org.w3c.dom.Node) MNode(gov.sandia.n2a.db.MNode) File(java.io.File) 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