Search in sources :

Example 6 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class StructurePropertiesPanel method updateInterface.

/**
 * Comment
 */
private void updateInterface() {
    boolean bNonNullStructure = structure != null && fieldModel != null;
    nameTextField.setEditable(bNonNullStructure);
    annotationTextArea.setEditable(bNonNullStructure);
    boolean bMembrane = bNonNullStructure && structure instanceof Membrane;
    voltageLabel.setVisible(bMembrane);
    voltageTextField.setVisible(bMembrane);
    electrophysiologyLabel.setVisible(bMembrane);
    positiveFeatureLabel.setVisible(bMembrane);
    positiveFeatureComboBox.setVisible(bMembrane);
    negativeFeatureLabel.setVisible(bMembrane);
    negativeFeatureComboBox.setVisible(bMembrane);
    electrophysiologyExplanationLabel.setVisible(bMembrane);
    if (bNonNullStructure) {
        nameTextField.setText(structure.getName());
        annotationTextArea.setText(fieldModel.getVcMetaData().getFreeTextAnnotation(structure));
        StructureSize structureSize = structure.getStructureSize();
        sizeTextField.setText(structureSize.getName() + " [" + structureSize.getUnitDefinition().getSymbolUnicode() + "]");
        if (bMembrane) {
            Membrane membrane = (Membrane) structure;
            MembraneVoltage memVoltage = membrane.getMembraneVoltage();
            voltageTextField.setText(memVoltage.getName() + " [" + memVoltage.getUnitDefinition().getSymbolUnicode() + "]");
            // if membrane has +ve/-ve feature set, set the comboBox with that selection.
            ElectricalTopology electricalTopology = fieldModel.getElectricalTopology();
            Feature positiveFeature = electricalTopology.getPositiveFeature(membrane);
            if (positiveFeature != null) {
                positiveFeatureComboBox.setSelectedItem(positiveFeature.getName());
            }
            Feature negativeFeature = electricalTopology.getNegativeFeature(membrane);
            if (negativeFeature != null) {
                negativeFeatureComboBox.setSelectedItem(negativeFeature.getName());
            }
            this.electrophysiologyExplanationLabel.setText(getExplanationText());
        }
    } else {
        annotationTextArea.setText(null);
        nameTextField.setText(null);
        sizeTextField.setText(null);
        voltageTextField.setText(null);
    }
}
Also used : MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) ElectricalTopology(cbit.vcell.model.Model.ElectricalTopology) Membrane(cbit.vcell.model.Membrane) StructureSize(cbit.vcell.model.Structure.StructureSize) Feature(cbit.vcell.model.Feature)

Example 7 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class BioCartoonTool method pasteReactionSteps0.

/**
 * pasteReactionSteps0 : does the actual pasting. First called with a cloned model, to track issues. If user still wants to proceed, the paste
 * is performed on the original model.
 *
 * Insert the method's description here.
 * Creation date: (5/10/2003 3:55:25 PM)
 * @param pasteToModel cbit.vcell.model.Model
 * @param pasteToStructure cbit.vcell.model.Structure
 * @param bNew boolean
 */
