use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getBioEvents.
public BioEvent[] getBioEvents(SimulationContext simContext, Element bioEventsElement) throws XmlParseException {
Iterator<Element> bioEventsIterator = bioEventsElement.getChildren(XMLTags.BioEventTag, vcNamespace).iterator();
Vector<BioEvent> bioEventsVector = new Vector<BioEvent>();
while (bioEventsIterator.hasNext()) {
Element bEventElement = (Element) bioEventsIterator.next();
BioEvent newBioEvent = null;
String name = unMangle(bEventElement.getAttributeValue(XMLTags.NameAttrTag));
Element triggerElement = bEventElement.getChild(XMLTags.TriggerTag, vcNamespace);
if (triggerElement != null && triggerElement.getText().length() > 0) {
//
// read legacy VCell 5.3 style trigger and delay elements
//
// <Trigger>(t>3.0)</Trigger>
// <Delay UseValuesFromTriggerTime="true">3.0</Delay> [optional]
//
Expression triggerExpression = unMangleExpression(triggerElement.getText());
// read <Delay>
Expression delayDurationExpression = null;
boolean useValuesFromTriggerTime = true;
Element delayElement = bEventElement.getChild(XMLTags.DelayTag, vcNamespace);
if (delayElement != null) {
useValuesFromTriggerTime = Boolean.valueOf(delayElement.getAttributeValue(XMLTags.UseValuesFromTriggerTimeAttrTag)).booleanValue();
delayDurationExpression = unMangleExpression((delayElement.getText()));
}
newBioEvent = new BioEvent(name, TriggerType.GeneralTrigger, useValuesFromTriggerTime, simContext);
try {
newBioEvent.setParameterValue(BioEventParameterType.GeneralTriggerFunction, triggerExpression);
if (delayDurationExpression != null) {
newBioEvent.setParameterValue(BioEventParameterType.TriggerDelay, delayDurationExpression);
}
} catch (ExpressionBindingException | PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("failed to read trigger or delay expressions in bioEvent " + name + ": " + e.getMessage(), e);
}
} else if (triggerElement != null && triggerElement.getText().length() == 0) {
//
// read legacy first-pass VCell 5.4 style trigger and delay elements
//
// <Trigger>
// <TriggerParameters triggerClass="TriggerGeneral">
// (t > 500.0)
// </TriggerParameters>
// </Trigger>
// <Delay UseValuesFromTriggerTime="true">3.0</Delay> [optional]
//
final String TriggerParametersTag = "TriggerParameters";
final String TriggerClassAttrTag = "triggerClass";
final String TriggerClassAttrValue_TriggerGeneral = "TriggerGeneral";
Element triggerParametersElement = triggerElement.getChild(TriggerParametersTag, vcNamespace);
Expression triggerExpression = null;
String triggerClass = triggerParametersElement.getAttributeValue(TriggerClassAttrTag);
if (triggerClass.equals(TriggerClassAttrValue_TriggerGeneral)) {
triggerExpression = unMangleExpression(triggerParametersElement.getText());
} else {
// not general trigger (just make it never happen, user will have to edit "t > -1")
triggerExpression = Expression.relational(">", new Expression(simContext.getModel().getTIME(), simContext.getModel().getNameScope()), new Expression(-1.0));
}
// read <Delay>
Expression delayDurationExpression = null;
boolean useValuesFromTriggerTime = true;
Element delayElement = bEventElement.getChild(XMLTags.DelayTag, vcNamespace);
if (delayElement != null) {
useValuesFromTriggerTime = Boolean.valueOf(delayElement.getAttributeValue(XMLTags.UseValuesFromTriggerTimeAttrTag)).booleanValue();
delayDurationExpression = unMangleExpression((delayElement.getText()));
}
newBioEvent = new BioEvent(name, TriggerType.GeneralTrigger, useValuesFromTriggerTime, simContext);
try {
newBioEvent.setParameterValue(BioEventParameterType.GeneralTriggerFunction, triggerExpression);
if (delayDurationExpression != null) {
newBioEvent.setParameterValue(BioEventParameterType.TriggerDelay, delayDurationExpression);
}
} catch (ExpressionBindingException | PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("failed to read trigger or delay expressions in bioEvent " + name + ": " + e.getMessage(), e);
}
} else {
//
// VCell 5.4 style bioevent parameters
//
//
TriggerType triggerType = TriggerType.fromXmlName(bEventElement.getAttributeValue(XMLTags.BioEventTriggerTypeAttrTag));
boolean bUseValuesFromTriggerTime = Boolean.parseBoolean(bEventElement.getAttributeValue(XMLTags.UseValuesFromTriggerTimeAttrTag));
newBioEvent = new BioEvent(name, triggerType, bUseValuesFromTriggerTime, simContext);
Iterator<Element> paramElementIter = bEventElement.getChildren(XMLTags.ParameterTag, vcNamespace).iterator();
ArrayList<LocalParameter> parameters = new ArrayList<LocalParameter>();
boolean bHasGeneralTriggerParam = false;
while (paramElementIter.hasNext()) {
Element paramElement = paramElementIter.next();
// Get parameter attributes
String paramName = paramElement.getAttributeValue(XMLTags.NameAttrTag);
Expression exp = unMangleExpression(paramElement.getText());
String roleStr = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
BioEventParameterType parameterType = BioEventParameterType.fromRoleXmlName(roleStr);
if (parameterType == BioEventParameterType.GeneralTriggerFunction) {
bHasGeneralTriggerParam = true;
}
VCUnitDefinition unit = simContext.getModel().getUnitSystem().getInstance_TBD();
String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
if (unitSymbol != null) {
unit = simContext.getModel().getUnitSystem().getInstance(unitSymbol);
}
parameters.add(newBioEvent.createNewParameter(paramName, parameterType, exp, unit));
}
if (!bHasGeneralTriggerParam) {
parameters.add(newBioEvent.createNewParameter(BioEventParameterType.GeneralTriggerFunction.getDefaultName(), BioEventParameterType.GeneralTriggerFunction, // computed as needed
null, simContext.getModel().getUnitSystem().getInstance_DIMENSIONLESS()));
}
try {
newBioEvent.setParameters(parameters.toArray(new LocalParameter[0]));
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new XmlParseException("failed to read parameters in bioEvent " + name + ": " + e.getMessage(), e);
}
}
ArrayList<BioEvent.EventAssignment> eventAssignmentList = new ArrayList<BioEvent.EventAssignment>();
Iterator<Element> iter = bEventElement.getChildren(XMLTags.EventAssignmentTag, vcNamespace).iterator();
while (iter.hasNext()) {
Element eventAssignmentElement = iter.next();
try {
String varname = eventAssignmentElement.getAttributeValue(XMLTags.EventAssignmentVariableAttrTag);
Expression assignExp = unMangleExpression(eventAssignmentElement.getText());
SymbolTableEntry target = simContext.getEntry(varname);
BioEvent.EventAssignment eventAssignment = newBioEvent.new EventAssignment(target, assignExp);
eventAssignmentList.add(eventAssignment);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
}
try {
newBioEvent.setEventAssignmentsList(eventAssignmentList);
} catch (PropertyVetoException e1) {
e1.printStackTrace(System.out);
throw new XmlParseException(e1);
}
try {
newBioEvent.bind();
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
bioEventsVector.add(newBioEvent);
}
return ((BioEvent[]) BeanUtils.getArray(bioEventsVector, BioEvent.class));
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getSimulation.
/**
* This method returns a Simulation object from a XML element.
* Creation date: (4/26/2001 12:14:30 PM)
* @return cbit.vcell.solver.Simulation
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
Simulation getSimulation(Element param, MathDescription mathDesc) throws XmlParseException {
// retrive metadata (if any)
SimulationVersion simulationVersion = getSimulationVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
// create new simulation
Simulation simulation = null;
if (simulationVersion != null) {
simulation = new Simulation(simulationVersion, mathDesc);
} else {
simulation = new Simulation(mathDesc);
}
// set attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
try {
simulation.setName(name);
// String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
// if (annotation!=null) {
// simulation.setDescription(unMangle(annotation));
// }
// Add Annotation
String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
if (annotationText != null && annotationText.length() > 0) {
simulation.setDescription(unMangle(annotationText));
}
} catch (java.beans.PropertyVetoException e) {
throw new XmlParseException(e);
}
// Retrieve MathOverrides
simulation.setMathOverrides(getMathOverrides(param.getChild(XMLTags.MathOverridesTag, vcNamespace), simulation));
// Retrieve SolverTaskDescription
try {
simulation.setSolverTaskDescription(getSolverTaskDescription(param.getChild(XMLTags.SolverTaskDescriptionTag, vcNamespace), simulation));
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was fired when setting the SolverTaskDescroiption object to the Simulation object " + name, e);
}
Element dataProcessingInstructionsElement = param.getChild(XMLTags.DataProcessingInstructionsTag, vcNamespace);
if (dataProcessingInstructionsElement != null) {
String scriptName = dataProcessingInstructionsElement.getAttributeValue(XMLTags.DataProcessingScriptNameAttrTag);
String scriptInput = dataProcessingInstructionsElement.getText();
simulation.setDataProcessingInstructions(new DataProcessingInstructions(scriptName, scriptInput));
}
// Retrieve MeshEspecification (if any)
Element tempElement = param.getChild(XMLTags.MeshSpecTag, vcNamespace);
if (tempElement != null) {
try {
simulation.setMeshSpecification(getMeshSpecification(tempElement, mathDesc.getGeometry()));
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A ProperyVetoException was fired when setting the MeshSpecification to a new Simulation!", e);
}
}
return simulation;
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method readParameters.
private void readParameters(List<Element> parameterElements, ParameterContext parameterContext, HashMap<String, ParameterRoleEnum> roleHash, ParameterRoleEnum userDefinedRole, HashSet<String> xmlRolesTagsToIgnore, Model model) throws XmlParseException {
String contextName = parameterContext.getNameScope().getName();
try {
//
// prepopulate varHash with reserved symbols
//
VariableHash varHash = new VariableHash();
addResevedSymbols(varHash, model);
//
for (Element xmlParam : parameterElements) {
String parsedParamName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
String parsedRoleString = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
String parsedExpressionString = xmlParam.getText();
//
if (xmlRolesTagsToIgnore.contains(parsedRoleString)) {
varHash.removeVariable(parsedParamName);
continue;
}
Expression paramExp = null;
if (parsedExpressionString.trim().length() > 0) {
paramExp = unMangleExpression(parsedExpressionString);
}
if (varHash.getVariable(parsedParamName) == null) {
Domain domain = null;
varHash.addVariable(new Function(parsedParamName, paramExp, domain));
} else {
if (model.getReservedSymbolByName(parsedParamName) != null) {
varHash.removeVariable(parsedParamName);
Domain domain = null;
varHash.addVariable(new Function(parsedParamName, paramExp, domain));
}
}
//
// get the parameter for this xml role string
//
ParameterRoleEnum paramRole = roleHash.get(parsedRoleString);
if (paramRole == null) {
throw new XmlParseException("parameter '" + parsedParamName + "' has unexpected role '" + parsedRoleString + "' in '" + contextName + "'");
}
//
if (paramRole != userDefinedRole) {
LocalParameter paramWithSameRole = parameterContext.getLocalParameterFromRole(paramRole);
if (paramWithSameRole == null) {
throw new XmlParseException("can't find parameter with role '" + parsedRoleString + "' in '" + contextName + "'");
}
//
if (!paramWithSameRole.getName().equals(parsedParamName)) {
//
// first rename other parameters with same name
//
LocalParameter paramWithSameNameButDifferentRole = parameterContext.getLocalParameterFromName(parsedParamName);
if (paramWithSameNameButDifferentRole != null) {
//
// find available name
//
int n = 0;
String newName = parsedParamName + "_" + n++;
while (parameterContext.getEntry(newName) != null) {
newName = parsedParamName + "_" + n++;
}
parameterContext.renameLocalParameter(parsedParamName, newName);
}
//
// then rename parameter with correct role
//
parameterContext.renameLocalParameter(paramWithSameRole.getName(), parsedParamName);
}
}
}
//
// create unresolved parameters for all unresolved symbols
//
String unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
while (unresolvedSymbol != null) {
try {
Domain domain = null;
// will turn into an UnresolvedParameter.
varHash.addVariable(new Function(unresolvedSymbol, new Expression(0.0), domain));
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
parameterContext.addUnresolvedParameter(unresolvedSymbol);
unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
}
//
// in topological order, add parameters to model (getting units also).
// note that all pre-defined parameters already have the correct names
// here we set expressions on pre-defined parameters and add user-defined parameters
//
Variable[] sortedVariables = varHash.getTopologicallyReorderedVariables();
ModelUnitSystem modelUnitSystem = model.getUnitSystem();
for (int i = sortedVariables.length - 1; i >= 0; i--) {
if (sortedVariables[i] instanceof Function) {
Function paramFunction = (Function) sortedVariables[i];
Element xmlParam = null;
for (int j = 0; j < parameterElements.size(); j++) {
Element tempParam = (Element) parameterElements.get(j);
if (paramFunction.getName().equals(unMangle(tempParam.getAttributeValue(XMLTags.NameAttrTag)))) {
xmlParam = tempParam;
break;
}
}
if (xmlParam == null) {
// must have been an unresolved parameter
continue;
}
String symbol = xmlParam.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
VCUnitDefinition unit = null;
if (symbol != null) {
unit = modelUnitSystem.getInstance(symbol);
}
LocalParameter tempParam = parameterContext.getLocalParameterFromName(paramFunction.getName());
if (tempParam == null) {
tempParam = parameterContext.addLocalParameter(paramFunction.getName(), new Expression(0.0), userDefinedRole, unit, userDefinedRole.getDescription());
parameterContext.setParameterValue(tempParam, paramFunction.getExpression(), true);
} else {
if (tempParam.getExpression() != null) {
// if the expression is null, it should remain null.
parameterContext.setParameterValue(tempParam, paramFunction.getExpression(), true);
}
tempParam.setUnitDefinition(unit);
}
}
}
} catch (PropertyVetoException | ExpressionException | MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while setting parameters for '" + contextName + "': " + e.getMessage(), e);
}
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getRbmReactionRule.
private ReactionRule getRbmReactionRule(Element reactionRuleElement, Model newModel) throws XmlParseException {
String n = reactionRuleElement.getAttributeValue(XMLTags.NameAttrTag);
if (n == null || n.isEmpty()) {
System.out.println("XMLReader: getRbmReactionRule: name is missing.");
return null;
}
try {
boolean reversible = Boolean.valueOf(reactionRuleElement.getAttributeValue(XMLTags.RbmReactionRuleReversibleTag));
// get 1st structure if attribute missing
String structureName = reactionRuleElement.getAttributeValue(XMLTags.StructureAttrTag, newModel.getStructures()[0].getName());
Structure structure = newModel.getStructure(structureName);
ReactionRule reactionRule = new ReactionRule(newModel, n, structure, reversible);
// we ignore this, name and label are the same thing for now
String reactionRuleLabel = reactionRuleElement.getAttributeValue(XMLTags.RbmReactionRuleLabelTag);
//
// old style kinetics placed parameter values as attributes
// look for attributes named ("MassActionKf","MassActionKr","MichaelisMentenKcat","MichaelisMentenKm","SaturableKs","SaturableVmax")
String[] oldKineticsAttributes = new String[] { XMLTags.RbmMassActionKfAttrTag_DEPRECATED, XMLTags.RbmMassActionKrAttrTag_DEPRECATED, XMLTags.RbmMichaelisMentenKcatAttrTag_DEPRECATED, XMLTags.RbmMichaelisMentenKmAttrTag_DEPRECATED, XMLTags.RbmSaturableKsAttrTag_DEPRECATED, XMLTags.RbmSaturableVmaxAttrTag_DEPRECATED };
boolean bOldKineticsFound = false;
for (String oldKineticsAttribute : oldKineticsAttributes) {
if (reactionRuleElement.getAttribute(oldKineticsAttribute) != null) {
bOldKineticsFound = true;
}
}
if (bOldKineticsFound) {
readOldRbmKineticsAttributes(reactionRuleElement, reactionRule);
} else {
Element kineticsElement = reactionRuleElement.getChild(XMLTags.KineticsTag, vcNamespace);
if (kineticsElement != null) {
String kineticLawTypeString = kineticsElement.getAttributeValue(XMLTags.KineticsTypeAttrTag);
RbmKineticLaw.RateLawType rateLawType = null;
if (XMLTags.RbmKineticTypeMassAction.equals(kineticLawTypeString)) {
rateLawType = RateLawType.MassAction;
} else if (XMLTags.RbmKineticTypeMichaelisMenten.equals(kineticLawTypeString)) {
rateLawType = RateLawType.MichaelisMenten;
} else if (XMLTags.RbmKineticTypeSaturable.equals(kineticLawTypeString)) {
rateLawType = RateLawType.Saturable;
} else {
throw new RuntimeException("unexpected rate law type " + kineticLawTypeString);
}
reactionRule.setKineticLaw(new RbmKineticLaw(reactionRule, rateLawType));
List<Element> parameterElements = kineticsElement.getChildren(XMLTags.ParameterTag, vcNamespace);
HashMap<String, ParameterRoleEnum> roleHash = new HashMap<String, ParameterContext.ParameterRoleEnum>();
roleHash.put(XMLTags.RbmMassActionKfRole, RbmKineticLawParameterType.MassActionForwardRate);
roleHash.put(XMLTags.RbmMassActionKrRole, RbmKineticLawParameterType.MassActionReverseRate);
roleHash.put(XMLTags.RbmMichaelisMentenKcatRole, RbmKineticLawParameterType.MichaelisMentenKcat);
roleHash.put(XMLTags.RbmMichaelisMentenKmRole, RbmKineticLawParameterType.MichaelisMentenKm);
roleHash.put(XMLTags.RbmSaturableVmaxRole, RbmKineticLawParameterType.SaturableVmax);
roleHash.put(XMLTags.RbmSaturableKsRole, RbmKineticLawParameterType.SaturableKs);
roleHash.put(XMLTags.RbmUserDefinedRole, RbmKineticLawParameterType.UserDefined);
HashSet<String> xmlRolesToIgnore = new HashSet<String>();
xmlRolesToIgnore.add(XMLTags.RbmRuleRateRole);
ParameterContext parameterContext = reactionRule.getKineticLaw().getParameterContext();
readParameters(parameterElements, parameterContext, roleHash, RbmKineticLawParameterType.UserDefined, xmlRolesToIgnore, newModel);
}
}
Element e1 = reactionRuleElement.getChild(XMLTags.RbmReactantPatternsListTag, vcNamespace);
getRbmReactantPatternsList(e1, reactionRule, newModel);
Element e2 = reactionRuleElement.getChild(XMLTags.RbmProductPatternsListTag, vcNamespace);
getRbmProductPatternsList(e2, reactionRule, newModel);
reactionRule.checkMatchConsistency();
return reactionRule;
} catch (PropertyVetoException | ExpressionException ex) {
ex.printStackTrace(System.out);
throw new RuntimeException("failed to parse kinetics for reaction rule '" + n + "': " + ex.getMessage(), ex);
}
}
use of java.beans.PropertyVetoException in project vcell by virtualcell.
the class XmlReader method getReactionSpec.
/**
* Insert the method's description here.
* Creation date: (4/26/2001 4:13:26 PM)
* @return cbit.vcell.mapping.ReactionSpec
* @param param org.jdom.Element
*/
private ReactionSpec getReactionSpec(Element param, SimulationContext simulationContext) throws XmlParseException {
ReactionSpec reactionspec = null;
// retrieve the reactionstep reference
String reactionstepname = unMangle(param.getAttributeValue(XMLTags.ReactionStepRefAttrTag));
ReactionStep reactionstepref = (ReactionStep) simulationContext.getModel().getReactionStep(reactionstepname);
if (reactionstepref == null) {
throw new XmlParseException("The reference to the ReactionStep " + reactionstepname + ", could not be resolved!");
}
// Create the new SpeciesContextSpec
reactionspec = new ReactionSpec(reactionstepref, simulationContext);
// set the reactionMapping value
String temp = param.getAttributeValue(XMLTags.ReactionMappingAttrTag);
try {
reactionspec.setReactionMapping(temp);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A PropertyVetoException was fired when setting the reactionMapping value " + temp + ", in a reactionSpec object!", e);
}
return reactionspec;
}
Aggregations