Search in sources :

Example 56 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class CartesianMeshVtkFileWriter method getVtuVarInfos.

public VtuVarInfo[] getVtuVarInfos(VCellSimFiles vcellFiles, OutputContext outputContext, VCData vcData) throws IOException, DataAccessException, MathException {
    CartesianMeshFileReader reader = new CartesianMeshFileReader();
    CartesianMesh mesh = reader.readFromFiles(vcellFiles);
    List<String> volumeDomainNames = mesh.getVolumeDomainNames();
    List<String> membraneDomainNames = mesh.getMembraneDomainNames();
    ArrayList<String> allDomains = new ArrayList<String>();
    allDomains.addAll(volumeDomainNames);
    allDomains.addAll(membraneDomainNames);
    DataIdentifier[] dataIdentifiers = vcData.getVarAndFunctionDataIdentifiers(outputContext);
    AnnotatedFunction[] annotationFunctions = vcData.getFunctions(outputContext);
    ArrayList<VtuVarInfo> varInfos = new ArrayList<VtuVarInfo>();
    for (String domainName : allDomains) {
        VariableDomain varDomain = VariableDomain.VARIABLEDOMAIN_UNKNOWN;
        if (volumeDomainNames.contains(domainName)) {
            varDomain = VariableDomain.VARIABLEDOMAIN_VOLUME;
        } else if (membraneDomainNames.contains(domainName)) {
            varDomain = VariableDomain.VARIABLEDOMAIN_MEMBRANE;
        }
        for (DataIdentifier dataID : dataIdentifiers) {
            if (dataID.getDomain() == null || dataID.getDomain().getName().equals(domainName)) {
                boolean bMeshVar = isMeshVar(dataID);
                String expressionString = null;
                if (dataID.isFunction()) {
                    for (AnnotatedFunction f : annotationFunctions) {
                        if (f.getName().equals(dataID.getName())) {
                            expressionString = f.getExpression().infix();
                        }
                    }
                }
                varInfos.add(new VtuVarInfo(dataID.getName(), "(" + domainName + ")  " + dataID.getDisplayName(), domainName, varDomain, expressionString, DataType.CellData, bMeshVar));
            }
        }
        varInfos.add(new VtuVarInfo(GLOBAL_INDEX_VAR, "(" + domainName + ")  " + GLOBAL_INDEX_VAR, domainName, varDomain, null, DataType.CellData, true));
        varInfos.add(new VtuVarInfo(REGION_ID_VAR, "(" + domainName + ")  " + REGION_ID_VAR, domainName, varDomain, null, DataType.CellData, true));
    }
    return varInfos.toArray(new VtuVarInfo[0]);
}
Also used : CartesianMeshFileReader(org.vcell.vis.io.CartesianMeshFileReader) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) DataIdentifier(cbit.vcell.simdata.DataIdentifier) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) ArrayList(java.util.ArrayList) CartesianMesh(org.vcell.vis.vcell.CartesianMesh) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 57 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class FunctionFileCrawler method scan.

/**
 * Insert the method's description here.
 * Creation date: (2/2/01 3:40:29 PM)
 */
private void scan(File userDir, File outputDir) throws Exception {
    File outputFile = null;
    java.io.PrintWriter pw = null;
    try {
        outputFile = new File(outputDir, "FunctionFileCrawler_" + userDir.getName() + ".txt");
        pw = new java.io.PrintWriter(new java.io.FileOutputStream(outputFile));
        // 
        // file filter for *.functions files
        // 
        java.io.FilenameFilter functionFileFilter = new java.io.FilenameFilter() {

            public boolean accept(File dir, String name) {
                return name.endsWith(".functions");
            }
        };
        // find all the log files
        File[] functionFiles = userDir.listFiles(functionFileFilter);
        // loop through all the functions files
        int filesWithSpaceInNames = 0;
        for (int i = 0; i < functionFiles.length; i++) {
            File fnFile = functionFiles[i];
            if (fnFile.exists()) {
                // read the functions from the function files and and check if they have spaces
                Vector<AnnotatedFunction> annotatedFnsVector = FunctionFileGenerator.readFunctionsFile(fnFile, null);
                boolean bNameHasSpaces = false;
                for (int j = 0; j < annotatedFnsVector.size(); j++) {
                    AnnotatedFunction afn = annotatedFnsVector.elementAt(j);
                    if (afn.getName().indexOf(" ") > 0) {
                        // if function name has space, mangle the name and store the function in a different list.
                        bNameHasSpaces = true;
                        String newName = TokenMangler.fixTokenStrict(afn.getName());
                        annotatedFnsVector.set(j, new AnnotatedFunction(newName, afn.getExpression(), afn.getDomain(), afn.getErrorString(), afn.getFunctionType(), afn.getFunctionCatogery()));
                    } else {
                        annotatedFnsVector.set(j, afn);
                    }
                }
                // If function file had function(s) with space(s), need to rewrite function file
                if (bNameHasSpaces) {
                    FunctionFileGenerator ffg = new FunctionFileGenerator(fnFile.getPath(), annotatedFnsVector);
                    ffg.generateFunctionFile();
                    filesWithSpaceInNames++;
                    totalNumOfFilesModified++;
                }
            } else {
                System.err.println("Function file : " + fnFile.getName() + " does not exist.");
            }
        }
        System.out.println("NUM Files with spaces in names : " + filesWithSpaceInNames + "; NUM Files with No spaces in names : " + (functionFiles.length - filesWithSpaceInNames));
    } finally {
        if (pw != null) {
            pw.close();
        }
        if (lg.isTraceEnabled())
            lg.trace("User " + userDir.getName() + ", See " + outputFile.getAbsolutePath() + " for details");
    }
}
Also used : FunctionFileGenerator(cbit.vcell.solvers.FunctionFileGenerator) File(java.io.File) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 58 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class ServerDocumentManager method getMathModelUnresolved.

