Search in sources :

Example 6 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class OptimizationService method optimize.

public static OptimizationResultSet optimize(ParameterEstimationTask parameterEstimationTask) throws Exception {
    // if (OperatingSystemInfo.getInstance().isMac()){
    // throw new RuntimeException("parameter estimation not currently available on Mac\n\n   try Windows or Linux.\n\n   coming soon on Mac.");
    // }
    copasiOptCallbacks.reset();
    updateMath(parameterEstimationTask.getSimulationContext(), NetworkGenerationRequirements.ComputeFullStandardTimeout);
    StringBuffer issueText = new StringBuffer();
    java.util.Vector<Issue> issueList = new java.util.Vector<Issue>();
    IssueContext issueContext = new IssueContext();
    parameterEstimationTask.gatherIssues(issueContext, issueList);
    boolean bFailed = false;
    for (int i = 0; i < issueList.size(); i++) {
        Issue issue = (Issue) issueList.elementAt(i);
        issueText.append(issue.getMessage() + "\n");
        if (issue.getSeverity() == Issue.SEVERITY_ERROR) {
            bFailed = true;
            break;
        }
    }
    if (bFailed) {
        throw new OptimizationException(issueText.toString());
    }
    parameterEstimationTask.refreshMappings();
    OptimizationResultSet optResultSet = CopasiOptimizationSolver.solveLocalPython(new ParameterEstimationTaskSimulatorIDA(), parameterEstimationTask, copasiOptCallbacks, callback);
    return optResultSet;
}
Also used : OptimizationException(cbit.vcell.opt.OptimizationException) Issue(org.vcell.util.Issue) OptimizationResultSet(cbit.vcell.opt.OptimizationResultSet) IssueContext(org.vcell.util.IssueContext) ParameterEstimationTaskSimulatorIDA(org.vcell.optimization.ParameterEstimationTaskSimulatorIDA)

Example 7 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class WorkflowTest method main.

