Search in sources :

Example 76 with SpeciesPattern

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

the class ObservableTreeModel method populateTree.

public void populateTree() {
    if (observable == null || bioModel == null) {
        return;
    }
    rootNode.setUserObject(observable);
    rootNode.removeAllChildren();
    int count = 0;
    for (SpeciesPattern sp : observable.getSpeciesPatternList()) {
        BioModelNode spNode = new BioModelNode(new SpeciesPatternLocal(sp, ++count));
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            BioModelNode node = createMolecularTypePatternNode(mtp);
            spNode.add(node);
        }
        rootNode.add(spNode);
    }
    nodeStructureChanged(rootNode);
    // GuiUtils.treeExpandAll(ownerTree, rootNode, true);
    GuiUtils.treeExpandAllRows(ownerTree);
    observable.firePropertyChange("entityChange", null, "bbb");
}
Also used : BioModelNode(cbit.vcell.desktop.BioModelNode) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 77 with SpeciesPattern

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

the class ObservableTreeModel method setObservable.

public void setObservable(RbmObservable newValue) {
    if (newValue == observable) {
        return;
    }
    RbmObservable oldValue = observable;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(this);
        for (SpeciesPattern speciesPattern : oldValue.getSpeciesPatternList()) {
            RbmUtils.removePropertyChangeListener(speciesPattern, this);
        }
    }
    observable = newValue;
    if (newValue != null) {
        newValue.addPropertyChangeListener(this);
        for (SpeciesPattern speciesPattern : newValue.getSpeciesPatternList()) {
            RbmUtils.addPropertyChangeListener(speciesPattern, this);
        }
    }
    populateTree();
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 78 with SpeciesPattern

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

the class ObservableTreeModel method propertyChange.

public void propertyChange(PropertyChangeEvent evt) {
    if (evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_NAME)) {
        nodeChanged(rootNode);
    } else if (evt.getSource() == observable && evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_TYPE)) {
        nodeChanged(rootNode);
    } else if (evt.getPropertyName().equals("entityChange")) {
        nodeChanged(rootNode);
    } else {
        populateTree();
        Object source = evt.getSource();
        if (source == observable) {
            if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN_LIST)) {
                List<SpeciesPattern> oldValue = (List<SpeciesPattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (SpeciesPattern sp : oldValue) {
                        RbmUtils.removePropertyChangeListener(sp, this);
                    }
                }
                List<SpeciesPattern> newValue = (List<SpeciesPattern>) evt.getNewValue();
                if (newValue != null) {
                    for (SpeciesPattern sp : newValue) {
                        RbmUtils.addPropertyChangeListener(sp, this);
                    }
                }
            } else if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN)) {
                SpeciesPattern newValue = (SpeciesPattern) evt.getNewValue();
                if (newValue != null) {
                    RbmUtils.addPropertyChangeListener(newValue, this);
                }
            }
        } else if (source instanceof SpeciesPattern) {
            if (evt.getPropertyName().equals(SpeciesPattern.PROPERTY_NAME_MOLECULAR_TYPE_PATTERNS)) {
                List<MolecularTypePattern> oldValue = (List<MolecularTypePattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (MolecularTypePattern mtp : oldValue) {
                        RbmUtils.removePropertyChangeListener(mtp, this);
                    }
                }
                List<MolecularTypePattern> newValue = (List<MolecularTypePattern>) evt.getNewValue();
                if (newValue != null) {
                    for (MolecularTypePattern mtp : newValue) {
                        RbmUtils.addPropertyChangeListener(mtp, this);
                    }
                }
            }
        } else if (source instanceof MolecularTypePattern) {
            if (evt.getPropertyName().equals(MolecularTypePattern.PROPERTY_NAME_COMPONENT_PATTERN_LIST)) {
                List<MolecularComponentPattern> oldValue = (List<MolecularComponentPattern>) evt.getOldValue();
                if (oldValue != null) {
                    for (MolecularComponentPattern mcp : oldValue) {
                        RbmUtils.removePropertyChangeListener(mcp, this);
                    }
                }
                List<MolecularComponentPattern> newValue = (List<MolecularComponentPattern>) evt.getNewValue();
                if (newValue != null) {
                    for (MolecularComponentPattern mcp : newValue) {
                        RbmUtils.addPropertyChangeListener(mcp, this);
                    }
                }
            }
        } else if (source instanceof MolecularComponentPattern) {
            if (evt.getSource().equals(MolecularComponentPattern.PROPERTY_NAME_COMPONENT_STATE)) {
                ComponentStateDefinition oldValue = (ComponentStateDefinition) evt.getOldValue();
                if (oldValue != null) {
                    oldValue.removePropertyChangeListener(this);
                }
                ComponentStateDefinition newValue = (ComponentStateDefinition) evt.getNewValue();
                if (newValue != null) {
                    newValue.addPropertyChangeListener(this);
                }
            }
        }
    }
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) List(java.util.List) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 79 with SpeciesPattern

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

the class RbmObservable method gatherIssues.