/**
 * 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
 */
// 
// this returns a MathModel that has duplicate instances of the same objects
// 
public MathModel getMathModelUnresolved(QueryHashtable dbc, User user, KeyValue mathModelKey) throws DataAccessException, java.sql.SQLException {
    // 
    // get meta data associated with MathModel
    // 
    MathModelMetaData mathModelMetaData = dbServer.getMathModelMetaData(user, mathModelKey);
    // 
    // get list of appropriate child components
    // 
    KeyValue mathDescriptionKey = mathModelMetaData.getMathKey();
    KeyValue[] simKeys = getKeyArrayFromEnumeration(mathModelMetaData.getSimulationKeys());
    MathDescription mathDescription = dbServer.getDBTopLevel().getMathDescription(dbc, user, mathDescriptionKey);
    Simulation[] simArray = new Simulation[simKeys.length];
    for (int i = 0; i < simKeys.length; i++) {
        Simulation sim = dbServer.getDBTopLevel().getSimulation(dbc, user, simKeys[i]);
        // 
        try {
            simArray[i] = (Simulation) BeanUtils.cloneSerializable(sim);
        } catch (Throwable e) {
            throw new RuntimeException("exception cloning Simulation: " + e.getMessage());
        }
        if (!simArray[i].getMathDescription().getKey().compareEqual(mathDescriptionKey)) {
            // throw new DataAccessException("simulation("+simKeys[i]+").mathDescription = "+simArray[i].getMathDescription().getKey()+", MathModel.mathDescription = "+mathDescriptionKey);
            System.out.println("ClientDocumentManager.getMathModel(), simulation(" + simKeys[i] + ").mathDescription = " + simArray[i].getMathDescription().getKey() + ", MathModel.mathDescription = " + mathDescriptionKey);
        }
    }
    // 
    // create new MathModel according to loaded MathModelMetaData
    // 
    MathModel newMathModel = new MathModel(mathModelMetaData.getVersion());
    try {
        newMathModel.setMathDescription(mathDescription);
        newMathModel.setSimulations(simArray);
        ArrayList<AnnotatedFunction> outputFunctions = mathModelMetaData.getOutputFunctions();
        if (outputFunctions != null) {
            newMathModel.getOutputFunctionContext().setOutputFunctions(outputFunctions);
        }
    } catch (java.beans.PropertyVetoException e) {
        throw new DataAccessException("PropertyVetoException caught " + e.getMessage());
    }
    // 
    try {
        newMathModel = (MathModel) BeanUtils.cloneSerializable(newMathModel);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("MathModel clone failed: " + e.getMessage());
    }
    newMathModel.refreshDependencies();
    // 
    return newMathModel;
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) KeyValue(org.vcell.util.document.KeyValue) MathDescription(cbit.vcell.math.MathDescription) MathModelMetaData(cbit.vcell.mathmodel.MathModelMetaData) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) PropertyVetoException(java.beans.PropertyVetoException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) Simulation(cbit.vcell.solver.Simulation) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 59 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class DisplayTimeSeries method displayImageTimeSeries.

