Skip to content

Commit 0efa9a3

Browse files
committed
Merge branch 'dan-ss-xmlproducer'
2 parents 029bfb7 + 5f3a9e1 commit 0efa9a3

File tree

3 files changed

+119
-39
lines changed

3 files changed

+119
-39
lines changed

vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -855,18 +855,22 @@ public class XMLTags {
855855
public final static String SiteAttributesSpecTag = "SiteAttributesSpec";
856856
public final static String SiteRefAttrTag = "SiteRef";
857857
public final static String MoleculeRefAttrTag = "MoleculeRef";
858-
public final static String SiteLocationRefAttrTag = "LocationRef";
859-
public final static String SiteInitialStateRefAttrTag = "InitialStateRef";
860-
public final static String SiteRadiusAttrTag = "Radius";
861-
public final static String SiteDiffusionAttrTag = "Diffusion";
862-
public final static String SiteColorAttrTag = "Color";
863-
public final static String SiteLocationTag = "Location";
864-
public final static String SiteXAttributeTag = "X";
865-
public final static String SiteYAttributeTag = "Y";
866-
public final static String SiteZAttributeTag = "Z";
867-
public final static String BondLengthAttrTag = "BondLength";
858+
public final static String SiteLocationRefAttrTag = "SiteLocationRef";
859+
public final static String SiteRadiusAttrTag = "SiteRadius";
860+
public final static String SiteDiffusionAttrTag = "SiteDiffusion";
861+
public final static String SiteColorAttrTag = "SiteColor";
862+
public final static String SiteCoordXAttrTag = "SiteCoordX";
863+
public final static String SiteCoordYAttrTag = "SiteCoordY";
864+
public final static String SiteCoordZAttrTag = "SiteCoordZ";
865+
866+
public final static String InternalLinkSpecTag = "InternalLinkSpec";
868867
public final static String SiteOneRefAttrTag = "SiteOneRef";
869868
public final static String SiteTwoRefAttrTag = "SiteTwoRef";
870869

870+
public final static String BondLengthAttrTag = "BondLength";
871+
public final static String SubTypeAttrTag = "SubType";
872+
public final static String TransitionConditionAttrTag = "TransitionCondition";
873+
874+
871875

872876
}

vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java

Lines changed: 104 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
import java.util.Enumeration;
2020
import java.util.HashMap;
2121
import java.util.Iterator;
22+
import java.util.LinkedHashMap;
2223
import java.util.List;
2324
import java.util.Locale;
2425
import java.util.Map;
26+
import java.util.Map.Entry;
27+
import java.util.Set;
2528
import java.util.Vector;
2629

