Search in sources :

Example 1 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class PDEExportDataPanel method createSimulationSelector.

private ExportSpecs.SimulationSelector createSimulationSelector() {
    ExportSpecs.SimulationSelector simulationSelector = new ExportSpecs.SimulationSelector() {

        private ExportSpecs.SimNameSimDataID[] multiSimNameSimDataIDs;

        // private ExportSpecs.ExportParamScanInfo exportParamScanInfo;
        private int[] selectedParamScanIndexes;

        private Simulation[] simulations;

        public SimNameSimDataID[] getSelectedSimDataInfo() {
            // }
            if (multiSimNameSimDataIDs == null) {
                return new ExportSpecs.SimNameSimDataID[] { currentSimNameSimDataID };
            }
            return multiSimNameSimDataIDs;
        }

        public void selectSimulations() {
            getNumAvailableSimulations();
            String[][] rowData = new String[simulations.length][5];
            for (int i = 0; i < rowData.length; i++) {
                rowData[i][0] = simulations[i].getName();
                rowData[i][1] = simulations[i].getMeshSpecification().getSamplingSize().toString();
                rowData[i][2] = simulations[i].getSolverTaskDescription().getExpectedNumTimePoints() + "";
                rowData[i][3] = simulations[i].getSolverTaskDescription().getTimeBounds().getEndingTime() + "";
                rowData[i][4] = simulations[i].getSolverTaskDescription().getOutputTimeSpec().getShortDescription();
            }
            try {
                int[] choices = DialogUtils.showComponentOKCancelTableList(PDEExportDataPanel.this, "Choose Sims to export together", new String[] { "Simulation", "Mesh x,y,z", "NumTimePoints", "EndTime", "Output Descr." }, rowData, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
                if (choices != null) {
                    multiSimNameSimDataIDs = new ExportSpecs.SimNameSimDataID[choices.length];
                    for (int i = 0; i < choices.length; i++) {
                        multiSimNameSimDataIDs[i] = new ExportSpecs.SimNameSimDataID(simulations[choices[i]].getName(), simulations[choices[i]].getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), SimResultsViewer.getParamScanInfo(simulations[choices[i]], (currentSimNameSimDataID == null ? 0 : currentSimNameSimDataID.getDefaultJobIndex())));
                    }
                }
            } catch (UserCancelException uce) {
            // ignore
            }
        }

        public void selectParamScanInfo() {
            String[][] rowData = new String[currentSimNameSimDataID.getExportParamScanInfo().getParamScanJobIndexes().length][currentSimNameSimDataID.getExportParamScanInfo().getParamScanConstantNames().length];
            for (int i = 0; i < rowData.length; i++) {
                for (int j = 0; j < rowData[i].length; j++) {
                    rowData[i][j] = currentSimNameSimDataID.getExportParamScanInfo().getParamScanConstantValues()[i][j];
                }
            }
            try {
                int[] choices = DialogUtils.showComponentOKCancelTableList(PDEExportDataPanel.this, "Choose ParameterScans to export together", currentSimNameSimDataID.getExportParamScanInfo().getParamScanConstantNames(), rowData, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
                if (choices != null && choices.length > 0) {
                    selectedParamScanIndexes = new int[choices.length];
                    // String[][] selectedParamScanValues = new String[choices.length][currentSimNameSimDataID.getExportParamScanInfo().getParamScanConstantNames().length];
                    for (int i = 0; i < choices.length; i++) {
                        selectedParamScanIndexes[i] = choices[i];
                    // for (int j = 0; j < currentSimNameSimDataID.getExportParamScanInfo().getParamScanConstantNames().length; j++) {
                    // selectedParamScanValues[i][j] = currentSimNameSimDataID.getExportParamScanInfo().getParamScanConstantValues()[choices[i]][j];
                    // }
                    }
                // exportParamScanInfo =
                // new ExportSpecs.ExportParamScanInfo(selectedParamScanIndexes, selectedParamScanIndexes[0], currentSimNameSimDataID.getExportParamScanInfo().getParamScanConstantNames(), selectedParamScanValues);
                } else {
                    selectedParamScanIndexes = null;
                }
            } catch (UserCancelException uce) {
            // ignore
            }
        }

        public int[] getselectedParamScanIndexes() {
            return selectedParamScanIndexes;
        }

        public int getNumAvailableParamScans() {
            if (currentSimNameSimDataID == null || currentSimNameSimDataID.getExportParamScanInfo() == null) {
                return 0;
            }
            return currentSimNameSimDataID.getExportParamScanInfo().getParamScanJobIndexes().length;
        }

        public int getNumAvailableSimulations() {
            if (simulations == null) {
                VCDocument thisDocument = (getDataViewerManager() instanceof DocumentWindowManager ? ((DocumentWindowManager) getDataViewerManager()).getVCDocument() : null);
                if (thisDocument instanceof BioModel) {
                    String thisSimContextName = dataInfoProvider.getSimulationModelInfo().getContextName();
                    SimulationContext[] simContexts = ((BioModel) thisDocument).getSimulationContexts();
                    SimulationContext thisSimulationContext = null;
                    for (int i = 0; i < simContexts.length; i++) {
                        if (thisSimContextName.equals(thisDocument.getName() + "::" + simContexts[i].getName())) {
                            thisSimulationContext = simContexts[i];
                            break;
                        }
                    }
                    simulations = thisSimulationContext.getSimulations();
                } else if (thisDocument instanceof MathModel) {
                    simulations = ((MathModel) thisDocument).getSimulations();
                } else {
                    simulations = new Simulation[0];
                }
            }
            return simulations.length;
        }
    };
    return simulationSelector;
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCDocument(org.vcell.util.document.VCDocument) ExportSpecs(cbit.vcell.export.server.ExportSpecs) UserCancelException(org.vcell.util.UserCancelException) SimulationContext(cbit.vcell.mapping.SimulationContext) SimNameSimDataID(cbit.vcell.export.server.ExportSpecs.SimNameSimDataID) Simulation(cbit.vcell.solver.Simulation) SimNameSimDataID(cbit.vcell.export.server.ExportSpecs.SimNameSimDataID) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) BioModel(cbit.vcell.biomodel.BioModel)

Example 2 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class ClientRequestManager method newDocument.

/**
 * Insert the method's description here.
 * Creation date: (5/21/2004 4:20:47 AM)
 * @param documentType int
 */
public AsynchClientTask[] newDocument(TopLevelWindowManager requester, final VCDocument.DocumentCreationInfo documentCreationInfo) {
    // gcwtodo
    AsynchClientTask createNewDocumentTask = new AsynchClientTask("Creating New Document", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            VCDocument doc = (VCDocument) hashTable.get("doc");
            DocumentWindowManager windowManager = createDocumentWindowManager(doc);
            DocumentWindow dw = getMdiManager().createNewDocumentWindow(windowManager);
            if (windowManager != null) {
                hashTable.put("windowManager", windowManager);
            }
            setFinalWindow(hashTable, dw);
        }
    };
    if (documentCreationInfo.getDocumentType() == VCDocumentType.MATHMODEL_DOC && documentCreationInfo.getOption() == VCDocument.MATH_OPTION_SPATIAL_NEW) {
        final AsynchClientTask createSpatialMathModelTask = new AsynchClientTask("creating mathmodel", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                Geometry geometry = null;
                geometry = (Geometry) hashTable.get("doc");
                MathModel mathModel = createMathModel("Untitled", geometry);
                mathModel.setName("MathModel" + (getMdiManager().getNumCreatedDocumentWindows() + 1));
                hashTable.put("doc", mathModel);
            }
        };
        requester.createGeometry(null, new AsynchClientTask[] { createSpatialMathModelTask, createNewDocumentTask }, "Choose geometry type to start MathModel creation", "Create MathModel", null);
        return null;
    }
    /* asynchronous and not blocking any window */
    AsynchClientTask[] taskArray = null;
    if (documentCreationInfo.getPreCreatedDocument() == null) {
        AsynchClientTask[] taskArray1 = createNewDocument(requester, documentCreationInfo);
        taskArray = new AsynchClientTask[taskArray1.length + 1];
        System.arraycopy(taskArray1, 0, taskArray, 0, taskArray1.length);
    } else {
        taskArray = new AsynchClientTask[2];
        taskArray[0] = new AsynchClientTask("Setting document...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                hashTable.put("doc", documentCreationInfo.getPreCreatedDocument());
            }
        };
    }
    taskArray[taskArray.length - 1] = createNewDocumentTask;
    return taskArray;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathModel(cbit.vcell.mathmodel.MathModel) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) 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) DocumentWindow(cbit.vcell.client.desktop.DocumentWindow) Geometry(cbit.vcell.geometry.Geometry) CSGObject(cbit.vcell.geometry.CSGObject)

