use of cbit.vcell.model.Kinetics.KineticsParameter in project vcell by virtualcell.
the class ApplicationConstraintsGenerator method fromApplication.
/**
* Insert the method's description here.
* Creation date: (6/26/01 8:25:55 AM)
* @return cbit.vcell.constraints.ConstraintContainerImpl
*/
public static ConstraintContainerImpl fromApplication(SimulationContext simContext) {
try {
ConstraintContainerImpl ccImpl = new ConstraintContainerImpl();
// ====================
// add physical limits
// ====================
//
// no negative concentrations
//
cbit.vcell.model.Model model = simContext.getModel();
cbit.vcell.model.SpeciesContext[] speciesContexts = model.getSpeciesContexts();
for (int i = 0; i < speciesContexts.length; i++) {
ccImpl.addSimpleBound(new SimpleBounds(speciesContexts[i].getName(), new RealInterval(0, Double.POSITIVE_INFINITY), AbstractConstraint.PHYSICAL_LIMIT, "non-negative concentration"));
}
for (int i = 0; i < speciesContexts.length; i++) {
SpeciesContextSpecParameter initParam = (simContext.getReactionContext().getSpeciesContextSpec(speciesContexts[i])).getInitialConditionParameter();
if (initParam != null) {
double initialValue = initParam.getExpression().evaluateConstant();
ccImpl.addSimpleBound(new SimpleBounds(speciesContexts[i].getName(), new RealInterval(initialValue), AbstractConstraint.MODELING_ASSUMPTION, "specified \"initialCondition\""));
}
}
// =========================
// add modeling assumptions
// =========================
//
// mass action forward and reverse rates should be non-negative
//
cbit.vcell.model.ReactionStep[] reactionSteps = model.getReactionSteps();
for (int i = 0; i < reactionSteps.length; i++) {
Kinetics kinetics = reactionSteps[i].getKinetics();
if (kinetics instanceof MassActionKinetics) {
Expression forwardRateConstraintExp = new Expression(((MassActionKinetics) kinetics).getForwardRateParameter().getExpression().infix() + ">=0");
forwardRateConstraintExp = getSteadyStateExpression(forwardRateConstraintExp);
if (!forwardRateConstraintExp.compareEqual(new Expression(1.0))) {
ccImpl.addGeneralConstraint(new GeneralConstraint(forwardRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "non-negative forward rate"));
}
Expression reverseRateConstraintExp = new Expression(((MassActionKinetics) kinetics).getReverseRateParameter().getExpression().infix() + ">=0");
reverseRateConstraintExp = getSteadyStateExpression(reverseRateConstraintExp);
if (!reverseRateConstraintExp.compareEqual(new Expression(1.0))) {
ccImpl.addGeneralConstraint(new GeneralConstraint(reverseRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "non-negative reverse rate"));
}
}
KineticsParameter authoritativeParameter = kinetics.getAuthoritativeParameter();
Expression kineticRateConstraintExp = new Expression(authoritativeParameter.getName() + "==" + authoritativeParameter.getExpression().infix());
kineticRateConstraintExp = getSteadyStateExpression(kineticRateConstraintExp);
if (!kineticRateConstraintExp.compareEqual(new Expression(1.0))) {
ccImpl.addGeneralConstraint(new GeneralConstraint(kineticRateConstraintExp, AbstractConstraint.MODELING_ASSUMPTION, "definition"));
}
}
//
for (int i = 0; i < reactionSteps.length; i++) {
Kinetics kinetics = reactionSteps[i].getKinetics();
Kinetics.KineticsParameter[] parameters = kinetics.getKineticsParameters();
for (int j = 0; j < parameters.length; j++) {
Expression exp = parameters[j].getExpression();
if (exp.getSymbols() == null || exp.getSymbols().length == 0) {
//
try {
double constantValue = exp.evaluateConstant();
RealInterval interval = new RealInterval(constantValue);
ccImpl.addSimpleBound(new SimpleBounds(parameters[j].getName(), interval, AbstractConstraint.MODELING_ASSUMPTION, "model value"));
} catch (cbit.vcell.parser.ExpressionException e) {
System.out.println("error evaluating parameter " + parameters[j].getName() + " in reaction step " + reactionSteps[i].getName());
}
} else {
Expression parameterDefinitionExp = new Expression(parameters[j].getName() + "==" + parameters[j].getExpression().infix());
parameterDefinitionExp = getSteadyStateExpression(parameterDefinitionExp);
if (!parameterDefinitionExp.compareEqual(new Expression(1.0))) {
ccImpl.addGeneralConstraint(new GeneralConstraint(parameterDefinitionExp, AbstractConstraint.MODELING_ASSUMPTION, "parameter definition"));
}
}
}
}
ccImpl.addSimpleBound(new SimpleBounds(model.getFARADAY_CONSTANT().getName(), new RealInterval(model.getFARADAY_CONSTANT().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "Faraday's constant"));
ccImpl.addSimpleBound(new SimpleBounds(model.getTEMPERATURE().getName(), new RealInterval(300), AbstractConstraint.PHYSICAL_LIMIT, "Absolute Temperature Kelvin"));
ccImpl.addSimpleBound(new SimpleBounds(model.getGAS_CONSTANT().getName(), new RealInterval(model.getGAS_CONSTANT().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "ideal gas constant"));
ccImpl.addSimpleBound(new SimpleBounds(model.getKMILLIVOLTS().getName(), new RealInterval(model.getKMILLIVOLTS().getExpression().evaluateConstant()), AbstractConstraint.PHYSICAL_LIMIT, "ideal gas constant"));
return ccImpl;
} catch (cbit.vcell.parser.ExpressionException e) {
e.printStackTrace(System.out);
return null;
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
return null;
}
}
use of cbit.vcell.model.Kinetics.KineticsParameter in project vcell by virtualcell.
the class BioModelParametersTableModel method setValueAt.
public void setValueAt(Object value, int row, int col) {
if (value == null) {
return;
}
try {
String inputValue = (String) value;
inputValue = inputValue.trim();
EditableSymbolTableEntry parameter = getValueAt(row);
switch(col) {
case COLUMN_NAME:
{
if (inputValue.length() == 0) {
return;
}
parameter.setName(inputValue);
break;
}
case COLUMN_EXPRESSION:
{
String newExpressionString = inputValue;
if (parameter instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
SpeciesContextSpec.SpeciesContextSpecParameter scsParm = (SpeciesContextSpec.SpeciesContextSpecParameter) parameter;
Expression newExp = null;
if (newExpressionString == null || newExpressionString.trim().length() == 0) {
if (scsParm.getRole() == SpeciesContextSpec.ROLE_InitialConcentration || scsParm.getRole() == SpeciesContextSpec.ROLE_DiffusionRate || scsParm.getRole() == SpeciesContextSpec.ROLE_InitialCount) {
newExp = new Expression(0.0);
}
} else {
newExp = new Expression(newExpressionString);
}
scsParm.setExpression(newExp);
} else if (parameter instanceof KineticsParameter) {
Expression exp1 = new Expression(inputValue);
Kinetics kinetics = ((KineticsParameter) parameter).getKinetics();
kinetics.setParameterValue((Kinetics.KineticsParameter) parameter, exp1);
} else {
Expression exp1 = new Expression(inputValue);
exp1.bindExpression(parameter.getNameScope().getScopedSymbolTable());
parameter.setExpression(exp1);
}
break;
}
case COLUMN_UNIT:
{
ModelUnitSystem modelUnitSystem = getModel().getUnitSystem();
if (inputValue.length() == 0) {
parameter.setUnitDefinition(modelUnitSystem.getInstance_TBD());
} else {
if (!parameter.getUnitDefinition().getSymbol().equals(inputValue)) {
parameter.setUnitDefinition(modelUnitSystem.getInstance(inputValue));
}
}
break;
}
}
} catch (Exception e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(ownerTable, e.getMessage());
}
}
use of cbit.vcell.model.Kinetics.KineticsParameter 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.Kinetics.KineticsParameter in project vcell by virtualcell.
the class XmlReader method getSimpleReaction.
/**
* This method returns a SimpleReaction object from a XML element.
* Creation date: (3/16/2001 11:52:02 AM)
* @return cbit.vcell.model.SimpleReaction
* @param param org.jdom.Element
*/
private SimpleReaction getSimpleReaction(Element param, Model model) throws XmlParseException {
// resolve reference to the structure that it belongs to.
String structureName = unMangle(param.getAttributeValue(XMLTags.StructureAttrTag));
Structure structureref = (Structure) model.getStructure(structureName);
if (structureref == null) {
throw new XmlParseException("The structure " + structureName + "could not be resolved!");
}
// try to get keValue information
String keystring = param.getAttributeValue(XMLTags.KeyValueAttrTag);
KeyValue key = null;
if (keystring != null && keystring.length() > 0 && this.readKeysFlag) {
key = new KeyValue(keystring);
}
// ---Instantiate a new Simplereaction---
SimpleReaction simplereaction = null;
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String reversibleAttributeValue = param.getAttributeValue(XMLTags.ReversibleAttrTag);
boolean bReversible = true;
if (reversibleAttributeValue != null) {
if (Boolean.TRUE.toString().equals(reversibleAttributeValue)) {
bReversible = true;
} else if (Boolean.FALSE.toString().equals(reversibleAttributeValue)) {
bReversible = false;
} else {
throw new RuntimeException("unexpected value " + reversibleAttributeValue + " for reversible flag for reaction " + name);
}
}
try {
simplereaction = new SimpleReaction(model, structureref, key, name, bReversible);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("An error occurred while trying to create the simpleReaction " + name, e);
}
// Annotation
// String rsAnnotation = null;
// String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
// if (annotationText!=null && annotationText.length()>0) {
// rsAnnotation = unMangle(annotationText);
// }
// simplereaction.setAnnotation(rsAnnotation);
// set the fluxOption
String fluxOptionString = null;
fluxOptionString = param.getAttributeValue(XMLTags.FluxOptionAttrTag);
if (fluxOptionString != null && fluxOptionString.length() > 0) {
try {
if (fluxOptionString.equals(XMLTags.FluxOptionElectricalOnly)) {
simplereaction.setPhysicsOptions(SimpleReaction.PHYSICS_ELECTRICAL_ONLY);
} else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularAndElectrical)) {
simplereaction.setPhysicsOptions(SimpleReaction.PHYSICS_MOLECULAR_AND_ELECTRICAL);
} else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularOnly)) {
simplereaction.setPhysicsOptions(SimpleReaction.PHYSICS_MOLECULAR_ONLY);
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("A propertyVetoException was fired when setting the fluxOption to the flux reaction " + name, e);
}
}
// Add Reactants
try {
Iterator<Element> iterator = param.getChildren(XMLTags.ReactantTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
// Add Reactant to this SimpleReaction
simplereaction.addReactionParticipant(getReactant(temp, simplereaction, model));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a reactant to the reaction " + name, e);
}
// Add Products
try {
Iterator<Element> iterator = param.getChildren(XMLTags.ProductTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
// Add Product to this simplereaction
simplereaction.addReactionParticipant(getProduct(temp, simplereaction, model));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a product to the reaction " + name + " : ", e);
}
// Add Catalyst(Modifiers)
try {
Iterator<Element> iterator = param.getChildren(XMLTags.CatalystTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
simplereaction.addReactionParticipant(getCatalyst(temp, simplereaction, model));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a catalyst to the reaction " + name, e);
}
// Add Kinetics
Element tempKinet = param.getChild(XMLTags.KineticsTag, vcNamespace);
if (tempKinet != null) {
simplereaction.setKinetics(getKinetics(tempKinet, simplereaction, model));
}
// set the valence (for legacy support for "chargeCarrierValence" stored with reaction).
String valenceString = null;
try {
valenceString = unMangle(param.getAttributeValue(XMLTags.FluxCarrierValenceAttrTag));
if (valenceString != null && valenceString.length() > 0) {
KineticsParameter chargeValenceParameter = simplereaction.getKinetics().getChargeValenceParameter();
if (chargeValenceParameter != null) {
chargeValenceParameter.setExpression(new Expression(Integer.parseInt(unMangle(valenceString))));
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
throw new XmlParseException("A NumberFormatException was fired when setting the (integer) valence '" + valenceString + "' (integer) to the reaction " + name, e);
}
return simplereaction;
}
use of cbit.vcell.model.Kinetics.KineticsParameter in project vcell by virtualcell.
the class ReactionPropertiesPanel method setReversible.
private void setReversible(boolean bReversible) {
reactionStep.setReversible(bReversible);
if (reactionStep.getKinetics() instanceof MassActionKinetics) {
KineticsParameter kp = reactionStep.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KReverse);
kp.setExpression(new Expression(0.0d));
}
getParameterTableModel().refreshData();
}
Aggregations