Search in sources :

Example 6 with VCLogger

use of cbit.util.xml.VCLogger in project vcell by virtualcell.

the class SBMLSpatialTest method test.

// @Test
public void test() throws Exception {
    // BioModel bioModel1 = BioModelTest.getExampleWithImage();
    URL vcmlURL = SBMLSpatialTest.class.getResource("Solver_Suite_6_2.vcml");
    File vcmlFile = new File(vcmlURL.toURI());
    BioModel bioModel1 = XmlHelper.XMLToBioModel(new XMLSource(vcmlFile));
    bioModel1.refreshDependencies();
    // for (int i = 0; i<bioModel1.getNumSimulationContexts(); i++){
    for (int i = 5; i == 5; i++) {
        SimulationContext sc1 = bioModel1.getSimulationContext(i);
        if (sc1.getApplicationType() != Application.NETWORK_DETERMINISTIC) {
            System.err.println(sc1.getName() + " is not a network determistic application");
            continue;
        }
        boolean isSpatial = sc1.getGeometry().getDimension() > 0;
        SBMLExporter exporter = new SBMLExporter(bioModel1, 3, 1, isSpatial);
        sc1.refreshMathDescription(null, NetworkGenerationRequirements.ComputeFullNoTimeout);
        // sc1.setMathDescription(sc1.createNewMathMapping(null, NetworkGenerationRequirements.ComputeFullNoTimeout).getMathDescription());
        exporter.setSelectedSimContext(sc1);
        VCellSBMLDoc sbmlDoc = exporter.convertToSBML();
        for (UnitDefinition unitDefn : sbmlDoc.model.getListOfUnitDefinitions()) {
            for (Unit unit : unitDefn.getListOfUnits()) {
                System.out.println(unit.getKind());
                if (!unit.isSetKind()) {
                    throw new RuntimeException("kind of unit " + unit.printUnit() + " of UnitDefn " + UnitDefinition.printUnits(unitDefn) + " is not set");
                }
            }
        }
        // sbmlDoc.document.setConsistencyChecks(CHECK_CATEGORY.UNITS_CONSISTENCY, false);
        // int numErrors = sbmlDoc.document.checkConsistency();
        // System.out.println("consistency check, num errors = "+numErrors);
        // if (numErrors>0){
        // SBMLErrorLog errorLog = sbmlDoc.document.getListOfErrors();
        // for (int err=0; err<errorLog.getErrorCount(); err++){
        // System.err.println("ERROR IN EXPORTED SBML: "+errorLog.getError(err).getMessage());
        // }
        // //Assert.fail("generated SBML document was found to be inconsistent");
        // }
        String sbmlString = sbmlDoc.xmlString;
        File tempFile = File.createTempFile("sbmlSpatialTest_SBML_", ".sbml.xml");
        FileUtils.write(tempFile, sbmlString);
        System.out.println(tempFile);
        try {
            VCLogger argVCLogger = new TLogger();
            SBMLImporter importer = new SBMLImporter(tempFile.getAbsolutePath(), argVCLogger, isSpatial);
            BioModel bioModel2 = importer.getBioModel();
            File tempFile2 = File.createTempFile("sbmlSpatialTest_Biomodel_", ".vcml.xml");
            FileUtils.write(tempFile2, XmlHelper.bioModelToXML(bioModel2));
            System.out.println(tempFile2);
            // if (true) { throw new RuntimeException("stop"); }
            bioModel2.refreshDependencies();
            SimulationContext sc2 = bioModel2.getSimulationContext(0);
            // sc2.refreshMathDescription(null, NetworkGenerationRequirements.ComputeFullNoTimeout);
            sc2.setMathDescription(sc2.createNewMathMapping(null, NetworkGenerationRequirements.ComputeFullNoTimeout).getMathDescription());
            if (!sc1.getMathDescription().isValid()) {
                throw new RuntimeException("sc1.math is not valid");
            }
            if (!sc2.getMathDescription().isValid()) {
                throw new RuntimeException("sc2.math is not valid");
            }
            MathCompareResults mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), sc1.getMathDescription(), sc2.getMathDescription());
            if (!mathCompareResults.isEquivalent()) {
                System.out.println("MATH DESCRIPTION 1 <UNCHANGED>");
                System.out.println(sc1.getMathDescription().getVCML_database());
                System.out.println("MATH DESCRIPTION 2 <UNCHANGED>");
                System.out.println(sc2.getMathDescription().getVCML_database());
                // if (mathCompareResults.decision  == Decision.MathDifferent_SUBDOMAINS_DONT_MATCH){
                // BioModel bioModel1_copy = XmlHelper.XMLToBioModel(new XMLSource(vcmlFile));
                // bioModel1_copy.refreshDependencies();
                // SimulationContext sc1_copy = bioModel1_copy.getSimulationContext(i);
                // VCImage image = sc1_copy.getGeometry().getGeometrySpec().getImage();
                // if (image!=null){
                // ArrayList<VCPixelClass> pcList = new ArrayList<VCPixelClass>();
                // for (VCPixelClass pc : image.getPixelClasses()){
                // pcList.add(new VCPixelClass(pc.getKey(),SBMLExporter.DOMAIN_TYPE_PREFIX+pc.getPixelClassName(),pc.getPixel()));
                // }
                // image.setPixelClasses(pcList.toArray(new VCPixelClass[0]));
                // }
                // for (GeometryClass gc : sc1_copy.getGeometry().getGeometryClasses()){
                // System.out.println("name before "+gc.getName());
                // gc.setName(SBMLExporter.DOMAIN_TYPE_PREFIX+gc.getName());
                // System.out.println("name after "+gc.getName());
                // }
                // sc1_copy.checkValidity();
                // bioModel1_copy.refreshDependencies();
                // sc1_copy.getGeometry().precomputeAll(new GeometryThumbnailImageFactoryAWT(), true, true);
                // sc1_copy.setMathDescription(sc1_copy.createNewMathMapping(null, NetworkGenerationRequirements.ComputeFullNoTimeout).getMathDescription());
                // MathCompareResults mathCompareResults_renamedSubdomains = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(),sc1_copy.getMathDescription(), sc2.getMathDescription());
                // if (!mathCompareResults_renamedSubdomains.isEquivalent()){
                // System.out.println("MATH DESCRIPTION 1 <RENAMED>");
                // System.out.println(sc1_copy.getMathDescription().getVCML_database());
                // Assert.fail(mathCompareResults_renamedSubdomains.decision+" "+mathCompareResults_renamedSubdomains.details);
                // }
                // }else{
                System.err.println(mathCompareResults.decision + " " + mathCompareResults.details);
            // }
            } else {
                System.out.println("MATHS WERE EQUIVALENT");
            }
        } finally {
            tempFile.delete();
        }
    }
    // loop over determinstic applications
    System.out.println("done");
}
Also used : SBMLImporter(org.vcell.sbml.vcell.SBMLImporter) SBMLExporter(org.vcell.sbml.vcell.SBMLExporter) SimulationContext(cbit.vcell.mapping.SimulationContext) Unit(org.sbml.jsbml.Unit) URL(java.net.URL) BioModel(cbit.vcell.biomodel.BioModel) VCellSBMLDoc(org.vcell.sbml.vcell.SBMLExporter.VCellSBMLDoc) MathCompareResults(cbit.vcell.math.MathCompareResults) File(java.io.File) XMLSource(cbit.vcell.xml.XMLSource) UnitDefinition(org.sbml.jsbml.UnitDefinition) VCLogger(cbit.util.xml.VCLogger)

Aggregations

VCLogger (cbit.util.xml.VCLogger)6 BioModel (cbit.vcell.biomodel.BioModel)5 File (java.io.File)5 SBMLImporter (org.vcell.sbml.vcell.SBMLImporter)4 IOException (java.io.IOException)3 SimulationContext (cbit.vcell.mapping.SimulationContext)2 XMLSource (cbit.vcell.xml.XMLSource)2 TranslationLogger (cbit.vcell.client.TranslationLogger)1 UnitSystemSelectionPanel (cbit.vcell.client.desktop.biomodel.UnitSystemSelectionPanel)1 StructureMapping (cbit.vcell.mapping.StructureMapping)1 MathCompareResults (cbit.vcell.math.MathCompareResults)1 MathDescription (cbit.vcell.math.MathDescription)1 DistributedKinetics (cbit.vcell.model.DistributedKinetics)1 Kinetics (cbit.vcell.model.Kinetics)1 LumpedKinetics (cbit.vcell.model.LumpedKinetics)1 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)1 ReactionStep (cbit.vcell.model.ReactionStep)1 Structure (cbit.vcell.model.Structure)1 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)1 Simulation (cbit.vcell.solver.Simulation)1