Search in sources :

Example 1 with AnalysisTask

use of cbit.vcell.modelopt.AnalysisTask in project vcell by virtualcell.

the class AnalysisTaskComboBoxModel method setSimulationContext.

/**
 * Sets the simulationContext property (cbit.vcell.mapping.SimulationContext) value.
 * @param simulationContext The new value for the property.
 * @see #getSimulationContext
 */
public void setSimulationContext(SimulationContext simulationContext) {
    if (fieldSimulationContext == simulationContext) {
        return;
    }
    if (fieldSimulationContext != null) {
        fieldSimulationContext.removePropertyChangeListener(this);
        if (fieldSimulationContext.getAnalysisTasks() != null) {
            for (int i = 0; i < fieldSimulationContext.getAnalysisTasks().length; i++) {
                fieldSimulationContext.getAnalysisTasks()[i].removePropertyChangeListener(this);
            }
        }
    }
    int oldSize = getSize();
    AnalysisTask oldSelection = (AnalysisTask) getSelectedItem();
    fieldSimulationContext = simulationContext;
    if (simulationContext != null) {
        simulationContext.addPropertyChangeListener(this);
        if (simulationContext.getAnalysisTasks() != null) {
            for (int i = 0; i < simulationContext.getAnalysisTasks().length; i++) {
                simulationContext.getAnalysisTasks()[i].addPropertyChangeListener(this);
            }
        }
    }
    if (oldSize > 0) {
        fireIntervalRemoved(this, 0, oldSize - 1);
    }
    if (simulationContext != null) {
        fireIntervalAdded(this, 0, getSize());
        // 
        // try to select corresponding item if exists
        // 
        AnalysisTask[] analysisTasks = simulationContext.getAnalysisTasks();
        AnalysisTask newSelection = null;
        if (oldSelection != null) {
            if (getIndexOf(oldSelection) > -1) {
                newSelection = oldSelection;
            } else {
                for (int i = 0; analysisTasks != null && i < analysisTasks.length; i++) {
                    if (analysisTasks[i].getName().equals(oldSelection.getName())) {
                        newSelection = analysisTasks[i];
                    }
                }
            }
        }
        if (newSelection == null && analysisTasks != null && analysisTasks.length > 0) {
            newSelection = analysisTasks[0];
        }
        setSelectedItem(newSelection);
    }
}
Also used : AnalysisTask(cbit.vcell.modelopt.AnalysisTask)

Example 2 with AnalysisTask

use of cbit.vcell.modelopt.AnalysisTask in project vcell by virtualcell.

the class ParameterEstimationPanel method getAnalysisTaskComboBox.

private javax.swing.JComboBox getAnalysisTaskComboBox() {
    if (taskComboBox == null) {
        taskComboBox = new javax.swing.JComboBox();
        taskComboBox.setRenderer(new DefaultListCellRenderer() {

            public java.awt.Component getListCellRendererComponent(javax.swing.JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                if (value instanceof AnalysisTask) {
                    AnalysisTask analysisTask = (AnalysisTask) value;
                    setText(analysisTask.getName());
                } else {
                    setText((value == null) ? "" : value.toString());
                }
                return this;
            }
        });
        taskComboBox.setEnabled(false);
        analysisTaskComboBoxModel = new AnalysisTaskComboBoxModel();
        taskComboBox.setModel(analysisTaskComboBoxModel);
    }
    return taskComboBox;
}
Also used : DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) AnalysisTask(cbit.vcell.modelopt.AnalysisTask) JComboBox(javax.swing.JComboBox) AnalysisTaskComboBoxModel(org.vcell.optimization.gui.AnalysisTaskComboBoxModel)

Example 3 with AnalysisTask

use of cbit.vcell.modelopt.AnalysisTask in project vcell by virtualcell.

the class ParameterEstimationPanel method copyAnalysisTaskButton_ActionPerformed.

private void copyAnalysisTaskButton_ActionPerformed() {
    try {
        AnalysisTask taskToCopy = getSelectedAnalysisTask();
        if (simulationContext != null && taskToCopy != null) {
            AnalysisTask newAnalysisTask = simulationContext.copyAnalysisTask(taskToCopy);
            getAnalysisTaskComboBox().setSelectedItem(newAnalysisTask);
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
        DialogUtils.showErrorDialog(this, e.getMessage(), e);
    }
}
Also used : AnalysisTask(cbit.vcell.modelopt.AnalysisTask) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException)

Example 4 with AnalysisTask

use of cbit.vcell.modelopt.AnalysisTask in project vcell by virtualcell.

the class SimulationContext method copyAnalysisTask.

/**
 * Sets the simulations property (cbit.vcell.solver.Simulation[]) value.
 * @param simulations The new value for the property.
 * @exception java.beans.PropertyVetoException The exception description.
 * @see #getSimulations
 */
