Search in sources :

Example 21 with ReactionStep

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

the class TransformMassActionTableModel method saveTransformedReactions.

public void saveTransformedReactions() throws Exception {
    // isTransformable and TransformedREactions are stored according to the indexes in model reaction steps.
    boolean[] isTransformable = getTransformMassActions().getIsTransformable();
    TransformMassActions.TransformedReaction[] trs = getTransformMassActions().getTransformedReactionSteps();
    ReactionStep[] origReactions = getModel().getReactionSteps();
    // names of those who can be transformed and will be transformed
    String okTransReacNames = "";
    // names of those who can be transformed and will not be transformed
    String noTransReacNames = "";
    // names of those who can not be transformed
    String errReacNames = "";
    for (int i = 0; i < isTransformable.length; i++) {
        if (trs[i].getTransformType() == TransformMassActions.TransformedReaction.TRANSFORMABLE && getIsSelected(i)) {
            okTransReacNames = okTransReacNames + origReactions[i].getName() + ",";
        } else if (trs[i].getTransformType() == TransformMassActions.TransformedReaction.TRANSFORMABLE && !getIsSelected(i)) {
            noTransReacNames = noTransReacNames + origReactions[i].getName() + ",";
        } else if (!isTransformable[i]) {
            errReacNames = errReacNames + origReactions[i].getName() + ",";
        }
    }
    // set transformed Mass Action kinetics to model reactions
    for (int i = 0; i < origReactions.length; i++) {
        if (getIsSelected(i)) {
            // for simple reaction, we replace the original kinetics with MassActionKinetics if it wasn't MassActionKinetics
            if (origReactions[i] instanceof SimpleReaction) {
                if (!(origReactions[i].getKinetics() instanceof MassActionKinetics)) {
                    // ***Below we will physically change the simple reaction***
                    // put all kinetic parameters together into array newKps
                    Vector<Kinetics.KineticsParameter> newKps = new Vector<Kinetics.KineticsParameter>();
                    // get original kinetic parameters which are not current density and reaction rate.
                    // those parameters are basically the symbols in rate expression.
                    Vector<Kinetics.KineticsParameter> origKps = new Vector<Kinetics.KineticsParameter>();
                    Kinetics.KineticsParameter[] Kps = origReactions[i].getKinetics().getKineticsParameters();
                    for (int j = 0; j < Kps.length; j++) {
                        if (!(Kps[j].getRole() == Kinetics.ROLE_CurrentDensity || Kps[j].getRole() == Kinetics.ROLE_ReactionRate)) {
                            origKps.add(Kps[j]);
                        }
                    }
                    // create mass action kinetics for the original reaction step
                    MassActionKinetics maKinetics = new MassActionKinetics(origReactions[i]);
                    maKinetics.getKineticsParameterFromRole(Kinetics.ROLE_KForward).setExpression(trs[i].getMassActionFunction().getForwardRate());
                    maKinetics.getKineticsParameterFromRole(Kinetics.ROLE_KReverse).setExpression(trs[i].getMassActionFunction().getReverseRate());
                    // Kinetics)
                    for (int j = 0; j < maKinetics.getKineticsParameters().length; j++) {
                        newKps.add(maKinetics.getKineticsParameters(j));
                    }
                    // copy other kinetic parameters from original kinetics
                    for (int j = 0; j < origKps.size(); j++) {
                        newKps.add(origKps.elementAt(j));
                    }
                    // add parameters to mass action kinetics
                    KineticsParameter[] newParameters = new KineticsParameter[newKps.size()];
                    newParameters = (KineticsParameter[]) newKps.toArray(newParameters);
                    maKinetics.addKineticsParameters(newParameters);
                    // after adding all the parameters, we bind the forward/reverse rate expression with symbol table (the reaction step itself)
                    origReactions[i].getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KForward).getExpression().bindExpression(origReactions[i]);
                    origReactions[i].getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KReverse).getExpression().bindExpression(origReactions[i]);
                }
            }
        // for flux, we set the flux reaction back, coz we will parse it to mass action form in stochastic math mapping.
        // However, we don't physically change it.
        }
    }
    String msg = "";
    if (!okTransReacNames.equals("")) {
        msg = msg + okTransReacNames + " have been transformed.\n";
    }
    // message to be displayed in popupdialog of DocumentWindow
    if (!msg.equals("")) {
        throw new Exception(msg);
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionStep(cbit.vcell.model.ReactionStep) MassActionKinetics(cbit.vcell.model.MassActionKinetics) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Kinetics(cbit.vcell.model.Kinetics) Vector(java.util.Vector)

Example 22 with ReactionStep

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

the class ParameterTableModel method setReactionStep.

/**
 * Sets the geometry property (cbit.vcell.geometry.Geometry) value.
 * @param geometry The new value for the property.
 * @see #getGeometry
 */
public void setReactionStep(ReactionStep newValue) {
    ReactionStep oldValue = reactionStep;
    reactionStep = newValue;
    firePropertyChange("reactionStep", oldValue, newValue);
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep)

Example 23 with ReactionStep

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

the class ParameterTableModel method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    if (evt.getSource() == this && evt.getPropertyName().equals("reactionStep")) {
        ReactionStep oldValue = (ReactionStep) evt.getOldValue();
        if (oldValue != null) {
            oldValue.removePropertyChangeListener(this);
            oldValue.getKinetics().removePropertyChangeListener(this);
            for (int i = 0; i < oldValue.getKinetics().getKineticsParameters().length; i++) {
                oldValue.getKinetics().getKineticsParameters()[i].removePropertyChangeListener(this);
            }
            for (int i = 0; i < oldValue.getKinetics().getProxyParameters().length; i++) {
                oldValue.getKinetics().getProxyParameters()[i].removePropertyChangeListener(this);
            }
        }
        ReactionStep newValue = (ReactionStep) evt.getNewValue();
        if (newValue != null) {
            newValue.addPropertyChangeListener(this);
            newValue.getKinetics().addPropertyChangeListener(this);
            for (int i = 0; i < newValue.getKinetics().getKineticsParameters().length; i++) {
                newValue.getKinetics().getKineticsParameters()[i].removePropertyChangeListener(this);
                newValue.getKinetics().getKineticsParameters()[i].addPropertyChangeListener(this);
            }
            for (int i = 0; i < newValue.getKinetics().getProxyParameters().length; i++) {
                newValue.getKinetics().getProxyParameters()[i].removePropertyChangeListener(this);
                newValue.getKinetics().getProxyParameters()[i].addPropertyChangeListener(this);
            }
            autoCompleteSymbolFilter = reactionStep.getAutoCompleteSymbolFilter();
        }
        refreshData();
    }
    if (evt.getSource() == reactionStep && evt.getPropertyName().equals(ReactionStep.PROPERTY_NAME_KINETICS)) {
        Kinetics oldValue = (Kinetics) evt.getOldValue();
        if (oldValue != null) {
            oldValue.removePropertyChangeListener(this);
            for (int i = 0; i < oldValue.getKineticsParameters().length; i++) {
                oldValue.getKineticsParameters()[i].removePropertyChangeListener(this);
            }
            for (int i = 0; i < oldValue.getProxyParameters().length; i++) {
                oldValue.getProxyParameters()[i].removePropertyChangeListener(this);
            }
        }
        Kinetics newValue = (Kinetics) evt.getNewValue();
        if (newValue != null) {
            newValue.addPropertyChangeListener(this);
            for (int i = 0; i < newValue.getKineticsParameters().length; i++) {
                newValue.getKineticsParameters()[i].removePropertyChangeListener(this);
                newValue.getKineticsParameters()[i].addPropertyChangeListener(this);
            }
            for (int i = 0; i < newValue.getProxyParameters().length; i++) {
                newValue.getProxyParameters()[i].removePropertyChangeListener(this);
                newValue.getProxyParameters()[i].addPropertyChangeListener(this);
            }
        }
        // get rid of all Catalysts when changing kynetic type
        if (reactionStep != null && reactionStep.hasCatalyst() && newValue != null && newValue != oldValue) {
            List<ReactionParticipant> rpList = new ArrayList<>(Arrays.asList(reactionStep.getReactionParticipants()));
            for (ReactionParticipant rp : rpList) {
                if (rp instanceof Catalyst) {
                    try {
                        reactionStep.removeReactionParticipant(rp);
                    } catch (PropertyVetoException | ExpressionException | ModelException e) {
                        // do nothing if it fails
                        e.printStackTrace();
                    }
                }
            }
        }
        refreshData();
    }
    if (evt.getSource() instanceof Kinetics && (evt.getPropertyName().equals("kineticsParameters") || evt.getPropertyName().equals("proxyParameters"))) {
        Parameter[] oldParams = (Parameter[]) evt.getOldValue();
        Parameter[] newParams = (Parameter[]) evt.getNewValue();
        for (int i = 0; oldParams != null && i < oldParams.length; i++) {
            oldParams[i].removePropertyChangeListener(this);
        }
        for (int i = 0; newParams != null && i < newParams.length; i++) {
            newParams[i].removePropertyChangeListener(this);
            newParams[i].addPropertyChangeListener(this);
        }
        if (evt.getPropertyName().equals("proxyParameters")) {
            List<Parameter> addedList = new ArrayList<>(Arrays.asList(newParams));
            addedList.removeAll(Arrays.asList(oldParams));
            List<Parameter> removedList = new ArrayList<>(Arrays.asList(oldParams));
            removedList.removeAll(Arrays.asList(newParams));
            if (reactionStep != null) {
                for (Parameter removed : removedList) {
                    if (removed instanceof ProxyParameter && ((ProxyParameter) removed).getTarget() instanceof SpeciesContext) {
                        SpeciesContext sc = (SpeciesContext) ((ProxyParameter) removed).getTarget();
                        if (reactionStep.getReactant(sc.getName()) == null && reactionStep.getProduct(sc.getName()) == null && reactionStep.getCatalyst(sc.getName()) != null) {
                            try {
                                reactionStep.removeReactionParticipant(reactionStep.getCatalyst(sc.getName()));
                            } catch (PropertyVetoException | ExpressionException | ModelException e) {
                                // we do nothing
                                e.printStackTrace();
                            }
                        }
                    }
                }
                for (Parameter added : addedList) {
                    if (added instanceof ProxyParameter && ((ProxyParameter) added).getTarget() instanceof SpeciesContext) {
                        SpeciesContext sc = (SpeciesContext) ((ProxyParameter) added).getTarget();
                        if (reactionStep.getReactant(sc.getName()) == null && reactionStep.getProduct(sc.getName()) == null && reactionStep.getCatalyst(sc.getName()) == null) {
                            try {
                                reactionStep.addCatalyst(sc);
                            } catch (PropertyVetoException | ModelException e) {
                                // we do nothing
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
        refreshData();
    }
    if (evt.getSource() instanceof Parameter) {
        fireTableRowsUpdated(0, getRowCount() - 1);
    }
}
Also used : ModelException(cbit.vcell.model.ModelException) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) ProxyParameter(cbit.vcell.model.ProxyParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) ReactionStep(cbit.vcell.model.ReactionStep) ProxyParameter(cbit.vcell.model.ProxyParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) Parameter(cbit.vcell.model.Parameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) Kinetics(cbit.vcell.model.Kinetics) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Catalyst(cbit.vcell.model.Catalyst)

Example 24 with ReactionStep

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

the class BioModel method getVCID.

public VCID getVCID(Identifiable identifiable) {
    if (identifiable == null) {
        return null;
    }
    String localName;
    String className;
    if (identifiable instanceof SpeciesContext) {
        localName = ((SpeciesContext) identifiable).getName();
        className = VCID.CLASS_SPECIES_CONTEXT;
    } else if (identifiable instanceof Species) {
        localName = ((Species) identifiable).getCommonName();
        className = VCID.CLASS_SPECIES;
    } else if (identifiable instanceof Structure) {
        localName = ((Structure) identifiable).getName();
        className = VCID.CLASS_STRUCTURE;
    } else if (identifiable instanceof ReactionStep) {
        localName = ((ReactionStep) identifiable).getName();
        className = VCID.CLASS_REACTION_STEP;
    } else if (identifiable instanceof BioModel) {
        localName = ((BioModel) identifiable).getName();
        className = VCID.CLASS_BIOMODEL;
    } else if (identifiable instanceof BioPaxObject) {
        localName = ((BioPaxObject) identifiable).getID();
        className = VCID.CLASS_BIOPAX_OBJECT;
    } else if (identifiable instanceof MolecularType) {
        localName = ((MolecularType) identifiable).getName();
        className = VCID.CLASS_MOLECULE;
    } else if (identifiable instanceof ReactionRule) {
        localName = ((ReactionRule) identifiable).getName();
        className = VCID.CLASS_REACTION_RULE;
    } else if (identifiable instanceof RbmObservable) {
        localName = ((RbmObservable) identifiable).getName();
        className = VCID.CLASS_OBSERVABLE;
    } else if (identifiable instanceof Model.ModelParameter) {
        localName = ((Model.ModelParameter) identifiable).getName();
        className = VCID.CLASS_MODEL_PARAMETER;
    } else if (identifiable instanceof SimulationContext) {
        localName = ((SimulationContext) identifiable).getName();
        className = VCID.CLASS_APPLICATION;
    } else {
        throw new RuntimeException("unsupported Identifiable class");
    }
    localName = TokenMangler.mangleVCId(localName);
    VCID vcid;
    try {
        vcid = VCID.fromString(className + "(" + localName + ")");
    } catch (VCID.InvalidVCIDException e) {
        e.printStackTrace();
        throw new RuntimeException(e.getMessage());
    }
    return vcid;
}
Also used : VCID(cbit.vcell.biomodel.meta.VCID) ReactionRule(cbit.vcell.model.ReactionRule) BioPaxObject(org.vcell.pathway.BioPaxObject) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) MolecularType(org.vcell.model.rbm.MolecularType) ReactionStep(cbit.vcell.model.ReactionStep) RelationshipModel(org.vcell.relationship.RelationshipModel) Model(cbit.vcell.model.Model) PathwayModel(org.vcell.pathway.PathwayModel) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species)

Example 25 with ReactionStep

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

the class BioModel method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   	and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    // 
    if (evt.getSource() instanceof SimulationContext && evt.getPropertyName().equals("mathDescription") && evt.getNewValue() != null) {
        if (fieldSimulations != null) {
            for (int i = 0; i < fieldSimulations.length; i++) {
                if (fieldSimulations[i].getMathDescription() == evt.getOldValue()) {
                    try {
                        fieldSimulations[i].setMathDescription((MathDescription) evt.getNewValue());
                    } catch (PropertyVetoException e) {
                        System.out.println("error propagating math from SimulationContext '" + ((SimulationContext) evt.getSource()).getName() + "' to Simulation '" + fieldSimulations[i].getName());
                        e.printStackTrace(System.out);
                    }
                }
            }
        }
    }
    // 
    if (evt.getSource() == this && evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_SIMULATIONS) && evt.getNewValue() != null) {
        // 
        if (evt.getOldValue() != null) {
            Simulation[] simulations = (Simulation[]) evt.getOldValue();
            for (int i = 0; i < simulations.length; i++) {
                simulations[i].removeVetoableChangeListener(this);
                simulations[i].removePropertyChangeListener(this);
            }
        }
        // 
        if (evt.getOldValue() != null) {
            Simulation[] simulations = (Simulation[]) evt.getNewValue();
            for (int i = 0; i < simulations.length; i++) {
                simulations[i].addVetoableChangeListener(this);
                simulations[i].addPropertyChangeListener(this);
            }
        }
    }
    if (evt.getSource() == this && evt.getPropertyName().equals(PROPERTY_NAME_SIMULATION_CONTEXTS) && evt.getNewValue() != null) {
        // 
        if (evt.getOldValue() != null) {
            SimulationContext[] simulationContexts = (SimulationContext[]) evt.getOldValue();
            for (int i = 0; i < simulationContexts.length; i++) {
                simulationContexts[i].removeVetoableChangeListener(this);
                simulationContexts[i].removePropertyChangeListener(this);
            }
        }
        // 
        if (evt.getOldValue() != null) {
            SimulationContext[] simulationContexts = (SimulationContext[]) evt.getNewValue();
            for (int i = 0; i < simulationContexts.length; i++) {
                simulationContexts[i].addVetoableChangeListener(this);
                simulationContexts[i].addPropertyChangeListener(this);
            }
        }
    }
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(Model.PROPERTY_NAME_SPECIES_CONTEXTS) || evt.getPropertyName().equals(Model.PROPERTY_NAME_REACTION_STEPS))) {
        // remove the relationship objects if the biomodelEntity objects were removed
        Set<BioModelEntityObject> removedObjects = relationshipModel.getBioModelEntityObjects();
        for (SpeciesContext sc : fieldModel.getSpeciesContexts()) {
            removedObjects.remove(sc);
        }
        for (ReactionStep rs : fieldModel.getReactionSteps()) {
            removedObjects.remove(rs);
        }
        for (MolecularType mt : fieldModel.getRbmModelContainer().getMolecularTypeList()) {
            removedObjects.remove(mt);
        }
        for (ReactionRule rr : fieldModel.getRbmModelContainer().getReactionRuleList()) {
            removedObjects.remove(rr);
        }
        relationshipModel.removeRelationshipObjects(removedObjects);
    }
    // adjust the relationship model when a molecule gets deleted
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST))) {
        @SuppressWarnings("unchecked") List<MolecularType> oldListCopy = new ArrayList<MolecularType>((List<MolecularType>) evt.getOldValue());
        @SuppressWarnings("unchecked") List<MolecularType> newList = (List<MolecularType>) evt.getNewValue();
        if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
            // something got deleted
            oldListCopy.removeAll(newList);
            for (MolecularType removedMt : oldListCopy) {
                relationshipModel.removeRelationshipObject(removedMt);
            }
        }
    }
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST))) {
        @SuppressWarnings("unchecked") List<ReactionRule> oldListCopy = new ArrayList<ReactionRule>((List<ReactionRule>) evt.getOldValue());
        @SuppressWarnings("unchecked") List<ReactionRule> newList = (List<ReactionRule>) evt.getNewValue();
        if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
            // something got deleted
            oldListCopy.removeAll(newList);
            for (ReactionRule removedRr : oldListCopy) {
                relationshipModel.removeRelationshipObject(removedRr);
            }
        }
    }
    if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(Model.PROPERTY_NAME_MODEL_ENTITY_NAME))) {
        firePropertyChange(Model.PROPERTY_NAME_MODEL_ENTITY_NAME, evt.getOldValue(), evt.getNewValue());
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ArrayList(java.util.ArrayList) SpeciesContext(cbit.vcell.model.SpeciesContext) SimulationContext(cbit.vcell.mapping.SimulationContext) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Simulation(cbit.vcell.solver.Simulation) ReactionStep(cbit.vcell.model.ReactionStep) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

ReactionStep (cbit.vcell.model.ReactionStep)111 SpeciesContext (cbit.vcell.model.SpeciesContext)55 Structure (cbit.vcell.model.Structure)37 ReactionParticipant (cbit.vcell.model.ReactionParticipant)33 Expression (cbit.vcell.parser.Expression)33 Model (cbit.vcell.model.Model)32 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)30 ArrayList (java.util.ArrayList)29 ReactionRule (cbit.vcell.model.ReactionRule)26 ModelParameter (cbit.vcell.model.Model.ModelParameter)25 Reactant (cbit.vcell.model.Reactant)25 Kinetics (cbit.vcell.model.Kinetics)24 Product (cbit.vcell.model.Product)23 PropertyVetoException (java.beans.PropertyVetoException)23 SimpleReaction (cbit.vcell.model.SimpleReaction)20 ExpressionException (cbit.vcell.parser.ExpressionException)20 Vector (java.util.Vector)19 SimulationContext (cbit.vcell.mapping.SimulationContext)18 Membrane (cbit.vcell.model.Membrane)18 BioModel (cbit.vcell.biomodel.BioModel)17