Search in sources :

Example 26 with XMLSource

use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.

the class ClientDocumentManager method getMathModelXML.

/**
 * Insert the method's description here.
 * Creation date: (3/29/2004 4:04:16 PM)
 * @return java.lang.String
 * @param vType cbit.sql.VersionableType
 * @param vKey cbit.sql.KeyValue
 */
private XMLHolder<MathModel> getMathModelXML(KeyValue vKey) throws DataAccessException {
    try {
        String xmlString = (String) xmlHash.get(vKey);
        if (xmlString == null) {
            xmlString = sessionManager.getUserMetaDbServer().getMathModelXML(vKey).toString();
            if (xmlString != null) {
                MathModel mathModel = XmlHelper.XMLToMathModel(new XMLSource(xmlString));
                String newXmlString = XmlHelper.mathModelToXML(mathModel);
                xmlHash.put(vKey, newXmlString);
                return new XMLHolder<MathModel>(newXmlString, mathModel);
            } else {
                throw new RuntimeException("unexpected: UserMetaDbServer.getMathModelXML() returned null");
            }
        } else {
            return new XMLHolder<MathModel>(xmlString);
        }
    } catch (ObjectNotFoundException e) {
        throw new DataAccessException("MathModel (id=" + vKey + ") does not exist. It either " + "has been deleted or its reference is outdated. Please use menu 'Server->Reconnect' to update document references.");
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw FailToLoadDocumentExc.createException(e, vKey, this);
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) BigString(org.vcell.util.BigString) XMLSource(cbit.vcell.xml.XMLSource) DataAccessException(org.vcell.util.DataAccessException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 27 with XMLSource

use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.

the class ClientDocumentManager method getGeometry.

/**
 * Insert the method's description here.
 * Creation date: (11/14/00 4:02:44 PM)
 * @return cbit.vcell.biomodel.BioModel
 * @param bioModelInfo cbit.vcell.biomodel.BioModelInfo
 */
public Geometry getGeometry(GeometryInfo geometryInfo) throws DataAccessException {
    Geometry geometry = null;
    try {
        XMLSource geomSource = new XMLSource(getGeometryXML(geometryInfo.getVersion().getVersionKey()));
        geometry = XmlHelper.XMLToGeometry(geomSource);
    } catch (XmlParseException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException(e.getMessage());
    }
    try {
        if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
            geometry.getGeometrySurfaceDescription().updateAll();
        }
    } catch (Exception e) {
        e.printStackTrace(System.out);
    // throw new DataAccessException("Geometric surface generation error:\n"+e.getMessage());
    }
    return geometry;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) XmlParseException(cbit.vcell.xml.XmlParseException) XMLSource(cbit.vcell.xml.XMLSource) DataAccessException(org.vcell.util.DataAccessException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException)

Example 28 with XMLSource

use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.

the class ClientDocumentManager method getGeometryFromDatabaseXML.

/**
 * Insert the method's description here.
 * Creation date: (9/22/2004 5:22:40 PM)
 * @return cbit.vcell.mathmodel.MathModel
 * @param mathModelXML java.lang.String
 */
private Geometry getGeometryFromDatabaseXML(String geometryXML) throws DataAccessException {
    try {
        Geometry geometry = XmlHelper.XMLToGeometry(new XMLSource(geometryXML));
        geometry.refreshDependencies();
        try {
            if (geometry.getDimension() > 0) {
                geometry.getGeometrySurfaceDescription().updateAll();
            }
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new DataAccessException("Geometric surface generation error:\n" + e.getMessage());
        }
        return geometry;
    } catch (XmlParseException e) {
        e.printStackTrace();
        throw new DataAccessException(e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) XmlParseException(cbit.vcell.xml.XmlParseException) XMLSource(cbit.vcell.xml.XMLSource) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException)

Example 29 with XMLSource

use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.

the class HybridSolverTester method runHybridTest.

public void runHybridTest(String site) {
    try {
        double[] timePoints = null;
        File mathModelFile = new File(mathModelVCMLFileName);
        XMLSource vcmlSource = new XMLSource(mathModelFile);
        MathModel mathModel = XmlHelper.XMLToMathModel(vcmlSource);
        File simDataDir = mathModelFile.getParentFile();
        Simulation sim = mathModel.getSimulations()[0];
        // run multiple trials and each run will have a simID = origSimID + i
        for (int i = 0; i < numRuns; i++) {
            System.out.println("--------------Trial No: " + (startTrialNo + i) + "----------------");
            // replace random seed
            sim.getSolverTaskDescription().getSmoldynSimulationOptions().setRandomSeed(new Integer(startTrialNo + i));
            // create sim job
            int jobIndex = startTrialNo + i;
            SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, null), 0);
            /*
				 * When you want to run the multiple trials on local uncomment the line below.
				 */
            // ResourceUtil.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
            /*
				 * When you want to run the multiple trials on server (without VCell user interface), use the next line of code 
				 * Corresponding changes should be made in the shell script runhybridtest for the location of executable on server
				 */
            FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simDataDir, false);
            fvSolver.startSolver();
            SolverStatus status = fvSolver.getSolverStatus();
            while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
                System.out.println("progress: " + (int) (fvSolver.getProgress() * 100) + "%");
                // ask status every 2 seconds
                Thread.sleep(2000);
                status = fvSolver.getSolverStatus();
            }
            if (status.getStatus() == SolverStatus.SOLVER_FINISHED) {
                // get data
                VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getVersion().getVersionKey(), sim.getVersion().getOwner());
                VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
                File hdf5File = new File(simDataDir, vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
                DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(vcSimDataID, false, null), hdf5File);
                if (i == 0) {
                    // do only one time
                    timePoints = dataProcessingOutputInfo.getVariableTimePoints();
                    for (int j = 0; j < varNames.length; j++) {
                        // row: numTimePoints, col:first col time + numRuns
                        double[][] data = new double[numRuns + 1][timePoints.length];
                        data[0] = timePoints;
                        results.add(data);
                    }
                }
                // write into results after each run
                for (int j = 0; j < varNames.length; j++) {
                    results.get(j)[i + 1] = dataProcessingOutputInfo.getVariableStatValues().get(varNames[j]);
                }
                // delete the file generated for this run
                deleteSimFiles(simDataDir, vcSimDataID);
            } else {
                throw new Exception("Sover did not finish normally." + status);
            }
        }
        // write to output file, tab delimited
        if (results != null && results.size() > 0) {
            for (int j = 0; j < varNames.length; j++) {
                File file = new File(simDataDir, "SimID_" + sim.getVersion().getVersionKey().toString() + "_" + varNames[j] + "_" + startTrialNo + ".txt");
                PrintWriter pw = new PrintWriter(file);
                double[][] data = results.get(j);
                if (data != null) {
                    for (int k = 0; k < data.length; k++) {
                        if (!bPrintTime && k == 0) {
                            continue;
                        }
                        String rowStr = (k == 0) ? "Time\t" : ("trialNo_" + (startTrialNo + k - 1) + "\t");
                        double[] rowData = data[k];
                        for (int q = 0; q < rowData.length; q++) {
                            rowStr += rowData[q] + "\t";
                        }
                        pw.println(rowStr);
                    }
                }
                pw.close();
            }
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) SimulationTask(cbit.vcell.messaging.server.SimulationTask) BigString(org.vcell.util.BigString) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) FVSolverStandalone(cbit.vcell.solvers.FVSolverStandalone) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) Simulation(cbit.vcell.solver.Simulation) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File) XMLSource(cbit.vcell.xml.XMLSource) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter)

