use of org.vcell.util.Token in project vcell by virtualcell.
the class CommentedBlockObject method parseBlock.
/**
* parse out VCML block after name is set
* @param mathdesc parent
* @param tokens token stream source; should be set to read beginning of block
* @throws MathException
* @throws ExpressionException
*/
protected void parseBlock(MathDescription mathdesc, CommentStringTokenizer tokens) throws MathException, ExpressionException {
String beginBlockString = tokens.nextToken();
if (!beginBlockString.equalsIgnoreCase(VCML.BeginBlock)) {
throw new MathFormatException("unexpected token " + beginBlockString + " expecting " + VCML.BeginBlock);
}
while (tokens.hasMoreTokens()) {
Token token = tokens.next();
String tokenString = token.getValue();
if (tokenString.equalsIgnoreCase(VCML.EndBlock)) {
setAfterComment(token.getAfterComment());
return;
}
parse(mathdesc, tokenString, tokens);
}
}
use of org.vcell.util.Token in project vcell by virtualcell.
the class MathDescription method read_database.
/**
* This method was created by a SmartGuide.
* @param tokens java.util.StringTokenizer
* @exception java.lang.Exception The exception description.
*/
public void read_database(CommentStringTokenizer tokens) throws MathException {
clearAll();
VariableHash varHash = new VariableHash();
try {
Token token = tokens.next();
if (token.getValue().equalsIgnoreCase(VCML.MathDescription)) {
// token = tokens.nextToken();
// setName(token);
// CHECK THIS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// if(!token.equals(argName)){
// throw new DataAccessException("MathDescription Version Name and Token Name Don't match");
// }
String tokenStr = tokens.nextToken();
if (!tokenStr.equalsIgnoreCase(VCML.BeginBlock)) {
throw new MathException("unexpected token " + tokenStr + " expecting " + VCML.BeginBlock);
}
}
while (tokens.hasMoreTokens()) {
token = tokens.next();
String tokenStr = token.getValue();
if (tokenStr.equalsIgnoreCase(VCML.EndBlock)) {
break;
}
if (tokenStr.equalsIgnoreCase(VCML.VolumeVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
VolVariable var = new VolVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
// addVariable0(outside);
continue;
}
//
if (tokenStr.equalsIgnoreCase(VCML.Task)) {
while (tokens.hasMoreTokens()) {
// toss away until end of block
tokenStr = tokens.nextToken();
if (tokenStr.equalsIgnoreCase(VCML.EndBlock)) {
break;
}
}
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.MembraneVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
MemVariable var = new MemVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.FilamentVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
FilamentVariable var = new FilamentVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.PointVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
PointVariable var = new PointVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.VolumeRegionVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
VolumeRegionVariable var = new VolumeRegionVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.MembraneRegionVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
MembraneRegionVariable var = new MembraneRegionVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.FilamentRegionVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
FilamentRegionVariable var = new FilamentRegionVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.Constant)) {
tokenStr = tokens.nextToken();
Expression exp = MathFunctionDefinitions.fixFunctionSyntax(tokens);
Constant constant = new Constant(tokenStr, exp);
transcribeComments(constant, token);
varHash.addVariable(constant);
continue;
}
if (tokenStr.equalsIgnoreCase("Parameter")) {
tokenStr = tokens.nextToken();
ParameterVariable pv = new ParameterVariable(tokenStr);
transcribeComments(pv, token);
varHash.addVariable(pv);
continue;
}
// stochastic variable
if (tokenStr.equalsIgnoreCase(VCML.StochVolVariable)) {
tokenStr = tokens.nextToken();
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
StochVolVariable var = new StochVolVariable(name);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.VolumeParticleVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
VolumeParticleVariable var = new VolumeParticleVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.MembraneParticleVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
MembraneParticleVariable var = new MembraneParticleVariable(name, domain);
transcribeComments(var, token);
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.ParticleMolecularType)) {
tokenStr = tokens.nextToken();
String name = tokenStr;
ParticleMolecularType particleMolecularType = new ParticleMolecularType(name);
particleMolecularType.read(tokens);
addParticleMolecularType(particleMolecularType);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.VolumeParticleObservable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
VolumeParticleObservable particle = new VolumeParticleObservable(name, domain, ObservableType.Molecules);
// TODO: here
particle.read(this, tokens, varHash);
varHash.addVariable(particle);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.VolumeParticleSpeciesPattern)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
// will set the locationName inside .read()
VolumeParticleSpeciesPattern var = new VolumeParticleSpeciesPattern(name, domain, null);
var.read(this, tokens);
// this is not really a variable and shouldn't be in the hash
// sadly the way we check consistency for compartments makes in necessary
varHash.addVariable(var);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.Function)) {
tokenStr = tokens.nextToken();
Expression exp = MathFunctionDefinitions.fixFunctionSyntax(tokens);
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
/**
* ---------------------------------------------------------------
* ATTENTATION: this is a quick fix for a specific user to load his model
* with a function name as "ATP/ADP". This syntax is not allowed.
*-----------------------------------------------------------------------
*/
if (name.equals("ATP/ADP")) {
name = "ATP_ADP_renamed";
System.err.print("Applying species function name change ATP/ADP to ATP_ADP for a specific user (key=2288008)");
Thread.dumpStack();
}
Function function = new Function(name, exp, domain);
transcribeComments(function, token);
varHash.addVariable(function);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.CompartmentSubDomain)) {
if (variableList.size() == 0) {
setAllVariables(varHash.getAlphabeticallyOrderedVariables());
}
CompartmentSubDomain subDomain = new CompartmentSubDomain(token, this, tokens);
addSubDomain0(subDomain);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.MembraneSubDomain)) {
if (variableList.size() == 0) {
setAllVariables(varHash.getAlphabeticallyOrderedVariables());
}
MembraneSubDomain subDomain = MembraneSubDomain.create(this, token, tokens);
addSubDomain0(subDomain);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.FilamentSubDomain)) {
if (variableList.size() == 0) {
setAllVariables(varHash.getAlphabeticallyOrderedVariables());
}
tokenStr = tokens.nextToken();
String subDomainName = tokenStr;
tokenStr = tokens.nextToken();
CompartmentSubDomain outsideCompartment = getCompartmentSubDomain(tokenStr);
if (outsideCompartment == null) {
throw new MathFormatException("defined membrane subdomain without a corresponding outside volume subdomain first");
}
FilamentSubDomain subDomain = new FilamentSubDomain(subDomainName, outsideCompartment);
subDomain.read(this, tokens);
addSubDomain0(subDomain);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.PointSubDomain)) {
if (variableList.size() == 0) {
setAllVariables(varHash.getAlphabeticallyOrderedVariables());
}
tokenStr = tokens.nextToken();
String subDomainName = tokenStr;
PointSubDomain subDomain = new PointSubDomain(subDomainName);
subDomain.parseBlock(this, tokens);
addSubDomain0(subDomain);
continue;
}
//
if (tokenStr.equalsIgnoreCase(VCML.Mesh)) {
while (tokens.hasMoreTokens()) {
// toss away until end of block
tokenStr = tokens.nextToken();
if (tokenStr.equalsIgnoreCase(VCML.EndBlock)) {
break;
}
}
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.Event)) {
if (variableList.size() == 0) {
setAllVariables(varHash.getAlphabeticallyOrderedVariables());
}
// Event event = new Event(tokenStr, this, tokens);
Event event = new Event(token, this, tokens);
eventList.add(event);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.VolumeRandomVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
RandomVariable randomVariable = new VolumeRandomVariable(name, this, tokens, domain);
transcribeComments(randomVariable, token);
varHash.addVariable(randomVariable);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.MembraneRandomVariable)) {
tokenStr = tokens.nextToken();
Domain domain = Variable.getDomainFromCombinedIdentifier(tokenStr);
String name = Variable.getNameFromCombinedIdentifier(tokenStr);
RandomVariable randomVariable = new MembraneRandomVariable(name, this, tokens, domain);
transcribeComments(randomVariable, token);
varHash.addVariable(randomVariable);
continue;
}
if (tokenStr.equalsIgnoreCase(VCML.PostProcessingBlock)) {
postProcessingBlock.read(tokens);
continue;
}
throw new MathFormatException("unexpected identifier " + tokenStr);
}
} catch (Throwable e) {
e.printStackTrace(System.out);
throw new MathException("line #" + tokens.lineIndex() + " Exception: " + e.getMessage());
}
refreshDependencies();
fireStateChanged();
}
Aggregations