Search in sources :

Example 1 with MassActionKinetics

use of cbit.vcell.model.MassActionKinetics 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 MassActionKinetics

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

the class RbmNetworkGenerator method generateModel.

public static void generateModel(BioModel bioModel, String netfile) throws Exception {
    Model model = bioModel.getModel();
    Map<String, SpeciesContext> speciesMap = new HashMap<String, SpeciesContext>();
    Map<String, ReactionStep> reactionMap = new HashMap<String, ReactionStep>();
    List<ReactionLine> reactionLineList = new ArrayList<ReactionLine>();
    BufferedReader br = new BufferedReader(new StringReader(netfile));
    int reversibleCount = 0;
    int reactionCount = 0;
    while (true) {
        String line = br.readLine();
        if (line == null) {
            break;
        }
        line = line.trim();
        if (line.equals(BEGIN_PARAMETERS)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_PARAMETERS)) {
                    break;
                }
                StringTokenizer st = new StringTokenizer(line2);
                String token1 = st.nextToken();
                String token2 = st.nextToken();
                String token3 = st.nextToken();
                ModelParameter mp = model.new ModelParameter(token2, new Expression(token3), Model.ROLE_UserDefined, bioModel.getModel().getUnitSystem().getInstance_TBD());
                model.addModelParameter(mp);
            }
        } else if (line.equals(BEGIN_SPECIES)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_SPECIES)) {
                    break;
                }
                StringTokenizer st = new StringTokenizer(line2);
                // no
                String token1 = st.nextToken();
                // pattern
                String token2 = st.nextToken();
                // initial condition
                String token3 = st.nextToken();
                String newname = token2.replaceAll("\\.", "_");
                newname = newname.replaceAll("[\\(,][a-zA-Z]\\w*", "");
                newname = newname.replaceAll("~|!\\d*", "");
                newname = newname.replaceAll("\\(\\)", "");
                newname = newname.replaceAll("\\)", "");
                SpeciesContext sc = model.createSpeciesContext(model.getStructure(0));
                sc.setName(newname);
                bioModel.getVCMetaData().setFreeTextAnnotation(sc, token2);
                bioModel.getVCMetaData().setFreeTextAnnotation(sc.getSpecies(), token2);
                speciesMap.put(token1, sc);
            }
        } else if (line.equals(BEGIN_REACTIONS)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_REACTIONS)) {
                    break;
                }
                ++reactionCount;
                StringTokenizer st = new StringTokenizer(line2);
                String token1 = st.nextToken();
                // reactants
                String token2 = st.nextToken();
                // products
                String token3 = st.nextToken();
                // rate
                String token4 = st.nextToken();
                String token5 = st.nextToken();
                boolean bFoundReversible = false;
                Expression rate = new Expression(token4);
                for (ReactionLine rl : reactionLineList) {
                    if (token2.equals(rl.products) && token3.equals(rl.reactants) && token5.equals(rl.ruleLabel + "r")) {
                        ReactionStep rs = reactionMap.get(rl.no);
                        ((MassActionKinetics) rs.getKinetics()).getReverseRateParameter().setExpression(rate);
                        reactionLineList.remove(rl);
                        bFoundReversible = true;
                        break;
                    }
                }
                if (bFoundReversible) {
                    ++reversibleCount;
                    continue;
                }
                ReactionLine rl = new ReactionLine(token1, token2, token3, token5);
                reactionLineList.add(rl);
                SimpleReaction reaction = model.createSimpleReaction(model.getStructure(0));
                reactionMap.put(token1, reaction);
                reaction.setModel(model);
                bioModel.getVCMetaData().setFreeTextAnnotation(reaction, line2);
                MassActionKinetics kinetics = new MassActionKinetics(reaction);
                reaction.setKinetics(kinetics);
                st = new StringTokenizer(token2, ",");
                while (st.hasMoreTokens()) {
                    String t = st.nextToken();
                    SpeciesContext sc = speciesMap.get(t);
                    if (sc != null) {
                        boolean bExists = false;
                        for (ReactionParticipant rp : reaction.getReactionParticipants()) {
                            if (rp instanceof Reactant && rp.getSpeciesContext() == sc) {
                                rp.setStoichiometry(rp.getStoichiometry() + 1);
                                bExists = true;
                                break;
                            }
                        }
                        if (!bExists) {
                            reaction.addReactant(sc, 1);
                        }
                    }
                }
                st = new StringTokenizer(token3, ",");
                while (st.hasMoreTokens()) {
                    String t = st.nextToken();
                    SpeciesContext sc = speciesMap.get(t);
                    if (sc != null) {
                        boolean bExists = false;
                        for (ReactionParticipant rp : reaction.getReactionParticipants()) {
                            if (rp instanceof Product && rp.getSpeciesContext() == sc) {
                                rp.setStoichiometry(rp.getStoichiometry() + 1);
                                bExists = true;
                                break;
                            }
                        }
                        if (!bExists) {
                            reaction.addProduct(sc, 1);
                        }
                    }
                }
                kinetics.getForwardRateParameter().setExpression(rate);
            }
        }
    }
    System.out.println(model.getNumSpecies() + " species added");
    System.out.println(model.getNumReactions() + " reactions added");
    System.out.println(reversibleCount + " reversible reactions found");
    if (reactionCount != model.getNumReactions() + reversibleCount) {
        throw new RuntimeException("Reactions are not imported correctly!");
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) ModelParameter(cbit.vcell.model.Model.ModelParameter) StringTokenizer(java.util.StringTokenizer) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) MassActionKinetics(cbit.vcell.model.MassActionKinetics) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 3 with MassActionKinetics

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

