use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class BioEvent method setTriggerType.
public void setTriggerType(TriggerType triggerType) {
if (triggerType == this.triggerType) {
return;
}
this.triggerType = triggerType;
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition unit_TBD = modelUnitSystem.getInstance_TBD();
VCUnitDefinition unit_Dimensionless = modelUnitSystem.getInstance_DIMENSIONLESS();
VCUnitDefinition unit_modelTime = modelUnitSystem.getTimeUnit();
LocalParameter delayParam = parameterContext.new LocalParameter(BioEventParameterType.TriggerDelay.getDefaultName(), new Expression(0.0), BioEventParameterType.TriggerDelay, unit_modelTime, BioEventParameterType.TriggerDelay.getDescription());
LocalParameter generatedGeneralTriggerParam = parameterContext.new LocalParameter(BioEventParameterType.GeneralTriggerFunction.getDefaultName(), null, BioEventParameterType.GeneralTriggerFunction, unit_Dimensionless, BioEventParameterType.GeneralTriggerFunction.getDescription());
switch(triggerType) {
case GeneralTrigger:
{
try {
parameterContext.setLocalParameters(new LocalParameter[] { delayParam, parameterContext.new LocalParameter(BioEventParameterType.GeneralTriggerFunction.getDefaultName(), new Expression(0.0), BioEventParameterType.GeneralTriggerFunction, unit_Dimensionless, BioEventParameterType.GeneralTriggerFunction.getDescription()) });
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
break;
}
case ObservableAboveThreshold:
case ObservableBelowThreshold:
{
try {
parameterContext.setLocalParameters(new LocalParameter[] { delayParam, generatedGeneralTriggerParam, parameterContext.new LocalParameter(BioEventParameterType.Observable.getDefaultName(), null, BioEventParameterType.Observable, unit_TBD, BioEventParameterType.Observable.getDescription()), parameterContext.new LocalParameter(BioEventParameterType.Threshold.getDefaultName(), new Expression(1.0), BioEventParameterType.Threshold, unit_TBD, BioEventParameterType.Threshold.getDescription()) });
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
break;
}
case SingleTriggerTime:
{
try {
parameterContext.setLocalParameters(new LocalParameter[] { delayParam, generatedGeneralTriggerParam, parameterContext.new LocalParameter(BioEventParameterType.SingleTriggerTime.getDefaultName(), new Expression(1.0), BioEventParameterType.SingleTriggerTime, unit_modelTime, BioEventParameterType.SingleTriggerTime.getDescription()) });
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
break;
}
case LinearRangeTimes:
case LogRangeTimes:
{
try {
parameterContext.setLocalParameters(new LocalParameter[] { delayParam, generatedGeneralTriggerParam, parameterContext.new LocalParameter(BioEventParameterType.RangeMinTime.getDefaultName(), new Expression(1.0), BioEventParameterType.RangeMinTime, unit_modelTime, BioEventParameterType.RangeMinTime.getDescription()), parameterContext.new LocalParameter(BioEventParameterType.RangeMaxTime.getDefaultName(), new Expression(10.0), BioEventParameterType.RangeMaxTime, unit_modelTime, BioEventParameterType.RangeMaxTime.getDescription()), parameterContext.new LocalParameter(BioEventParameterType.RangeNumTimes.getDefaultName(), new Expression(9), BioEventParameterType.RangeNumTimes, unit_modelTime, BioEventParameterType.RangeNumTimes.getDescription()) });
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
break;
}
case ListOfTimes:
{
try {
parameterContext.setLocalParameters(new LocalParameter[] { delayParam, generatedGeneralTriggerParam, parameterContext.new LocalParameter(BioEventParameterType.TimeListItem.getDefaultName() + "0", new Expression(1.0), BioEventParameterType.TimeListItem, unit_modelTime, BioEventParameterType.TimeListItem.getDescription()), parameterContext.new LocalParameter(BioEventParameterType.TimeListItem.getDefaultName() + "1", new Expression(2.0), BioEventParameterType.TimeListItem, unit_modelTime, BioEventParameterType.TimeListItem.getDescription()), parameterContext.new LocalParameter(BioEventParameterType.TimeListItem.getDefaultName() + "2", new Expression(3.0), BioEventParameterType.TimeListItem, unit_modelTime, BioEventParameterType.TimeListItem.getDescription()) });
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage(), e);
}
break;
}
default:
{
throw new RuntimeException("unsupported rule-based kinetic law " + triggerType);
}
}
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class DistributedKinetics method getInwardCurrentDensity.
private Expression getInwardCurrentDensity() throws ExpressionException, PropertyVetoException {
//
// lumped kinetics always have same units (molecules/s) or (pA) whether used in a FluxReaction or a SimpleReaction
//
// CurrentMagnitude = reactionRate * valence * F * unitFactor
//
// for FluxReaction
//
Model model = getReactionStep().getModel();
Expression F = getSymbolExpression(model.getFARADAY_CONSTANT());
Expression reactionRate = getSymbolExpression(getReactionRateParameter());
Expression z = getSymbolExpression(getChargeValenceParameter());
Expression tempInwardCurrentDensityExpression = Expression.mult(z, F, reactionRate);
VCUnitDefinition tempRateUnit = getReactionRateParameter().getUnitDefinition().multiplyBy(model.getFARADAY_CONSTANT().getUnitDefinition()).multiplyBy(getChargeValenceParameter().getUnitDefinition());
VCUnitDefinition desiredUnit = getCurrentDensityParameter().getUnitDefinition();
Expression unitFactorExp = getElectricalUnitFactor(desiredUnit.divideBy(tempRateUnit));
if (unitFactorExp != null) {
tempInwardCurrentDensityExpression = Expression.mult(tempInwardCurrentDensityExpression, unitFactorExp);
}
if (hasOutwardFlux()) {
tempInwardCurrentDensityExpression = Expression.negate(tempInwardCurrentDensityExpression);
}
return tempInwardCurrentDensityExpression;
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class DistributedKinetics method updateInwardCurrentDensityFromReactionRate.
protected void updateInwardCurrentDensityFromReactionRate() throws ExpressionException, PropertyVetoException {
KineticsParameter rateParmInput = getReactionRateParameter();
KineticsParameter currentParm = getCurrentDensityParameter();
if (currentParm == null && rateParmInput == null) {
return;
}
if (getReactionStep().getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_AND_ELECTRICAL) {
Expression tempCurrentDensityExpression = getInwardCurrentDensity();
if (currentParm == null) {
Model model = getReactionStep().getModel();
VCUnitDefinition currentUnit = model.getUnitSystem().getCurrentDensityUnit();
addKineticsParameter(new KineticsParameter(getDefaultParameterName(ROLE_CurrentDensity), tempCurrentDensityExpression, ROLE_CurrentDensity, currentUnit));
} else {
currentParm.setExpression(tempCurrentDensityExpression);
}
} else {
if (currentParm != null && !currentParm.getExpression().isZero()) {
// removeKineticsParameter(rateParm);
currentParm.setExpression(new Expression(0.0));
}
KineticsParameter unitParam = getKineticsParameterFromRole(ROLE_ElectricalUnitFactor);
if (unitParam != null) {
removeKineticsParameter(unitParam);
}
}
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class DistributedKinetics method updateReactionRatesFromInwardCurrentDensity.
protected void updateReactionRatesFromInwardCurrentDensity() throws ExpressionException, PropertyVetoException {
KineticsParameter currentParm = getCurrentDensityParameter();
KineticsParameter rateParm = getReactionRateParameter();
if (currentParm == null && rateParm == null) {
return;
}
if (getReactionStep().getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_AND_ELECTRICAL) {
Expression tempRateExpression = getReactionRate();
if (rateParm == null) {
Model model = getReactionStep().getModel();
VCUnitDefinition rateUnit = null;
if (getReactionStep() instanceof SimpleReaction) {
rateUnit = model.getUnitSystem().getMembraneReactionRateUnit();
} else if (getReactionStep() instanceof FluxReaction) {
rateUnit = model.getUnitSystem().getFluxReactionUnit();
} else {
rateUnit = model.getUnitSystem().getInstance_TBD();
}
addKineticsParameter(new KineticsParameter(getDefaultParameterName(ROLE_LumpedReactionRate), tempRateExpression, ROLE_LumpedReactionRate, rateUnit));
} else {
rateParm.setExpression(tempRateExpression);
}
} else {
if (rateParm != null && !rateParm.getExpression().isZero()) {
// removeKineticsParameter(rateParm);
rateParm.setExpression(new Expression(0.0));
}
KineticsParameter unitParam = getKineticsParameterFromRole(ROLE_ElectricalUnitFactor);
if (unitParam != null) {
removeKineticsParameter(unitParam);
}
}
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class Kinetics method resolveUndefinedUnits.
/**
* Insert the method's description here.
* Creation date: (4/13/2004 3:09:21 PM)
*/
public void resolveUndefinedUnits() {
//
if (!bResolvingUnits) {
bResolvingUnits = true;
try {
if (getReactionStep().getModel() != null) {
ModelUnitSystem modelUnitSystem = getReactionStep().getModel().getUnitSystem();
boolean bAnyTBDUnits = false;
for (int i = 0; i < fieldKineticsParameters.length; i++) {
if (fieldKineticsParameters[i].getUnitDefinition() == null) {
// not ready to resolve units yet
return;
} else if (fieldKineticsParameters[i].getUnitDefinition().isTBD()) {
bAnyTBDUnits = true;
}
}
//
if (bAnyTBDUnits) {
VCUnitEvaluator unitEvaluator = new VCUnitEvaluator(modelUnitSystem);
VCUnitDefinition[] vcUnitDefinitions = unitEvaluator.suggestUnitDefinitions(fieldKineticsParameters);
for (int i = 0; i < fieldKineticsParameters.length; i++) {
if (!fieldKineticsParameters[i].getUnitDefinition().isEquivalent(vcUnitDefinitions[i])) {
fieldKineticsParameters[i].setUnitDefinition(vcUnitDefinitions[i]);
}
}
// System.out.println("successfully completed Kinetics.resolveUndefinedUnits() for ReactionStep '"+getReactionStep()+"'");
}
}
} catch (Exception e) {
if (lg.isEnabledFor(Level.WARN)) {
lg.warn("Kinetics.resolveUndefinedUnits(): EXCEPTION: " + e.getMessage());
}
} finally {
bResolvingUnits = false;
}
}
}
Aggregations