Search in sources :

Example 76 with Model

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

the class StructureAnalyzer method refreshTotalSpeciesContextMappings.

/**
 * This method was created in VisualAge.
 */
private void refreshTotalSpeciesContextMappings() throws java.beans.PropertyVetoException {
    if (structures == null) {
        return;
    }
    // System.out.println("StructureAnalyzer.refreshSpeciesContextMappings()");
    // GeometryContext geoContext = mathMapping.getSimulationContext().getGeometryContext();
    Model model = mathMapping_4_8.getSimulationContext().getReactionContext().getModel();
    // 
    // note, the order of species is specified such that the first species have priority
    // when the null space is solved for dependent variables.  So the order of priority
    // for elimination are as follows:
    // 
    // 1) Species involved with fast reactions.
    // 2) Species not involved with fast reactions.
    // 
    Vector<SpeciesContextMapping> scmList = new Vector<SpeciesContextMapping>();
    // 
    for (int i = 0; i < structures.length; i++) {
        SpeciesContext[] speciesContexts = model.getSpeciesContexts(structures[i]);
        for (int j = 0; j < speciesContexts.length; j++) {
            SpeciesContext sc = speciesContexts[j];
            SpeciesContextMapping scm = mathMapping_4_8.getSpeciesContextMapping(sc);
            SpeciesContextSpec scs = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(sc);
            if (scm.isFastParticipant() && !scs.isConstant()) {
                scmList.addElement(scm);
            }
        }
    }
    // 
    for (int i = 0; i < structures.length; i++) {
        SpeciesContext[] speciesContexts = model.getSpeciesContexts(structures[i]);
        for (int j = 0; j < speciesContexts.length; j++) {
            SpeciesContext sc = speciesContexts[j];
            SpeciesContextMapping scm = mathMapping_4_8.getSpeciesContextMapping(sc);
            SpeciesContextSpec scs = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(sc);
            if (!scm.isFastParticipant() && !scs.isConstant()) {
                scmList.addElement(scm);
            }
        }
    }
    if (scmList.size() > 0) {
        speciesContextMappings = new SpeciesContextMapping[scmList.size()];
        scmList.copyInto(speciesContextMappings);
        for (int i = 0; i < speciesContextMappings.length; i++) {
            speciesContextMappings[i].setRate(new Expression(0.0));
        // System.out.println("speciesContextMappings["+i+"] = "+speciesContextMappings[i].getSpeciesContext().getName());
        }
    } else {
        speciesContextMappings = null;
    }
    // System.out.println("StructureAnalyzer.refreshTotalSpeciesContextMapping(), speciesContextMappings.length = "+scmList.size());
    // 
    // get all reactionSteps associated with these structures
    // 
    Vector<ReactionStep> rsList = new Vector<ReactionStep>();
    ReactionSpec[] allReactionSpecs = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpecs();
    for (int i = 0; i < allReactionSpecs.length; i++) {
        if (allReactionSpecs[i].isExcluded()) {
            continue;
        }
        ReactionStep rs = allReactionSpecs[i].getReactionStep();
        for (int j = 0; j < structures.length; j++) {
            if (rs.getStructure() == structures[j]) {
                rsList.addElement(rs);
            }
        }
    }
    // 
    for (int i = 0; i < scmList.size(); i++) {
        SpeciesContextMapping scm = (SpeciesContextMapping) scmList.elementAt(i);
        if (scm.isPDERequired()) {
            rsList.addElement(new DiffusionDummyReactionStep("DiffusionDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
        }
        if (scm.hasEventAssignment()) {
            rsList.addElement(new EventDummyReactionStep("EventDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
        }
        if (scm.hasHybridReaction()) {
            rsList.addElement(new HybridDummyReactionStep("HybridDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
        }
        SimulationContext simContext = mathMapping_4_8.getSimulationContext();
        if (simContext.isStoch() && simContext.getGeometry().getDimension() > 0 && !simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext()).isForceContinuous()) {
            rsList.addElement(new ParticleDummyReactionStep("ParticleDummyReactionStep" + i, model, scm.getSpeciesContext().getStructure(), scm.getSpeciesContext()));
        }
    }
    if (rsList.size() > 0) {
        reactionSteps = new ReactionStep[rsList.size()];
        rsList.copyInto(reactionSteps);
    } else {
        reactionSteps = null;
    }
// System.out.println("StructureAnalyzer.refreshTotalSpeciesContextMapping(), reactionSteps.length = "+scmList.size());
}
Also used : ParticleDummyReactionStep(cbit.vcell.mapping.ParticleDummyReactionStep) SpeciesContextMapping(cbit.vcell.mapping.SpeciesContextMapping) ReactionSpec(cbit.vcell.mapping.ReactionSpec) EventDummyReactionStep(cbit.vcell.mapping.EventDummyReactionStep) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) SimulationContext(cbit.vcell.mapping.SimulationContext) Expression(cbit.vcell.parser.Expression) DummyReactionStep(cbit.vcell.mapping.DummyReactionStep) ReactionStep(cbit.vcell.model.ReactionStep) EventDummyReactionStep(cbit.vcell.mapping.EventDummyReactionStep) ParticleDummyReactionStep(cbit.vcell.mapping.ParticleDummyReactionStep) DiffusionDummyReactionStep(cbit.vcell.mapping.DiffusionDummyReactionStep) HybridDummyReactionStep(cbit.vcell.mapping.HybridDummyReactionStep) Model(cbit.vcell.model.Model) HybridDummyReactionStep(cbit.vcell.mapping.HybridDummyReactionStep) Vector(java.util.Vector) DiffusionDummyReactionStep(cbit.vcell.mapping.DiffusionDummyReactionStep)

Example 77 with Model

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

the class GeometryContext method setModel.

/**
 * Sets the model property (cbit.vcell.model.Model) value.
 * @param model The new value for the property.
 * @see #getModel
 */
public void setModel(Model model) throws MappingException {
    Model oldValue = fieldModel;
    fieldModel = model;
    try {
        refreshStructureMappings();
        refreshDependencies();
    } catch (PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new MappingException(e.getMessage());
    }
    firePropertyChange("model", oldValue, model);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Model(cbit.vcell.model.Model)

Example 78 with Model

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

the class ReactionContext method setModel.

/**
 * Sets the model property (cbit.vcell.model.Model) value.
 * @param model The new value for the property.
 * @see #getModel
 */
public void setModel(Model model) throws MappingException, java.beans.PropertyVetoException {
    Model oldValue = fieldModel;
    fieldModel = model;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(this);
        oldValue.removeVetoableChangeListener(this);
    }
    if (fieldModel != null) {
        fieldModel.addPropertyChangeListener(this);
        fieldModel.addVetoableChangeListener(this);
    }
    refreshSpeciesContextSpecs();
    refreshReactionSpecs();
    refreshReactionRuleSpecs();
    firePropertyChange("model", oldValue, model);
}
Also used : Model(cbit.vcell.model.Model)

Example 79 with Model

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

the class RulebasedTransformer method transform.

@Override
public final RulebasedTransformation transform(SimulationContext originalSimContext, MathMappingCallback mathMappingCallback, NetworkGenerationRequirements netGenReq_NOT_USED) {
    SimulationContext transformedSimContext;
    keyMap.clear();
    try {
        transformedSimContext = (SimulationContext) BeanUtils.cloneSerializable(originalSimContext);
        transformedSimContext.getModel().refreshDependencies();
        transformedSimContext.refreshDependencies();
        transformedSimContext.compareEqual(originalSimContext);
    } catch (ClassNotFoundException | IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Unexpected transform exception: " + e.getMessage());
    }
    final Model transformedModel = transformedSimContext.getModel();
    transformedModel.refreshDependencies();
    transformedSimContext.refreshDependencies1(false);
    ArrayList<ModelEntityMapping> entityMappings = new ArrayList<ModelEntityMapping>();
    try {
        transform(originalSimContext, transformedSimContext, entityMappings, mathMappingCallback);
    } catch (PropertyVetoException e) {
        e.printStackTrace();
        throw new RuntimeException("Unexpected transform exception: " + e.getMessage());
    }
    ModelEntityMapping[] modelEntityMappings = entityMappings.toArray(new ModelEntityMapping[0]);
    return new RulebasedTransformation(originalSimContext, transformedSimContext, modelEntityMappings, ruleElementMap, rulesForwardMap, rulesReverseMap);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Model(cbit.vcell.model.Model) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 80 with Model

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

the class BioModelEditorModelPanel method addNewReaction.

private void addNewReaction() {
    if (reactionEditorPanel == null) {
        reactionEditorPanel = new ReactionEditorPanel();
    }
    Model model = getModel();
    reactionEditorPanel.setModel(model);
    while (true) {
        int confirm = DialogUtils.showComponentOKCancelDialog(this, reactionEditorPanel, "New Reaction");
        if (confirm == javax.swing.JOptionPane.OK_OPTION) {
            Structure reactionStructure = reactionEditorPanel.getStructure();
            String reactionName = reactionEditorPanel.getReactionName();
            String equationString = reactionEditorPanel.getEquationString();
            try {
                if (reactionName == null || reactionName.trim().length() == 0 || equationString == null || equationString.trim().length() == 0) {
                    throw new RuntimeException("Reaction name or equation cannot be empty.");
                }
                if (getModel().getReactionStep(reactionName) != null) {
                    throw new RuntimeException("Reaction '" + reactionName + "' already exists.");
                }
                ReactionStep simpleReaction = new SimpleReaction(model, reactionStructure, "dummy", true);
                ReactionParticipant[] rpArray = ModelProcessEquation.parseReaction(simpleReaction, getModel(), equationString);
                // StructureTopology structTopology = getModel().getStructureTopology();
                // for (ReactionParticipant reactionParticipant : rpArray) {
                // if (reactionParticipant.getStructure() == reactionStructure) {
                // continue;
                // }
                // if (reactionStructure instanceof Feature) {
                // throw new RuntimeException("Species '" + reactionParticipant.getSpeciesContext().getName() + "' must be in the same volume compartment as reaction.");
                // } else if (reactionStructure instanceof Membrane) {
                // if (structTopology.getInsideFeature((Membrane)reactionStructure) != reactionParticipant.getStructure()
                // && (structTopology.getOutsideFeature((Membrane)reactionStructure)) != reactionParticipant.getStructure()) {
                // throw new RuntimeException("Species '" + reactionParticipant.getSpeciesContext().getName() + "' must be adjacent to " +
                // "or within reaction's structure '" + reactionStructure.getName() + "'.");
                // }
                // }
                // }
                simpleReaction = getModel().createSimpleReaction(reactionStructure);
                for (ReactionParticipant rp : rpArray) {
                    SpeciesContext speciesContext = rp.getSpeciesContext();
                    if (bioModel.getModel().getSpeciesContext(speciesContext.getName()) == null) {
                        bioModel.getModel().addSpecies(speciesContext.getSpecies());
                        bioModel.getModel().addSpeciesContext(speciesContext);
                    }
                }
                simpleReaction.setReactionParticipants(rpArray);
                simpleReaction.setName(reactionName);
                setSelectedObjects(new Object[] { simpleReaction });
                break;
            } catch (Exception e) {
                e.printStackTrace();
                DialogUtils.showErrorDialog(this, e.getMessage());
            }
        } else {
            break;
        }
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) ListSelectionModel(javax.swing.ListSelectionModel) BioModel(cbit.vcell.biomodel.BioModel) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) GraphModel(cbit.gui.graph.GraphModel) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) ReactionParticipant(cbit.vcell.model.ReactionParticipant) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

Model (cbit.vcell.model.Model)107 BioModel (cbit.vcell.biomodel.BioModel)53 SpeciesContext (cbit.vcell.model.SpeciesContext)44 Expression (cbit.vcell.parser.Expression)42 Structure (cbit.vcell.model.Structure)35 PropertyVetoException (java.beans.PropertyVetoException)34 SimulationContext (cbit.vcell.mapping.SimulationContext)27 ReactionStep (cbit.vcell.model.ReactionStep)27 ModelParameter (cbit.vcell.model.Model.ModelParameter)23 ExpressionException (cbit.vcell.parser.ExpressionException)22 ArrayList (java.util.ArrayList)22 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)21 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)19 MathDescription (cbit.vcell.math.MathDescription)17 Feature (cbit.vcell.model.Feature)16 ModelException (cbit.vcell.model.ModelException)16 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)16 SubVolume (cbit.vcell.geometry.SubVolume)15 Parameter (cbit.vcell.model.Parameter)15 StructureMapping (cbit.vcell.mapping.StructureMapping)14