19
19
import java .util .Enumeration ;
20
20
import java .util .HashMap ;
21
21
import java .util .Iterator ;
22
+ import java .util .LinkedHashMap ;
22
23
import java .util .List ;
23
24
import java .util .Locale ;
24
25
import java .util .Map ;
26
+ import java .util .Map .Entry ;
27
+ import java .util .Set ;
25
28
import java .util .Vector ;
26
29
27
30
import org .apache .commons .lang3 .mutable .Mutable ;
31
34
import org .jdom .Document ;
32
35
import org .jdom .Element ;
33
36
import org .jdom .Namespace ;
37
+ import org .jdom .output .Format ;
38
+ import org .jdom .output .XMLOutputter ;
34
39
import org .sbpax .schemas .util .DefaultNameSpaces ;
35
40
import org .vcell .chombo .ChomboSolverSpec ;
36
41
import org .vcell .chombo .RefinementRoi ;
121
126
import cbit .vcell .mapping .MicroscopeMeasurement .ConvolutionKernel ;
122
127
import cbit .vcell .mapping .MicroscopeMeasurement .GaussianConvolutionKernel ;
123
128
import cbit .vcell .mapping .MicroscopeMeasurement .ProjectionZKernel ;
129
+ import cbit .vcell .mapping .MolecularInternalLinkSpec ;
124
130
import cbit .vcell .mapping .ParameterContext .LocalParameter ;
125
131
import cbit .vcell .mapping .ParameterContext .ParameterRoleEnum ;
132
+ import cbit .vcell .mapping .ReactionRuleSpec .TransitionCondition ;
126
133
import cbit .vcell .mapping .RateRule ;
127
134
import cbit .vcell .mapping .ReactionContext ;
128
135
import cbit .vcell .mapping .ReactionRuleSpec ;
129
136
import cbit .vcell .mapping .ReactionSpec ;
130
137
import cbit .vcell .mapping .SimulationContext ;
131
138
import cbit .vcell .mapping .SimulationContext .Application ;
132
139
import cbit .vcell .mapping .SimulationContext .SimulationContextParameter ;
140
+ import cbit .vcell .mapping .SiteAttributesSpec ;
133
141
import cbit .vcell .mapping .SpeciesContextSpec ;
134
142
import cbit .vcell .mapping .StructureMapping ;
135
143
import cbit .vcell .mapping .TotalCurrentClampStimulus ;
@@ -1483,7 +1491,7 @@ private Element getXML(ReactionContext param) {
1483
1491
//Add SpeciesContextSpecs
1484
1492
SpeciesContextSpec [] array = param .getSpeciesContextSpecs ();
1485
1493
for (int i =0 ; i <array .length ; i ++){
1486
- reactioncontext .addContent ( getXML (array [i ]) );
1494
+ reactioncontext .addContent ( getXML (array [i ], param . getSimulationContext () ) );
1487
1495
}
1488
1496
//Add ReactionSpecs
1489
1497
ReactionSpec [] reactionarray = param .getReactionSpecs ();
@@ -1492,8 +1500,8 @@ private Element getXML(ReactionContext param) {
1492
1500
}
1493
1501
//Add ReactionRuleSpecs
1494
1502
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 () ) );
1497
1505
}
1498
1506
1499
1507
return reactioncontext ;
@@ -1517,13 +1525,28 @@ private Element getXML(ReactionSpec param) {
1517
1525
}
1518
1526
1519
1527
//For rateRules in SimulationContext
1520
- public Element getXML (ReactionRuleSpec [] reactionRuleSpecs ) {
1528
+ public Element getXML (ReactionRuleSpec [] reactionRuleSpecs , SimulationContext simContext ) {
1521
1529
Element reactionRuleSpecsElement = new Element (XMLTags .ReactionRuleSpecsTag );
1522
1530
for (ReactionRuleSpec reactionRuleSpec : reactionRuleSpecs ){
1523
1531
Element reactionRuleSpecElement = new Element (XMLTags .ReactionRuleSpecTag );
1524
1532
reactionRuleSpecElement .setAttribute (XMLTags .ReactionRuleRefAttrTag , mangle (reactionRuleSpec .getReactionRule ().getName ()));
1525
1533
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
+ }
1527
1550
reactionRuleSpecsElement .addContent (reactionRuleSpecElement );
1528
1551
}
1529
1552
@@ -1544,19 +1567,24 @@ public Element getXML(SimulationContext param, BioModel bioModel) throws XmlPars
1544
1567
String name = mangle (param .getName ());
1545
1568
simulationcontext .setAttribute (XMLTags .NameAttrTag , name );
1546
1569
//set isStoch, isUsingConcentration attributes
1547
- if (applicationType == Application .NETWORK_STOCHASTIC )
1548
- {
1570
+ if (applicationType == Application .NETWORK_STOCHASTIC ) {
1549
1571
simulationcontext .setAttribute (XMLTags .StochAttrTag , "true" );
1550
1572
setBooleanAttribute (simulationcontext , XMLTags .ConcentrationAttrTag , param .isUsingConcentration ());
1551
1573
// write out 'randomizeInitConditin' flag only if non-spatial stochastic simContext
1552
1574
if (param .getGeometry ().getDimension () == 0 ) {
1553
1575
setBooleanAttribute (simulationcontext , XMLTags .RandomizeInitConditionTag ,param .isRandomizeInitCondition ());
1554
1576
}
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 {
1558
1585
simulationcontext .setAttribute (XMLTags .StochAttrTag , "false" );
1559
1586
simulationcontext .setAttribute (XMLTags .ConcentrationAttrTag , "true" );
1587
+ setBooleanAttribute (simulationcontext , XMLTags .SpringSaLaDAttrTag , false );
1560
1588
}
1561
1589
final boolean ruleBased = param .getApplicationType () == SimulationContext .Application .RULE_BASED_STOCHASTIC ;
1562
1590
setBooleanAttribute (simulationcontext ,XMLTags .RuleBasedAttrTag , ruleBased );
@@ -1567,8 +1595,6 @@ public Element getXML(SimulationContext param, BioModel bioModel) throws XmlPars
1567
1595
setBooleanAttribute (simulationcontext , XMLTags .RandomizeInitConditionTag ,param .isRandomizeInitCondition ());
1568
1596
}
1569
1597
}
1570
- final boolean springSaLaD = param .getApplicationType () == SimulationContext .Application .SPRINGSALAD ;
1571
- setBooleanAttribute (simulationcontext , XMLTags .SpringSaLaDAttrTag , springSaLaD );
1572
1598
1573
1599
setBooleanAttribute (simulationcontext ,XMLTags .MassConservationModelReductionTag , param .isUsingMassConservationModelReduction ());
1574
1600
setBooleanAttribute (simulationcontext ,XMLTags .InsufficientIterationsTag ,param .isInsufficientIterations ());
@@ -1829,24 +1855,21 @@ private Element getXML(FieldDataSymbol fds, ModelUnitSystem modelUnitSystem) {
1829
1855
<LocalizedCompoundSpec LocalizedCompoundRef="MT0" ForceConstant="false" WellMixed="false" ForceContinuous="false">
1830
1856
<InitialConcentration>0.0</InitialConcentration>
1831
1857
<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
+
1843
1866
</LocalizedCompoundSpec>
1844
1867
<ReactionRuleSpecs>
1845
1868
<ReactionRuleSpec ReactionRuleRef="r0" ReactionRuleMapping="included" BondLength="1.0" />
1846
1869
</ReactionRuleSpecs>
1847
1870
</ReactionContext>
1848
1871
*/
1849
- private Element getXML (SpeciesContextSpec param ) {
1872
+ private Element getXML (SpeciesContextSpec param , SimulationContext simContext ) {
1850
1873
Element speciesContextSpecElement = new Element (XMLTags .SpeciesContextSpecTag );
1851
1874
1852
1875
//Add Attributes
@@ -1877,11 +1900,64 @@ else if(initAmt != null)
1877
1900
}
1878
1901
//Add diffusion
1879
1902
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
+ }
1884
1956
}
1957
+ XMLOutputter outp = new XMLOutputter (Format .getPrettyFormat ());
1958
+ String sout = outp .outputString (speciesContextSpecElement );
1959
+ System .out .println (sout );
1960
+
1885
1961
// write BoundaryConditions
1886
1962
cbit .vcell .parser .Expression exp ;
1887
1963
Element boundaries = new Element (XMLTags .BoundariesTag );
0 commit comments