Search in sources :

Example 6 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class FVSolverStandalone method writeVCGAndResampleFieldData.

protected void writeVCGAndResampleFieldData() throws SolverException {
    fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_PROC_GEOM);
    try {
        // write subdomains file
        SubdomainInfo.write(new File(getSaveDirectory(), baseName + SimDataConstants.SUBDOMAINS_FILE_SUFFIX), simTask.getSimulation().getMathDescription());
        PrintWriter pw = new PrintWriter(new FileWriter(new File(getSaveDirectory(), baseName + SimDataConstants.VCG_FILE_EXTENSION)));
        GeometryFileWriter.write(pw, getResampledGeometry());
        pw.close();
        FieldDataIdentifierSpec[] argFieldDataIDSpecs = simTask.getSimulationJob().getFieldDataIdentifierSpecs();
        if (argFieldDataIDSpecs != null && argFieldDataIDSpecs.length > 0) {
            fireSolverStarting(SimulationMessage.MESSAGE_SOLVEREVENT_STARTING_RESAMPLE_FD);
            FieldFunctionArguments psfFieldFunc = null;
            Variable var = simTask.getSimulationJob().getSimulationSymbolTable().getVariable(Simulation.PSF_FUNCTION_NAME);
            if (var != null) {
                FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments(var.getExpression());
                if (ffas == null || ffas.length == 0) {
                    throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
                } else {
                    Expression newexp;
                    try {
                        newexp = new Expression(ffas[0].infix());
                        if (!var.getExpression().compareEqual(newexp)) {
                            throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
                        }
                        psfFieldFunc = ffas[0];
                    } catch (ExpressionException e) {
                        e.printStackTrace();
                        throw new DataAccessException(e.getMessage());
                    }
                }
            }
            boolean[] bResample = new boolean[argFieldDataIDSpecs.length];
            Arrays.fill(bResample, true);
            for (int i = 0; i < argFieldDataIDSpecs.length; i++) {
                argFieldDataIDSpecs[i].getFieldFuncArgs().getTime().bindExpression(simTask.getSimulationJob().getSimulationSymbolTable());
                if (argFieldDataIDSpecs[i].getFieldFuncArgs().equals(psfFieldFunc)) {
                    bResample[i] = false;
                }
            }
            int numMembraneElements = getResampledGeometry().getGeometrySurfaceDescription().getSurfaceCollection().getTotalPolygonCount();
            CartesianMesh simpleMesh = CartesianMesh.createSimpleCartesianMesh(getResampledGeometry().getOrigin(), getResampledGeometry().getExtent(), simTask.getSimulation().getMeshSpecification().getSamplingSize(), getResampledGeometry().getGeometrySurfaceDescription().getRegionImage());
            String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
            DataSetControllerImpl dsci = new DataSetControllerImpl(null, getSaveDirectory().getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
            dsci.writeFieldFunctionData(null, argFieldDataIDSpecs, bResample, simpleMesh, simResampleInfoProvider, numMembraneElements, HESM_OVERWRITE_AND_CONTINUE);
        }
    } catch (Exception e) {
        throw new SolverException(e.getMessage());
    }
}
Also used : Variable(cbit.vcell.math.Variable) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) FileWriter(java.io.FileWriter) ExpressionException(cbit.vcell.parser.ExpressionException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException) PrintWriter(java.io.PrintWriter)

Example 7 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class FiniteVolumeFileWriter method writeFieldData.

/**
 * # Field Data
 * FIELD_DATA_BEGIN
 * #id, name, varname, time filename
 * 0 _VCell_FieldData_0 FRAP_binding_ALPHA rfB 0.1 \\users\\fgao\\SimID_22489731_0_FRAP_binding_ALPHA_rfB_0_1.fdat
 * FIELD_DATA_END
 * @throws FileNotFoundException
 * @throws ExpressionException
 * @throws DataAccessException
 */
