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);
}
}
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");
}
}
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;
}
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);
}
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();
}
Aggregations