Search in sources :

Example 16 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class XmlReader method getRbmMolecularComponentPattern.

private MolecularComponentPattern getRbmMolecularComponentPattern(Element e, MolecularTypePattern mtp, MolecularType mt, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    String s = e.getAttributeValue(XMLTags.RbmMolecularComponentTag);
    if (s == null || s.isEmpty()) {
        System.out.println("XMLReader: getRbmMolecularComponentPattern: MolecularComponent name is missing.");
        return null;
    }
    MolecularComponent c = mt.getMolecularComponent(s);
    if (c == null) {
        System.out.println("XMLReader: getRbmMolecularComponentPattern: encountered reference " + s + " to non-existing MolecularComponent.");
        return null;
    }
    ComponentStatePattern csp = new ComponentStatePattern();
    MolecularComponentPattern mcp = new MolecularComponentPattern(c);
    s = e.getAttributeValue(XMLTags.RbmMolecularComponentStatePatternTag);
    if (s != null && !s.isEmpty()) {
        // state may be missing, we set it only if is present
        ComponentStateDefinition cs = c.getComponentStateDefinition(s);
        if (cs == null) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: encountered reference " + s + " to non-existing MolecularComponentState.");
            return null;
        }
        csp = new ComponentStatePattern(cs);
        mcp.setComponentStatePattern(csp);
    }
    // s = e.getAttributeValue(XMLTags.RbmMolecularTypeAnyTag);
    // if(s!=null && !s.isEmpty()) {
    // boolean any = Boolean.parseBoolean(s);
    // csp.setAny(any);
    // }
    s = e.getAttributeValue(XMLTags.RbmBondTypeAttrTag);
    BondType bondType = BondType.fromSymbol(s);
    if (bondType == BondType.Specified) {
        int bondId = Integer.parseInt(s);
        mcp.setBondId(bondId);
    }
    mcp.setBondType(bondType);
    // sanity check, we only read the names here and make sure they make sense
    Element bondElement = e.getChild(XMLTags.RbmBondTag, vcNamespace);
    if (bondElement != null) {
        // it's actually the name of the MolecularType inside this pattern
        String molecularTypeName = bondElement.getAttributeValue(XMLTags.RbmMolecularTypePatternTag);
        String molecularComponentName = bondElement.getAttributeValue(XMLTags.RbmMolecularComponentPatternTag);
        if (molecularTypeName == null || molecularTypeName.isEmpty()) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: Bond Attribute molecularTypeName missing.");
            return mcp;
        }
        if (molecularComponentName == null || molecularComponentName.isEmpty()) {
            System.out.println("XMLReader: getRbmMolecularComponentPattern: Bond Attribute molecularComponentName missing.");
            return mcp;
        }
        // we'll have a bond here, it will be properly initialized during RbmObservable.resolveBonds() call  !!!
        Bond bond = new Bond();
        mcp.setBond(bond);
    }
    return mcp;
}
Also used : BondType(org.vcell.model.rbm.MolecularComponentPattern.BondType) ParticleBondType(cbit.vcell.math.ParticleMolecularComponentPattern.ParticleBondType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ParticleMolecularComponent(cbit.vcell.math.ParticleMolecularComponent) MolecularComponent(org.vcell.model.rbm.MolecularComponent) ParticleMolecularComponentPattern(cbit.vcell.math.ParticleMolecularComponentPattern) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ParticleComponentStatePattern(cbit.vcell.math.ParticleComponentStatePattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) Element(org.jdom.Element) Bond(org.vcell.model.rbm.SpeciesPattern.Bond) ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 17 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class XmlReader method getRbmComponentStateDefinition.

private ComponentStateDefinition getRbmComponentStateDefinition(Element e, Model newModel) {
    String s = e.getAttributeValue(XMLTags.NameAttrTag);
    if (s == null || s.isEmpty()) {
        System.out.println("XMLReader: getRbmComponentState: name is missing.");
        return null;
    }
    ComponentStateDefinition cs = new ComponentStateDefinition(s);
    // }
    return cs;
}
Also used : ParticleComponentStateDefinition(cbit.vcell.math.ParticleComponentStateDefinition) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 18 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class MolecularTypePropertiesPanel method addNewFromTree.

public void addNewFromTree() {
    Object obj = molecularTypeTree.getLastSelectedPathComponent();
    if (obj == null || !(obj instanceof BioModelNode)) {
        return;
    }
    BioModelNode selectedNode = (BioModelNode) obj;
    Object selectedUserObject = selectedNode.getUserObject();
    if (selectedUserObject == molecularType) {
        MolecularComponent molecularComponent = molecularType.createMolecularComponent();
        molecularType.addMolecularComponent(molecularComponent);
        bioModel.getModel().getRbmModelContainer().adjustSpeciesContextPatterns(molecularType, molecularComponent);
        bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent);
        bioModel.getModel().getRbmModelContainer().adjustRulesPatterns(molecularType, molecularComponent);
        molecularTypeTree.startEditingAtPath(molecularTypeTreeModel.findObjectPath(null, molecularComponent));
    } else if (selectedUserObject instanceof MolecularComponent) {
        MolecularComponent molecularComponent = (MolecularComponent) selectedUserObject;
        ComponentStateDefinition componentStateDefinition = molecularComponent.createComponentStateDefinition();
        molecularComponent.addComponentStateDefinition(componentStateDefinition);
        bioModel.getModel().getRbmModelContainer().adjustObservablesPatterns(molecularType, molecularComponent, componentStateDefinition);
        molecularTypeTree.startEditingAtPath(molecularTypeTreeModel.findObjectPath(null, componentStateDefinition));
    }
}
Also used : MolecularComponent(org.vcell.model.rbm.MolecularComponent) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) BioModelNode(cbit.vcell.desktop.BioModelNode) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 19 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class MolecularTypePropertiesPanel method deleteFromTree.