Example 30 with XMLSource

use of cbit.vcell.xml.XMLSource in project vcell by virtualcell.

the class StochtestRunService method runOne.

public void runOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
    StochtestRun stochtestRun = StochtestDbUtils.acceptNextWaitingStochtestRun(conFactory);
    String biomodelXML = null;
    if (stochtestRun != null) {
        String networkGenProbs = null;
        try {
            User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
            ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.dbServerImpl);
            biomodelXML = serverDocumentManager.getBioModelXML(new QueryHashtable(), user, stochtestRun.stochtest.biomodelRef, true);
            BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelXML));
            bioModel.refreshDependencies();
            SimulationContext srcSimContext = null;
            for (SimulationContext sc : bioModel.getSimulationContexts()) {
                if (sc.getKey().equals(stochtestRun.stochtest.simContextRef)) {
                    srcSimContext = sc;
                }
            }
            if (srcSimContext == null) {
                throw new RuntimeException("cannot find simcontext with key=" + stochtestRun.stochtest.simContextRef);
            }
            // 
            for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
                scs.setConstant(false);
            }
            SimulationContext simContext = srcSimContext;
            StochtestMathType parentMathType = stochtestRun.parentMathType;
            StochtestMathType mathType = stochtestRun.mathType;
            if (parentMathType != mathType) {
                if (parentMathType == StochtestMathType.nonspatialstochastic && mathType == StochtestMathType.rules) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedRules", false, Application.RULE_BASED_STOCHASTIC);
                } else if (parentMathType == StochtestMathType.rules && mathType == StochtestMathType.nonspatialstochastic) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedSSA", false, Application.NETWORK_STOCHASTIC);
                } else {
                    throw new RuntimeException("unexpected copy of simcontext from " + parentMathType + " to " + mathType);
                }
                bioModel.addSimulationContext(simContext);
            }
            MathMappingCallback mathMappingCallback = new MathMappingCallback() {

                @Override
                public void setProgressFraction(float fractionDone) {
                }

                @Override
                public void setMessage(String message) {
                }

                @Override
                public boolean isInterrupted() {
                    return false;
                }
            };
            MathMapping mathMapping = simContext.createNewMathMapping(mathMappingCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
            MathDescription mathDesc = mathMapping.getMathDescription(mathMappingCallback);
            simContext.setMathDescription(mathDesc);
            if (simContext.isInsufficientIterations()) {
                networkGenProbs = "insufficientIterations";
            } else if (simContext.isInsufficientMaxMolecules()) {
                networkGenProbs = "insufficientMaxMolecules";
            }
            File baseDirectory = StochtestFileUtils.createDirFile(baseDir, stochtestRun);
            try {
                OutputTimeSpec outputTimeSpec = new UniformOutputTimeSpec(0.5);
                double endTime = 10.0;
                computeTrials(simContext, stochtestRun, baseDirectory, outputTimeSpec, endTime, numTrials);
                StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.complete, null, networkGenProbs);
            } finally {
                StochtestFileUtils.clearDir(baseDirectory);
            }
        } catch (Exception e) {
            StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.failed, e.getMessage(), networkGenProbs);
            // 
            if (biomodelXML != null) {
                XmlUtil.writeXMLStringToFile(biomodelXML, new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + ".vcml").getPath(), false);
            }
            // 
            // write exception trace to .txt file
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            e.printStackTrace(printWriter);
            printWriter.flush();
            System.out.println(stringWriter.getBuffer().toString());
            XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + "_error.txt").getPath(), false);
        }
    } else {
        System.out.println("no jobs waiting");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) MathDescription(cbit.vcell.math.MathDescription) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) ServerDocumentManager(cbit.vcell.modeldb.ServerDocumentManager) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) GeometryException(cbit.vcell.geometry.GeometryException) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) StringWriter(java.io.StringWriter) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping) XMLSource(cbit.vcell.xml.XMLSource) File(java.io.File) PrintWriter(java.io.PrintWriter)

Aggregations

XMLSource (cbit.vcell.xml.XMLSource)50 BioModel (cbit.vcell.biomodel.BioModel)37 XmlParseException (cbit.vcell.xml.XmlParseException)31 DataAccessException (org.vcell.util.DataAccessException)27 SimulationContext (cbit.vcell.mapping.SimulationContext)22 BigString (org.vcell.util.BigString)22 KeyValue (org.vcell.util.document.KeyValue)21 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)19 Simulation (cbit.vcell.solver.Simulation)18 SQLException (java.sql.SQLException)15 User (org.vcell.util.document.User)15 BioModelInfo (org.vcell.util.document.BioModelInfo)13 MathException (cbit.vcell.math.MathException)12 ExpressionException (cbit.vcell.parser.ExpressionException)12 PropertyVetoException (java.beans.PropertyVetoException)12 MappingException (cbit.vcell.mapping.MappingException)11 MathModel (cbit.vcell.mathmodel.MathModel)11 IOException (java.io.IOException)11 MathDescription (cbit.vcell.math.MathDescription)10 File (java.io.File)10