Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Infinity and NaN in SBML values and MathML #1381

Merged
merged 4 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2975,18 +2975,35 @@ private static void addOutputFunctions(org.sbml.jsbml.Model sbmlModel, BioModel
private static void applySavedExpressions(org.sbml.jsbml.Model sbmlModel, SBMLSymbolMapping sbmlSymbolMapping, VCLogger vcLogger) throws Exception{
for(SBase sbmlValueTargetSbase : sbmlSymbolMapping.getSbmlValueTargets()){
Double sbmlValue = sbmlSymbolMapping.getSbmlValue(sbmlValueTargetSbase);
if(sbmlValue != null && !sbmlValue.isInfinite() && !sbmlValue.isNaN()){
final Expression sbmlValueExp;
if (sbmlValue != null) {
if (sbmlValue.isInfinite() && sbmlValue > 0) {
sbmlValueExp = new Expression(Double.MAX_VALUE);
logger.debug("setting infinite value for SBML id " + sbmlValueTargetSbase.getId() + " to " + Double.MAX_VALUE);
} else if (sbmlValue.isInfinite() && sbmlValue < 0){
sbmlValueExp = new Expression(-Double.MAX_VALUE);
logger.debug("setting infinite value for SBML id " + sbmlValueTargetSbase.getId() + " to " + -Double.MAX_VALUE);
} else if (sbmlValue.isNaN()){
sbmlValueExp = new Expression("0/0");
logger.debug("setting NaN value for SBML id " + sbmlValueTargetSbase.getId() + " to 0/0");
} else {
sbmlValueExp = new Expression(sbmlValue);
}
} else {
sbmlValueExp = null;
}
if(sbmlValueExp != null){
EditableSymbolTableEntry targetSte = sbmlSymbolMapping.getInitialSte(sbmlValueTargetSbase);
try {
if(targetSte != null){
if(targetSte.isExpressionEditable()){
targetSte.setExpression(new Expression(sbmlValue));
targetSte.setExpression(sbmlValueExp);
}
} else {
targetSte = sbmlSymbolMapping.getRuntimeSte(sbmlValueTargetSbase);
if(targetSte != null){
if(targetSte.isExpressionEditable()){
targetSte.setExpression(new Expression(sbmlValue));
targetSte.setExpression(sbmlValueExp);
}
} else {
logger.error("couldn't find vcell object mapped to sbml object: " + sbmlValueTargetSbase);
Expand All @@ -2998,7 +3015,7 @@ private static void applySavedExpressions(org.sbml.jsbml.Model sbmlModel, SBMLSy
vcLogger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.OverallWarning, msg);
}
} else {
String msg = "missing or unexpected value attribute '" + sbmlValue + "' for SBML object id " + sbmlValueTargetSbase.getId();
String msg = "missing value attribute for SBML object id " + sbmlValueTargetSbase.getId();
logger.error(msg);
vcLogger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.OverallWarning, msg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public static Map<Integer, SBMLTestSuiteTest.FAULT> knownFaults() {
faults.put(627, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'Metabolite_123' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that y
faults.put(628, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'Metabolite_8' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that you
faults.put(632, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'k4b' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that you have pro
faults.put(696, SBMLTestSuiteTest.FAULT.MATHML_PARSING); // cause: Error adding Lambda function UnsupportedConstruct: error parsing expression ' <math><notanumber/></math>': node type 'notanumber' not supported yet
faults.put(696, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'Metabolite_16' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that yo
faults.put(705, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'Metabolite_21' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that yo
faults.put(706, SBMLTestSuiteTest.FAULT.UNCATEGORIZED); // cause: found more than one SBase match for sid=v, matched [org.vcell.sbml.vcell.SBMLSymbolMapping$SBaseWrapper@67cc48df, org.vcell.sbml.vcell.SBMLSymbolMapping$SBaseWrapper@483ac21f]
faults.put(710, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'Metabolite_0_0' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that y
Expand All @@ -179,7 +179,6 @@ public static Map<Integer, SBMLTestSuiteTest.FAULT> knownFaults() {
faults.put(872, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'beta' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that you have pr
faults.put(908, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'Metabolite_2' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that you
faults.put(925, SBMLTestSuiteTest.FAULT.UNCATEGORIZED); // cause: OverallWarning: missing or unexpected value attribute '-Infinity' for SBML object id log_time
faults.put(952, SBMLTestSuiteTest.FAULT.MATHML_PARSING); // cause: Error adding Lambda function UnsupportedConstruct: error parsing expression ' <math><notanumber/></math>': node type 'notanumber' not supported yet
faults.put(956, SBMLTestSuiteTest.FAULT.MATHML_PARSING); // cause: Error adding Lambda function UnsupportedConstruct: error parsing expression ' <math><notanumber/></math>': node type 'notanumber' not supported yet
faults.put(961, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'rateOf_re15' to model: 're15' is either not found in your model or is not allowed to be used in the current context. Check that you have provided t
faults.put(969, SBMLTestSuiteTest.FAULT.EXPRESSION_BINDING_EXCEPTION); // cause: Error binding global parameter 'Metabolite_11' to model: 'UNRESOLVED.initConc' is either not found in your model or is not allowed to be used in the current context. Check that yo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,6 @@ public static Collection<Integer> testCases() {
faults.put(943, FAULT.DELAY);
faults.put(945, FAULT.STRUCTURE_SIZE_IN_ASSIGNMENT_RULE);
faults.put(947, FAULT.STRUCTURE_SIZE_IN_ASSIGNMENT_RULE);
faults.put(950, FAULT.VALUE_NAN_INF_OR_MISSING);
faults.put(951, FAULT.VALUE_NAN_INF_OR_MISSING);
faults.put(957, FAULT.XOR_MISSING);
faults.put(958, FAULT.XOR_MISSING);
faults.put(959, FAULT.INCONSISTENT_UNIT_SYSTEM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,19 @@ private SimpleNode getRootNode(Element nodeMathML, String timeSymbol) throws Exp
} else {
throw new ExpressionException("csymbol node type "+nodeMathML.getAttributeValue(MathMLTags.DEFINITIONURL)+" not supported yet");
}
} else{
} else if (nodeMathML.getName().equals(MathMLTags.NOT_A_NUMBER)){
ASTFloatNode zeroNode = new ASTFloatNode(0.0);
ASTFloatNode zeroNode2 = new ASTFloatNode(0.0);
ASTInvertTermNode invNode = new ASTInvertTermNode();
invNode.jjtAddChild(zeroNode2);
ASTMultNode multNode = new ASTMultNode();
multNode.jjtAddChild(zeroNode);
multNode.jjtAddChild(invNode);
return multNode;
} else if (nodeMathML.getName().equals(MathMLTags.INFINITY)) {
ASTFloatNode infNode = new ASTFloatNode(Double.MAX_VALUE);
return infNode;
}else{
throw new ExpressionException("node type '"+nodeMathML.getName()+"' not supported yet");
}
}
Expand Down
20 changes: 20 additions & 0 deletions vcell-math/src/test/java/cbit/vcell/parser/MathMLTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ public void testMathMLParsing_XOR() throws IOException, ExpressionException {
assertTrue(equiv, msg);
}

@Test
public void testNaN_MathmlParsing() throws ExpressionException {
String nanMathML = "<notanumber/>";
Expression exp = new ExpressionMathMLParser(null).fromMathML(nanMathML, "t");
Expression expectedExp = new Expression("0/0");
boolean equiv = ExpressionUtils.functionallyEquivalent(exp, expectedExp, true);
String msg = "not equivalent: origExp='"+exp.infix()+"', expMathML='"+expectedExp.infix()+"'";
assertTrue(equiv, msg);
}

@Test
public void testInfinity_MathmlParsing() throws ExpressionException {
String nanMathML = "<infinity/>";
Expression exp = new ExpressionMathMLParser(null).fromMathML(nanMathML, "t");
Expression expectedExp = new Expression(Double.MAX_VALUE);
boolean equiv = ExpressionUtils.functionallyEquivalent(exp, expectedExp, true);
String msg = "not equivalent: origExp='"+exp.infix()+"', expMathML='"+expectedExp.infix()+"'";
assertTrue(equiv, msg);
}


@ParameterizedTest
@MethodSource("testCases")
Expand Down