public AnalysisTask copyAnalysisTask(AnalysisTask analysisTask) throws java.beans.PropertyVetoException, ExpressionException, MappingException, MathException {
    if (analysisTask instanceof ParameterEstimationTask) {
        String parameterEstimationName = analysisTask.getName() + " Copy";
        AnalysisTask[] analysisTasks = getAnalysisTasks();
        boolean found = true;
        while (found) {
            found = false;
            parameterEstimationName = TokenMangler.getNextEnumeratedToken(parameterEstimationName);
            for (int i = 0; analysisTasks != null && i < analysisTasks.length; i++) {
                if (analysisTasks[i].getName().equals(parameterEstimationName)) {
                    found = true;
                    continue;
                }
            }
        }
        ParameterEstimationTask newParameterEstimationTask = new ParameterEstimationTask(this, (ParameterEstimationTask) analysisTask);
        newParameterEstimationTask.setName(parameterEstimationName);
        addAnalysisTask(newParameterEstimationTask);
        return newParameterEstimationTask;
    } else {
        throw new RuntimeException("don't know how to copy AnalysisTask of type " + analysisTask.getClass().getName());
    }
}
Also used : ParameterEstimationTask(cbit.vcell.modelopt.ParameterEstimationTask) AnalysisTask(cbit.vcell.modelopt.AnalysisTask)

Example 5 with AnalysisTask

use of cbit.vcell.modelopt.AnalysisTask in project vcell by virtualcell.

the class SimulationContext method gatherIssues.

