Search in sources :

Example 1 with GeneralLumpedKinetics

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

the class SBMLImporter method addReactions.

/**
 * addReactions:
 */
protected void addReactions(VCMetaData metaData) {
    if (sbmlModel == null) {
        throw new SBMLImportException("SBML model is NULL");
    }
    ListOf<Reaction> reactions = sbmlModel.getListOfReactions();
    final int numReactions = reactions.size();
    if (numReactions == 0) {
        lg.info("No Reactions");
        return;
    }
    // all reactions
    ArrayList<ReactionStep> vcReactionList = new ArrayList<>();
    // just the fast ones
    ArrayList<ReactionStep> fastReactionList = new ArrayList<>();
    Model vcModel = vcBioModel.getSimulationContext(0).getModel();
    ModelUnitSystem vcModelUnitSystem = vcModel.getUnitSystem();
    SpeciesContext[] vcSpeciesContexts = vcModel.getSpeciesContexts();
    try {
        for (Reaction sbmlRxn : reactions) {
            ReactionStep vcReaction = null;
            String rxnName = sbmlRxn.getId();
            boolean bReversible = true;
            if (sbmlRxn.isSetReversible()) {
                bReversible = sbmlRxn.getReversible();
            }
            // Check of reaction annotation is present; if so, does it have
            // an embedded element (flux or simpleRxn).
            // Create a fluxReaction or simpleReaction accordingly.
            Element sbmlImportRelatedElement = sbmlAnnotationUtil.readVCellSpecificAnnotation(sbmlRxn);
            Structure reactionStructure = getReactionStructure(sbmlRxn, vcSpeciesContexts, sbmlImportRelatedElement);
            if (sbmlImportRelatedElement != null) {
                Element embeddedRxnElement = getEmbeddedElementInAnnotation(sbmlImportRelatedElement, REACTION);
                if (embeddedRxnElement != null) {
                    if (embeddedRxnElement.getName().equals(XMLTags.FluxStepTag)) {
                        // If embedded element is a flux reaction, set flux
                        // reaction's strucure, flux carrier, physicsOption
                        // from the element attributes.
                        String structName = embeddedRxnElement.getAttributeValue(XMLTags.StructureAttrTag);
                        CastInfo<Membrane> ci = SBMLHelper.getTypedStructure(Membrane.class, vcModel, structName);
                        if (!ci.isGood()) {
                            throw new SBMLImportException("Appears that the flux reaction is occuring on " + ci.actualName() + ", not a membrane.");
                        }
                        vcReaction = new FluxReaction(vcModel, ci.get(), null, rxnName, bReversible);
                        vcReaction.setModel(vcModel);
                        // Set the fluxOption on the flux reaction based on
                        // whether it is molecular, molecular & electrical,
                        // electrical.
                        String fluxOptionStr = embeddedRxnElement.getAttributeValue(XMLTags.FluxOptionAttrTag);
                        if (fluxOptionStr.equals(XMLTags.FluxOptionMolecularOnly)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_MOLECULAR_ONLY);
                        } else if (fluxOptionStr.equals(XMLTags.FluxOptionMolecularAndElectrical)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_MOLECULAR_AND_ELECTRICAL);
                        } else if (fluxOptionStr.equals(XMLTags.FluxOptionElectricalOnly)) {
                            ((FluxReaction) vcReaction).setPhysicsOptions(ReactionStep.PHYSICS_ELECTRICAL_ONLY);
                        } else {
                            localIssueList.add(new Issue(vcReaction, issueContext, IssueCategory.SBMLImport_Reaction, "Unknown FluxOption : " + fluxOptionStr + " for SBML reaction : " + rxnName, Issue.SEVERITY_WARNING));
                        // logger.sendMessage(VCLogger.Priority.MediumPriority,
                        // VCLogger.ErrorType.ReactionError,
                        // "Unknown FluxOption : " + fluxOptionStr +
                        // " for SBML reaction : " + rxnName);
                        }
                    } else if (embeddedRxnElement.getName().equals(XMLTags.SimpleReactionTag)) {
                        // if embedded element is a simple reaction, set
                        // simple reaction's structure from element
                        // attributes
                        vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnName, bReversible);
                    }
                } else {
                    vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnName, bReversible);
                }
            } else {
                vcReaction = new SimpleReaction(vcModel, reactionStructure, rxnName, bReversible);
            }
            // set annotations and notes on vcReactions[i]
            sbmlAnnotationUtil.readAnnotation(vcReaction, sbmlRxn);
            sbmlAnnotationUtil.readNotes(vcReaction, sbmlRxn);
            // the limit on the reactionName length.
            if (rxnName.length() > 64) {
                String freeTextAnnotation = metaData.getFreeTextAnnotation(vcReaction);
                if (freeTextAnnotation == null) {
                    freeTextAnnotation = "";
                }
                StringBuffer oldRxnAnnotation = new StringBuffer(freeTextAnnotation);
                oldRxnAnnotation.append("\n\n" + rxnName);
                metaData.setFreeTextAnnotation(vcReaction, oldRxnAnnotation.toString());
            }
            // Now add the reactants, products, modifiers as specified by
            // the sbmlRxn
            addReactionParticipants(sbmlRxn, vcReaction);
            KineticLaw kLaw = sbmlRxn.getKineticLaw();
            Kinetics kinetics = null;
            if (kLaw != null) {
                // Convert the formula from kineticLaw into MathML and then
                // to an expression (infix) to be used in VCell kinetics
                ASTNode sbmlRateMath = kLaw.getMath();
                Expression kLawRateExpr = getExpressionFromFormula(sbmlRateMath);
                Expression vcRateExpression = new Expression(kLawRateExpr);
                // modifier (catalyst) to the reaction.
                for (int k = 0; k < vcSpeciesContexts.length; k++) {
                    if (vcRateExpression.hasSymbol(vcSpeciesContexts[k].getName())) {
                        if ((vcReaction.getReactant(vcSpeciesContexts[k].getName()) == null) && (vcReaction.getProduct(vcSpeciesContexts[k].getName()) == null) && (vcReaction.getCatalyst(vcSpeciesContexts[k].getName()) == null)) {
                            // This means that the speciesContext is not a
                            // reactant, product or modifier : it has to be
                            // added to the VC Rxn as a catalyst
                            vcReaction.addCatalyst(vcSpeciesContexts[k]);
                        }
                    }
                }
                // set kinetics on VCell reaction
                if (bSpatial) {
                    // if spatial SBML ('isSpatial' attribute set), create
                    // DistributedKinetics)
                    SpatialReactionPlugin ssrplugin = (SpatialReactionPlugin) sbmlRxn.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
                    // 'spatial'
                    if (ssrplugin != null && ssrplugin.getIsLocal()) {
                        kinetics = new GeneralKinetics(vcReaction);
                    } else {
                        kinetics = new GeneralLumpedKinetics(vcReaction);
                    }
                } else {
                    kinetics = new GeneralLumpedKinetics(vcReaction);
                }
                // set kinetics on vcReaction
                vcReaction.setKinetics(kinetics);
                // If the name of the rate parameter has been changed by
                // user, or matches with global/local param,
                // it has to be changed.
                resolveRxnParameterNameConflicts(sbmlRxn, kinetics, sbmlImportRelatedElement);
                /**
                 * Now, based on the kinetic law expression, see if the rate
                 * is expressed in concentration/time or substance/time : If
                 * the compartment_id of the compartment corresponding to
                 * the structure in which the reaction takes place occurs in
                 * the rate law expression, it is in concentration/time;
                 * divide it by the compartment size and bring in the rate
                 * law as 'Distributed' kinetics. If not, the rate law is in
                 * substance/time; bring it in (as is) as 'Lumped' kinetics.
                 */
                ListOf<LocalParameter> localParameters = kLaw.getListOfLocalParameters();
                for (LocalParameter p : localParameters) {
                    String paramName = p.getId();
                    KineticsParameter kineticsParameter = kinetics.getKineticsParameter(paramName);
                    if (kineticsParameter == null) {
                        // add unresolved for now to prevent errors in kinetics.setParameterValue(kp,vcRateExpression) below
                        kinetics.addUnresolvedParameter(paramName);
                    }
                }
                KineticsParameter kp = kinetics.getAuthoritativeParameter();
                if (lg.isDebugEnabled()) {
                    lg.debug("Setting " + kp.getName() + ":  " + vcRateExpression.infix());
                }
                kinetics.setParameterValue(kp, vcRateExpression);
                // If there are any global parameters used in the kinetics,
                // and if they have species,
                // check if the species are already reactionParticipants in
                // the reaction. If not, add them as catalysts.
                KineticsProxyParameter[] kpps = kinetics.getProxyParameters();
                for (int j = 0; j < kpps.length; j++) {
                    if (kpps[j].getTarget() instanceof ModelParameter) {
                        ModelParameter mp = (ModelParameter) kpps[j].getTarget();
                        HashSet<String> refSpeciesNameHash = new HashSet<String>();
                        getReferencedSpeciesInExpr(mp.getExpression(), refSpeciesNameHash);
                        java.util.Iterator<String> refSpIterator = refSpeciesNameHash.iterator();
                        while (refSpIterator.hasNext()) {
                            String spName = refSpIterator.next();
                            org.sbml.jsbml.Species sp = sbmlModel.getSpecies(spName);
                            ArrayList<ReactionParticipant> rpArray = getVCReactionParticipantsFromSymbol(vcReaction, sp.getId());
                            if (rpArray == null || rpArray.size() == 0) {
                                // This means that the speciesContext is not
                                // a reactant, product or modifier : it has
                                // to be added as a catalyst
                                vcReaction.addCatalyst(vcModel.getSpeciesContext(sp.getId()));
                            }
                        }
                    }
                }
                // model - local params cannot be defined by rules.
                for (LocalParameter param : localParameters) {
                    String paramName = param.getId();
                    Expression exp = new Expression(param.getValue());
                    String unitString = param.getUnits();
                    VCUnitDefinition paramUnit = sbmlUnitIdentifierHash.get(unitString);
                    if (paramUnit == null) {
                        paramUnit = vcModelUnitSystem.getInstance_TBD();
                    }
                    // check if sbml local param is in kinetic params list;
                    // if so, add its value.
                    boolean lpSet = false;
                    KineticsParameter kineticsParameter = kinetics.getKineticsParameter(paramName);
                    if (kineticsParameter != null) {
                        if (lg.isDebugEnabled()) {
                            lg.debug("Setting local " + kineticsParameter.getName() + ":  " + exp.infix());
                        }
                        kineticsParameter.setExpression(exp);
                        kineticsParameter.setUnitDefinition(paramUnit);
                        lpSet = true;
                    } else {
                        UnresolvedParameter ur = kinetics.getUnresolvedParameter(paramName);
                        if (ur != null) {
                            kinetics.addUserDefinedKineticsParameter(paramName, exp, paramUnit);
                            lpSet = true;
                        }
                    }
                    if (!lpSet) {
                        // check if it is a proxy parameter (specifically,
                        // speciesContext or model parameter (structureSize
                        // too)).
                        KineticsProxyParameter kpp = kinetics.getProxyParameter(paramName);
                        // and units to local param values
                        if (kpp != null && kpp.getTarget() instanceof ModelParameter) {
                            kinetics.convertParameterType(kpp, false);
                            kineticsParameter = kinetics.getKineticsParameter(paramName);
                            kinetics.setParameterValue(kineticsParameter, exp);
                            kineticsParameter.setUnitDefinition(paramUnit);
                        }
                    }
                }
            } else {
                // sbmlKLaw was null, so creating a GeneralKinetics with 0.0
                // as rate.
                kinetics = new GeneralKinetics(vcReaction);
            }
            // end - if-else KLaw != null
            // set the reaction kinetics, and add reaction to the vcell
            // model.
            kinetics.resolveUndefinedUnits();
            // System.out.println("ADDED SBML REACTION : \"" + rxnName +
            // "\" to VCModel");
            vcReactionList.add(vcReaction);
            if (sbmlRxn.isSetFast() && sbmlRxn.getFast()) {
                fastReactionList.add(vcReaction);
            }
        }
        // end - for vcReactions
        ReactionStep[] array = vcReactionList.toArray(new ReactionStep[vcReactionList.size()]);
        vcModel.setReactionSteps(array);
        final ReactionContext rc = vcBioModel.getSimulationContext(0).getReactionContext();
        for (ReactionStep frs : fastReactionList) {
            final ReactionSpec rs = rc.getReactionSpec(frs);
            rs.setReactionMapping(ReactionSpec.FAST);
        }
    } catch (ModelPropertyVetoException mpve) {
        throw new SBMLImportException(mpve.getMessage(), mpve);
    } catch (Exception e1) {
        e1.printStackTrace(System.out);
        throw new SBMLImportException(e1.getMessage(), e1);
    }
}
Also used : Issue(org.vcell.util.Issue) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralKinetics(cbit.vcell.model.GeneralKinetics) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) ReactionContext(cbit.vcell.mapping.ReactionContext) HashSet(java.util.HashSet) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) ReactionSpec(cbit.vcell.mapping.ReactionSpec) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ReactionStep(cbit.vcell.model.ReactionStep) Kinetics(cbit.vcell.model.Kinetics) GeneralKinetics(cbit.vcell.model.GeneralKinetics) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) KineticLaw(org.sbml.jsbml.KineticLaw) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Element(org.jdom.Element) UnresolvedParameter(cbit.vcell.model.Kinetics.UnresolvedParameter) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) ASTNode(org.sbml.jsbml.ASTNode) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) SpatialReactionPlugin(org.sbml.jsbml.ext.spatial.SpatialReactionPlugin) SimpleReaction(cbit.vcell.model.SimpleReaction) Reaction(org.sbml.jsbml.Reaction) SimpleReaction(cbit.vcell.model.SimpleReaction) FluxReaction(cbit.vcell.model.FluxReaction) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) XMLStreamException(javax.xml.stream.XMLStreamException) SbmlException(org.vcell.sbml.SbmlException) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) SBMLException(org.sbml.jsbml.SBMLException) ModelPropertyVetoException(cbit.vcell.model.ModelPropertyVetoException) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(org.sbml.jsbml.LocalParameter) Expression(cbit.vcell.parser.Expression) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel)

