Skip to content

Commit

Permalink
Merge branch 'dan-ss-xmlproducer'
Browse files Browse the repository at this point in the history
  • Loading branch information
danv61 committed Sep 13, 2023
2 parents 029bfb7 + 5f3a9e1 commit 0efa9a3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 39 deletions.
24 changes: 14 additions & 10 deletions vcell-core/src/main/java/cbit/vcell/xml/XMLTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -855,18 +855,22 @@ 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 BondLengthAttrTag = "BondLength";
public final static String SiteLocationRefAttrTag = "SiteLocationRef";
public final static String SiteRadiusAttrTag = "SiteRadius";
public final static String SiteDiffusionAttrTag = "SiteDiffusion";
public final static String SiteColorAttrTag = "SiteColor";
public final static String SiteCoordXAttrTag = "SiteCoordX";
public final static String SiteCoordYAttrTag = "SiteCoordY";
public final static String SiteCoordZAttrTag = "SiteCoordZ";

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";



}
132 changes: 104 additions & 28 deletions vcell-core/src/main/java/cbit/vcell/xml/Xmlproducer.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
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;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;

import org.apache.commons.lang3.mutable.Mutable;
Expand All @@ -31,6 +34,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;
Expand Down Expand Up @@ -121,15 +126,18 @@
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.ReactionRuleSpec.TransitionCondition;
import cbit.vcell.mapping.RateRule;
import cbit.vcell.mapping.ReactionContext;
import cbit.vcell.mapping.ReactionRuleSpec;
import cbit.vcell.mapping.ReactionSpec;
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;
Expand Down Expand Up @@ -1483,7 +1491,7 @@ private Element getXML(ReactionContext param) {
//Add SpeciesContextSpecs
SpeciesContextSpec[] array = param.getSpeciesContextSpecs();
for (int i =0; i<array.length ; i ++){
reactioncontext.addContent( getXML(array[i]) );
reactioncontext.addContent( getXML(array[i], param.getSimulationContext()) );
}
//Add ReactionSpecs
ReactionSpec[] reactionarray = param.getReactionSpecs();
Expand All @@ -1492,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;
Expand All @@ -1517,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<String, Object> 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);
}

Expand All @@ -1544,19 +1567,24 @@ public Element getXML(SimulationContext param, BioModel bioModel) throws XmlPars
String name = mangle(param.getName());
simulationcontext.setAttribute(XMLTags.NameAttrTag, name);
//set isStoch, isUsingConcentration attributes
if (applicationType == Application.NETWORK_STOCHASTIC)
{
if (applicationType == Application.NETWORK_STOCHASTIC) {
simulationcontext.setAttribute(XMLTags.StochAttrTag, "true");
setBooleanAttribute(simulationcontext, XMLTags.ConcentrationAttrTag, param.isUsingConcentration());
// write out 'randomizeInitConditin' flag only if non-spatial stochastic simContext
if(param.getGeometry().getDimension() == 0) {
setBooleanAttribute(simulationcontext, XMLTags.RandomizeInitConditionTag,param.isRandomizeInitCondition());
}
}
else
{
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, false);
} else if(applicationType == Application.SPRINGSALAD) {
boolean isRandomizeInitCondition = param.isRandomizeInitCondition();
boolean isUsingConcentration = param.isUsingConcentration();
simulationcontext.setAttribute(XMLTags.StochAttrTag, "false");
setBooleanAttribute(simulationcontext, XMLTags.ConcentrationAttrTag, isUsingConcentration);
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, true);
} else {
simulationcontext.setAttribute(XMLTags.StochAttrTag, "false");
simulationcontext.setAttribute(XMLTags.ConcentrationAttrTag, "true");
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, false);
}
final boolean ruleBased = param.getApplicationType() == SimulationContext.Application.RULE_BASED_STOCHASTIC;
setBooleanAttribute(simulationcontext,XMLTags.RuleBasedAttrTag, ruleBased);
Expand All @@ -1567,8 +1595,6 @@ public Element getXML(SimulationContext param, BioModel bioModel) throws XmlPars
setBooleanAttribute(simulationcontext, XMLTags.RandomizeInitConditionTag,param.isRandomizeInitCondition());
}
}
final boolean springSaLaD = param.getApplicationType() == SimulationContext.Application.SPRINGSALAD;
setBooleanAttribute(simulationcontext, XMLTags.SpringSaLaDAttrTag, springSaLaD);

setBooleanAttribute(simulationcontext,XMLTags.MassConservationModelReductionTag, param.isUsingMassConservationModelReduction());
setBooleanAttribute(simulationcontext,XMLTags.InsufficientIterationsTag,param.isInsufficientIterations());
Expand Down Expand Up @@ -1829,24 +1855,21 @@ private Element getXML(FieldDataSymbol fds, ModelUnitSystem modelUnitSystem) {
<LocalizedCompoundSpec LocalizedCompoundRef="MT0" ForceConstant="false" WellMixed="false" ForceContinuous="false">
<InitialConcentration>0.0</InitialConcentration>
<Diffusion>10.0</Diffusion>
<SiteAttributesMap>
<SiteAttributesSpec SiteRef="Site0" MoleculeRef="MT0" LocationRef="Intracellular" InitialStateRef="state0" Radius="1.0" Diffusion="1.0" Color="RED">
<Location X="2.0" Y="1.0" Z="1.0" />
</SiteAttributesSpec>
<SiteAttributesSpec SiteRef="Anchor" MoleculeRef="MT0" LocationRef="Membrane" InitialStateRef="anchor" Radius="1.0" Diffusion="1.0" Color="RED">
<Location X="1.0" Y="1.0" Z="1.0" />
</SiteAttributesSpec>
</SiteAttributesMap>
<InternalLinkSet>
<InternalLinkSpec MoleculeRef="MT0" SiteOneRef="Anchor" SiteTwoRef="Site0" />
<InternalLinkSet>
<SiteAttributesSpec SiteRef="Site0" MoleculeRef="MT0" SiteLocationRefAttrTag="Intracellular" Radius="1.0" Diffusion="1.0" Color="RED"
SiteCoordX="1.0" SiteCoordZ="1.0" SiteCoordZ="1.0" />
<SiteAttributesSpec SiteRef="Anchor" MoleculeRef="MT0" SiteLocationRefAttrTag="Membrane" Radius="1.0" Diffusion="1.0" Color="RED"
SiteCoordX="1.0" SiteCoordZ="1.0" SiteCoordZ="1.0" />
<InternalLinkSpec MoleculeRef="MT0" SiteOneRef="Anchor" SiteTwoRef="Site0" />
</LocalizedCompoundSpec>
<ReactionRuleSpecs>
<ReactionRuleSpec ReactionRuleRef="r0" ReactionRuleMapping="included" BondLength="1.0" />
</ReactionRuleSpecs>
</ReactionContext>
*/
private Element getXML(SpeciesContextSpec param) {
private Element getXML(SpeciesContextSpec param, SimulationContext simContext) {
Element speciesContextSpecElement = new Element(XMLTags.SpeciesContextSpecTag);

//Add Attributes
Expand Down Expand Up @@ -1877,11 +1900,64 @@ 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(Application.SPRINGSALAD == simContext.getApplicationType() && 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(Application.SPRINGSALAD == simContext.getApplicationType() && param.getSiteAttributesMap() != null && param.getSiteAttributesMap().size() > 0) {
for (Entry<MolecularComponentPattern, SiteAttributesSpec> 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());
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;
Element boundaries = new Element(XMLTags.BoundariesTag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 0efa9a3

Please sign in to comment.