Search in sources :

Example 46 with MathException

use of cbit.vcell.math.MathException in project vcell by virtualcell.

the class MathVerifier method scanBioModels.

/**
 * Insert the method's description here.
 * Creation date: (2/2/01 3:40:29 PM)
 */
public void scanBioModels(boolean bUpdateDatabase, KeyValue[] bioModelKeys) throws MathException, MappingException, SQLException, DataAccessException, ModelException, ExpressionException {
    java.util.Calendar calendar = java.util.GregorianCalendar.getInstance();
    // calendar.set(2002,java.util.Calendar.MAY,7+1);
    calendar.set(2002, java.util.Calendar.JULY, 1);
    final java.util.Date fluxCorrectionOrDisablingBugFixDate = calendar.getTime();
    // calendar.set(2001,java.util.Calendar.JUNE,13+1);
    calendar.set(2002, java.util.Calendar.JANUARY, 1);
    final java.util.Date totalVolumeCorrectionFixDate = calendar.getTime();
    User user = new User(PropertyLoader.ADMINISTRATOR_ACCOUNT, new KeyValue(PropertyLoader.ADMINISTRATOR_ID));
    for (int i = 0; i < bioModelKeys.length; i++) {
        BioModelInfo bioModelInfo = dbServerImpl.getBioModelInfo(user, bioModelKeys[i]);
        if (lg.isTraceEnabled())
            lg.trace("Testing bioModel with key '" + bioModelKeys[i] + "'");
        java.sql.Connection con = null;
        java.sql.Statement stmt = null;
        try {
            // 
            // read in the BioModel from the database
            // 
            BigString bioModelXML = dbServerImpl.getBioModelXML(user, bioModelInfo.getVersion().getVersionKey());
            BioModel bioModelFromDB = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
            BioModel bioModelNewMath = XmlHelper.XMLToBioModel(new XMLSource(bioModelXML.toString()));
            bioModelFromDB.refreshDependencies();
            bioModelNewMath.refreshDependencies();
            // 
            // get all Simulations for this model
            // 
            Simulation[] modelSimsFromDB = bioModelFromDB.getSimulations();
            // 
            // for each application, recompute mathDescription, and verify it is equivalent
            // then check each associated simulation to ensure math overrides are applied in an equivalent manner also.
            // 
            SimulationContext[] simContextsFromDB = bioModelFromDB.getSimulationContexts();
            SimulationContext[] simContextsNewMath = bioModelNewMath.getSimulationContexts();
            for (int k = 0; k < simContextsFromDB.length; k++) {
                SimulationContext simContextFromDB = simContextsFromDB[k];
                Simulation[] appSimsFromDB = simContextFromDB.getSimulations();
                SimulationContext simContextNewMath = simContextsNewMath[k];
                Simulation[] appSimsNewMath = simContextNewMath.getSimulations();
                MathCompareResults mathCompareResults = null;
                try {
                    MathDescription origMathDesc = simContextFromDB.getMathDescription();
                    // 
                    // find out if any simulation belonging to this Application has data
                    // 
                    boolean bApplicationHasData = false;
                    for (int l = 0; l < modelSimsFromDB.length; l++) {
                        SimulationStatusPersistent simulationStatus = dbServerImpl.getSimulationStatus(modelSimsFromDB[l].getKey());
                        if (simulationStatus != null && simulationStatus.getHasData()) {
                            bApplicationHasData = true;
                        }
                    }
                    // 
                    try {
                        if (simContextNewMath.getGeometry().getDimension() > 0 && simContextNewMath.getGeometry().getGeometrySurfaceDescription().getGeometricRegions() == null) {
                            simContextNewMath.getGeometry().getGeometrySurfaceDescription().updateAll();
                        }
                    } catch (Exception e) {
                        e.printStackTrace(System.out);
                    }
                    // 
                    // updated mathdescription loaded into copy of biomodel, then test for equivalence.
                    // 
                    cbit.vcell.mapping.MathMapping mathMapping = simContextNewMath.createNewMathMapping();
                    MathDescription newMathDesc = mathMapping.getMathDescription();
                    String issueString = null;
                    org.vcell.util.Issue[] issues = mathMapping.getIssues();
                    if (issues != null && issues.length > 0) {
                        StringBuffer buffer = new StringBuffer("Issues(" + issues.length + "):");
                        for (int l = 0; l < issues.length; l++) {
                            buffer.append(" <<" + issues[l].toString() + ">>");
                        }
                        issueString = buffer.toString();
                    }
                    simContextNewMath.setMathDescription(newMathDesc);
                    MathCompareResults testIfSameResults = cbit.vcell.math.MathUtilities.testIfSame(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
                    mathCompareResults = MathDescription.testEquivalency(SimulationSymbolTable.createMathSymbolTableFactory(), origMathDesc, newMathDesc);
                    StringBuffer buffer = new StringBuffer();
                    buffer.append(">>>BioModel(" + bioModelFromDB.getVersion().getVersionKey() + ") '" + bioModelFromDB.getName() + "':" + bioModelFromDB.getVersion().getDate() + ", Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "' <<EQUIV=" + mathCompareResults.isEquivalent() + ">>: " + mathCompareResults.toDatabaseStatus());
                    // 
                    if (bUpdateDatabase) {
                        con = null;
                        stmt = null;
                        try {
                            con = conFactory.getConnection(new Object());
                            stmt = con.createStatement();
                            // KeyValue mathKey = origMathDesc.getKey();
                            String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.hasData.getUnqualifiedColName() + " = " + ((bApplicationHasData) ? (1) : (0)) + ", " + SimContextStat2Table.table.equiv.getUnqualifiedColName() + " = " + (mathCompareResults.isEquivalent() ? (1) : (0)) + ", " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.toDatabaseStatus()) + "'" + ((issueString != null) ? (", " + SimContextStat2Table.table.comments.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(issueString, 255) + "'") : ("")) + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
                            int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                            if (numRowsChanged != 1) {
                                System.out.println("failed to update status");
                            }
                            con.commit();
                            if (lg.isTraceEnabled())
                                lg.trace("-------------- Update=true, saved 'newMath' for Application '" + simContextFromDB.getName() + "'");
                        } catch (SQLException e) {
                            lg.error(e.getMessage(), e);
                            if (lg.isWarnEnabled())
                                lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE MATH for Application '" + simContextFromDB.getName() + "'");
                        } finally {
                            if (stmt != null) {
                                stmt.close();
                            }
                            con.close();
                        }
                    }
                } catch (Throwable e) {
                    // exception in SimContext
                    lg.error(e.getMessage(), e);
                    if (bUpdateDatabase) {
                        con = null;
                        stmt = null;
                        try {
                            con = conFactory.getConnection(new Object());
                            stmt = con.createStatement();
                            String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
                            if (status.length() > 255)
                                status = status.substring(0, 254) + "'";
                            String UPDATESTATUS = "UPDATE " + SimContextStat2Table.table.getTableName() + " SET " + SimContextStat2Table.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimContextStat2Table.table.simContextRef.getUnqualifiedColName() + " = " + simContextFromDB.getKey();
                            int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                            if (numRowsChanged != 1) {
                                System.out.println("failed to update status with exception");
                            }
                            con.commit();
                            if (lg.isTraceEnabled())
                                lg.trace("-------------- Update=true, saved exception for Application '" + simContextFromDB.getName() + "'");
                        } catch (SQLException e2) {
                            lg.error(e2.getMessage(), e2);
                            if (lg.isWarnEnabled())
                                lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for Application '" + simContextFromDB.getName() + "'");
                        } finally {
                            if (stmt != null) {
                                stmt.close();
                            }
                            con.close();
                        }
                    }
                }
                // 
                for (int l = 0; l < appSimsFromDB.length; l++) {
                    try {
                        boolean bSimEquivalent = Simulation.testEquivalency(appSimsNewMath[l], appSimsFromDB[l], mathCompareResults);
                        if (lg.isTraceEnabled())
                            lg.trace("Application(" + simContextFromDB.getKey() + ") '" + simContextFromDB.getName() + "', " + "Simulation(" + modelSimsFromDB[l].getKey() + ") '" + modelSimsFromDB[l].getName() + "':" + modelSimsFromDB[l].getVersion().getDate() + "mathEquivalency=" + mathCompareResults.isEquivalent() + ", simEquivalency=" + bSimEquivalent);
                        // 
                        if (bUpdateDatabase) {
                            con = null;
                            stmt = null;
                            try {
                                con = conFactory.getConnection(new Object());
                                stmt = con.createStatement();
                                String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.equiv.getUnqualifiedColName() + " = " + ((bSimEquivalent) ? (1) : (0)) + ", " + SimStatTable.table.status.getUnqualifiedColName() + " = '" + org.vcell.util.TokenMangler.getSQLEscapedString(mathCompareResults.decision.description) + "'" + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
                                int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                                if (numRowsChanged != 1) {
                                    System.out.println("failed to update status");
                                }
                                con.commit();
                                if (lg.isTraceEnabled())
                                    lg.trace("-------------- Update=true, saved 'simulation status for simulation '" + appSimsFromDB[l].getName() + "'");
                            } catch (SQLException e) {
                                lg.error(e.getMessage(), e);
                                if (lg.isWarnEnabled())
                                    lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO UPDATE status for simulation '" + appSimsFromDB[l].getName() + "'");
                            } finally {
                                if (stmt != null) {
                                    stmt.close();
                                }
                                con.close();
                            }
                        }
                    } catch (Throwable e) {
                        // exception in SimContext
                        lg.error(e.getMessage(), e);
                        if (bUpdateDatabase) {
                            con = null;
                            stmt = null;
                            try {
                                con = conFactory.getConnection(new Object());
                                stmt = con.createStatement();
                                String status = "'EXCEPTION: " + org.vcell.util.TokenMangler.getSQLEscapedString(e.toString()) + "'";
                                if (status.length() > 255)
                                    status = status.substring(0, 254) + "'";
                                String UPDATESTATUS = "UPDATE " + SimStatTable.table.getTableName() + " SET " + SimStatTable.table.status.getUnqualifiedColName() + " = " + status + " WHERE " + SimStatTable.table.simRef.getUnqualifiedColName() + " = " + appSimsFromDB[l].getKey();
                                int numRowsChanged = stmt.executeUpdate(UPDATESTATUS);
                                if (numRowsChanged != 1) {
                                    System.out.println("failed to update status with exception");
                                }
                                con.commit();
                                if (lg.isTraceEnabled())
                                    lg.trace("-------------- Update=true, saved exception for Simulation '" + appSimsFromDB[l].getName() + "'");
                            } catch (SQLException e2) {
                                lg.error(e2.getMessage(), e2);
                                if (lg.isWarnEnabled())
                                    lg.warn("*&*&*&*&*&*&*& Update=true, FAILED TO save exception status for simulation '" + appSimsFromDB[l].getName() + "'");
                            } finally {
                                if (stmt != null) {
                                    stmt.close();
                                }
                                con.close();
                            }
                        }
                    }
                }
            }
        } catch (Throwable e) {
            // exception in whole BioModel
            lg.error(e.getMessage(), e);
        // can't update anything in database, since we don't know what simcontexts are involved
        }
    }
}
Also used : User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Connection(java.sql.Connection) MathDescription(cbit.vcell.math.MathDescription) SQLException(java.sql.SQLException) BigString(org.vcell.util.BigString) BigString(org.vcell.util.BigString) MathCompareResults(cbit.vcell.math.MathCompareResults) BioModelInfo(org.vcell.util.document.BioModelInfo) SimulationStatusPersistent(cbit.vcell.server.SimulationStatusPersistent) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) MatrixException(cbit.vcell.matrix.MatrixException) ModelException(cbit.vcell.model.ModelException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) SQLException(java.sql.SQLException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) Simulation(cbit.vcell.solver.Simulation) BioModel(cbit.vcell.biomodel.BioModel) XMLSource(cbit.vcell.xml.XMLSource)

