Search in sources :

Example 36 with ReactionRule

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

the class ParticipantSignatureShapePanel method refreshRuleAnalysis.

private void refreshRuleAnalysis() {
    reportMap.clear();
    modelRuleEntryMap.clear();
    bRuleAnalysisFailedMap.clear();
    if (reactionRuleMap == null || reactionRuleMap.isEmpty()) {
        return;
    }
    for (Map.Entry<String, ReactionRule> entry : reactionRuleMap.entrySet()) {
        String key = entry.getKey();
        ReactionRule rr = entry.getValue();
        ModelRuleFactory factory = new ModelRuleFactory();
        ModelRuleEntry modelRuleEntry = factory.createRuleEntry(rr, 0, ReactionRuleDirection.forward);
        try {
            RuleAnalysisReport report = RuleAnalysis.analyze(modelRuleEntry, false);
            reportMap.put(key, report);
            modelRuleEntryMap.put(key, modelRuleEntry);
            bRuleAnalysisFailedMap.put(key, false);
        } catch (Exception e) {
            e.printStackTrace();
            System.err.println("exception computing RuleAnalysis report for " + key + ": " + e.getMessage());
            bRuleAnalysisFailedMap.put(key, true);
            bRuleAnalysisFailed = true;
        }
    }
}
Also used : ModelRuleFactory(cbit.vcell.model.ModelRuleFactory) RuleAnalysisReport(org.vcell.model.rbm.RuleAnalysisReport) ModelRuleEntry(cbit.vcell.model.ModelRuleFactory.ModelRuleEntry) ReactionRule(cbit.vcell.model.ReactionRule) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 37 with ReactionRule

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

the class BioCartoonTool method pasteReactionsAndRules.

public static final void pasteReactionsAndRules(Component requester, ReactionSpeciesCopy rsCopy, Model pasteModel, Structure structTo, RXPasteInterface rxPasteInterface) {
    PasteHelper[] pasteHelper = new PasteHelper[1];
    AsynchClientTask issueTask = new AsynchClientTask("Checking Issues...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Model clonedModel = (Model) org.vcell.util.BeanUtils.cloneSerializable(pasteModel);
            clonedModel.refreshDependencies();
            // Model clonedModel = pasteModel;
            IssueContext issueContext = new IssueContext(ContextType.Model, clonedModel, null);
            Vector<Issue> issues = new Vector<>();
            checkStructuresCompatibility(rsCopy, clonedModel, structTo, issues, issueContext);
            Set<MolecularType> mtFromListStrict = getMoleculesFromStrict(rsCopy, clonedModel, issues, issueContext);
            if (issues.size() != 0) {
                // at this point we can only have fatal error issues or no issues at all
                if (!printIssues(issues, requester)) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
            }
            // map all the structures of the reactions, rules and their participants to existing structures, at need make new structures
            // key is the "from" structure, value is the name of the equivalent "to" structure
            // on the first position we have the struct from where we copy (key) and the struct where we paste (value)
            Map<Structure, String> structuresMap;
            if (rsCopy.getStructuresArr().length > 1) {
                // throws CANCEL_GENERIC if the user cancels
                structuresMap = mapStructures(requester, rsCopy, clonedModel, structTo, issueContext);
            } else {
                // if length == 1 it's just structFrom which automatically maps to structTo
                structuresMap = new LinkedHashMap<>();
                structuresMap.put(rsCopy.getFromStructure(), structTo.getName());
            }
            pasteMolecules(mtFromListStrict, clonedModel, structuresMap);
            List<ReactionRule> rulesTo = pasteRules(rsCopy, clonedModel, structTo, issues, issueContext, structuresMap);
            // for(ReactionRule rr : rulesTo) {
            // clonedModel.getRbmModelContainer().addReactionRule(rr);
            // }
            clonedModel.getRbmModelContainer().addReactionRules(rulesTo);
            // TODO: make any final verifications in the cloned model here
            // if anything is wrong exit here with some helpful message
            // .....
            // otherwise go directly to populating the real model
            mapStructures(structuresMap, pasteModel);
            pasteMolecules(mtFromListStrict, pasteModel, structuresMap);
            // we repeat all the steps to paste the rules in the real model instead of the clone
            rulesTo = pasteRules(rsCopy, pasteModel, structTo, issues, issueContext, structuresMap);
            // for(ReactionRule rr : rulesTo) {
            // pasteModel.getRbmModelContainer().addReactionRule(rr);
            // }
            pasteModel.getRbmModelContainer().addReactionRules(rulesTo);
            System.out.println("done");
        }
    };
    AsynchClientTask pasteRXTask = new AsynchClientTask("Pasting Reaction...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            IssueContext issueContext = new IssueContext(ContextType.Model, pasteModel, null);
        // if (pasteHelper[0].issues.size() != 0) {
        // printIssues(pasteHelper[0].issues, requester);
        // }
        // if(rxPasteInterface != null){
        // for(BioModelEntityObject newBioModelEntityObject:pasteHelper[0].reactionsAndSpeciesContexts.keySet()) {
        // ReactionCartoonTool.copyRelativePosition(rxPasteInterface.getGraphPane().getGraphModel(), pasteHelper[0].reactionsAndSpeciesContexts.get(newBioModelEntityObject), newBioModelEntityObject);
        // }
        // ReactionCartoonTool.selectAndSaveDiagram(rxPasteInterface, new ArrayList<BioModelEntityObject>(pasteHelper[0].reactionsAndSpeciesContexts.keySet()));
        // //					//Setup to allow dispatcher to set focus on a specified component after it closes the ProgressPopup
        // setFinalWindow(hashTable, rxPasteInterface.getGraphPane());
        // }
        }
    };
    ClientTaskDispatcher.dispatch(requester, new Hashtable<>(), new AsynchClientTask[] { issueTask, pasteRXTask }, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Issue(org.vcell.util.Issue) ReactionRule(cbit.vcell.model.ReactionRule) Hashtable(java.util.Hashtable) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) IssueContext(org.vcell.util.IssueContext) Structure(cbit.vcell.model.Structure) Vector(java.util.Vector)

