Search in sources :

Example 1 with Macroscopic_IRRKinetics

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

the class Xmlproducer method getXML.

/**
 * This method returns a XML representation of a Kinetics object type.
 * Creation date: (2/26/2001 7:31:43 PM)
 * @return Element
 * @param param cbit.vcell.model.Kinetics
 */
private Element getXML(Kinetics param) throws XmlParseException {
    String kineticsType = null;
    if (param instanceof GeneralKinetics) {
        // process a GeneralKinetics object
        kineticsType = XMLTags.KineticsTypeGeneralKinetics;
    } else if (param instanceof MassActionKinetics) {
        // Process a MassActionKinetics
        kineticsType = XMLTags.KineticsTypeMassAction;
    } else if (param instanceof NernstKinetics) {
        // Process a NernstKinetics
        kineticsType = XMLTags.KineticsTypeNernst;
    } else if (param instanceof GHKKinetics) {
        // Process a GHKKinetics
        kineticsType = XMLTags.KineticsTypeGHK;
    } else if (param instanceof GeneralCurrentKinetics) {
        // Process a GeneralCurrentKinetics
        kineticsType = XMLTags.KineticsTypeGeneralCurrentKinetics;
    } else if (param instanceof HMM_IRRKinetics) {
        // Process a HenriMichaelasMentenKinetics (irreversible)
        kineticsType = XMLTags.KineticsTypeHMM_Irr;
    } else if (param instanceof HMM_REVKinetics) {
        // Process a HenriMichaelasMentenKinetics (reversible)
        kineticsType = XMLTags.KineticsTypeHMM_Rev;
    } else if (param instanceof GeneralLumpedKinetics) {
        // Process a GeneralLumpedKinetics
        kineticsType = XMLTags.KineticsTypeGeneralLumped;
    } else if (param instanceof GeneralCurrentLumpedKinetics) {
        // Process a GeneralCurrentLumpedKinetics
        kineticsType = XMLTags.KineticsTypeGeneralCurrentLumped;
    } else if (param instanceof GeneralPermeabilityKinetics) {
        // Process a GeneralPermeabilityKinetics
        kineticsType = XMLTags.KineticsTypeGeneralPermeability;
    } else if (param instanceof Macroscopic_IRRKinetics) {
        // Process a Macroscopic_IRRKinetics
        kineticsType = XMLTags.KineticsTypeMacroscopic_Irr;
    } else if (param instanceof Microscopic_IRRKinetics) {
        // Process a Microscopic_IRRKinetics
        kineticsType = XMLTags.KineticsTypeMicroscopic_Irr;
    }
    Element kinetics = new Element(XMLTags.KineticsTag);
    // Add atributes
    kinetics.setAttribute(XMLTags.KineticsTypeAttrTag, kineticsType);
    // Add Kinetics Parameters
    Kinetics.KineticsParameter[] parameters = param.getKineticsParameters();
    for (int i = 0; i < parameters.length; i++) {
        Kinetics.KineticsParameter parm = parameters[i];
        Element tempparameter = new Element(XMLTags.ParameterTag);
        // Get parameter attributes
        tempparameter.setAttribute(XMLTags.NameAttrTag, mangle(parm.getName()));
        tempparameter.setAttribute(XMLTags.ParamRoleAttrTag, param.getDefaultParameterDesc(parm.getRole()));
        VCUnitDefinition unit = parm.getUnitDefinition();
        if (unit != null) {
            tempparameter.setAttribute(XMLTags.VCUnitDefinitionAttrTag, unit.getSymbol());
        }
        tempparameter.addContent(mangleExpression(parm.getExpression()));
        // Add the parameter to the general kinetics object
        kinetics.addContent(tempparameter);
    }
    return kinetics;
}
Also used : HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) GHKKinetics(cbit.vcell.model.GHKKinetics) Element(org.jdom.Element) NernstKinetics(cbit.vcell.model.NernstKinetics) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) GeneralKinetics(cbit.vcell.model.GeneralKinetics) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) GeneralCurrentKinetics(cbit.vcell.model.GeneralCurrentKinetics) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) GeneralCurrentLumpedKinetics(cbit.vcell.model.GeneralCurrentLumpedKinetics) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Macroscopic_IRRKinetics(cbit.vcell.model.Macroscopic_IRRKinetics) Macroscopic_IRRKinetics(cbit.vcell.model.Macroscopic_IRRKinetics) Kinetics(cbit.vcell.model.Kinetics) NernstKinetics(cbit.vcell.model.NernstKinetics) GeneralKinetics(cbit.vcell.model.GeneralKinetics) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) GeneralPermeabilityKinetics(cbit.vcell.model.GeneralPermeabilityKinetics) GHKKinetics(cbit.vcell.model.GHKKinetics) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Microscopic_IRRKinetics(cbit.vcell.model.Microscopic_IRRKinetics) GeneralCurrentKinetics(cbit.vcell.model.GeneralCurrentKinetics) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) GeneralCurrentLumpedKinetics(cbit.vcell.model.GeneralCurrentLumpedKinetics) GeneralPermeabilityKinetics(cbit.vcell.model.GeneralPermeabilityKinetics) Microscopic_IRRKinetics(cbit.vcell.model.Microscopic_IRRKinetics)