public void deleteFromTree() {
    Object obj = molecularTypeTree.getLastSelectedPathComponent();
    if (obj == null || !(obj instanceof BioModelNode)) {
        return;
    }
    BioModelNode selectedNode = (BioModelNode) obj;
    TreeNode parent = selectedNode.getParent();
    if (!(parent instanceof BioModelNode)) {
        return;
    }
    BioModelNode parentNode = (BioModelNode) parent;
    Object selectedUserObject = selectedNode.getUserObject();
    if (selectedUserObject instanceof MolecularComponent) {
        MolecularComponent mc = (MolecularComponent) selectedUserObject;
        Object userObject = parentNode.getUserObject();
        if (userObject instanceof MolecularType) {
            MolecularType mt = (MolecularType) userObject;
            // detailed verifications will be done there, to see if they are being used in reactions, species, observables
            if (!mc.getComponentStateDefinitions().isEmpty()) {
                String[] options = { "OK" };
                String errMsg = mc.getDisplayType() + " '<b>" + mc.getDisplayName() + "</b>' cannot be deleted because it contains explicit States.";
                errMsg += "<br>Please delete each individual State first.";
                errMsg += "<br><br>Detailed usage information will be provided at that time to help you decide.";
                errMsg = "<html>" + errMsg + "</html>";
                JOptionPane.showOptionDialog(this.getParent().getParent(), errMsg, "Delete " + mc.getDisplayType(), JOptionPane.NO_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[0]);
                return;
            }
            // we find and display component usage information to help the user decide
            Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
            bioModel.getModel().getRbmModelContainer().findComponentUsage(mt, mc, usedHere);
            if (!usedHere.isEmpty()) {
                String errMsg = mc.dependenciesToHtml(usedHere);
                errMsg += "<br><br>Delete anyway?";
                errMsg = "<html>" + errMsg + "</html>";
                int dialogButton = JOptionPane.YES_NO_OPTION;
                int returnCode = JOptionPane.showConfirmDialog(this.getParent().getParent(), errMsg, "Delete " + mc.getDisplayType(), dialogButton);
                if (returnCode == JOptionPane.YES_OPTION) {
                    // keep this code in sync with MolecularTypeTableModel.setValueAt
                    if (bioModel.getModel().getRbmModelContainer().delete(mt, mc) == true) {
                        mt.removeMolecularComponent(mc);
                    }
                } else {
                    return;
                }
            } else {
                if (bioModel.getModel().getRbmModelContainer().delete(mt, mc) == true) {
                    mt.removeMolecularComponent(mc);
                }
            }
        }
    } else if (selectedUserObject instanceof ComponentStateDefinition) {
        ComponentStateDefinition csd = (ComponentStateDefinition) selectedUserObject;
        Object userObject = parentNode.getUserObject();
        if (!(userObject instanceof MolecularComponent)) {
            System.out.println("Unexpected parent in tree hierarchy for " + ComponentStateDefinition.typeName + " " + csd.getDisplayName() + "!");
            return;
        }
        MolecularComponent mc = (MolecularComponent) userObject;
        TreeNode grandParent = parentNode.getParent();
        BioModelNode grandParentNode = (BioModelNode) grandParent;
        userObject = grandParentNode.getUserObject();
        if (!(userObject instanceof MolecularType)) {
            System.out.println("Unexpected parent in tree hierarchy for " + mc.getDisplayType() + " " + mc.getDisplayName() + "!");
            return;
        }
        MolecularType mt = (MolecularType) userObject;
        Map<String, Pair<Displayable, SpeciesPattern>> usedHere = new LinkedHashMap<String, Pair<Displayable, SpeciesPattern>>();
        bioModel.getModel().getRbmModelContainer().findStateUsage(mt, mc, csd, usedHere);
        if (!usedHere.isEmpty()) {
            String errMsg = csd.dependenciesToHtml(usedHere);
            errMsg += "<br><br>Delete anyway?";
            errMsg = "<html>" + errMsg + "</html>";
            int dialogButton = JOptionPane.YES_NO_OPTION;
            int returnCode = JOptionPane.showConfirmDialog(this.getParent().getParent(), errMsg, "Delete " + ComponentStateDefinition.typeName, dialogButton);
            if (returnCode == JOptionPane.YES_OPTION) {
                // keep this code in sync with MolecularTypeTableModel.setValueAt
                if (bioModel.getModel().getRbmModelContainer().delete(mt, mc, csd) == true) {
                    // this stays
                    mc.deleteComponentStateDefinition(csd);
                }
            } else {
                return;
            }
        } else {
            if (bioModel.getModel().getRbmModelContainer().delete(mt, mc, csd) == true) {
                // this stays
                mc.deleteComponentStateDefinition(csd);
            }
        }
    // mc.deleteComponentStateDefinition(csd);
    }
}
Also used : Displayable(org.vcell.util.Displayable) BioModelNode(cbit.vcell.desktop.BioModelNode) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point) LinkedHashMap(java.util.LinkedHashMap) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition) MolecularType(org.vcell.model.rbm.MolecularType) MolecularComponent(org.vcell.model.rbm.MolecularComponent) TreeNode(javax.swing.tree.TreeNode) RelationshipObject(org.vcell.relationship.RelationshipObject) BioPaxObject(org.vcell.pathway.BioPaxObject) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) ActionMap(javax.swing.ActionMap) InputMap(javax.swing.InputMap) Pair(org.vcell.util.Pair)

