use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.
the class SpeciesContextSpecsTableModel method computeData.
protected List<SpeciesContextSpec> computeData() {
ArrayList<SpeciesContextSpec> allParameterList = new ArrayList<SpeciesContextSpec>();
if (getSimulationContext() != null) {
allParameterList.addAll(Arrays.asList(getSimulationContext().getReactionContext().getSpeciesContextSpecs()));
} else {
return null;
}
boolean bSearchInactive = searchText == null || searchText.length() == 0;
if (bSearchInactive) {
return allParameterList;
}
String lowerCaseSearchText = bSearchInactive ? null : searchText.toLowerCase();
ArrayList<SpeciesContextSpec> parameterList = new ArrayList<SpeciesContextSpec>();
for (SpeciesContextSpec parameter : allParameterList) {
if (bSearchInactive || parameter.getSpeciesContext().getName().toLowerCase().contains(lowerCaseSearchText)) /*|| parameter.getSpeciesContext().getStructure().getName().toLowerCase().contains(lowerCaseSearchText)*/
{
parameterList.add(parameter);
}
}
return parameterList;
}
use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.
the class SpeciesContextSpecsTableModel method getValueAt.
/**
* getValueAt method comment.
*/
public Object getValueAt(int row, int col) {
try {
SpeciesContextSpec scSpec = getValueAt(row);
ColumnType columnType = columns.get(col);
switch(columnType) {
case COLUMN_SPECIESCONTEXT:
{
return scSpec.getSpeciesContext();
}
case COLUMN_STRUCTURE:
{
return scSpec.getSpeciesContext().getStructure();
}
case COLUMN_DEPICTION:
{
return scSpec.getSpeciesContext().getSpeciesPattern();
}
case COLUMN_CLAMPED:
{
return new Boolean(scSpec.isConstant());
}
case COLUMN_WELLMIXED:
{
return (scSpec.isConstant() || scSpec.isWellMixed()) && !getSimulationContext().isStoch();
}
case COLUMN_INITIAL:
{
SpeciesContextSpecParameter initialConditionParameter = scSpec.getInitialConditionParameter();
if (initialConditionParameter != null) {
return new ScopedExpression(initialConditionParameter.getExpression(), initialConditionParameter.getNameScope(), true, true, autoCompleteSymbolFilter);
} else {
return null;
}
}
case COLUMN_DIFFUSION:
{
SpeciesContextSpecParameter diffusionParameter = scSpec.getDiffusionParameter();
if (diffusionParameter != null && !scSpec.isConstant() && scSpec.isWellMixed() != null && !scSpec.isWellMixed()) {
return new ScopedExpression(diffusionParameter.getExpression(), diffusionParameter.getNameScope(), true, true, autoCompleteSymbolFilter);
} else {
return null;
}
}
case COLUMN_FORCECONTINUOUS:
{
return new Boolean(scSpec.isForceContinuous());
}
default:
{
return null;
}
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
return null;
}
}
use of cbit.vcell.mapping.SpeciesContextSpec in project vcell by virtualcell.
the class ModelUnitConverter method createBioModelWithNewUnitSystem.
public static BioModel createBioModelWithNewUnitSystem(BioModel oldBioModel, ModelUnitSystem newUnitSystem) throws ExpressionException, XmlParseException {
// new BioModel has new unit system applied to all built-in units ... but expressions still need to be corrected (see below).
BioModel newBioModel = XmlHelper.cloneBioModelWithNewUnitSystem(oldBioModel, newUnitSystem);
Model newModel = newBioModel.getModel();
Model oldModel = oldBioModel.getModel();
for (Parameter p : newBioModel.getModel().getModelParameters()) {
convertVarsWithUnitFactors(oldBioModel.getModel(), newBioModel.getModel(), p);
}
for (ReactionStep reactionStep : newBioModel.getModel().getReactionSteps()) {
SymbolTable oldSymbolTable = oldBioModel.getModel().getReactionStep(reactionStep.getName());
SymbolTable newSymbolTable = reactionStep;
for (Parameter p : reactionStep.getKinetics().getUnresolvedParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
for (Parameter p : reactionStep.getKinetics().getKineticsParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
}
for (ReactionRule reactionRule : newBioModel.getModel().getRbmModelContainer().getReactionRuleList()) {
SymbolTable oldSymbolTable = oldBioModel.getModel().getRbmModelContainer().getReactionRule(reactionRule.getName()).getKineticLaw().getScopedSymbolTable();
SymbolTable newSymbolTable = reactionRule.getKineticLaw().getScopedSymbolTable();
for (Parameter p : reactionRule.getKineticLaw().getUnresolvedParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
for (Parameter p : reactionRule.getKineticLaw().getLocalParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
}
for (SimulationContext simContext : newBioModel.getSimulationContexts()) {
SimulationContext oldSimContext = oldBioModel.getSimulationContext(simContext.getName());
// ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
for (StructureMapping mapping : simContext.getGeometryContext().getStructureMappings()) {
Structure oldStructure = oldModel.getStructure(mapping.getStructure().getName());
StructureMapping oldMapping = oldSimContext.getGeometryContext().getStructureMapping(oldStructure);
for (Parameter p : mapping.computeApplicableParameterList()) {
convertVarsWithUnitFactors(oldMapping, mapping, p);
}
}
for (SpeciesContextSpec spec : simContext.getReactionContext().getSpeciesContextSpecs()) {
SpeciesContext oldSpeciesContext = oldModel.getSpeciesContext(spec.getSpeciesContext().getName());
SpeciesContextSpec oldSpec = oldSimContext.getReactionContext().getSpeciesContextSpec(oldSpeciesContext);
for (Parameter p : spec.computeApplicableParameterList()) {
convertVarsWithUnitFactors(oldSpec, spec, p);
}
}
for (int i = 0; i < simContext.getElectricalStimuli().length; i++) {
ElectricalStimulus newElectricalStimulus = simContext.getElectricalStimuli()[i];
ElectricalStimulus oldElectricalStimulus = oldSimContext.getElectricalStimuli()[i];
for (Parameter p : newElectricalStimulus.getParameters()) {
convertVarsWithUnitFactors(oldElectricalStimulus.getNameScope().getScopedSymbolTable(), newElectricalStimulus.getNameScope().getScopedSymbolTable(), p);
}
}
// convert events : trigger and delay parameters and event assignments
for (int i = 0; simContext.getBioEvents() != null && oldSimContext.getBioEvents() != null && i < simContext.getBioEvents().length; i++) {
BioEvent newBioEvent = simContext.getBioEvents()[i];
BioEvent oldBioEvent = oldSimContext.getBioEvent(newBioEvent.getName());
for (Parameter p : newBioEvent.getEventParameters()) {
convertVarsWithUnitFactors(oldBioEvent.getNameScope().getScopedSymbolTable(), newBioEvent.getNameScope().getScopedSymbolTable(), p);
}
// for each event assignment expression
for (int e = 0; e < newBioEvent.getEventAssignments().size(); e++) {
ScopedSymbolTable newSymbolTable = newBioEvent.getNameScope().getScopedSymbolTable();
ScopedSymbolTable oldSymbolTable = oldBioEvent.getNameScope().getScopedSymbolTable();
EventAssignment newEventAssignment = newBioEvent.getEventAssignments().get(e);
EventAssignment oldEventAssignment = oldBioEvent.getEventAssignments().get(e);
VCUnitDefinition oldTargetUnit = oldEventAssignment.getTarget().getUnitDefinition();
VCUnitDefinition newTargetUnit = newEventAssignment.getTarget().getUnitDefinition();
Expression eventAssgnExpr = newEventAssignment.getAssignmentExpression();
convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, eventAssgnExpr);
}
}
/**
* @TODO: If rate rule variable unit is TBD, we still need to handle the rate expression unit.
*/
// convert rate rules
RateRule[] rateRules = simContext.getRateRules();
if (rateRules != null && rateRules.length > 0) {
for (RateRule rateRule : rateRules) {
RateRule oldRateRule = oldSimContext.getRateRule(rateRule.getName());
ScopedSymbolTable oldSymbolTable = oldRateRule.getSimulationContext();
ScopedSymbolTable newSymbolTable = rateRule.getSimulationContext();
VCUnitDefinition oldTargetUnit = oldRateRule.getRateRuleVar().getUnitDefinition();
VCUnitDefinition newTargetUnit = rateRule.getRateRuleVar().getUnitDefinition();
Expression rateRuleExpr = rateRule.getRateRuleExpression();
convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, rateRuleExpr);
}
}
}
// end for - simulationContext
return newBioModel;
}
use of cbit.vcell.mapping.SpeciesContextSpec 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.SpeciesContextSpec 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