Search in sources :

Example 56 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class StandaloneRuleBasedTest method checkNonspatialStochasticSimContext.

private static void checkNonspatialStochasticSimContext(SimulationContext srcSimContext, File baseDirectory, int numTrials, long bngTimeoutDuration) 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 networkGenRequirements = NetworkGenerationRequirements.getComputeFull(bngTimeoutDuration);
    bioModel.addSimulationContext(newODEApp);
    newODEApp.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenRequirements);
    bioModel.addSimulationContext(newRuleBasedApp);
    newRuleBasedApp.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenRequirements);
    srcSimContext.refreshMathDescription(new MathMappingCallbackTaskAdapter(null), networkGenRequirements);
    // Create non-spatialStoch, ODE and RuleBased sims
    Simulation nonspatialStochAppNewSim = srcSimContext.addNewSimulation(STOCH_SIM_NAME, /*SimulationOwner.DEFAULT_SIM_NAME_PREFIX*/
    new MathMappingCallbackTaskAdapter(null), networkGenRequirements);
    Simulation newODEAppNewSim = newODEApp.addNewSimulation(ODE_SIM_NAME, new MathMappingCallbackTaskAdapter(null), networkGenRequirements);
    Simulation newRuleBasedAppNewSim = newRuleBasedApp.addNewSimulation(NFS_SIM_NAME, new MathMappingCallbackTaskAdapter(null), networkGenRequirements);
    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);
        StochtestFileUtils.writeVarDiffData(new File(baseDirectory, VARDIFF_FILE), sampleDataStoch1, sampleDataStoch2);
        StochtestFileUtils.writeKolmogorovSmirnovTest(new File(baseDirectory, KS_TEST_FILE), sampleDataStoch1, sampleDataStoch2);
        StochtestFileUtils.writeChiSquareTest(new File(baseDirectory, ChiSquared_TEST_FILE), sampleDataStoch1, sampleDataStoch2);
        StochtestFileUtils.writeData(sampleDataStoch1, new File(baseDirectory, "data." + sampleDataStoch1.datasetName + ".json"));
        StochtestFileUtils.writeData(sampleDataStoch2, new File(baseDirectory, "data." + sampleDataStoch2.datasetName + ".json"));
        StochtestFileUtils.writeData(sampleDataDeterministic, new File(baseDirectory, "data." + sampleDataDeterministic.datasetName + ".json"));
    } finally {
        srcSimContext.removeSimulation(nonspatialStochAppNewSim);
        newODEApp.removeSimulation(newODEAppNewSim);
        newRuleBasedApp.removeSimulation(newRuleBasedAppNewSim);
    }
}
Also used : MathMappingCallbackTaskAdapter(cbit.vcell.mapping.MathMappingCallbackTaskAdapter) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) TimeSeriesMultitrialData(org.vcell.stochtest.TimeSeriesMultitrialData) 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) File(java.io.File) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 57 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class ClientRobot method run.

/**
 * Insert the method's description here.
 * Creation date: (3/8/01 3:04:15 PM)
 */
public void run() {
    try {
        String[] args = { host, userid, password };
        setManagerManager(cbit.vcell.client.test.ClientTester.mainInit(args, "ClientRobot", null));
        for (int i = 0; i < 10; i++) {
            log.print("Robot " + getName() + "starting loop : " + i);
            BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelFile));
            String newName = "bioModel_" + getName() + "_" + Math.random();
            log.print("Saving bioModel \"" + newName + "\"");
            getManagerManager().getDocumentManager().saveAsNew(bioModel, newName, null);
            BioModelInfo[] bioModelInfos = getManagerManager().getDocumentManager().getBioModelInfos();
            if (bioModelInfos != null && bioModelInfos.length > 0) {
                for (int j = 0; j < bioModelInfos.length; j++) {
                    log.print("bioModelInfo[" + j + "] = " + bioModelInfos[j]);
                }
            }
        }
    } catch (Throwable e) {
        log.exception(e);
    } finally {
        log.alert("Robot " + getName() + " exiting");
    }
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) BioModelInfo(org.vcell.util.document.BioModelInfo) XMLSource(cbit.vcell.xml.XMLSource)

Example 58 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class SBMLExportTest method getBiomodelByName.

static BioModel getBiomodelByName(VCellConnection vcn, String name) throws RemoteProxyException, DataAccessException, XmlParseException {
    EscapedName eName = new EscapedName(name);
    UserMetaDbServer dataServer = vcn.getUserMetaDbServer();
    for (BioModelInfo bmi : dataServer.getBioModelInfos(false)) {
        String mName = bmi.getVersion().getName();
        if (eName.matches(mName)) {
            KeyValue bioModelKey = bmi.getVersion().getVersionKey();
            BigString bioModelXML = dataServer.getBioModelXML(bioModelKey);
            BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
            return bioModel;
        }
    }
    // if not found, list what's available
    for (BioModelInfo bmi : dataServer.getBioModelInfos(false)) {
        String mName = bmi.getVersion().getName();
        System.out.println(mName);
    }
    return null;
}
Also used : UserMetaDbServer(cbit.vcell.server.UserMetaDbServer) KeyValue(org.vcell.util.document.KeyValue) BioModel(cbit.vcell.biomodel.BioModel) BioModelInfo(org.vcell.util.document.BioModelInfo) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource)

