Search in sources :

Example 81 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class ClientRequestManager method createFDOSFromSurfaceFile.

public static FieldDataFileOperationSpec createFDOSFromSurfaceFile(File surfaceFile) throws Exception {
    SurfaceCollection surfaceCollection = createSurfaceCollectionFromSurfaceFile(surfaceFile);
    if (surfaceCollection != null) {
        Geometry geometry = RayCaster.createGeometryFromSTL(new GeometryThumbnailImageFactoryAWT(), surfaceCollection, 1000000);
        FieldDataFileOperationSpec fdfos = new FieldDataFileOperationSpec();
        fdfos.origin = geometry.getOrigin();
        fdfos.extent = geometry.getExtent();
        VCImage image = geometry.getGeometrySpec().getImage();
        if (image.getNumPixelClasses() == 1) {
            throw new Exception("STL import failed during processing, pixelclass count=1");
        }
        fdfos.isize = new ISize(image.getNumX(), image.getNumY(), image.getNumZ());
        byte[] pixels = image.getPixels();
        short[] dataToSegment = new short[image.getNumXYZ()];
        for (int i = 0; i < pixels.length; i++) {
            dataToSegment[i] = pixels[i];
        }
        fdfos.shortSpecData = new short[][][] { { dataToSegment } };
        return fdfos;
    }
    return null;
}
Also used : SurfaceCollection(cbit.vcell.geometry.surface.SurfaceCollection) Geometry(cbit.vcell.geometry.Geometry) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) ISize(org.vcell.util.ISize) VCImage(cbit.image.VCImage) ProgrammingException(org.vcell.util.ProgrammingException) GeometryException(cbit.vcell.geometry.GeometryException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) DataFormatException(java.util.zip.DataFormatException) UserCancelException(org.vcell.util.UserCancelException)

Example 82 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class OptXmlWriter method getModelXML.

public static Element getModelXML(PdeObjectiveFunction pdeObjectiveFunction, String[] parameterNames) {
    Element modelElement = new Element(OptXmlTags.Model_Tag);
    try {
        SpatialReferenceData refData = pdeObjectiveFunction.getReferenceData();
        double refDataEndTime = refData.getDataByRow(refData.getNumDataRows() - 1)[0];
        // 
        // post the problem either as an IDA or CVODE model
        // 
        org.vcell.util.document.SimulationVersion simVersion = new org.vcell.util.document.SimulationVersion(new KeyValue("12345"), "name", new org.vcell.util.document.User("user", new KeyValue("123")), new org.vcell.util.document.GroupAccessNone(), // versionBranchPointRef
        null, // branchID
        new java.math.BigDecimal(1.0), new java.util.Date(), org.vcell.util.document.VersionFlag.Archived, "", null);
        Simulation simulation = new Simulation(simVersion, pdeObjectiveFunction.getMathDescription());
        simulation.getMeshSpecification().setSamplingSize(refData.getDataISize());
        double[] times = refData.getDataByColumn(0);
        double minDt = Double.POSITIVE_INFINITY;
        for (int i = 1; i < times.length; i++) {
            minDt = Math.min(minDt, times[i] - times[i - 1]);
        }
        simulation.getSolverTaskDescription().setTimeBounds(new cbit.vcell.solver.TimeBounds(0.0, refDataEndTime));
        simulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolume);
        simulation.getSolverTaskDescription().setTimeStep(new TimeStep(minDt / 5, minDt / 5, minDt / 5));
        // clone and resample geometry
        Geometry resampledGeometry = null;
        try {
            resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
            GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
            ISize newSize = simulation.getMeshSpecification().getSamplingSize();
            geoSurfaceDesc.setVolumeSampleSize(newSize);
            geoSurfaceDesc.updateAll();
        } catch (Exception e) {
            e.printStackTrace();
            throw new SolverException(e.getMessage());
        }
        SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, pdeObjectiveFunction.getFieldDataIDSs()), 0);
        StringWriter simulationInputStringWriter = new StringWriter();
        FiniteVolumeFileWriter fvFileWriter = new FiniteVolumeFileWriter(new PrintWriter(simulationInputStringWriter, true), simTask, resampledGeometry, pdeObjectiveFunction.getWorkingDirectory());
        fvFileWriter.write(parameterNames);
        simulationInputStringWriter.close();
        modelElement.setAttribute(OptXmlTags.ModelType_Attr, OptXmlTags.ModelType_Attr_FVSOLVER);
        CDATA simulationInputText = new CDATA(simulationInputStringWriter.getBuffer().toString());
        modelElement.addContent(simulationInputText);
    } catch (Exception e) {
        e.printStackTrace(System.out);
        throw new OptimizationException("failed to create fv input file: " + e.getMessage());
    }
    return modelElement;
}
Also used : OptimizationException(cbit.vcell.opt.OptimizationException) KeyValue(org.vcell.util.document.KeyValue) SimulationTask(cbit.vcell.messaging.server.SimulationTask) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) Element(org.jdom.Element) FiniteVolumeFileWriter(cbit.vcell.solvers.FiniteVolumeFileWriter) TimeStep(cbit.vcell.solver.TimeStep) StringWriter(java.io.StringWriter) SpatialReferenceData(cbit.vcell.opt.SpatialReferenceData) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter) Constraint(cbit.vcell.opt.Constraint) OptimizationException(cbit.vcell.opt.OptimizationException) XMLStreamException(javax.xml.stream.XMLStreamException) SBMLException(org.sbml.jsbml.SBMLException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) ExpressionException(cbit.vcell.parser.ExpressionException) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) SolverException(cbit.vcell.solver.SolverException) CDATA(org.jdom.CDATA)