2730
import org.apache.commons.lang3.mutable.Mutable;
@@ -31,6 +34,8 @@
3134
import org.jdom.Document;
3235
import org.jdom.Element;
3336
import org.jdom.Namespace;
37+
import org.jdom.output.Format;
38+
import org.jdom.output.XMLOutputter;
3439
import org.sbpax.schemas.util.DefaultNameSpaces;
3540
import org.vcell.chombo.ChomboSolverSpec;
3641
import org.vcell.chombo.RefinementRoi;
@@ -121,15 +126,18 @@
121126
import cbit.vcell.mapping.MicroscopeMeasurement.ConvolutionKernel;
122127
import cbit.vcell.mapping.MicroscopeMeasurement.GaussianConvolutionKernel;
123128
import cbit.vcell.mapping.MicroscopeMeasurement.ProjectionZKernel;
129+
import cbit.vcell.mapping.MolecularInternalLinkSpec;
124130
import cbit.vcell.mapping.ParameterContext.LocalParameter;
125131
import cbit.vcell.mapping.ParameterContext.ParameterRoleEnum;
132+
import cbit.vcell.mapping.ReactionRuleSpec.TransitionCondition;
126133
import cbit.vcell.mapping.RateRule;
127134
import cbit.vcell.mapping.ReactionContext;
128135
import cbit.vcell.mapping.ReactionRuleSpec;
129136
import cbit.vcell.mapping.ReactionSpec;
130137
import cbit.vcell.mapping.SimulationContext;
131138
import cbit.vcell.mapping.SimulationContext.Application;
132139
import cbit.vcell.mapping.SimulationContext.SimulationContextParameter;
140+
import cbit.vcell.mapping.SiteAttributesSpec;
133141
import cbit.vcell.mapping.SpeciesContextSpec;
134142
import cbit.vcell.mapping.StructureMapping;
135143
import cbit.vcell.mapping.TotalCurrentClampStimulus;
@@ -1483,7 +1491,7 @@ private Element getXML(ReactionContext param) {
14831491
//Add SpeciesContextSpecs
14841492
SpeciesContextSpec[] array = param.getSpeciesContextSpecs();
14851493
for (int i =0; i<array.length ; i ++){
1486-
reactioncontext.addContent( getXML(array[i]) );
1494+
reactioncontext.addContent( getXML(array[i], param.getSimulationContext()) );
14871495
}
14881496
//Add ReactionSpecs
14891497
ReactionSpec[] reactionarray = param.getReactionSpecs();
@@ -1492,8 +1500,8 @@ private Element getXML(ReactionContext param) {
14921500
}
14931501
//Add ReactionRuleSpecs
14941502
ReactionRuleSpec[] reactionRuleArray = param.getReactionRuleSpecs();
1495-
if (reactionRuleArray.length>0){
1496-
reactioncontext.addContent( getXML(reactionRuleArray) );
1503+
if (reactionRuleArray.length>0) {
1504+
reactioncontext.addContent( getXML(reactionRuleArray, param.getSimulationContext()) );
14971505
}
14981506

14991507
return reactioncontext;
@@ -1517,13 +1525,28 @@ private Element getXML(ReactionSpec param) {
15171525
}
15181526

15191527
//For rateRules in SimulationContext
1520-
public Element getXML(ReactionRuleSpec[] reactionRuleSpecs) {
1528+
public Element getXML(ReactionRuleSpec[] reactionRuleSpecs, SimulationContext simContext) {
15211529
Element reactionRuleSpecsElement = new Element(XMLTags.ReactionRuleSpecsTag);
15221530
for (ReactionRuleSpec reactionRuleSpec : reactionRuleSpecs){
15231531
Element reactionRuleSpecElement = new Element(XMLTags.ReactionRuleSpecTag);
15241532
reactionRuleSpecElement.setAttribute(XMLTags.ReactionRuleRefAttrTag, mangle(reactionRuleSpec.getReactionRule().getName()));
15251533
reactionRuleSpecElement.setAttribute(XMLTags.ReactionRuleMappingAttrTag, mangle(reactionRuleSpec.getReactionRuleMapping().getDatabaseName()));
1526-
1534+
if(Application.SPRINGSALAD == simContext.getApplicationType()) {
1535+
reactionRuleSpecElement.setAttribute(XMLTags.BondLengthAttrTag, Double.toString(reactionRuleSpec.getFieldBondLength()));
1536+
//
1537+
// the next 2 attributes are sent only for debugging purposes, they are derived attributes and should be calculated at needed
1538+
//
1539+
Map<String, Object> analysisResults = new LinkedHashMap<> ();
1540+
reactionRuleSpec.analizeReaction(analysisResults);
1541+
ReactionRuleSpec.Subtype st = reactionRuleSpec.getSubtype(analysisResults);
1542+
reactionRuleSpecElement.setAttribute(XMLTags.SubTypeAttrTag, st.columnName);
1543+
if(ReactionRuleSpec.Subtype.TRANSITION == st) {
1544+
TransitionCondition tc = reactionRuleSpec.getTransitionCondition(analysisResults);
1545+
if(tc != null) {
1546+
reactionRuleSpecElement.setAttribute(XMLTags.TransitionConditionAttrTag, tc.vcellName);
1547+
}
1548+
}
1549+
}
15271550
reactionRuleSpecsElement.addContent(reactionRuleSpecElement);
15281551
}
15291552

@@ -1544,19 +1567,24 @@ public Element getXML(SimulationContext param, BioModel bioModel) throws XmlPars
15441567
String name = mangle(param.getName());
15451568
simulationcontext.setAttribute(XMLTags.NameAttrTag, name);
15461569
//set isStoch, isUsingConcentration attributes
1547-
if (applicationType == Application.NETWORK_STOCHASTIC)
1548-
{
1570+
if (applicationType == Application.NETWORK_STOCHASTIC) {
15491571
simulationcontext.setAttribute(XMLTags.StochAttrTag, "true");
15501572
setBooleanAttribute(simulationcontext, XMLTags.ConcentrationAttrTag, param.isUsingConcentration());
15511573
// write out 'randomizeInitConditin' flag only if non-spatial stochastic simContext
15521574
if(param.getGeometry().getDimension() == 0) {
15531575
setBooleanAttribute(simulationcontext, XMLTags.RandomizeInitConditionTag,param.isRandomizeInitCondition());
15541576
}
1555-
}
1556-
else
1557-
{
1577+
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, false);
1578+
} else if(applicationType == Application.SPRINGSALAD) {
1579+
boolean isRandomizeInitCondition = param.isRandomizeInitCondition();
1580+
boolean isUsingConcentration = param.isUsingConcentration();
1581+
simulationcontext.setAttribute(XMLTags.StochAttrTag, "false");
1582+
setBooleanAttribute(simulationcontext, XMLTags.ConcentrationAttrTag, isUsingConcentration);
1583+
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, true);
1584+
} else {
15581585
simulationcontext.setAttribute(XMLTags.StochAttrTag, "false");
15591586
simulationcontext.setAttribute(XMLTags.ConcentrationAttrTag, "true");
1587+
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, false);
15601588
}
15611589
final boolean ruleBased = param.getApplicationType() == SimulationContext.Application.RULE_BASED_STOCHASTIC;
15621590
setBooleanAttribute(simulationcontext,XMLTags.RuleBasedAttrTag, ruleBased);
@@ -1567,8 +1595,6 @@ public Element getXML(SimulationContext param, BioModel bioModel) throws XmlPars
15671595
setBooleanAttribute(simulationcontext, XMLTags.RandomizeInitConditionTag,param.isRandomizeInitCondition());
15681596
}
15691597
}
1570-
final boolean springSaLaD = param.getApplicationType() == SimulationContext.Application.SPRINGSALAD;
1571-
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, springSaLaD);
15721598