public static void displayImageTimeSeries(final ImageTimeSeries<Image> imageTimeSeries, String title, WindowListener windowListener) throws ImageException, IOException {
    ISize size = imageTimeSeries.getISize();
    int dimension = (size.getZ() > 0) ? (3) : (2);
    Extent extent = imageTimeSeries.getExtent();
    Origin origin = imageTimeSeries.getAllImages()[0].getOrigin();
    // don't care ... no surfaces
    double filterCutoffFrequency = 0.5;
    VCImage vcImage = new VCImageUncompressed(null, new byte[size.getXYZ()], extent, size.getX(), size.getY(), size.getZ());
    RegionImage regionImage = new RegionImage(vcImage, dimension, extent, origin, filterCutoffFrequency);
    final CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, size, regionImage);
    final DataIdentifier dataIdentifier = new DataIdentifier("var", VariableType.VOLUME, new Domain("domain"), false, "var");
    final DataSetController dataSetController = new DataSetController() {

        @Override
        public ExportEvent makeRemoteFile(OutputContext outputContext, ExportSpecs exportSpecs) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public TimeSeriesJobResults getTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdataID, TimeSeriesJobSpec timeSeriesJobSpec) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdataID, String varName, double time) throws RemoteProxyException, DataAccessException {
            double timePoint = time;
            double[] timePoints = getDataSetTimes(vcdataID);
            int index = -1;
            for (int i = 0; i < timePoints.length; i++) {
                if (timePoint == timePoints[i]) {
                    index = i;
                    break;
                }
            }
            double[] data = imageTimeSeries.getAllImages()[index].getDoublePixels();
            PDEDataInfo pdeDataInfo = new PDEDataInfo(null, null, varName, time, 0);
            VariableType varType = VariableType.VOLUME;
            return new SimDataBlock(pdeDataInfo, data, varType);
        }

        @Override
        public boolean getParticleDataExists(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return false;
        }

        @Override
        public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdataID, double time) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public ODESimData getODEData(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public CartesianMesh getMesh(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return mesh;
        }

        @Override
        public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdataID, String variable, double time, SpatialSelection spatialSelection) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public AnnotatedFunction[] getFunctions(OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return new AnnotatedFunction[0];
        }

        @Override
        public double[] getDataSetTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return imageTimeSeries.getImageTimeStamps();
        }

        @Override
        public DataSetTimeSeries getDataSetTimeSeries(VCDataIdentifier vcdataID, String[] variableNames) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataSetMetadata getDataSetMetadata(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return new DataIdentifier[] { dataIdentifier };
        }

        @Override
        public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataOperationResults doDataOperation(DataOperation dataOperation) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public VtuFileContainer getEmptyVtuMeshFiles(VCDataIdentifier vcdataID, int timeIndex) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuMeshData(OutputContext outputContext, VCDataIdentifier vcdataID, VtuVarInfo var, double time) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public VtuVarInfo[] getVtuVarInfos(OutputContext outputContext, VCDataIdentifier vcDataIdentifier) throws DataAccessException, RemoteProxyException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public NFSimMolecularConfigurations getNFSimMolecularConfigurations(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }
    };
    DataSetControllerProvider dataSetControllerProvider = new DataSetControllerProvider() {

        @Override
        public DataSetController getDataSetController() throws DataAccessException {
            return dataSetController;
        }
    };
    VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
    OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
    VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {

        public User getOwner() {
            return new User("nouser", null);
        }

        public KeyValue getDataKey() {
            return null;
        }

        public String getID() {
            return "mydata";
        }
    };
    PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
    ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
    PDEDataViewer pdeDataViewer = new PDEDataViewer();
    JFrame jframe = new JFrame();
    jframe.setTitle(title);
    jframe.getContentPane().add(pdeDataViewer);
    jframe.setSize(1000, 600);
    jframe.setVisible(true);
    if (windowListener != null) {
        jframe.addWindowListener(windowListener);
    }
    pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
Also used : Origin(org.vcell.util.Origin) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) User(org.vcell.util.document.User) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ExportSpecs(cbit.vcell.export.server.ExportSpecs) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) VCImage(cbit.image.VCImage) PDEDataInfo(cbit.vcell.simdata.PDEDataInfo) DataSetControllerProvider(cbit.vcell.server.DataSetControllerProvider) SimDataBlock(cbit.vcell.simdata.SimDataBlock) SpatialSelection(cbit.vcell.simdata.SpatialSelection) JFrame(javax.swing.JFrame) VCDataManager(cbit.vcell.simdata.VCDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) DataOperation(cbit.vcell.simdata.DataOperation) VariableType(cbit.vcell.math.VariableType) DataSetController(cbit.vcell.server.DataSetController) VCImageUncompressed(cbit.image.VCImageUncompressed) OutputContext(cbit.vcell.simdata.OutputContext) CartesianMesh(cbit.vcell.solvers.CartesianMesh) PDEDataManager(cbit.vcell.simdata.PDEDataManager) RegionImage(cbit.vcell.geometry.RegionImage) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) Domain(cbit.vcell.math.Variable.Domain) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer)