Example 83 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class XmlHelper method simToXML.

public static String simToXML(Simulation sim) throws XmlParseException {
    String simString = null;
    if (sim == null) {
        throw new XmlParseException("Invalid input for Simulation: " + sim);
    }
    Xmlproducer xmlProducer = new Xmlproducer(true);
    // cannot be null
    MathDescription md = sim.getMathDescription();
    Geometry geom = md.getGeometry();
    Element container = new Element(SIM_CONTAINER);
    Element mathElement = xmlProducer.getXML(md);
    Element simElement = xmlProducer.getXML(sim);
    if (geom != null) {
        Element geomElement = xmlProducer.getXML(geom);
        container.addContent(geomElement);
    } else {
        System.err.println("No corresponding geometry for the simulation: " + sim.getName());
    }
    container.addContent(mathElement);
    container.addContent(simElement);
    container = XmlUtil.setDefaultNamespace(container, Namespace.getNamespace(XMLTags.VCML_NS));
    simString = XmlUtil.xmlToString(container);
    return simString;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) MathDescription(cbit.vcell.math.MathDescription) Element(org.jdom.Element)

Example 84 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class XmlHelper method simTaskToXML.

public static String simTaskToXML(SimulationTask simTask) throws XmlParseException {
    String simTaskString = null;
    if (simTask == null) {
        throw new XmlParseException("Invalid input for SimulationTask: " + simTask);
    }
    Xmlproducer xmlProducer = new Xmlproducer(true);
    SimulationJob simJob = simTask.getSimulationJob();
    Simulation sim = simJob.getSimulation();
    Element container = new Element(SimulationTask_tag);
    int taskId = simTask.getTaskID();
    container.setAttribute(TaskId_attr, "" + taskId);
    int jobIndex = simJob.getJobIndex();
    container.setAttribute(JobIndex_attr, "" + jobIndex);
    String computeResource = simTask.getComputeResource();
    if (computeResource != null) {
        Element computeResourceElement = new Element(ComputeResource_tag);
        Text text = new Text(computeResource);
        computeResourceElement.addContent(text);
        container.addContent(computeResourceElement);
    }
    FieldDataIdentifierSpec[] fdisSpecs = simJob.getFieldDataIdentifierSpecs();
    if (fdisSpecs != null) {
        for (FieldDataIdentifierSpec fdisSpec : fdisSpecs) {
            Element fdisElement = new Element(FieldFunctionIdentifierSpec_tag);
            fdisElement.setText(fdisSpec.toCSVString());
            container.addContent(fdisElement);
        }
    }
    MathDescription md = sim.getMathDescription();
    Element mathElement = xmlProducer.getXML(md);
    container.addContent(mathElement);
    Element simElement = xmlProducer.getXML(sim);
    container.addContent(simElement);
    Geometry geom = md.getGeometry();
    if (geom != null) {
        Element geomElement = xmlProducer.getXML(geom);
        container.addContent(geomElement);
    } else {
        System.err.println("No corresponding geometry for the simulation: " + sim.getName());
    }
    container = XmlUtil.setDefaultNamespace(container, Namespace.getNamespace(XMLTags.VCML_NS));
    simTaskString = XmlUtil.xmlToString(container);
    return simTaskString;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) MathDescription(cbit.vcell.math.MathDescription) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) Element(org.jdom.Element) Text(org.jdom.Text) SimulationJob(cbit.vcell.solver.SimulationJob)

