use of cbit.vcell.mapping.AssignmentRule in project vcell by virtualcell.
the class SimulationWorkspaceModelInfo method addAssignmentRuleParametersToMetaData.
private static void addAssignmentRuleParametersToMetaData(SimulationContext simulationContext, HashMap<String, DataSymbolMetadata> metaDataMap) {
if (metaDataMap != null && simulationContext.getAssignmentRules() != null) {
for (AssignmentRule ar : simulationContext.getAssignmentRules()) {
if (ar.getAssignmentRuleVar() instanceof Model.ModelParameter) {
Model.ModelParameter mp = (Model.ModelParameter) ar.getAssignmentRuleVar();
VCUnitDefinition unit = mp.getUnitDefinition();
String tooltip = "Assignment Rule Variable (ModelParameter), Function";
DataSymbolMetadata dsmd = new DataSymbolMetadata(BioModelCategoryType.Other, unit, tooltip);
metaDataMap.put(mp.getName(), dsmd);
}
}
}
}
use of cbit.vcell.mapping.AssignmentRule in project vcell by virtualcell.
the class SpeciesContextSpecsTableModel method isCellEditable.
/**
* Insert the method's description here.
* Creation date: (2/24/01 12:27:46 AM)
* @return boolean
* @param rowIndex int
* @param columnIndex int
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
SpeciesContextSpec speciesContextSpec = getValueAt(rowIndex);
ColumnType columnType = columns.get(columnIndex);
switch(columnType) {
case COLUMN_SPECIESCONTEXT:
{
return false;
}
case COLUMN_STRUCTURE:
{
return false;
}
case COLUMN_DEPICTION:
{
return false;
}
case COLUMN_CLAMPED:
{
return true;
}
case COLUMN_RULES:
{
return false;
}
case COLUMN_WELLMIXED:
{
return !speciesContextSpec.isConstant() && !getSimulationContext().isStoch();
}
case COLUMN_FORCECONTINUOUS:
{
return !speciesContextSpec.isConstant() && getSimulationContext().isStoch();
}
case COLUMN_INITIAL:
{
// RateRule rr = fieldSimulationContext.getRateRule(speciesContextSpec.getSpeciesContext());
AssignmentRule ar = fieldSimulationContext.getAssignmentRule(speciesContextSpec.getSpeciesContext());
if (/*rr != null || */
ar != null) {
return false;
}
return true;
}
case COLUMN_DIFFUSION:
{
return !speciesContextSpec.isConstant() && (!speciesContextSpec.isWellMixed() || getSimulationContext().isStoch());
}
default:
{
return false;
}
}
}
use of cbit.vcell.mapping.AssignmentRule in project vcell by virtualcell.
the class SpeciesContextSpecsTableModel method propertyChange.
/**
* This method gets called when a bound property is changed.
* @param evt A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() instanceof ReactionContext && evt.getPropertyName().equals("speciesContextSpecs")) {
updateListenersReactionContext((ReactionContext) evt.getSource(), true);
updateListenersReactionContext((ReactionContext) evt.getSource(), false);
refreshData();
}
if (evt.getSource() instanceof SpeciesContext && evt.getPropertyName().equals("name")) {
fireTableRowsUpdated(0, getRowCount() - 1);
}
if (evt.getSource() == getSimulationContext() && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_ASSIGNMENT_RULE_CHANGE)) {
AssignmentRule oldRule = (AssignmentRule) evt.getOldValue();
AssignmentRule newRule = (AssignmentRule) evt.getNewValue();
onAssignmentRuleVariableChanged(oldRule, newRule);
} else if (evt.getSource() == getSimulationContext() && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_RATE_RULE_CHANGE)) {
RateRule oldRule = (RateRule) evt.getOldValue();
RateRule newRule = (RateRule) evt.getNewValue();
onRateRuleVariableChanged(oldRule, newRule);
} else if (evt.getSource() == getSimulationContext() && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_ASSIGNMENTRULES)) {
System.out.println(evt.getPropertyName());
AssignmentRule[] oldRules = (AssignmentRule[]) evt.getOldValue();
AssignmentRule[] newRules = (AssignmentRule[]) evt.getNewValue();
if (oldRules != null && newRules != null && oldRules.length > newRules.length) {
onAssignmentRuleDelete(oldRules, newRules);
}
} else if (evt.getSource() == getSimulationContext() && evt.getPropertyName().equals(SimulationContext.PROPERTY_NAME_RATERULES)) {
System.out.println(evt.getPropertyName());
RateRule[] oldRules = (RateRule[]) evt.getOldValue();
RateRule[] newRules = (RateRule[]) evt.getNewValue();
if (oldRules != null && newRules != null && oldRules.length > newRules.length) {
onRateRuleDelete(oldRules, newRules);
}
}
if (evt.getSource() instanceof SpeciesContextSpec) {
fireTableRowsUpdated(0, getRowCount() - 1);
}
if (evt.getSource() instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
fireTableRowsUpdated(0, getRowCount() - 1);
}
if (evt.getSource() instanceof GeometryContext) {
refreshColumns();
fireTableStructureChanged();
}
}
use of cbit.vcell.mapping.AssignmentRule in project vcell by virtualcell.
the class SpeciesContextSpecsTableModel method onAssignmentRuleDelete.
private void onAssignmentRuleDelete(AssignmentRule[] oldRules, AssignmentRule[] newRules) {
System.out.println("old: " + oldRules.length + ", new: " + newRules.length);
AssignmentRule deleted = null;
for (AssignmentRule candidate : oldRules) {
boolean found = false;
for (AssignmentRule rule : newRules) {
if (candidate.getName().equals(rule.getName())) {
found = true;
break;
}
}
if (found == false) {
deleted = candidate;
break;
}
}
if (deleted == null || deleted.getSimulationContext() != fieldSimulationContext) {
return;
}
SymbolTableEntry ste = deleted.getAssignmentRuleVar();
if (ste instanceof SpeciesContext) {
SpeciesContext sc = (SpeciesContext) ste;
removeRuleVariableMark(sc, true);
}
}
use of cbit.vcell.mapping.AssignmentRule 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).
String biomodelXMLString = XmlHelper.bioModelToXML(oldBioModel);
XMLSource newXMLSource = new XMLSource(biomodelXMLString);
BioModel newBioModel = XmlHelper.XMLToBioModel(newXMLSource, true, 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);
}
Kinetics kinetics = reactionStep.getKinetics();
KineticsParameter kineticsParameter = null;
if (kinetics.getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate) != null) {
kineticsParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate);
} else if (kinetics.getKineticsParameterFromRole(Kinetics.ROLE_LumpedReactionRate) != null) {
kineticsParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_LumpedReactionRate);
} else {
throw new RuntimeException("Role 'reaction rate' or role 'lumped reaction rate' expected");
}
Expression rateExpression = kineticsParameter.getExpression();
jscl.math.Expression jsclExpression = null;
String jsclExpressionString = rateExpression.infix_JSCL();
try {
jsclExpression = jscl.math.Expression.valueOf(jsclExpressionString);
} catch (jscl.text.ParseException e) {
e.printStackTrace(System.out);
System.out.println("JSCL couldn't parse \"" + jsclExpressionString + "\"");
return null;
}
jscl.math.Generic g1 = jsclExpression.expand().simplify();
Expression newRate = new Expression(SymbolUtils.getRestoredStringJSCL(g1.toString()));
newRate.bindExpression(reactionStep);
// reactionStep.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).setExpression(newRate.flatten());
if (reactionStep.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate) != null) {
reactionStep.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).setExpression(newRate.flatten());
}
}
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);
}
}
AssignmentRule[] assignmentRules = simContext.getAssignmentRules();
if (assignmentRules != null && assignmentRules.length > 0) {
for (AssignmentRule assignmentRule : assignmentRules) {
AssignmentRule oldAssignRule = oldSimContext.getAssignmentRule(assignmentRule.getName());
ScopedSymbolTable oldSymbolTable = oldAssignRule.getSimulationContext();
ScopedSymbolTable newSymbolTable = assignmentRule.getSimulationContext();
VCUnitDefinition oldTargetUnit = oldAssignRule.getAssignmentRuleVar().getUnitDefinition();
VCUnitDefinition newTargetUnit = assignmentRule.getAssignmentRuleVar().getUnitDefinition();
Expression assignmentRuleExpr = assignmentRule.getAssignmentRuleExpression();
convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, assignmentRuleExpr);
}
}
}
// end for - simulationContext
return newBioModel;
}
Aggregations