use of cbit.vcell.model.Feature in project vcell by virtualcell.
the class XmlReader method getMembrane.
/**
* This method returns a Membrane object from a XML element.
* Creation date: (4/4/2001 4:17:32 PM)
* @return cbit.vcell.model.Membrane
* @param param org.jdom.Element
*/
private Membrane getMembrane(Model model, Element param, List<Structure> featureList) throws XmlParseException {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
Membrane newmembrane = null;
// retrieve the key if there is one
KeyValue key = null;
String stringkey = param.getAttributeValue(XMLTags.KeyValueAttrTag);
if (stringkey != null && stringkey.length() > 0 && this.readKeysFlag) {
key = new KeyValue(stringkey);
}
// try to create new Membrane named "name"
try {
newmembrane = new Membrane(key, name);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("An error occurred while trying to create the Membrane object " + name, e);
}
// set inside feature
String infeaturename = unMangle(param.getAttributeValue(XMLTags.InsideFeatureTag));
String outfeaturename = unMangle(param.getAttributeValue(XMLTags.OutsideFeatureTag));
String posFeatureName = unMangle(param.getAttributeValue(XMLTags.PositiveFeatureTag));
String negFeatureName = unMangle(param.getAttributeValue(XMLTags.NegativeFeatureTag));
Feature infeatureref = null;
Feature outfeatureref = null;
Feature posFeature = null;
Feature negFeature = null;
for (Structure s : featureList) {
String sname = s.getName();
if (sname.equals(infeaturename)) {
infeatureref = (Feature) s;
}
if (sname.equals(outfeaturename)) {
outfeatureref = (Feature) s;
}
if (sname.equals(posFeatureName)) {
posFeature = (Feature) s;
}
if (sname.equals(negFeatureName)) {
negFeature = (Feature) s;
}
}
// set inside and outside features
if (infeatureref != null) {
model.getStructureTopology().setInsideFeature(newmembrane, infeatureref);
}
if (outfeatureref != null) {
model.getStructureTopology().setOutsideFeature(newmembrane, outfeatureref);
}
// set positive & negative features
if (posFeature != null) {
model.getElectricalTopology().setPositiveFeature(newmembrane, posFeature);
}
if (negFeature != null) {
model.getElectricalTopology().setNegativeFeature(newmembrane, negFeature);
}
// set MemVoltName
if (param.getAttribute(XMLTags.MemVoltNameTag) == null) {
throw new XmlParseException("Error reading membrane Voltage Name!");
}
String memvoltName = unMangle(param.getAttributeValue(XMLTags.MemVoltNameTag));
try {
newmembrane.getMembraneVoltage().setName(memvoltName);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("Error setting the membrane Voltage Name", e);
}
return newmembrane;
}
use of cbit.vcell.model.Feature 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.model.Feature in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method identifies if the structure as a parameter is a Feature or a Membrane, and then calls the respective getXML method.
* Creation date: (2/22/2001 6:31:04 PM)
* @return Element
* @param param cbit.vcell.model.Structure
* @param model cbit.vcell.model.Model
*/
private Element getXML(Structure structure, Model model) throws XmlParseException {
Element structureElement = null;
StructureTopology structTopology = model.getStructureTopology();
if (structure instanceof Feature) {
// This is a Feature
structureElement = new Element(XMLTags.FeatureTag);
} else if (structure instanceof Membrane) {
// process a Membrane
structureElement = new Element(XMLTags.MembraneTag);
// add specific attributes
Feature insideFeature = structTopology.getInsideFeature((Membrane) structure);
if (insideFeature != null) {
structureElement.setAttribute(XMLTags.InsideFeatureTag, mangle(insideFeature.getName()));
}
Feature outsideFeature = structTopology.getOutsideFeature((Membrane) structure);
if (outsideFeature != null) {
structureElement.setAttribute(XMLTags.OutsideFeatureTag, mangle(outsideFeature.getName()));
}
// positive & negative features for electrical topology
ElectricalTopology electricalTopology = model.getElectricalTopology();
Feature positiveFeature = electricalTopology.getPositiveFeature((Membrane) structure);
if (positiveFeature != null) {
structureElement.setAttribute(XMLTags.PositiveFeatureTag, mangle(positiveFeature.getName()));
}
Feature negativeFeature = electricalTopology.getNegativeFeature((Membrane) structure);
if (negativeFeature != null) {
structureElement.setAttribute(XMLTags.NegativeFeatureTag, mangle(negativeFeature.getName()));
}
structureElement.setAttribute(XMLTags.MemVoltNameTag, mangle(((Membrane) structure).getMembraneVoltage().getName()));
} else {
throw new XmlParseException("An unknown type of structure was found:" + structure.getClass().getName());
}
// add attributes
structureElement.setAttribute(XMLTags.NameAttrTag, mangle(structure.getName()));
// If the keyFlag is on, print Keys
if (structure.getKey() != null && this.printKeysFlag) {
structureElement.setAttribute(XMLTags.KeyValueAttrTag, structure.getKey().toString());
}
return structureElement;
}
use of cbit.vcell.model.Feature in project vcell by virtualcell.
the class SpeciesContextSpec method initializeForSpatial.
public void initializeForSpatial() {
if (getDiffusionParameter() != null && getDiffusionParameter().getExpression() != null && getDiffusionParameter().getExpression().isZero()) {
Expression e = null;
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition micronsqpersecond = modelUnitSystem.getInstance("um2.s-1");
if (speciesContext.getStructure() instanceof Feature) {
RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(10, getDiffusionParameter().getUnitDefinition()));
e = new Expression(rn.doubleValue());
} else if (speciesContext.getStructure() instanceof Membrane) {
RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(0.1, getDiffusionParameter().getUnitDefinition()));
e = new Expression(rn.doubleValue());
} else {
RationalNumber rn = RationalNumber.getApproximateFraction(micronsqpersecond.convertTo(1.0, getDiffusionParameter().getUnitDefinition()));
e = new Expression(rn.doubleValue());
}
try {
getDiffusionParameter().setExpression(e);
} catch (ExpressionBindingException e1) {
e1.printStackTrace();
throw new RuntimeException("Error while initializing diffusion rate, " + e1.getMessage());
}
}
}
use of cbit.vcell.model.Feature in project vcell by virtualcell.
the class SpeciesContextSpec method hasTransport.
public boolean hasTransport() {
if (isConstant() || isWellMixed() || simulationContext == null || simulationContext.getGeometry() == null || simulationContext.getGeometry().getDimension() == 0) {
return false;
}
int dimension = simulationContext.getGeometry().getDimension();
SpeciesContext speciesContext = getSpeciesContext();
if (speciesContext.getStructure() instanceof Membrane) {
if (dimension > 1 && !getDiffusionParameter().getExpression().isZero()) {
return true;
}
} else if (speciesContext.getStructure() instanceof Feature) {
if (!getDiffusionParameter().getExpression().isZero()) {
return true;
}
if (getVelocityXParameter().getExpression() != null && !getVelocityXParameter().getExpression().isZero()) {
return true;
}
SpatialQuantity[] velX_quantities = getVelocityQuantities(QuantityComponent.X);
if (velX_quantities.length > 0) {
return true;
}
if (dimension > 1) {
if (getVelocityYParameter().getExpression() != null && !getVelocityYParameter().getExpression().isZero()) {
return true;
}
if (dimension > 2) {
if (getVelocityZParameter().getExpression() != null && !getVelocityZParameter().getExpression().isZero()) {
return true;
}
}
}
}
return false;
}
Aggregations