Example 20 with ComponentStateDefinition

use of org.vcell.model.rbm.ComponentStateDefinition in project vcell by virtualcell.

the class MolecularTypeTableModel method pattern.

private String pattern(MolecularType molecularType) {
    String str = molecularType.getName() + "(";
    List<MolecularComponent> mcl = molecularType.getComponentList();
    for (int i = 0; i < mcl.size(); i++) {
        MolecularComponent mc = mcl.get(i);
        str += mc.getName();
        List<ComponentStateDefinition> csdl = mc.getComponentStateDefinitions();
        for (int j = 0; j < csdl.size(); j++) {
            ComponentStateDefinition cs = csdl.get(j);
            str += "~" + cs.getName();
        }
        if (i < mcl.size() - 1) {
            str += ",";
        }
    }
    str += ")";
    return str;
}
Also used : MolecularComponent(org.vcell.model.rbm.MolecularComponent) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Aggregations

ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)31 MolecularComponent (org.vcell.model.rbm.MolecularComponent)23 MolecularType (org.vcell.model.rbm.MolecularType)15 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)12 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)10 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)10 BioModelNode (cbit.vcell.desktop.BioModelNode)8 LinkedHashMap (java.util.LinkedHashMap)7 Icon (javax.swing.Icon)7 Point (java.awt.Point)6 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)6 ParticleComponentStateDefinition (cbit.vcell.math.ParticleComponentStateDefinition)5 List (java.util.List)5 Graphics (java.awt.Graphics)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 JMenuItem (javax.swing.JMenuItem)4 BondType (org.vcell.model.rbm.MolecularComponentPattern.BondType)4 Bond (org.vcell.model.rbm.SpeciesPattern.Bond)4 BioPaxObject (org.vcell.pathway.BioPaxObject)4