Search in sources :

Example 36 with RbmObservable

use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.

the class XmlReader method getRbmObservables.

private RbmObservable getRbmObservables(Element e, Model newModel) {
    String n = e.getAttributeValue(XMLTags.NameAttrTag);
    if (n == null || n.isEmpty()) {
        System.out.println("XMLReader: getRbmObservables: name is missing.");
        return null;
    }
    String t = e.getAttributeValue(XMLTags.RbmObservableTypeTag);
    if (t == null || t.isEmpty()) {
        System.out.println("XMLReader: getRbmObservables: type is missing.");
        return null;
    }
    RbmObservable.ObservableType ot = RbmObservable.ObservableType.Molecules;
    if (!t.equals(ot.name())) {
        ot = RbmObservable.ObservableType.Species;
    }
    Structure structure = null;
    String structureName = e.getAttributeValue(XMLTags.StructureAttrTag);
    if (structureName == null || structureName.isEmpty()) {
        // the tag is missing
        if (newModel.getStructures().length == 1) {
            // possible old single compartment model where we were not saving the structure for observable
            structure = newModel.getStructure(0);
        } else {
            throw new RuntimeException("XMLReader: structure missing for observable " + n);
        }
    } else {
        structure = newModel.getStructure(structureName);
    }
    RbmObservable o = new RbmObservable(newModel, n, structure, ot);
    // Sequence
    RbmObservable.Sequence se = RbmObservable.Sequence.Multimolecular;
    String ses = e.getAttributeValue(XMLTags.RbmObservableSequenceAttrTag);
    if (ses != null && ses.equals(RbmObservable.Sequence.PolymerLengthEqual.name())) {
        se = RbmObservable.Sequence.PolymerLengthEqual;
    } else if (ses != null && ses.equals(RbmObservable.Sequence.PolymerLengthGreater.name())) {
        se = RbmObservable.Sequence.PolymerLengthGreater;
    }
    o.setSequence(se);
    String lens = e.getAttributeValue(XMLTags.RbmObservableLenEqualAttrTag);
    if (lens != null) {
        // may be null for older models in which case the observable has default initial values
        int len = Integer.parseInt(lens);
        o.setSequenceLength(RbmObservable.Sequence.PolymerLengthEqual, len);
    }
    lens = e.getAttributeValue(XMLTags.RbmObservableLenGreaterAttrTag);
    if (lens != null) {
        int len = Integer.parseInt(lens);
        o.setSequenceLength(RbmObservable.Sequence.PolymerLengthGreater, len);
    }
    // Element element = e.getChild(XMLTags.RbmSpeciesPatternTag, vcNamespace);
    // SpeciesPattern sp = getSpeciesPattern(element, newModel);
    List<Element> children = e.getChildren(XMLTags.RbmSpeciesPatternTag, vcNamespace);
    for (Element e2 : children) {
        SpeciesPattern sp = getSpeciesPattern(e2, newModel);
        // setSpeciesPattern() will call resolveBonds()
        if (sp != null) {
            o.addSpeciesPattern(sp);
        }
    }
    return o;
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) Element(org.jdom.Element) Structure(cbit.vcell.model.Structure) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 37 with RbmObservable

use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.

the class RbmNetworkGenerator method writeObservables.

public static void writeObservables(PrintWriter writer, RbmModelContainer rbmModelContainer, CompartmentMode compartmentMode) {
    writer.println(BEGIN_OBSERVABLES);
    List<RbmObservable> observablesList = rbmModelContainer.getObservableList();
    for (RbmObservable oo : observablesList) {
        writer.println(RbmUtils.toBnglString(oo, compartmentMode));
    }
    writer.println(END_OBSERVABLES);
    writer.println();
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable)

Example 38 with RbmObservable

use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.

the class Xmlproducer method getXML.

