Search in sources :

Example 41 with AnnotatedFunction

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("");
}
Also used : AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 42 with AnnotatedFunction

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;
}
Also used : VariableType(cbit.vcell.math.VariableType) Expression(cbit.vcell.parser.Expression) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) FilamentSubDomain(cbit.vcell.math.FilamentSubDomain) PointSubDomain(cbit.vcell.math.PointSubDomain) Domain(cbit.vcell.math.Variable.Domain) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 43 with AnnotatedFunction

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;
}
Also used : Simulation(cbit.vcell.solver.Simulation) Element(org.jdom.Element) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 44 with AnnotatedFunction

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);
    }
}
Also used : MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) ArrayList(java.util.ArrayList) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) NetworkGenerationRequirements(cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements) XMLSource(cbit.vcell.xml.XMLSource) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 45 with AnnotatedFunction

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;
            }
    }
}
Also used : VariableType(cbit.vcell.math.VariableType) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) InconsistentDomainException(cbit.vcell.math.InconsistentDomainException) ExpressionException(cbit.vcell.parser.ExpressionException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Aggregations

AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)61 DataAccessException (org.vcell.util.DataAccessException)21 ExpressionException (cbit.vcell.parser.ExpressionException)20 Expression (cbit.vcell.parser.Expression)17 ArrayList (java.util.ArrayList)17 Simulation (cbit.vcell.solver.Simulation)15 IOException (java.io.IOException)15 OutputContext (cbit.vcell.simdata.OutputContext)14 MathException (cbit.vcell.math.MathException)12 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)12 SimulationContext (cbit.vcell.mapping.SimulationContext)11 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)10 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 FileNotFoundException (java.io.FileNotFoundException)8 Domain (cbit.vcell.math.Variable.Domain)7 VariableType (cbit.vcell.math.VariableType)7 XmlParseException (cbit.vcell.xml.XmlParseException)7 PropertyVetoException (java.beans.PropertyVetoException)7 File (java.io.File)7