use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class Kinetics method setParameterValue.
/**
* This method was created by a SmartGuide.
* @param expressionString java.lang.String
* @exception java.lang.Exception The exception description.
*/
public void setParameterValue(KineticsParameter parm, Expression exp) throws ExpressionException, PropertyVetoException {
Parameter p = getKineticsParameter(parm.getName());
if (p != parm) {
throw new RuntimeException("parameter " + parm.getName() + " not found");
}
Expression oldExpression = parm.getExpression();
boolean bBound = false;
try {
KineticsParameter[] newKineticsParameters = (KineticsParameter[]) fieldKineticsParameters.clone();
// KineticsProxyParameter newProxyParameters[] = (KineticsProxyParameter[])fieldProxyParameters.clone();
String[] symbols = exp.getSymbols();
ModelUnitSystem modelUnitSystem = getReactionStep().getModel().getUnitSystem();
for (int i = 0; symbols != null && i < symbols.length; i++) {
SymbolTableEntry ste = reactionStep.getEntry(symbols[i]);
if (ste == null) {
newKineticsParameters = (KineticsParameter[]) BeanUtils.addElement(newKineticsParameters, new KineticsParameter(symbols[i], new Expression(0.0), ROLE_UserDefined, modelUnitSystem.getInstance_TBD()));
}
}
parm.setExpression(exp);
setKineticsParameters(newKineticsParameters);
// setProxyParameters(newProxyParameters);
exp.bindExpression(reactionStep);
bBound = true;
} finally {
try {
if (!bBound) {
parm.setExpression(oldExpression);
}
cleanupParameters();
} catch (ModelException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class Model method createModelParameter.
public ModelParameter createModelParameter() {
String globalParamName = null;
int count = 0;
while (true) {
globalParamName = "g" + count;
if (getModelParameter(globalParamName) == null) {
break;
}
count++;
}
try {
ModelParameter modelParameter = new ModelParameter(globalParamName, new Expression(0), Model.ROLE_UserDefined, unitSystem.getInstance_TBD());
addModelParameter(modelParameter);
return modelParameter;
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class StochMathMapping_4_8 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.
*/
private void refreshVariables() throws MappingException {
//
// non-constant dependant variables(means rely on other contants/functions) require a function
//
Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = enum1.nextElement();
SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
if (scm.getDependencyExpression() != null && !scs.isConstant()) {
// scm.setVariable(new Function(scm.getSpeciesContext().getName(),scm.getDependencyExpression()));
scm.setVariable(null);
}
}
//
// non-constant independant variables require either a membrane or volume variable
//
enum1 = getSpeciesContextMappings();
// stochastic substance unit from modelUnitSystem
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition stochSubstanceUnit = modelUnitSystem.getStochasticSubstanceUnit();
while (enum1.hasMoreElements()) {
SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
// stochastic variable is always a function of size.
MathMapping_4_8.SpeciesCountParameter spCountParm = null;
try {
String countName = scs.getSpeciesContext().getName() + BIO_PARAM_SUFFIX_SPECIES_COUNT;
Expression countExp = new Expression(0.0);
spCountParm = addSpeciesCountParameter(countName, countExp, MathMapping_4_8.PARAMETER_ROLE_COUNT, stochSubstanceUnit, scs);
} 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.getName()), scs.getSpeciesContext());
concExp.bindExpression(this);
addSpeciesConcentrationParameter(concName, concExp, MathMapping_4_8.PARAMETER_ROLE_CONCENRATION, scs.getSpeciesContext().getUnitDefinition(), scs);
} catch (Exception e) {
e.printStackTrace();
throw new MappingException(e.getMessage());
}
if (scm.getDependencyExpression() == null && !scs.isConstant()) {
scm.setVariable(new StochVolVariable(getMathSymbol(spCountParm, getSimulationContext().getGeometryContext().getStructureMapping(scs.getSpeciesContext().getStructure()))));
mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
}
}
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class OutputOptionsPanel method checkExplicitOutputTimes.
private boolean checkExplicitOutputTimes(ExplicitOutputTimeSpec ots) {
boolean bValid = true;
double startingTime = solverTaskDescription.getTimeBounds().getStartingTime();
double endingTime = solverTaskDescription.getTimeBounds().getEndingTime();
double[] times = ((ExplicitOutputTimeSpec) ots).getOutputTimes();
if (times[0] < startingTime || times[times.length - 1] > endingTime) {
bValid = false;
String ret = PopupGenerator.showWarningDialog(OutputOptionsPanel.this, "Output times should be within [" + startingTime + "," + endingTime + "].\n\nChange ENDING TIME to " + times[times.length - 1] + "?", new String[] { UserMessage.OPTION_YES, UserMessage.OPTION_NO }, UserMessage.OPTION_YES);
if (ret.equals(UserMessage.OPTION_YES)) {
try {
solverTaskDescription.setTimeBounds(new TimeBounds(startingTime, times[times.length - 1]));
bValid = true;
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
DialogUtils.showErrorDialog(OutputOptionsPanel.this, e.getMessage());
}
}
}
if (bValid) {
getOutputTimesTextField().setBorder(UIManager.getBorder("TextField.border"));
} else {
getOutputTimesTextField().setBorder(GuiConstants.ProblematicTextFieldBorder);
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
getOutputTimesTextField().requestFocus();
}
});
}
return bValid;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class BioModel 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 SimulationContext && evt.getPropertyName().equals("mathDescription") && evt.getNewValue() != null) {
if (fieldSimulations != null) {
for (int i = 0; i < fieldSimulations.length; i++) {
if (fieldSimulations[i].getMathDescription() == evt.getOldValue()) {
try {
fieldSimulations[i].setMathDescription((MathDescription) evt.getNewValue());
} catch (PropertyVetoException e) {
System.out.println("error propagating math from SimulationContext '" + ((SimulationContext) evt.getSource()).getName() + "' to Simulation '" + fieldSimulations[i].getName());
e.printStackTrace(System.out);
}
}
}
}
}
//
if (evt.getSource() == this && evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_SIMULATIONS) && evt.getNewValue() != null) {
//
if (evt.getOldValue() != null) {
Simulation[] simulations = (Simulation[]) evt.getOldValue();
for (int i = 0; i < simulations.length; i++) {
simulations[i].removeVetoableChangeListener(this);
simulations[i].removePropertyChangeListener(this);
}
}
//
if (evt.getOldValue() != null) {
Simulation[] simulations = (Simulation[]) evt.getNewValue();
for (int i = 0; i < simulations.length; i++) {
simulations[i].addVetoableChangeListener(this);
simulations[i].addPropertyChangeListener(this);
}
}
}
if (evt.getSource() == this && evt.getPropertyName().equals(PROPERTY_NAME_SIMULATION_CONTEXTS) && evt.getNewValue() != null) {
//
if (evt.getOldValue() != null) {
SimulationContext[] simulationContexts = (SimulationContext[]) evt.getOldValue();
for (int i = 0; i < simulationContexts.length; i++) {
simulationContexts[i].removeVetoableChangeListener(this);
simulationContexts[i].removePropertyChangeListener(this);
}
}
//
if (evt.getOldValue() != null) {
SimulationContext[] simulationContexts = (SimulationContext[]) evt.getNewValue();
for (int i = 0; i < simulationContexts.length; i++) {
simulationContexts[i].addVetoableChangeListener(this);
simulationContexts[i].addPropertyChangeListener(this);
}
}
}
if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(Model.PROPERTY_NAME_SPECIES_CONTEXTS) || evt.getPropertyName().equals(Model.PROPERTY_NAME_REACTION_STEPS))) {
// remove the relationship objects if the biomodelEntity objects were removed
Set<BioModelEntityObject> removedObjects = relationshipModel.getBioModelEntityObjects();
for (SpeciesContext sc : fieldModel.getSpeciesContexts()) {
removedObjects.remove(sc);
}
for (ReactionStep rs : fieldModel.getReactionSteps()) {
removedObjects.remove(rs);
}
for (MolecularType mt : fieldModel.getRbmModelContainer().getMolecularTypeList()) {
removedObjects.remove(mt);
}
for (ReactionRule rr : fieldModel.getRbmModelContainer().getReactionRuleList()) {
removedObjects.remove(rr);
}
relationshipModel.removeRelationshipObjects(removedObjects);
}
// adjust the relationship model when a molecule gets deleted
if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST))) {
@SuppressWarnings("unchecked") List<MolecularType> oldListCopy = new ArrayList<MolecularType>((List<MolecularType>) evt.getOldValue());
@SuppressWarnings("unchecked") List<MolecularType> newList = (List<MolecularType>) evt.getNewValue();
if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
// something got deleted
oldListCopy.removeAll(newList);
for (MolecularType removedMt : oldListCopy) {
relationshipModel.removeRelationshipObject(removedMt);
}
}
}
if (evt.getSource() == fieldModel && (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST))) {
@SuppressWarnings("unchecked") List<ReactionRule> oldListCopy = new ArrayList<ReactionRule>((List<ReactionRule>) evt.getOldValue());
@SuppressWarnings("unchecked") List<ReactionRule> newList = (List<ReactionRule>) evt.getNewValue();
if (newList != null && oldListCopy != null && oldListCopy.size() > newList.size()) {
// something got deleted
oldListCopy.removeAll(newList);
for (ReactionRule removedRr : oldListCopy) {
relationshipModel.removeRelationshipObject(removedRr);
}
}
}
}
Aggregations