// private Element getXMLShort(SpeciesPattern param) {
// Element e = new Element(XMLTags.RbmSpeciesPatternTag);
// e.setAttribute(XMLTags.NameAttrTag, mangle(param.getId()));
// return e;
// }
private Element getXML(RbmObservable param) {
    // if RbmObservableEmbedded we don't save the model or the structure
    // we know which they are once we use the XmlReader to recreate the object
    Element e = new Element(XMLTags.RbmObservableTag);
    e.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
    RbmObservable.ObservableType ot = param.getType();
    e.setAttribute(XMLTags.RbmObservableTypeTag, mangle(ot.name()));
    String sequenceName = param.getSequence().name();
    e.setAttribute(XMLTags.RbmObservableSequenceAttrTag, sequenceName);
    e.setAttribute(XMLTags.RbmObservableLenEqualAttrTag, "" + param.getSequenceLength(RbmObservable.Sequence.PolymerLengthEqual));
    e.setAttribute(XMLTags.RbmObservableLenGreaterAttrTag, "" + param.getSequenceLength(RbmObservable.Sequence.PolymerLengthGreater));
    e.setAttribute(XMLTags.StructureAttrTag, mangle(param.getStructure().getName()));
    // SpeciesPattern sp = param.getSpeciesPattern(0);
    // Element e1 = new Element(XMLTags.RbmSpeciesPatternTag);
    // e1.setAttribute(XMLTags.NameAttrTag, mangle(sp.getId()));
    // e.addContent(getXML(sp));
    List<SpeciesPattern> spl = param.getSpeciesPatternList();
    for (SpeciesPattern sp : spl) {
        e.addContent(getXML(sp));
    }
    return e;
}
Also used : Element(org.jdom.Element) RbmObservable(cbit.vcell.model.RbmObservable) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) VolumeParticleSpeciesPattern(cbit.vcell.math.VolumeParticleSpeciesPattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 39 with RbmObservable

use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.

the class RbmObservableTreeCellRenderer method getTreeCellRendererComponent.

@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    setBorder(null);
    if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObject = node.getUserObject();
        obj = userObject;
        String text = null;
        Icon icon = null;
        String toolTip = null;
        if (userObject instanceof RbmObservable) {
            RbmObservable ob = (RbmObservable) userObject;
            text = toHtml(ob);
            toolTip = toHtmlWithTip(ob);
            icon = VCellIcons.rbmObservableIcon;
        } else if (userObject instanceof SpeciesPatternLocal) {
            SpeciesPatternLocal spl = (SpeciesPatternLocal) userObject;
            text = toHtml(spl, true);
            toolTip = toHtmlWithTip(spl, true);
            icon = VCellIcons.rbmProductIcon;
        } else if (userObject instanceof MolecularTypePattern) {
            MolecularTypePattern molecularTypePattern = (MolecularTypePattern) userObject;
            text = toHtml(molecularTypePattern, true);
            toolTip = toHtmlWithTip(molecularTypePattern, true);
            if (owner == null) {
                icon = VCellIcons.rbmMolecularTypeSimpleIcon;
                ;
            } else {
                Graphics gc = owner.getGraphics();
                icon = new MolecularTypeSmallShape(1, 5, molecularTypePattern.getMolecularType(), null, gc, molecularTypePattern.getMolecularType(), null, issueManager);
            }
        } else if (userObject instanceof MolecularComponentPattern) {
            MolecularComponentPattern mcp = (MolecularComponentPattern) userObject;
            text = toHtml(mcp, true);
            toolTip = toHtmlWithTip(mcp, true);
            icon = VCellIcons.rbmComponentGrayIcon;
            if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
                icon = VCellIcons.rbmComponentGrayStateIcon;
            }
            if (mcp.isbVisible()) {
                icon = VCellIcons.rbmComponentGreenIcon;
                if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
                    icon = VCellIcons.rbmComponentGreenStateIcon;
                }
            }
            ComponentStatePattern csp = mcp.getComponentStatePattern();
            if (csp != null && !csp.isAny()) {
                icon = VCellIcons.rbmComponentGreenIcon;
                if (mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
                    icon = VCellIcons.rbmComponentGreenStateIcon;
                }
            }
            BioModelNode parent = (BioModelNode) ((BioModelNode) value).getParent().getParent().getParent();
            if (parent == null) {
                icon = VCellIcons.rbmComponentErrorIcon;
                return this;
            }
            Object parentObject = parent.getUserObject();
            if (!(parentObject instanceof RbmObservable)) {
                icon = VCellIcons.rbmComponentErrorIcon;
                return this;
            }
            if (hasErrorIssues((RbmObservable) parentObject, mcp, mcp.getMolecularComponent())) {
                icon = VCellIcons.rbmComponentErrorIcon;
            }
        } else if (userObject instanceof StateLocal) {
            StateLocal sl = (StateLocal) userObject;
            text = toHtml(sl, true);
            toolTip = toHtmlWithTip(sl, true);
            icon = VCellIcons.rbmComponentStateIcon;
        } else if (userObject instanceof BondLocal) {
            BondLocal bl = (BondLocal) userObject;
            text = toHtml(bl, sel);
            toolTip = toHtmlWithTip(bl, true);
            icon = VCellIcons.rbmBondIcon;
        } else {
            if (userObject != null) {
                System.out.println(userObject.toString());
                text = userObject.toString();
            } else {
                text = "null user object";
            }
        }
        setText(text);
        setIcon(icon);
        setToolTipText(toolTip == null ? text : toolTip);
    }
    return this;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) RbmObservable(cbit.vcell.model.RbmObservable) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) StateLocal(cbit.vcell.client.desktop.biomodel.RbmDefaultTreeModel.StateLocal) BioModelNode(cbit.vcell.desktop.BioModelNode) Graphics(java.awt.Graphics) MolecularTypeSmallShape(cbit.vcell.graph.MolecularTypeSmallShape) SpeciesPatternLocal(cbit.vcell.client.desktop.biomodel.RbmDefaultTreeModel.SpeciesPatternLocal) BondLocal(cbit.vcell.client.desktop.biomodel.RbmDefaultTreeModel.BondLocal) Icon(javax.swing.Icon) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Example 40 with RbmObservable