private static final PasteHelper pasteReactionSteps0(HashMap<String, HashMap<ReactionParticipant, Structure>> rxPartMapStructure, Component parent, IssueContext issueContext, ReactionStep[] copyFromRxSteps, Model pasteToModel, Structure pasteToStructure, boolean bNew, /*boolean bUseDBSpecies,*/
UserResolvedRxElements userResolvedRxElements) throws Exception {
    HashMap<BioModelEntityObject, BioModelEntityObject> reactionsAndSpeciesContexts = new HashMap<>();
    if (copyFromRxSteps == null || copyFromRxSteps.length == 0 || pasteToModel == null || pasteToStructure == null) {
        throw new IllegalArgumentException("CartoonTool.pasteReactionSteps Error " + (copyFromRxSteps == null || copyFromRxSteps.length == 0 ? "reactionStepsArr empty " : "") + (pasteToModel == null ? "model is null " : "") + (pasteToStructure == null ? "struct is null " : ""));
    }
    if (!pasteToModel.contains(pasteToStructure)) {
        throw new IllegalArgumentException("CartoonTool.pasteReactionSteps model " + pasteToModel.getName() + " does not contain structure " + pasteToStructure.getName());
    }
    // Check PasteToModel has preferred targets if set
    if (userResolvedRxElements != null) {
        for (int i = 0; i < userResolvedRxElements.toSpeciesArr.length; i++) {
            if (userResolvedRxElements.toSpeciesArr[i] != null) {
                if (!pasteToModel.contains(userResolvedRxElements.toSpeciesArr[i])) {
                    throw new RuntimeException("PasteToModel does not contain preferred Species " + userResolvedRxElements.toSpeciesArr[i]);
                }
            }
            if (userResolvedRxElements.toStructureArr[i] != null) {
                if (!pasteToModel.contains(userResolvedRxElements.toStructureArr[i])) {
                    throw new RuntimeException("PasteToModel does not contain preferred Structure " + userResolvedRxElements.toStructureArr[i]);
                }
            }
        }
    }
    int counter = 0;
    Structure currentStruct = pasteToStructure;
    String copiedStructName = copyFromRxSteps[counter].getStructure().getName();
    StructureTopology structTopology = (copyFromRxSteps[counter].getModel() == null ? pasteToModel.getStructureTopology() : copyFromRxSteps[counter].getModel().getStructureTopology());
    IdentityHashMap<Species, Species> speciesHash = new IdentityHashMap<Species, Species>();
    IdentityHashMap<SpeciesContext, SpeciesContext> speciesContextHash = new IdentityHashMap<SpeciesContext, SpeciesContext>();
    Vector<Issue> issueVector = new Vector<Issue>();
    do {
        // create a new reaction, instead of cloning the old one; set struc
        ReactionStep copyFromReactionStep = copyFromRxSteps[counter];
        String newName = copyFromReactionStep.getName();
        while (pasteToModel.getReactionStep(newName) != null) {
            newName = org.vcell.util.TokenMangler.getNextEnumeratedToken(newName);
        }
        ReactionStep newReactionStep = null;
        if (copyFromReactionStep instanceof SimpleReaction) {
            newReactionStep = new SimpleReaction(pasteToModel, currentStruct, newName, copyFromReactionStep.isReversible());
        } else if (copyFromReactionStep instanceof FluxReaction && currentStruct instanceof Membrane) {
            newReactionStep = new FluxReaction(pasteToModel, (Membrane) currentStruct, null, newName, copyFromReactionStep.isReversible());
        }
        pasteToModel.addReactionStep(newReactionStep);
        reactionsAndSpeciesContexts.put(newReactionStep, copyFromReactionStep);
        Structure toRxnStruct = newReactionStep.getStructure();
        Structure fromRxnStruct = copyFromReactionStep.getStructure();
        if (!fromRxnStruct.getClass().equals(pasteToStructure.getClass())) {
            throw new Exception("Cannot copy reaction from " + fromRxnStruct.getTypeName() + " to " + pasteToStructure.getTypeName() + ".");
        }
        // add appropriate reactionParticipants to newReactionStep.
        StructureTopology toStructureTopology = pasteToModel.getStructureTopology();
        ReactionParticipant[] copyFromRxParticipantArr = copyFromReactionStep.getReactionParticipants();
        if (rxPartMapStructure == null) {
            // null during 'issues' trial
            rxPartMapStructure = new HashMap<String, HashMap<ReactionParticipant, Structure>>();
        }
        if (rxPartMapStructure.get(copyFromReactionStep.getName()) == null) {
            // Ask user to assign species to compartments for each reaction to be pasted
            rxPartMapStructure.put(copyFromReactionStep.getName(), askUserResolveMembraneConnections(parent, pasteToModel.getStructures(), currentStruct, fromRxnStruct, toRxnStruct, copyFromRxParticipantArr, toStructureTopology, structTopology));
        }
        for (int i = 0; i < copyFromRxParticipantArr.length; i += 1) {
            Structure pasteToStruct = currentStruct;
            // if(toRxnStruct instanceof Membrane){
            pasteToStruct = rxPartMapStructure.get(copyFromReactionStep.getName()).get(copyFromRxParticipantArr[i]);
            // if(pasteToStruct == null){
            // for(ReactionParticipant myRXPart:rxPartMapStructure.get(copyFromReactionStep.getName()).keySet()){
            // if(myRXPart.getSpeciesContext().getName().equals(copyFromRxParticipantArr[i].getSpeciesContext().getName())){
            // pasteToStruct = rxPartMapStructure.get(copyFromReactionStep.getName()).get(myRXPart);
            // break;
            // }
            // }
            // }
            // }
            // this adds the speciesContexts and species (if any) to the model)
            String rootSC = ReactionCartoonTool.speciesContextRootFinder(copyFromRxParticipantArr[i].getSpeciesContext());
            SpeciesContext newSc = null;
            SpeciesContext[] matchSC = pasteToModel.getSpeciesContexts();
            for (int j = 0; matchSC != null && j < matchSC.length; j++) {
                String matchRoot = ReactionCartoonTool.speciesContextRootFinder(matchSC[j]);
                if (matchRoot != null && matchRoot.equals(rootSC) && matchSC[j].getStructure().getName().equals(pasteToStruct.getName())) {
                    newSc = matchSC[j];
                    reactionsAndSpeciesContexts.put(newSc, matchSC[j]);
                    break;
                }
            }
            if (newSc == null) {
                newSc = pasteSpecies(parent, copyFromRxParticipantArr[i].getSpecies(), rootSC, pasteToModel, pasteToStruct, bNew, /*bUseDBSpecies,*/
                speciesHash, UserResolvedRxElements.getPreferredReactionElement(userResolvedRxElements, copyFromRxParticipantArr[i]));
                reactionsAndSpeciesContexts.put(newSc, copyFromRxParticipantArr[i].getSpeciesContext());
            }
            // record the old-new speciesContexts (reactionparticipants) in the IdHashMap, this is useful, esp for 'Paste new', while replacing proxyparams.
            SpeciesContext oldSc = copyFromRxParticipantArr[i].getSpeciesContext();
            if (speciesContextHash.get(oldSc) == null) {
                speciesContextHash.put(oldSc, newSc);
            }
            if (copyFromRxParticipantArr[i] instanceof Reactant) {
                newReactionStep.addReactionParticipant(new Reactant(null, newReactionStep, newSc, copyFromRxParticipantArr[i].getStoichiometry()));
            } else if (copyFromRxParticipantArr[i] instanceof Product) {
                newReactionStep.addReactionParticipant(new Product(null, newReactionStep, newSc, copyFromRxParticipantArr[i].getStoichiometry()));
            } else if (copyFromRxParticipantArr[i] instanceof Catalyst) {
                newReactionStep.addCatalyst(newSc);
            }
        }
        // // If 'newReactionStep' is a fluxRxn, set its fluxCarrier
        // if (newReactionStep instanceof FluxReaction) {
        // if (fluxCarrierSp != null) {
        // ((FluxReaction)newReactionStep).setFluxCarrier(fluxCarrierSp, pasteToModel);
        // } else {
        // throw new RuntimeException("Could not set FluxCarrier species for the flux reaction to be pasted");
        // }
        // }
        // For each kinetic parameter expression for new kinetics, replace the proxyParams from old kinetics with proxyParams in new kinetics
        // i.e., if the proxyParams are speciesContexts, replace with corresponding speciesContext in newReactionStep;
        // if the proxyParams are structureSizes or MembraneVoltages, replace with corresponding structure quantity in newReactionStep
        Kinetics oldKinetics = copyFromReactionStep.getKinetics();
        KineticsParameter[] oldKps = oldKinetics.getKineticsParameters();
        KineticsProxyParameter[] oldKprps = oldKinetics.getProxyParameters();
        Hashtable<String, Expression> paramExprHash = new Hashtable<String, Expression>();
        for (int i = 0; oldKps != null && i < oldKps.length; i++) {
            Expression newExpression = new Expression(oldKps[i].getExpression());
            for (int j = 0; oldKprps != null && j < oldKprps.length; j++) {
                // check if kinetic proxy parameter is in kinetic parameter expression
                if (newExpression.hasSymbol(oldKprps[j].getName())) {
                    SymbolTableEntry ste = oldKprps[j].getTarget();
                    Model pasteFromModel = copyFromReactionStep.getModel();
                    if (ste instanceof SpeciesContext) {
                        // if newRxnStruct is a feature/membrane, get matching spContexts from old reaction and replace them in new rate expr.
                        SpeciesContext oldSC = (SpeciesContext) ste;
                        SpeciesContext newSC = speciesContextHash.get(oldSC);
                        if (newSC == null) {
                            // check if oldSc is present in paste-model; if not, add it.
                            if (!pasteToModel.equals(pasteFromModel)) {
                                if (pasteToModel.getSpeciesContext(oldSC.getName()) == null) {
                                    // if paste-model has oldSc struct, paste it there,
                                    Structure newSCStruct = pasteToModel.getStructure(oldSC.getStructure().getName());
                                    if (newSCStruct != null) {
                                        newSC = pasteSpecies(parent, oldSC.getSpecies(), null, pasteToModel, newSCStruct, bNew, /*bUseDBSpecies,*/
                                        speciesHash, UserResolvedRxElements.getPreferredReactionElement(userResolvedRxElements, oldSC));
                                        speciesContextHash.put(oldSC, newSC);
                                    } else {
                                        // oldStruct wasn't found in paste-model, paste it in newRxnStruct and add warning to issues list
                                        newSC = pasteSpecies(parent, oldSC.getSpecies(), null, pasteToModel, toRxnStruct, bNew, /*bUseDBSpecies,*/
                                        speciesHash, UserResolvedRxElements.getPreferredReactionElement(userResolvedRxElements, oldSC));
                                        speciesContextHash.put(oldSC, newSC);
                                        Issue issue = new Issue(oldSC, issueContext, IssueCategory.CopyPaste, "SpeciesContext '" + oldSC.getSpecies().getCommonName() + "' was not found in compartment '" + oldSC.getStructure().getName() + "' in the model; the species was added to the compartment '" + toRxnStruct.getName() + "' where the reaction was pasted.", Issue.SEVERITY_WARNING);
                                        issueVector.add(issue);
                                    }
                                }
                            }
                        // if models are the same and newSc is null, then oldSc is not a rxnParticipant. Leave it as is in the expr.
                        }
                        if (newSC != null) {
                            reactionsAndSpeciesContexts.put(newSC, oldSC);
                            newExpression.substituteInPlace(new Expression(ste.getName()), new Expression(newSC.getName()));
                        }
                    // SpeciesContext sc = null;
                    // Species newSp = model.getSpecies(oldSc.getSpecies().getCommonName());
                    // if  (oldSc.getStructure() == (oldRxnStruct)) {
                    // sc = model.getSpeciesContext(newSp, newRxnStruct);
                    // } else {
                    // if (newRxnStruct instanceof Membrane) {
                    // // for a membrane, we need to make sure that inside-outside spContexts used are appropriately replaced.
                    // if (oldSc.getStructure() == ((Membrane)oldRxnStruct).getOutsideFeature()) {
                    // // old speciesContext is outside (old) membrane, new spContext should be outside new membrane
                    // sc = model.getSpeciesContext(newSp, ((Membrane)newRxnStruct).getOutsideFeature());
                    // } else if (oldSc.getStructure() == ((Membrane)oldRxnStruct).getInsideFeature()) {
                    // // old speciesContext is inside (old) membrane, new spContext should be inside new membrane
                    // sc = model.getSpeciesContext(newSp, ((Membrane)newRxnStruct).getInsideFeature());
                    // }
                    // }
                    // }
                    // if (sc != null) {
                    // newExpression.substituteInPlace(new Expression(ste.getName()), new Expression(sc.getName()));
                    // }
                    } else if (ste instanceof StructureSize) {
                        Structure str = ((StructureSize) ste).getStructure();
                        // if the structure size used is same as the structure in which the reaction is present, change the structSize to appropriate new struct
                        if (str.compareEqual(fromRxnStruct)) {
                            newExpression.substituteInPlace(new Expression(ste.getName()), new Expression(toRxnStruct.getStructureSize().getName()));
                        } else {
                            if (fromRxnStruct instanceof Membrane) {
                                if (str.equals(structTopology.getOutsideFeature((Membrane) fromRxnStruct))) {
                                    newExpression.substituteInPlace(new Expression(ste.getName()), new Expression(structTopology.getOutsideFeature((Membrane) toRxnStruct).getStructureSize().getName()));
                                } else if (str.equals(structTopology.getInsideFeature((Membrane) fromRxnStruct))) {
                                    newExpression.substituteInPlace(new Expression(ste.getName()), new Expression(structTopology.getInsideFeature((Membrane) toRxnStruct).getStructureSize().getName()));
                                }
                            }
                        }
                    } else if (ste instanceof MembraneVoltage) {
                        Membrane membr = ((MembraneVoltage) ste).getMembrane();
                        // if the MembraneVoltage used is same as that of the membrane in which the reaction is present, change the MemVoltage
                        if ((fromRxnStruct instanceof Membrane) && (membr.compareEqual(fromRxnStruct))) {
                            newExpression.substituteInPlace(new Expression(ste.getName()), new Expression(((Membrane) toRxnStruct).getMembraneVoltage().getName()));
                        }
                    } else if (ste instanceof ModelParameter) {
                        // see if model has this global parameter (if rxn is being pasted into another model, it won't)
                        if (!pasteToModel.equals(pasteFromModel)) {
                            ModelParameter oldMp = (ModelParameter) ste;
                            ModelParameter mp = pasteToModel.getModelParameter(oldMp.getName());
                            boolean bNonNumeric = false;
                            String newMpName = oldMp.getName();
                            if (mp != null) {
                                // new model has a model parameter with same name - are they the same param?
                                if (!mp.getExpression().equals(oldMp.getExpression())) {
                                    // no, they are not the same param, so mangle the 'ste' name and add as global in the other model
                                    while (pasteToModel.getModelParameter(newMpName) != null) {
                                        newMpName = TokenMangler.getNextEnumeratedToken(newMpName);
                                    }
                                    // if expression if numeric, add it as such. If not, set it to 0.0 and add it as global
                                    Expression exp = oldMp.getExpression();
                                    if (!exp.flatten().isNumeric()) {
                                        exp = new Expression(0.0);
                                        bNonNumeric = true;
                                    }
                                    ModelParameter newMp = pasteToModel.new ModelParameter(newMpName, exp, Model.ROLE_UserDefined, oldMp.getUnitDefinition());
                                    String annotation = "Copied from model : " + pasteFromModel.getNameScope();
                                    newMp.setModelParameterAnnotation(annotation);
                                    pasteToModel.addModelParameter(newMp);
                                    // if global param name had to be changed, make sure newExpr is updated as well.
                                    if (!newMpName.equals(oldMp.getName())) {
                                        newExpression.substituteInPlace(new Expression(oldMp.getName()), new Expression(newMpName));
                                    }
                                }
                            } else {
                                // no global param with same name was found in other model, so add it to other model.
                                // if expression if numeric, add it as such. If not, set it to 0.0 and add it as global
                                Expression exp = oldMp.getExpression();
                                if (!exp.flatten().isNumeric()) {
                                    exp = new Expression(0.0);
                                    bNonNumeric = true;
                                }
                                ModelParameter newMp = pasteToModel.new ModelParameter(newMpName, exp, Model.ROLE_UserDefined, oldMp.getUnitDefinition());
                                String annotation = "Copied from model : " + pasteFromModel.getNameScope();
                                newMp.setModelParameterAnnotation(annotation);
                                pasteToModel.addModelParameter(newMp);
                            }
                            // if a non-numeric parameter was encountered in the old model, it was added as a numeric (0.0), warn user of change.
                            if (bNonNumeric) {
                                Issue issue = new Issue(oldMp, issueContext, IssueCategory.CopyPaste, "Global parameter '" + oldMp.getName() + "' was non-numeric; it has been added " + "as global parameter '" + newMpName + "' in the new model with value = 0.0. " + "Please update its value, if required, before using it.", Issue.SEVERITY_WARNING);
                                issueVector.add(issue);
                            }
                        }
                    }
                }
            // end - if newExpr.hasSymbol(ProxyParam)
            }
            // now if store <param names, new expression> in hashTable
            if (paramExprHash.get(oldKps[i].getName()) == null) {
                paramExprHash.put(oldKps[i].getName(), newExpression);
            }
        }
        // end for - oldKps (old kinetic parameters)
        // use this new expression to generate 'vcml' for the (new) kinetics (easier way to transfer all kinetic parameters)
        String newKineticsStr = oldKinetics.writeTokensWithReplacingProxyParams(paramExprHash);
        // convert the kinetics 'vcml' to tokens.
        CommentStringTokenizer kineticsTokens = new CommentStringTokenizer(newKineticsStr);
        // skip the first token;
        kineticsTokens.nextToken();
        // second token is the kinetic type; use this to create a dummy kinetics
        String kineticType = kineticsTokens.nextToken();
        Kinetics newkinetics = KineticsDescription.fromVCMLKineticsName(kineticType).createKinetics(newReactionStep);
        // use the remaining tokens to construct the new kinetics
        newkinetics.fromTokens(newKineticsStr);
        // bind newkinetics to newReactionStep and add it to newReactionStep
        newkinetics.bind(newReactionStep);
        newReactionStep.setKinetics(newkinetics);
        counter += 1;
        if (counter == copyFromRxSteps.length) {
            break;
        }
        if (!copiedStructName.equals(fromRxnStruct.getName())) {
            if (currentStruct instanceof Feature) {
                currentStruct = structTopology.getMembrane((Feature) currentStruct);
            } else if (currentStruct instanceof Membrane) {
                currentStruct = structTopology.getInsideFeature((Membrane) currentStruct);
            }
        }
        copiedStructName = fromRxnStruct.getName();
    } while (true);
    return new PasteHelper(issueVector, rxPartMapStructure, reactionsAndSpeciesContexts);
}
Also used : Issue(org.vcell.util.Issue) IdentityHashMap(java.util.IdentityHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityHashMap(java.util.IdentityHashMap) Product(cbit.vcell.model.Product) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) Feature(cbit.vcell.model.Feature) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) Vector(java.util.Vector) SimpleReaction(cbit.vcell.model.SimpleReaction) KineticsProxyParameter(cbit.vcell.model.Kinetics.KineticsProxyParameter) StructureTopology(cbit.vcell.model.Model.StructureTopology) Hashtable(java.util.Hashtable) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject) StructureSize(cbit.vcell.model.Structure.StructureSize) PropertyVetoException(java.beans.PropertyVetoException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) UserCancelException(org.vcell.util.UserCancelException) ModelParameter(cbit.vcell.model.Model.ModelParameter) Expression(cbit.vcell.parser.Expression) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) ReactionStep(cbit.vcell.model.ReactionStep) Model(cbit.vcell.model.Model) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) Kinetics(cbit.vcell.model.Kinetics) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Catalyst(cbit.vcell.model.Catalyst)