private void writeFieldData() throws FileNotFoundException, ExpressionException, DataAccessException {
    FieldDataIdentifierSpec[] fieldDataIDSpecs = simTask.getSimulationJob().getFieldDataIdentifierSpecs();
    if (fieldDataIDSpecs == null || fieldDataIDSpecs.length == 0) {
        return;
    }
    String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
    DataSetControllerImpl dsci = new DataSetControllerImpl(null, workingDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
    printWriter.println("# Field Data");
    printWriter.println("FIELD_DATA_BEGIN");
    printWriter.println("#id, type, new name, name, varname, time, filename");
    FieldFunctionArguments psfFieldFunc = null;
    Variable var = simTask.getSimulationJob().getSimulationSymbolTable().getVariable(Simulation.PSF_FUNCTION_NAME);
    if (var != null) {
        FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments(var.getExpression());
        if (ffas == null || ffas.length == 0) {
            throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
        } else {
            Expression newexp = new Expression(ffas[0].infix());
            if (!var.getExpression().compareEqual(newexp)) {
                throw new DataAccessException("Point Spread Function " + Simulation.PSF_FUNCTION_NAME + " can only be a single field function.");
            }
            psfFieldFunc = ffas[0];
        }
    }
    int index = 0;
    HashSet<FieldDataIdentifierSpec> uniqueFieldDataIDSpecs = new HashSet<FieldDataIdentifierSpec>();
    uniqueFieldDataNSet = new HashSet<FieldDataNumerics>();
    for (int i = 0; i < fieldDataIDSpecs.length; i++) {
        if (!uniqueFieldDataIDSpecs.contains(fieldDataIDSpecs[i])) {
            FieldFunctionArguments ffa = fieldDataIDSpecs[i].getFieldFuncArgs();
            File newResampledFieldDataFile = new File(workingDirectory, SimulationData.createCanonicalResampleFileName((VCSimulationDataIdentifier) simTask.getSimulationJob().getVCDataIdentifier(), fieldDataIDSpecs[i].getFieldFuncArgs()));
            uniqueFieldDataIDSpecs.add(fieldDataIDSpecs[i]);
            VariableType varType = fieldDataIDSpecs[i].getFieldFuncArgs().getVariableType();
            SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fieldDataIDSpecs[i].getExternalDataIdentifier(), fieldDataIDSpecs[i].getFieldFuncArgs().getVariableName(), fieldDataIDSpecs[i].getFieldFuncArgs().getTime().evaluateConstant());
            VariableType dataVarType = simDataBlock.getVariableType();
            if (varType.equals(VariableType.UNKNOWN)) {
                varType = dataVarType;
            } else if (!varType.equals(dataVarType)) {
                throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
            }
            if (psfFieldFunc != null && psfFieldFunc.equals(ffa)) {
                psfFieldIndex = index;
            }
            String fieldDataID = "_VCell_FieldData_" + index;
            printWriter.println(index + " " + varType.getTypeName() + " " + fieldDataID + " " + ffa.getFieldName() + " " + ffa.getVariableName() + " " + ffa.getTime().infix() + " " + newResampledFieldDataFile);
            uniqueFieldDataNSet.add(new FieldDataNumerics(SimulationData.createCanonicalFieldFunctionSyntax(ffa.getFieldName(), ffa.getVariableName(), ffa.getTime().evaluateConstant(), ffa.getVariableType().getTypeName()), fieldDataID));
            index++;
        }
    }
    if (psfFieldIndex >= 0) {
        printWriter.println("PSF_FIELD_DATA_INDEX " + psfFieldIndex);
    }
    printWriter.println("FIELD_DATA_END");
    printWriter.println();
}
Also used : FilamentVariable(cbit.vcell.math.FilamentVariable) VolVariable(cbit.vcell.math.VolVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) ParameterVariable(cbit.vcell.math.ParameterVariable) RandomVariable(cbit.vcell.math.RandomVariable) VolumeRandomVariable(cbit.vcell.math.VolumeRandomVariable) MembraneRegionVariable(cbit.vcell.math.MembraneRegionVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) MembraneRandomVariable(cbit.vcell.math.MembraneRandomVariable) VolumeRegionVariable(cbit.vcell.math.VolumeRegionVariable) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) MemVariable(cbit.vcell.math.MemVariable) Variable(cbit.vcell.math.Variable) VariableType(cbit.vcell.math.VariableType) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimDataBlock(cbit.vcell.simdata.SimDataBlock) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException) HashSet(java.util.HashSet)

Example 8 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class VCellClientDataServiceImpl method getVtkManager.

@Override
public VtkManager getVtkManager(SimulationDataSetRef simulationDataSetRef) throws FileNotFoundException, DataAccessException {
    VCSimulationDataIdentifier vcSimulationDataIdentifier = getVCSimulationDataIdentifier(simulationDataSetRef);
    VtkManager vtkManager = null;
    if (!simulationDataSetRef.isLocal) {
        vtkManager = vcellClient.getRequestManager().getVtkManager(null, vcSimulationDataIdentifier);
    } else {
        // ---- preliminary : construct the localDatasetControllerProvider
        File primaryDir = ResourceUtil.getLocalRootDir();
        User usr = User.tempUser;
        DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
        ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
        LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
        VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
        vtkManager = new VtkManager(null, vcDataManager, vcSimulationDataIdentifier);
    }
    return vtkManager;
}
Also used : LocalDataSetControllerProvider(cbit.vcell.client.LocalDataSetControllerProvider) User(org.vcell.util.document.User) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) LocalVCSimulationDataIdentifier(cbit.vcell.client.ClientSimManager.LocalVCSimulationDataIdentifier) VtkManager(cbit.vcell.simdata.VtkManager) File(java.io.File) VCDataManager(cbit.vcell.simdata.VCDataManager)