Example 2 with GeneralLumpedKinetics

use of cbit.vcell.model.GeneralLumpedKinetics 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 3 with GeneralLumpedKinetics

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

the class ReactionCartoonTool method lineAction.

private void lineAction(Structure startStructure, SpeciesContext speciesContextEnd) throws PropertyVetoException, Exception {
    Structure endStructure = speciesContextEnd.getStructure();
    Model model = getModel();
    ReactionStep reaction = null;
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    Structure reactionStructure = null;
    if (startStructure != endStructure) {
        if (startStructure instanceof Feature && endStructure instanceof Feature) {
            // Feature ==> Feature-speciesContext
            Feature startFeature = (Feature) startStructure;
            Feature endFeature = (Feature) endStructure;
            // Feature ==> feature-speciesContext with no membrane between : create a 0th-order simpleReaction in startFeature with GeneralLumpedKinetics
            reactionStructure = startStructure;
            reaction = model.createSimpleReaction(reactionStructure);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
        } else if (startStructure instanceof Feature && endStructure instanceof Membrane) {
            // Feature ==> membrane-species : Create volume species ; create membrane reaction ; add volume species as reactant and membrane species(End) as product.
            reactionStructure = endStructure;
            reaction = model.createSimpleReaction(reactionStructure);
            SpeciesContext startingSpeciesContext = model.createSpeciesContext(startStructure);
            reaction.addReactant(startingSpeciesContext, 1);
            positionShapeForObject(startStructure, startingSpeciesContext, startPos);
        } else if (startStructure instanceof Membrane && endStructure instanceof Feature) {
            // Membrane ==> Feature-species : 0th-order reaction in membrane
            reactionStructure = startStructure;
            reaction = model.createSimpleReaction(reactionStructure);
        } else if (startStructure instanceof Membrane && endStructure instanceof Membrane) {
            // Membrane ==> membrane-species : the 2 membranes are different : create a 0th-order lumped simpleReaction in startMembrane
            reactionStructure = startStructure;
            reaction = model.createSimpleReaction(reactionStructure);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
        }
    } else {
        // startStructure == endStructure : 0th-order simplereaction in structure
        reactionStructure = startStructure;
        reaction = model.createSimpleReaction(reactionStructure);
    }
    // speciesContextEnd should be added as a product to reaction (if not flux).
    if (!(reaction instanceof FluxReaction)) {
        reaction.addProduct(speciesContextEnd, 1);
    }
    positionShapeForObject(reactionStructure, reaction, new Point((2 * startPos.x + 8 * endPos.x) / 10, (2 * startPos.y + 8 * endPos.y) / 10));
    getReactionCartoon().notifyChangeEvent();
    getGraphModel().clearSelection();
    getGraphModel().select(reaction);
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) GraphModel(cbit.gui.graph.GraphModel) Membrane(cbit.vcell.model.Membrane) FluxReaction(cbit.vcell.model.FluxReaction) Point(java.awt.Point) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) SpeciesContext(cbit.vcell.model.SpeciesContext) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Example 4 with GeneralLumpedKinetics

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

