Search in sources :

Example 6 with LocalProxyParameter

use of cbit.vcell.mapping.ParameterContext.LocalProxyParameter in project vcell by virtualcell.

the class RbmKineticLaw method clone.

public static void clone(RbmKineticLaw toKineticLaw, ReactionRule fromRule, ReactionRule toRule) {
    RbmKineticLaw fromKineticLaw = fromRule.getKineticLaw();
    Model toModel = toRule.getModel();
    Model fromModel = fromRule.getModel();
    try {
        for (LocalParameter fromLocalParameter : fromKineticLaw.parameterContext.getLocalParameters()) {
            if (fromLocalParameter.getRole() != RbmKineticLawParameterType.UserDefined) {
                // find built-in parameter with same role and copy expression.
                // copy name also in case it was changed.
                LocalParameter toLocalParameter = toKineticLaw.parameterContext.getLocalParameterFromRole(fromLocalParameter.getRole());
                String toName = new String(fromLocalParameter.getName());
                if (!toName.equals(toLocalParameter.getName())) {
                    // new name must be different from existing name, no point to rename otherwise
                    toLocalParameter.setName(toName);
                }
                Expression fromExpression = fromLocalParameter.getExpression();
                if (fromExpression != null) {
                    Expression toExpression = new Expression(fromExpression);
                    toKineticLaw.setParameterValue(toLocalParameter, toExpression, true);
                }
            // TODO: units are not updated!
            }
        }
        for (LocalParameter fromLocalParameter : fromKineticLaw.parameterContext.getLocalParameters()) {
            if (fromLocalParameter.getRole() == RbmKineticLawParameterType.UserDefined) {
                LocalParameter toLocalParameter = toKineticLaw.getLocalParameter(fromLocalParameter.getName());
                if (toLocalParameter == null) {
                    // 
                    // after lazy parameter creation we didn't find a user-defined rule parameter with this same name.
                    // 
                    // there must be a global symbol with the same name, that the local reaction parameter has overridden.
                    // 
                    ParameterContext.LocalProxyParameter rule_proxy_parameter = null;
                    for (ProxyParameter proxyParameter : fromKineticLaw.getProxyParameters()) {
                        if (proxyParameter.getName().equals(fromLocalParameter.getName())) {
                            rule_proxy_parameter = (LocalProxyParameter) proxyParameter;
                        }
                    }
                    if (rule_proxy_parameter != null) {
                        // we want to convert to local
                        boolean bConvertToGlobal = false;
                        toKineticLaw.convertParameterType(rule_proxy_parameter, bConvertToGlobal);
                    } else {
                        // could find neither local parameter nor proxy parameter
                        throw new RuntimeException("user defined parameter " + fromLocalParameter.getName() + " from reactionRule " + fromRule.getName() + " didn't map to a reactionRule parameter");
                    }
                } else if (toLocalParameter.getRole() == RbmKineticLawParameterType.UserDefined) {
                    Expression expression = fromLocalParameter.getExpression();
                    if (expression != null) {
                        toKineticLaw.setParameterValue(toLocalParameter, expression, true);
                    }
                // TODO: make copy constructor for VCUnitDefinition
                // VCUnitDefinition toUnitDefinition = new VCUnitDefinition(fromLocalParameter.getUnitDefinition());
                // toLocalParameter.setUnitDefinition(toUnitDefinition);
                } else {
                    throw new RuntimeException("user defined parameter " + fromLocalParameter.getName() + " from reactionRule " + fromRule.getName() + " mapped to a reactionRule parameter with unexpected role " + toLocalParameter.getRole().getDescription());
                }
            }
        }
    // TODO: some params were assumed to be local but they are global in the 'from'
    // need to find if we have a global with same name, rename at need and make it global
    } catch (PropertyVetoException | ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException("Problem attempting to set RbmKineticLaw expression: " + e.getMessage());
    }
}
Also used : LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) Expression(cbit.vcell.parser.Expression) ParameterContext(cbit.vcell.mapping.ParameterContext) GlobalParameterContext(cbit.vcell.mapping.ParameterContext.GlobalParameterContext)

Example 7 with LocalProxyParameter

use of cbit.vcell.mapping.ParameterContext.LocalProxyParameter in project vcell by virtualcell.

the class RbmKineticLaw method duplicate.

