Search in sources :

Example 1 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class SimulationDataTest method noZero.

/*
	@Test
	public void nameTest( ) {
		KeyValue kv = new KeyValue("8675904");
		for (int j : jIndexes) {
			for (int i = 1; i < 10000; i++) {
				String old = SimulationData.createCanonicalSmoldynOutputFileNameOld(kv, j, i);
				String now = SimulationData.createCanonicalSmoldynOutputFileName(kv, j, i);
				if (!old.equals(now)) {
					System.err.println(old + " and " + now);
				}
				assertTrue(old.equals(now));
			}
		}
	}
	*/
@Test(expected = IllegalArgumentException.class)
public void noZero() {
    KeyValue kv = new KeyValue("8675904");
    String now = SimulationData.createCanonicalSmoldynOutputFileName(kv, 0, 0);
    System.out.println("never see " + now);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Test(org.junit.Test)

Example 2 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class VCellDataTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        ResourceUtil.setNativeLibraryDirectory();
        KeyValue simKey = new KeyValue("1661241954");
        String pathPrefix = "C:\\Users\\schaff\\.vcell\\simdata\\user\\";
        File meshFile = new File(pathPrefix + "SimID_" + simKey + "_0_.mesh");
        File meshMetricsFile = new File(pathPrefix + "SimID_" + simKey + "_0_.meshmetrics");
        File subdomainFile = new File(pathPrefix + "SimID_" + simKey + "_0_.subdomains");
        File logFile = new File(pathPrefix + "SimID_" + simKey + "_0_.log");
        File zipFile = new File(pathPrefix + "SimID_" + simKey + "_0_00.zip");
        File postprocessingFile = new File(pathPrefix + "SimID_" + simKey + "_0_.hdf5");
        VCellSimFiles vcellFiles = new VCellSimFiles(simKey, 0, meshFile, meshMetricsFile, subdomainFile, logFile, postprocessingFile);
        vcellFiles.addDataFileEntry(zipFile, new File("SimID_" + simKey + "_0_0000.sim"), 0.0);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0001.sim"),0.05);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0002.sim"),0.10);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0003.sim"),0.15);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0004.sim"),0.20);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0005.sim"),0.25);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0006.sim"),0.30);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0007.sim"),0.35);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0008.sim"),0.40);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0009.sim"),0.45);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0010.sim"),0.50);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0011.sim"),0.55);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0012.sim"),0.60);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0013.sim"),0.65);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0014.sim"),0.70);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0015.sim"),0.75);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0016.sim"),0.80);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0017.sim"),0.85);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0018.sim"),0.90);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0019.sim"),0.95);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0020.sim"),1.0);
        // process each domain separately (only have to process the mesh once for each one)
        CartesianMeshVtkFileWriter cartesianMeshVtkFileWriter = new CartesianMeshVtkFileWriter();
        File destinationDirectory = new File("C:\\Developer\\eclipse\\workspace\\VCell_5.3_visfull\\VtkData\\");
        File[] generatedFiles = cartesianMeshVtkFileWriter.writeVtuExportFiles(vcellFiles, destinationDirectory, null);
        boolean bDisplay = true;
        if (bDisplay) {
            CartesianMeshFileReader reader = new CartesianMeshFileReader();
            CartesianMesh mesh = reader.readFromFiles(vcellFiles);
            ArrayList<String> allDomainNames = new ArrayList<String>();
            allDomainNames.addAll(mesh.getVolumeDomainNames());
            allDomainNames.addAll(mesh.getMembraneDomainNames());
            for (String domain : allDomainNames) {
                for (int timeIndex = 0; timeIndex < vcellFiles.getTimes().size(); timeIndex++) {
                    // String filename = new File(destinationDirectory,vcellFiles.getCannonicalFilePrefix(domain,timeIndex)+".vtu").getAbsolutePath();
                    // vtkUnstructuredGrid vtkgrid = vtkGridUtils.read(filename);
                    // vtkgrid.BuildLinks();
                    // 
                    // String varName0 = vtkgrid.GetCellData().GetArrayName(0);
                    // String varName1 = vtkgrid.GetCellData().GetArrayName(1);
                    // SimpleVTKViewer simpleViewer = new SimpleVTKViewer();
                    // simpleViewer.showGrid(vtkgrid, varName0, varName1);
                    Thread.sleep(1000);
                }
            }
        }
        // CartesianMeshFileReader reader = new CartesianMeshFileReader();
        // CartesianMesh mesh = reader.readFromFiles(vcellFiles);
        // CartesianMeshMapping cartesianMeshMapping = new CartesianMeshMapping();
        // 
        // //String domainName = mesh.meshRegionInfo.getVolumeDomainNames().get(1);
        // String domainName = mesh.meshRegionInfo.getVolumeDomainNames().get(0);
        // 
        // System.out.println("making visMesh for domain "+domainName+" of ["+mesh.meshRegionInfo.getVolumeDomainNames()+"]");
        // VisMesh visMesh = cartesianMeshMapping.fromMeshData(mesh, domainName);
        // final int numElements = visMesh.getPolyhedra().size();
        // final double[] data1 = new double[numElements];
        // final double[] data2 = new double[numElements];
        // 
        // for (int i=0;i<numElements;i++){
        // data1[i] = Math.sin(i/10000.0);
        // data2[i] = Math.cos(i/10000.0);
        // }
        // VisMeshData visData = new VisMeshData() {
        // private String[] names = new String[] { "data1", "data2" };
        // 
        // @Override
        // public String[] getVarNames() {
        // return new String[] { "data1", "data2" };
        // }
        // 
        // @Override
        // public double getTime() {
        // return 0.0;
        // }
        // 
        // @Override
        // public double[] getData(String var) {
        // if (var.equals("data1")){
        // return data1;
        // }else if (var.equals("data2")){
        // return data2;
        // }else{
        // throw new RuntimeException("var "+var+" not found");
        // }
        // }
        // };
        // 
        // VisDomain visDomain = new VisDomain("domain1",visMesh,visData);
        // VtkGridUtils vtkGridUtils = new VtkGridUtils();
        // vtkUnstructuredGrid vtkgrid = vtkGridUtils.getVtkGrid(visDomain);
        // vtkgrid = TestVTK.testWindowedSincPolyDataFilter(vtkgrid);
        // String filenameBinary = "testBinary.vtu";
        // vtkGridUtils.writeXML(vtkgrid, filenameBinary, false);
        // vtkgrid = vtkGridUtils.read(filenameBinary);
        // //vtkgrid.s
        // vtkgrid.BuildLinks();
        // SimpleVTKViewer simpleViewer = new SimpleVTKViewer();
        // String[] varNames = visDomain.getVisMeshData().getVarNames();
        // simpleViewer.showGrid(vtkgrid, varNames[0], varNames[1]);
        System.out.println("ran");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : CartesianMeshFileReader(org.vcell.vis.io.CartesianMeshFileReader) KeyValue(org.vcell.util.document.KeyValue) CartesianMeshVtkFileWriter(org.vcell.vis.mapping.vcell.CartesianMeshVtkFileWriter) ArrayList(java.util.ArrayList) VCellSimFiles(org.vcell.vis.io.VCellSimFiles) CartesianMesh(org.vcell.vis.vcell.CartesianMesh) File(java.io.File)