Example 47 with MathException

use of cbit.vcell.math.MathException in project vcell by virtualcell.

the class SimulationContextDbDriver method assignAnalysisTasksSQL.

/**
 * This method was created in VisualAge.
 * @param simContext cbit.vcell.mapping.SimulationContext
 */
private void assignAnalysisTasksSQL(Connection con, KeyValue simContextKey, SimulationContext simContext) throws SQLException, DataAccessException {
    String sql;
    AnalysisTaskXMLTable analysisTaskTable = AnalysisTaskXMLTable.table;
    sql = " SELECT " + analysisTaskTable.analysisTaskXML.toString() + " FROM " + analysisTaskTable.getTableName() + " WHERE " + analysisTaskTable.simContextRef + " = " + simContextKey + " ORDER BY " + // order-by to maintain order ... not really necessary
    analysisTaskTable.insertDate;
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        while (rset.next()) {
            String analysisXML = (String) getLOB(rset, analysisTaskTable.analysisTaskXML, dbSyntax);
            org.jdom.Element rootElement = XmlUtil.stringToXML(analysisXML, null).getRootElement();
            cbit.vcell.modelopt.ParameterEstimationTask parameterEstimationTask = cbit.vcell.modelopt.ParameterEstimationTaskXMLPersistence.getParameterEstimationTask(rootElement, simContext);
            simContext.addAnalysisTask(parameterEstimationTask);
        }
    } catch (MathException | MappingException | PropertyVetoException | ExpressionException e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException(e.getMessage());
    } finally {
        if (stmt != null) {
            stmt.close();
        }
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ExpressionException(cbit.vcell.parser.ExpressionException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) MathException(cbit.vcell.math.MathException) ResultSet(java.sql.ResultSet) DataAccessException(org.vcell.util.DataAccessException)

Example 48 with MathException

use of cbit.vcell.math.MathException in project vcell by virtualcell.

the class FastSystemAnalyzer method refreshInvarianceMatrix.

/**
 */
private void refreshInvarianceMatrix() throws MathException, ExpressionException {
    // 
    // the invariance's are expressed in matrix form
    // 
    // |a a a a a -1  0  0|   |x1|   |0|
    // |a a a a a  0 -1  0| * |x2| = |0|
    // |a a a a a  0  0 -1|   |x3|   |0|
    // |x4|
    // |x5|
    // |c1|
    // |c2|
    // |c3|
    // 
    Variable[] vars = new Variable[fastVarList.size()];
    fastVarList.copyInto(vars);
    int numVars = fastVarList.size();
    int rows = fastSystem.getNumFastInvariants();
    int cols = numVars + fastSystem.getNumFastInvariants();
    RationalExpMatrix matrix = new RationalExpMatrix(rows, cols);
    Enumeration<FastInvariant> fastInvariantsEnum = fastSystem.getFastInvariants();
    for (int i = 0; i < rows && fastInvariantsEnum.hasMoreElements(); i++) {
        FastInvariant fi = (FastInvariant) fastInvariantsEnum.nextElement();
        Expression function = fi.getFunction();
        for (int j = 0; j < numVars; j++) {
            Variable var = (Variable) fastVarList.elementAt(j);
            Expression exp = function.differentiate(var.getName());
            exp.bindExpression(null);
            exp = exp.flatten();
            RationalExp coeffRationalExp = RationalExpUtils.getRationalExp(exp);
            matrix.set_elem(i, j, coeffRationalExp);
        }
        matrix.set_elem(i, numVars + i, -1);
    }
    // Print
    System.out.println("origMatrix");
    matrix.show();
    // 
    // gaussian elimination on the matrix give the following representation
    // note that some column pivoting (variable re-ordering) is sometimes required to
    // determine N-r dependent vars
    // 
    // |10i0iccc|
    // |01i0iccc|  where (c)'s are the coefficients for constants of invariances
    // |00i1iccc|        (i)'s are the coefficients for dependent vars in terms of independent vars
    // 
    // Print
    System.out.println("reducedMatrix");
    if (rows > 0) {
        try {
            matrix.gaussianElimination(new RationalExpMatrix(rows, rows));
        } catch (MatrixException e) {
            e.printStackTrace(System.out);
            throw new MathException(e.getMessage());
        }
    }
    matrix.show();
    for (int i = 0; i < vars.length; i++) {
        System.out.print(vars[i].getName() + "  ");
    }
    System.out.println("");
    // 
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < rows; j++) {
            RationalExp rexp = matrix.get(i, j).simplify();
            matrix.set_elem(i, j, rexp);
        }
    }
    for (int i = 0; i < rows; i++) {
        // 
        if (!matrix.get(i, i).isConstant() || matrix.get(i, i).getConstant().doubleValue() != 1) {
            for (int j = i + 1; j < numVars; j++) {
                if (matrix.get(i, j).isConstant() && matrix.get(i, j).getConstant().doubleValue() == 1.0) {
                    for (int ii = 0; ii < rows; ii++) {
                        RationalExp temp = matrix.get(ii, i);
                        matrix.set_elem(ii, i, matrix.get(ii, j));
                        matrix.set_elem(ii, j, temp);
                    }
                    Variable tempVar = vars[i];
                    vars[i] = vars[j];
                    vars[j] = tempVar;
                    break;
                }
            }
        }
    }
    // Print
    for (int i = 0; i < vars.length; i++) {
        System.out.print(vars[i].getName() + "  ");
    }
    System.out.println("");
    matrix.show();
    // 
    // separate into dependent and indepent variables, and chop off identity matrix (left N-r columns)
    // 
    // T       |iiccc|                   T
    // [x1 x2 x4] = -1 * |iiccc| * [x3 x5 c1 c2 c3]
    // |iiccc|
    // 
    // 
    int numInvariants = fastSystem.getNumFastInvariants();
    dependentVarList.removeAllElements();
    for (int i = 0; i < numInvariants; i++) {
        dependentVarList.addElement(vars[i]);
    }
    independentVarList.removeAllElements();
    for (int i = numInvariants; i < vars.length; i++) {
        independentVarList.addElement(vars[i]);
    }
    int new_cols = independentVarList.size() + numInvariants;
    dependencyMatrix = new RationalExpMatrix(rows, new_cols);
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < new_cols; j++) {
            RationalExp rexp = matrix.get(i, j + dependentVarList.size()).simplify().minus();
            dependencyMatrix.set_elem(i, j, rexp);
        }
    }
    // Print
    System.out.println("\n\nDEPENDENCY MATRIX");
    dependencyMatrix.show();
    System.out.print("dependent vars: ");
    for (int i = 0; i < dependentVarList.size(); i++) {
        System.out.print(((Variable) dependentVarList.elementAt(i)).getName() + "  ");
    }
    System.out.println("");
    System.out.print("independent vars: ");
    for (int i = 0; i < independentVarList.size(); i++) {
        System.out.print(((Variable) independentVarList.elementAt(i)).getName() + "  ");
    }
    System.out.println("");
}
Also used : MatrixException(cbit.vcell.matrix.MatrixException) ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MemVariable(cbit.vcell.math.MemVariable) RationalExpMatrix(cbit.vcell.matrix.RationalExpMatrix) Expression(cbit.vcell.parser.Expression) MathException(cbit.vcell.math.MathException) RationalExp(cbit.vcell.matrix.RationalExp) FastInvariant(cbit.vcell.math.FastInvariant)

