use of cbit.vcell.model.ProxyParameter in project vcell by virtualcell.
the class AbstractStochMathMapping method getSubstitutedExpr.
/**
* @param expr
* @param bConcentration
* @return
* @throws ExpressionException
*/
protected Expression getSubstitutedExpr(Expression expr, boolean bConcentration, boolean bIsInitialCondn) throws ExpressionException {
expr = new Expression(expr);
String[] symbols = expr.getSymbols();
// Check if 'expr' has other speciesContexts in its expression, need to replace it with 'spContext_init'
for (int j = 0; symbols != null && j < symbols.length; j++) {
// if symbol is a speciesContext, replacing it with a reference to initial condition for that speciesContext.
SpeciesContext spC = null;
SymbolTableEntry ste = expr.getSymbolBinding(symbols[j]);
if (ste instanceof ProxyParameter) {
// if expression is for speciesContextSpec or Kinetics, ste will be a ProxyParameter instance.
ProxyParameter spspp = (ProxyParameter) ste;
if (spspp.getTarget() instanceof SpeciesContext) {
spC = (SpeciesContext) spspp.getTarget();
}
} else if (ste instanceof SpeciesContext) {
// if expression is for a global parameter, ste will be a SpeciesContext instance.
spC = (SpeciesContext) ste;
}
if (spC != null) {
SpeciesContextSpec spcspec = getSimulationContext().getReactionContext().getSpeciesContextSpec(spC);
Parameter spCParm = null;
if (bConcentration && bIsInitialCondn) {
// speciesContext has initConcentration set, so need to replace 'spContext' in 'expr' 'spContext_init'
spCParm = spcspec.getParameterFromRole(SpeciesContextSpec.ROLE_InitialConcentration);
} else if (!bConcentration && bIsInitialCondn) {
// speciesContext has initCount set, so need to replace 'spContext' in 'expr' 'spContext_initCount'
spCParm = spcspec.getParameterFromRole(SpeciesContextSpec.ROLE_InitialCount);
} else if (bConcentration && !bIsInitialCondn) {
// need to replace 'spContext' in 'expr' 'spContext_Conc'
spCParm = getSpeciesConcentrationParameter(spC);
} else if (!bConcentration && !bIsInitialCondn) {
// need to replace 'spContext' in 'expr' 'spContext_Count'
spCParm = getSpeciesCountParameter(spC);
}
// need to get init condn expression, but can't get it from getMathSymbol() (mapping between bio and math), hence get it as below.
Expression scsInitExpr = new Expression(spCParm, getNameScope());
// scsInitExpr.bindExpression(this);
expr.substituteInPlace(new Expression(spC.getName()), scsInitExpr);
}
}
return expr;
}
use of cbit.vcell.model.ProxyParameter in project vcell by virtualcell.
the class BioModelParametersTableModel method bioModelChange.
@Override
protected void bioModelChange(PropertyChangeEvent evt) {
super.bioModelChange(evt);
BioModel oldValue = (BioModel) evt.getOldValue();
if (oldValue != null) {
for (EditableSymbolTableEntry parameter : oldValue.getModel().getModelParameters()) {
parameter.removePropertyChangeListener(this);
}
for (SpeciesContext sc : oldValue.getModel().getSpeciesContexts()) {
sc.removePropertyChangeListener(this);
}
for (ReactionStep reactionStep : oldValue.getModel().getReactionSteps()) {
reactionStep.removePropertyChangeListener(this);
Kinetics kinetics = reactionStep.getKinetics();
kinetics.removePropertyChangeListener(this);
for (KineticsParameter kineticsEditableSymbolTableEntry : kinetics.getKineticsParameters()) {
kineticsEditableSymbolTableEntry.removePropertyChangeListener(this);
}
for (ProxyParameter proxyEditableSymbolTableEntry : kinetics.getProxyParameters()) {
proxyEditableSymbolTableEntry.removePropertyChangeListener(this);
}
for (UnresolvedParameter unresolvedEditableSymbolTableEntry : kinetics.getUnresolvedParameters()) {
unresolvedEditableSymbolTableEntry.removePropertyChangeListener(this);
}
}
for (SimulationContext simulationContext : oldValue.getSimulationContexts()) {
simulationContext.removePropertyChangeListener(this);
simulationContext.getGeometryContext().removePropertyChangeListener(this);
for (StructureMapping mapping : simulationContext.getGeometryContext().getStructureMappings()) {
mapping.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
simulationContext.getReactionContext().removePropertyChangeListener(this);
for (SpeciesContextSpec spec : simulationContext.getReactionContext().getSpeciesContextSpecs()) {
spec.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : spec.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
for (ElectricalStimulus elect : simulationContext.getElectricalStimuli()) {
elect.removePropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : elect.getParameters()) {
parameter.removePropertyChangeListener(this);
}
}
for (SpatialObject spatialObject : simulationContext.getSpatialObjects()) {
spatialObject.removePropertyChangeListener(this);
}
for (SpatialProcess spatialProcess : simulationContext.getSpatialProcesses()) {
spatialProcess.removePropertyChangeListener(this);
for (LocalParameter p : spatialProcess.getParameters()) {
p.removePropertyChangeListener(this);
}
}
for (SimulationContextParameter p : simulationContext.getSimulationContextParameters()) {
p.removePropertyChangeListener(this);
}
}
}
BioModel newValue = (BioModel) evt.getNewValue();
if (newValue != null) {
for (ModelParameter modelEditableSymbolTableEntry : newValue.getModel().getModelParameters()) {
modelEditableSymbolTableEntry.addPropertyChangeListener(this);
}
for (SpeciesContext sc : newValue.getModel().getSpeciesContexts()) {
sc.addPropertyChangeListener(this);
}
for (ReactionStep reactionStep : newValue.getModel().getReactionSteps()) {
reactionStep.addPropertyChangeListener(this);
Kinetics kinetics = reactionStep.getKinetics();
kinetics.addPropertyChangeListener(this);
for (KineticsParameter kineticsEditableSymbolTableEntry : kinetics.getKineticsParameters()) {
kineticsEditableSymbolTableEntry.addPropertyChangeListener(this);
}
for (ProxyParameter proxyEditableSymbolTableEntry : kinetics.getProxyParameters()) {
proxyEditableSymbolTableEntry.addPropertyChangeListener(this);
}
for (UnresolvedParameter unresolvedEditableSymbolTableEntry : kinetics.getUnresolvedParameters()) {
unresolvedEditableSymbolTableEntry.addPropertyChangeListener(this);
}
}
for (SimulationContext simulationContext : newValue.getSimulationContexts()) {
simulationContext.addPropertyChangeListener(this);
simulationContext.getGeometryContext().addPropertyChangeListener(this);
for (StructureMapping mapping : simulationContext.getGeometryContext().getStructureMappings()) {
mapping.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : mapping.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
simulationContext.getReactionContext().addPropertyChangeListener(this);
for (SpeciesContextSpec spec : simulationContext.getReactionContext().getSpeciesContextSpecs()) {
spec.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : spec.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
for (ElectricalStimulus elect : simulationContext.getElectricalStimuli()) {
elect.addPropertyChangeListener(this);
for (EditableSymbolTableEntry parameter : elect.getParameters()) {
parameter.addPropertyChangeListener(this);
}
}
for (SpatialObject spatialObject : simulationContext.getSpatialObjects()) {
spatialObject.addPropertyChangeListener(this);
}
for (SpatialProcess spatialProcess : simulationContext.getSpatialProcesses()) {
spatialProcess.addPropertyChangeListener(this);
for (LocalParameter p : spatialProcess.getParameters()) {
p.addPropertyChangeListener(this);
}
}
for (SimulationContextParameter p : simulationContext.getSimulationContextParameters()) {
p.addPropertyChangeListener(this);
}
}
}
}
use of cbit.vcell.model.ProxyParameter in project vcell by virtualcell.
the class SEDMLExporter method getSymbolTableEntryForModelEntity.
private SymbolTableEntry getSymbolTableEntryForModelEntity(MathSymbolMapping mathSymbolMapping, String paramName) {
cbit.vcell.math.Variable mathVar = mathSymbolMapping.findVariableByName(paramName);
SymbolTableEntry[] stEntries = mathSymbolMapping.getBiologicalSymbol(mathVar);
if (stEntries == null || stEntries.length == 0) {
throw new NullPointerException("No matching biological symbol for : " + paramName);
}
// if the extra stes in the array are KineticsProxyParameters/ModelQuantities, remove them from array. Should be left with only one entry for overriddenConstantName
if (stEntries.length > 1) {
//
// If there are more than one stEntries, usually, it is a regular ste (species, global parameter, structure, etc) together with
// kineticsProxyParameters (that have the regular ste as target) or Model quantities (structure size, membrane voltage).
// So filtering out the kinticProxyParametes should leave only the regular parameter,
// which is what we want. If there are more, then there is a problem.
//
ArrayList<SymbolTableEntry> steList = new ArrayList<SymbolTableEntry>(Arrays.asList(stEntries));
for (int i = 0; i < stEntries.length; i++) {
if (stEntries[i] instanceof ProxyParameter) {
SymbolTableEntry ppTargetSte = ((ProxyParameter) stEntries[i]).getTarget();
if (steList.contains(ppTargetSte) || ppTargetSte instanceof ModelQuantity) {
steList.remove(stEntries[i]);
}
}
if (stEntries[i] instanceof ModelQuantity) {
if (steList.contains(stEntries[i])) {
steList.remove(stEntries[i]);
}
}
}
// after removing proxy parameters, cannot have more than one ste in list
if (steList.size() == 0) {
throw new RuntimeException("No mapping entry for constant : '" + paramName + "'.");
}
if (steList.size() > 1) {
throw new RuntimeException("Cannot have more than one mapping entry for constant : '" + paramName + "'.");
}
SymbolTableEntry[] stes = (SymbolTableEntry[]) steList.toArray(new SymbolTableEntry[0]);
return stes[0];
} else {
return stEntries[0];
}
}
Aggregations