Example 2 with Macroscopic_IRRKinetics

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

the class XmlReader method getKinetics.

/**
 * This method returns a Kinetics object from a XML Element based on the value of the kinetics type attribute.
 * Creation date: (3/19/2001 4:42:04 PM)
 * @return cbit.vcell.model.Kinetics
 * @param param org.jdom.Element
 */
private Kinetics getKinetics(Element param, ReactionStep reaction, Model model) throws XmlParseException {
    VariableHash varHash = new VariableHash();
    addResevedSymbols(varHash, model);
    String type = param.getAttributeValue(XMLTags.KineticsTypeAttrTag);
    Kinetics newKinetics = null;
    try {
        if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralKinetics)) {
            // create a general kinetics
            newKinetics = new GeneralKinetics(reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralCurrentKinetics)) {
            // Create GeneralCurrentKinetics
            newKinetics = new GeneralCurrentKinetics(reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeMassAction) && reaction instanceof SimpleReaction) {
            // create a Mass Action kinetics
            newKinetics = new MassActionKinetics((SimpleReaction) reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeNernst) && reaction instanceof FluxReaction) {
            // create NernstKinetics
            newKinetics = new NernstKinetics((FluxReaction) reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGHK) && reaction instanceof FluxReaction) {
            // create GHKKinetics
            newKinetics = new GHKKinetics((FluxReaction) reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeHMM_Irr) && reaction instanceof SimpleReaction) {
            // create HMM_IrrKinetics
            newKinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeHMM_Rev) && reaction instanceof SimpleReaction) {
            // create HMM_RevKinetics
            newKinetics = new HMM_REVKinetics((SimpleReaction) reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralTotal_oldname)) {
            // create GeneralTotalKinetics
            newKinetics = new GeneralLumpedKinetics(reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralLumped)) {
            // create GeneralLumpedKinetics
            newKinetics = new GeneralLumpedKinetics(reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralCurrentLumped)) {
            // create GeneralCurrentLumpedKinetics
            newKinetics = new GeneralCurrentLumpedKinetics(reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralPermeability) && reaction instanceof FluxReaction) {
            // create GeneralPermeabilityKinetics
            newKinetics = new GeneralPermeabilityKinetics((FluxReaction) reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeMacroscopic_Irr) && reaction instanceof SimpleReaction) {
            // create Macroscopic_IRRKinetics
            newKinetics = new Macroscopic_IRRKinetics((SimpleReaction) reaction);
        } else if (type.equalsIgnoreCase(XMLTags.KineticsTypeMicroscopic_Irr) && reaction instanceof SimpleReaction) {
            // create Microscopic_IRRKinetics
            newKinetics = new Microscopic_IRRKinetics((SimpleReaction) reaction);
        } else {
            throw new XmlParseException("Unknown kinetics type: " + type);
        }
    } catch (ExpressionException e) {
        e.printStackTrace();
        throw new XmlParseException("Error creating the kinetics for reaction: " + reaction.getName(), e);
    }
    try {
        // transaction begin flag ... yeah, this is a hack
        newKinetics.reading(true);
        // Read all of the parameters
        List<Element> list = param.getChildren(XMLTags.ParameterTag, vcNamespace);
        // add constants that may be used in kinetics.
        // VariableHash varHash = getVariablesHash();
        ArrayList<String> reserved = new ArrayList<String>();
        ReservedSymbol[] reservedSymbols = reaction.getModel().getReservedSymbols();
        for (ReservedSymbol rs : reservedSymbols) {
            reserved.add(rs.getName());
        }
        try {
            if (reaction.getStructure() instanceof Membrane) {
                Membrane membrane = (Membrane) reaction.getStructure();
                varHash.addVariable(new Constant(membrane.getMembraneVoltage().getName(), new Expression(0.0)));
                reserved.add(membrane.getMembraneVoltage().getName());
            }
            // 
            // add Reactants, Products, and Catalysts (ReactionParticipants)
            // 
            ReactionParticipant[] rp = reaction.getReactionParticipants();
            for (int i = 0; i < rp.length; i++) {
                varHash.addVariable(new Constant(rp[i].getName(), new Expression(0.0)));
            }
        } catch (MathException e) {
            e.printStackTrace(System.out);
            throw new XmlParseException("error reordering parameters according to dependencies: ", e);
        }
        // 
        for (Element xmlParam : list) {
            String paramName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
            String role = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
            String paramExpStr = xmlParam.getText();
            Expression paramExp = unMangleExpression(paramExpStr);
            try {
                if (varHash.getVariable(paramName) == null) {
                    varHash.addVariable(new Function(paramName, paramExp, null));
                } else {
                    if (reserved.contains(paramName)) {
                        varHash.removeVariable(paramName);
                        varHash.addVariable(new Function(paramName, paramExp, null));
                    }
                }
            } catch (MathException e) {
                e.printStackTrace(System.out);
                throw new XmlParseException("error reordering parameters according to dependencies: ", e);
            }
            Kinetics.KineticsParameter tempParam = null;
            if (!role.equals(XMLTags.ParamRoleUserDefinedTag)) {
                tempParam = newKinetics.getKineticsParameterFromRole(Kinetics.getParamRoleFromDefaultDesc(role));
            } else {
                continue;
            }
            // hack for bringing in General Total kinetics without breaking.
            if (tempParam == null && newKinetics instanceof GeneralLumpedKinetics) {
                if (role.equals(Kinetics.GTK_AssumedCompartmentSize_oldname) || role.equals(Kinetics.GTK_ReactionRate_oldname) || role.equals(Kinetics.GTK_CurrentDensity_oldname)) {
                    continue;
                } else if (role.equals(VCMODL.TotalRate_oldname)) {
                    tempParam = newKinetics.getKineticsParameterFromRole(Kinetics.ROLE_LumpedReactionRate);
                }
            }
            // hack from bringing in chargeValence parameters without breaking
            if (tempParam == null && Kinetics.getParamRoleFromDefaultDesc(role) == Kinetics.ROLE_ChargeValence) {
                tempParam = newKinetics.getChargeValenceParameter();
            }
            if (tempParam == null) {
                throw new XmlParseException("parameter with role '" + role + "' not found in kinetics type '" + type + "'");
            }
            // 
            if (!tempParam.getName().equals(paramName)) {
                Kinetics.KineticsParameter multNameParam = newKinetics.getKineticsParameter(paramName);
                int n = 0;
                while (multNameParam != null) {
                    String tempName = paramName + "_" + n++;
                    newKinetics.renameParameter(paramName, tempName);
                    multNameParam = newKinetics.getKineticsParameter(tempName);
                }
                newKinetics.renameParameter(tempParam.getName(), paramName);
            }
        }
        // 
        // create unresolved parameters for all unresolved symbols
        // 
        String unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
        while (unresolvedSymbol != null) {
            try {
                // will turn into an UnresolvedParameter.
                varHash.addVariable(new Function(unresolvedSymbol, new Expression(0.0), null));
            } catch (MathException e) {
                e.printStackTrace(System.out);
                throw new XmlParseException(e);
            }
            newKinetics.addUnresolvedParameter(unresolvedSymbol);
            unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
        }
        Variable[] sortedVariables = varHash.getTopologicallyReorderedVariables();
        ModelUnitSystem modelUnitSystem = reaction.getModel().getUnitSystem();
        for (int i = sortedVariables.length - 1; i >= 0; i--) {
            if (sortedVariables[i] instanceof Function) {
                Function paramFunction = (Function) sortedVariables[i];
                Element xmlParam = null;
                for (int j = 0; j < list.size(); j++) {
                    Element tempParam = (Element) list.get(j);
                    if (paramFunction.getName().equals(unMangle(tempParam.getAttributeValue(XMLTags.NameAttrTag)))) {
                        xmlParam = tempParam;
                        break;
                    }
                }
                if (xmlParam == null) {
                    // must have been an unresolved parameter
                    continue;
                }
                String symbol = xmlParam.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
                VCUnitDefinition unit = null;
                if (symbol != null) {
                    unit = modelUnitSystem.getInstance(symbol);
                }
                Kinetics.KineticsParameter tempParam = newKinetics.getKineticsParameter(paramFunction.getName());
                if (tempParam == null) {
                    newKinetics.addUserDefinedKineticsParameter(paramFunction.getName(), paramFunction.getExpression(), unit);
                } else {
                    newKinetics.setParameterValue(tempParam, paramFunction.getExpression());
                    tempParam.setUnitDefinition(unit);
                }
            }
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace(System.out);
        throw new XmlParseException("Exception while setting parameters for Reaction : " + reaction.getName(), e);
    } catch (ExpressionException e) {
        e.printStackTrace(System.out);
        throw new XmlParseException("Exception while settings parameters for Reaction : " + reaction.getName(), e);
    } finally {
        newKinetics.reading(false);
    }
    return newKinetics;
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) StochVolVariable(cbit.vcell.math.StochVolVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) InsideVariable(cbit.vcell.math.InsideVariable) VolVariable(cbit.vcell.math.VolVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) PointVariable(cbit.vcell.math.PointVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) ParticleVariable(cbit.vcell.math.ParticleVariable) MemVariable(cbit.vcell.math.MemVariable) FilamentRegionVariable(cbit.vcell.math.FilamentRegionVariable) Variable(cbit.vcell.math.Variable) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) VariableHash(cbit.vcell.math.VariableHash) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) MacroscopicRateConstant(cbit.vcell.math.MacroscopicRateConstant) Constant(cbit.vcell.math.Constant) Element(org.jdom.Element) ReservedSymbol(cbit.vcell.model.Model.ReservedSymbol) NernstKinetics(cbit.vcell.model.NernstKinetics) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction) GeneralKinetics(cbit.vcell.model.GeneralKinetics) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) GeneralCurrentKinetics(cbit.vcell.model.GeneralCurrentKinetics) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) Function(cbit.vcell.math.Function) GeneralCurrentLumpedKinetics(cbit.vcell.model.GeneralCurrentLumpedKinetics) Membrane(cbit.vcell.model.Membrane) Macroscopic_IRRKinetics(cbit.vcell.model.Macroscopic_IRRKinetics) GeneralPermeabilityKinetics(cbit.vcell.model.GeneralPermeabilityKinetics) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) SimpleReaction(cbit.vcell.model.SimpleReaction) GHKKinetics(cbit.vcell.model.GHKKinetics) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Macroscopic_IRRKinetics(cbit.vcell.model.Macroscopic_IRRKinetics) Kinetics(cbit.vcell.model.Kinetics) NernstKinetics(cbit.vcell.model.NernstKinetics) GeneralKinetics(cbit.vcell.model.GeneralKinetics) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) GeneralPermeabilityKinetics(cbit.vcell.model.GeneralPermeabilityKinetics) GHKKinetics(cbit.vcell.model.GHKKinetics) MassActionKinetics(cbit.vcell.model.MassActionKinetics) Microscopic_IRRKinetics(cbit.vcell.model.Microscopic_IRRKinetics) GeneralCurrentKinetics(cbit.vcell.model.GeneralCurrentKinetics) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) GeneralCurrentLumpedKinetics(cbit.vcell.model.GeneralCurrentLumpedKinetics) Microscopic_IRRKinetics(cbit.vcell.model.Microscopic_IRRKinetics) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Aggregations

