use of cbit.vcell.math.ParticleSpeciesPattern in project vcell by virtualcell.
the class NFsimXMLWriter method getParticleSpeciesPatternList.
private static Element getParticleSpeciesPatternList(String prefix0, ParticleObservable particleObservable) {
Element listOfPatternsElement = new Element("ListOfPatterns");
for (int molecularPatternIndex = 0; molecularPatternIndex < particleObservable.getParticleSpeciesPatterns().size(); molecularPatternIndex++) {
ParticleSpeciesPattern pattern = particleObservable.getParticleSpeciesPatterns().get(molecularPatternIndex);
if (pattern instanceof VolumeParticleSpeciesPattern) {
Element patternElement;
try {
String molecularPatternID = "P" + (molecularPatternIndex + 1);
patternElement = getObservableParticipantPattern(prefix0, molecularPatternID, (VolumeParticleSpeciesPattern) pattern, "Pattern", particleObservable.getSequence(), particleObservable.getQuantity());
listOfPatternsElement.addContent(patternElement);
} catch (SolverException e) {
e.printStackTrace();
}
}
}
return listOfPatternsElement;
}
use of cbit.vcell.math.ParticleSpeciesPattern in project vcell by virtualcell.
the class NFsimXMLWriter method getListOfSpecies.
private static Element getListOfSpecies(MathDescription mathDesc, SimulationSymbolTable simulationSymbolTable) throws SolverException {
CompartmentSubDomain compartmentSubDomain = (CompartmentSubDomain) mathDesc.getSubDomains().nextElement();
//
// NFsim expects a list of seed species. These are concrete species patterns that have a "ParticleProperties" element defined (for initial conditions).
//
Element listOfSpeciesElement = new Element("ListOfSpecies");
for (int speciesIndex = 0; speciesIndex < compartmentSubDomain.getParticleProperties().size(); speciesIndex++) {
// seedSpecies.getSpeciesPattern().resolveBonds();
ParticleProperties particleProperties = compartmentSubDomain.getParticleProperties().get(speciesIndex);
Element speciesElement = new Element("Species");
String speciesID = "S" + (speciesIndex + 1);
ParticleSpeciesPattern seedSpecies = (ParticleSpeciesPattern) particleProperties.getVariable();
speciesElement.setAttribute("id", speciesID);
speciesElement.setAttribute("name", seedSpecies.getName());
List<ParticleInitialCondition> particleInitialConditions = particleProperties.getParticleInitialConditions();
if (particleInitialConditions.size() != 1) {
throw new SolverException("multiple particle initial conditions not expected for " + ParticleSpeciesPattern.class.getSimpleName() + " " + seedSpecies.getName());
}
// the initial conditions must be a count in math (ParticleInitialConditionCount)
if (!(particleInitialConditions.get(0) instanceof ParticleInitialConditionCount)) {
throw new SolverException("expecting initial count for " + ParticleSpeciesPattern.class.getSimpleName() + " " + seedSpecies.getName());
}
ParticleInitialConditionCount initialCount = (ParticleInitialConditionCount) particleInitialConditions.get(0);
try {
double value = evaluateConstant(initialCount.getCount(), simulationSymbolTable);
Integer maxMoleculesPerType = simulationSymbolTable.getSimulation().getSolverTaskDescription().getNFSimSimulationOptions().getMaxMoleculesPerType();
if (maxMoleculesPerType == null) {
maxMoleculesPerType = NFsimSimulationOptions.DefaultMaxMoleculesPerSpecies;
}
if (maxMoleculesPerType.doubleValue() < value) {
String eMessage = "The Initial count for Species '" + seedSpecies.getName() + "' is " + BigDecimal.valueOf(value).toBigInteger();
eMessage += ", which is higher than the limit of " + maxMoleculesPerType + ".\n";
eMessage += "Please do one of the following: \n- reduce the Initial Condition value for this Species or reduce the compartment size\n";
eMessage += "- increase the maximal number of Molecules per Molecular Type in the Advanced Solver Options panel.";
throw new RuntimeException(eMessage);
}
speciesElement.setAttribute("concentration", Double.toString(value));
} catch (ExpressionException | MathException e) {
e.printStackTrace();
throw new SolverException("error processing initial count of " + ParticleSpeciesPattern.class.getSimpleName() + " " + seedSpecies.getName() + ": " + e.getMessage());
}
HashMap<Bond, BondSites> bondSiteMapping = new HashMap<Bond, BondSites>();
Element listOfMoleculesElement = getListOfMolecules(speciesID, seedSpecies, bondSiteMapping);
speciesElement.addContent(listOfMoleculesElement);
if (bondSiteMapping.size() > 0) {
Element listOfBondsElement = getListOfBonds(bondSiteMapping);
speciesElement.addContent(listOfBondsElement);
}
listOfSpeciesElement.addContent(speciesElement);
}
return listOfSpeciesElement;
}
use of cbit.vcell.math.ParticleSpeciesPattern in project vcell by virtualcell.
the class XmlReader method getVolumeParticleObservable.
private VolumeParticleObservable getVolumeParticleObservable(Element param, VariableHash varHash) throws XmlParseException {
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
String domainStr = unMangle(param.getAttributeValue(XMLTags.DomainAttrTag));
Domain domain = null;
if (domainStr != null) {
domain = new Domain(domainStr);
}
String molecularTypeString = unMangle(param.getAttributeValue(XMLTags.ParticleMolecularTypePatternTag));
ObservableType observableType = ObservableType.fromString(molecularTypeString);
VolumeParticleObservable var = new VolumeParticleObservable(name, domain, observableType);
String sequenceAttr = param.getAttributeValue(XMLTags.ParticleObservableSequenceTypeAttrTag);
if (sequenceAttr != null) {
Sequence sequence = Sequence.fromString(sequenceAttr);
String sequenceLength = param.getAttributeValue(XMLTags.ParticleObservableSequenceLengthAttrTag);
var.setSequence(sequence);
if (sequence != Sequence.Multimolecular) {
var.setQuantity(Integer.parseInt(sequenceLength));
}
} else {
var.setSequence(Sequence.Multimolecular);
}
Element volumeParticleSpeciesPatternsElement = param.getChild(XMLTags.VolumeParticleSpeciesPatternsTag, vcNamespace);
List<Element> volumeParticleSpeciesPatternList = volumeParticleSpeciesPatternsElement.getChildren(XMLTags.VolumeParticleSpeciesPatternTag, vcNamespace);
for (Element volumeParticleSpeciesPattern : volumeParticleSpeciesPatternList) {
String volumeParticleSpeciesPatternName = unMangle(volumeParticleSpeciesPattern.getAttributeValue(XMLTags.NameAttrTag));
Variable v = varHash.getVariable(volumeParticleSpeciesPatternName);
if (v == null) {
throw new XmlParseException("failed to find VolumeParticleSpeciesPattern named " + volumeParticleSpeciesPatternName);
}
if (v instanceof ParticleSpeciesPattern) {
var.addParticleSpeciesPattern((ParticleSpeciesPattern) v);
} else {
throw new XmlParseException("Variable " + volumeParticleSpeciesPatternName + " is not a ParticleSpeciesPattern");
}
}
return var;
}
use of cbit.vcell.math.ParticleSpeciesPattern in project vcell by virtualcell.
the class RbmUtils method toBnglStringShort.
public static String toBnglStringShort(ParticleJumpProcess particleJumpProcess, List<ParticleSpeciesPattern> reactantSpeciesPatterns, List<ParticleSpeciesPattern> productSpeciesPatterns) {
StringBuilder buffer = new StringBuilder();
for (int i = 0; i < reactantSpeciesPatterns.size(); i++) {
ParticleSpeciesPattern reactantSpeciesPattern = reactantSpeciesPatterns.get(i);
if (i > 0) {
buffer.append(" + ");
}
buffer.append(toBnglString(reactantSpeciesPattern));
}
// particleJumpProcesses are not reversible
boolean bReversible = false;
buffer.append(bReversible ? " <-> " : " -> ");
for (int i = 0; i < productSpeciesPatterns.size(); i++) {
ParticleSpeciesPattern productSpeciesPattern = productSpeciesPatterns.get(i);
if (i > 0) {
buffer.append(" + ");
}
buffer.append(toBnglString(productSpeciesPattern));
}
return buffer.toString();
}
use of cbit.vcell.math.ParticleSpeciesPattern in project vcell by virtualcell.
the class Xmlproducer method getVolumeParticleSpeciesPatternList.
private Element getVolumeParticleSpeciesPatternList(ParticleObservable param) {
org.jdom.Element e = null;
e = new org.jdom.Element(XMLTags.VolumeParticleSpeciesPatternsTag);
for (ParticleSpeciesPattern pp : param.getParticleSpeciesPatterns()) {
org.jdom.Element e1 = new org.jdom.Element(XMLTags.VolumeParticleSpeciesPatternTag);
e1.setAttribute(XMLTags.NameAttrTag, mangle(pp.getName()));
e.addContent(e1);
}
return e;
}
Aggregations