Example 85 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class XmlHelper method XMLToGeometry.

static Geometry XMLToGeometry(XMLSource xmlSource, boolean printkeys) throws XmlParseException {
    Geometry geometry = null;
    if (xmlSource == null) {
        throw new XmlParseException("Invalid xml for Geometry.");
    }
    Document xmlDoc = xmlSource.getXmlDoc();
    // NOTES:
    // * The root element can be <Biomodel> (old-style vcml) OR <vcml> (new-style vcml)
    // * With the old-style vcml, the namespace was " "
    // * With the new-style vcml, there is an intermediate stage where the namespace for <vcml> root
    // was set to "http://sourceforge.net/projects/VCell/version0.4" for some models and
    // "http://sourceforge.net/projects/vcell/vcml" for some models; and the namespace for child element
    // <biomdel>, etc. was " "
    // * The final new-style vcml has (should have) the namespace "http://sourceforge.net/projects/vcell/vcml"
    // for <vcml> and all children elements.
    // The code below attempts to take care of this situation.
    Element root = xmlDoc.getRootElement();
    Namespace ns = null;
    if (root.getName().equals(XMLTags.VcmlRootNodeTag)) {
        // NEW WAY - with xml string containing xml declaration, vcml element, namespace, etc ...
        ns = root.getNamespace();
        Element geoRoot = root.getChild(XMLTags.GeometryTag, ns);
        if (geoRoot == null) {
            geoRoot = root.getChild(XMLTags.GeometryTag);
            // geoRoot was null, so obtained the <Geometry> element with namespace " ";
            // Re-set the namespace so that the correct XMLReader constructor is invoked.
            ns = null;
        }
        root = geoRoot;
    }
    // else - root is assumed to be old-style vcml with <Geometry> as root.
    // common for both new-style (with xml declaration, vcml element, etc) and old-style (geometry is root)
    // If namespace is null, xml is the old-style xml with geometry as root, so invoke XMLReader without namespace argument.
    XmlReader reader = null;
    if (ns == null) {
        reader = new XmlReader(printkeys);
    } else {
        reader = new XmlReader(printkeys, ns);
    }
    geometry = reader.getGeometry(root);
    geometry.refreshDependencies();
    return geometry;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) Element(org.jdom.Element) Document(org.jdom.Document) VCDocument(org.vcell.util.document.VCDocument) Namespace(org.jdom.Namespace)

Aggregations

Geometry (cbit.vcell.geometry.Geometry)121 MathDescription (cbit.vcell.math.MathDescription)32 SimulationContext (cbit.vcell.mapping.SimulationContext)31 Simulation (cbit.vcell.solver.Simulation)29 PropertyVetoException (java.beans.PropertyVetoException)24 BioModel (cbit.vcell.biomodel.BioModel)23 DataAccessException (org.vcell.util.DataAccessException)23 VCImage (cbit.image.VCImage)22 SubVolume (cbit.vcell.geometry.SubVolume)21 MathModel (cbit.vcell.mathmodel.MathModel)21 Expression (cbit.vcell.parser.Expression)19 ISize (org.vcell.util.ISize)19 Hashtable (java.util.Hashtable)18 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)17 UserCancelException (org.vcell.util.UserCancelException)17 KeyValue (org.vcell.util.document.KeyValue)17 ImageException (cbit.image.ImageException)16 Extent (org.vcell.util.Extent)16 SurfaceClass (cbit.vcell.geometry.SurfaceClass)15 ExpressionException (cbit.vcell.parser.ExpressionException)15