use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class DBReactionWizardPanel method parameterNameSelectionChanged.
/**
* Comment
*/
private void parameterNameSelectionChanged() {
try {
javax.swing.DefaultListModel dlm = (javax.swing.DefaultListModel) getParameterValuesJList().getModel();
dlm.removeAllElements();
//
if (getParameterNamesJList().getSelectedValue() != null) {
// final cbit.vcell.clientdb.DocumentManager docManager = getDocumentManager();
// final javax.swing.JList jlist = getReactionsJList();
final MapStringToObject parameNameMSO = (MapStringToObject) getParameterNamesJList().getSelectedValue();
final KeyValue reactionStepKey = ((ReactionStepInfo) parameNameMSO.getToObject()).getReactionKey();
//
final String RXSTEP_HASH_VALUE_KEY = "rxStep";
AsynchClientTask searchReactions = new AsynchClientTask("Getting Full Reaction", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hash) throws Exception {
Model reactionModel = getDocumentManager().getReactionStepAsModel(reactionStepKey);
ReactionStep rStep = reactionModel.getReactionStep(((ReactionStepInfo) parameNameMSO.getToObject()).getReactionName());
if (rStep != null) {
rStep.rebindAllToModel(reactionModel);
hash.put(RXSTEP_HASH_VALUE_KEY, rStep);
}
}
};
//
AsynchClientTask updateRXParams = new AsynchClientTask("updateRXParams", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hash) throws DataAccessException {
ReactionStep rStep = (ReactionStep) hash.get(RXSTEP_HASH_VALUE_KEY);
if (rStep != null) {
Kinetics.KineticsParameter[] kpArr = rStep.getKinetics().getKineticsParameters();
ReactionParticipant[] rpArr = rStep.getReactionParticipants();
//
javax.swing.DefaultListModel pvdlm = (javax.swing.DefaultListModel) getParameterValuesJList().getModel();
pvdlm.removeAllElements();
for (int i = 0; i < kpArr.length; i += 1) {
pvdlm.addElement("Parameter - " + kpArr[i].getName().toString() + " = " + kpArr[i].getExpression().infix());
}
pvdlm.addElement("PhysicsOption=" + rStep.getPhysicsOptions());
for (int i = 0; i < rpArr.length; i += 1) {
String role = "Unknown";
if (rpArr[i] instanceof Reactant) {
role = "Reactant";
} else if (rpArr[i] instanceof Product) {
role = "Product";
} else if (rpArr[i] instanceof Catalyst) {
role = "Catalyst";
}
String fluxFlag = "";
// if(rStep instanceof FluxReaction){
// Membrane rStepStruct = (Membrane)rStep.getStructure();
// if(rpArr[i] instanceof Flux){
// if(rpArr[i].getStructure().equals(getModel().getStructureTopology().getOutsideFeature(rStepStruct))){
// fluxFlag = "Outside";
// }else{
// fluxFlag = "Inside";
// }
// }
// }
pvdlm.addElement("RXParticipant(" + role + ") " + fluxFlag + " " + (rpArr[i].getSpecies().getDBSpecies() != null ? "*" : "-") + " " + rpArr[i].getSpeciesContext().getName());
}
}
setReactionStep(rStep);
configureBFN();
}
};
//
Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(this, hashTemp, new AsynchClientTask[] { searchReactions, updateRXParams }, true);
} else {
setReactionStep(null);
}
} catch (Exception e) {
PopupGenerator.showErrorDialog(this, e.getMessage(), e);
}
//
configureBFN();
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class SimulationContext method checkValidity.
public void checkValidity() throws MappingException {
// spatial
if (getGeometry().getDimension() > 0) {
//
// fail if any enabled Reactions have LumpedKinetics.
//
// StringBuffer buffer = new StringBuffer();
// ReactionSpec[] reactionSpecs = getReactionContext().getReactionSpecs();
// for (int i = 0; i < reactionSpecs.length; i++) {
// if (!reactionSpecs[i].isExcluded() && reactionSpecs[i].getReactionStep().getKinetics() instanceof LumpedKinetics){
// buffer.append("reaction \""+reactionSpecs[i].getReactionStep().getName()+"\" in compartment \""+reactionSpecs[i].getReactionStep().getStructure().getName()+"\"\n");
// }
// }
// if (buffer.length()>0){
// throw new MappingException("Spatial application \""+getName()+"\" cannot process reactions with spatially lumped kinetics, see kinetics for :\n"+buffer.toString());
//
// }
} else {
// old-style ODE models should still work
if (applicationType == Application.NETWORK_DETERMINISTIC && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().isAllSizeSpecifiedNull()) {
// old style ODE models
return;
}
// otherwise, all sizes should be present and positive.
if (!getGeometryContext().isAllSizeSpecifiedPositive()) {
throw new MappingException("Application " + getName() + ":\nAll structure sizes must be assigned positive values.\nPlease go to StructureMapping tab to check the sizes.");
}
// if rate rules are present, if any species has a rate rules, it should not be a reaction participant in any reaction.
RateRule[] rateRules = getRateRules();
if (rateRules != null && rateRules.length > 0) {
if (getModel() != null) {
ReactionStep[] reactionSteps = getModel().getReactionSteps();
ReactionParticipant[] reactionParticipants = null;
for (ReactionStep rs : reactionSteps) {
reactionParticipants = rs.getReactionParticipants();
for (ReactionParticipant rp : reactionParticipants) {
if (rp instanceof Reactant || rp instanceof Product) {
if (getRateRule(rp.getSpeciesContext()) != null) {
throw new RuntimeException("Species '" + rp.getSpeciesContext().getName() + "' is a reactant/product in reaction '" + rs.getName() + "' ; cannot also have a rate rule.");
}
}
}
}
}
}
}
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class SpeciesContextSpec method gatherIssues.
/**
* Insert the method's description here.
* Creation date: (11/1/2005 10:03:46 AM)
* @param issueVector java.util.Vector
*/
public void gatherIssues(IssueContext issueContext, List<Issue> issueVector) {
issueContext = issueContext.newChildContext(ContextType.SpeciesContextSpec, this);
//
for (int i = 0; i < fieldParameters.length; i++) {
RealInterval simpleBounds = parameterBounds[fieldParameters[i].getRole()];
if (simpleBounds != null) {
String parmName = fieldParameters[i].getNameScope().getName() + "." + fieldParameters[i].getName();
issueVector.add(new SimpleBoundsIssue(fieldParameters[i], issueContext, simpleBounds, "parameter " + parmName + ": must be within " + simpleBounds.toString()));
}
}
if (bForceContinuous && !bConstant && getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() > 0)) {
// if it's particle or constant we're good
SpeciesContext sc = getSpeciesContext();
ReactionContext rc = getSimulationContext().getReactionContext();
ReactionSpec[] rsArray = rc.getReactionSpecs();
for (ReactionSpec rs : rsArray) {
if (!rs.isExcluded()) {
// we only care about reactions which are not excluded
// true if "this" is part of current reaction
boolean iAmParticipant = false;
// true if current reaction has at least a particle participant
boolean haveParticle = false;
ReactionStep step = rs.getReactionStep();
for (ReactionParticipant p : step.getReactionParticipants()) {
if (p instanceof Product || p instanceof Reactant) {
SpeciesContextSpec candidate = rc.getSpeciesContextSpec(p.getSpeciesContext());
if (candidate == this) {
iAmParticipant = true;
} else if (!candidate.isForceContinuous() && !candidate.isConstant()) {
haveParticle = true;
}
}
}
if (iAmParticipant && haveParticle) {
String msg = "Continuous Species won't conserve mass in particle reaction " + rs.getReactionStep().getName() + ".";
String tip = "Mass conservation for reactions of binding between discrete and continuous species is handled approximately. <br>" + "To avoid any algorithmic approximation, which may produce undesired results, the user is advised to indicate <br>" + "the continuous species in those reactions as modifiers (i.e. 'catalysts') in the physiology.";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.SEVERITY_WARNING));
// we issue warning as soon as we found the first reaction which satisfies criteria
break;
}
}
}
}
if (!bForceContinuous && bConstant) {
if (getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() > 0)) {
String msg = "Clamped Species must be continuous rather than particles.";
String tip = "If choose 'clamped', must also choose 'forceContinuous'";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, tip, Issue.SEVERITY_ERROR));
}
}
if (bForceContinuous && !bConstant) {
if (getSimulationContext().isStoch() && (getSimulationContext().getGeometry().getDimension() == 0)) {
String msg = "Non-constant species is forced continuous, not supported for nonspatial stochastic applications.";
issueVector.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
}
}
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class StochMathMapping method getProbabilityRate.
/**
* Get probability expression for the specific elementary reaction.
* Input: ReactionStep, the reaction. isForwardDirection, if the elementary reaction is forward from the reactionstep.
* Output: Expression. the probability expression.
* Creation date: (9/14/2006 3:22:58 PM)
* @throws ExpressionException
*/
private Expression getProbabilityRate(ReactionStep reactionStep, Expression rateConstantExpr, boolean isForwardDirection) throws MappingException, ExpressionException, ModelException {
// the structure where reaction happens
StructureMapping sm = getSimulationContext().getGeometryContext().getStructureMapping(reactionStep.getStructure());
Model model = getSimulationContext().getModel();
Expression reactionStructureSize = new Expression(sm.getStructure().getStructureSize(), getNameScope());
VCUnitDefinition reactionSubstanceUnit = model.getUnitSystem().getSubstanceUnit(reactionStep.getStructure());
VCUnitDefinition stochasticSubstanceUnit = model.getUnitSystem().getStochasticSubstanceUnit();
Expression reactionSubstanceUnitFactor = getUnitFactor(stochasticSubstanceUnit.divideBy(reactionSubstanceUnit));
Expression factorExpr = Expression.mult(reactionStructureSize, reactionSubstanceUnitFactor);
// Using the MassActionFunction to write out the math description
MassActionSolver.MassActionFunction maFunc = null;
Kinetics kinetics = reactionStep.getKinetics();
if (kinetics.getKineticsDescription().equals(KineticsDescription.MassAction) || kinetics.getKineticsDescription().equals(KineticsDescription.General) || kinetics.getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
Expression rateExp = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getExpression();
Parameter forwardRateParameter = null;
Parameter reverseRateParameter = null;
if (kinetics.getKineticsDescription().equals(KineticsDescription.MassAction)) {
forwardRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_KForward);
reverseRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_KReverse);
} else if (kinetics.getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
forwardRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
reverseRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
}
maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, reactionStep);
if (maFunc.getForwardRate() == null && maFunc.getReverseRate() == null) {
throw new MappingException("Cannot generate stochastic math mapping for the reaction:" + reactionStep.getName() + "\nLooking for the rate function according to the form of k1*Reactant1^Stoir1*Reactant2^Stoir2...-k2*Product1^Stoip1*Product2^Stoip2.");
}
} else {
throw new MappingException("Cannot generate stochastic math mapping for the reaction:" + reactionStep.getName() + "\n. Unsupported kinetic type " + kinetics.getKineticsDescription().getName());
}
List<ReactionParticipant> reacPart;
if (isForwardDirection) {
reacPart = maFunc.getReactants();
System.out.println("forward reaction rate (coefficient?) is " + maFunc.getForwardRate().infix());
} else {
reacPart = maFunc.getProducts();
System.out.println("reverse reaction rate (coefficient?) is " + maFunc.getReverseRate().infix());
}
Expression rxnProbabilityExpr = null;
for (int i = 0; i < reacPart.size(); i++) {
VCUnitDefinition speciesSubstanceUnit = model.getUnitSystem().getSubstanceUnit(reacPart.get(i).getStructure());
Expression speciesUnitFactor = getUnitFactor(speciesSubstanceUnit.divideBy(stochasticSubstanceUnit));
int stoichiometry = 0;
stoichiometry = reacPart.get(i).getStoichiometry();
// ******the following part is to form the s*(s-1)(s-2)..(s-stoi+1).portion of the probability rate.
Expression speciesStructureSize = new Expression(reacPart.get(i).getStructure().getStructureSize(), getNameScope());
Expression speciesFactor = Expression.div(speciesUnitFactor, speciesStructureSize);
// s*(s-1)(s-2)..(s-stoi+1)
SpeciesCountParameter spCountParam = getSpeciesCountParameter(reacPart.get(i).getSpeciesContext());
Expression spCount_exp = new Expression(spCountParam, getNameScope());
// species from uM to No. of Particles, form s*(s-1)*(s-2)
Expression speciesFactorial = new Expression(spCount_exp);
for (int j = 1; j < stoichiometry; j++) {
speciesFactorial = Expression.mult(speciesFactorial, Expression.add(spCount_exp, new Expression(-j)));
}
// update total factor with speceies factor
if (stoichiometry == 1) {
factorExpr = Expression.mult(factorExpr, speciesFactor);
} else if (stoichiometry > 1) {
// rxnProbExpr * (structSize^stoichiometry)
factorExpr = Expression.mult(factorExpr, Expression.power(speciesFactor, new Expression(stoichiometry)));
}
if (rxnProbabilityExpr == null) {
rxnProbabilityExpr = new Expression(speciesFactorial);
} else {
// for more than one reactant
rxnProbabilityExpr = Expression.mult(rxnProbabilityExpr, speciesFactorial);
}
}
// Now construct the probability expression.
Expression probExp = null;
if (rateConstantExpr == null) {
throw new MappingException("Can not find reaction rate constant in reaction: " + reactionStep.getName());
} else if (rxnProbabilityExpr == null) {
probExp = new Expression(rateConstantExpr);
} else if ((rateConstantExpr != null) && (rxnProbabilityExpr != null)) {
probExp = Expression.mult(rateConstantExpr, rxnProbabilityExpr);
}
// simplify the factor
RationalExp factorRatExp = RationalExpUtils.getRationalExp(factorExpr);
factorExpr = new Expression(factorRatExp.infixString());
factorExpr.bindExpression(this);
// get probability rate with converting factor
probExp = Expression.mult(probExp, factorExpr);
probExp = probExp.flatten();
return probExp;
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class MembraneStructureAnalyzer method refreshResolvedFluxes.
/**
* This method was created in VisualAge.
*/
void refreshResolvedFluxes() throws Exception {
// System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes()");
GeometryContext geoContext = mathMapping_4_8.getSimulationContext().getGeometryContext();
StructureTopology structTopology = mathMapping_4_8.getSimulationContext().getModel().getStructureTopology();
Vector<ResolvedFlux> resolvedFluxList = new Vector<ResolvedFlux>();
//
// for each reaction, get all fluxReactions associated with this membrane
//
Vector<ReactionStep> fluxList = new Vector<ReactionStep>();
ReactionSpec[] reactionSpecs = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpecs();
for (int j = 0; j < reactionSpecs.length; j++) {
if (reactionSpecs[j].isExcluded()) {
continue;
}
ReactionStep rs = reactionSpecs[j].getReactionStep();
if (rs.getStructure() == getMembrane()) {
if (rs instanceof FluxReaction) {
fluxList.addElement(rs);
}
}
}
//
for (int i = 0; i < fluxList.size(); i++) {
FluxReaction fr = (FluxReaction) fluxList.elementAt(i);
Species fluxCarrier = null;
for (ReactionParticipant rp : fr.getReactionParticipants()) {
if (rp instanceof Reactant || rp instanceof Product) {
if (fluxCarrier == null) {
fluxCarrier = rp.getSpecies();
} else {
if (fluxCarrier != rp.getSpecies()) {
throw new Exception("Flux reaction '" + fr.getName() + "' with multiple species not allowed in VCell 4.8.");
}
}
}
}
if (fluxCarrier == null) {
continue;
}
ResolvedFlux rf = null;
for (int j = 0; j < resolvedFluxList.size(); j++) {
ResolvedFlux rf_tmp = (ResolvedFlux) resolvedFluxList.elementAt(j);
if (rf_tmp.getSpecies() == fluxCarrier) {
rf = rf_tmp;
}
}
//
// if "inside" speciesContext is not "fixed", add flux to ResolvedFlux
//
SpeciesContext insideSpeciesContext = mathMapping_4_8.getSimulationContext().getModel().getSpeciesContext(fluxCarrier, structTopology.getInsideFeature(getMembrane()));
SpeciesContextSpec insideSpeciesContextSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(insideSpeciesContext);
// if (!insideSpeciesContextSpec.isConstant()){
if (bNoFluxIfFixed || !insideSpeciesContextSpec.isConstant()) {
if (bNoFluxIfFixed && insideSpeciesContextSpec.isConstant()) {
bNoFluxIfFixedExercised = true;
}
if (rf == null) {
rf = new ResolvedFlux(fluxCarrier, fr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
resolvedFluxList.addElement(rf);
}
FeatureMapping insideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping((structTopology.getInsideFeature((Membrane) fr.getStructure())));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(insideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression insideFluxCorrection = Expression.invert(residualVolumeFraction);
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
insideFluxCorrection = new Expression(1.0);
}
//
if (fr.getKinetics() instanceof DistributedKinetics) {
Expression reactionRateParameter = new Expression(((DistributedKinetics) fr.getKinetics()).getReactionRateParameter(), mathMapping_4_8.getNameScope());
if (rf.inFluxExpression.isZero()) {
rf.inFluxExpression = Expression.mult(reactionRateParameter, insideFluxCorrection).flatten();
} else {
rf.inFluxExpression = Expression.add(rf.inFluxExpression, Expression.mult(reactionRateParameter, insideFluxCorrection).flatten());
}
} else if (fr.getKinetics() instanceof LumpedKinetics) {
throw new RuntimeException("Lumped Kinetics for fluxes not yet supported");
} else {
throw new RuntimeException("unexpected Kinetic type in MembraneStructureAnalyzer.refreshResolvedFluxes()");
}
// rf.inFlux.bindExpression(mathMapping);
}
SpeciesContext outsideSpeciesContext = mathMapping_4_8.getSimulationContext().getModel().getSpeciesContext(fluxCarrier, structTopology.getOutsideFeature(getMembrane()));
SpeciesContextSpec outsideSpeciesContextSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(outsideSpeciesContext);
// if (!outsideSpeciesContextSpec.isConstant()){
if (bNoFluxIfFixed || !outsideSpeciesContextSpec.isConstant()) {
if (bNoFluxIfFixed && outsideSpeciesContextSpec.isConstant()) {
bNoFluxIfFixedExercised = true;
}
if (rf == null) {
rf = new ResolvedFlux(fluxCarrier, fr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
resolvedFluxList.addElement(rf);
}
FeatureMapping outsideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getOutsideFeature((Membrane) fr.getStructure()));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(outsideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression outsideFluxCorrection = Expression.invert(residualVolumeFraction);
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
outsideFluxCorrection = new Expression(1.0);
}
//
if (fr.getKinetics() instanceof DistributedKinetics) {
Expression reactionRateParameter = new Expression(((DistributedKinetics) fr.getKinetics()).getReactionRateParameter(), mathMapping_4_8.getNameScope());
if (rf.outFluxExpression.isZero()) {
rf.outFluxExpression = Expression.mult(Expression.negate(reactionRateParameter), outsideFluxCorrection).flatten();
} else {
rf.outFluxExpression = Expression.add(rf.outFluxExpression, Expression.mult(Expression.negate(reactionRateParameter), outsideFluxCorrection).flatten());
}
} else if (fr.getKinetics() instanceof LumpedKinetics) {
throw new RuntimeException("Lumped Kinetics not yet supported for Flux Reaction: " + fr.getName());
} else {
throw new RuntimeException("unexpected Kinetics type for Flux Reaction " + fr.getName());
}
// rf.outFlux.bindExpression(mathMapping);
}
}
//
// for each reaction, incorporate all reactionSteps involving binding with volumetric species
//
double kMoleValue = 1 / 602.0;
for (int i = 0; i < reactionSpecs.length; i++) {
if (reactionSpecs[i].isExcluded()) {
continue;
}
ReactionStep rs = reactionSpecs[i].getReactionStep();
if (rs.getStructure() == getMembrane()) {
if (rs instanceof SimpleReaction) {
SimpleReaction sr = (SimpleReaction) rs;
ReactionParticipant[] rp_Array = sr.getReactionParticipants();
for (int k = 0; k < rp_Array.length; k++) {
if (rp_Array[k] instanceof Reactant || rp_Array[k] instanceof Product) {
SpeciesContextSpec scs = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(rp_Array[k].getSpeciesContext());
// if (rp_Array[k].getStructure() instanceof Feature && !scs.isConstant()){
if (rp_Array[k].getStructure() instanceof Feature && (bNoFluxIfFixed || !scs.isConstant())) {
if (bNoFluxIfFixed && scs.isConstant()) {
bNoFluxIfFixedExercised = true;
}
//
// for each Reactant or Product binding to this membrane...
//
//
// get ResolvedFlux for this species
//
ResolvedFlux rf = null;
for (int j = 0; j < resolvedFluxList.size(); j++) {
ResolvedFlux rf_tmp = (ResolvedFlux) resolvedFluxList.elementAt(j);
if (rf_tmp.getSpecies() == rp_Array[k].getSpecies()) {
rf = rf_tmp;
}
}
if (rf == null) {
rf = new ResolvedFlux(rp_Array[k].getSpecies(), sr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
resolvedFluxList.addElement(rf);
}
Expression reactionRateExpression = getReactionRateExpression(sr, rp_Array[k]).renameBoundSymbols(mathMapping_4_8.getNameScope());
if (rp_Array[k].getStructure() == structTopology.getInsideFeature(getMembrane())) {
//
// for binding on inside, add to ResolvedFlux.inFlux
//
FeatureMapping insideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getInsideFeature(getMembrane()));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(insideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression insideFluxCorrection = Expression.div(new Expression(kMoleValue), residualVolumeFraction).flatten();
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
insideFluxCorrection = new Expression(kMoleValue);
}
if (rf.inFluxExpression.isZero()) {
rf.inFluxExpression = Expression.mult(insideFluxCorrection, reactionRateExpression);
} else {
rf.inFluxExpression = Expression.add(rf.inFluxExpression, Expression.mult(insideFluxCorrection, reactionRateExpression));
}
// rf.inFlux.bindExpression(mathMapping);
} else if (rp_Array[k].getStructure() == structTopology.getOutsideFeature(getMembrane())) {
//
// for binding on outside, add to ResolvedFlux.outFlux
//
FeatureMapping outsideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getOutsideFeature(getMembrane()));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(outsideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression outsideFluxCorrection = Expression.div(new Expression(kMoleValue), residualVolumeFraction).flatten();
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
outsideFluxCorrection = new Expression(kMoleValue);
}
if (rf.outFluxExpression.isZero()) {
rf.outFluxExpression = Expression.mult(outsideFluxCorrection, reactionRateExpression);
} else {
rf.outFluxExpression = Expression.add(rf.outFluxExpression, Expression.mult(outsideFluxCorrection, reactionRateExpression));
}
// rf.outFlux.bindExpression(mathMapping);
} else {
throw new Exception("SpeciesContext " + rp_Array[k].getSpeciesContext().getName() + " doesn't border membrane " + getMembrane().getName() + " but reacts there");
}
}
}
}
}
}
}
//
if (resolvedFluxList.size() > 0) {
resolvedFluxes = new ResolvedFlux[resolvedFluxList.size()];
resolvedFluxList.copyInto(resolvedFluxes);
} else {
resolvedFluxes = null;
}
}
Aggregations