use of cbit.vcell.mapping.SimContextTransformer.ModelEntityMapping in project vcell by virtualcell.
the class MathSymbolMapping method transform.
public void transform(SimContextTransformation transformation) {
if (transformation == null || transformation.modelEntityMappings == null) {
return;
}
for (ModelEntityMapping mapping : transformation.modelEntityMappings) {
Variable var = biologicalToMathHash.remove(mapping.newModelObj);
if (var != null) {
biologicalToMathHash.put(mapping.origModelObj, var);
}
String varName = biologicalToMathSymbolNameHash.remove(mapping.newModelObj);
if (varName != null) {
biologicalToMathSymbolNameHash.put(mapping.origModelObj, varName);
}
}
for (Map.Entry<Variable, SymbolTableEntry[]> entry : mathToBiologicalHash.entrySet()) {
Variable key = entry.getKey();
SymbolTableEntry[] newBiologicalSymbols = entry.getValue();
ArrayList<SymbolTableEntry> origStes = new ArrayList<SymbolTableEntry>();
for (SymbolTableEntry newBiologicalSymbol : newBiologicalSymbols) {
// replace all array entries with those from the original model
for (ModelEntityMapping mapping : transformation.modelEntityMappings) {
if (newBiologicalSymbol == mapping.newModelObj) {
origStes.add(mapping.origModelObj);
}
}
}
entry.setValue(origStes.toArray(new SymbolTableEntry[0]));
}
}
use of cbit.vcell.mapping.SimContextTransformer.ModelEntityMapping in project vcell by virtualcell.
the class StochMathMapping method refreshVariables.
/**
* Map speciesContext to variable, used for structural analysis (slow reactions and fast reactions)
* Creation date: (10/25/2006 8:59:43 AM)
* @exception cbit.vcell.mapping.MappingException The exception description.
*/
@Override
protected void refreshVariables() throws MappingException {
//
// stochastic species need species variables require either a membrane or volume variable
//
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
// stochastic variable is always a function of size.
SpeciesCountParameter spCountParm = null;
try {
String countName = scs.getSpeciesContext().getName() + BIO_PARAM_SUFFIX_SPECIES_COUNT;
Expression countExp = new Expression(0.0);
spCountParm = addSpeciesCountParameter(countName, countExp, PARAMETER_ROLE_SPECIES_COUNT, scs.getInitialCountParameter().getUnitDefinition(), scs.getSpeciesContext());
} catch (PropertyVetoException pve) {
pve.printStackTrace();
throw new MappingException(pve.getMessage());
}
// add concentration of species as MathMappingParameter - this will map to species concentration function
try {
String concName = scs.getSpeciesContext().getName() + BIO_PARAM_SUFFIX_SPECIES_CONCENTRATION;
Expression concExp = getExpressionAmtToConc(new Expression(spCountParm, getNameScope()), scs.getSpeciesContext().getStructure());
concExp.bindExpression(this);
addSpeciesConcentrationParameter(concName, concExp, PARAMETER_ROLE_SPECIES_CONCENRATION, scs.getSpeciesContext().getUnitDefinition(), scs.getSpeciesContext());
} catch (Exception e) {
e.printStackTrace();
throw new MappingException(e.getMessage(), e);
}
// we always add variables, all species are independent variables, no matter they are constant or not.
String countMathSymbol = getMathSymbol(spCountParm, getSimulationContext().getGeometryContext().getStructureMapping(scs.getSpeciesContext().getStructure()).getGeometryClass());
scm.setVariable(new StochVolVariable(countMathSymbol));
}
//
// if the original (untransformed) model has any explicit observables (which are rule-based components), then the transformed model maps these observables to "Concentration" ModelParameters.
//
// for symmetry with the RuleBasedMathMapping, we want to generate a "_Count" version of these observables if applicable.
//
// so if a rule-to-network "transformation" was performed, we want to find those ModelParameters which map to Observables (concentrations) so that we can generate an additional "Count" function (by scaling by compartment size and performing a unit conversion).
//
SimContextTransformation transformation = getTransformation();
if (transformation != null) {
ModelEntityMapping[] modelEntityMappings = transformation.modelEntityMappings;
if (modelEntityMappings != null) {
for (ModelEntityMapping mem : modelEntityMappings) {
if (mem.newModelObj instanceof ModelParameter && mem.origModelObj instanceof RbmObservable) {
ModelParameter concObservableParameter = (ModelParameter) mem.newModelObj;
RbmObservable observable = (RbmObservable) mem.origModelObj;
try {
Expression countExp = getExpressionConcToExpectedCount(new Expression(concObservableParameter, getNameScope()), observable.getStructure());
// countExp.bindExpression(this);
addObservableCountParameter(concObservableParameter.getName() + BIO_PARAM_SUFFIX_SPECIES_COUNT, countExp, PARAMETER_ROLE_OBSERVABLE_COUNT, getSimulationContext().getModel().getUnitSystem().getStochasticSubstanceUnit(), observable);
} catch (ExpressionException | PropertyVetoException e) {
e.printStackTrace();
throw new MappingException(e.getMessage(), e);
}
}
}
}
}
}
Aggregations