use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class FunctionFileGenerator method writefunctionFile.
/**
* Insert the method's description here.
* Creation date: (1/12/2004 2:18:45 PM)
*/
public void writefunctionFile(PrintWriter out) {
out.println("##---------------------------------------------");
out.println("## " + basefileName);
out.println("##---------------------------------------------");
out.println("");
if (annotatedFunctionList != null) {
for (AnnotatedFunction f : annotatedFunctionList) {
out.print(f.getQualifiedName() + "; " + f.getExpression().infix() + "; " + f.getErrorString() + "; " + f.getFunctionType().toString() + "; " + f.isOldUserDefined());
out.println();
}
}
out.println("");
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class XmlReader method getOutputFunction.
private AnnotatedFunction getOutputFunction(Element param) throws XmlParseException {
// get attributes
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String temp = param.getText();
Expression exp = unMangleExpression(temp);
String errStr = unMangle(param.getAttributeValue(XMLTags.ErrorStringTag));
VariableType funcType = VariableType.UNKNOWN;
String funcTypeAttr = param.getAttributeValue(XMLTags.FunctionTypeTag);
if (funcTypeAttr != null) {
String funcTypeStr = unMangle(funcTypeAttr);
funcType = VariableType.getVariableTypeFromVariableTypeName(funcTypeStr);
}
// -- create new AnnotatedFunction --
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
AnnotatedFunction function = new AnnotatedFunction(name, exp, domain, errStr, funcType, FunctionCategory.OUTPUTFUNCTION);
return function;
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method returns the XML representation of a MathModel.
* Creation date: (3/28/2001 12:27:28 PM)
* @return Element
* @param param cbit.vcell.mathmodel.MathModel
*/
public Element getXML(MathModel param) throws XmlParseException {
Element mathmodel = new Element(XMLTags.MathModelTag);
// Add Attributes
String name = param.getName();
mathmodel.setAttribute(XMLTags.NameAttrTag, mangle(name));
// add Annotation
if (param.getDescription() != null && param.getDescription().length() > 0) {
Element annotationElem = new Element(XMLTags.AnnotationTag);
annotationElem.setText(mangle(param.getDescription()));
mathmodel.addContent(annotationElem);
}
// Add Geometry
try {
mathmodel.addContent(getXML(param.getMathDescription().getGeometry()));
} catch (XmlParseException e) {
e.printStackTrace();
throw new XmlParseException("A problem occurred when trying to process the geometry!", e);
}
// Add Mathdescription
mathmodel.addContent(getXML(param.getMathDescription()));
// Add output functions
if (param.getOutputFunctionContext() != null) {
ArrayList<AnnotatedFunction> outputFunctions = param.getOutputFunctionContext().getOutputFunctionsList();
if (outputFunctions != null && outputFunctions.size() > 0) {
// get output functions
mathmodel.addContent(getXML(outputFunctions));
}
}
// Add Simulations
cbit.vcell.solver.Simulation[] arraysim = param.getSimulations();
if (arraysim != null) {
for (int i = 0; i < arraysim.length; i++) {
mathmodel.addContent(getXML(arraysim[i]));
}
}
// Add Metadata (if there is)
if (param.getVersion() != null) {
mathmodel.addContent(getXML(param.getVersion(), param.getName(), param.getDescription()));
}
// MIRIAMHelper.addToSBMLAnnotation(mathmodel, param.getMIRIAMAnnotation(), true);
return mathmodel;
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class RuleBasedTest method checkNonspatialStochasticSimContext.
private static void checkNonspatialStochasticSimContext(SimulationContext srcSimContext, File baseDirectory, int numTrials) throws Exception {
if (!srcSimContext.getApplicationType().equals(Application.NETWORK_STOCHASTIC) || srcSimContext.getGeometry().getDimension() != 0) {
throw new RuntimeException("simContext is of type " + srcSimContext.getApplicationType() + " and geometry dimension of " + srcSimContext.getGeometry().getDimension() + ", expecting nonspatial stochastic");
}
BioModel origBioModel = srcSimContext.getBioModel();
BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(XmlHelper.bioModelToXML(origBioModel)));
bioModel.refreshDependencies();
// create ODE and RuleBased
SimulationContext newODEApp = SimulationContext.copySimulationContext(srcSimContext, "aUniqueNewODEApp", false, Application.NETWORK_DETERMINISTIC);
SimulationContext newRuleBasedApp = SimulationContext.copySimulationContext(srcSimContext, "aUniqueNewRuleBasedApp", false, Application.RULE_BASED_STOCHASTIC);
newODEApp.setBioModel(bioModel);
newRuleBasedApp.setBioModel(bioModel);
ArrayList<AnnotatedFunction> outputFunctionsList = srcSimContext.getOutputFunctionContext().getOutputFunctionsList();
// OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
newODEApp.getOutputFunctionContext().setOutputFunctions(outputFunctionsList);
newRuleBasedApp.getOutputFunctionContext().setOutputFunctions(outputFunctionsList);
NetworkGenerationRequirements networkGenerationRequirements = NetworkGenerationRequirements.AllowTruncatedStandardTimeout;
bioModel.addSimulationContext(newODEApp);
newODEApp.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
bioModel.addSimulationContext(newRuleBasedApp);
newRuleBasedApp.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
srcSimContext.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
// Create non-spatialStoch, ODE and RuleBased sims
Simulation nonspatialStochAppNewSim = srcSimContext.addNewSimulation(STOCH_SIM_NAME, /*SimulationOwner.DEFAULT_SIM_NAME_PREFIX*/
new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
Simulation newODEAppNewSim = newODEApp.addNewSimulation(ODE_SIM_NAME, new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
Simulation newRuleBasedAppNewSim = newRuleBasedApp.addNewSimulation(NFS_SIM_NAME, new MathMappingCallbackTaskAdapter(null), networkGenerationRequirements);
nonspatialStochAppNewSim.setSimulationOwner(srcSimContext);
newODEAppNewSim.setSimulationOwner(newODEApp);
newRuleBasedAppNewSim.setSimulationOwner(newRuleBasedApp);
try {
bioModel.getModel().getSpeciesContexts();
ArrayList<String> varNameList = new ArrayList<String>();
for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
varNameList.add(scs.getSpeciesContext().getName());
}
String[] varNames = varNameList.toArray(new String[0]);
OutputTimeSpec outputTimeSpec = nonspatialStochAppNewSim.getSolverTaskDescription().getOutputTimeSpec();
ArrayList<Double> sampleTimeList = new ArrayList<Double>();
if (outputTimeSpec instanceof UniformOutputTimeSpec) {
double endingTime = nonspatialStochAppNewSim.getSolverTaskDescription().getTimeBounds().getEndingTime();
double dT = ((UniformOutputTimeSpec) outputTimeSpec).getOutputTimeStep();
int currTimeIndex = 0;
while (currTimeIndex * dT <= (endingTime + 1e-8)) {
sampleTimeList.add(currTimeIndex * dT);
currTimeIndex++;
}
}
double[] sampleTimes = new double[sampleTimeList.size()];
for (int i = 0; i < sampleTimes.length; i++) {
sampleTimes[i] = sampleTimeList.get(i);
}
TimeSeriesMultitrialData sampleDataStoch1 = new TimeSeriesMultitrialData("stochastic1", varNames, sampleTimes, numTrials);
TimeSeriesMultitrialData sampleDataStoch2 = new TimeSeriesMultitrialData("stochastic2", varNames, sampleTimes, numTrials);
TimeSeriesMultitrialData sampleDataDeterministic = new TimeSeriesMultitrialData("determinstic", varNames, sampleTimes, 1);
runsolver(nonspatialStochAppNewSim, baseDirectory, numTrials, sampleDataStoch1);
runsolver(newODEAppNewSim, baseDirectory, 1, sampleDataDeterministic);
runsolver(newRuleBasedAppNewSim, baseDirectory, numTrials, sampleDataStoch2);
writeVarDiffData(baseDirectory, sampleDataStoch1, sampleDataStoch2);
writeKolmogorovSmirnovTest(baseDirectory, sampleDataStoch1, sampleDataStoch2);
writeChiSquareTest(baseDirectory, sampleDataStoch1, sampleDataStoch2);
writeData(baseDirectory, sampleDataStoch1);
writeData(baseDirectory, sampleDataStoch2);
writeData(baseDirectory, sampleDataDeterministic);
} finally {
srcSimContext.removeSimulation(nonspatialStochAppNewSim);
newODEApp.removeSimulation(newODEAppNewSim);
newRuleBasedApp.removeSimulation(newRuleBasedAppNewSim);
}
}
use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.
the class OutputFunctionsListTableModel method setValueAt.
/**
* Insert the method's description here.
* Creation date: (7/12/2004 2:01:23 PM)
* @param aValue java.lang.Object
* @param rowIndex int
* @param columnIndex int
*/
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
AnnotatedFunction outputFunction = getValueAt(rowIndex);
switch(columnIndex) {
case COLUMN_OUTPUTFN_EXPRESSION:
{
try {
Expression exp = new Expression((String) aValue);
if (exp.compareEqual(outputFunction.getExpression())) {
return;
}
exp.bindExpression(outputFunctionContext);
VariableType vt = outputFunctionContext.computeFunctionTypeWRTExpression(outputFunction, exp);
if (!vt.compareEqual(outputFunction.getFunctionType())) {
}
outputFunction.setExpression(exp);
fireTableRowsUpdated(rowIndex, rowIndex);
outputFunctionContext.firePropertyChange("outputFunctions", null, outputFunctionContext.getOutputFunctionsList());
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
} catch (InconsistentDomainException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
}
break;
}
}
}
Aggregations