GHKKinetics (cbit.vcell.model.GHKKinetics)2 GeneralCurrentKinetics (cbit.vcell.model.GeneralCurrentKinetics)2 GeneralCurrentLumpedKinetics (cbit.vcell.model.GeneralCurrentLumpedKinetics)2 GeneralKinetics (cbit.vcell.model.GeneralKinetics)2 GeneralLumpedKinetics (cbit.vcell.model.GeneralLumpedKinetics)2 GeneralPermeabilityKinetics (cbit.vcell.model.GeneralPermeabilityKinetics)2 HMM_IRRKinetics (cbit.vcell.model.HMM_IRRKinetics)2 HMM_REVKinetics (cbit.vcell.model.HMM_REVKinetics)2 Kinetics (cbit.vcell.model.Kinetics)2 Macroscopic_IRRKinetics (cbit.vcell.model.Macroscopic_IRRKinetics)2 MassActionKinetics (cbit.vcell.model.MassActionKinetics)2 Microscopic_IRRKinetics (cbit.vcell.model.Microscopic_IRRKinetics)2 NernstKinetics (cbit.vcell.model.NernstKinetics)2 Constant (cbit.vcell.math.Constant)1 FilamentRegionVariable (cbit.vcell.math.FilamentRegionVariable)1 FilamentVariable (cbit.vcell.math.FilamentVariable)1 Function (cbit.vcell.math.Function)1 InsideVariable (cbit.vcell.math.InsideVariable)1 MacroscopicRateConstant (cbit.vcell.math.MacroscopicRateConstant)1 MathException (cbit.vcell.math.MathException)1