use of cbit.vcell.math.ParticleProperties 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.ParticleProperties in project vcell by virtualcell.
the class SmoldynFileWriter method writeMolecules.
private void writeMolecules() throws ExpressionException, MathException {
// write molecules
StringBuilder sb = new StringBuilder();
int max_mol = 0;
Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
while (subDomainEnumeration.hasMoreElements()) {
SubDomain subDomain = subDomainEnumeration.nextElement();
for (ParticleProperties particleProperties : subDomain.getParticleProperties()) {
ArrayList<ParticleInitialCondition> particleInitialConditions = particleProperties.getParticleInitialConditions();
String variableName = getVariableName(particleProperties.getVariable(), subDomain);
for (ParticleInitialCondition pic : particleInitialConditions) {
if (pic instanceof ParticleInitialConditionCount) {
max_mol += writeInitialCount((ParticleInitialConditionCount) pic, subDomain, variableName, sb);
} else if (pic instanceof ParticleInitialConditionConcentration) {
max_mol += writeInitialConcentration((ParticleInitialConditionConcentration) pic, subDomain, particleProperties.getVariable(), variableName, sb);
}
}
if (lg.isDebugEnabled()) {
lg.debug("subdomain " + subDomain.getName() + ' ' + variableName + " processed, maximum mol estimate now " + max_mol);
}
}
}
if (max_mol > MAX_MOLECULE_LIMIT) {
throw new MathException(VCellErrorMessages.getSmoldynMaxMolReachedErrorMessage((long) max_mol, MAX_MOLECULE_LIMIT));
}
int max_adjusted = max_mol * MOLECULE_MAX_COEFFICIENT;
if (max_adjusted < MIN_MOLECULE_LIMIT) {
if (lg.isInfoEnabled()) {
lg.info("adjusting computed max " + max_adjusted + " to minimum " + MIN_MOLECULE_LIMIT);
}
max_adjusted = MIN_MOLECULE_LIMIT;
}
if (max_adjusted > MAX_MOLECULE_LIMIT) {
if (lg.isInfoEnabled()) {
lg.info("adjusting computed max " + max_adjusted + " to maximum " + MAX_MOLECULE_LIMIT);
}
max_adjusted = MAX_MOLECULE_LIMIT;
}
printWriter.println("# molecules");
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.max_mol + " " + max_adjusted);
printWriter.println(sb);
}
use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.
the class SmoldynFileWriter method writeDrifts.
private void writeDrifts() throws ExpressionBindingException, ExpressionException, MathException {
// writer diffusion properties
printWriter.println("# drift properties");
Enumeration<SubDomain> subDomainEnumeration = mathDesc.getSubDomains();
while (subDomainEnumeration.hasMoreElements()) {
SubDomain subDomain = subDomainEnumeration.nextElement();
List<ParticleProperties> particlePropertiesList = subDomain.getParticleProperties();
for (ParticleProperties pp : particlePropertiesList) {
String variableName = null;
if (subDomain instanceof MembraneSubDomain) {
variableName = getVariableName(pp.getVariable(), subDomain);
} else {
variableName = getVariableName(pp.getVariable(), null);
}
try {
double driftX = 0.0;
if (pp.getDriftX() != null) {
driftX = subsituteFlattenToConstant(pp.getDriftX());
}
double driftY = 0.0;
if (pp.getDriftY() != null) {
driftY = subsituteFlattenToConstant(pp.getDriftY());
}
double driftZ = 0.0;
if (pp.getDriftZ() != null) {
driftZ = subsituteFlattenToConstant(pp.getDriftZ());
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.drift + " " + variableName + " " + driftX + " " + driftY + " " + driftZ);
} catch (NotAConstantException ex) {
throw new ExpressionException("diffusion coefficient for variable " + variableName + " is not a constant. Constants are required for all diffusion coefficients");
}
}
}
printWriter.println();
}
use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method returns a XML representation of a CompartmentSubDomain object.
* Creation date: (3/2/2001 1:18:55 PM)
* @return Element
* @param param cbit.vcell.math.CompartmentSubDomain
*/
private Element getXML(CompartmentSubDomain param) throws XmlParseException {
Element compartment = new Element(XMLTags.CompartmentSubDomainTag);
compartment.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
// Add boundaryType subelements
Element boundary;
// Xm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXm().boundaryTypeStringValue());
compartment.addContent(boundary);
// Xp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXp().boundaryTypeStringValue());
compartment.addContent(boundary);
// Ym
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYm().boundaryTypeStringValue());
compartment.addContent(boundary);
// Yp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYp().boundaryTypeStringValue());
compartment.addContent(boundary);
// Zm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZm().boundaryTypeStringValue());
compartment.addContent(boundary);
// Zp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZp().boundaryTypeStringValue());
compartment.addContent(boundary);
// add BoundaryConditionSpecs
for (BoundaryConditionSpec bcs : param.getBoundaryconditionSpecs()) {
compartment.addContent(getXML(bcs));
}
// Add Equations
Enumeration<Equation> enum1 = param.getEquations();
while (enum1.hasMoreElements()) {
Equation equ = enum1.nextElement();
compartment.addContent(getXML(equ));
}
// Add FastSystem
if (param.getFastSystem() != null) {
compartment.addContent(getXML(param.getFastSystem()));
}
// Add Variable Initial Condition
for (VarIniCondition varIni : param.getVarIniConditions()) {
compartment.addContent(getXML(varIni));
}
// Add JumpProcesses
for (JumpProcess jp : param.getJumpProcesses()) {
compartment.addContent(getXML(jp));
}
for (ParticleJumpProcess pjp : param.getParticleJumpProcesses()) {
compartment.addContent(getXML(pjp));
}
for (ParticleProperties pp : param.getParticleProperties()) {
compartment.addContent(getXML(pp));
}
return compartment;
}
use of cbit.vcell.math.ParticleProperties in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method returns a XML representation of a MembraneSubDomain object.
* Creation date: (3/2/2001 5:40:17 PM)
* @return Element
* @param param cbit.vcell.math.MembraneSubDomain
*/
private Element getXML(MembraneSubDomain param) throws XmlParseException {
Element membrane = new Element(XMLTags.MembraneSubDomainTag);
// Add attributes
membrane.setAttribute(XMLTags.NameAttrTag, mangle(param.getName()));
membrane.setAttribute(XMLTags.InsideCompartmentTag, mangle(param.getInsideCompartment().getName()));
membrane.setAttribute(XMLTags.OutsideCompartmentTag, mangle(param.getOutsideCompartment().getName()));
// Add boundaryType subelements
Element boundary;
// Xm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXm().boundaryTypeStringValue());
membrane.addContent(boundary);
// Xp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueXp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionXp().boundaryTypeStringValue());
membrane.addContent(boundary);
// Ym
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYm().boundaryTypeStringValue());
membrane.addContent(boundary);
// Yp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueYp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionYp().boundaryTypeStringValue());
membrane.addContent(boundary);
// Zm
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZm);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZm().boundaryTypeStringValue());
membrane.addContent(boundary);
// Zp
boundary = new Element(XMLTags.BoundaryTypeTag);
boundary.setAttribute(XMLTags.BoundaryAttrTag, XMLTags.BoundaryAttrValueZp);
boundary.setAttribute(XMLTags.BoundaryTypeAttrTag, param.getBoundaryConditionZp().boundaryTypeStringValue());
membrane.addContent(boundary);
// Add Equation subelements
Enumeration<Equation> enum1 = param.getEquations();
while (enum1.hasMoreElements()) {
Equation equ = enum1.nextElement();
membrane.addContent(getXML(equ));
}
// Add JumConditions
Enumeration<JumpCondition> enum2 = param.getJumpConditions();
while (enum2.hasMoreElements()) {
JumpCondition jc = (JumpCondition) enum2.nextElement();
membrane.addContent(getXML(jc));
}
// Add FastSystem (if there is)
if (param.getFastSystem() != null) {
membrane.addContent(getXML(param.getFastSystem()));
}
for (ParticleProperties pp : param.getParticleProperties()) {
membrane.addContent(getXML(pp));
}
for (ParticleJumpProcess pjp : param.getParticleJumpProcesses()) {
membrane.addContent(getXML(pjp));
}
Mutable<Element> velocity = new MutableObject<>();
addVelocityMaybe(velocity, XMLTags.XAttrTag, param.getVelocityX());
addVelocityMaybe(velocity, XMLTags.YAttrTag, param.getVelocityY());
if (velocity.getValue() != null) {
membrane.addContent(velocity.getValue());
}
return membrane;
}
Aggregations