Example 60 with AnnotatedFunction

use of cbit.vcell.solver.AnnotatedFunction in project vcell by virtualcell.

the class NagiosVCellCheck method checkVCell.

private static String checkVCell(VCELL_CHECK_LEVEL checkLevel, String rmiHostName, int rmiPort, String rmiBootstrapStubName, String vcellNagiosPassword, int warningTimeout, int criticalTimeout) throws Exception {
    long startTime = System.currentTimeMillis();
    SimulationStatusPersistent lastSimStatus = null;
    if (rmiHostName == null || rmiPort == -1) {
        throw new UnexpectedTestStateException("Host name/ip and rmiPort required for testing, rmihostname=" + rmiHostName + " rmiport=" + rmiPort);
    }
    String rmiUrl = "//" + rmiHostName + ":" + rmiPort + "/" + rmiBootstrapStubName;
    VCellBootstrap vcellBootstrap = null;
    try {
        vcellBootstrap = (VCellBootstrap) Naming.lookup(rmiUrl);
    } catch (Exception e) {
        throw new UnexpectedTestStateException("Error during bootstrap lookup, " + e.getClass().getSimpleName() + " " + e.getMessage());
    }
    if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.CONNECT_1.ordinal()) {
        if (vcellNagiosPassword == null) {
            throw new UnexpectedTestStateException("vcellNagios Password required for " + VCELL_CHECK_LEVEL.CONNECT_1.toString() + " and above");
        }
        VCellConnection vcellConnection = vcellBootstrap.getVCellConnection(new UserLoginInfo("vcellNagios", new DigestedPassword(vcellNagiosPassword)));
        if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.INFOS_2.ordinal()) {
            VCInfoContainer vcInfoContainer = vcellConnection.getUserMetaDbServer().getVCInfoContainer();
            if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.LOAD_3.ordinal()) {
                KeyValue bioModelKey = null;
                final String testModelName = "Solver Suite 5.1 (BETA only ode)";
                for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                    if (bioModelInfo.getVersion().getName().equals(testModelName)) {
                        bioModelKey = bioModelInfo.getVersion().getVersionKey();
                        break;
                    }
                }
                BigString bioModelXML = vcellConnection.getUserMetaDbServer().getBioModelXML(bioModelKey);
                BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
                bioModel.refreshDependencies();
                if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.DATA_4.ordinal()) {
                    final String testSimContextName = "non-spatial ODE";
                    SimulationContext simulationContext = bioModel.getSimulationContext(testSimContextName);
                    final String testSimName = "Copy of combined ida/cvode";
                    Simulation simulation = simulationContext.getSimulation(testSimName);
                    if (simulation == null) {
                        throw new UnexpectedTestStateException("Couldn't find sim '" + testSimName + "' for " + checkLevel.toString());
                    }
                    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(simulation.getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), 0);
                    ArrayList<AnnotatedFunction> outputFunctionsList = simulationContext.getOutputFunctionContext().getOutputFunctionsList();
                    OutputContext outputContext = new OutputContext(outputFunctionsList.toArray(new AnnotatedFunction[outputFunctionsList.size()]));
                    double[] times = vcellConnection.getDataSetController().getDataSetTimes(vcSimulationDataIdentifier);
                    ODESimData odeSimData = vcellConnection.getDataSetController().getODEData(vcSimulationDataIdentifier);
                    // SimDataBlock simDataBlock = vcellConnection.getDataSetController().getSimDataBlock(outputContext, vcSimulationDataIdentifier, "RanC_cyt",times[times.length-1]);
                    if (checkLevel.ordinal() >= VCELL_CHECK_LEVEL.RUN_5.ordinal()) {
                        KeyValue copy1Key = null;
                        KeyValue copy2Key = null;
                        try {
                            if (simulationContext.getSimulations().length != 1) {
                                throw new UnexpectedTestStateException("Expecting only 1 sim to be copied for " + checkLevel.toString());
                            }
                            SimulationStatusPersistent simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(simulation.getVersion().getVersionKey());
                            if (!simulationStatus.isCompleted()) {
                                throw new UnexpectedTestStateException("Expecting completed sim to copy for " + checkLevel.toString());
                            }
                            String copyModelName = testModelName + "_" + rmiHostName + "_" + rmiPort;
                            for (BioModelInfo bioModelInfo : vcInfoContainer.getBioModelInfos()) {
                                if (bioModelInfo.getVersion().getName().equals(copyModelName)) {
                                    throw new UnexpectedTestStateException("Messy test environment, not expecting " + copyModelName + " to exist at this point");
                                }
                            }
                            BigString copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModelAs(bioModelXML, copyModelName, null);
                            BioModel copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                            copy1Key = copyBioModel.getVersion().getVersionKey();
                            copyBioModel.refreshDependencies();
                            Simulation copySim = copyBioModel.getSimulationContext(testSimContextName).copySimulation(copyBioModel.getSimulationContext(testSimContextName).getSimulation(testSimName));
                            final String copyTestSimName = "test";
                            copySim.setName(copyTestSimName);
                            copyBioModel.refreshDependencies();
                            copyBioModelXMLStr = new BigString(XmlHelper.bioModelToXML(copyBioModel));
                            copyBioModelXMLStr = vcellConnection.getUserMetaDbServer().saveBioModel(copyBioModelXMLStr, null);
                            copyBioModel = XmlHelper.XMLToBioModel(new XMLSource(copyBioModelXMLStr.toString()));
                            copy2Key = copyBioModel.getVersion().getVersionKey();
                            copyBioModel.refreshDependencies();
                            Simulation newSimulation = copyBioModel.getSimulationContext(testSimContextName).getSimulation(copyTestSimName);
                            simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                            if (simulationStatus != null && !simulationStatus.isNeverRan()) {
                                throw new UnexpectedTestStateException("Expecting new sim to have 'never ran' status for " + checkLevel.toString());
                            }
                            VCSimulationIdentifier newSimID = new VCSimulationIdentifier(newSimulation.getVersion().getVersionKey(), copyBioModel.getVersion().getOwner());
                            vcellConnection.getSimulationController().startSimulation(newSimID, 1);
                            lastSimStatus = simulationStatus;
                            MessageEvent[] messageEvents = null;
                            while (simulationStatus == null || (!simulationStatus.isStopped() && !simulationStatus.isCompleted() && !simulationStatus.isFailed())) {
                                Thread.sleep(200);
                                if (((System.currentTimeMillis() - startTime) / 1000) > criticalTimeout) {
                                    vcellConnection.getSimulationController().stopSimulation(newSimID);
                                    vcellConnection.getMessageEvents();
                                    break;
                                }
                                simulationStatus = vcellConnection.getUserMetaDbServer().getSimulationStatus(newSimulation.getVersion().getVersionKey());
                                if (simulationStatus != null && !simulationStatus.toString().equals((lastSimStatus == null ? null : lastSimStatus.toString()))) {
                                    lastSimStatus = simulationStatus;
                                }
                                messageEvents = vcellConnection.getMessageEvents();
                            }
                        } finally {
                            try {
                                if (copy1Key != null) {
                                    vcellConnection.getUserMetaDbServer().deleteBioModel(copy1Key);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            try {
                                if (copy2Key != null) {
                                    vcellConnection.getUserMetaDbServer().deleteBioModel(copy2Key);
                                }
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }
                }
            }
        }
    }
    long endTime = System.currentTimeMillis();
    if (criticalTimeout != -1 && ((endTime - startTime) / 1000) > criticalTimeout) {
        throw new Exception(checkLevel.toString() + " test exceeded criticalTimeout=" + criticalTimeout + " seconds lastSimStatus=" + lastSimStatus);
    }
    if (warningTimeout != -1 && ((endTime - startTime) / 1000) > warningTimeout) {
        throw new WarningTestConditionException(checkLevel.toString() + " test exceeded warningTimeout=" + warningTimeout + " seconds lastSimStatus=" + lastSimStatus);
    }
    return vcellBootstrap.getVCellSoftwareVersion();
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) KeyValue(org.vcell.util.document.KeyValue) MessageEvent(cbit.rmi.event.MessageEvent) VCellBootstrap(cbit.vcell.server.VCellBootstrap) BigString(org.vcell.util.BigString) ODESimData(cbit.vcell.solver.ode.ODESimData) DigestedPassword(org.vcell.util.document.UserLoginInfo.DigestedPassword) BigString(org.vcell.util.BigString) VCInfoContainer(org.vcell.util.document.VCInfoContainer) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) VCellConnection(cbit.vcell.server.VCellConnection) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) UserLoginInfo(org.vcell.util.document.UserLoginInfo) XMLSource(cbit.vcell.xml.XMLSource)

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