Example 3 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class XmlReader method getSimulationVersion.

/**
 * This method returns a Version object from an XML representation.
 * Creation date: (3/16/2001 3:41:24 PM)
 * @return cbit.sql.Version
 * @param param org.jdom.Element
 */
private SimulationVersion getSimulationVersion(Element xmlVersion) throws XmlParseException {
    if (xmlVersion == null) {
        return null;
    }
    // determine if it should be processed using the 'fromVersionable'
    if (xmlVersion.getAttributeValue(XMLTags.FromVersionableTag) == null || Boolean.valueOf(xmlVersion.getAttributeValue(XMLTags.FromVersionableTag)).booleanValue() || this.readKeysFlag == false) {
        // this came from a versionable object, so skip! Or it should not explicitly import the information inside the Version
        return null;
    }
    // Read all the attributes
    // *name
    String name = unMangle(xmlVersion.getAttributeValue(XMLTags.NameAttrTag));
    // *key
    String temp = xmlVersion.getAttributeValue(XMLTags.KeyValueAttrTag);
    KeyValue key = new KeyValue(temp);
    // *owner
    Element tempElement = xmlVersion.getChild(XMLTags.OwnerTag, vcNamespace);
    User owner = new User(unMangle(tempElement.getAttributeValue(XMLTags.NameAttrTag)), new KeyValue(tempElement.getAttributeValue(XMLTags.IdentifierAttrTag)));
    // *access
    GroupAccess groupAccess = getGroupAccess(xmlVersion.getChild(XMLTags.GroupAccessTag, vcNamespace));
    // *Branchpointref
    temp = xmlVersion.getAttributeValue(XMLTags.BranchPointRefTag);
    KeyValue branchpointref = null;
    if (temp != null) {
        branchpointref = new KeyValue(temp);
    }
    // *BranchID
    java.math.BigDecimal branchId = new java.math.BigDecimal(xmlVersion.getAttributeValue(XMLTags.BranchIdAttrTag));
    // *Flag
    temp = xmlVersion.getAttributeValue(XMLTags.FlagAttrTag);
    VersionFlag flag = VersionFlag.fromInt(Integer.parseInt(temp));
    // *Date
    java.util.Date date = null;
    temp = xmlVersion.getAttributeValue(XMLTags.DateAttrTag);
    if (temp != null) {
        try {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat(BeanUtils.vcDateFormat, Locale.US);
            date = simpleDateFormat.parse(temp);
        } catch (java.text.ParseException e) {
            e.printStackTrace();
            throw new XmlParseException("Invalid date:" + temp, e);
        }
    }
    // *DataSimulationRef
    KeyValue parentSimRefKey = null;
    tempElement = xmlVersion.getChild(XMLTags.ParentSimRefTag, vcNamespace);
    if (tempElement != null) {
        parentSimRefKey = new KeyValue(tempElement.getAttributeValue(XMLTags.KeyValueAttrTag));
    }
    // *Annotation
    String annotation = null;
    String annotationText = xmlVersion.getChildText(XMLTags.AnnotationTag, vcNamespace);
    if (annotationText != null && annotationText.length() > 0) {
        annotation = unMangle(annotationText);
    }
    // Create and return the version object
    return new SimulationVersion(key, name, owner, groupAccess, branchpointref, branchId, date, flag, annotation, parentSimRefKey);
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) Element(org.jdom.Element) VersionFlag(org.vcell.util.document.VersionFlag) SimulationVersion(org.vcell.util.document.SimulationVersion) SpeciesContext(cbit.vcell.model.SpeciesContext) DataContext(cbit.vcell.data.DataContext) ReactionContext(cbit.vcell.mapping.ReactionContext) RDFXMLContext(org.vcell.pathway.persistence.RDFXMLContext) SimulationContext(cbit.vcell.mapping.SimulationContext) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) ParameterContext(cbit.vcell.mapping.ParameterContext) GroupAccess(org.vcell.util.document.GroupAccess) SimpleDateFormat(java.text.SimpleDateFormat)