the class SBPAXKineticsExtractor method extractKineticsExactMatch.

public static boolean extractKineticsExactMatch(ReactionStep reaction, Process process) throws ExpressionException, PropertyVetoException {
    // we try a perfect match first based on the existence of a SBOTerm in the kinetic law
    if (process.getControl() == null) {
        // no control means no kinetic law - nothing more to do
        return true;
    }
    Control control = process.getControl();
    ArrayList<SBEntity> sbEntities = control.getSBSubEntity();
    for (SBEntity sbE : sbEntities) {
        // the only SBSubEntities allowed in a control are kinetic laws
        if (sbE.getID().contains("kineticLaw")) {
            // build list of the parameters of this kinetic law in sboParams
            // params of this kinetic law
            ArrayList<SBOParam> sboParams = new ArrayList<SBOParam>();
            ArrayList<SBEntity> subEntities = sbE.getSBSubEntity();
            for (SBEntity subEntity : subEntities) {
                if (subEntity instanceof SBMeasurable) {
                    SBMeasurable m = (SBMeasurable) subEntity;
                    if (!m.hasTerm()) {
                        // we don't know what to do with a measurable with no SBTerm
                        break;
                    }
                    String termName = m.extractSBOTermAsString();
                    SBOTerm sboT = SBOListEx.sboMap.get(termName);
                    System.out.println("    " + sboT.getIndex() + "  " + sboT.getName());
                    SBOParam sboParam = matchSBOParam(sboT);
                    if (m.hasNumber()) {
                        double number = m.getNumber().get(0);
                        sboParam.setNumber(number);
                    }
                    if (m.hasUnit()) {
                        String unit = m.extractSBOUnitAsString();
                        sboParam.setUnit(unit);
                    }
                    sboParams.add(sboParam);
                }
            }
            // find if a kinetic law type exists and if not guesstimate one based on parameters
            // simple rule: if we have a Km param it's MM, otherwise it's mass action
            ArrayList<SBVocabulary> sbTerms = sbE.getSBTerm();
            if (sbTerms.isEmpty()) {
                // return false;
                SBVocabulary sbTerm = new SBVocabulary();
                ArrayList<String> termNames = new ArrayList<String>();
                String id;
                SBOParam kMichaelis = extractMichaelisForwardParam(sboParams);
                if (kMichaelis == null) {
                    // mass action rate law
                    id = new String("SBO:0000012");
                } else {
                    // irreversible Henri-Michaelis-Menten rate law
                    id = new String("SBO:0000029");
                }
                // termNames.add(id);
                // sbTerm.setTerm(termNames);
                sbTerm.setID(id);
                sbTerms.add(sbTerm);
            }
            System.out.println(" kinetic law ID: " + sbTerms.get(0).getID());
            // identify the kinetic law type (mass action, michaelis menten, etc) and bring it in vCell
            for (SBVocabulary sbv : sbTerms) {
                // use for loop even though we only expect 1 SBTerm
                // SBVocabulary id, used to retrieve the kinetic law type
                String vocabularyID = sbv.getID();
                SBOTerm sboT = SBOUtil.getSBOTermFromVocabularyId(vocabularyID);
                System.out.println(vocabularyID + "   " + sboT.getName());
                SBOParam kForward;
                SBOParam kCat;
                SBOParam vM;
                SBOParam kReverse;
                SBOParam kMichaelis;
                Kinetics kinetics;
                MappedKinetics current = matchSBOKineticLaw(sboT);
                switch(current) {
                    case SBO_0000069:
                    case SBO_0000432:
                        // some kinetic laws unknown to vCell will fall through to this category
                        // honestly i don't know what to do with them
                        System.out.println("GeneralKinetics");
                        // TODO: what to do here?
                        return true;
                    case SBO_0000012:
                    case SBO_0000078:
                        System.out.println("MassActionKinetics - reversible");
                        kForward = extractKForwardParam(sboParams);
                        kReverse = extractKReverseParam(sboParams);
                        kinetics = new MassActionKinetics(reaction);
                        reaction.setKinetics(kinetics);
                        setKForwardParam(reaction, kForward, kinetics);
                        setKReverseParam(reaction, kReverse, kinetics);
                        return true;
                    case SBO_0000043:
                        System.out.println("MassActionKinetics - zeroth order irreversible, Kr <- 0  ");
                        kForward = extractKForwardParam(sboParams);
                        kinetics = new MassActionKinetics(reaction);
                        // TODO: what to do here?
                        return true;
                    case SBO_0000044:
                        System.out.println("MassActionKinetics - first order irreversible, Kr <- 0  ");
                        kForward = extractKForwardParam(sboParams);
                        kinetics = new MassActionKinetics(reaction);
                        reaction.setKinetics(kinetics);
                        setKForwardParam(reaction, kForward, kinetics);
                        return true;
                    case SBO_0000028:
                    case SBO_0000029:
                        System.out.println("HMM_IRRKinetics");
                        // TODO: make kCat global variable, set its number and unit in annotation
                        // TODO: make vM global variable, set its number and unit in annotation
                        // get the numbers, if present (may be null)
                        kMichaelis = extractMichaelisForwardParam(sboParams);
                        vM = extractVMForwardParam(sboParams, process);
                        kCat = extractKCatForwardParam(sboParams);
                        kinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
                        try {
                            // TODO: create expression only if kCat != null, otherwise use vM directly (if != null) otherwise ???
                            kinetics.reading(true);
                            setVMForwardParamAsExpression(reaction, kCat, kinetics);
                        } finally {
                            kinetics.reading(false);
                        }
                        reaction.setKinetics(kinetics);
                        setMichaelisForwardParam(reaction, kMichaelis, kinetics);
                        return true;
                    case SBO_0000438:
                        System.out.println("HMMREVKinetics");
                        kinetics = new HMM_REVKinetics((SimpleReaction) reaction);
                        return true;
                    default:
                        // TODO: guessing happens above - if we have nothing by now we need to raise runtime exception
                        // change the code below !!!
                        System.out.println("Unable to match the SBOTerm with any compatible kinetic law.");
                        // found unmapped kinetic law, we'll try to guess a match
                        return false;
                }
            }
        }
    }
    // no SBTerm found so we cannot know for sure the kinetic law, we'll have to guess it
    return false;
}
Also used : SBVocabulary(org.vcell.pathway.sbpax.SBVocabulary) SimpleReaction(cbit.vcell.model.SimpleReaction) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) ArrayList(java.util.ArrayList) SBOTerm(org.vcell.pathway.sbo.SBOTerm) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) SBEntity(org.vcell.pathway.sbpax.SBEntity) SBOParam(org.vcell.pathway.sbo.SBOParam) SBMeasurable(org.vcell.pathway.sbpax.SBMeasurable) Control(org.vcell.pathway.Control) MassActionKinetics(cbit.vcell.model.MassActionKinetics) HMM_IRRKinetics(cbit.vcell.model.HMM_IRRKinetics) Kinetics(cbit.vcell.model.Kinetics) HMM_REVKinetics(cbit.vcell.model.HMM_REVKinetics) MassActionKinetics(cbit.vcell.model.MassActionKinetics)