the class ReactionCartoonTool method lineAction.

private void lineAction(SpeciesContext speciesContextStart, SpeciesContext speciesContextEnd) throws Exception {
    Structure endStructure = speciesContextEnd.getStructure();
    Structure startStructure = speciesContextStart.getStructure();
    Model model = getModel();
    ReactionStep reaction = null;
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    Structure reactionStructure = null;
    boolean bLumpedKinetics = false;
    if (startStructure != endStructure) {
        if (startStructure instanceof Feature && endStructure instanceof Feature) {
            // Feature-speciesContext ==> Feature-speciesContext
            Membrane membraneBetween = model.getStructureTopology().getMembrane((Feature) startStructure, (Feature) endStructure);
            // Feature-speciesContext ==> Feature-speciesContext with membrane in between : add reaction in Membrane (scStart : reactant; scEnd : pdt)
            if (membraneBetween != null) {
                reactionStructure = membraneBetween;
            } else {
                // Feature-speciesContext ==> Feature-speciesContext with no membrane between : create a lumped reaction in startFeature
                reactionStructure = startStructure;
                bLumpedKinetics = true;
            }
        } else if (startStructure instanceof Feature && endStructure instanceof Membrane) {
            // Feature-speciesContext ==> Membrane-speciesContext : create membrane reaction ; add scStart : reactant and scEnd : pdt.
            reactionStructure = endStructure;
        } else if (startStructure instanceof Membrane && endStructure instanceof Feature) {
            // Membrane-speciesContext ==> Feature-speciesContext : create reaction in membrane; scStart : reactant, scEnd : pdt.
            reactionStructure = startStructure;
        } else if (startStructure instanceof Membrane && endStructure instanceof Membrane) {
            // Membrane-speciesContext ==> Membrane-speciesContext : the 2 membranes are different : create lumped reaction in endMembrane
            reactionStructure = endStructure;
            bLumpedKinetics = true;
        }
    } else {
        // startStructure == endStructure : create reaction in structure
        reactionStructure = startStructure;
    }
    reaction = model.createSimpleReaction(reactionStructure);
    if (bLumpedKinetics) {
        reaction.setKinetics(new GeneralLumpedKinetics(reaction));
    }
    reaction.addReactant(speciesContextStart, 1);
    reaction.addProduct(speciesContextEnd, 1);
    positionShapeForObject(reactionStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
    getReactionCartoon().notifyChangeEvent();
    getGraphModel().clearSelection();
    getGraphModel().select(reaction);
}
Also used : ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) GraphModel(cbit.gui.graph.GraphModel) Membrane(cbit.vcell.model.Membrane) Point(java.awt.Point) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) Structure(cbit.vcell.model.Structure) Feature(cbit.vcell.model.Feature)