Example 3 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class ClientRequestManager method changeGeometry0.

private void changeGeometry0(final TopLevelWindowManager requester, final SimulationContext simContext) {
    AsynchClientTask selectDocumentTypeTask = createSelectDocTask(requester);
    AsynchClientTask selectLoadGeomTask = createSelectLoadGeomTask(requester);
    AsynchClientTask processGeometryTask = new AsynchClientTask("Processing geometry...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Geometry newGeometry = (Geometry) hashTable.get(GEOMETRY_KEY);
            if (requester instanceof MathModelWindowManager) {
                // User can cancel here
                continueAfterMathModelGeomChangeWarning((MathModelWindowManager) requester, newGeometry);
            }
            if (newGeometry.getDimension() > 0 && newGeometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
                newGeometry.getGeometrySurfaceDescription().updateAll();
            }
        }
    };
    AsynchClientTask setNewGeometryTask = new AsynchClientTask("Setting new Geometry...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Geometry newGeometry = (Geometry) hashTable.get(GEOMETRY_KEY);
            if (newGeometry != null) {
                if (requester instanceof BioModelWindowManager) {
                    simContext.setGeometry(newGeometry);
                } else if (requester instanceof MathModelWindowManager) {
                    MathModel mathModel = (MathModel) ((MathModelWindowManager) requester).getVCDocument();
                    mathModel.getMathDescription().setGeometry(newGeometry);
                }
            }
        }
    };
    Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
    ClientTaskDispatcher.dispatch(requester.getComponent(), hashTable, new AsynchClientTask[] { selectDocumentTypeTask, selectLoadGeomTask, processGeometryTask, setNewGeometryTask }, false);
}
Also used : Geometry(cbit.vcell.geometry.Geometry) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) MathModel(cbit.vcell.mathmodel.MathModel) Hashtable(java.util.Hashtable) CSGObject(cbit.vcell.geometry.CSGObject)