Example 8 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class DistributedKinetics method toDistributedKinetics.

public static DistributedKinetics toDistributedKinetics(LumpedKinetics origLumpedKinetics) {
    KineticsParameter[] origLumpedKineticsParms = origLumpedKinetics.getKineticsParameters();
    ReactionStep reactionStep = origLumpedKinetics.getReactionStep();
    try {
        Vector<KineticsParameter> parmsToAdd = new Vector<KineticsParameter>();
        DistributedKinetics distributedKinetics = null;
        StructureSize structureSize = origLumpedKinetics.getReactionStep().getStructure().getStructureSize();
        Expression sizeExp = new Expression(structureSize.getName());
        VCUnitDefinition sizeUnit = structureSize.getUnitDefinition();
        if (origLumpedKinetics.getKineticsDescription().isElectrical()) {
            if (origLumpedKinetics.getReactionStep() instanceof FluxReaction) {
                distributedKinetics = new GeneralCurrentKinetics((FluxReaction) reactionStep);
            } else if (origLumpedKinetics.getReactionStep() instanceof SimpleReaction) {
                distributedKinetics = new GeneralCurrentKinetics((SimpleReaction) reactionStep);
            } else {
                throw new RuntimeException("DistributedKinetics.toDistributedKinetics(" + origLumpedKinetics.getReactionStep() + ") not supported");
            }
        } else {
            if (origLumpedKinetics.getReactionStep() instanceof FluxReaction) {
                distributedKinetics = new GeneralKinetics((FluxReaction) reactionStep);
            } else if (origLumpedKinetics.getReactionStep() instanceof SimpleReaction) {
                distributedKinetics = new GeneralKinetics((SimpleReaction) reactionStep);
            } else {
                throw new RuntimeException("DistributedKinetics.toDistributedKinetics(" + origLumpedKinetics.getReactionStep() + ") not supported");
            }
        }
        Expression unitFactor = new Expression(distributedKinetics.getAuthoritativeParameter().getUnitDefinition().multiplyBy(sizeUnit).divideBy(origLumpedKinetics.getAuthoritativeParameter().getUnitDefinition()).getDimensionlessScale());
        Expression distributionFactor = Expression.div(unitFactor, sizeExp);
        KineticsParameter lumpedAuthoritativeParm = origLumpedKinetics.getAuthoritativeParameter();
        KineticsParameter distAuthoritativeParam = distributedKinetics.getAuthoritativeParameter();
        Expression newDistributedAuthoritativeExp = Expression.mult(distributionFactor, lumpedAuthoritativeParm.getExpression()).flatten();
        Expression substitutedExp = newDistributedAuthoritativeExp.getSubstitutedExpression(sizeExp, new Expression(1.0));
        if (ExpressionUtils.functionallyEquivalent(newDistributedAuthoritativeExp, substitutedExp, false)) {
            newDistributedAuthoritativeExp = substitutedExp.flatten();
        }
        parmsToAdd.add(distributedKinetics.new KineticsParameter(distAuthoritativeParam.getName(), newDistributedAuthoritativeExp, distAuthoritativeParam.getRole(), distAuthoritativeParam.getUnitDefinition()));
        for (int i = 0; i < origLumpedKineticsParms.length; i++) {
            if (origLumpedKineticsParms[i].getRole() != Kinetics.ROLE_LumpedReactionRate && origLumpedKineticsParms[i].getRole() != Kinetics.ROLE_LumpedCurrent) {
                parmsToAdd.add(distributedKinetics.new KineticsParameter(origLumpedKineticsParms[i].getName(), new Expression(origLumpedKineticsParms[i].getExpression()), Kinetics.ROLE_UserDefined, origLumpedKineticsParms[i].getUnitDefinition()));
            }
        }
        distributedKinetics.addKineticsParameters(parmsToAdd.toArray(new KineticsParameter[parmsToAdd.size()]));
        return distributedKinetics;
    } catch (PropertyVetoException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to create distributed Kinetics for reaction: \"" + origLumpedKinetics.getReactionStep().getName() + "\": " + e.getMessage());
    } catch (ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to create distributed Kinetics for reaction: \"" + origLumpedKinetics.getReactionStep().getName() + "\": " + e.getMessage());
    }
}
Also used : StructureSize(cbit.vcell.model.Structure.StructureSize) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Vector(java.util.Vector)