public void gatherIssues(IssueContext issueContext, List<Issue> issueVector, boolean bIgnoreMathDescription) {
    // issueContext = issueContext.newChildContext(ContextType.SimContext, this);
    if (applicationType.equals(Application.RULE_BASED_STOCHASTIC)) {
        for (ReactionRuleSpec rrs : getReactionContext().getReactionRuleSpecs()) {
            if (rrs.isExcluded()) {
                continue;
            }
            ReactionRule rr = rrs.getReactionRule();
            if (rr.getReactantPatterns().size() > 2) {
                String message = "NFSim doesn't support more than 2 reactants within a reaction rule.";
                issueVector.add(new Issue(rr, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
            if (rr.isReversible() && rr.getProductPatterns().size() > 2) {
                String message = "NFSim doesn't support more than 2 products within a reversible reaction rule.";
                issueVector.add(new Issue(rr, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
        }
        for (ReactionSpec rrs : getReactionContext().getReactionSpecs()) {
            if (rrs.isExcluded()) {
                continue;
            }
            ReactionStep rs = rrs.getReactionStep();
            if (rs.getNumReactants() > 2) {
                String message = "NFSim doesn't support more than 2 reactants within a reaction step.";
                issueVector.add(new Issue(rs, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
            if (rs.isReversible() && rs.getNumProducts() > 2) {
                String message = "NFSim doesn't support more than 2 products within a reversible reaction step.";
                issueVector.add(new Issue(rs, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
            }
        }
        // we give warning when we have plain reactions with participants with patterns;
        // making rules from these may result in inconsistent interpretation for the constant rates
        boolean isParticipantWithPattern = false;
        for (ReactionSpec rrs : getReactionContext().getReactionSpecs()) {
            if (rrs.isExcluded()) {
                continue;
            }
            ReactionStep rs = rrs.getReactionStep();
            for (Reactant r : rs.getReactants()) {
                if (r.getSpeciesContext().hasSpeciesPattern()) {
                    isParticipantWithPattern = true;
                    break;
                }
            }
            if (isParticipantWithPattern) {
                break;
            }
            for (Product p : rs.getProducts()) {
                if (p.getSpeciesContext().hasSpeciesPattern()) {
                    isParticipantWithPattern = true;
                    break;
                }
            }
            if (isParticipantWithPattern) {
                break;
            }
        }
        if (isParticipantWithPattern) {
            String message = SimulationContext.rateWarning2;
            String tooltip = SimulationContext.rateWarning;
            issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, tooltip, Issue.Severity.WARNING));
        }
        for (Structure struct : getModel().getStructures()) {
            String name = struct.getName();
            if (!name.equals(TokenMangler.fixTokenStrict(name))) {
                String msg = "'" + name + "' not legal identifier for rule-based stochastic applications, try '" + TokenMangler.fixTokenStrict(name) + "'.";
                issueVector.add(new Issue(struct, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
            }
        }
    }
    if (fieldBioEvents != null) {
        for (BioEvent bioEvent : fieldBioEvents) {
            bioEvent.gatherIssues(issueContext, issueVector);
        }
    }
    if (spatialObjects != null) {
        for (SpatialObject spatialObject : spatialObjects) {
            spatialObject.gatherIssues(issueContext, issueVector);
        }
    }
    if (spatialProcesses != null) {
        for (SpatialProcess spatialProcess : spatialProcesses) {
            spatialProcess.gatherIssues(issueContext, issueVector);
        }
    }
    if (fieldRateRules != null) {
        // to avoid duplicated Issues for the same problem
        Set<String> alreadyIssue = new HashSet<>();
        for (RateRule rr : fieldRateRules) {
            rr.gatherIssues(issueContext, issueVector, alreadyIssue);
        }
    }
    if (fieldAssignmentRules != null) {
        Set<String> alreadyIssue = new HashSet<>();
        for (AssignmentRule ar : fieldAssignmentRules) {
            ar.gatherIssues(issueContext, issueVector, alreadyIssue);
        }
    }
    if (applicationType.equals(Application.NETWORK_DETERMINISTIC) && getModel().getRbmModelContainer().getMolecularTypeList().size() > 0) {
        // we're going to use network transformer to flatten (or we already did)
        if (isInsufficientIterations()) {
            issueVector.add(new Issue(this, issueContext, IssueCategory.RbmNetworkConstraintsBad, IssueInsufficientIterations, Issue.Severity.WARNING));
        }
        if (isInsufficientMaxMolecules()) {
            issueVector.add(new Issue(this, issueContext, IssueCategory.RbmNetworkConstraintsBad, IssueInsufficientMolecules, Issue.Severity.WARNING));
        }
    }
    Geometry geo = getGeometryContext().getGeometry();
    int dimension = geo.getDimension();
    if (dimension != 0) {
        for (ReactionSpec rrs : getReactionContext().getReactionSpecs()) {
            if (rrs.isExcluded()) {
                continue;
            }
            ReactionStep rs = rrs.getReactionStep();
            if (rs.getStructure() instanceof Membrane) {
                continue;
            }
            // for spatial applications
            // we look for reactions where reactants and products are in more than one compartments
            // if such reactions are not on a membrane, we issue a warning
            Set<Structure> features = new HashSet<>();
            for (Reactant r : rs.getReactants()) {
                Structure struct = r.getStructure();
                if (struct instanceof Feature) {
                    features.add(struct);
                }
            }
            for (Product p : rs.getProducts()) {
                Structure struct = p.getStructure();
                if (struct instanceof Feature) {
                    features.add(struct);
                }
            }
            if (features.size() > 1) {
                String message = "Reaction must be situated on a membrane (spatial application present)";
                String tooltip = "Spatial application '" + getName() + "' requires that reactions between compartments must be situated on a membrane.";
                issueVector.add(new Issue(rs, issueContext, IssueCategory.Identifiers, message, tooltip, Issue.Severity.WARNING));
            }
        }
    }
    getReactionContext().gatherIssues(issueContext, issueVector);
    getGeometryContext().gatherIssues(issueContext, issueVector);
    if (fieldAnalysisTasks != null) {
        for (AnalysisTask analysisTask : fieldAnalysisTasks) {
            analysisTask.gatherIssues(issueContext, issueVector);
        }
    }
    getOutputFunctionContext().gatherIssues(issueContext, issueVector);
    getMicroscopeMeasurement().gatherIssues(issueContext, issueVector);
    if (getMathDescription() != null && !bIgnoreMathDescription) {
        getMathDescription().gatherIssues(issueContext, issueVector);
    }
    if (networkConstraints == null) {
    // issueVector.add(new Issue(this, issueContext, IssueCategory.RbmNetworkConstraintsBad, "Network Constraints is null", Issue.Severity.ERROR));
    } else {
        networkConstraints.gatherIssues(issueContext, issueVector);
    }
}
Also used : Issue(org.vcell.util.Issue) ReactionRule(cbit.vcell.model.ReactionRule) Product(cbit.vcell.model.Product) Reactant(cbit.vcell.model.Reactant) Feature(cbit.vcell.model.Feature) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) Geometry(cbit.vcell.geometry.Geometry) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) ReactionStep(cbit.vcell.model.ReactionStep) AnalysisTask(cbit.vcell.modelopt.AnalysisTask) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) HashSet(java.util.HashSet)

Aggregations

AnalysisTask (cbit.vcell.modelopt.AnalysisTask)9 ParameterEstimationTask (cbit.vcell.modelopt.ParameterEstimationTask)4 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)3 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)3 PropertyVetoException (java.beans.PropertyVetoException)3 Geometry (cbit.vcell.geometry.Geometry)2 AssignmentRule (cbit.vcell.mapping.AssignmentRule)2 BioEvent (cbit.vcell.mapping.BioEvent)2 RateRule (cbit.vcell.mapping.RateRule)2 SimulationContext (cbit.vcell.mapping.SimulationContext)2 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)2 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)2 Element (org.jdom.Element)2 NetworkConstraints (org.vcell.model.rbm.NetworkConstraints)2 ImageException (cbit.image.ImageException)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 DataContext (cbit.vcell.data.DataContext)1 DataSymbol (cbit.vcell.data.DataSymbol)1 FieldDataSymbol (cbit.vcell.data.FieldDataSymbol)1 GeometryClass (cbit.vcell.geometry.GeometryClass)1