Example 9 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class VCellServices method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    OperatingSystemInfo.getInstance();
    if (args.length != 3 && args.length != 0) {
        System.out.println("Missing arguments: " + VCellServices.class.getName() + " [sshHost sshUser sshKeyFile] ");
        System.exit(1);
    }
    try {
        PropertyLoader.loadProperties(REQUIRED_SERVICE_PROPERTIES);
        ResourceUtil.setNativeLibraryDirectory();
        new LibraryLoaderThread(false).start();
        PythonSupport.verifyInstallation(new PythonPackage[] { PythonPackage.VTK, PythonPackage.THRIFT });
        CommandService commandService = null;
        if (args.length == 3) {
            String sshHost = args[0];
            String sshUser = args[1];
            File sshKeyFile = new File(args[2]);
            try {
                commandService = new CommandServiceSshNative(sshHost, sshUser, sshKeyFile);
                commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
                lg.trace("SSH Connection test passed with installed keyfile, running ls as user " + sshUser + " on " + sshHost);
            } catch (Exception e) {
                e.printStackTrace();
                try {
                    commandService = new CommandServiceSshNative(sshHost, sshUser, sshKeyFile, new File("/root"));
                    commandService.command(new String[] { "/usr/bin/env bash -c ls | head -5" });
                    lg.trace("SSH Connection test passed after installing keyfile, running ls as user " + sshUser + " on " + sshHost);
                } catch (Exception e2) {
                    e.printStackTrace();
                    throw new RuntimeException("failed to establish an ssh command connection to " + sshHost + " as user '" + sshUser + "' using key '" + sshKeyFile + "'", e);
                }
            }
            // can't make user directories, they are remote.
            AbstractSolver.bMakeUserDirs = false;
        } else {
            commandService = new CommandServiceLocal();
        }
        BatchSystemType batchSystemType = BatchSystemType.SLURM;
        HtcProxy htcProxy = null;
        switch(batchSystemType) {
            case SLURM:
                {
                    htcProxy = new SlurmProxy(commandService, PropertyLoader.getRequiredProperty(PropertyLoader.htcUser));
                    break;
                }
            default:
                {
                    throw new RuntimeException("unrecognized batch scheduling option :" + batchSystemType);
                }
        }
        int serviceOrdinal = 0;
        VCMongoMessage.serviceStartup(ServiceName.dispatch, new Integer(serviceOrdinal), args);
        // //
        // // JMX registration
        // //
        // MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        // mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        ServiceInstanceStatus serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.MASTER, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
        ConnectionFactory conFactory = DatabaseService.getInstance().createConnectionFactory();
        KeyFactory keyFactory = conFactory.getKeyFactory();
        DatabaseServerImpl databaseServerImpl = new DatabaseServerImpl(conFactory, keyFactory);
        AdminDBTopLevel adminDbTopLevel = new AdminDBTopLevel(conFactory);
        SimulationDatabase simulationDatabase = new SimulationDatabaseDirect(adminDbTopLevel, databaseServerImpl, true);
        Cachetable cacheTable = new Cachetable(MessageConstants.MINUTE_IN_MS * 20);
        DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cacheTable, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty)), new File(PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty))));
        ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
        // add dataJobListener
        DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
        VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new ServerMessagingDelegate());
        VCellServices vcellServices = new VCellServices(htcProxy, vcMessagingService, serviceInstanceStatus, databaseServerImpl, dataServerImpl, simulationDatabase);
        dataSetControllerImpl.addDataJobListener(vcellServices);
        exportServiceImpl.addExportListener(vcellServices);
        vcellServices.init();
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
}
Also used : Cachetable(cbit.vcell.simdata.Cachetable) DataServerImpl(cbit.vcell.simdata.DataServerImpl) ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) HtcProxy(cbit.vcell.message.server.htc.HtcProxy) CommandService(cbit.vcell.message.server.cmd.CommandService) VCMessagingService(cbit.vcell.message.VCMessagingService) ConnectionFactory(org.vcell.db.ConnectionFactory) SimulationDatabaseDirect(cbit.vcell.message.server.dispatcher.SimulationDatabaseDirect) CommandServiceLocal(cbit.vcell.message.server.cmd.CommandServiceLocal) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DatabaseServerImpl(cbit.vcell.modeldb.DatabaseServerImpl) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) KeyFactory(org.vcell.db.KeyFactory) AdminDBTopLevel(cbit.vcell.modeldb.AdminDBTopLevel) SimulationDatabase(cbit.vcell.message.server.dispatcher.SimulationDatabase) LibraryLoaderThread(cbit.vcell.resource.LibraryLoaderThread) SlurmProxy(cbit.vcell.message.server.htc.slurm.SlurmProxy) VCMessagingException(cbit.vcell.message.VCMessagingException) Date(java.util.Date) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) BatchSystemType(cbit.vcell.server.HtcJobID.BatchSystemType) File(java.io.File) CommandServiceSshNative(cbit.vcell.message.server.cmd.CommandServiceSshNative)