Example 4 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class ClientRequestManager method createMathModel.

/**
 * Insert the method's description here.
 * Creation date: (5/24/2004 12:22:11 PM)
 * @param windowID java.lang.String
 */
private MathModel createMathModel(String name, Geometry geometry) {
    MathModel mathModel = new MathModel(null);
    MathDescription mathDesc = mathModel.getMathDescription();
    try {
        mathDesc.setGeometry(geometry);
        if (geometry.getDimension() == 0) {
            mathDesc.addSubDomain(new CompartmentSubDomain("Compartment", CompartmentSubDomain.NON_SPATIAL_PRIORITY));
        } else {
            try {
                if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
                    geometry.getGeometrySurfaceDescription().updateAll();
                }
            } catch (ImageException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("Geometric surface generation error: \n" + e.getMessage());
            } catch (GeometryException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException("Geometric surface generation error: \n" + e.getMessage());
            }
            SubVolume[] subVolumes = geometry.getGeometrySpec().getSubVolumes();
            for (int i = 0; i < subVolumes.length; i++) {
                mathDesc.addSubDomain(new CompartmentSubDomain(subVolumes[i].getName(), subVolumes[i].getHandle()));
            }
            // 
            // add only those MembraneSubDomains corresponding to surfaces that acutally exist in geometry.
            // 
            GeometricRegion[] regions = geometry.getGeometrySurfaceDescription().getGeometricRegions();
            for (int i = 0; i < regions.length; i++) {
                if (regions[i] instanceof SurfaceGeometricRegion) {
                    SurfaceGeometricRegion surfaceRegion = (SurfaceGeometricRegion) regions[i];
                    SubVolume subVolume1 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[0]).getSubVolume();
                    SubVolume subVolume2 = ((VolumeGeometricRegion) surfaceRegion.getAdjacentGeometricRegions()[1]).getSubVolume();
                    CompartmentSubDomain compartment1 = mathDesc.getCompartmentSubDomain(subVolume1.getName());
                    CompartmentSubDomain compartment2 = mathDesc.getCompartmentSubDomain(subVolume2.getName());
                    MembraneSubDomain membraneSubDomain = mathDesc.getMembraneSubDomain(compartment1, compartment2);
                    if (membraneSubDomain == null) {
                        SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(subVolume1, subVolume2);
                        membraneSubDomain = new MembraneSubDomain(compartment1, compartment2, surfaceClass.getName());
                        mathDesc.addSubDomain(membraneSubDomain);
                    }
                }
            }
        }
        mathDesc.isValid();
        mathModel.setName(name);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
    return mathModel;
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) ImageException(cbit.image.ImageException) SetMathDescription(cbit.vcell.client.task.SetMathDescription) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) GeometryException(cbit.vcell.geometry.GeometryException) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) 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) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 5 with MathModel