Example 5 with GeneralLumpedKinetics

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

the class ReactionCartoonTool method lineAction.

private void lineAction(Structure startStructure, Structure endStructure, Shape endShape) throws Exception, PropertyVetoException, ExpressionException {
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    if (endStructure.equals(startStructure)) {
        SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endStructure);
        reaction.addReactant(speciesContext1, 1);
        reaction.addProduct(speciesContext2, 1);
        getReactionCartoon().notifyChangeEvent();
        positionShapeForObject(endStructure, speciesContext1, startPos);
        positionShapeForObject(endStructure, speciesContext2, endPos);
        positionShapeForObject(endStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
        getGraphModel().clearSelection();
        getGraphModel().select(reaction);
    } else {
        if (endStructure instanceof Membrane && startStructure instanceof Feature) {
            Membrane endMembrane = (Membrane) endStructure;
            Feature startFeature = (Feature) startStructure;
            // if(structTopology.getOutsideFeature(endMembrane).equals(startFeature) || structTopology.getInsideFeature(endMembrane).equals(startFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startFeature);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endMembrane);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startFeature, speciesContext1, startPos);
            positionShapeForObject(endMembrane, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = endShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + endShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(endMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Membrane) {
            Membrane startMembrane = (Membrane) startStructure;
            Feature endFeature = (Feature) endStructure;
            // if(structTopology.getOutsideFeature(startMembrane).equals(endFeature) || structTopology.getInsideFeature(startMembrane).equals(endFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startMembrane);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endFeature);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startMembrane, speciesContext1, startPos);
            positionShapeForObject(endFeature, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = startShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + startShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(startMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Feature) {
            Feature startFeature = (Feature) startStructure;
            Feature endFeature = (Feature) endStructure;
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        } else if (endStructure instanceof Membrane && startStructure instanceof Membrane) {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        }
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Membrane(cbit.vcell.model.Membrane) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) Point(java.awt.Point) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) Feature(cbit.vcell.model.Feature) Point(java.awt.Point)

Aggregations

GeneralLumpedKinetics (cbit.vcell.model.GeneralLumpedKinetics)6 Membrane (cbit.vcell.model.Membrane)5 BioModel (cbit.vcell.biomodel.BioModel)3 Feature (cbit.vcell.model.Feature)3 FluxReaction (cbit.vcell.model.FluxReaction)3 GeneralKinetics (cbit.vcell.model.GeneralKinetics)3 Kinetics (cbit.vcell.model.Kinetics)3 SimpleReaction (cbit.vcell.model.SimpleReaction)3 Point (java.awt.Point)3 GraphModel (cbit.gui.graph.GraphModel)2 GHKKinetics (cbit.vcell.model.GHKKinetics)2 GeneralCurrentKinetics (cbit.vcell.model.GeneralCurrentKinetics)2 GeneralCurrentLumpedKinetics (cbit.vcell.model.GeneralCurrentLumpedKinetics)2 GeneralPermeabilityKinetics (cbit.vcell.model.GeneralPermeabilityKinetics)2 HMM_IRRKinetics (cbit.vcell.model.HMM_IRRKinetics)2 HMM_REVKinetics (cbit.vcell.model.HMM_REVKinetics)2 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)2 Model (cbit.vcell.model.Model)2 ReactionStep (cbit.vcell.model.ReactionStep)2 SpeciesContext (cbit.vcell.model.SpeciesContext)2