Example 9 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class LumpedKinetics method toLumpedKinetics.

public static LumpedKinetics toLumpedKinetics(DistributedKinetics distributedKinetics) {
    KineticsParameter[] distKineticsParms = distributedKinetics.getKineticsParameters();
    ReactionStep reactionStep = distributedKinetics.getReactionStep();
    try {
        Vector<KineticsParameter> parmsToAdd = new Vector<KineticsParameter>();
        LumpedKinetics lumpedKinetics = null;
        StructureSize structureSize = distributedKinetics.getReactionStep().getStructure().getStructureSize();
        Expression sizeExp = new Expression(structureSize.getName());
        VCUnitDefinition sizeUnit = structureSize.getUnitDefinition();
        if (distributedKinetics.getKineticsDescription().isElectrical()) {
            if (reactionStep instanceof FluxReaction) {
                lumpedKinetics = new GeneralCurrentLumpedKinetics((FluxReaction) reactionStep);
            } else if (reactionStep instanceof SimpleReaction) {
                lumpedKinetics = new GeneralCurrentLumpedKinetics((SimpleReaction) reactionStep);
            } else {
                throw new RuntimeException("LumpedKinetics.toLumpedKinetics(" + reactionStep.getClass().getSimpleName() + ") not supported");
            }
        } else {
            if (reactionStep instanceof FluxReaction) {
                lumpedKinetics = new GeneralLumpedKinetics((FluxReaction) reactionStep);
            } else if (reactionStep instanceof SimpleReaction) {
                lumpedKinetics = new GeneralLumpedKinetics((SimpleReaction) reactionStep);
            } else {
                throw new RuntimeException("LumpedKinetics.toLumpedKinetics(" + reactionStep.getClass().getSimpleName() + ") not supported");
            }
        }
        Expression unitFactor = new Expression(lumpedKinetics.getAuthoritativeParameter().getUnitDefinition().divideBy(sizeUnit).divideBy(distributedKinetics.getAuthoritativeParameter().getUnitDefinition()).getDimensionlessScale());
        Expression lumpingFactor = Expression.mult(sizeExp, unitFactor);
        KineticsParameter distAuthoritativeParam = distributedKinetics.getAuthoritativeParameter();
        KineticsParameter lumpedAuthoritativeParam = lumpedKinetics.getAuthoritativeParameter();
        Expression newLumpedAuthoritativeExp = Expression.mult(lumpingFactor, distAuthoritativeParam.getExpression()).flatten();
        Expression substitutedExp = newLumpedAuthoritativeExp.getSubstitutedExpression(sizeExp, new Expression(1.0));
        if (ExpressionUtils.functionallyEquivalent(newLumpedAuthoritativeExp, substitutedExp, false)) {
            newLumpedAuthoritativeExp = substitutedExp.flatten();
        }
        parmsToAdd.add(lumpedKinetics.new KineticsParameter(lumpedAuthoritativeParam.getName(), newLumpedAuthoritativeExp, lumpedAuthoritativeParam.getRole(), lumpedAuthoritativeParam.getUnitDefinition()));
        for (int i = 0; i < distKineticsParms.length; i++) {
            if (distKineticsParms[i].getRole() != Kinetics.ROLE_ReactionRate && distKineticsParms[i].getRole() != Kinetics.ROLE_CurrentDensity) {
                parmsToAdd.add(lumpedKinetics.new KineticsParameter(distKineticsParms[i].getName(), new Expression(distKineticsParms[i].getExpression()), Kinetics.ROLE_UserDefined, distKineticsParms[i].getUnitDefinition()));
            }
        }
        lumpedKinetics.addKineticsParameters(parmsToAdd.toArray(new KineticsParameter[parmsToAdd.size()]));
        return lumpedKinetics;
    } catch (PropertyVetoException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to create lumped Kinetics for reaction: \"" + reactionStep.getName() + "\": " + e.getMessage());
    } catch (ExpressionException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to create lumped Kinetics for reaction: \"" + reactionStep.getName() + "\": " + e.getMessage());
    }
}
Also used : StructureSize(cbit.vcell.model.Structure.StructureSize) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Vector(java.util.Vector)