Example 10 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class SimDataServer method main.

/**
 * Starts the application.
 * @param args an array of command-line arguments
 */
public static void main(java.lang.String[] args) {
    if (args.length < 1) {
        System.out.println("Missing arguments: " + SimDataServer.class.getName() + " serviceOrdinal [EXPORTONLY] [logdir]");
        System.exit(1);
    }
    try {
        PropertyLoader.loadProperties();
        int serviceOrdinal = Integer.parseInt(args[0]);
        String logdir = null;
        boolean bExportOnly = false;
        if (args.length > 1) {
            if (args[1].equalsIgnoreCase("EXPORTONLY")) {
                bExportOnly = true;
                VCMongoMessage.serviceStartup(ServiceName.export, new Integer(serviceOrdinal), args);
                if (args.length > 2) {
                    logdir = args[2];
                }
            } else {
                VCMongoMessage.serviceStartup(ServiceName.simData, new Integer(serviceOrdinal), args);
                logdir = args[1];
            }
        }
        ServiceInstanceStatus serviceInstanceStatus = null;
        ServiceName serviceName = null;
        if (bExportOnly) {
            serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DATAEXPORT, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
            serviceName = ServiceName.export;
        } else {
            serviceInstanceStatus = new ServiceInstanceStatus(VCellServerID.getSystemServerID(), ServiceType.DATA, serviceOrdinal, ManageUtils.getHostName(), new Date(), true);
            serviceName = ServiceName.simData;
        }
        VCMongoMessage.serviceStartup(serviceName, new Integer(serviceOrdinal), args);
        // 
        // JMX registration
        // 
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
        mbs.registerMBean(new VCellServiceMXBeanImpl(), new ObjectName(VCellServiceMXBean.jmxObjectName));
        Cachetable cacheTable = new Cachetable(MessageConstants.MINUTE_IN_MS * 20);
        DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(cacheTable, new File(PropertyLoader.getRequiredProperty(PropertyLoader.primarySimDataDirInternalProperty)), new File(PropertyLoader.getRequiredProperty(PropertyLoader.secondarySimDataDirInternalProperty)));
        ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
        DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, exportServiceImpl);
        VCMessagingService vcMessagingService = VCellServiceHelper.getInstance().loadService(VCMessagingService.class);
        vcMessagingService.setDelegate(new ServerMessagingDelegate());
        SimDataServer simDataServer = new SimDataServer(serviceInstanceStatus, dataServerImpl, vcMessagingService, false);
        // add dataJobListener
        dataSetControllerImpl.addDataJobListener(simDataServer);
        // add export listener
        exportServiceImpl.addExportListener(simDataServer);
        simDataServer.init();
    } catch (Throwable e) {
        e.printStackTrace(System.out);
    }
}
Also used : Cachetable(cbit.vcell.simdata.Cachetable) DataServerImpl(cbit.vcell.simdata.DataServerImpl) ServerMessagingDelegate(cbit.vcell.message.server.ServerMessagingDelegate) VCMessagingService(cbit.vcell.message.VCMessagingService) Date(java.util.Date) ObjectName(javax.management.ObjectName) ServiceName(cbit.vcell.mongodb.VCMongoMessage.ServiceName) VCellServiceMXBeanImpl(cbit.vcell.message.server.jmx.VCellServiceMXBeanImpl) ServiceInstanceStatus(cbit.vcell.message.server.ServiceInstanceStatus) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) File(java.io.File) MBeanServer(javax.management.MBeanServer)

Aggregations

DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)23 File (java.io.File)15 DataAccessException (org.vcell.util.DataAccessException)10 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 CartesianMesh (cbit.vcell.solvers.CartesianMesh)8 IOException (java.io.IOException)8 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)7 Cachetable (cbit.vcell.simdata.Cachetable)7 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)6 SolverException (cbit.vcell.solver.SolverException)6 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)6 User (org.vcell.util.document.User)6 SimDataBlock (cbit.vcell.simdata.SimDataBlock)5 VariableType (cbit.vcell.math.VariableType)4 DataServerImpl (cbit.vcell.simdata.DataServerImpl)4 OutputContext (cbit.vcell.simdata.OutputContext)4 Simulation (cbit.vcell.solver.Simulation)4 ArrayList (java.util.ArrayList)4 ThriftDataAccessException (org.vcell.vcellij.api.ThriftDataAccessException)4 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)3