Search in sources :

Example 6 with NameScope

use of cbit.vcell.parser.NameScope in project vcell by virtualcell.

the class ParameterContext method renameLocalParameter.

/**
 * Insert the method's description here.
 * Creation date: (5/24/01 4:05:36 PM)
 */
public void renameLocalParameter(String oldName, String newName) throws ExpressionException, java.beans.PropertyVetoException {
    if (oldName == null || newName == null) {
        throw new RuntimeException("renameParameter from '" + oldName + "' to '" + newName + "', nulls are not allowed");
    }
    NameScope nameScope = getNameScope();
    String prefix = AbstractNameScope.getPrefix(newName);
    String strippedName = AbstractNameScope.getStrippedIdentifier(newName);
    if (prefix != null) {
        NameScope prefixNameScope = nameScope.getNameScopeFromPrefix(prefix);
        if (prefixNameScope != nameScope) {
            // from different namescope, then strip any prefix.
            throw new ExpressionException("reaction parameter cannot be renamed to '" + newName + "', name is scoped to '" + prefixNameScope.getName() + "'");
        }
    }
    newName = strippedName;
    if (oldName.equals(newName)) {
        throw new RuntimeException("renameParameter from '" + oldName + "' to '" + newName + "', same name not allowed");
    }
    LocalParameter existingParameter = getLocalParameterFromName(newName);
    if (existingParameter != null) {
        throw new RuntimeException("Parameter '" + newName + "' already exists.");
    }
    LocalParameter parameter = getLocalParameterFromName(oldName);
    if (parameter != null) {
        // 
        // must change name in ElectricalStimulusParameter directly
        // then change all references to this name in the other parameter's expressions.
        // 
        LocalParameter[] newParameters = (LocalParameter[]) getLocalParameters().clone();
        // 
        // replaces parameter with name 'oldName' with new parameter with name 'newName' and original expression.
        // 
        parameter.fieldParameterName = newName;
        // 
        for (int i = 0; i < newParameters.length; i++) {
            if (newParameters[i].getExpression() != null) {
                Expression newExp = newParameters[i].getExpression().renameBoundSymbols(getNameScope());
                newParameters[i].setExpression(newExp);
            }
        }
        setLocalParameters(newParameters);
        // 
        try {
            cleanupParameters();
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new RuntimeException(e.getMessage());
        }
        parameter.firePropertyChange("name", oldName, newName);
    }
}
Also used : NameScope(cbit.vcell.parser.NameScope) AbstractNameScope(cbit.vcell.parser.AbstractNameScope) BioNameScope(cbit.vcell.model.BioNameScope) Expression(cbit.vcell.parser.Expression) ExpressionException(cbit.vcell.parser.ExpressionException) VCUnitException(cbit.vcell.units.VCUnitException) PropertyVetoException(java.beans.PropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException)

Example 7 with NameScope

use of cbit.vcell.parser.NameScope in project vcell by virtualcell.

the class ExpressionCanvas method setNameScope.

/**
 * Sets the nameScope property (cbit.vcell.parser.NameScope) value.
 * @param nameScope The new value for the property.
 * @see #getNameScope
 */
public void setNameScope(NameScope nameScope) {
    cbit.vcell.parser.NameScope oldValue = fieldNameScope;
    fieldNameScope = nameScope;
    firePropertyChange("nameScope", oldValue, nameScope);
}
Also used : NameScope(cbit.vcell.parser.NameScope)

Example 8 with NameScope

use of cbit.vcell.parser.NameScope in project vcell by virtualcell.

the class SBPAXHMMRevLawBuilder method addKinetics.

public void addKinetics(KineticContext context) {
    try {
        ReactionStep reaction = context.getReaction();
        HMM_REVKinetics kinetics = new HMM_REVKinetics((SimpleReaction) reaction);
        NameScope modelScope = reaction.getModel().getNameScope();
        ModelParameter kMichaelisFwd = context.getParameter(SBOList.MICHAELIS_CONST_FORW);
        if (kMichaelisFwd != null) {
            KineticsParameter kmfParameter = kinetics.getKmFwdParameter();
            kmfParameter.setExpression(new Expression(kMichaelisFwd, modelScope));
            kmfParameter.setUnitDefinition(kMichaelisFwd.getUnitDefinition());
        }
        ModelParameter kcatf = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
        if (kcatf != null && context.getCatalysts().size() == 1) {
            KineticsParameter vmaxfParameter = kinetics.getVmaxFwdParameter();
            Catalyst catalyst = context.getCatalysts().iterator().next();
            vmaxfParameter.setExpression(Expression.mult(new Expression(kcatf, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
        // vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
        } else {
            ModelParameter vMaxf = context.getParameter(SBOList.MAXIMAL_VELOCITY_FORW);
            if (vMaxf != null) {
                KineticsParameter vmaxfParameter = kinetics.getVmaxFwdParameter();
                vmaxfParameter.setExpression(new Expression(vMaxf, modelScope));
                vmaxfParameter.setUnitDefinition(vMaxf.getUnitDefinition());
            }
        }
        ModelParameter kMichaelisRev = context.getParameter(SBOList.MICHAELIS_CONST_REV);
        if (kMichaelisRev != null) {
            KineticsParameter kmrParameter = kinetics.getKmRevParameter();
            kmrParameter.setExpression(new Expression(kMichaelisRev, modelScope));
            kmrParameter.setUnitDefinition(kMichaelisRev.getUnitDefinition());
        }
        ModelParameter kcatr = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
        if (kcatr != null && context.getCatalysts().size() == 1) {
            KineticsParameter vmaxrParameter = kinetics.getVmaxRevParameter();
            Catalyst catalyst = context.getCatalysts().iterator().next();
            vmaxrParameter.setExpression(Expression.mult(new Expression(kcatr, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
        // vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
        } else {
            ModelParameter vMaxr = context.getParameter(SBOList.MAXIMAL_VELOCITY_REV);
            if (vMaxr != null) {
                KineticsParameter vmaxrParameter = kinetics.getVmaxRevParameter();
                vmaxrParameter.setExpression(new Expression(vMaxr, modelScope));
                vmaxrParameter.setUnitDefinition(vMaxr.getUnitDefinition());
            }
        }
    } catch (ExpressionException e) {
        e.printStackTrace();
    }
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) NameScope(cbit.vcell.parser.NameScope) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) Catalyst(cbit.vcell.model.Catalyst) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

NameScope (cbit.vcell.parser.NameScope)8 Expression (cbit.vcell.parser.Expression)4 ExpressionException (cbit.vcell.parser.ExpressionException)3 Catalyst (cbit.vcell.model.Catalyst)2 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)2 ModelParameter (cbit.vcell.model.Model.ModelParameter)2 ReactionStep (cbit.vcell.model.ReactionStep)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 BorderLayout (java.awt.BorderLayout)2 Component (java.awt.Component)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 JButton (javax.swing.JButton)2 JCheckBox (javax.swing.JCheckBox)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 JTable (javax.swing.JTable)2 JTextField (javax.swing.JTextField)2 DefaultScrollTableCellRenderer (org.vcell.util.gui.DefaultScrollTableCellRenderer)2