Example 38 with ReactionRule

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

the class ParticipantSignatureShapePanel method hasBondChanged.

public RuleAnalysisChanged hasBondChanged(String key, MolecularComponentPattern molecularComponentPattern) {
    ReactionRule reactionRule = reactionRuleMap.get(key);
    if (reactionRule == null) {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
    ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
    RuleAnalysisReport report = reportMap.get(key);
    if (modelRuleEntry == null || report == null) {
        System.out.println("modelRuleEntry == null || report == null,  NOT GOOD!");
    // refreshRuleAnalysis();
    }
    if (!bRuleAnalysisFailed && report != null) {
        MolecularComponentEntry molecularComponentEntry = modelRuleEntry.findMolecularComponentEntry(molecularComponentPattern);
        if (report.hasBondChanged(molecularComponentEntry)) {
            return RuleAnalysisChanged.CHANGED;
        } else {
            return RuleAnalysisChanged.UNCHANGED;
        }
    } else {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
}
Also used : RuleAnalysisReport(org.vcell.model.rbm.RuleAnalysisReport) ModelRuleEntry(cbit.vcell.model.ModelRuleFactory.ModelRuleEntry) ReactionRule(cbit.vcell.model.ReactionRule) MolecularComponentEntry(org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry)

Example 39 with ReactionRule

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

the class ParticipantSignatureShapePanel method hasStateChanged.

public RuleAnalysisChanged hasStateChanged(String key, MolecularComponentPattern molecularComponentPattern) {
    ReactionRule reactionRule = reactionRuleMap.get(key);
    if (reactionRule == null) {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
    ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
    RuleAnalysisReport report = reportMap.get(key);
    if (modelRuleEntry == null || report == null) {
        System.out.println("modelRuleEntry == null || report == null,  NOT GOOD!");
    // refreshRuleAnalysis();
    }
    if (!bRuleAnalysisFailed && report != null) {
        MolecularComponentEntry molecularComponentEntry = modelRuleEntry.findMolecularComponentEntry(molecularComponentPattern);
        if (report.hasStateChanged(molecularComponentEntry)) {
            return RuleAnalysisChanged.CHANGED;
        } else {
            return RuleAnalysisChanged.UNCHANGED;
        }
    } else {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
}
Also used : RuleAnalysisReport(org.vcell.model.rbm.RuleAnalysisReport) ModelRuleEntry(cbit.vcell.model.ModelRuleFactory.ModelRuleEntry) ReactionRule(cbit.vcell.model.ReactionRule) MolecularComponentEntry(org.vcell.model.rbm.RuleAnalysis.MolecularComponentEntry)

Example 40 with ReactionRule

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

the class ParticipantSignatureShapePanel method hasNoMatch.

public RuleAnalysisChanged hasNoMatch(String key, MolecularTypePattern molecularTypePattern) {
    ReactionRule reactionRule = reactionRuleMap.get(key);
    if (reactionRule == null) {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
    ModelRuleEntry modelRuleEntry = modelRuleEntryMap.get(key);
    RuleAnalysisReport report = reportMap.get(key);
    if (modelRuleEntry == null || report == null) {
        System.out.println("modelRuleEntry == null || report == null,  NOT GOOD!");
    // refreshRuleAnalysis();
    }
    if (!bRuleAnalysisFailed && report != null) {
        MolecularTypeEntry molecularTypeEntry = modelRuleEntry.findMolecularTypeEntry(molecularTypePattern);
        if (report.hasNoMatch(molecularTypeEntry)) {
            return RuleAnalysisChanged.CHANGED;
        } else {
            return RuleAnalysisChanged.UNCHANGED;
        }
    } else {
        return RuleAnalysisChanged.ANALYSISFAILED;
    }
}
Also used : RuleAnalysisReport(org.vcell.model.rbm.RuleAnalysisReport) ModelRuleEntry(cbit.vcell.model.ModelRuleFactory.ModelRuleEntry) ReactionRule(cbit.vcell.model.ReactionRule) MolecularTypeEntry(org.vcell.model.rbm.RuleAnalysis.MolecularTypeEntry)

Aggregations

ReactionRule (cbit.vcell.model.ReactionRule)77 ArrayList (java.util.ArrayList)29 ReactionStep (cbit.vcell.model.ReactionStep)26 SpeciesContext (cbit.vcell.model.SpeciesContext)26 Structure (cbit.vcell.model.Structure)26 RbmObservable (cbit.vcell.model.RbmObservable)19 MolecularType (org.vcell.model.rbm.MolecularType)19 ProductPattern (cbit.vcell.model.ProductPattern)17 ReactantPattern (cbit.vcell.model.ReactantPattern)17 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)16 Model (cbit.vcell.model.Model)15 PropertyVetoException (java.beans.PropertyVetoException)14 SimulationContext (cbit.vcell.mapping.SimulationContext)13 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)10 BioModel (cbit.vcell.biomodel.BioModel)9 Expression (cbit.vcell.parser.Expression)9 List (java.util.List)9 Parameter (cbit.vcell.model.Parameter)8 Product (cbit.vcell.model.Product)8 RbmKineticLaw (cbit.vcell.model.RbmKineticLaw)8