use of org.sbml.jsbml.Compartment in project vcell by virtualcell.
the class SBMLImporter method checkIdentifiersNameLength.
private void checkIdentifiersNameLength() throws Exception {
// Check compartment name lengths
ListOf listofIds = sbmlModel.getListOfCompartments();
boolean bLongCompartmentName = false;
SBase issueSource = null;
for (int i = 0; i < sbmlModel.getNumCompartments(); i++) {
Compartment compartment = (Compartment) listofIds.get(i);
String compartmentName = compartment.getId();
if (compartmentName.length() > 64) {
bLongCompartmentName = true;
issueSource = compartment;
}
}
// Check species name lengths
listofIds = sbmlModel.getListOfSpecies();
boolean bLongSpeciesName = false;
for (int i = 0; i < sbmlModel.getNumSpecies(); i++) {
org.sbml.jsbml.Species species = (org.sbml.jsbml.Species) listofIds.get(i);
String speciesName = species.getId();
if (speciesName.length() > 64) {
bLongSpeciesName = true;
issueSource = species;
}
}
// Check parameter name lengths
listofIds = sbmlModel.getListOfParameters();
boolean bLongParameterName = false;
for (int i = 0; i < sbmlModel.getNumParameters(); i++) {
Parameter param = (Parameter) listofIds.get(i);
String paramName = param.getId();
if (paramName.length() > 64) {
bLongParameterName = true;
issueSource = param;
}
}
// Check reaction name lengths
listofIds = sbmlModel.getListOfReactions();
boolean bLongReactionName = false;
for (int i = 0; i < sbmlModel.getNumReactions(); i++) {
Reaction rxn = (Reaction) listofIds.get(i);
String rxnName = rxn.getId();
if (rxnName.length() > 64) {
bLongReactionName = true;
issueSource = rxn;
}
}
if (bLongCompartmentName || bLongSpeciesName || bLongParameterName || bLongReactionName) {
String warningMsg = "WARNING: The imported model has one or more ";
if (bLongCompartmentName) {
warningMsg = warningMsg + "compartments, ";
}
if (bLongSpeciesName) {
warningMsg = warningMsg + "species, ";
}
if (bLongParameterName) {
warningMsg = warningMsg + "global parameters, ";
}
if (bLongReactionName) {
warningMsg = warningMsg + "reactions ";
}
warningMsg = warningMsg + "that have ids/names that are longer than 64 characters. \n\nUser is STRONGLY recommeded to shorten " + "the names to avoid problems with the length of expressions these names might be used in.";
localIssueList.add(new Issue(new SBMLIssueSource(issueSource), issueContext, IssueCategory.SBMLImport_UnsupportedAttributeOrElement, warningMsg, Issue.SEVERITY_WARNING));
// logger.sendMessage(VCLogger.Priority.MediumPriority,
// VCLogger.ErrorType.UnsupportedConstruct, warningMsg);
}
}
use of org.sbml.jsbml.Compartment in project vcell by virtualcell.
the class SBMLImporter method setSpeciesInitialConditions.
/**
* setSpeciesInitialConditions : called after speciesContexts and global
* parameters have been set. Checks for init conditions set on species in
* the Sbml model, and if it is set using an assignment rule, obtain the
* corresponding expression. Obtain the sbml -> vc unit conversion factor
* for species concentrations to adjust the species initial condition
* units/factor.
*/
private void setSpeciesInitialConditions() {
try {
// fill in SpeciesContextSpec for each speciesContext
Model vcModel = vcBioModel.getSimulationContext(0).getModel();
SpeciesContext[] vcSpeciesContexts = vcModel.getSpeciesContexts();
for (int i = 0; i < vcSpeciesContexts.length; i++) {
org.sbml.jsbml.Species sbmlSpecies = (org.sbml.jsbml.Species) sbmlModel.getSpecies(vcSpeciesContexts[i].getName());
// Sometimes, the species name can be null or a blank string; in
// that case, use species id as the name.
String speciesName = sbmlSpecies.getId();
Compartment compartment = (Compartment) sbmlModel.getCompartment(sbmlSpecies.getCompartment());
Expression initExpr = null;
if (sbmlSpecies.isSetInitialConcentration()) {
// If initial
// Concentration
// is set
Expression initConcentration = new Expression(sbmlSpecies.getInitialConcentration());
// check if initConc is set by a (assignment) rule. That
// takes precedence over initConc value set on species.
initExpr = getValueFromAssignmentRule(speciesName);
if (initExpr == null) {
initExpr = new Expression(initConcentration);
}
} else if (sbmlSpecies.isSetInitialAmount()) {
// If initial
// amount is set
double initAmount = sbmlSpecies.getInitialAmount();
// initConcentration. Else, throw exception.
if (compartment.isSetSize()) {
double compartmentSize = compartment.getSize();
Expression initConcentration = new Expression(0.0);
if (compartmentSize != 0.0) {
initConcentration = new Expression(initAmount / compartmentSize);
} else {
logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.UnitError, "compartment '" + compartment.getId() + "' has zero size, unable to determine initial concentration for species " + speciesName);
}
// check if initConc is set by a (assignment) rule. That
// takes precedence over initConc/initAmt value set on
// species.
initExpr = getValueFromAssignmentRule(speciesName);
if (initExpr == null) {
initExpr = new Expression(initConcentration);
}
} else {
logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.SpeciesError, " Compartment '" + compartment.getId() + "' size not set or is defined by a rule; cannot calculate initConc.");
}
} else {
// initConc/initAmt not set; check if species has a
// (assignment) rule.
initExpr = getValueFromAssignmentRule(speciesName);
if (initExpr == null) {
// warning and set it to 0.0
if (sbmlModel.getInitialAssignment(speciesName) == null) {
localIssueList.add(new Issue(new SBMLIssueSource(sbmlModel.getSpecies(speciesName)), issueContext, IssueCategory.SBMLImport_MissingSpeciesInitCondition, "no initial condition for species " + speciesName + ", assuming 0.0", Issue.SEVERITY_WARNING));
// logger.sendMessage(VCLogger.Priority.MediumPriority,
// VCLogger.ErrorType.UnitError,
// "no initial condition for species "+speciesName+", assuming 0.0");
}
initExpr = new Expression(0.0);
}
}
// similar to the conversion that is done in reactions.
if (initExpr != null) {
// initExpr will be changed
initExpr = adjustExpression(initExpr, vcModel);
}
// If any of the symbols in the expression for speciesConc is a
// rule, expand it.
substituteGlobalParamRulesInPlace(initExpr, false);
SpeciesContextSpec speciesContextSpec = vcBioModel.getSimulationContext(0).getReactionContext().getSpeciesContextSpec(vcSpeciesContexts[i]);
speciesContextSpec.getInitialConditionParameter().setExpression(initExpr);
speciesContextSpec.setConstant(sbmlSpecies.getBoundaryCondition() || sbmlSpecies.getConstant());
}
} catch (Throwable e) {
e.printStackTrace(System.out);
throw new SBMLImportException("Error setting initial condition for species context; " + e.getMessage(), e);
}
}
Aggregations