From 7a08c8f3bee00f7304afd6bc8646af430b0bd035 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Thu, 7 Sep 2023 15:14:30 -0400 Subject: [PATCH 1/4] WIP xml producer, springsalad specific fields --- .../src/main/java/cbit/vcell/xml/XMLTags.java | 20 +++--- .../main/java/cbit/vcell/xml/Xmlproducer.java | 69 ++++++++++++++++--- 2 files changed, 69 insertions(+), 20 deletions(-) diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java index 81e9f345a8..f77c0f0a6b 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java @@ -855,16 +855,18 @@ public class XMLTags { public final static String SiteAttributesSpecTag = "SiteAttributesSpec"; public final static String SiteRefAttrTag = "SiteRef"; public final static String MoleculeRefAttrTag = "MoleculeRef"; - public final static String SiteLocationRefAttrTag = "LocationRef"; - public final static String SiteInitialStateRefAttrTag = "InitialStateRef"; - public final static String SiteRadiusAttrTag = "Radius"; - public final static String SiteDiffusionAttrTag = "Diffusion"; - public final static String SiteColorAttrTag = "Color"; - public final static String SiteLocationTag = "Location"; - public final static String SiteXAttributeTag = "X"; - public final static String SiteYAttributeTag = "Y"; - public final static String SiteZAttributeTag = "Z"; + public final static String SiteLocationRefAttrTag = "SiteLocationRef"; + public final static String SiteInitialStateRefAttrTag = "SiteInitialStateRef"; + public final static String SiteRadiusAttrTag = "SiteRadius"; + public final static String SiteDiffusionAttrTag = "SiteDiffusion"; + public final static String SiteColorAttrTag = "SiteColor"; + public final static String SiteLocationTag = "SiteLocation"; + public final static String SiteXAttributeTag = "SiteX"; + public final static String SiteYAttributeTag = "SiteY"; + public final static String SiteZAttributeTag = "SiteZ"; public final static String BondLengthAttrTag = "BondLength"; + + public final static String InternalLinkSpecTag = "internallinkSpec"; public final static String SiteOneRefAttrTag = "SiteOneRef"; public final static String SiteTwoRefAttrTag = "SiteTwoRef"; diff --git a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java index 8cf5df450a..8ce098c83e 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java @@ -22,6 +22,8 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; import java.util.Vector; import org.apache.commons.lang3.mutable.Mutable; @@ -121,6 +123,7 @@ import cbit.vcell.mapping.MicroscopeMeasurement.ConvolutionKernel; import cbit.vcell.mapping.MicroscopeMeasurement.GaussianConvolutionKernel; import cbit.vcell.mapping.MicroscopeMeasurement.ProjectionZKernel; +import cbit.vcell.mapping.MolecularInternalLinkSpec; import cbit.vcell.mapping.ParameterContext.LocalParameter; import cbit.vcell.mapping.ParameterContext.ParameterRoleEnum; import cbit.vcell.mapping.RateRule; @@ -130,6 +133,7 @@ import cbit.vcell.mapping.SimulationContext; import cbit.vcell.mapping.SimulationContext.Application; import cbit.vcell.mapping.SimulationContext.SimulationContextParameter; +import cbit.vcell.mapping.SiteAttributesSpec; import cbit.vcell.mapping.SpeciesContextSpec; import cbit.vcell.mapping.StructureMapping; import cbit.vcell.mapping.TotalCurrentClampStimulus; @@ -1829,17 +1833,16 @@ private Element getXML(FieldDataSymbol fds, ModelUnitSystem modelUnitSystem) { 0.0 10.0 - - - - - - - - - - - + + + + + + + + + + @@ -1882,6 +1885,50 @@ else if(initAmt != null) diffusion.addContent(mangleExpression(diffRate)); speciesContextSpecElement.addContent(diffusion); } + + // SpringSaLaD specific stuff + // the producer is dumb, we save whatever we have; the reader may be smart and check for consistency, maybe initialize what's missing with defaults? + if(param.getInternalLinkSet() != null && param.getInternalLinkSet().size() > 0 ) { + for(MolecularInternalLinkSpec mils : param.getInternalLinkSet()) { + SpeciesContext sc = param.getSpeciesContext(); + SpeciesPattern sp = sc.getSpeciesPattern(); + if(sp == null || sp.getMolecularTypePatterns().size() != 1) { + break; // the species pattern must refer to exactly one molecule, links are intramollecular only + // throw new IllegalArgumentException("The species pattern must contain exactly one molecule."); + } + MolecularTypePattern mtp = sp.getMolecularTypePatterns().get(0); // the one and only + MolecularType mt = mtp.getMolecularType(); + + Element milsElement = new Element(XMLTags.InternalLinkSpecTag); + milsElement.setAttribute(XMLTags.MoleculeRefAttrTag, mt.getName()); + milsElement.setAttribute(XMLTags.SiteOneRefAttrTag, mils.getMolecularComponentPatternOne().getMolecularComponent().getName()); + milsElement.setAttribute(XMLTags.SiteTwoRefAttrTag, mils.getMolecularComponentPatternTwo().getMolecularComponent().getName()); + speciesContextSpecElement.addContent(milsElement); + } + } + if(param.getSiteAttributesMap() != null && param.getSiteAttributesMap().size() > 0) { + for (Entry entry : param.getSiteAttributesMap().entrySet()) { + SpeciesContext sc = param.getSpeciesContext(); + SpeciesPattern sp = sc.getSpeciesPattern(); + if(sp == null || sp.getMolecularTypePatterns().size() != 1) { + break; // the species pattern must refer to exactly one molecule, links are intramollecular only + // throw new IllegalArgumentException("The species pattern must contain exactly one molecule."); + } + MolecularTypePattern mtp = sp.getMolecularTypePatterns().get(0); // the one and only + MolecularType mt = mtp.getMolecularType(); + + MolecularComponentPattern mcp = entry.getKey(); + SiteAttributesSpec sas = entry.getValue(); + Element sasElement = new Element(XMLTags.SiteAttributesSpecTag); + sasElement.setAttribute(XMLTags.SiteRefAttrTag, mcp.getMolecularComponent().getName()); + sasElement.setAttribute(XMLTags.MoleculeRefAttrTag, mt.getName()); + // TODO: add more attributes + + speciesContextSpecElement.addContent(sasElement); + } + } + + // write BoundaryConditions cbit.vcell.parser.Expression exp; Element boundaries = new Element(XMLTags.BoundariesTag); From 70dd6963f5ce86ca91a3d9477eeebea9af6df6c3 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Fri, 8 Sep 2023 15:51:00 -0400 Subject: [PATCH 2/4] WIP xml producer, springsalad specific fields --- .../src/main/java/cbit/vcell/xml/XMLTags.java | 8 +++--- .../main/java/cbit/vcell/xml/Xmlproducer.java | 25 ++++++++++++------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java index f77c0f0a6b..b2577a5c1b 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java @@ -856,14 +856,12 @@ public class XMLTags { public final static String SiteRefAttrTag = "SiteRef"; public final static String MoleculeRefAttrTag = "MoleculeRef"; public final static String SiteLocationRefAttrTag = "SiteLocationRef"; - public final static String SiteInitialStateRefAttrTag = "SiteInitialStateRef"; public final static String SiteRadiusAttrTag = "SiteRadius"; public final static String SiteDiffusionAttrTag = "SiteDiffusion"; public final static String SiteColorAttrTag = "SiteColor"; - public final static String SiteLocationTag = "SiteLocation"; - public final static String SiteXAttributeTag = "SiteX"; - public final static String SiteYAttributeTag = "SiteY"; - public final static String SiteZAttributeTag = "SiteZ"; + public final static String SiteCoordXAttrTag = "SiteCoordX"; + public final static String SiteCoordYAttrTag = "SiteCoordY"; + public final static String SiteCoordZAttrTag = "SiteCoordZ"; public final static String BondLengthAttrTag = "BondLength"; public final static String InternalLinkSpecTag = "internallinkSpec"; diff --git a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java index 8ce098c83e..6bb46212b2 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java @@ -33,6 +33,8 @@ import org.jdom.Document; import org.jdom.Element; import org.jdom.Namespace; +import org.jdom.output.Format; +import org.jdom.output.XMLOutputter; import org.sbpax.schemas.util.DefaultNameSpaces; import org.vcell.chombo.ChomboSolverSpec; import org.vcell.chombo.RefinementRoi; @@ -1834,12 +1836,10 @@ private Element getXML(FieldDataSymbol fds, ModelUnitSystem modelUnitSystem) { 0.0 10.0 - - - - - - + + @@ -1922,12 +1922,19 @@ else if(initAmt != null) Element sasElement = new Element(XMLTags.SiteAttributesSpecTag); sasElement.setAttribute(XMLTags.SiteRefAttrTag, mcp.getMolecularComponent().getName()); sasElement.setAttribute(XMLTags.MoleculeRefAttrTag, mt.getName()); - // TODO: add more attributes - + sasElement.setAttribute(XMLTags.SiteLocationRefAttrTag, sas.getLocation().getName()); + sasElement.setAttribute(XMLTags.SiteCoordXAttrTag, Double.toString(sas.getCoordinate().getX())); + sasElement.setAttribute(XMLTags.SiteCoordYAttrTag, Double.toString(sas.getCoordinate().getX())); + sasElement.setAttribute(XMLTags.SiteCoordZAttrTag, Double.toString(sas.getCoordinate().getX())); + sasElement.setAttribute(XMLTags.SiteRadiusAttrTag, Double.toString(sas.getRadius())); + sasElement.setAttribute(XMLTags.SiteDiffusionAttrTag, Double.toString(sas.getDiffusionRate())); + sasElement.setAttribute(XMLTags.SiteColorAttrTag, sas.getColor().getName()); speciesContextSpecElement.addContent(sasElement); } } - + XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat()); + String sout = outp.outputString(speciesContextSpecElement); + System.out.println(sout); // write BoundaryConditions cbit.vcell.parser.Expression exp; From f58ea331ca5c5e017e9d94c35da752cc231eaa49 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Wed, 13 Sep 2023 13:30:57 -0400 Subject: [PATCH 3/4] WIP the XMLproducer for springsalad (general application flags management, localized compound spec, internal link spec, site attribute spec) --- .../src/main/java/cbit/vcell/xml/XMLTags.java | 2 +- .../main/java/cbit/vcell/xml/Xmlproducer.java | 35 +++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java index b2577a5c1b..0a11179dd3 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java @@ -864,7 +864,7 @@ public class XMLTags { public final static String SiteCoordZAttrTag = "SiteCoordZ"; public final static String BondLengthAttrTag = "BondLength"; - public final static String InternalLinkSpecTag = "internallinkSpec"; + public final static String InternalLinkSpecTag = "InternalLinkSpec"; public final static String SiteOneRefAttrTag = "SiteOneRef"; public final static String SiteTwoRefAttrTag = "SiteTwoRef"; diff --git a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java index 6bb46212b2..e901607c41 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java @@ -1489,7 +1489,7 @@ private Element getXML(ReactionContext param) { //Add SpeciesContextSpecs SpeciesContextSpec[] array = param.getSpeciesContextSpecs(); for (int i =0; i */ -private Element getXML(SpeciesContextSpec param) { +private Element getXML(SpeciesContextSpec param, SimulationContext simContext) { Element speciesContextSpecElement = new Element(XMLTags.SpeciesContextSpecTag); //Add Attributes @@ -1880,15 +1883,17 @@ else if(initAmt != null) } //Add diffusion cbit.vcell.parser.Expression diffRate = param.getDiffusionParameter().getExpression(); - if (diffRate!=null){ - Element diffusion = new Element(XMLTags.DiffusionTag); - diffusion.addContent(mangleExpression(diffRate)); - speciesContextSpecElement.addContent(diffusion); + if (diffRate!=null) { + if(Application.SPRINGSALAD != simContext.getApplicationType()) { // in SS diffusion only happens at the site level + Element diffusion = new Element(XMLTags.DiffusionTag); + diffusion.addContent(mangleExpression(diffRate)); + speciesContextSpecElement.addContent(diffusion); + } } // SpringSaLaD specific stuff // the producer is dumb, we save whatever we have; the reader may be smart and check for consistency, maybe initialize what's missing with defaults? - if(param.getInternalLinkSet() != null && param.getInternalLinkSet().size() > 0 ) { + if(Application.SPRINGSALAD == simContext.getApplicationType() && param.getInternalLinkSet() != null && param.getInternalLinkSet().size() > 0 ) { for(MolecularInternalLinkSpec mils : param.getInternalLinkSet()) { SpeciesContext sc = param.getSpeciesContext(); SpeciesPattern sp = sc.getSpeciesPattern(); @@ -1906,7 +1911,7 @@ else if(initAmt != null) speciesContextSpecElement.addContent(milsElement); } } - if(param.getSiteAttributesMap() != null && param.getSiteAttributesMap().size() > 0) { + if(Application.SPRINGSALAD == simContext.getApplicationType() && param.getSiteAttributesMap() != null && param.getSiteAttributesMap().size() > 0) { for (Entry entry : param.getSiteAttributesMap().entrySet()) { SpeciesContext sc = param.getSpeciesContext(); SpeciesPattern sp = sc.getSpeciesPattern(); From 5f3a9e131abcc6572eb9ce04a68ef2e7a407d418 Mon Sep 17 00:00:00 2001 From: Dan Vasilescu Date: Wed, 13 Sep 2023 14:47:38 -0400 Subject: [PATCH 4/4] WIP the XMLproducer for springsalad (springsalad-specific reaction rule spec params) --- .../src/main/java/cbit/vcell/xml/XMLTags.java | 6 ++++- .../main/java/cbit/vcell/xml/Xmlproducer.java | 25 ++++++++++++++++--- .../cbit/vcell/modeldb/SimContextTable.java | 2 +- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java index 0a11179dd3..5db5d3b36c 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java @@ -862,11 +862,15 @@ public class XMLTags { public final static String SiteCoordXAttrTag = "SiteCoordX"; public final static String SiteCoordYAttrTag = "SiteCoordY"; public final static String SiteCoordZAttrTag = "SiteCoordZ"; - public final static String BondLengthAttrTag = "BondLength"; public final static String InternalLinkSpecTag = "InternalLinkSpec"; public final static String SiteOneRefAttrTag = "SiteOneRef"; public final static String SiteTwoRefAttrTag = "SiteTwoRef"; + public final static String BondLengthAttrTag = "BondLength"; + public final static String SubTypeAttrTag = "SubType"; + public final static String TransitionConditionAttrTag = "TransitionCondition"; + + } diff --git a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java index e901607c41..3d200a0484 100644 --- a/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java +++ b/vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java @@ -19,6 +19,7 @@ import java.util.Enumeration; import java.util.HashMap; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -128,6 +129,7 @@ import cbit.vcell.mapping.MolecularInternalLinkSpec; import cbit.vcell.mapping.ParameterContext.LocalParameter; import cbit.vcell.mapping.ParameterContext.ParameterRoleEnum; +import cbit.vcell.mapping.ReactionRuleSpec.TransitionCondition; import cbit.vcell.mapping.RateRule; import cbit.vcell.mapping.ReactionContext; import cbit.vcell.mapping.ReactionRuleSpec; @@ -1498,8 +1500,8 @@ private Element getXML(ReactionContext param) { } //Add ReactionRuleSpecs ReactionRuleSpec[] reactionRuleArray = param.getReactionRuleSpecs(); - if (reactionRuleArray.length>0){ - reactioncontext.addContent( getXML(reactionRuleArray) ); + if (reactionRuleArray.length>0) { + reactioncontext.addContent( getXML(reactionRuleArray, param.getSimulationContext()) ); } return reactioncontext; @@ -1523,13 +1525,28 @@ private Element getXML(ReactionSpec param) { } //For rateRules in SimulationContext -public Element getXML(ReactionRuleSpec[] reactionRuleSpecs) { +public Element getXML(ReactionRuleSpec[] reactionRuleSpecs, SimulationContext simContext) { Element reactionRuleSpecsElement = new Element(XMLTags.ReactionRuleSpecsTag); for (ReactionRuleSpec reactionRuleSpec : reactionRuleSpecs){ Element reactionRuleSpecElement = new Element(XMLTags.ReactionRuleSpecTag); reactionRuleSpecElement.setAttribute(XMLTags.ReactionRuleRefAttrTag, mangle(reactionRuleSpec.getReactionRule().getName())); reactionRuleSpecElement.setAttribute(XMLTags.ReactionRuleMappingAttrTag, mangle(reactionRuleSpec.getReactionRuleMapping().getDatabaseName())); - + if(Application.SPRINGSALAD == simContext.getApplicationType()) { + reactionRuleSpecElement.setAttribute(XMLTags.BondLengthAttrTag, Double.toString(reactionRuleSpec.getFieldBondLength())); + // + // the next 2 attributes are sent only for debugging purposes, they are derived attributes and should be calculated at needed + // + Map analysisResults = new LinkedHashMap<> (); + reactionRuleSpec.analizeReaction(analysisResults); + ReactionRuleSpec.Subtype st = reactionRuleSpec.getSubtype(analysisResults); + reactionRuleSpecElement.setAttribute(XMLTags.SubTypeAttrTag, st.columnName); + if(ReactionRuleSpec.Subtype.TRANSITION == st) { + TransitionCondition tc = reactionRuleSpec.getTransitionCondition(analysisResults); + if(tc != null) { + reactionRuleSpecElement.setAttribute(XMLTags.TransitionConditionAttrTag, tc.vcellName); + } + } + } reactionRuleSpecsElement.addContent(reactionRuleSpecElement); } diff --git a/vcell-server/src/main/java/cbit/vcell/modeldb/SimContextTable.java b/vcell-server/src/main/java/cbit/vcell/modeldb/SimContextTable.java index 0fae894f50..199bbca316 100644 --- a/vcell-server/src/main/java/cbit/vcell/modeldb/SimContextTable.java +++ b/vcell-server/src/main/java/cbit/vcell/modeldb/SimContextTable.java @@ -315,7 +315,7 @@ public static String getAppComponentsForDatabase(SimulationContext simContext) { // ReactionRuleSpecs ReactionRuleSpec[] reactionRuleSpecs = simContext.getReactionContext().getReactionRuleSpecs(); if (reactionRuleSpecs != null && reactionRuleSpecs.length > 0){ - Element reactionRuleSpecsElement = xmlProducer.getXML(reactionRuleSpecs); + Element reactionRuleSpecsElement = xmlProducer.getXML(reactionRuleSpecs, simContext); appComponentsElement.addContent(reactionRuleSpecsElement); }