use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getVolumeParticleSpeciesPattern.
private VolumeParticleSpeciesPattern getVolumeParticleSpeciesPattern(Element param, MathDescription mathdes) throws XmlParseException {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
String location = unMangle(param.getAttributeValue(XMLTags.LocationAttrTag));
VolumeParticleSpeciesPattern var = new VolumeParticleSpeciesPattern(name, domain, location);
List<Element> molecularTypeList = param.getChildren(XMLTags.ParticleMolecularTypePatternTag, vcNamespace);
for (Element molecularType : molecularTypeList) {
ParticleMolecularTypePattern p = getParticleMolecularTypePattern(molecularType, mathdes);
var.addMolecularTypePattern(p);
}
// for (Element levelElement : levelElementList) {
return var;
}
use of cbit.vcell.math.Variable.Domain 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 cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getVolumeRegionVariable.
/**
* This method returns a VolumeRegionVariable object from a XML Element.
* Creation date: (5/16/2001 2:56:34 PM)
* @return cbit.vcell.math.VolumeRegionVariable
* @param param org.jdom.Element
*/
private VolumeRegionVariable getVolumeRegionVariable(Element param) {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
// -- create new VolumeRegionVariable object
VolumeRegionVariable volRegVariable = new VolumeRegionVariable(name, domain);
transcribeComments(param, volRegVariable);
return volRegVariable;
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getVolumeParticleObservable.
private VolumeParticleObservable getVolumeParticleObservable(Element param, VariableHash varHash) throws XmlParseException {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
String molecularTypeString = unMangle(param.getAttributeValue(XMLTags.ParticleMolecularTypePatternTag));
ObservableType observableType = ObservableType.fromString(molecularTypeString);
VolumeParticleObservable var = new VolumeParticleObservable(name, domain, observableType);
String sequenceAttr = param.getAttributeValue(XMLTags.ParticleObservableSequenceTypeAttrTag);
if (sequenceAttr != null) {
Sequence sequence = Sequence.fromString(sequenceAttr);
String sequenceLength = param.getAttributeValue(XMLTags.ParticleObservableSequenceLengthAttrTag);
var.setSequence(sequence);
if (sequence != Sequence.Multimolecular) {
var.setQuantity(Integer.parseInt(sequenceLength));
}
} else {
var.setSequence(Sequence.Multimolecular);
}
Element volumeParticleSpeciesPatternsElement = param.getChild(XMLTags.VolumeParticleSpeciesPatternsTag, vcNamespace);
List<Element> volumeParticleSpeciesPatternList = volumeParticleSpeciesPatternsElement.getChildren(XMLTags.VolumeParticleSpeciesPatternTag, vcNamespace);
for (Element volumeParticleSpeciesPattern : volumeParticleSpeciesPatternList) {
String volumeParticleSpeciesPatternName = unMangle(volumeParticleSpeciesPattern.getAttributeValue(XMLTags.NameAttrTag));
Variable v = varHash.getVariable(volumeParticleSpeciesPatternName);
if (v == null) {
throw new XmlParseException("failed to find VolumeParticleSpeciesPattern named " + volumeParticleSpeciesPatternName);
}
if (v instanceof ParticleSpeciesPattern) {
var.addParticleSpeciesPattern((ParticleSpeciesPattern) v);
} else {
throw new XmlParseException("Variable " + volumeParticleSpeciesPatternName + " is not a ParticleSpeciesPattern");
}
}
return var;
}
use of cbit.vcell.math.Variable.Domain in project vcell by virtualcell.
the class XmlReader method getVolumeParticalVariable.
private VolumeParticleVariable getVolumeParticalVariable(Element param) {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
// -- create new VolVariable object
VolumeParticleVariable var = new VolumeParticleVariable(name, domain);
transcribeComments(param, var);
return var;
}
Aggregations