use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class XmlReader method getMicroscopeMeasurement.
public void getMicroscopeMeasurement(Element element, SimulationContext simContext) {
MicroscopeMeasurement microscopeMeasurement = simContext.getMicroscopeMeasurement();
String name = element.getAttributeValue(XMLTags.NameAttrTag);
microscopeMeasurement.setName(name);
Element kernelElement = element.getChild(XMLTags.ConvolutionKernel, vcNamespace);
String type = kernelElement.getAttributeValue(XMLTags.TypeAttrTag);
ConvolutionKernel ck = null;
if (type.equals(XMLTags.ConvolutionKernel_Type_ProjectionZKernel)) {
ck = new ProjectionZKernel();
} else if (type.equals(XMLTags.ConvolutionKernel_Type_GaussianConvolutionKernel)) {
Element e = kernelElement.getChild(XMLTags.KernelGaussianSigmaXY, vcNamespace);
String s = e.getText();
Expression sigmaXY = unMangleExpression(s);
e = kernelElement.getChild(XMLTags.KernelGaussianSigmaZ, vcNamespace);
s = e.getText();
Expression sigmaZ = unMangleExpression(s);
ck = new GaussianConvolutionKernel(sigmaXY, sigmaZ);
}
microscopeMeasurement.setConvolutionKernel(ck);
List<Element> children = element.getChildren(XMLTags.FluorescenceSpecies, vcNamespace);
for (Element c : children) {
String speciesName = c.getAttributeValue(XMLTags.NameAttrTag);
SpeciesContext sc = simContext.getModel().getSpeciesContext(speciesName);
microscopeMeasurement.addFluorescentSpecies(sc);
}
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class XmlReader method getSimulationContextParameter.
public SimulationContextParameter getSimulationContextParameter(Element paramElement, SimulationContext simContext) {
// get its attributes : name, role and unit definition
String appParamName = unMangle(paramElement.getAttributeValue(XMLTags.NameAttrTag));
String role = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
ModelUnitSystem modelUnitSystem = simContext.getModel().getUnitSystem();
int appParamRole = -1;
if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
appParamRole = SimulationContext.ROLE_UserDefined;
} else {
throw new RuntimeException("unknown type of application parameter (not user-defined)");
}
String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
VCUnitDefinition appParamUnit = null;
if (unitSymbol != null) {
appParamUnit = modelUnitSystem.getInstance(unitSymbol);
}
// get parameter contents : expression; annotation, if any.
String appParamExpStr = paramElement.getText();
Expression appParamExp = unMangleExpression(appParamExpStr);
// String appParamAnnotation = null;
// String annotationText = paramElement.getChildText(XMLTags.AnnotationTag, vcNamespace);
// if (annotationText != null && annotationText.length() > 0) {
// appParamAnnotation = unMangle(annotationText);
// }
// create new global parameter
SimulationContextParameter newAppParam = simContext.new SimulationContextParameter(appParamName, appParamExp, appParamRole, appParamUnit);
return newAppParam;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class XmlReader method getFluxReaction.
/**
* This method returns a FluxReaction object from a XML element.
* Creation date: (3/16/2001 11:52:02 AM)
* @return cbit.vcell.model.FluxReaction
* @param param org.jdom.Element
* @throws XmlParseException
* @throws PropertyVetoException
* @throws ModelException
* @throws Exception
*/
private FluxReaction getFluxReaction(Element param, Model model) throws XmlParseException, PropertyVetoException {
// retrieve the key if there is one
KeyValue key = null;
String keystring = param.getAttributeValue(XMLTags.KeyValueAttrTag);
if (keystring != null && keystring.length() > 0 && this.readKeysFlag) {
key = new KeyValue(keystring);
}
// resolve reference to the Membrane
String structureName = unMangle(param.getAttributeValue(XMLTags.StructureAttrTag));
Membrane structureref = (Membrane) model.getStructure(structureName);
if (structureref == null) {
throw new XmlParseException("The membrane " + structureName + " could not be resolved in the dictionnary!");
}
// -- Instantiate new FluxReaction --
FluxReaction fluxreaction = 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 {
fluxreaction = new FluxReaction(model, structureref, key, name, bReversible);
fluxreaction.setModel(model);
} catch (Exception e) {
e.printStackTrace();
throw new XmlParseException("An exception occurred while trying to create the FluxReaction " + name, e);
}
// resolve reference to the fluxCarrier
if (param.getAttribute(XMLTags.FluxCarrierAttrTag) != null) {
String speciesname = unMangle(param.getAttributeValue(XMLTags.FluxCarrierAttrTag));
Species specieref = model.getSpecies(speciesname);
if (specieref != null) {
Feature insideFeature = model.getStructureTopology().getInsideFeature(structureref);
try {
if (insideFeature != null) {
SpeciesContext insideSpeciesContext = model.getSpeciesContext(specieref, insideFeature);
fluxreaction.addProduct(insideSpeciesContext, 1);
}
Feature outsideFeature = model.getStructureTopology().getOutsideFeature(structureref);
if (outsideFeature != null) {
SpeciesContext outsideSpeciesContext = model.getSpeciesContext(specieref, outsideFeature);
fluxreaction.addReactant(outsideSpeciesContext, 1);
}
} catch (ModelException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e.getMessage());
}
}
}
// Annotation
// String rsAnnotation = null;
// String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
// if (annotationText!=null && annotationText.length()>0) {
// rsAnnotation = unMangle(annotationText);
// }
// fluxreaction.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)) {
fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_ELECTRICAL_ONLY);
} else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularAndElectrical)) {
fluxreaction.setPhysicsOptions(FluxReaction.PHYSICS_MOLECULAR_AND_ELECTRICAL);
} else if (fluxOptionString.equals(XMLTags.FluxOptionMolecularOnly)) {
fluxreaction.setPhysicsOptions(FluxReaction.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, if any
try {
Iterator<Element> iterator = param.getChildren(XMLTags.ReactantTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
// Add Reactant to this SimpleReaction
fluxreaction.addReactionParticipant(getReactant(temp, fluxreaction, model));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a reactant to the reaction " + name + " : " + e.getMessage());
}
// Add Products, if any
try {
Iterator<Element> iterator = param.getChildren(XMLTags.ProductTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
// Add Product to this simplereaction
fluxreaction.addReactionParticipant(getProduct(temp, fluxreaction, model));
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error adding a product to the reaction " + name + " : " + e.getMessage());
}
// Add Catalyst(Modifiers) (if there are)
Iterator<Element> iterator = param.getChildren(XMLTags.CatalystTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element temp = iterator.next();
fluxreaction.addReactionParticipant(getCatalyst(temp, fluxreaction, model));
}
// Add Kinetics
fluxreaction.setKinetics(getKinetics(param.getChild(XMLTags.KineticsTag, vcNamespace), fluxreaction, 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 = fluxreaction.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 flux reaction " + name, e);
}
return fluxreaction;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class XmlReader method getFastSystem.
/**
* This method returns a FastSystemImplicit from a XML Element.
* Creation date: (5/18/2001 2:38:56 PM)
* @return cbit.vcell.math.FastSystemImplicit
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private FastSystem getFastSystem(Element param, MathDescription mathDesc) throws XmlParseException {
// Create a new FastSystem
FastSystem fastSystem = new FastSystem(mathDesc);
// Process the FastInvariants
Iterator<Element> iterator = param.getChildren(XMLTags.FastInvariantTag, vcNamespace).iterator();
FastInvariant fastInvariant = null;
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
String temp = tempElement.getText();
try {
Expression newExp = unMangleExpression(temp);
fastInvariant = new FastInvariant(newExp);
fastSystem.addFastInvariant(fastInvariant);
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding the FastInvariant " + fastInvariant + ", to a FastSystem!" + " : ", e);
}
}
// Process the FastRate
iterator = param.getChildren(XMLTags.FastRateTag, vcNamespace).iterator();
FastRate fastRate = null;
while (iterator.hasNext()) {
Element tempElement = (Element) iterator.next();
String temp = tempElement.getText();
try {
Expression newExp = unMangleExpression(temp);
fastRate = new FastRate(newExp);
fastSystem.addFastRate(fastRate);
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException("A MathException was fired when adding the FastRate " + fastRate + ", to a FastSystem!", e);
}
}
return fastSystem;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class XmlReader method getVarIniCount.
/**
* This method return a VarIniCondition object from a XML element.
* Creation date: (7/24/2006 5:26:05 PM)
* @return cbit.vcell.math.VarIniCondition
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private VarIniCondition getVarIniCount(Element param, MathDescription md) throws XmlParseException, MathException, ExpressionException {
// retrieve values
Expression exp = unMangleExpression(param.getText());
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
Variable var = md.getVariable(name);
if (var == null) {
throw new MathFormatException("variable " + name + " not defined");
}
if (!(var instanceof StochVolVariable)) {
throw new MathFormatException("variable " + name + " not a Stochastic Volume Variable");
}
try {
VarIniCondition varIni = new VarIniCount(var, exp);
return varIni;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations