Search in sources :

Example 31 with XmlParseException

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

the class VCellClientDataServiceImpl method getSimsFromOpenModels.

@Override
public List<SimulationDataSetRef> getSimsFromOpenModels() {
    ArrayList<SimulationDataSetRef> simulationDataSetRefs = new ArrayList<SimulationDataSetRef>();
    for (TopLevelWindowManager windowManager : vcellClient.getMdiManager().getWindowManagers()) {
        Simulation[] simulations = null;
        VCDocument modelDocument = null;
        if (windowManager instanceof BioModelWindowManager) {
            BioModelWindowManager selectedBioWindowManager = (BioModelWindowManager) windowManager;
            BioModel bioModel = selectedBioWindowManager.getBioModel();
            simulations = bioModel.getSimulations();
            modelDocument = bioModel;
        // simOwnerCount = bioModel.getNumSimulationContexts();
        } else if (windowManager instanceof MathModelWindowManager) {
            MathModelWindowManager selectedMathWindowManager = (MathModelWindowManager) windowManager;
            MathModel mathModel = selectedMathWindowManager.getMathModel();
            simulations = mathModel.getSimulations();
            modelDocument = mathModel;
        // simOwnerCount = 1;
        }
        if (simulations != null) {
            for (Simulation simulation : simulations) {
                if (!isVtkSupported(simulation)) {
                    continue;
                }
                Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
                Extent extent = simulation.getMathDescription().getGeometry().getExtent();
                SimulationInfo simInfo = simulation.getSimulationInfo();
                SimulationStatus simStatus = vcellClient.getRequestManager().getServerSimulationStatus(simInfo);
                for (int jobIndex = 0; jobIndex < simulation.getScanCount(); jobIndex++) {
                    if (simStatus != null && simStatus.getHasData()) {
                        SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simulation, modelDocument, jobIndex, false);
                        simulationDataSetRefs.add(simulationDataSetReference);
                    }
                }
            }
        }
    }
    File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
    String[] simtaskFilenames = localSimDir.list((dir, name) -> (name.endsWith(".simtask.xml")));
    for (String simtaskFilename : simtaskFilenames) {
        try {
            SimulationTask simTask = XmlHelper.XMLToSimTask(org.apache.commons.io.FileUtils.readFileToString(new File(localSimDir, simtaskFilename)));
            VCDocument modelDocument = null;
            SimulationDataSetRef simulationDataSetReference = VCellClientDataServiceImpl.createSimulationDataSetRef(simTask.getSimulation(), modelDocument, simTask.getSimulationJob().getJobIndex(), true);
            simulationDataSetRefs.add(simulationDataSetReference);
        } catch (ExpressionException | XmlParseException | IOException e) {
            e.printStackTrace();
        }
    }
    return simulationDataSetRefs;
}
Also used : Origin(org.vcell.util.Origin) MathModel(cbit.vcell.mathmodel.MathModel) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) Extent(org.vcell.util.Extent) ArrayList(java.util.ArrayList) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) MathModelWindowManager(cbit.vcell.client.MathModelWindowManager) ExpressionException(cbit.vcell.parser.ExpressionException) Simulation(cbit.vcell.solver.Simulation) BioModelWindowManager(cbit.vcell.client.BioModelWindowManager) SimulationStatus(cbit.vcell.server.SimulationStatus) BioModel(cbit.vcell.biomodel.BioModel) File(java.io.File) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 32 with XmlParseException

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

the class HTCSolver method writeJavaInputFile.

protected void writeJavaInputFile() throws SolverException {
    PrintWriter pw = null;
    try {
        File inputFile = new File(getBaseName() + JAVA_INPUT_EXTENSION);
        if (!inputFile.exists()) {
            // write input file which is just xml
            String xmlString = XmlHelper.simToXML(simTask.getSimulation());
            pw = new PrintWriter(inputFile);
            pw.println(xmlString);
            pw.close();
        }
    } catch (XmlParseException e) {
        e.printStackTrace(System.out);
        throw new SolverException(e.getMessage());
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.out);
        throw new SolverException(e.getMessage());
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}
Also used : FileNotFoundException(java.io.FileNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 33 with XmlParseException

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

the class StochtestCompareService method compareOne.

public void compareOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
    StochtestCompare stochtestCompare = StochtestDbUtils.acceptNextWaitingStochtestCompare(conFactory);
    String biomodelXML = null;
    if (stochtestCompare != null) {
        try {
            StochtestRun stochtestRun1 = StochtestDbUtils.getStochtestRun(conFactory, stochtestCompare.stochtestRun1ref);
            StochtestRun stochtestRun2 = StochtestDbUtils.getStochtestRun(conFactory, stochtestCompare.stochtestRun2ref);
            if (stochtestRun1.status != StochtestRunStatus.complete) {
                throw new RuntimeException("incomplete run status found: " + stochtestRun1.status.name());
            }
            if (stochtestRun2.status != StochtestRunStatus.complete) {
                throw new RuntimeException("incomplete run status found: " + stochtestRun2.status.name());
            }
            TimeSeriesMultitrialData data1 = StochtestFileUtils.readData(StochtestFileUtils.getStochtestRunDataFile(baseDir, stochtestRun1));
            TimeSeriesMultitrialData data2 = StochtestFileUtils.readData(StochtestFileUtils.getStochtestRunDataFile(baseDir, stochtestRun2));
            SummaryStatistics results = TimeSeriesMultitrialData.statisticsSummary(data1, data2);
            XmlUtil.writeXMLStringToFile(results.results(), new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_summary.txt").getPath(), false);
            StochtestFileUtils.writeVarDiffData(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_vardiff.csv"), data1, data2);
            StochtestFileUtils.writeKolmogorovSmirnovTest(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_kolmogorovSmirnov.csv"), data1, data2);
            StochtestFileUtils.writeChiSquareTest(new File(baseDir, "stochtestcompare_" + stochtestCompare.key + "_chiSquared.csv"), data1, data2);
            StochtestCompareStatus status = (results.pass()) ? StochtestCompareStatus.not_verydifferent : StochtestCompareStatus.verydifferent;
            StochtestDbUtils.finalizeAcceptedStochtestCompare(conFactory, stochtestCompare, status, null, results);
        } catch (Exception e) {
            StochtestDbUtils.finalizeAcceptedStochtestCompare(conFactory, stochtestCompare, StochtestCompare.StochtestCompareStatus.failed, e.getMessage(), null);
            // 
            // write exception trace to .txt file
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            e.printStackTrace(printWriter);
            printWriter.flush();
            System.out.println(stringWriter.getBuffer().toString());
            XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestCompare.key + "_error.txt").getPath(), false);
        }
    } else {
        System.out.println("no compare jobs waiting");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : StochtestCompareStatus(org.vcell.stochtest.StochtestCompare.StochtestCompareStatus) StringWriter(java.io.StringWriter) SummaryStatistics(org.vcell.stochtest.TimeSeriesMultitrialData.SummaryStatistics) File(java.io.File) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) PropertyVetoException(java.beans.PropertyVetoException) MappingException(cbit.vcell.mapping.MappingException) SQLException(java.sql.SQLException) GeometryException(cbit.vcell.geometry.GeometryException) XmlParseException(cbit.vcell.xml.XmlParseException) PrintWriter(java.io.PrintWriter)

Example 34 with XmlParseException

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

the class StochtestRunService method runOne.

public void runOne() throws IllegalArgumentException, SQLException, DataAccessException, XmlParseException, PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException, IOException {
    StochtestRun stochtestRun = StochtestDbUtils.acceptNextWaitingStochtestRun(conFactory);
    String biomodelXML = null;
    if (stochtestRun != null) {
        String networkGenProbs = null;
        try {
            User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
            ServerDocumentManager serverDocumentManager = new ServerDocumentManager(this.dbServerImpl);
            biomodelXML = serverDocumentManager.getBioModelXML(new QueryHashtable(), user, stochtestRun.stochtest.biomodelRef, true);
            BioModel bioModel = XmlHelper.XMLToBioModel(new XMLSource(biomodelXML));
            bioModel.refreshDependencies();
            SimulationContext srcSimContext = null;
            for (SimulationContext sc : bioModel.getSimulationContexts()) {
                if (sc.getKey().equals(stochtestRun.stochtest.simContextRef)) {
                    srcSimContext = sc;
                }
            }
            if (srcSimContext == null) {
                throw new RuntimeException("cannot find simcontext with key=" + stochtestRun.stochtest.simContextRef);
            }
            // 
            for (SpeciesContextSpec scs : srcSimContext.getReactionContext().getSpeciesContextSpecs()) {
                scs.setConstant(false);
            }
            SimulationContext simContext = srcSimContext;
            StochtestMathType parentMathType = stochtestRun.parentMathType;
            StochtestMathType mathType = stochtestRun.mathType;
            if (parentMathType != mathType) {
                if (parentMathType == StochtestMathType.nonspatialstochastic && mathType == StochtestMathType.rules) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedRules", false, Application.RULE_BASED_STOCHASTIC);
                } else if (parentMathType == StochtestMathType.rules && mathType == StochtestMathType.nonspatialstochastic) {
                    simContext = SimulationContext.copySimulationContext(srcSimContext, "generatedSSA", false, Application.NETWORK_STOCHASTIC);
                } else {
                    throw new RuntimeException("unexpected copy of simcontext from " + parentMathType + " to " + mathType);
                }
                bioModel.addSimulationContext(simContext);
            }
            MathMappingCallback mathMappingCallback = new MathMappingCallback() {

                @Override
                public void setProgressFraction(float fractionDone) {
                }

                @Override
                public void setMessage(String message) {
                }

                @Override
                public boolean isInterrupted() {
                    return false;
                }
            };
            MathMapping mathMapping = simContext.createNewMathMapping(mathMappingCallback, NetworkGenerationRequirements.ComputeFullStandardTimeout);
            MathDescription mathDesc = mathMapping.getMathDescription(mathMappingCallback);
            simContext.setMathDescription(mathDesc);
            if (simContext.isInsufficientIterations()) {
                networkGenProbs = "insufficientIterations";
            } else if (simContext.isInsufficientMaxMolecules()) {
                networkGenProbs = "insufficientMaxMolecules";
            }
            File baseDirectory = StochtestFileUtils.createDirFile(baseDir, stochtestRun);
            try {
                OutputTimeSpec outputTimeSpec = new UniformOutputTimeSpec(0.5);
                double endTime = 10.0;
                computeTrials(simContext, stochtestRun, baseDirectory, outputTimeSpec, endTime, numTrials);
                StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.complete, null, networkGenProbs);
            } finally {
                StochtestFileUtils.clearDir(baseDirectory);
            }
        } catch (Exception e) {
            StochtestDbUtils.finalizeAcceptedStochtestRun(conFactory, stochtestRun, StochtestRun.StochtestRunStatus.failed, e.getMessage(), networkGenProbs);
            // 
            if (biomodelXML != null) {
                XmlUtil.writeXMLStringToFile(biomodelXML, new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + ".vcml").getPath(), false);
            }
            // 
            // write exception trace to .txt file
            // 
            StringWriter stringWriter = new StringWriter();
            PrintWriter printWriter = new PrintWriter(stringWriter);
            e.printStackTrace(printWriter);
            printWriter.flush();
            System.out.println(stringWriter.getBuffer().toString());
            XmlUtil.writeXMLStringToFile(stringWriter.getBuffer().toString(), new File(baseDir, "stochtestrun_" + stochtestRun.stochtest.key + "_error.txt").getPath(), false);
        }
    } else {
        System.out.println("no jobs waiting");
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : QueryHashtable(cbit.sql.QueryHashtable) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) MathMappingCallback(cbit.vcell.mapping.SimulationContext.MathMappingCallback) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) MathDescription(cbit.vcell.math.MathDescription) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) ServerDocumentManager(cbit.vcell.modeldb.ServerDocumentManager) PropertyVetoException(java.beans.PropertyVetoException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) GeometryException(cbit.vcell.geometry.GeometryException) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) StringWriter(java.io.StringWriter) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping) XMLSource(cbit.vcell.xml.XMLSource) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 35 with XmlParseException

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

the class MicroscopyXmlReader method getUShortImage.

/**
 * This method returns a VCIMage object from a XML representation.
 * Creation date: (3/16/2001 3:41:24 PM)
 * @param param org.jdom.Element
 * @return VCImage
 * @throws XmlParseException
 */
private UShortImage getUShortImage(Element param) throws XmlParseException {
    // get the attributes
    Element tempelement = param.getChild(XMLTags.ImageDataTag);
    int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
    int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
    int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
    int compressSize = Integer.parseInt(tempelement.getAttributeValue(XMLTags.CompressedSizeTag));
    final int BYTES_PER_SHORT = 2;
    int UNCOMPRESSED_SIZE_BYTES = aNumX * aNumY * aNumZ * BYTES_PER_SHORT;
    // getpixels
    String hexEncodedBytes = tempelement.getText();
    byte[] rawBytes = org.vcell.util.Hex.toBytes(hexEncodedBytes);
    ByteArrayInputStream rawByteArrayInputStream = new ByteArrayInputStream(rawBytes);
    InputStream rawInputStream = rawByteArrayInputStream;
    if (compressSize != UNCOMPRESSED_SIZE_BYTES) {
        rawInputStream = new InflaterInputStream(rawByteArrayInputStream);
    }
    byte[] shortsAsBytes = new byte[UNCOMPRESSED_SIZE_BYTES];
    int readCount = 0;
    try {
        while ((readCount += rawInputStream.read(shortsAsBytes, readCount, shortsAsBytes.length - readCount)) != shortsAsBytes.length) {
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image pixels: ", e);
    } finally {
        if (rawInputStream != null) {
            try {
                rawInputStream.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
    ByteBuffer byteBuffer = ByteBuffer.wrap(shortsAsBytes);
    short[] shortPixels = new short[aNumX * aNumY * aNumZ];
    for (int i = 0; i < shortPixels.length; i++) {
        shortPixels[i] = byteBuffer.getShort();
    }
    Element extentElement = param.getChild(XMLTags.ExtentTag);
    Extent extent = null;
    if (extentElement != null) {
        extent = vcellXMLReader.getExtent(extentElement);
    }
    Element originElement = param.getChild(XMLTags.OriginTag);
    Origin origin = null;
    if (originElement != null) {
        origin = vcellXMLReader.getOrigin(originElement);
    }
    // //set attributes
    // String name = this.unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
    // String annotation = param.getChildText(XMLTags.AnnotationTag);
    UShortImage newimage;
    try {
        newimage = new UShortImage(shortPixels, origin, extent, aNumX, aNumY, aNumZ);
    } catch (ImageException e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image", e);
    }
    return newimage;
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) XmlParseException(cbit.vcell.xml.XmlParseException) ByteBuffer(java.nio.ByteBuffer) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

XmlParseException (cbit.vcell.xml.XmlParseException)49 DataAccessException (org.vcell.util.DataAccessException)35 XMLSource (cbit.vcell.xml.XMLSource)19 BigString (org.vcell.util.BigString)18 BioModel (cbit.vcell.biomodel.BioModel)16 KeyValue (org.vcell.util.document.KeyValue)16 SQLException (java.sql.SQLException)14 ExpressionException (cbit.vcell.parser.ExpressionException)12 IOException (java.io.IOException)12 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)11 SimulationContext (cbit.vcell.mapping.SimulationContext)10 PrintWriter (java.io.PrintWriter)9 User (org.vcell.util.document.User)9 MathException (cbit.vcell.math.MathException)8 MathModel (cbit.vcell.mathmodel.MathModel)8 Element (org.jdom.Element)8 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)8 BioModelInfo (org.vcell.util.document.BioModelInfo)7 PropertyVetoException (java.beans.PropertyVetoException)5 File (java.io.File)5