15731599
setBooleanAttribute(simulationcontext,XMLTags.MassConservationModelReductionTag, param.isUsingMassConservationModelReduction());
15741600
setBooleanAttribute(simulationcontext,XMLTags.InsufficientIterationsTag,param.isInsufficientIterations());
@@ -1829,24 +1855,21 @@ private Element getXML(FieldDataSymbol fds, ModelUnitSystem modelUnitSystem) {
18291855
<LocalizedCompoundSpec LocalizedCompoundRef="MT0" ForceConstant="false" WellMixed="false" ForceContinuous="false">
18301856
<InitialConcentration>0.0</InitialConcentration>
18311857
<Diffusion>10.0</Diffusion>
1832-
<SiteAttributesMap>
1833-
<SiteAttributesSpec SiteRef="Site0" MoleculeRef="MT0" LocationRef="Intracellular" InitialStateRef="state0" Radius="1.0" Diffusion="1.0" Color="RED">
1834-
<Location X="2.0" Y="1.0" Z="1.0" />
1835-
</SiteAttributesSpec>
1836-
<SiteAttributesSpec SiteRef="Anchor" MoleculeRef="MT0" LocationRef="Membrane" InitialStateRef="anchor" Radius="1.0" Diffusion="1.0" Color="RED">
1837-
<Location X="1.0" Y="1.0" Z="1.0" />
1838-
</SiteAttributesSpec>
1839-
</SiteAttributesMap>
1840-
<InternalLinkSet>
1841-
<InternalLinkSpec MoleculeRef="MT0" SiteOneRef="Anchor" SiteTwoRef="Site0" />
1842-
<InternalLinkSet>
1858+
1859+
<SiteAttributesSpec SiteRef="Site0" MoleculeRef="MT0" SiteLocationRefAttrTag="Intracellular" Radius="1.0" Diffusion="1.0" Color="RED"
1860+
SiteCoordX="1.0" SiteCoordZ="1.0" SiteCoordZ="1.0" />
1861+
<SiteAttributesSpec SiteRef="Anchor" MoleculeRef="MT0" SiteLocationRefAttrTag="Membrane" Radius="1.0" Diffusion="1.0" Color="RED"
1862+
SiteCoordX="1.0" SiteCoordZ="1.0" SiteCoordZ="1.0" />
1863+
1864+
<InternalLinkSpec MoleculeRef="MT0" SiteOneRef="Anchor" SiteTwoRef="Site0" />
1865+
18431866
</LocalizedCompoundSpec>
18441867
<ReactionRuleSpecs>
18451868
<ReactionRuleSpec ReactionRuleRef="r0" ReactionRuleMapping="included" BondLength="1.0" />
18461869
</ReactionRuleSpecs>
18471870
</ReactionContext>
18481871
*/
1849-
private Element getXML(SpeciesContextSpec param) {
1872+
private Element getXML(SpeciesContextSpec param, SimulationContext simContext) {
18501873
Element speciesContextSpecElement = new Element(XMLTags.SpeciesContextSpecTag);
18511874

18521875
//Add Attributes
@@ -1877,11 +1900,64 @@ else if(initAmt != null)
18771900
}
18781901
//Add diffusion
18791902
cbit.vcell.parser.Expression diffRate = param.getDiffusionParameter().getExpression();
1880-
if (diffRate!=null){
1881-
Element diffusion = new Element(XMLTags.DiffusionTag);
1882-
diffusion.addContent(mangleExpression(diffRate));
1883-
speciesContextSpecElement.addContent(diffusion);
1903+
if (diffRate!=null) {
1904+
if(Application.SPRINGSALAD != simContext.getApplicationType()) { // in SS diffusion only happens at the site level
1905+
Element diffusion = new Element(XMLTags.DiffusionTag);
1906+
diffusion.addContent(mangleExpression(diffRate));
1907+
speciesContextSpecElement.addContent(diffusion);
1908+
}
1909+
}
1910+
1911+
// SpringSaLaD specific stuff
1912+
// 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?
1913+
if(Application.SPRINGSALAD == simContext.getApplicationType() && param.getInternalLinkSet() != null && param.getInternalLinkSet().size() > 0 ) {
1914+
for(MolecularInternalLinkSpec mils : param.getInternalLinkSet()) {
1915+
SpeciesContext sc = param.getSpeciesContext();
1916+
SpeciesPattern sp = sc.getSpeciesPattern();
1917+
if(sp == null || sp.getMolecularTypePatterns().size() != 1) {
1918+
break; // the species pattern must refer to exactly one molecule, links are intramollecular only
1919+
// throw new IllegalArgumentException("The species pattern must contain exactly one molecule.");
1920+
}
1921+
MolecularTypePattern mtp = sp.getMolecularTypePatterns().get(0); // the one and only
1922+
MolecularType mt = mtp.getMolecularType();
1923+
1924+
Element milsElement = new Element(XMLTags.InternalLinkSpecTag);
1925+
milsElement.setAttribute(XMLTags.MoleculeRefAttrTag, mt.getName());
1926+
milsElement.setAttribute(XMLTags.SiteOneRefAttrTag, mils.getMolecularComponentPatternOne().getMolecularComponent().getName());
1927+
milsElement.setAttribute(XMLTags.SiteTwoRefAttrTag, mils.getMolecularComponentPatternTwo().getMolecularComponent().getName());
1928+
speciesContextSpecElement.addContent(milsElement);
1929+
}
1930+
}
1931+
if(Application.SPRINGSALAD == simContext.getApplicationType() && param.getSiteAttributesMap() != null && param.getSiteAttributesMap().size() > 0) {
1932+
for (Entry<MolecularComponentPattern, SiteAttributesSpec> entry : param.getSiteAttributesMap().entrySet()) {
1933+
SpeciesContext sc = param.getSpeciesContext();
1934+
SpeciesPattern sp = sc.getSpeciesPattern();
1935+
if(sp == null || sp.getMolecularTypePatterns().size() != 1) {
1936+
break; // the species pattern must refer to exactly one molecule, links are intramollecular only
1937+
// throw new IllegalArgumentException("The species pattern must contain exactly one molecule.");
1938+
}
1939+
MolecularTypePattern mtp = sp.getMolecularTypePatterns().get(0); // the one and only
1940+
MolecularType mt = mtp.getMolecularType();
1941+
1942+
MolecularComponentPattern mcp = entry.getKey();
1943+
SiteAttributesSpec sas = entry.getValue();
1944+
Element sasElement = new Element(XMLTags.SiteAttributesSpecTag);
1945+
sasElement.setAttribute(XMLTags.SiteRefAttrTag, mcp.getMolecularComponent().getName());
1946+
sasElement.setAttribute(XMLTags.MoleculeRefAttrTag, mt.getName());
1947+
sasElement.setAttribute(XMLTags.SiteLocationRefAttrTag, sas.getLocation().getName());
1948+
sasElement.setAttribute(XMLTags.SiteCoordXAttrTag, Double.toString(sas.getCoordinate().getX()));
1949+
sasElement.setAttribute(XMLTags.SiteCoordYAttrTag, Double.toString(sas.getCoordinate().getX()));
1950+
sasElement.setAttribute(XMLTags.SiteCoordZAttrTag, Double.toString(sas.getCoordinate().getX()));
1951+
sasElement.setAttribute(XMLTags.SiteRadiusAttrTag, Double.toString(sas.getRadius()));
1952+
sasElement.setAttribute(XMLTags.SiteDiffusionAttrTag, Double.toString(sas.getDiffusionRate()));
1953+
sasElement.setAttribute(XMLTags.SiteColorAttrTag, sas.getColor().getName());
1954+
speciesContextSpecElement.addContent(sasElement);
1955+
}
18841956
}
1957+
XMLOutputter outp = new XMLOutputter(Format.getPrettyFormat());
1958+
String sout = outp.outputString(speciesContextSpecElement);
1959+
System.out.println(sout);
1960+
18851961
// write BoundaryConditions
18861962
cbit.vcell.parser.Expression exp;
18871963
Element boundaries = new Element(XMLTags.BoundariesTag);

vcell-server/src/main/java/cbit/vcell/modeldb/SimContextTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ public static String getAppComponentsForDatabase(SimulationContext simContext) {
315315
// ReactionRuleSpecs
316316
ReactionRuleSpec[] reactionRuleSpecs = simContext.getReactionContext().getReactionRuleSpecs();
317317
if (reactionRuleSpecs != null && reactionRuleSpecs.length > 0){
318-
Element reactionRuleSpecsElement = xmlProducer.getXML(reactionRuleSpecs);
318+
Element reactionRuleSpecsElement = xmlProducer.getXML(reactionRuleSpecs, simContext);
319319
appComponentsElement.addContent(reactionRuleSpecsElement);
320320
}
321321

0 commit comments

Comments
 (0)