diff --git a/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/ReactionRulePropertiesTableModel.java b/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/ReactionRulePropertiesTableModel.java index 6db7a855f8..60c53974e6 100644 --- a/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/ReactionRulePropertiesTableModel.java +++ b/vcell-client/src/main/java/cbit/vcell/client/desktop/biomodel/ReactionRulePropertiesTableModel.java @@ -310,11 +310,6 @@ public void propertyChange(java.beans.PropertyChangeEvent evt) { } } -/** - * Sets the geometry property (cbit.vcell.geometry.Geometry) value. - * @param geometry The new value for the property. - * @see #getGeometry - */ public void setReactionRule(ReactionRule newValue) { ReactionRule oldValue = reactionRule; reactionRule = newValue; diff --git a/vcell-core/src/main/java/cbit/vcell/mapping/NetworkTransformer.java b/vcell-core/src/main/java/cbit/vcell/mapping/NetworkTransformer.java index 32c4862ada..79b0113baa 100644 --- a/vcell-core/src/main/java/cbit/vcell/mapping/NetworkTransformer.java +++ b/vcell-core/src/main/java/cbit/vcell/mapping/NetworkTransformer.java @@ -11,6 +11,8 @@ import java.util.List; import java.util.Map; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.vcell.model.bngl.ParseException; import org.vcell.model.rbm.FakeReactionRuleRateParameter; import org.vcell.model.rbm.FakeSeedSpeciesInitialConditionsParameter; @@ -68,6 +70,8 @@ */ public class NetworkTransformer implements SimContextTransformer { + private final static Logger lg = LogManager.getLogger(NetworkTransformer.class); + private Map> speciesEquivalenceMap = new LinkedHashMap>(); private Map kineticsParameterMap = new LinkedHashMap(); public final static int defaultSpeciesLimit = 800; // 1000 @@ -142,13 +146,13 @@ public String convertToBngl(SimulationContext simulationContext, boolean ignoreF } String bngl = bnglStringWriter.toString(); pw.close(); -// System.out.println(bngl); +// lg.debug(bngl); // for (Map.Entry> entry : speciesEquivalenceMap.entrySet()) { // String key = entry.getKey(); // Pair value = entry.getValue(); // SpeciesContext sc = value.one; // Expression initial = value.two; -// System.out.println("key: " + key + ", species: " + sc.getName() + ", initial: " + initial.infix()); +// lg.debug("key: " + key + ", species: " + sc.getName() + ", initial: " + initial.infix()); // } return bngl; } @@ -179,24 +183,24 @@ private BNGOutputSpec generateNetwork(SimulationContext simContext, MathMappingC Pair value = entry.getValue(); SpeciesContext sc = value.one; Expression initial = value.two; - System.out.println("key: " + key.fakeParameterName + ", species: " + sc.getName() + ", initial: " + initial.infix()); + lg.info("key: " + key.fakeParameterName + ", species: " + sc.getName() + ", initial: " + initial.infix()); } String md5hash = MD5.md5(input); if(isBngHashValid(input, md5hash, simContext)) { String s = "Previously saved outputSpec is up-to-date, no need to generate network."; - System.out.println(s); + lg.info(s); tcm = new TaskCallbackMessage(TaskCallbackStatus.Notification, s); simContext.appendToConsole(tcm); if(simContext.isInsufficientIterations()) { s = NetworkTransformer.getInsufficientIterationsMessage(); - System.out.println(s); + lg.info(s); tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s); simContext.appendToConsole(tcm); } if(simContext.isInsufficientMaxMolecules()) { s = NetworkTransformer.getInsufficientMaxMoleculesMessage(); - System.out.println(s); + lg.info(s); tcm = new TaskCallbackMessage(TaskCallbackStatus.Error, s); simContext.appendToConsole(tcm); } @@ -265,16 +269,16 @@ private BNGOutputSpec generateNetwork(SimulationContext simContext, MathMappingC throw new RuntimeException(message); } -// System.out.println("new hash: " + md5hash); -// System.out.println("old hash: " + simContext.getMd5hash()); +// lg.debug("new hash: " + md5hash); +// lg.debug("old hash: " + simContext.getMd5hash()); if(md5hash != null && md5hash.length() != 0 && outputSpec != null) { - System.out.println("saving hash and output spec"); + lg.info("saving hash and output spec"); synchronized (this) { simContext.setMd5hash(md5hash); simContext.setMostRecentlyCreatedOutputSpec(outputSpec); } } else { - System.out.println("something is wrong with the hash and/or output spec"); + lg.debug("something is wrong with the hash and/or output spec"); } return (BNGOutputSpec)BeanUtils.cloneSerializable(outputSpec); } @@ -290,8 +294,8 @@ private void transform(SimulationContext simContext, SimulationContext transform simContext.appendToConsole(tcm); tcm = new TaskCallbackMessage(TaskCallbackStatus.TaskStart, msg); simContext.appendToConsole(tcm); - long startTime = System.currentTimeMillis(); - System.out.println("Convert to bngl, execute BNG, retrieve the results."); +// long startTime = System.currentTimeMillis(); + lg.info("Convert to bngl, execute BNG, retrieve the results."); try { BNGOutputSpec outputSpec = generateNetwork(simContext, mathMappingCallback, networkGenerationRequirements); if (mathMappingCallback.isInterrupted()){ @@ -300,28 +304,28 @@ private void transform(SimulationContext simContext, SimulationContext transform simContext.appendToConsole(tcm); throw new UserCancelException(msg); } - long endTime = System.currentTimeMillis(); - long elapsedTime = endTime - startTime; - System.out.println(" " + elapsedTime + " milliseconds"); +// long endTime = System.currentTimeMillis(); +// long elapsedTime = endTime - startTime; +// lg.info(" " + elapsedTime + " milliseconds"); Model model = transformedSimulationContext.getModel(); ReactionContext reactionContext = transformedSimulationContext.getReactionContext(); // ---- Parameters ----------------------------------------------------------------------------------------------- - startTime = System.currentTimeMillis(); +// startTime = System.currentTimeMillis(); for (int i = 0; i < outputSpec.getBNGParams().length; i++){ BNGParameter p = outputSpec.getBNGParams()[i]; -// System.out.println(i+1 + ":\t\t"+ p.toString()); +// lg.info(i+1 + ":\t\t"+ p.toString()); if(model.getRbmModelContainer().getParameter(p.getName()) != null) { -// System.out.println(" ...already exists."); +// lg.warn(" ...already exists."); continue; // if it's already there we don't try to add it again; this should be true for all of them! } String s = p.getName(); if(NetworkConstraints.SPECIES_LIMIT_PARAMETER.equals(s)) { - System.out.println("found NetworkConstraints seciesLimit parameter."); + lg.info("found NetworkConstraints seciesLimit parameter."); continue; } if(NetworkConstraints.REACTIONS_LIMIT_PARAMETER.equals(s)) { - System.out.println("found NetworkConstraints reactionsLimit parameter."); + lg.info("found NetworkConstraints reactionsLimit parameter."); continue; } @@ -331,7 +335,7 @@ private void transform(SimulationContext simContext, SimulationContext transform } FakeReactionRuleRateParameter fakeKineticParam = FakeReactionRuleRateParameter.fromString(s); if(fakeKineticParam != null) { - System.out.println("found fakeKineticParam "+fakeKineticParam.fakeParameterName); + lg.info("found fakeKineticParam "+fakeKineticParam.fakeParameterName); continue; // we get rid of the fake parameters we use as keys } throw new RuntimeException("unexpected parameter "+p.getName()+" in internal BNG processing"); @@ -339,16 +343,16 @@ private void transform(SimulationContext simContext, SimulationContext transform // exp.bindExpression(model.getRbmModelContainer().getSymbolTable()); // model.getRbmModelContainer().addParameter(p.getName(), exp, model.getUnitSystem().getInstance_TBD()); } - endTime = System.currentTimeMillis(); - elapsedTime = endTime - startTime; - msg = "Adding " + outputSpec.getBNGParams().length + " parameters to model, " + elapsedTime + " ms"; - System.out.println(msg); +// endTime = System.currentTimeMillis(); +// elapsedTime = endTime - startTime; +// msg = "Adding " + outputSpec.getBNGParams().length + " parameters to model, " + elapsedTime + " ms"; +// lg.info(msg); // ---- Species ------------------------------------------------------------------------------------------------------------ mathMappingCallback.setMessage("generating network: adding species..."); mathMappingCallback.setProgressFraction(progressFractionQuota/4.0f); - startTime = System.currentTimeMillis(); - System.out.println("\nSpecies :"); +// startTime = System.currentTimeMillis(); + lg.info("\nSpecies :"); HashMap speciesMap = new HashMap(); // the reactions will need this map to recover the names of species knowing only the networkFileIndex LinkedHashMap sMap = new LinkedHashMap(); LinkedHashMap scMap = new LinkedHashMap(); @@ -359,7 +363,7 @@ private void transform(SimulationContext simContext, SimulationContext transform // final int decimalTickCount = Math.max(outputSpec.getBNGSpecies().length/10, 1); for (int i = 0; i < outputSpec.getBNGSpecies().length; i++){ BNGSpecies s = outputSpec.getBNGSpecies()[i]; -// System.out.println(i+1 + ":\t\t"+ s.toString()); +// lg.debug(i+1 + ":\t\t"+ s.toString()); String key = s.getConcentration().infix(); FakeSeedSpeciesInitialConditionsParameter fakeParam = FakeSeedSpeciesInitialConditionsParameter.fromString(key); @@ -372,7 +376,7 @@ private void transform(SimulationContext simContext, SimulationContext transform // we'll have to find the species context from the cloned model which correspond to the original species SpeciesContext sc = model.getSpeciesContext(originalsc.getName()); -// System.out.println(sc.getName() + ", " + sc.getSpecies().getCommonName() + " ...is one of the original seed species."); +// lg.info(sc.getName() + ", " + sc.getSpecies().getCommonName() + " ...is one of the original seed species."); speciesMap.put(s.getNetworkFileIndex(), sc.getName()); // existing name sMap.put(sc.getName(), sc.getSpecies()); scMap.put(sc.getName(), sc); @@ -440,7 +444,7 @@ private void transform(SimulationContext simContext, SimulationContext transform throw new UserCancelException(msg); } // if(i%50 == 0) { -// System.out.println(i+""); +// lg.info(i+""); // } // if(i%decimalTickCount == 0) { // int multiplier = i/decimalTickCount; @@ -449,11 +453,11 @@ private void transform(SimulationContext simContext, SimulationContext transform // } } -// System.out.println("Total generated species: " + countGenerated); -// System.out.println("------------------------ " + sMap.size() + " species in the map."); -// System.out.println("------------------------ " + scMap.size() + " species contexts in the map."); -// System.out.println("------------------------ " + model.getSpecies().length + " species in the Model."); -// System.out.println("------------------------ " + model.getSpeciesContexts().length + " species contexts in the Model."); +// lg.info("Total generated species: " + countGenerated); +// lg.info("------------------------ " + sMap.size() + " species in the map."); +// lg.info("------------------------ " + scMap.size() + " species contexts in the map."); +// lg.info("------------------------ " + model.getSpecies().length + " species in the Model."); +// lg.info("------------------------ " + model.getSpeciesContexts().length + " species contexts in the Model."); for(SpeciesContext sc1 : model.getSpeciesContexts()) { boolean found = false; @@ -461,13 +465,13 @@ private void transform(SimulationContext simContext, SimulationContext transform SpeciesContext sc2 = entry.getValue(); if(sc1.getName().equals(sc2.getName())) { found = true; -// System.out.println("found species context " + sc1.getName() + " of species " + sc1.getSpecies().getCommonName() + " // " + sc2.getSpecies().getCommonName()); +// lg.info("found species context " + sc1.getName() + " of species " + sc1.getSpecies().getCommonName() + " // " + sc2.getSpecies().getCommonName()); break; } } if(found == false) { // we add to the map the species context and the species which exist in the model but which are not in the map yet // the only ones in this situation should be plain species which were not given to bngl for flattening (they are flat already) -// System.out.println("species context " + sc1.getName() + " not found in the map. Adding it."); +// lg.debug("species context " + sc1.getName() + " not found in the map. Adding it."); scMap.put(sc1.getName(), sc1); sMap.put(sc1.getName(), sc1.getSpecies()); noMapForThese.add(sc1); @@ -479,12 +483,12 @@ private void transform(SimulationContext simContext, SimulationContext transform Species s2 = entry.getValue(); if(s1.getCommonName().equals(s2.getCommonName())) { found = true; -// System.out.println("found species " + s1.getCommonName()); +// lg.info("found species " + s1.getCommonName()); break; } } if(found == false) { - System.err.println("species " + s1.getCommonName() + " not found in the map!"); + lg.error("species " + s1.getCommonName() + " not found in the map!"); } } SpeciesContext[] sca = new SpeciesContext[scMap.size()]; @@ -519,16 +523,16 @@ private void transform(SimulationContext simContext, SimulationContext transform // for(SpeciesContext sc : sca) { // clean all the species patterns from the flattened species, we have no sp now // sc.setSpeciesPattern(null); // } - endTime = System.currentTimeMillis(); - elapsedTime = endTime - startTime; - msg = "Adding " + outputSpec.getBNGSpecies().length + " species to model, " + elapsedTime + " ms"; - System.out.println(msg); - +// endTime = System.currentTimeMillis(); +// elapsedTime = endTime - startTime; +// msg = "Adding " + outputSpec.getBNGSpecies().length + " species to model, " + elapsedTime + " ms"; +// lg.info(msg); + // ---- Reactions ----------------------------------------------------------------------------------------------------- mathMappingCallback.setMessage("generating network: adding reactions..."); mathMappingCallback.setProgressFraction(progressFractionQuota/4.0f*3.0f); - startTime = System.currentTimeMillis(); - System.out.println("\nReactions :"); +// startTime = System.currentTimeMillis(); + lg.info("\nReactions :"); Map> ruleKeyMap = new HashMap>(); Map directBNGReactionsMap = new HashMap(); @@ -554,7 +558,7 @@ private void transform(SimulationContext simContext, SimulationContext transform Map reactionStepMap = new HashMap(); for (int i = 0; i < outputSpec.getBNGReactions().length; i++){ BNGReaction bngReaction = outputSpec.getBNGReactions()[i]; -// System.out.println(i+1 + ":\t\t"+ r.writeReaction()); +// lg.info(i+1 + ":\t\t"+ r.writeReaction()); String baseName = bngReaction.getRuleName(); // Hack to correct a corrupted bng reaction name, until we fix the root cause // which may never happen since we encountered this problem only one time in many years @@ -562,7 +566,7 @@ private void transform(SimulationContext simContext, SimulationContext transform int pos = baseName.indexOf(","); baseName = baseName.substring(0, pos); } -// System.out.println(i + ": " + baseName); +// lg.info(i + ": " + baseName); String reactionName = null; HashSet keySetsForThisRule = ruleKeyMap.get(bngReaction.getRuleName()); if (keySetsForThisRule.size()==1 && model.getReactionStep(bngReaction.getRuleName()) == null && !reactionStepMap.containsKey(bngReaction.getRuleName())) { // we can reuse the reaction rule labels @@ -593,7 +597,7 @@ private void transform(SimulationContext simContext, SimulationContext transform ReactionRule rr = model.getRbmModelContainer().getReactionRule(name); if(rr == null) { // temp code, trying to catch a rare random bug, may be a race condition of some sort - System.out.println("ReactionRule " + name + " not found."); + lg.error("ReactionRule " + name + " not found."); } Structure structure = rr.getStructure(); @@ -734,25 +738,29 @@ private void transform(SimulationContext simContext, SimulationContext transform simContext.appendToConsole(tcm); throw new UserCancelException(msg); } - endTime = System.currentTimeMillis(); - elapsedTime = endTime - startTime; - msg = "Adding " + outputSpec.getBNGReactions().length + " reactions to model, " + elapsedTime + " ms"; - System.out.println(msg); +// endTime = System.currentTimeMillis(); +// elapsedTime = endTime - startTime; +// msg = "Adding " + outputSpec.getBNGReactions().length + " reactions to model, " + elapsedTime + " ms"; +// lg.info(msg); // clean all the reaction rules model.getRbmModelContainer().getReactionRuleList().clear(); // ---- Observables ------------------------------------------------------------------------------------------------- mathMappingCallback.setMessage("generating network: adding observables..."); mathMappingCallback.setProgressFraction(progressFractionQuota/8.0f*7.0f); - startTime = System.currentTimeMillis(); - System.out.println("\nObservables :"); +// startTime = System.currentTimeMillis(); + + lg.info("\nObservables :"); + // we delete all observables; instead, for each of them we create a user-defined global parameter + // which is the sum of all generated (by flattening) species that satisfy the observable pattern RbmModelContainer rbmmc = model.getRbmModelContainer(); for (int i = 0; i < outputSpec.getObservableGroups().length; i++){ + ObservableGroup o = outputSpec.getObservableGroups()[i]; -// System.out.println(i+1 + ":\t\t" + o.toString()); +// lg.info(i+1 + ":\t\t" + o.toString()); if(rbmmc.getParameter(o.getObservableGroupName()) != null) { - System.out.println(" ...already exists."); + lg.info(" ...already exists."); continue; // if it's already there we don't try to add it again; this should be true for all of them! } ArrayList terms = new ArrayList(); @@ -764,8 +772,9 @@ private void transform(SimulationContext simContext, SimulationContext transform exp.bindExpression(rbmmc.getSymbolTable()); RbmObservable originalObservable = rbmmc.getObservable(o.getObservableGroupName()); VCUnitDefinition observableUnitDefinition = originalObservable.getUnitDefinition(); - rbmmc.removeObservable(originalObservable); - Parameter newParameter = rbmmc.addParameter(o.getObservableGroupName(), exp, observableUnitDefinition); + + rbmmc.removeObservable(originalObservable, Model.PropertyNotificationMode.Silent); + Parameter newParameter = rbmmc.addParameter(o.getObservableGroupName(), exp, observableUnitDefinition, Model.PropertyNotificationMode.Silent); RbmObservable origObservable = simContext.getModel().getRbmModelContainer().getObservable(o.getObservableGroupName()); ModelEntityMapping em = new ModelEntityMapping(origObservable,newParameter); @@ -777,18 +786,15 @@ private void transform(SimulationContext simContext, SimulationContext transform simContext.appendToConsole(tcm); throw new UserCancelException(msg); } - endTime = System.currentTimeMillis(); - elapsedTime = endTime - startTime; - msg = "Adding " + outputSpec.getObservableGroups().length + " observables to model, " + elapsedTime + " ms"; - System.out.println(msg); +// endTime = System.currentTimeMillis(); +// elapsedTime = endTime - startTime; +// msg = "Adding " + outputSpec.getObservableGroups().length + " observables to model, " + elapsedTime + " ms"; +// lg.info(msg); } catch (PropertyVetoException | ModelException | ExpressionException | ClassNotFoundException | IOException ex) { throw new RuntimeException(ex.getMessage(), ex); } - System.out.println("Done transforming"); - msg = "Generating math..."; - System.out.println(msg); mathMappingCallback.setMessage(msg); mathMappingCallback.setProgressFraction(progressFractionQuota); } @@ -824,7 +830,7 @@ private Expression applyKineticsExpressions(BNGReaction bngReaction, KineticsPar throw new RuntimeException("unexpected identifier "+fakeSymbol+" in kinetic law during network generation"); } LocalParameter localParameter = this.kineticsParameterMap.get(fakeParameter); - System.out.println(localParameter.getNameScope()); + lg.info(localParameter.getNameScope()); if (localParameter.getNameScope() instanceof ReactionRule.ReactionRuleNameScope){ reactionRule = ((ReactionRule.ReactionRuleNameScope)localParameter.getNameScope()).getReactionRule(); } diff --git a/vcell-core/src/main/java/cbit/vcell/model/Model.java b/vcell-core/src/main/java/cbit/vcell/model/Model.java index 319b8f2630..a5a1681fe2 100644 --- a/vcell-core/src/main/java/cbit/vcell/model/Model.java +++ b/vcell-core/src/main/java/cbit/vcell/model/Model.java @@ -1572,7 +1572,10 @@ public ReactionRule createReactionRule(String label, Structure structure, boolea return new ReactionRule(Model.this, label, structure, bReversible); } - public final void setObservableList(List newValue) throws PropertyVetoException{ + public final void setObservableList(List newValue) throws PropertyVetoException { + setObservableList(newValue, PropertyNotificationMode.Loud); + } + public final void setObservableList(List newValue, PropertyNotificationMode mode) throws PropertyVetoException{ List oldValue = observableList; fireVetoableChange(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST, oldValue, newValue); if(oldValue != null){ @@ -1590,7 +1593,9 @@ public final void setObservableList(List newValue) throws Propert mt.setModel(Model.this); } } - firePropertyChange(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST, oldValue, newValue); + if(mode == PropertyNotificationMode.Loud) { + firePropertyChange(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST, oldValue, newValue); + } } public List getMolecularTypeList(){ @@ -1610,8 +1615,14 @@ public Parameter addFunction(String name, Expression expression, VCUnitDefinitio return Model.this.addModelParameter(new ModelParameter(name, expression, ROLE_UserDefined, unitDefinition)); } + public Parameter addParameter(String name, Expression expression, VCUnitDefinition unitDefinition, PropertyNotificationMode mode) throws ModelException, PropertyVetoException { + ModelParameter mp = new ModelParameter(name, expression, ROLE_UserDefined, unitDefinition); + return Model.this.addModelParameter(mp, mode); + + } public Parameter addParameter(String name, Expression expression, VCUnitDefinition unitDefinition) throws ModelException, PropertyVetoException{ - return Model.this.addModelParameter(new ModelParameter(name, expression, ROLE_UserDefined, unitDefinition)); + Parameter ret = addParameter(name, expression, unitDefinition, PropertyNotificationMode.Loud); + return ret; } public RbmObservable getObservable(String obName){ @@ -1639,12 +1650,16 @@ public Parameter getParameter(String obName){ } public boolean removeObservable(RbmObservable observable) throws PropertyVetoException{ + boolean ret = removeObservable(observable, PropertyNotificationMode.Loud); + return ret; + } + public boolean removeObservable(RbmObservable observable, PropertyNotificationMode mode) throws PropertyVetoException{ if(!observableList.contains(observable)){ return false; } ArrayList newValue = new ArrayList(observableList); newValue.remove(observable); - setObservableList(newValue); + setObservableList(newValue, mode); return true; } @@ -1957,6 +1972,11 @@ public void adjustRulesPatterns(MolecularType mt, MolecularComponent mc){ } } + public enum PropertyNotificationMode { + Silent, + Loud + } + public Model(Version argVersion){ this(argVersion, ModelUnitSystem.createDefaultVCModelUnitSystem()); } @@ -2052,11 +2072,14 @@ private ReservedSymbol[] createReservedSymbols(){ // ModelParameter modelParameter = new ModelParameter(name, expr, role, units); // return modelParameter; //} - public ModelParameter addModelParameter(Model.ModelParameter modelParameter) throws PropertyVetoException{ + ModelParameter ret = addModelParameter(modelParameter, PropertyNotificationMode.Loud); + return ret; + } + public ModelParameter addModelParameter(Model.ModelParameter modelParameter, PropertyNotificationMode mode) throws PropertyVetoException{ // if (!contains(modelParameter)){ Model.ModelParameter[] newModelParameters = ArrayUtils.addElement(fieldModelParameters, modelParameter); - setModelParameters(newModelParameters); + setModelParameters(newModelParameters, mode); // } return modelParameter; } @@ -3721,12 +3744,16 @@ public void setDiagrams(int index, Diagram diagrams){ ; } - public void setModelParameters(ModelParameter[] modelParameters) throws java.beans.PropertyVetoException{ + setModelParameters(modelParameters, PropertyNotificationMode.Loud); + } + public void setModelParameters(ModelParameter[] modelParameters, PropertyNotificationMode mode) throws java.beans.PropertyVetoException{ ModelParameter[] oldValue = fieldModelParameters; fireVetoableChange(Model.PROPERTY_NAME_MODEL_PARAMETERS, oldValue, modelParameters); fieldModelParameters = modelParameters; - firePropertyChange(Model.PROPERTY_NAME_MODEL_PARAMETERS, oldValue, modelParameters); + if(mode == PropertyNotificationMode.Loud) { + firePropertyChange(Model.PROPERTY_NAME_MODEL_PARAMETERS, oldValue, modelParameters); + } //System.out.print("vcModel model parameters ["); //for (ModelParameter p : oldValue){ diff --git a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java b/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java index bcb17b58d3..3e0cb7e070 100644 --- a/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java +++ b/vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLImporter.java @@ -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); @@ -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); } diff --git a/vcell-core/src/test/java/org/vcell/sbml/BMDB_SBMLImportTest.java b/vcell-core/src/test/java/org/vcell/sbml/BMDB_SBMLImportTest.java index 7bbc1702ad..7285e492b2 100644 --- a/vcell-core/src/test/java/org/vcell/sbml/BMDB_SBMLImportTest.java +++ b/vcell-core/src/test/java/org/vcell/sbml/BMDB_SBMLImportTest.java @@ -157,7 +157,7 @@ public static Map 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 ' ': 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 @@ -179,7 +179,6 @@ public static Map 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 ' ': node type 'notanumber' not supported yet faults.put(956, SBMLTestSuiteTest.FAULT.MATHML_PARSING); // cause: Error adding Lambda function UnsupportedConstruct: error parsing expression ' ': 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 diff --git a/vcell-core/src/test/java/org/vcell/sbml/SBMLTestSuiteTest.java b/vcell-core/src/test/java/org/vcell/sbml/SBMLTestSuiteTest.java index 439fa4a32e..c7ecfc0974 100644 --- a/vcell-core/src/test/java/org/vcell/sbml/SBMLTestSuiteTest.java +++ b/vcell-core/src/test/java/org/vcell/sbml/SBMLTestSuiteTest.java @@ -374,8 +374,6 @@ public static Collection 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); diff --git a/vcell-math/src/main/java/cbit/vcell/parser/ExpressionMathMLParser.java b/vcell-math/src/main/java/cbit/vcell/parser/ExpressionMathMLParser.java index 8fc9d7c1b9..3fdd14b178 100644 --- a/vcell-math/src/main/java/cbit/vcell/parser/ExpressionMathMLParser.java +++ b/vcell-math/src/main/java/cbit/vcell/parser/ExpressionMathMLParser.java @@ -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"); } } diff --git a/vcell-math/src/test/java/cbit/vcell/parser/MathMLTest.java b/vcell-math/src/test/java/cbit/vcell/parser/MathMLTest.java index 1c28811272..4aa7cd985b 100644 --- a/vcell-math/src/test/java/cbit/vcell/parser/MathMLTest.java +++ b/vcell-math/src/test/java/cbit/vcell/parser/MathMLTest.java @@ -80,6 +80,26 @@ public void testMathMLParsing_XOR() throws IOException, ExpressionException { assertTrue(equiv, msg); } + @Test + public void testNaN_MathmlParsing() throws ExpressionException { + String nanMathML = ""; + 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 = ""; + 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")