public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
    issueContext = issueContext.newChildContext(ContextType.RbmObservable, this);
    if (name == null) {
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Name of Observable is null", Issue.SEVERITY_ERROR));
    } else if (name.equals("")) {
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Name of Observable is empty", Issue.SEVERITY_WARNING));
    } else {
        if (speciesPatternList == null) {
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Species Pattern List is null", Issue.SEVERITY_ERROR));
        } else if (speciesPatternList.isEmpty()) {
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Species Pattern List is empty", Issue.SEVERITY_WARNING));
        } else {
            for (SpeciesPattern sp : speciesPatternList) {
                sp.checkSpeciesPattern(issueContext, issueList);
                sp.gatherIssues(issueContext, issueList);
                for (MolecularTypePattern mtpThis : sp.getMolecularTypePatterns()) {
                    checkComponentStateConsistency(issueContext, issueList, mtpThis);
                }
            }
        }
        if (type == null) {
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Type is null", Issue.SEVERITY_ERROR));
        }
    }
    for (SpeciesPattern sp : speciesPatternList) {
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            String name = mtp.getMolecularType().getDisplayName().toLowerCase();
            if (name.equals("trash")) {
                String message = "'Trash' is a reserved NFSim keyword and it cannot be used as an observable.";
                issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
        }
    }
    // ---------------------------------------- polymer notation restrictions
    // polymer notation may only contain one species pattern and one type of molecule
    boolean polymerAllowedSingle = true;
    // ---------------,,---------------- molecules in trivial state (question marks for bonds and states)
    boolean polymerAllowedSimple = true;
    if (speciesPatternList.size() > 1) {
        polymerAllowedSingle = false;
    }
    if (speciesPatternList.size() > 0) {
        SpeciesPattern sp = speciesPatternList.get(0);
        if (sp != null && !sp.getMolecularTypePatterns().isEmpty()) {
            if (sp.getMolecularTypePatterns().size() > 1) {
                polymerAllowedSingle = false;
            } else {
                MolecularTypePattern mtp = sp.getMolecularTypePatterns().get(0);
                if (mtp != null) {
                    for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                        if (mcp.isbVisible()) {
                            polymerAllowedSimple = false;
                            break;
                        }
                    }
                }
            }
        }
    }
    if (!polymerAllowedSingle && sequence != Sequence.Multimolecular) {
        String message = "Polymer may only be specified for Observable containing a single Molecule.";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
    } else if (!polymerAllowedSimple && sequence != Sequence.Multimolecular) {
        String message = "Polymer may only be specified for Observable with all bonds set to 'Possible' and all States set to 'Any'";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
    }
    if (sequence != Sequence.Multimolecular && type == ObservableType.Molecules) {
        String message = "The Polymer Observable must be of type 'Species'.";
        issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
    }
    if (name.equalsIgnoreCase("Rg3")) {
        System.out.println(name);
    }
    for (SpeciesPattern sp : speciesPatternList) {
        // we look for species patterns where the polymer notation would be more suitable
        Set<String> moleculeNames = new HashSet<>();
        boolean isTrivial = true;
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            moleculeNames.add(mtp.getMolecularType().getDisplayName());
            for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
                if (mcp.isbVisible()) {
                    isTrivial = false;
                    // we may have more than 1 sp in the observable, check them all
                    continue;
                }
            }
        }
        if (isTrivial && sp.getMolecularTypePatterns().size() > 1 && moleculeNames.size() == 1) {
            String message = "Please use the Polymer notation (i.e. " + moleculeNames.toArray()[0] + "()>" + (sp.getMolecularTypePatterns().size() - 1) + " ) ";
            message += "instead of " + sp.toString();
            issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            // if we find one sp that is suitable for polymer notation we stop here and don't check other sp
            break;
        }
    }
}
Also used : Issue(org.vcell.util.Issue) MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) HashSet(java.util.HashSet)

Example 80 with SpeciesPattern

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

the class RbmObservable method deleteStateFromPatterns.

public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
    for (SpeciesPattern sp : getSpeciesPatternList()) {
        for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
            if (mtp.getMolecularType() == mt) {
                List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
                for (MolecularComponentPattern mcp : componentPatterns) {
                    if (!(mcp.getMolecularComponent() == mc)) {
                        continue;
                    }
                    ComponentStatePattern csp = mcp.getComponentStatePattern();
                    if (csp == null) {
                        continue;
                    }
                    if (csp.isAny()) {
                        if (mc.getComponentStateDefinitions().size() == 1) {
                            mcp.setComponentStatePattern(null);
                        }
                        continue;
                    }
                    if (csp.getComponentStateDefinition() == csd) {
                        if (mc.getComponentStateDefinitions().size() == 1) {
                            // we are about to delete the last possible state, so we set the ComponentStatePattern to null
                            mcp.setComponentStatePattern(null);
                        } else {
                            // some other state is still available, we set the ComponentStatePattern to Any and let the user deal with it
                            csp = new ComponentStatePattern();
                            mcp.setComponentStatePattern(csp);
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) ComponentStatePattern(org.vcell.model.rbm.ComponentStatePattern) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)93 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)39 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)30 MolecularType (org.vcell.model.rbm.MolecularType)25 RbmObservable (cbit.vcell.model.RbmObservable)22 SpeciesContext (cbit.vcell.model.SpeciesContext)22 Structure (cbit.vcell.model.Structure)22 Point (java.awt.Point)18 ReactionRule (cbit.vcell.model.ReactionRule)16 ArrayList (java.util.ArrayList)16 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)16 Graphics (java.awt.Graphics)13 PropertyVetoException (java.beans.PropertyVetoException)13 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)12 ProductPattern (cbit.vcell.model.ProductPattern)12 ReactantPattern (cbit.vcell.model.ReactantPattern)12 Dimension (java.awt.Dimension)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)12 Model (cbit.vcell.model.Model)11 ModelException (cbit.vcell.model.ModelException)11