Example 4 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class XmlReader method getAnalyticSubVolume.

/**
 * This method returns an AnalyticSubVolume object from a XML representation.
 * Creation date: (5/1/2001 5:26:17 PM)
 * @return cbit.vcell.geometry.AnalyticSubVolume
 * @param param org.jdom.Element
 */
private AnalyticSubVolume getAnalyticSubVolume(Element param) throws XmlParseException {
    // retrieve the attributes
    String name = param.getAttributeValue(XMLTags.NameAttrTag);
    int handle = Integer.parseInt(param.getAttributeValue(XMLTags.HandleAttrTag));
    // process the key
    KeyValue key = null;
    String temp = param.getAttributeValue(XMLTags.KeyValueAttrTag);
    if (temp != null && temp.length() > 0 && this.readKeysFlag) {
        key = new KeyValue(temp);
    }
    // Retrieve the expression
    temp = param.getChildText(XMLTags.AnalyticExpressionTag, vcNamespace);
    if (temp == null) {
        throw new XmlParseException("A Problem occured while retrieving the analytic expression of the AnalyticSubvolume " + name);
    }
    Expression newexpression = unMangleExpression(temp);
    // Create the AnalyticCompartment
    AnalyticSubVolume newsubvolume = null;
    try {
        newsubvolume = new AnalyticSubVolume(key, name, newexpression, handle);
    } catch (ExpressionException e) {
        e.printStackTrace();
        throw new XmlParseException("An ExpressionException occured when creating the new AnalyticSubvolume " + name, e);
    }
    return newsubvolume;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) Expression(cbit.vcell.parser.Expression) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ExpressionException(cbit.vcell.parser.ExpressionException)

