use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.
the class ElectricalStimulus method parameterVCMLSet.
/**
* This method was created by a SmartGuide.
* @param tokens java.util.StringTokenizer
* @exception java.lang.Exception The exception description.
*/
public final void parameterVCMLSet(CommentStringTokenizer tokens) throws ExpressionException, PropertyVetoException {
if (tokens == null) {
return;
}
Vector<LocalParameter> esParametersV = new Vector<LocalParameter>();
if (!tokens.nextToken().equalsIgnoreCase(VCMODL.ElectricalStimulus) || !tokens.nextToken().equalsIgnoreCase(GENERAL_PROTOCOL) || !tokens.nextToken().equalsIgnoreCase(VCMODL.BeginBlock)) {
throw new RuntimeException(ElectricalStimulus.class.getName() + ".parameterVCMLRead, unexpected token ");
}
String token = null;
ModelUnitSystem modelUnitSystem = simulationContext.getModel().getUnitSystem();
while (tokens.hasMoreTokens()) {
token = tokens.nextToken();
if (token.equalsIgnoreCase(VCMODL.EndBlock)) {
break;
}
if (token.equalsIgnoreCase(VCMODL.Parameter)) {
String roleName = tokens.nextToken();
ElectricalStimulusParameterType parameterType = null;
for (ElectricalStimulusParameterType role : ElectricalStimulusParameterType.values()) {
if (roleName.equals(role.databaseRoleTag)) {
parameterType = role;
break;
}
}
if (parameterType == null) {
throw new RuntimeException(ElectricalStimulus.class.getName() + ".parameterVCMLRead, unexpected token for roleName " + roleName);
}
String parameterName = tokens.nextToken();
Expression exp = MathFunctionDefinitions.fixFunctionSyntax(tokens);
String unitsString = tokens.nextToken();
VCUnitDefinition unitDef = modelUnitSystem.getInstance_TBD();
if (unitsString.startsWith("[")) {
while (!unitsString.endsWith("]")) {
String tempToken = tokens.nextToken();
unitsString = unitsString + " " + tempToken;
}
//
// now string starts with '[' and ends with ']'
//
unitDef = modelUnitSystem.getInstance(unitsString.substring(1, unitsString.length() - 1));
} else {
tokens.pushToken(unitsString);
}
LocalParameter esp = parameterContext.new LocalParameter(parameterName, exp, parameterType, unitDef, parameterType.databaseRoleTag);
esParametersV.add(esp);
} else {
throw new RuntimeException(ElectricalStimulus.class.getName() + ".parameterVCMLRead, unexpected token for paramter tag " + token);
}
}
if (esParametersV.size() > 0) {
LocalParameter[] espArr = new LocalParameter[esParametersV.size()];
esParametersV.copyInto(espArr);
parameterContext.setLocalParameters(espArr);
} else {
parameterContext.setLocalParameters(null);
}
}
use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.
the class NetworkTransformer method applyKineticsExpressions.
// private Expression substituteFakeParameters(Expression paramExpression) throws ExpressionException {
// Expression newExp = new Expression(paramExpression);
// String[] fakeSymbols = paramExpression.getSymbols();
// for (String fakeSymbol : fakeSymbols){
// FakeReactionRuleRateParameter fakeParameter = FakeReactionRuleRateParameter.fromString(fakeSymbol);
// if (fakeParameter == null){
// throw new RuntimeException("unexpected identifier "+fakeSymbol+" in kinetic law during network generation");
// }
// LocalParameter localParameter = this.kineticsParameterMap.get(fakeParameter);
// Expression ruleExpression = localParameter.getExpression();
// newExp.substituteInPlace(new Expression(fakeSymbol), new Expression(ruleExpression));
// }
// return newExp;
// }
private Expression applyKineticsExpressions(BNGReaction bngReaction, KineticsParameter rateParameter, MassActionKinetics targetKinetics) throws ExpressionException {
ReactionRule reactionRule = null;
Expression paramExpression = bngReaction.getParamExpression();
Expression newExp = new Expression(paramExpression);
String[] fakeSymbols = paramExpression.getSymbols();
for (String fakeSymbol : fakeSymbols) {
FakeReactionRuleRateParameter fakeParameter = FakeReactionRuleRateParameter.fromString(fakeSymbol);
if (fakeParameter == null) {
throw new RuntimeException("unexpected identifier " + fakeSymbol + " in kinetic law during network generation");
}
LocalParameter localParameter = this.kineticsParameterMap.get(fakeParameter);
System.out.println(localParameter.getNameScope());
if (localParameter.getNameScope() instanceof ReactionRule.ReactionRuleNameScope) {
reactionRule = ((ReactionRule.ReactionRuleNameScope) localParameter.getNameScope()).getReactionRule();
}
Expression ruleExpression = localParameter.getExpression();
newExp.substituteInPlace(new Expression(fakeSymbol), new Expression(ruleExpression));
}
//
try {
targetKinetics.setParameterValue(rateParameter, newExp);
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException("failed to set kinetics expression for reaction " + targetKinetics.getReactionStep().getName() + ": " + e.getMessage(), e);
}
//
if (reactionRule != null) {
// try to set values from user-defined parameters into the target kinetics
for (LocalParameter localParameter : reactionRule.getKineticLaw().getLocalParameters()) {
if (localParameter.getRole() == RbmKineticLawParameterType.UserDefined) {
KineticsParameter userDefinedParam = targetKinetics.getKineticsParameter(localParameter.getName());
if (userDefinedParam != null) {
try {
targetKinetics.setParameterValue(userDefinedParam, localParameter.getExpression());
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException("failed to set kinetics expression for reaction " + targetKinetics.getReactionStep().getName() + ": " + e.getMessage(), e);
}
}
}
}
}
return newExp;
}
use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.
the class AbstractMathMapping method getMathSymbol0.
/**
* Substitutes appropriate variables for speciesContext bindings
*
* @return cbit.vcell.parser.Expression
* @param origExp cbit.vcell.parser.Expression
* @param structureMapping cbit.vcell.mapping.StructureMapping
*/
protected final String getMathSymbol0(SymbolTableEntry ste, GeometryClass geometryClass) throws MappingException {
String steName = ste.getName();
if (ste instanceof Kinetics.KineticsParameter) {
Integer count = localNameCountHash.get(steName);
if (count == null) {
throw new MappingException("KineticsParameter " + steName + " not found in local name count");
}
if (count > 1 || steName.equals("J")) {
return steName + "_" + ste.getNameScope().getName();
// return getNameScope().getSymbolName(ste);
} else {
return steName;
}
}
if (ste instanceof LocalParameter && ((LocalParameter) ste).getNameScope() instanceof ReactionRule.ReactionRuleNameScope) {
Integer count = localNameCountHash.get(steName);
if (count == null) {
throw new MappingException("Reaction Rule Parameter " + steName + " not found in local name count");
}
if (count > 1 || steName.equals("J")) {
return steName + "_" + ste.getNameScope().getName();
// return getNameScope().getSymbolName(ste);
} else {
return steName;
}
}
if (ste instanceof ProbabilityParameter) {
// be careful here, to see if we need mangle the reaction name
ProbabilityParameter probParm = (ProbabilityParameter) ste;
return probParm.getName() + PARAMETER_PROBABLIITY_RATE_SUFFIX;
}
if (ste instanceof SpeciesConcentrationParameter) {
SpeciesConcentrationParameter concParm = (SpeciesConcentrationParameter) ste;
return concParm.getSpeciesContext().getName() + MATH_FUNC_SUFFIX_SPECIES_CONCENTRATION;
}
if (ste instanceof SpeciesCountParameter) {
SpeciesCountParameter countParm = (SpeciesCountParameter) ste;
return countParm.getSpeciesContext().getName() + MATH_VAR_SUFFIX_SPECIES_COUNT;
}
if (ste instanceof ObservableConcentrationParameter) {
ObservableConcentrationParameter concParm = (ObservableConcentrationParameter) ste;
return concParm.getObservable().getName() + MATH_FUNC_SUFFIX_SPECIES_CONCENTRATION;
}
if (ste instanceof ObservableCountParameter) {
ObservableCountParameter countParm = (ObservableCountParameter) ste;
return countParm.getObservable().getName() + MATH_VAR_SUFFIX_SPECIES_COUNT;
}
if (ste instanceof RbmObservable) {
RbmObservable observable = (RbmObservable) ste;
return observable.getName() + MATH_FUNC_SUFFIX_SPECIES_CONCENTRATION;
}
if (ste instanceof EventAssignmentOrRateRuleInitParameter) {
EventAssignmentOrRateRuleInitParameter eventInitParm = (EventAssignmentOrRateRuleInitParameter) ste;
// + MATH_FUNC_SUFFIX_EVENTASSIGN_OR_RATE_INIT;
return eventInitParm.getName();
}
if (ste instanceof RateRuleRateParameter) {
RateRuleRateParameter rateRuleRateParm = (RateRuleRateParameter) ste;
// + MATH_FUNC_SUFFIX_RATERULE_RATE;
return rateRuleRateParm.getName();
}
if (ste instanceof Model.ReservedSymbol) {
return steName;
}
if (ste instanceof Membrane.MembraneVoltage) {
return steName;
}
if (ste instanceof Structure.StructureSize) {
Structure structure = ((Structure.StructureSize) ste).getStructure();
StructureMapping.StructureMappingParameter sizeParameter = simContext.getGeometryContext().getStructureMapping(structure).getSizeParameter();
return getMathSymbol(sizeParameter, geometryClass);
}
if (ste instanceof ProxyParameter) {
ProxyParameter pp = (ProxyParameter) ste;
return getMathSymbol0(pp.getTarget(), geometryClass);
}
//
if (ste instanceof ModelParameter) {
ModelParameter mp = (ModelParameter) ste;
return mp.getName();
}
if (ste instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
SpeciesContextSpec.SpeciesContextSpecParameter scsParm = (SpeciesContextSpec.SpeciesContextSpecParameter) ste;
SpeciesContext speciesContext = ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext();
SpeciesContextMapping scm = getSpeciesContextMapping(speciesContext);
String speciesContextVarName = null;
if (scm.getVariable() != null) {
speciesContextVarName = scm.getVariable().getName();
} else {
speciesContextVarName = speciesContext.getName();
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_InitialConcentration) {
return speciesContextVarName + MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX + TokenMangler.fixTokenStrict(scsParm.getUnitDefinition().getSymbol());
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_InitialCount) {
return speciesContextVarName + MATH_FUNC_SUFFIX_SPECIES_INIT_COUNT;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_DiffusionRate) {
return speciesContextVarName + PARAMETER_DIFFUSION_RATE_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueXm) {
return speciesContextVarName + PARAMETER_BOUNDARY_XM_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueXp) {
return speciesContextVarName + PARAMETER_BOUNDARY_XP_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueYm) {
return speciesContextVarName + PARAMETER_BOUNDARY_YM_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueYp) {
return speciesContextVarName + PARAMETER_BOUNDARY_YP_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueZm) {
return speciesContextVarName + PARAMETER_BOUNDARY_ZM_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueZp) {
return speciesContextVarName + PARAMETER_BOUNDARY_ZP_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityX) {
return speciesContextVarName + PARAMETER_VELOCITY_X_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityY) {
return speciesContextVarName + PARAMETER_VELOCITY_Y_SUFFIX;
}
if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityZ) {
return speciesContextVarName + PARAMETER_VELOCITY_Z_SUFFIX;
}
}
if (ste instanceof ElectricalDevice.ElectricalDeviceParameter) {
ElectricalDevice.ElectricalDeviceParameter edParm = (ElectricalDevice.ElectricalDeviceParameter) ste;
ElectricalDevice electricalDevice = (ElectricalDevice) edParm.getNameScope().getScopedSymbolTable();
if (electricalDevice instanceof MembraneElectricalDevice) {
String nameWithScope = ((MembraneElectricalDevice) electricalDevice).getMembraneMapping().getMembrane().getNameScope().getName();
if (edParm.getRole() == ElectricalDevice.ROLE_TotalCurrent) {
return PARAMETER_TOTAL_CURRENT_PREFIX + nameWithScope;
}
if (edParm.getRole() == ElectricalDevice.ROLE_TransmembraneCurrent) {
return PARAMETER_TRANSMEMBRANE_CURRENT_PREFIX + nameWithScope;
}
// }else if (electricalDevice instanceof CurrentClampElectricalDevice) {
// if (edParm.getRole()==ElectricalDevice.ROLE_TotalCurrentDensity){
// return "I_"+((CurrentClampElectricalDevice)electricalDevice).getCurrentClampStimulus().getNameScope().getName();
// }
// if (edParm.getRole()==ElectricalDevice.ROLE_TransmembraneCurrentDensity){
// return "F_"+((CurrentClampElectricalDevice)electricalDevice).getCurrentClampStimulus().getNameScope().getName();
// }
// }else if (electricalDevice instanceof VoltageClampElectricalDevice) {
// if (edParm.getRole()==ElectricalDevice.ROLE_TotalCurrentDensity){
// return "I_"+((VoltageClampElectricalDevice)electricalDevice).getVoltageClampStimulus().getNameScope().getName();
// }
// if (edParm.getRole()==ElectricalDevice.ROLE_TransmembraneCurrentDensity){
// return "F_"+((VoltageClampElectricalDevice)electricalDevice).getVoltageClampStimulus().getNameScope().getName();
// }
}
}
if (ste instanceof LocalParameter && ((LocalParameter) ste).getNameScope() instanceof ElectricalStimulus.ElectricalStimulusNameScope) {
LocalParameter esParm = (LocalParameter) ste;
String nameWithScope = esParm.getNameScope().getName();
if (esParm.getRole() == ElectricalStimulus.ElectricalStimulusParameterType.TotalCurrent) {
return PARAMETER_TOTAL_CURRENT_PREFIX + nameWithScope;
} else if (esParm.getRole() == ElectricalStimulus.ElectricalStimulusParameterType.Voltage) {
return PARAMETER_VOLTAGE_PREFIX + nameWithScope;
}
}
if (ste instanceof StructureMapping.StructureMappingParameter) {
StructureMapping.StructureMappingParameter smParm = (StructureMapping.StructureMappingParameter) ste;
Structure structure = ((StructureMapping) (smParm.getNameScope().getScopedSymbolTable())).getStructure();
String nameWithScope = structure.getNameScope().getName();
int role = smParm.getRole();
if (role == StructureMapping.ROLE_InitialVoltage) {
return smParm.getName();
} else if (role == StructureMapping.ROLE_SpecificCapacitance) {
return PARAMETER_SPECIFIC_CAPACITANCE_PREFIX + nameWithScope;
} else if (role == StructureMapping.ROLE_Size) {
if (simContext.getGeometry().getDimension() == 0) {
// if geometry is compartmental, make sure compartment sizes are set if referenced in model.
if (smParm.getExpression() == null || smParm.getExpression().isZero()) {
throw new MappingException("\nIn non-spatial application '" + getSimulationContext().getName() + "', " + "size of structure '" + structure.getName() + "' must be assigned a " + "positive value if referenced in the model.\n\nPlease go to 'Structure Mapping' tab to check the size.");
}
}
return PARAMETER_SIZE_FUNCTION_PREFIX + nameWithScope;
} else if (role == StructureMapping.ROLE_AreaPerUnitArea) {
return "AreaPerUnitArea_" + nameWithScope;
} else if (role == StructureMapping.ROLE_AreaPerUnitVolume) {
return "AreaPerUnitVolume_" + nameWithScope;
} else if (role == StructureMapping.ROLE_VolumePerUnitArea) {
return "VolumePerUnitArea_" + nameWithScope;
} else if (role == StructureMapping.ROLE_VolumePerUnitVolume) {
return "VolumePerUnitVolume_" + nameWithScope;
}
}
//
if (ste instanceof SpeciesContext) {
SpeciesContext sc = (SpeciesContext) ste;
SpeciesContextMapping scm = getSpeciesContextMapping(sc);
if (scm == null) {
throw new RuntimeException("Species '" + sc.getName() + "' is referenced in model but may have been deleted. " + "Find its references in '" + GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_BIOMODEL_PARAMETERS + "'.");
}
//
if (geometryClass instanceof SubVolume) {
//
if (scm.getVariable() != null && !scm.getVariable().getName().equals(steName)) {
return scm.getVariable().getName();
}
//
// for reactions within a surface, may need "_INSIDE" or "_OUTSIDE" for jump condition
//
} else if (geometryClass instanceof SurfaceClass) {
//
// if the speciesContext is also within the surface, replace SpeciesContext name with Variable name
//
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(sc.getStructure());
if (sm.getGeometryClass() == geometryClass) {
if (scm.getVariable() != null && !(scm.getVariable().getName().equals(ste.getName()))) {
return scm.getVariable().getName();
}
//
// if the speciesContext is "inside" or "outside" the membrane
//
} else if (sm.getGeometryClass() instanceof SubVolume && ((SurfaceClass) geometryClass).isAdjacentTo((SubVolume) sm.getGeometryClass())) {
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(sc);
if (!scs.isConstant()) {
if (!scs.isDiffusing() && !scs.isWellMixed()) {
throw new MappingException("Enable diffusion in Application '" + simContext.getName() + "'. This must be done for any species (e.g '" + sc.getName() + "') in flux reactions.\n\n" + "To save or run simulations, set the diffusion rate to a non-zero " + "value in Initial Conditions or disable those reactions in Specifications->Reactions.");
}
}
if (scm.getVariable() != null) {
return scm.getVariable().getName();
}
} else {
throw new MappingException("species '" + sc.getName() + "' interacts with surface '" + geometryClass.getName() + "', but is not mapped spatially adjacent");
}
}
}
return getNameScope().getSymbolName(ste);
}
use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.
the class AbstractMathMapping method refreshLocalNameCount.
protected void refreshLocalNameCount() {
localNameCountHash.clear();
ReactionStep[] reactionSteps = simContext.getModel().getReactionSteps();
for (int j = 0; j < reactionSteps.length; j++) {
KineticsParameter[] params = reactionSteps[j].getKinetics().getKineticsParameters();
for (KineticsParameter kp : params) {
String name = kp.getName();
if (localNameCountHash.containsKey(name)) {
localNameCountHash.put(name, localNameCountHash.get(name) + 1);
} else {
localNameCountHash.put(name, 1);
}
}
}
List<ReactionRule> reactionRules = simContext.getModel().getRbmModelContainer().getReactionRuleList();
for (ReactionRule reactionRule : reactionRules) {
LocalParameter[] params = reactionRule.getKineticLaw().getLocalParameters();
for (LocalParameter kp : params) {
String name = kp.getName();
if (localNameCountHash.containsKey(name)) {
localNameCountHash.put(name, localNameCountHash.get(name) + 1);
} else {
localNameCountHash.put(name, 1);
}
}
}
SpeciesContext[] scs = simContext.getModel().getSpeciesContexts();
for (SpeciesContext sc : scs) {
String name = sc.getName();
if (localNameCountHash.containsKey(name)) {
localNameCountHash.put(name, localNameCountHash.get(name) + 1);
} else {
localNameCountHash.put(name, 1);
}
}
ModelParameter[] mps = simContext.getModel().getModelParameters();
for (ModelParameter mp : mps) {
String name = mp.getName();
if (localNameCountHash.containsKey(name)) {
localNameCountHash.put(name, localNameCountHash.get(name) + 1);
} else {
localNameCountHash.put(name, 1);
}
}
}
use of cbit.vcell.mapping.ParameterContext.LocalParameter in project vcell by virtualcell.
the class BioEvent method setTimeList.
public void setTimeList(Expression[] listExps) throws ExpressionBindingException, PropertyVetoException {
if (triggerType != TriggerType.ListOfTimes) {
throw new RuntimeException("list of times only available for " + TriggerType.ListOfTimes.name() + " trigger type");
}
//
// remove any existing TimeListItem parameters
//
ArrayList<LocalParameter> parameters = new ArrayList<LocalParameter>();
for (LocalParameter p : getEventParameters()) {
if (p.getRole() != BioEventParameterType.TimeListItem) {
parameters.add(p);
}
}
//
// generate new TimeListItem parameters from function arguments
//
VCUnitDefinition timeUnit = getSimulationContext().getModel().getUnitSystem().getTimeUnit();
String name = "t0";
for (Expression exp : listExps) {
String description = BioEventParameterType.TimeListItem.description;
parameters.add(parameterContext.new LocalParameter(name, exp, BioEventParameterType.TimeListItem, timeUnit, description));
name = TokenMangler.getNextEnumeratedToken(name);
}
setParameters(parameters.toArray(new LocalParameter[0]));
}
Aggregations