public static void duplicate(RbmKineticLaw to, ReactionRule fromRule) {
    RbmKineticLaw from = fromRule.getKineticLaw();
    try {
        for (LocalParameter fromLocalParameter : from.parameterContext.getLocalParameters()) {
            if (fromLocalParameter.getRole() != RbmKineticLawParameterType.UserDefined) {
                // find built-in parameter with same role and copy expression.
                // copy name also in case it was changed.
                LocalParameter toLocalParameter = to.parameterContext.getLocalParameterFromRole(fromLocalParameter.getRole());
                toLocalParameter.setName(fromLocalParameter.getName());
                Expression expression = fromLocalParameter.getExpression();
                if (expression != null) {
                    to.setParameterValue(toLocalParameter, new Expression(expression), true);
                }
            }
        }
        for (LocalParameter fromLocalParameter : from.parameterContext.getLocalParameters()) {
            if (fromLocalParameter.getRole() == RbmKineticLawParameterType.UserDefined) {
                LocalParameter toLocalParameter = to.getLocalParameter(fromLocalParameter.getName());
                if (toLocalParameter == null) {
                    // 
                    // after lazy parameter creation we didn't find a user-defined rule parameter with this same name.
                    // 
                    // there must be a global symbol with the same name, that the local reaction parameter has overridden.
                    // 
                    ParameterContext.LocalProxyParameter rule_proxy_parameter = null;
                    for (ProxyParameter proxyParameter : from.getProxyParameters()) {
                        if (proxyParameter.getName().equals(fromLocalParameter.getName())) {
                            rule_proxy_parameter = (LocalProxyParameter) proxyParameter;
                        }
                    }
                    if (rule_proxy_parameter != null) {
                        // we want to convert to local
                        boolean bConvertToGlobal = false;
                        to.convertParameterType(rule_proxy_parameter, bConvertToGlobal);
                    } else {
                        // could find neither local parameter nor proxy parameter
                        throw new RuntimeException("user defined parameter " + fromLocalParameter.getName() + " from reactionRule " + fromRule.getName() + " didn't map to a reactionRule parameter");
                    }
                } else if (toLocalParameter.getRole() == RbmKineticLawParameterType.UserDefined) {
                    Expression expression = fromLocalParameter.getExpression();
                    if (expression != null) {
                        to.setParameterValue(toLocalParameter, expression, true);
                    }
                    toLocalParameter.setUnitDefinition(fromLocalParameter.getUnitDefinition());
                } else {
                    throw new RuntimeException("user defined parameter " + fromLocalParameter.getName() + " from reactionRule " + fromRule.getName() + " mapped to a reactionRule parameter with unexpected role " + toLocalParameter.getRole().getDescription());
                }
            }
        }
    } catch (PropertyVetoException | ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException("Problem attempting to set RbmKineticLaw expression: " + e.getMessage());
    }
}
Also used : LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) Expression(cbit.vcell.parser.Expression) ParameterContext(cbit.vcell.mapping.ParameterContext) GlobalParameterContext(cbit.vcell.mapping.ParameterContext.GlobalParameterContext) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) ExpressionException(cbit.vcell.parser.ExpressionException)

Aggregations

LocalProxyParameter (cbit.vcell.mapping.ParameterContext.LocalProxyParameter)7 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)6 Expression (cbit.vcell.parser.Expression)5 ExpressionException (cbit.vcell.parser.ExpressionException)5 ModelParameter (cbit.vcell.model.Model.ModelParameter)4 PropertyVetoException (java.beans.PropertyVetoException)4 UnresolvedParameter (cbit.vcell.mapping.ParameterContext.UnresolvedParameter)3 Parameter (cbit.vcell.model.Parameter)3 SpeciesContext (cbit.vcell.model.SpeciesContext)3 ParameterContext (cbit.vcell.mapping.ParameterContext)2 GlobalParameterContext (cbit.vcell.mapping.ParameterContext.GlobalParameterContext)2 Model (cbit.vcell.model.Model)2 ModelQuantity (cbit.vcell.model.ModelQuantity)2 RbmKineticLaw (cbit.vcell.model.RbmKineticLaw)2 ReactionRule (cbit.vcell.model.ReactionRule)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 ScopedExpression (cbit.gui.ScopedExpression)1 Kinetics (cbit.vcell.model.Kinetics)1 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)1 MassActionKinetics (cbit.vcell.model.MassActionKinetics)1