Search in sources :

Example 46 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) ParseException(java.text.ParseException) 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 47 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) ParseException(java.text.ParseException) 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 48 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) ParseException(java.text.ParseException) 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 49 with XMLSource

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

the class ClientDocumentManager method getMathModelFromDatabaseXML.

/**
 * 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 MathModel getMathModelFromDatabaseXML(XMLHolder<MathModel> mathModelXML) throws DataAccessException {
    try {
        MathModel mm = mathModelXML.getDocument();
        if (mm == null) {
            mm = XmlHelper.XMLToMathModel(new XMLSource(mathModelXML.getXmlString()));
        }
        cacheSimulations(mm.getSimulations());
        mm.refreshDependencies();
        try {
            if (mm.getMathDescription().getGeometry().getDimension() > 0 && mm.getMathDescription().getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
                mm.getMathDescription().getGeometry().getGeometrySurfaceDescription().updateAll();
            }
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new DataAccessException("Geometric surface generation error:\n" + e.getMessage());
        }
        return mm;
    } catch (XmlParseException e) {
        e.printStackTrace();
        throw new DataAccessException(e.getClass().getName() + ": " + e.getMessage());
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) XmlParseException(cbit.vcell.xml.XmlParseException) XMLSource(cbit.vcell.xml.XMLSource) ParseException(java.text.ParseException) 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 50 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)

Aggregations

XMLSource (cbit.vcell.xml.XMLSource)62 BioModel (cbit.vcell.biomodel.BioModel)48 XmlParseException (cbit.vcell.xml.XmlParseException)33 DataAccessException (org.vcell.util.DataAccessException)33 SimulationContext (cbit.vcell.mapping.SimulationContext)28 BigString (org.vcell.util.BigString)26 KeyValue (org.vcell.util.document.KeyValue)25 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)24 Simulation (cbit.vcell.solver.Simulation)22 SQLException (java.sql.SQLException)20 IOException (java.io.IOException)17 User (org.vcell.util.document.User)17 File (java.io.File)15 MathModel (cbit.vcell.mathmodel.MathModel)14 PropertyVetoException (java.beans.PropertyVetoException)14 MathException (cbit.vcell.math.MathException)13 ExpressionException (cbit.vcell.parser.ExpressionException)13 MappingException (cbit.vcell.mapping.MappingException)12 MathDescription (cbit.vcell.math.MathDescription)11 PrintWriter (java.io.PrintWriter)11