use of cbit.vcell.model.RbmObservable in project vcell by virtualcell.

the class RbmTreeCellEditor method getTreeCellEditorComponent.

@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
    Component component = null;
    realEditor = defaultCellEditor;
    if (value instanceof BioModelNode) {
        BioModelNode node = (BioModelNode) value;
        Object userObject = node.getUserObject();
        String text = null;
        Icon icon = null;
        if (userObject instanceof MolecularType) {
            text = ((MolecularType) userObject).getName();
            icon = VCellIcons.rbmMolecularTypeIcon;
        } else if (userObject instanceof MolecularTypePattern) {
            text = ((MolecularTypePattern) userObject).getMolecularType().getName();
            icon = VCellIcons.rbmMolecularTypeIcon;
        } else if (userObject instanceof MolecularComponent) {
            BioModelNode parentNode = (BioModelNode) node.getParent();
            Object parentObject = parentNode == null ? null : parentNode.getUserObject();
            // TODO: look for the proper icon
            icon = VCellIcons.rbmComponentErrorIcon;
            if (parentObject instanceof MolecularType) {
                text = ((MolecularComponent) userObject).getName();
            } else if (parentObject instanceof MolecularTypePattern) {
                realEditor = getMolecularComponentPatternCellEditor();
                getMolecularComponentPatternCellEditor().molecularTypePattern = ((MolecularTypePattern) parentObject);
                // find SpeciesPattern
                while (true) {
                    parentNode = (BioModelNode) parentNode.getParent();
                    if (parentNode == null) {
                        break;
                    }
                    if (parentNode.getUserObject() instanceof RbmObservable) {
                        ((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.observable;
                        getMolecularComponentPatternCellEditor().speciesPattern = ((RbmObservable) parentNode.getUserObject()).getSpeciesPattern(0);
                        break;
                    }
                    if (parentNode.getUserObject() instanceof ReactionRule) {
                        ((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.reaction;
                        ReactionRulePropertiesTreeModel tm = (ReactionRulePropertiesTreeModel) tree.getModel();
                        switch(tm.getParticipantType()) {
                            case Reactant:
                                getMolecularComponentPatternCellEditor().speciesPattern = ((ReactionRule) parentNode.getUserObject()).getReactantPattern(0).getSpeciesPattern();
                                break;
                            case Product:
                                getMolecularComponentPatternCellEditor().speciesPattern = ((ReactionRule) parentNode.getUserObject()).getProductPattern(0).getSpeciesPattern();
                                break;
                        }
                    }
                    if (parentNode.getUserObject() instanceof SpeciesContext) {
                        ((MolecularComponentPatternCellEditor) realEditor).owner = MolecularComponentPatternCellEditor.species;
                        getMolecularComponentPatternCellEditor().speciesPattern = ((SpeciesContext) parentNode.getUserObject()).getSpeciesPattern();
                        break;
                    }
                }
            }
        } else if (userObject instanceof ComponentStateDefinition) {
            text = ((ComponentStateDefinition) userObject).getName();
            icon = VCellIcons.rbmComponentStateIcon;
        } else if (userObject instanceof RbmObservable) {
            text = ((RbmObservable) userObject).getName();
            icon = VCellIcons.rbmObservableIcon;
        }
        renderer.setOpenIcon(icon);
        renderer.setClosedIcon(icon);
        renderer.setLeafIcon(icon);
        component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
        if (editingComponent instanceof JTextField) {
            JTextField textField = (JTextField) editingComponent;
            textField.setText(text);
        }
    }
    return component;
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) RbmObservable(cbit.vcell.model.RbmObservable) BioModelNode(cbit.vcell.desktop.BioModelNode) SpeciesContext(cbit.vcell.model.SpeciesContext) JTextField(javax.swing.JTextField) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) Icon(javax.swing.Icon) Component(java.awt.Component) MolecularComponent(org.vcell.model.rbm.MolecularComponent) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern)

Aggregations

RbmObservable (cbit.vcell.model.RbmObservable)50 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)22 ReactionRule (cbit.vcell.model.ReactionRule)20 SpeciesContext (cbit.vcell.model.SpeciesContext)18 Structure (cbit.vcell.model.Structure)16 ArrayList (java.util.ArrayList)15 MolecularType (org.vcell.model.rbm.MolecularType)14 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)10 ReactionStep (cbit.vcell.model.ReactionStep)9 PropertyVetoException (java.beans.PropertyVetoException)8 SimulationContext (cbit.vcell.mapping.SimulationContext)7 Model (cbit.vcell.model.Model)7 BioModel (cbit.vcell.biomodel.BioModel)6 ModelException (cbit.vcell.model.ModelException)6 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)5 ProductPattern (cbit.vcell.model.ProductPattern)5 ReactantPattern (cbit.vcell.model.ReactantPattern)5 BioModelNode (cbit.vcell.desktop.BioModelNode)4 BioPaxObject (org.vcell.pathway.BioPaxObject)4 StructureToolShapeIcon (cbit.vcell.graph.gui.StructureToolShapeIcon)3