use of cbit.vcell.mathmodel.MathModel in project vcell by virtualcell.

the class MathModel_SBMLExporter method getSBMLString.

/**
 * Insert the method's description here.
 * Creation date: (4/11/2006 11:38:26 AM)
 * @return org.sbml.libsbml.Model
 * @param mathModel cbit.vcell.mathmodel.MathModel
 * @throws XMLStreamException
 * @throws SBMLException
 */
public static String getSBMLString(cbit.vcell.mathmodel.MathModel mathModel, long level, long version) throws cbit.vcell.parser.ExpressionException, java.io.IOException, SBMLException, XMLStreamException {
    if (mathModel.getMathDescription().isSpatial()) {
        throw new RuntimeException("spatial models export to SBML not supported");
    }
    if (mathModel.getMathDescription().hasFastSystems()) {
        throw new RuntimeException("math models with fast systems cannot be exported to SBML");
    }
    if (mathModel.getMathDescription().isNonSpatialStoch()) {
        throw new RuntimeException("stochastic math models cannot be exported to SBML");
    }
    if (!mathModel.getMathDescription().isValid()) {
        throw new RuntimeException("math model has an invalid Math Description, cannot export to SBML");
    }
    String dummyID = "ID_0";
    String compartmentId = "compartment";
    SBMLDocument sbmlDocument = new SBMLDocument((int) level, (int) version);
    Model sbmlModel = sbmlDocument.createModel();
    sbmlModel.setId("MathModel_" + TokenMangler.mangleToSName(mathModel.getName()));
    if (mathModel.getMathDescription().isSpatial()) {
        addGeometry(sbmlModel, mathModel);
    }
    Compartment compartment = sbmlModel.createCompartment();
    compartment.setId(compartmentId);
    // ------ For spatial SBML when implemented -----
    // if (vcMathModel.getMathDescription().isSpatial()){
    // // for spatial model, compartment(s) created in addGeometry(), based on number of subVolumes/surfaceClasses.
    // addGeometry();
    // } else {
    // // for non-spatial mathmodel, only 1 compartment; create it here.
    // String compartmentId = "compartment";
    // org.sbml.libsbml.Compartment compartment = sbmlModel.createCompartment();
    // compartment.setId(compartmentId);
    // }
    MathDescription mathDesc = mathModel.getMathDescription();
    Enumeration<Variable> enumVars = mathDesc.getVariables();
    while (enumVars.hasMoreElements()) {
        Variable vcVar = (Variable) enumVars.nextElement();
        // 
        if (vcVar instanceof cbit.vcell.math.VolVariable) {
        // 
        // skip for now, define later when defining ODEEquations.
        // 
        // org.sbml.libsbml.Species species = model.createSpecies();
        // species.setId(vcVar.getName());
        // species.setCompartment(compartmentId);
        } else if (vcVar instanceof cbit.vcell.math.Constant && ((cbit.vcell.math.Constant) vcVar).getExpression().isNumeric()) {
            Parameter param = sbmlModel.createParameter();
            param.setId(TokenMangler.mangleToSName(vcVar.getName()));
            param.setConstant(true);
            param.setValue(vcVar.getExpression().evaluateConstant());
        } else if (vcVar instanceof cbit.vcell.math.Constant || vcVar instanceof cbit.vcell.math.Function) {
            Parameter param = sbmlModel.createParameter();
            param.setId(TokenMangler.mangleToSName(vcVar.getName()));
            param.setConstant(false);
            // 
            // Function or Constant with expressions - create assignment rule and add to model.
            // 
            ASTNode mathNode = getFormulaFromExpression(vcVar.getExpression(), MathType.REAL);
            AssignmentRule assignmentRule = sbmlModel.createAssignmentRule();
            dummyID = TokenMangler.getNextEnumeratedToken(dummyID);
            assignmentRule.setId(dummyID);
            assignmentRule.setVariable(TokenMangler.mangleToSName(vcVar.getName()));
            assignmentRule.setMath(mathNode);
        // Create a parameter for this function/non-numeric constant, set its value to be 'not-constant',
        // add to model.
        }
    }
    cbit.vcell.math.CompartmentSubDomain subDomain = (cbit.vcell.math.CompartmentSubDomain) mathDesc.getSubDomains().nextElement();
    // System.out.println(model.toSBML());
    Enumeration<Equation> enumEqu = subDomain.getEquations();
    while (enumEqu.hasMoreElements()) {
        cbit.vcell.math.Equation equ = (cbit.vcell.math.Equation) enumEqu.nextElement();
        if (equ instanceof cbit.vcell.math.OdeEquation) {
            // For ODE equations, add the ode variable as a parameter, add rate as a rate rule and init condition as an initial assignment rule.
            Parameter param = sbmlModel.createParameter();
            param.setId(TokenMangler.mangleToSName(equ.getVariable().getName()));
            param.setConstant(false);
            // try to obtain the constant to which the init expression evaluates.
            RateRule rateRule = sbmlModel.createRateRule();
            rateRule.setVariable(TokenMangler.mangleToSName(equ.getVariable().getName()));
            rateRule.setMath(getFormulaFromExpression(equ.getRateExpression(), MathType.REAL));
            InitialAssignment initialAssignment = sbmlModel.createInitialAssignment();
            dummyID = TokenMangler.getNextEnumeratedToken(dummyID);
            initialAssignment.setId(dummyID);
            initialAssignment.setMath(getFormulaFromExpression(equ.getInitialExpression(), MathType.REAL));
            initialAssignment.setVariable(TokenMangler.mangleToSName(equ.getVariable().getName()));
        } else {
            throw new RuntimeException("equation type " + equ.getClass().getName() + " not supported");
        }
    }
    Iterator<Event> vcellEvents = mathDesc.getEvents();
    while (vcellEvents.hasNext()) {
        Event vcellEvent = vcellEvents.next();
        addSbmlEvent(sbmlModel, vcellEvent);
    }
    System.out.println(new SBMLWriter().writeSBMLToString(sbmlDocument));
    // validate the sbml document
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.GENERAL_CONSISTENCY, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.IDENTIFIER_CONSISTENCY, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.MATHML_CONSISTENCY, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.MODELING_PRACTICE, false);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.OVERDETERMINED_MODEL, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.SBO_CONSISTENCY, false);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.UNITS_CONSISTENCY, false);
    sbmlDocument.checkConsistency();
    // sbmlDocument.checkConsistencyOffline();
    long internalErrCount = sbmlDocument.getNumErrors();
    if (internalErrCount > 0) {
        StringBuffer sbmlErrbuf = new StringBuffer();
        for (int i = 0; i < internalErrCount; i++) {
            SBMLError sbmlErr = sbmlDocument.getError(i);
            if (sbmlErr.isError() || sbmlErr.isFatal()) {
                sbmlErrbuf.append(sbmlErr.getCategory() + " :: " + sbmlErr.getSeverity() + " :: " + sbmlErr.getMessage() + "\n");
            }
        }
        if (sbmlErrbuf.length() > 0) {
            throw new RuntimeException("SBML Internal consistency checks failed: \n" + sbmlErrbuf.toString());
        }
    }
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.GENERAL_CONSISTENCY, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.IDENTIFIER_CONSISTENCY, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.UNITS_CONSISTENCY, false);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.MATHML_CONSISTENCY, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.SBO_CONSISTENCY, false);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.OVERDETERMINED_MODEL, true);
    sbmlDocument.setConsistencyChecks(CHECK_CATEGORY.MODELING_PRACTICE, false);
    sbmlDocument.checkConsistency();
    // sbmlDocument.checkConsistencyOffline();
    long errCount = sbmlDocument.getNumErrors();
    if (errCount > 0) {
        StringBuffer sbmlErrbuf = new StringBuffer();
        for (int i = 0; i < errCount; i++) {
            SBMLError sbmlErr = sbmlDocument.getError(i);
            if (sbmlErr.isError() || sbmlErr.isFatal()) {
                sbmlErrbuf.append(sbmlErr.getCategory() + " :: " + sbmlErr.getSeverity() + " :: " + sbmlErr.getMessage() + "\n");
            }
        }
        if (sbmlErrbuf.length() > 0) {
            throw new RuntimeException("SBML validation failed: \n" + sbmlErrbuf.toString());
        }
    }
    // end of validation
    // start writing
    SBMLWriter sbmlWriter = new SBMLWriter();
    String sbmlStr = sbmlWriter.writeSBMLToString(sbmlDocument);
    // Error check - use libSBML's document.printError to print to outputstream
    System.out.println("\n\nSBML Export Error Report");
    sbmlDocument.printErrors(System.out);
    return sbmlStr;
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) SBMLDocument(org.sbml.jsbml.SBMLDocument) MathDescription(cbit.vcell.math.MathDescription) Compartment(org.sbml.jsbml.Compartment) SBMLError(org.sbml.jsbml.SBMLError) ASTNode(org.sbml.jsbml.ASTNode) RateRule(org.sbml.jsbml.RateRule) AssignmentRule(org.sbml.jsbml.AssignmentRule) Equation(cbit.vcell.math.Equation) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) InitialAssignment(org.sbml.jsbml.InitialAssignment) SBMLWriter(org.sbml.jsbml.SBMLWriter) Model(org.sbml.jsbml.Model) MathModel(cbit.vcell.mathmodel.MathModel) Parameter(org.sbml.jsbml.Parameter) Event(cbit.vcell.math.Event) Equation(cbit.vcell.math.Equation)

Aggregations

MathModel (cbit.vcell.mathmodel.MathModel)70 BioModel (cbit.vcell.biomodel.BioModel)26 Simulation (cbit.vcell.solver.Simulation)24 DataAccessException (org.vcell.util.DataAccessException)21 Geometry (cbit.vcell.geometry.Geometry)20 MathDescription (cbit.vcell.math.MathDescription)20 SimulationContext (cbit.vcell.mapping.SimulationContext)19 XmlParseException (cbit.vcell.xml.XmlParseException)13 MathModelInfo (org.vcell.util.document.MathModelInfo)12 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)11 UserCancelException (org.vcell.util.UserCancelException)11 VCDocument (org.vcell.util.document.VCDocument)11 XMLSource (cbit.vcell.xml.XMLSource)10 ExpressionException (cbit.vcell.parser.ExpressionException)9 File (java.io.File)9 KeyValue (org.vcell.util.document.KeyValue)8 PropertyVetoException (java.beans.PropertyVetoException)7 IOException (java.io.IOException)7 BigString (org.vcell.util.BigString)7 BioModelInfo (org.vcell.util.document.BioModelInfo)7