Example 49 with MathException

use of cbit.vcell.math.MathException in project vcell by virtualcell.

the class FastSystemAnalyzer method refreshFastVarList.

/**
 * @return java.util.Vector
 */
private void refreshFastVarList() throws MathException, ExpressionException {
    fastVarList.clear();
    // 
    // get list of unique (VolVariables and MemVariables) in fastRate expressions
    // 
    Enumeration<FastRate> fastRatesEnum = fastSystem.getFastRates();
    while (fastRatesEnum.hasMoreElements()) {
        FastRate fr = fastRatesEnum.nextElement();
        Expression exp = fr.getFunction();
        Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
        while (enum1.hasMoreElements()) {
            Variable var = enum1.nextElement();
            if (var instanceof VolVariable || var instanceof MemVariable) {
                if (!fastVarList.contains(var)) {
                    fastVarList.addElement(var);
                // System.out.println("FastSystemImplicit.refreshFastVarList(), FAST RATE VARIABLE: "+var.getName());
                }
            }
        }
    }
    // 
    // get list of all variables used in invariant expressions that are not used in fast rates
    // 
    Enumeration<FastInvariant> fastInvariantsEnum = fastSystem.getFastInvariants();
    while (fastInvariantsEnum.hasMoreElements()) {
        FastInvariant fi = (FastInvariant) fastInvariantsEnum.nextElement();
        Expression exp = fi.getFunction();
        // System.out.println("FastSystemImplicit.refreshFastVarList(), ORIGINAL FAST INVARIANT: "+exp);
        Enumeration<Variable> enum1 = MathUtilities.getRequiredVariables(exp, this);
        while (enum1.hasMoreElements()) {
            Variable var = enum1.nextElement();
            if (var instanceof VolVariable || var instanceof MemVariable) {
                if (!fastVarList.contains(var)) {
                    fastVarList.addElement(var);
                }
            }
        }
    }
    // 
    // verify that there are N equations (rates+invariants) and N unknowns (fastVariables)
    // 
    int numBoundFunctions = fastSystem.getNumFastInvariants() + fastSystem.getNumFastRates();
    if (fastVarList.size() != numBoundFunctions) {
        throw new MathException("FastSystem.checkDimension(), there are " + fastVarList.size() + " variables and " + numBoundFunctions + " FastInvariant's & FastRates");
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) Variable(cbit.vcell.math.Variable) VolVariable(cbit.vcell.math.VolVariable) MemVariable(cbit.vcell.math.MemVariable) MemVariable(cbit.vcell.math.MemVariable) Expression(cbit.vcell.parser.Expression) VolVariable(cbit.vcell.math.VolVariable) MathException(cbit.vcell.math.MathException) FastRate(cbit.vcell.math.FastRate) FastInvariant(cbit.vcell.math.FastInvariant)

Example 50 with MathException

use of cbit.vcell.math.MathException in project vcell by virtualcell.

the class XmlReader method getMathDescription.

/**
 * This method returns a MathDescription from a XML element.
 * Creation date: (4/26/2001 12:11:14 PM)
 * @return cbit.vcell.math.MathDescription
 * @param param org.jdom.Element
 * @exception cbit.vcell.xml.XmlParseException The exception description.
 */
MathDescription getMathDescription(Element param, Geometry geometry) throws XmlParseException {
    MathDescription mathdes = null;
    Element tempelement;
    // Retrieve Metadata(Version)
    Version version = getVersion(param.getChild(XMLTags.VersionTag, vcNamespace));
    // Retrieve attributes
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    // Create new MathDescription
    if (version != null) {
        mathdes = new MathDescription(version);
    } else {
        mathdes = new MathDescription(name);
    }
    try {
        // this step is needed!
        mathdes.setGeometry(geometry);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("a PropertyVetoException was fired when setting the Geometry to the Mathdescription in the simContext " + name, e);
    }
    // set attributes
    try {
        mathdes.setName(name);
        // String annotation = param.getAttributeValue(XMLTags.AnnotationAttrTag);
        // if (annotation!=null) {
        // mathdes.setDescription(unMangle(annotation));
        // }
        // add Annotation
        String annotationText = param.getChildText(XMLTags.AnnotationTag, vcNamespace);
        if (annotationText != null && annotationText.length() > 0) {
            mathdes.setDescription(unMangle(annotationText));
        }
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A PropertyVetoException was fired when setting the name " + name + ", to a new MathDescription!", e);
    }
    VariableHash varHash = new VariableHash();
    // Retrieve Constant
    Iterator<Element> iterator = param.getChildren(XMLTags.ConstantTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getConstant(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Retrieve FilamentRegionVariables
    iterator = param.getChildren(XMLTags.FilamentRegionVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getFilamentRegionVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Retrieve FilamentVariables
    iterator = param.getChildren(XMLTags.FilamentVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getFilamentVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // retrieve InsideVariables
    // **** This variables are for internal USE ******
    // Retrieve MembraneRegionVariable
    iterator = param.getChildren(XMLTags.MembraneRegionVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getMembraneRegionVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Retrieve MembraneVariable
    iterator = param.getChildren(XMLTags.MembraneVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getMemVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Retrieve PointVariable
    iterator = param.getChildren(XMLTags.PointVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getPointVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // retrieve OutsideVariables
    // **** This variables are for internal USE ******
    // Retrieve Volume Region variable
    iterator = param.getChildren(XMLTags.VolumeRegionVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getVolumeRegionVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Retrieve VolumeVariable
    iterator = param.getChildren(XMLTags.VolumeVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getVolVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Retrieve StochVolVariable
    iterator = param.getChildren(XMLTags.StochVolVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getStochVolVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // Retrieve all the Functions //This needs to be processed before all the variables are read!
    iterator = param.getChildren(XMLTags.FunctionTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getFunction(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    iterator = param.getChildren(XMLTags.VolumeRandomVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getRandomVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    iterator = param.getChildren(XMLTags.MembraneRandomVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getRandomVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    iterator = param.getChildren(XMLTags.VolumeParticleVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getVolumeParticalVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    iterator = param.getChildren(XMLTags.MembraneParticleVariableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getMembraneParticalVariable(tempelement));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // ParticleMolecularTypeTag       getParticleMolecularTypes
    // has to be done before VolumeParticleSpeciesPattern and VolumeParticleObservable
    iterator = param.getChildren(XMLTags.ParticleMolecularTypeTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        mathdes.addParticleMolecularType(getParticleMolecularType(tempelement));
    }
    // VolumeParticleSpeciesPatternTag
    iterator = param.getChildren(XMLTags.VolumeParticleSpeciesPatternTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getVolumeParticleSpeciesPattern(tempelement, mathdes));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // VolumeParticleObservableTag    getParticleObservables
    iterator = param.getChildren(XMLTags.VolumeParticleObservableTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            varHash.addVariable(getVolumeParticleObservable(tempelement, varHash));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException(e);
        }
    }
    // 
    try {
        mathdes.setAllVariables(varHash.getAlphabeticallyOrderedVariables());
    } catch (MathException e) {
        e.printStackTrace();
        throw new XmlParseException("Error adding the Function variables to the MathDescription " + name, e);
    } catch (ExpressionBindingException e) {
        e.printStackTrace();
        throw new XmlParseException("Error adding the Function variables to the MathDescription " + name, e);
    }
    // Retrieve CompartmentsSubdomains
    iterator = param.getChildren(XMLTags.CompartmentSubDomainTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            mathdes.addSubDomain(getCompartmentSubDomain(tempelement, mathdes));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("Error adding a new CompartmentSubDomain to the MathDescription " + name, e);
        }
    }
    // Retrieve MembraneSubdomains
    iterator = param.getChildren(XMLTags.MembraneSubDomainTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        try {
            mathdes.addSubDomain(getMembraneSubDomain(tempelement, mathdes));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("Error adding a new MembraneSubDomain to the MathDescription " + name, e);
        }
    }
    // Retrieve the FilamentSubdomain (if any)
    tempelement = param.getChild(XMLTags.FilamentSubDomainTag, vcNamespace);
    if (tempelement != null) {
        try {
            mathdes.addSubDomain(getFilamentSubDomain(tempelement, mathdes));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("Error adding a new FilamentSubDomain to the MathDescription " + name, e);
        }
    }
    // Retrieve the PointSubdomain (if any)
    tempelement = param.getChild(XMLTags.PointSubDomainTag, vcNamespace);
    if (tempelement != null) {
        try {
            mathdes.addSubDomain(getPointSubDomain(tempelement, mathdes));
        } catch (MathException e) {
            e.printStackTrace();
            throw new XmlParseException("Error adding a new PointSubDomain to the MathDescription " + name, e);
        }
    }
    iterator = param.getChildren(XMLTags.EventTag, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        Event event = getEvent(mathdes, tempelement);
        try {
            mathdes.addEvent(event);
        } catch (MathException e) {
            e.printStackTrace(System.out);
            throw new XmlParseException(e);
        }
    }
    iterator = param.getChildren(XMLTags.PostProcessingBlock, vcNamespace).iterator();
    while (iterator.hasNext()) {
        tempelement = (Element) iterator.next();
        getPostProcessingBlock(mathdes, tempelement);
    }
    return mathdes;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) MathDescription(cbit.vcell.math.MathDescription) Version(org.vcell.util.document.Version) RedistributionVersion(cbit.vcell.solvers.mb.MovingBoundarySolverOptions.RedistributionVersion) SimulationVersion(org.vcell.util.document.SimulationVersion) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) VariableHash(cbit.vcell.math.VariableHash) MathException(cbit.vcell.math.MathException) Element(org.jdom.Element) Event(cbit.vcell.math.Event) BioEvent(cbit.vcell.mapping.BioEvent) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException)

Aggregations

MathException (cbit.vcell.math.MathException)78 ExpressionException (cbit.vcell.parser.ExpressionException)46 Expression (cbit.vcell.parser.Expression)38 Variable (cbit.vcell.math.Variable)33 VolVariable (cbit.vcell.math.VolVariable)26 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)18 MemVariable (cbit.vcell.math.MemVariable)18 PropertyVetoException (java.beans.PropertyVetoException)18 DataAccessException (org.vcell.util.DataAccessException)16 MathDescription (cbit.vcell.math.MathDescription)15 Vector (java.util.Vector)15 Element (org.jdom.Element)15 IOException (java.io.IOException)14 Function (cbit.vcell.math.Function)13 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)13 MembraneParticleVariable (cbit.vcell.math.MembraneParticleVariable)12 ParticleVariable (cbit.vcell.math.ParticleVariable)12 VolumeParticleVariable (cbit.vcell.math.VolumeParticleVariable)12 ArrayList (java.util.ArrayList)12 MappingException (cbit.vcell.mapping.MappingException)11