public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("expecting 2 arguments");
        System.out.println("usage: java " + Workflow.class.getSimpleName() + " workingdir workflowInputFile");
        System.out.println("workingdir example: " + "D:\\developer\\eclipse\\workspace\\VCell_5.4_vmicro\\datadir");
        System.out.println("workflowInputFile example: " + "D:\\developer\\eclipse\\workspace\\VCell_5.4_vmicro\\workflow1.txt");
        System.exit(1);
    }
    try {
        // PropertyLoader.loadProperties();
        // workflowInputFile "C:\\developer\\eclipse\\workspace\\VCell_5.3_vmicro\\workflow1.txt"
        File workingDirectory = new File(args[0]);
        LocalWorkspace localWorkspace = new LocalWorkspace(workingDirectory);
        Repository repository = new MemoryRepository();
        String workflowLanguageText = BeanUtils.readBytesFromFile(new File(args[1]), null);
        Workflow workflow = Workflow.parse(repository, localWorkspace, workflowLanguageText);
        System.err.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> using hard-coded example instead <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
        // File vfrapFile = new File("D:\\Developer\\eclipse\\workspace_refactor\\VCell_5.4_vmicro\\3D_FRAP_2_ZProjection_Simulation1.vfrap");
        // Workflow workflow = getVFrapSimpleExample(workingDirectory, vfrapFile);
        TaskContext taskContext = new TaskContext(workflow, repository, localWorkspace);
        ArrayList<Issue> issues = new ArrayList<Issue>();
        IssueContext issueContext = new IssueContext();
        workflow.gatherIssues(issueContext, issues);
        // WorkflowJGraphProxy workflowJGraphProxy = new WorkflowJGraphProxy(workflow);
        // displayWorkflowGraphJGraphX(workflowJGraphProxy);
        WorkflowUtilities.displayWorkflowGraph(workflow);
        WorkflowUtilities.displayWorkflowTable(taskContext);
        workflow.reportIssues(issues, Issue.SEVERITY_INFO, true);
        // 
        // execute the workflow
        // 
        workflow.compute(taskContext, new WorkflowUtilities.Progress());
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : LocalWorkspace(org.vcell.vmicro.workflow.data.LocalWorkspace) TaskContext(org.vcell.workflow.TaskContext) Issue(org.vcell.util.Issue) ArrayList(java.util.ArrayList) Workflow(org.vcell.workflow.Workflow) MemoryRepository(org.vcell.workflow.MemoryRepository) Repository(org.vcell.workflow.Repository) MemoryRepository(org.vcell.workflow.MemoryRepository) IssueContext(org.vcell.util.IssueContext) File(java.io.File)

Example 8 with IssueContext

use of org.vcell.util.IssueContext 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 9 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class BioCartoonTool method pasteReactionSteps.

/**
 * pasteReactionSteps : this method clones the model argument and calls the private pasteReationSteps0 method with the cloned model to see if
 * there are any issues with the paste operation. If so, the issue list is popped up in a warning dialog, and user is given the option of proceeding
 * with the paste or cancelling the operation.
 *
 * @param reactionStepsArr : reactions to be pasted
 * @param model : model where reactions are to be pasted
 * @param struct : strucure in 'model' where the reactions should be pasted
 * @param bNew : is it 'paste' or 'paste new' reaction (new reaction Participants are created if 'bNew' is <true>).
 * @param guiRequestComponent : the parent component for the warning dialog that pops up the issues, if any, encountered in the pasting process
 * @throws Exception
 */
public static final void pasteReactionSteps(Component requester, ReactionStep[] reactionStepsArrOrig, Model pasteModel, Structure struct, boolean bNew, /*boolean bUseDBSpecies,*/
UserResolvedRxElements userResolvedRxElements, RXPasteInterface rxPasteInterface) {
    PasteHelper[] pasteHelper = new PasteHelper[1];
    AsynchClientTask issueTask = new AsynchClientTask("Checking Issues...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Model clonedModel = (Model) org.vcell.util.BeanUtils.cloneSerializable(pasteModel);
            clonedModel.refreshDependencies();
            IssueContext issueContext = new IssueContext(ContextType.Model, clonedModel, null);
            pasteHelper[0] = pasteReactionSteps0(null, requester, issueContext, reactionStepsArrOrig, clonedModel, clonedModel.getStructure(struct.getName()), bNew, /*bUseDBSpecies,*/
            UserResolvedRxElements.createCompatibleUserResolvedRxElements(userResolvedRxElements, clonedModel));
            if (pasteHelper[0].issues.size() != 0) {
                if (!printIssues(pasteHelper[0].issues, requester)) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
            }
            if (pasteHelper[0].rxPartMapStruct != null) {
                // Convert rxPartMapStruct instances from cloned to pasteModel
                HashMap<String, HashMap<ReactionParticipant, Structure>> new_rxPartMapStruct = new HashMap<>();
                for (int i = 0; reactionStepsArrOrig != null && i < reactionStepsArrOrig.length; i++) {
                    new_rxPartMapStruct.put(reactionStepsArrOrig[i].getName(), new HashMap<ReactionParticipant, Structure>());
                    for (ReactionParticipant rxPart : pasteHelper[0].rxPartMapStruct.get(reactionStepsArrOrig[i].getName()).keySet()) {
                        ReactionParticipant[] origRXParts = reactionStepsArrOrig[i].getReactionParticipants();
                        for (int j = 0; j < origRXParts.length; j++) {
                            if (origRXParts[j].getName().equals(rxPart.getName())) {
                                new_rxPartMapStruct.get(reactionStepsArrOrig[i].getName()).put(origRXParts[j], pasteModel.getStructure(pasteHelper[0].rxPartMapStruct.get(reactionStepsArrOrig[i].getName()).get(rxPart).getName()));
                            }
                        }
                    }
                }
                pasteHelper[0].rxPartMapStruct = new_rxPartMapStruct;
            }
        }
    };
    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);
            pasteHelper[0] = pasteReactionSteps0(pasteHelper[0].rxPartMapStruct, requester, issueContext, reactionStepsArrOrig, pasteModel, struct, bNew, /*bUseDBSpecies,*/
            userResolvedRxElements);
            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) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Hashtable(java.util.Hashtable) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) Model(cbit.vcell.model.Model) IssueContext(org.vcell.util.IssueContext) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 10 with IssueContext

use of org.vcell.util.IssueContext in project vcell by virtualcell.

the class MolecularComponentLargeShape method setComponentColor.