Example 59 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class RestDatabaseService method saveSimulation.

public SimulationSaveResponse saveSimulation(BiomodelSimulationSaveServerResource resource, User vcellUser, List<OverrideRepresentation> overrideRepresentations) throws PermissionException, ObjectNotFoundException, DataAccessException, SQLException, XmlParseException, PropertyVetoException, MappingException, ExpressionException {
    String simId = resource.getAttribute(VCellApiApplication.SIMULATIONID);
    KeyValue simKey = new KeyValue(simId);
    SimulationRep simRep = getSimulationRep(simKey);
    if (simRep == null) {
        throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
    }
    boolean myModel = simRep.getOwner().compareEqual(vcellUser);
    // get the bioModel
    String biomodelId = resource.getAttribute(VCellApiApplication.BIOMODELID);
    KeyValue biomodelKey = new KeyValue(biomodelId);
    BigString bioModelXML = this.databaseServerImpl.getBioModelXML(vcellUser, biomodelKey);
    BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
    // copy the simulation as new
    Simulation origSimulation = null;
    for (Simulation sim : bioModel.getSimulations()) {
        if (sim.getKey().equals(simKey)) {
            origSimulation = sim;
        }
    }
    if (origSimulation == null) {
        throw new RuntimeException("cannot find original Simulation");
    }
    SimulationContext simContext = bioModel.getSimulationContext(origSimulation);
    Simulation newUnsavedSimulation = simContext.copySimulation(origSimulation);
    // make appropriate changes
    // MATH OVERRIDES
    MathOverrides mathOverrides = new MathOverrides(newUnsavedSimulation);
    for (OverrideRepresentation overrideRep : overrideRepresentations) {
        overrideRep.applyMathOverrides(mathOverrides);
    }
    newUnsavedSimulation.setMathOverrides(mathOverrides);
    // save bioModel
    String editedBioModelXML = XmlHelper.bioModelToXML(bioModel);
    ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.databaseServerImpl);
    String modelName = bioModel.getName();
    if (!myModel) {
        modelName = modelName + "_" + Math.abs(new Random().nextInt());
    }
    String newBioModelXML = serverDocumentManager.saveBioModel(new QueryHashtable(), vcellUser, editedBioModelXML, modelName, null);
    BioModel savedBioModel = XmlHelper.XMLToBioModel(new XMLSource(newBioModelXML));
    Simulation savedSimulation = null;
    for (Simulation sim : savedBioModel.getSimulations()) {
        if (sim.getName().equals(newUnsavedSimulation.getName())) {
            savedSimulation = sim;
        }
    }
    if (savedSimulation == null) {
        throw new RuntimeException("cannot find new Simulation");
    }
    return new SimulationSaveResponse(savedBioModel, savedSimulation);
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) KeyValue(org.vcell.util.document.KeyValue) BigString(org.vcell.util.BigString) SimulationContext(cbit.vcell.mapping.SimulationContext) BigString(org.vcell.util.BigString) OverrideRepresentation(org.vcell.rest.common.OverrideRepresentation) ServerDocumentManager(cbit.vcell.modeldb.ServerDocumentManager) MathOverrides(cbit.vcell.solver.MathOverrides) Simulation(cbit.vcell.solver.Simulation) Random(java.util.Random) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource) SimulationRep(cbit.vcell.modeldb.SimulationRep)

Example 60 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class ApplicationsPropertiesPanel method setBioModel.

/**
 * Sets the speciesContext property (cbit.vcell.model.SpeciesContext) value.
 * @param speciesContext The new value for the property.
 * @see #getSpeciesContext
 */
public void setBioModel(BioModel newValue) {
    if (newValue == bioModel) {
        return;
    }
    BioModel oldValue = bioModel;
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(eventHandler);
        for (SimulationContext simContext : oldValue.getSimulationContexts()) {
            simContext.removePropertyChangeListener(eventHandler);
        }
    }
    bioModel = newValue;
    if (newValue != null) {
        newValue.addPropertyChangeListener(eventHandler);
        for (SimulationContext simContext : newValue.getSimulationContexts()) {
            simContext.addPropertyChangeListener(eventHandler);
        }
    }
    updateInterface();
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)158 SimulationContext (cbit.vcell.mapping.SimulationContext)72 Simulation (cbit.vcell.solver.Simulation)53 XMLSource (cbit.vcell.xml.XMLSource)37 KeyValue (org.vcell.util.document.KeyValue)36 MathModel (cbit.vcell.mathmodel.MathModel)33 DataAccessException (org.vcell.util.DataAccessException)29 XmlParseException (cbit.vcell.xml.XmlParseException)28 File (java.io.File)28 Model (cbit.vcell.model.Model)27 BioModelInfo (org.vcell.util.document.BioModelInfo)25 MathDescription (cbit.vcell.math.MathDescription)24 IOException (java.io.IOException)24 BigString (org.vcell.util.BigString)22 Geometry (cbit.vcell.geometry.Geometry)21 UserCancelException (org.vcell.util.UserCancelException)20 User (org.vcell.util.document.User)20 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)19 SpeciesContext (cbit.vcell.model.SpeciesContext)17 VCDocument (org.vcell.util.document.VCDocument)16