Example 10 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class Model method vetoableChange.

/**
 * This method was created in VisualAge.
 * @param e java.beans.PropertyChangeEvent
 * @exception java.beans.PropertyVetoException The exception description.
 */
public void vetoableChange(PropertyChangeEvent e) throws ModelPropertyVetoException {
    if (e.getSource() instanceof Structure) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            if (getStructure((String) e.getNewValue()) != null) {
                throw new ModelPropertyVetoException("another structure already using name " + e.getNewValue(), e);
            }
        }
    }
    if (e.getSource() instanceof ReactionStep) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            if (getReactionStep(newName) != null) {
                throw new ModelPropertyVetoException("another reaction step is already using name '" + newName + "'", e);
            }
        // validateNamingConflicts("Reaction",ReactionStep.class, newName, e);
        }
    }
    if (e.getSource() instanceof ReactionRule && e.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_NAME)) {
        if (!e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            if (getRbmModelContainer().getReactionRule(newName) != null) {
                throw new ModelPropertyVetoException("another reaction rule is already using name '" + newName + "'", e);
            }
            validateNamingConflicts("Rule", ReactionRule.class, newName, e);
        }
    }
    if (e.getSource() instanceof SpeciesContext) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            SpeciesContext sc = getSpeciesContext(newName);
            if (sc != null) {
                throw new ModelPropertyVetoException("another " + SpeciesContext.getTerm() + " defined in '" + sc.getStructure().getName() + "' already uses name '" + e.getNewValue() + "'", e);
            }
            validateNamingConflicts("SpeciesContext", SpeciesContext.class, newName, e);
        }
    }
    if (e.getSource() instanceof MembraneVoltage) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            SymbolTableEntry existingSTE = getLocalEntry(newName);
            if (existingSTE instanceof MembraneVoltage) {
                throw new ModelPropertyVetoException("new name \"" + newName + "\" conflicts with the voltage parameter name for membrane \"" + ((MembraneVoltage) existingSTE).getMembrane().getName() + "\"", e);
            }
            validateNamingConflicts("MembraneVoltage", MembraneVoltage.class, newName, e);
        }
    }
    if (e.getSource() instanceof StructureSize) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            SymbolTableEntry existingSTE = getLocalEntry(newName);
            if (existingSTE instanceof StructureSize) {
                throw new ModelPropertyVetoException("new name \"" + newName + "\" conflicts with the size parameter name for structure \"" + ((StructureSize) existingSTE).getStructure().getName() + "\"", e);
            }
            validateNamingConflicts("StructureSize", StructureSize.class, newName, e);
        }
    }
    if (e.getSource() instanceof ModelParameter) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            if (getModelParameter(newName) != null) {
                throw new ModelPropertyVetoException("Model Parameter with name '" + newName + "' already exists.", e);
            }
            validateNamingConflicts("Model Parameter", ModelParameter.class, newName, e);
        }
    }
    if (e.getSource() instanceof MolecularType) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            if (getRbmModelContainer().getMolecularType(newName) != null) {
                throw new ModelPropertyVetoException(MolecularType.typeName + " with name '" + newName + "' already exists.", e);
            }
            validateNamingConflicts(((MolecularType) e.getSource()).getDisplayType(), MolecularType.class, newName, e);
        }
    }
    if (e.getSource() instanceof RbmObservable) {
        if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
            String newName = (String) e.getNewValue();
            if (getRbmModelContainer().getObservable(newName) != null) {
                throw new ModelPropertyVetoException(((RbmObservable) e.getSource()).getDisplayType() + " with name '" + newName + "' already exists.", e);
            }
            validateNamingConflicts(((RbmObservable) e.getSource()).getDisplayType(), RbmObservable.class, newName, e);
        }
    }
    if (e.getSource() instanceof Species) {
        if (e.getPropertyName().equals("commonName") && !e.getOldValue().equals(e.getNewValue())) {
            String commonName = (String) e.getNewValue();
            if (commonName == null) {
                throw new ModelPropertyVetoException("species name cannot be null", e);
            }
            // 
            if (getSpecies(commonName) != null) {
                throw new ModelPropertyVetoException("Species with common name '" + commonName + "' already defined", e);
            }
            if (getReservedSymbolByName(commonName) != null) {
                throw new ModelPropertyVetoException("cannot use reserved symbol '" + commonName + "' as a Species common name", e, ModelPropertyVetoException.Category.RESERVED_SYMBOL);
            }
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST)) {
        ArrayList<MolecularType> newMolecularTypes = (ArrayList<MolecularType>) e.getNewValue();
        if (newMolecularTypes == null) {
            throw new ModelPropertyVetoException(MolecularType.typeName + " list cannot be null", e);
        }
        for (MolecularType mt : getRbmModelContainer().getMolecularTypeList()) {
            validateNamingConflicts(MolecularType.typeName, MolecularType.class, mt.getName(), e);
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST)) {
        ArrayList<RbmObservable> newObservables = (ArrayList<RbmObservable>) e.getNewValue();
        if (newObservables == null) {
            throw new ModelPropertyVetoException(RbmObservable.typeName + " list cannot be null", e);
        }
        for (RbmObservable observable : getRbmModelContainer().getObservableList()) {
            validateNamingConflicts(RbmObservable.typeName, RbmObservable.class, observable.getName(), e);
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST)) {
        ArrayList<ReactionRule> newReactionRules = (ArrayList<ReactionRule>) e.getNewValue();
        if (newReactionRules == null) {
            throw new ModelPropertyVetoException(ReactionRule.typeName + " list cannot be null", e);
        }
        for (ReactionRule rr : getRbmModelContainer().getReactionRuleList()) {
            validateNamingConflicts(ReactionRule.typeName, ReactionRule.class, rr.getName(), e);
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_STRUCTURES)) {
        Structure[] newStructures = (Structure[]) e.getNewValue();
        if (newStructures == null) {
            throw new ModelPropertyVetoException("structures cannot be null", e);
        }
        // 
        // look for duplicates of structure name, structure size name, membrane voltage name within new "structures" array
        // and look for symbol conflicts for StructureSize name and for MembraneVoltage name in existing "local" symbols.
        // 
        HashSet<String> structNameSet = new HashSet<String>();
        HashSet<String> structSymbolSet = new HashSet<String>();
        for (int i = 0; i < newStructures.length; i++) {
            String newStructureName = newStructures[i].getName();
            if (structNameSet.contains(newStructureName)) {
                throw new ModelPropertyVetoException("multiple structures with name '" + newStructureName + "' defined", e);
            }
            structNameSet.add(newStructureName);
            if (newStructures[i] instanceof Membrane) {
                String newMembraneVoltageName = ((Membrane) newStructures[i]).getMembraneVoltage().getName();
                if (structSymbolSet.contains(newMembraneVoltageName)) {
                // throw new ModelPropertyVetoException("membrane '"+newStructureName+"' has Voltage name '"+newMembraneVoltageName+"' that conflicts with another Voltage name or Size name",e);
                }
                structSymbolSet.add(newMembraneVoltageName);
                validateNamingConflicts("MembraneVoltage", MembraneVoltage.class, newMembraneVoltageName, e);
            }
            String newStructureSizeName = newStructures[i].getStructureSize().getName();
            if (structSymbolSet.contains(newStructureSizeName)) {
                throw new ModelPropertyVetoException("structure '" + newStructureName + "' has structure Size name '" + newStructureSizeName + "' that conflicts with another Voltage name or Size name", e);
            }
            structSymbolSet.add(newStructureSizeName);
            validateNamingConflicts("StructureSize", StructureSize.class, newStructureSizeName, e);
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_SPECIES)) {
        Species[] newSpeciesArray = (Species[]) e.getNewValue();
        if (newSpeciesArray == null) {
            throw new ModelPropertyVetoException("species cannot be null", e);
        }
        // 
        // check that names are not duplicated and that no common names are ReservedSymbols
        // 
        HashSet<String> commonNameSet = new HashSet<String>();
        for (int i = 0; i < newSpeciesArray.length; i++) {
            String commonName = newSpeciesArray[i].getCommonName();
            if (commonNameSet.contains(commonName)) {
                throw new ModelPropertyVetoException("multiple species with common name '" + commonName + "' defined", e);
            }
            if (getReservedSymbolByName(commonName) != null) {
                throw new ModelPropertyVetoException("cannot use reserved symbol '" + commonName + "' as a Species common name", e, ModelPropertyVetoException.Category.RESERVED_SYMBOL);
            }
            commonNameSet.add(commonName);
        }
        // 
        for (int j = 0; j < fieldSpeciesContexts.length; j++) {
            SpeciesContext sc = fieldSpeciesContexts[j];
            boolean bFound = false;
            for (int i = 0; i < newSpeciesArray.length; i++) {
                if (newSpeciesArray[i] == sc.getSpecies()) {
                    bFound = true;
                }
            }
            if (!bFound) {
                throw new ModelPropertyVetoException("species[] missing '" + sc.getSpecies().getCommonName() + "' referenced in SpeciesContext '" + sc.getName() + "'", e);
            }
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(Model.PROPERTY_NAME_MODEL_PARAMETERS)) {
        ModelParameter[] newModelParams = (ModelParameter[]) e.getNewValue();
        // 
        // check that names are not duplicated and that no common names are ReservedSymbols
        // 
        HashSet<String> namesSet = new HashSet<String>();
        for (int i = 0; i < newModelParams.length; i++) {
            if (namesSet.contains(newModelParams[i].getName())) {
                throw new ModelPropertyVetoException("Multiple model/global parameters with same name '" + newModelParams[i].getName() + "' defined", e);
            }
            namesSet.add(newModelParams[i].getName());
            validateNamingConflicts("Model Parameter", ModelParameter.class, newModelParams[i].getName(), e);
        }
        // 
        // make sure that kinetics of reactionSteps do not refer to modelParameter to be deleted
        // Find this model parameter, missing from 'newModelParams'; loop thro' all reactionStep kinetics to determine if it is used
        // 
        ModelParameter[] oldModelParameters = (ModelParameter[]) e.getOldValue();
        if (oldModelParameters.length > newModelParams.length) {
            // if 'newModelParameter' is smaller than 'oldModelParameter', one of the modelParams has been removed, find the missing one
            ModelParameter missingMP = null;
            for (int i = 0; i < oldModelParameters.length; i++) {
                if (!BeanUtils.arrayContains(newModelParams, oldModelParameters[i])) {
                    missingMP = oldModelParameters[i];
                }
            }
            // use this missing model parameter (to be deleted) to determine if it is used in any reaction kinetic parameters.
            if (missingMP != null) {
                Vector<String> referencingRxnsVector = new Vector<String>();
                for (int i = 0; i < fieldReactionSteps.length; i++) {
                    KineticsParameter[] kParams = fieldReactionSteps[i].getKinetics().getKineticsParameters();
                    for (int k = 0; k < kParams.length; k++) {
                        if (kParams[k].getExpression().hasSymbol(missingMP.getName()) && (fieldReactionSteps[i].getKinetics().getProxyParameter(missingMP.getName()) != null)) {
                            referencingRxnsVector.add(fieldReactionSteps[i].getName());
                            break;
                        }
                    }
                }
                // if there are any reactionSteps referencing the global, list them all in error msg.
                if (referencingRxnsVector.size() > 0) {
                    String msg = "Model Parameter '" + missingMP.getName() + "' is used in reaction(s): ";
                    for (int i = 0; i < referencingRxnsVector.size(); i++) {
                        msg = msg + "'" + referencingRxnsVector.elementAt(i) + "'";
                        if (i < referencingRxnsVector.size() - 1) {
                            msg = msg + ", ";
                        } else {
                            msg = msg + ". ";
                        }
                    }
                    msg = msg + "\n\nCannot delete '" + missingMP.getName() + "'.";
                    throw new ModelPropertyVetoException(msg, e);
                }
                // At this point, it is not referenced in a reactionStep, find out if the missing model is used in other model parameters
                // Enough to check in newModelParams array
                Vector<String> referencingModelParamsVector = new Vector<String>();
                for (int i = 0; i < newModelParams.length; i++) {
                    if (newModelParams[i].getExpression().hasSymbol(missingMP.getName())) {
                        referencingModelParamsVector.add(newModelParams[i].getName());
                    }
                }
                // if there are any model parameters referencing the global, list them all in error msg.
                if (referencingModelParamsVector.size() > 0) {
                    String msg = "Model Parameter '" + missingMP.getName() + "' is used in expression of other model parameter(s): ";
                    for (int i = 0; i < referencingModelParamsVector.size(); i++) {
                        msg = msg + "'" + referencingModelParamsVector.elementAt(i) + "'";
                        if (i < referencingModelParamsVector.size() - 1) {
                            msg = msg + ", ";
                        } else {
                            msg = msg + ". ";
                        }
                    }
                    msg = msg + "\n\nCannot delete '" + missingMP.getName() + "'.";
                    throw new ModelPropertyVetoException(msg, e);
                }
            }
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_SPECIES_CONTEXTS)) {
        SpeciesContext[] newSpeciesContextArray = (SpeciesContext[]) e.getNewValue();
        if (newSpeciesContextArray == null) {
            throw new ModelPropertyVetoException("speciesContexts cannot be null", e);
        }
        // 
        for (int i = 0; i < newSpeciesContextArray.length; i++) {
            if (!contains(newSpeciesContextArray[i].getSpecies())) {
                throw new ModelPropertyVetoException("can't add speciesContext '" + newSpeciesContextArray[i].getName() + "' before species '" + newSpeciesContextArray[i].getSpecies().getCommonName() + "'", e);
            }
            if (!contains(newSpeciesContextArray[i].getStructure())) {
                throw new ModelPropertyVetoException("can't add speciesContext '" + newSpeciesContextArray[i].getName() + "' before structure '" + newSpeciesContextArray[i].getStructure().getName() + "'", e);
            }
        }
        // 
        // check that names are not duplicated and that no names are ReservedSymbols
        // 
        HashSet<String> nameSet = new HashSet<String>();
        for (int i = 0; i < newSpeciesContextArray.length; i++) {
            if (nameSet.contains(newSpeciesContextArray[i].getName())) {
                throw new ModelPropertyVetoException("multiple speciesContexts with name '" + newSpeciesContextArray[i].getName() + "' defined", e);
            }
            nameSet.add(newSpeciesContextArray[i].getName());
            validateNamingConflicts("SpeciesContext", newSpeciesContextArray[i].getClass(), newSpeciesContextArray[i].getName(), e);
        }
        // 
        for (int i = 0; i < fieldReactionSteps.length; i++) {
            ReactionParticipant[] rpArray = fieldReactionSteps[i].getReactionParticipants();
            for (int k = 0; k < rpArray.length; k++) {
                boolean bFound = false;
                for (int j = 0; j < newSpeciesContextArray.length; j++) {
                    if (newSpeciesContextArray[j] == rpArray[k].getSpeciesContext()) {
                        bFound = true;
                        break;
                    }
                }
                if (!bFound) {
                    throw new ModelPropertyVetoException("reaction '" + fieldReactionSteps[i].getName() + "' requires '" + rpArray[k].getSpeciesContext().getName() + "'", e);
                }
            }
        }
    }
    if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_REACTION_STEPS)) {
        ReactionStep[] newReactionStepArr = (ReactionStep[]) e.getNewValue();
        // 
        for (int i = 0; i < newReactionStepArr.length; i += 1) {
            if (newReactionStepArr[i] == null) {
                throw new ModelPropertyVetoException("Null cannot be added to ReactionStep", e);
            }
        }
        // 
        // check that names are not duplicated and that no names are ReservedSymbols
        // because math generator complained if reactionsteps had same name
        // 
        HashSet<String> nameSet = new HashSet<String>();
        for (int i = 0; i < newReactionStepArr.length; i++) {
            String rxnName = newReactionStepArr[i].getName();
            if (nameSet.contains(rxnName)) {
                throw new ModelPropertyVetoException("multiple reactionSteps with name '" + rxnName + "' defined", e);
            }
            if (getReservedSymbolByName(rxnName) != null) {
                throw new ModelPropertyVetoException("cannot use reserved symbol '" + rxnName + "' as a Reaction name", e, ModelPropertyVetoException.Category.RESERVED_SYMBOL);
            }
            nameSet.add(rxnName);
        // validateNamingConflicts("Reaction", ReactionStep.class, newReactionStepArr[i].getName(), e);
        }
        // 
        for (int i = 0; i < newReactionStepArr.length; i++) {
            ReactionParticipant[] rpArray = newReactionStepArr[i].getReactionParticipants();
            for (int k = 0; k < rpArray.length; k++) {
                boolean bFound = false;
                for (int j = 0; j < fieldSpeciesContexts.length; j++) {
                    if (fieldSpeciesContexts[j] == rpArray[k].getSpeciesContext()) {
                        bFound = true;
                        break;
                    }
                }
                if (!bFound) {
                    throw new ModelPropertyVetoException("reaction '" + newReactionStepArr[i].getName() + "' requires '" + rpArray[k].getSpeciesContext().getName() + "'", e);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) Vector(java.util.Vector) HashSet(java.util.HashSet) StructureSize(cbit.vcell.model.Structure.StructureSize) MolecularType(org.vcell.model.rbm.MolecularType) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage)

Aggregations

StructureSize (cbit.vcell.model.Structure.StructureSize)13 MembraneVoltage (cbit.vcell.model.Membrane.MembraneVoltage)8 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)7 Expression (cbit.vcell.parser.Expression)6 SpeciesContext (cbit.vcell.model.SpeciesContext)5 Structure (cbit.vcell.model.Structure)5 PropertyVetoException (java.beans.PropertyVetoException)5 Vector (java.util.Vector)5 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)4 ModelParameter (cbit.vcell.model.Model.ModelParameter)4 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)3 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)3 Feature (cbit.vcell.model.Feature)3 Membrane (cbit.vcell.model.Membrane)3 StructureTopology (cbit.vcell.model.Model.StructureTopology)3 GeometryClass (cbit.vcell.geometry.GeometryClass)2 SubVolume (cbit.vcell.geometry.SubVolume)2 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 Model (cbit.vcell.model.Model)2 ReactionStep (cbit.vcell.model.ReactionStep)2