private Color setComponentColor() {
    boolean highlight = isHighlighted();
    if (owner == null) {
        return highlight == true ? componentBad.brighter() : componentBad;
    }
    Color componentColor = highlight == true ? componentBad.brighter() : componentBad;
    if (owner instanceof MolecularType) {
        componentColor = highlight == true ? componentPaleYellow.brighter() : componentPaleYellow;
    } else if (owner instanceof SpeciesContext) {
        if (shapePanel != null && !shapePanel.isShowNonTrivialOnly()) {
            componentColor = componentHidden;
        } else {
            componentColor = highlight == true ? componentPaleYellow.brighter() : componentPaleYellow;
        }
    } else if (mcp != null && owner instanceof RbmObservable) {
        if (shapePanel != null && !shapePanel.isEditable()) {
            componentColor = componentHidden;
        } else {
            componentColor = highlight == true ? componentHidden.brighter() : componentHidden;
        }
        if (mcp.getBondType() != BondType.Possible) {
            componentColor = highlight == true ? componentPaleYellow.brighter() : componentPaleYellow;
        }
    } else if (owner instanceof ReactionRule) {
        ReactionRule reactionRule = (ReactionRule) owner;
        if (shapePanel.getDisplayMode() == DisplayMode.participantSignatures) {
            componentColor = componentHidden;
            if (shapePanel.isShowNonTrivialOnly() == true) {
                if (mcp.getBondType() != BondType.Possible) {
                    componentColor = componentPaleYellow;
                } else {
                    componentColor = componentHidden;
                }
            }
            if (shapePanel.isShowDifferencesOnly()) {
                switch(shapePanel.hasBondChanged(reactionRule.getName(), mcp)) {
                    case CHANGED:
                        componentColor = Color.orange;
                        break;
                    case ANALYSISFAILED:
                        ArrayList<Issue> issueList = new ArrayList<Issue>();
                        reactionRule.gatherIssues(new IssueContext(), issueList);
                        boolean bRuleHasErrorIssues = false;
                        for (Issue issue : issueList) {
                            if (issue.getSeverity() == Severity.ERROR) {
                                bRuleHasErrorIssues = true;
                                break;
                            }
                        }
                        if (bRuleHasErrorIssues) {
                            componentColor = componentHidden;
                        } else {
                            System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                            componentColor = Color.red.darker();
                        }
                        break;
                    default:
                        break;
                }
            }
        } else if (shapePanel.getDisplayMode() == DisplayMode.rules) {
            componentColor = componentHidden;
            if (shapePanel.isShowNonTrivialOnly() == true) {
                if (mcp.getBondType() != BondType.Possible) {
                    componentColor = componentPaleYellow;
                } else {
                    componentColor = componentHidden;
                }
            }
            if (shapePanel.isShowDifferencesOnly()) {
                switch(shapePanel.hasBondChanged(mcp)) {
                    case CHANGED:
                        componentColor = Color.orange;
                        break;
                    case ANALYSISFAILED:
                        ArrayList<Issue> issueList = new ArrayList<Issue>();
                        reactionRule.gatherIssues(new IssueContext(), issueList);
                        boolean bRuleHasErrorIssues = false;
                        for (Issue issue : issueList) {
                            if (issue.getSeverity() == Severity.ERROR) {
                                bRuleHasErrorIssues = true;
                                break;
                            }
                        }
                        if (bRuleHasErrorIssues) {
                            componentColor = componentHidden;
                        } else {
                            System.err.println("ReactionRule Analysis failed, but there are not Error Issues with ReactionRule " + reactionRule.getName());
                            componentColor = Color.red.darker();
                        }
                        break;
                    default:
                        break;
                }
            }
        } else {
            componentColor = highlight == true ? componentHidden.brighter() : componentHidden;
            if (mcp.getBondType() != BondType.Possible) {
                componentColor = highlight == true ? componentPaleYellow.brighter() : componentPaleYellow;
            }
        }
    }
    if (hasErrorIssues(owner, mcp, mc)) {
        componentColor = highlight == true ? componentBad.brighter() : componentBad;
    }
    return componentColor;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) Issue(org.vcell.util.Issue) ReactionRule(cbit.vcell.model.ReactionRule) Color(java.awt.Color) RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) IssueContext(org.vcell.util.IssueContext) SpeciesContext(cbit.vcell.model.SpeciesContext)

Aggregations

IssueContext (org.vcell.util.IssueContext)17 Issue (org.vcell.util.Issue)14 ArrayList (java.util.ArrayList)9 ReactionRule (cbit.vcell.model.ReactionRule)4 Vector (java.util.Vector)4 MolecularType (org.vcell.model.rbm.MolecularType)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 MathDescription (cbit.vcell.math.MathDescription)3 Structure (cbit.vcell.model.Structure)3 Hashtable (java.util.Hashtable)3 SimulationContext (cbit.vcell.mapping.SimulationContext)2 Constant (cbit.vcell.math.Constant)2 Model (cbit.vcell.model.Model)2 RbmObservable (cbit.vcell.model.RbmObservable)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2 OptimizationException (cbit.vcell.opt.OptimizationException)2 OptimizationResultSet (cbit.vcell.opt.OptimizationResultSet)2 Color (java.awt.Color)2 ParameterEstimationTaskSimulatorIDA (org.vcell.optimization.ParameterEstimationTaskSimulatorIDA)2 DecoratedIssueSource (cbit.vcell.client.desktop.DecoratedIssueSource)1