Example 4 with MassActionKinetics

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

the class SBPAXKineticsExtractor method setKForwardParam.

private static void setKForwardParam(ReactionStep reaction, SBOParam kForward, Kinetics kinetics) throws ExpressionException, PropertyVetoException {
    if (kForward != null) {
        KineticsParameter fwdParam = ((MassActionKinetics) kinetics).getForwardRateParameter();
        kinetics.setParameterValue(fwdParam, new Expression(kForward.getNumber()));
        String unitF = SBOParam.formatUnit(kForward.getUnit());
        VCUnitDefinition fwdUnit = reaction.getModel().getUnitSystem().getInstance(unitF);
        fwdParam.setUnitDefinition(fwdUnit);
    }
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Expression(cbit.vcell.parser.Expression) MassActionKinetics(cbit.vcell.model.MassActionKinetics)

Example 5 with MassActionKinetics

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

the class SBPAXKineticsExtractor method setKReverseParam.

private static void setKReverseParam(ReactionStep reaction, SBOParam kReverse, Kinetics kinetics) throws ExpressionException, PropertyVetoException {
    if (kReverse != null) {
        KineticsParameter revParam = ((MassActionKinetics) kinetics).getReverseRateParameter();
        kinetics.setParameterValue(revParam, new Expression(kReverse.getNumber()));
        String unitR = SBOParam.formatUnit(kReverse.getUnit());
        VCUnitDefinition revUnit = reaction.getModel().getUnitSystem().getInstance(unitR);
        revParam.setUnitDefinition(revUnit);
    }
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Expression(cbit.vcell.parser.Expression) MassActionKinetics(cbit.vcell.model.MassActionKinetics)

Aggregations

MassActionKinetics (cbit.vcell.model.MassActionKinetics)16 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)11 Expression (cbit.vcell.parser.Expression)11 Kinetics (cbit.vcell.model.Kinetics)8 SimpleReaction (cbit.vcell.model.SimpleReaction)8 SpeciesContext (cbit.vcell.model.SpeciesContext)6 Model (cbit.vcell.model.Model)5 ReactionParticipant (cbit.vcell.model.ReactionParticipant)5 ReactionStep (cbit.vcell.model.ReactionStep)5 Function (cbit.vcell.math.Function)4 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)4 BioModel (cbit.vcell.biomodel.BioModel)3 MathDescription (cbit.vcell.math.MathDescription)3 Product (cbit.vcell.model.Product)3 Reactant (cbit.vcell.model.Reactant)3 ExpressionException (cbit.vcell.parser.ExpressionException)3 ArrayList (java.util.ArrayList)3 ImageException (cbit.image.ImageException)2 VCImage (cbit.image.VCImage)2 VCImageUncompressed (cbit.image.VCImageUncompressed)2