use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.
the class StructureAnalyzer method substituteIntoFastSystem.
/**
* This method was created in VisualAge.
*/
private void substituteIntoFastSystem() throws Exception {
//
for (int j = 0; j < speciesContextMappings.length; j++) {
if (speciesContextMappings[j].getDependencyExpression() != null) {
Expression dependentVar = new Expression(speciesContextMappings[j].getSpeciesContext(), mathMapping_4_8.getNameScope());
Expression dependentExp = new Expression(speciesContextMappings[j].getDependencyExpression());
// System.out.println("trying to substitute '"+dependentExp.toString()+"' for variable '"+dependentVar.toString()+"'");
for (int i = 0; i < fastSpeciesContextMappings.length; i++) {
SpeciesContextMapping scm = fastSpeciesContextMappings[i];
if (scm.getFastInvariant() != null) {
scm.getFastInvariant().substituteInPlace(dependentVar, dependentExp);
scm.setFastInvariant(scm.getFastInvariant().flatten());
} else {
scm.getFastRate().substituteInPlace(dependentVar, dependentExp);
scm.setFastRate(scm.getFastRate().flatten());
}
}
}
}
// for (int i=0;i<fastSpeciesContextMappings.length;i++){
// SpeciesContextMapping scm = fastSpeciesContextMappings[i];
// if (scm.fastInvariant!=null){
// System.out.println("fastInvariant for "+scm.getSpeciesContext().getName()+" = "+scm.fastInvariant.toString());
// }else{
// System.out.println("fastRate for "+scm.getSpeciesContext().getName()+" = "+scm.fastRate.toString());
// }
// }
}
use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.
the class StructureAnalyzer method refreshFastSystem.
/**
* Find which species are fast-independent, use their rates as the "fastRate"s.
* null space rows correspond to "fastInvariant".
*/
private void refreshFastSystem() throws Exception {
//
for (int v = 0; v < fastSpeciesContextMappings.length; v++) {
fastSpeciesContextMappings[v].setFastInvariant(null);
}
if (fastNullSpaceMatrix == null) {
// System.out.println("the fast matrix has full rank, there are no fast invariants");
return;
}
if (fastSpeciesContextMappings.length != fastNullSpaceMatrix.getNumCols()) {
throw new Exception("varName array not same dimension as b matrix");
}
StructureAnalyzer.Dependency[] dependencies = refreshTotalDependancies(fastNullSpaceMatrix, fastSpeciesContextMappings, mathMapping_4_8, true);
for (int i = 0; i < dependencies.length; i++) {
// String constantName = dependencies[i].invariantSymbolName;
Expression constantExp = dependencies[i].conservedMoietyExpression;
SpeciesContextMapping firstSCM = dependencies[i].speciesContextMapping;
// Expression exp = dependencies[i].dependencyExpression;
//
// store fastInvariant (e.g. (K_fast_total= xyz + wzy)
//
constantExp.bindExpression(mathMapping_4_8);
firstSCM.setFastInvariant(constantExp.flatten());
}
}
use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.
the class MathMapping_4_8 method getResolvedVolVariable.
/**
* Find the defined variable (VolVariable) for the resolved compartments.
* This method is used to assure only one variable is created.
* @return cbit.vcell.math.VolVariable
* @param species cbit.vcell.model.Species
*/
private VolVariable getResolvedVolVariable(Species species) {
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
if (scm.getSpeciesContext().getSpecies() == species) {
Variable var = scm.getVariable();
if (var instanceof VolVariable) {
Structure structure = scm.getSpeciesContext().getStructure();
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(structure);
if (structure instanceof Feature && getResolved(sm)) {
return (VolVariable) var;
}
}
}
}
return new VolVariable(TokenMangler.fixTokenStrict(species.getCommonName()), nullDomain);
}
use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.
the class MathMapping_4_8 method refreshVariables.
/**
* This method was created in VisualAge.
*/
private void refreshVariables() throws MappingException {
// System.out.println("MathMapping.refreshVariables()");
//
// non-constant dependent variables require a function
//
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() != null && !scs.isConstant()) {
// scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
scm.setVariable(null);
}
}
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (getSimulationContext().hasEventAssignment(scs.getSpeciesContext())) {
scm.setDependencyExpression(null);
}
}
//
// non-constant independent variables require either a membrane or volume variable
//
enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))) {
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
Structure struct = scm.getSpeciesContext().getStructure();
if (struct instanceof Feature) {
if (getResolved(sm)) {
scm.setVariable(getResolvedVolVariable(scm.getSpeciesContext().getSpecies()));
} else {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
}
} else if (struct instanceof Membrane) {
if (getResolved(sm)) {
scm.setVariable(new MemVariable(scm.getSpeciesContext().getName(), nullDomain));
} else {
scm.setVariable(new VolVariable(scm.getSpeciesContext().getName(), nullDomain));
}
} else {
throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
}
mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
}
}
}
use of cbit.vcell.mapping.SpeciesContextMapping in project vcell by virtualcell.
the class MathMapping_4_8 method refreshSpeciesContextMappings.
/**
* This method was created in VisualAge.
*/
private void refreshSpeciesContextMappings() throws ExpressionException, MappingException, MathException {
//
// create a SpeciesContextMapping for each speciesContextSpec.
//
// set initialExpression from SpeciesContextSpec.
// set diffusing
// set variable (only if "Constant" or "Function", else leave it as null)
//
speciesContextMappingList.removeAllElements();
SpeciesContextSpec[] speciesContextSpecs = simContext.getReactionContext().getSpeciesContextSpecs();
for (int i = 0; i < speciesContextSpecs.length; i++) {
SpeciesContextSpec scs = speciesContextSpecs[i];
SpeciesContextMapping scm = new SpeciesContextMapping(scs.getSpeciesContext());
scm.setPDERequired(simContext.isPDERequired(scs.getSpeciesContext()));
scm.setHasEventAssignment(simContext.hasEventAssignment(scs.getSpeciesContext()));
scm.setHasHybridReaction(false);
for (ReactionSpec reactionSpec : getSimulationContext().getReactionContext().getReactionSpecs()) {
if (!reactionSpec.isExcluded() && reactionSpec.hasHybrid(getSimulationContext(), scs.getSpeciesContext())) {
scm.setHasHybridReaction(true);
}
}
// scm.setAdvecting(isAdvectionRequired(scs.getSpeciesContext()));
if (scs.isConstant()) {
Expression initCond = scs.getInitialConditionParameter() == null ? null : scs.getInitialConditionParameter().getExpression();
scm.setDependencyExpression(initCond);
// //
// // determine if a Function is necessary
// //
// boolean bNeedFunction = false;
// if (initCond.getSymbols()!=null){
// bNeedFunction = true;
// }
// if (bNeedFunction){
// scm.setVariable(new Function(scm.getSpeciesContext().getName(),initCond));
// }else{
// scm.setVariable(new Constant(scm.getSpeciesContext().getName(),initCond));
// }
}
//
// test if participant in fast reaction step, request elimination if possible
//
scm.setFastParticipant(false);
ReactionSpec[] reactionSpecs = simContext.getReactionContext().getReactionSpecs();
for (int j = 0; j < reactionSpecs.length; j++) {
ReactionSpec reactionSpec = reactionSpecs[j];
if (reactionSpec.isExcluded()) {
continue;
}
ReactionStep rs = reactionSpec.getReactionStep();
if (rs instanceof SimpleReaction && rs.countNumReactionParticipants(scs.getSpeciesContext()) > 0) {
if (reactionSpec.isFast()) {
scm.setFastParticipant(true);
}
}
}
speciesContextMappingList.addElement(scm);
}
}
Aggregations