Example 5 with KeyValue

use of org.vcell.util.document.KeyValue in project vcell by virtualcell.

the class ParameterEstimationTaskSimulatorIDA method getRowColumnRestultSetByBestEstimations.

public RowColumnResultSet getRowColumnRestultSetByBestEstimations(ParameterEstimationTask parameterEstimationTask, String[] paramNames, double[] paramValues) throws Exception {
    // create a temp simulation based on math description
    KeyValue key = new KeyValue("" + Math.abs(new Random().nextLong()));
    SimulationVersion dummyVersion = new SimulationVersion(key, "name", new User("temp", new KeyValue("1")), null, null, null, null, null, null, null);
    Simulation simulation = new Simulation(dummyVersion, parameterEstimationTask.getSimulationContext().getMathDescription());
    ReferenceData refData = parameterEstimationTask.getModelOptimizationSpec().getReferenceData();
    double[] times = refData.getDataByColumn(0);
    double endTime = times[times.length - 1];
    ExplicitOutputTimeSpec exTimeSpec = new ExplicitOutputTimeSpec(times);
    // set simulation ending time and output interval
    simulation.getSolverTaskDescription().setTimeBounds(new TimeBounds(0, endTime));
    simulation.getSolverTaskDescription().setOutputTimeSpec(exTimeSpec);
    // set parameters as math overrides
    MathOverrides mathOverrides = simulation.getMathOverrides();
    for (int i = 0; i < paramNames.length; i++) {
        mathOverrides.putConstant(new Constant(paramNames[i], new Expression(paramValues[i])));
    }
    SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
    IDASolverStandalone idaSolver = new IDASolverStandalone(simTask, ResourceUtil.getLocalSimDir("temp"), false);
    // startSolver();
    idaSolver.runSolver();
    Thread.sleep(1000);
    long startTimeMS = System.currentTimeMillis();
    while (idaSolver.getSolverStatus().isRunning() && System.currentTimeMillis() < (startTimeMS + 10000L)) {
        Thread.sleep(500);
    }
    ODESolverResultSet resultset = idaSolver.getODESolverResultSet();
    return resultset;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) User(org.vcell.util.document.User) SimulationTask(cbit.vcell.messaging.server.SimulationTask) Constant(cbit.vcell.math.Constant) ReferenceData(cbit.vcell.opt.ReferenceData) TimeBounds(cbit.vcell.solver.TimeBounds) MathOverrides(cbit.vcell.solver.MathOverrides) ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) SimulationVersion(org.vcell.util.document.SimulationVersion) Random(java.util.Random) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) IDASolverStandalone(cbit.vcell.solver.ode.IDASolverStandalone) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) SimulationJob(cbit.vcell.solver.SimulationJob)

Aggregations

KeyValue (org.vcell.util.document.KeyValue)325 DataAccessException (org.vcell.util.DataAccessException)92 User (org.vcell.util.document.User)68 ResultSet (java.sql.ResultSet)57 Statement (java.sql.Statement)52 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)44 SQLException (java.sql.SQLException)43 BigString (org.vcell.util.BigString)40 BigDecimal (java.math.BigDecimal)38 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)37 BioModel (cbit.vcell.biomodel.BioModel)36 Simulation (cbit.vcell.solver.Simulation)33 XmlParseException (cbit.vcell.xml.XmlParseException)33 PropertyVetoException (java.beans.PropertyVetoException)33 Vector (java.util.Vector)33 Connection (java.sql.Connection)32 ArrayList (java.util.ArrayList)31 File (java.io.File)29 SimulationContext (cbit.vcell.mapping.SimulationContext)28 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)24