use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class Kinetics method convertParameterType.
/**
* convertParameterType : Used to convert a parameter from model (global) to local or vice versa depending on 'bConvertToLocal'
* @param param : the parameter to be converted (could be kinetic parameter or kineticProxyParameter)
* @param bConvertToGlobal : <true> => convert model to local parameter; <false> => convert local to model parameter
*/
public void convertParameterType(Parameter param, boolean bConvertToGlobal) throws PropertyVetoException, ExpressionBindingException {
Expression expression = param.getExpression();
if (!bConvertToGlobal) {
// need to convert model parameter (the proxyparam/global) to local (kinetics) parameter
if (!(param instanceof KineticsProxyParameter)) {
throw new RuntimeException("Parameter : \'" + param.getName() + "\' is not a proxy (global) parameter, cannot convert it to a local kinetics parameter.");
} else {
// first remove proxy param,
removeProxyParameter((KineticsProxyParameter) param);
// then add it as kinetic param
if (expression != null) {
Expression newExpr = new Expression(expression);
newExpr.bindExpression(getReactionStep());
addKineticsParameter(new KineticsParameter(param.getName(), newExpr, Kinetics.ROLE_UserDefined, param.getUnitDefinition()));
}
}
} else {
// need to convert local (the kinetics parameter) to model (proxy) parameter
if (!(param instanceof KineticsParameter)) {
throw new RuntimeException("Parameter : \'" + param.getName() + "\' is not a local kinetics parameter, cannot convert it to a global (proxy) parameter.");
} else {
// else remove kinetic param - should have already been checked in parameterTableModel
if (((KineticsParameter) param).getRole() != Kinetics.ROLE_UserDefined) {
throw new RuntimeException("Cannot convert pre-defined kinetic parameter : \'" + param.getName() + "\' to global parameter.");
}
// First add param as a model parameter, if it is not already present
ModelParameter mp = getReactionStep().getModel().getModelParameter(param.getName());
if (mp == null) {
Model model = getReactionStep().getModel();
Expression newExpr = new Expression(expression);
newExpr.bindExpression(model);
model.addModelParameter(model.new ModelParameter(param.getName(), newExpr, Model.ROLE_UserDefined, param.getUnitDefinition()));
}
// Then remove param as a kinetic param (if 'param' is a model param, it is automatically added as a (proxy/global) param,
// since it is present in the reaction rate equn.
removeKineticsParameter((KineticsParameter) param);
}
}
}
use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class ModelOptimizationSpec method getModelParameters.
/**
* Insert the method's description here.
* Creation date: (8/22/2005 10:38:04 AM)
* @return cbit.vcell.model.Parameter[]
*/
private Parameter[] getModelParameters() {
java.util.Vector<Parameter> modelParameterList = new java.util.Vector<Parameter>();
Model model = getSimulationContext().getModel();
//
// get Model (global) parameters
//
ModelParameter[] globalParams = model.getModelParameters();
for (int i = 0; i < globalParams.length; i++) {
if (globalParams[i] != null && globalParams[i].getExpression() != null && globalParams[i].getExpression().isNumeric()) {
modelParameterList.add(globalParams[i]);
}
}
//
// get kinetic parameters that are numbers
//
ReactionStep[] reactionSteps = model.getReactionSteps();
for (int i = 0; i < reactionSteps.length; i++) {
//
// make sure ReactionSteps are "enabled"
//
ReactionSpec reactionSpec = getSimulationContext().getReactionContext().getReactionSpec(reactionSteps[i]);
if (reactionSpec == null || reactionSpec.isExcluded()) {
continue;
}
Kinetics.KineticsParameter[] kineticsParameters = reactionSteps[i].getKinetics().getKineticsParameters();
for (int j = 0; j < kineticsParameters.length; j++) {
if (kineticsParameters[j].getExpression() != null && kineticsParameters[j].getExpression().isNumeric()) {
if (((kineticsParameters[j].getRole() == Kinetics.ROLE_CurrentDensity) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedCurrent)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_MOLECULAR_ONLY) {
continue;
}
if (((kineticsParameters[j].getRole() == Kinetics.ROLE_ReactionRate) || (kineticsParameters[j].getRole() == Kinetics.ROLE_LumpedReactionRate)) && reactionSteps[i].getPhysicsOptions() == ReactionStep.PHYSICS_ELECTRICAL_ONLY) {
continue;
}
modelParameterList.add(kineticsParameters[j]);
}
}
}
//
// get initial conditions that are numbers
//
SpeciesContextSpec[] speciesContextSpecs = getSimulationContext().getReactionContext().getSpeciesContextSpecs();
for (int i = 0; i < speciesContextSpecs.length; i++) {
SpeciesContextSpec.SpeciesContextSpecParameter initParam = speciesContextSpecs[i].getInitialConditionParameter();
if (initParam != null && initParam.getExpression() != null && initParam.getExpression().isNumeric()) {
modelParameterList.add(initParam);
}
}
//
// get structure parameters
//
StructureMapping[] structureMappings = getSimulationContext().getGeometryContext().getStructureMappings();
for (int i = 0; i < structureMappings.length; i++) {
StructureMapping.StructureMappingParameter[] parameters = structureMappings[i].getParameters();
for (int j = 0; j < parameters.length; j++) {
if (parameters[j].getRole() == StructureMapping.ROLE_SpecificCapacitance && structureMappings[i] instanceof MembraneMapping && !((MembraneMapping) structureMappings[i]).getCalculateVoltage()) {
continue;
}
if (parameters[j].getExpression() != null && parameters[j].getExpression().isNumeric()) {
modelParameterList.add(parameters[j]);
}
}
}
Parameter[] modelParameters = (Parameter[]) BeanUtils.getArray(modelParameterList, Parameter.class);
return modelParameters;
}
use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class SBMLExporter method addParameters.
/**
* addKineticParameterUnits:
* @throws SbmlException
*/
// private void addKineticAndGlobalParameterUnits() throws SbmlException {
//
// //
// // Get all kinetic parameters from simple reactions and flux reactions from the Biomodel
// // And all Model (global) parameters from Model.
// // For each parameter,
// // get its unit (VCunitDefinition)
// // check if it is part of unitsList - if so, continue
// // check if it is a base unit - if so, continue
// // else, get the converted unit (VC -> SBML)
// // add unit to sbmlModel unit definition
// //
//
// Vector<Parameter> paramsVector = new Vector<Parameter>();
// // Add globals
// Model vcModel = vcBioModel.getModel();
// ModelParameter[] globalParams = vcModel.getModelParameters();
// for (int i = 0; i < globalParams.length; i++) {
// paramsVector.addElement(globalParams[i]);
// }
// // Add reaction kinetic parameters
// ReactionStep[] vcReactions = vcModel.getReactionSteps();
// for (int i = 0; i < vcReactions.length; i++) {
// Kinetics rxnKinetics = vcReactions[i].getKinetics();
// Parameter[] kineticParams = rxnKinetics.getKineticsParameters();
// for (int j = 0; j < kineticParams.length; j++) {
// paramsVector.addElement(kineticParams[j]);
// }
// }
//
// for (int i = 0; i < paramsVector.size(); i++){
// Parameter param = (Parameter)paramsVector.elementAt(i);
// VCUnitDefinition paramUnitDefn = param.getUnitDefinition();
// if (paramUnitDefn == null || paramUnitDefn.isTBD()) {
// continue;
// }
// String unitSymbol = org.vcell.util.TokenMangler.mangleToSName(paramUnitDefn.getSymbol());
// if (unitSymbol == null) {
// continue;
// }
// getOrCreateSBMLUnit(paramUnitDefn);
// }
// }
/**
* At present, the Virtual cell doesn't support global parameters
* @throws SbmlException
*/
protected void addParameters() throws ExpressionException, SbmlException {
Model vcModel = getSelectedSimContext().getModel();
// add VCell global parameters to the SBML listofParameters
ModelParameter[] vcGlobalParams = vcModel.getModelParameters();
if (vcGlobalParams != null) {
for (ModelParameter vcParam : vcGlobalParams) {
org.sbml.jsbml.Parameter sbmlParam = sbmlModel.createParameter();
sbmlParam.setId(vcParam.getName());
sbmlParam.setConstant(vcParam.isConstant());
Expression paramExpr = new Expression(vcParam.getExpression());
boolean bParamIsNumeric = true;
if (paramExpr.isNumeric()) {
// For a VCell global param, if it is numeric, it has a constant value and is not defined by a rule, hence set Constant = true.
sbmlParam.setValue(paramExpr.evaluateConstant());
// the expression for modelParam might be numeric, but modelParam could have a rate rule, if so, set constant attribute to 'false'
if (getSelectedSimContext().getRateRule(vcParam) != null) {
bParamIsNumeric = false;
}
} else {
// non-numeric VCell global parameter will be defined by a (assignment) rule, hence mark Constant = false.
bParamIsNumeric = false;
// add assignment rule for param
ASTNode paramFormulaNode = getFormulaFromExpression(paramExpr);
AssignmentRule sbmlParamAssignmentRule = sbmlModel.createAssignmentRule();
sbmlParamAssignmentRule.setVariable(vcParam.getName());
sbmlParamAssignmentRule.setMath(paramFormulaNode);
}
sbmlParam.setConstant(bParamIsNumeric);
VCUnitDefinition vcParamUnit = vcParam.getUnitDefinition();
if (!vcParamUnit.isTBD()) {
sbmlParam.setUnits(getOrCreateSBMLUnit(vcParamUnit));
}
}
}
}
use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class SBMLImporter method addInitialAssignments.
protected void addInitialAssignments() {
if (sbmlModel == null) {
throw new SBMLImportException("SBML model is NULL");
}
ListOf listofInitialAssgns = sbmlModel.getListOfInitialAssignments();
if (listofInitialAssgns == null) {
System.out.println("No Initial Assignments specified");
return;
}
Model vcModel = vcBioModel.getSimulationContext(0).getModel();
for (int i = 0; i < sbmlModel.getNumInitialAssignments(); i++) {
try {
InitialAssignment initAssgn = (InitialAssignment) listofInitialAssgns.get(i);
String initAssgnSymbol = initAssgn.getSymbol();
Expression initAssignMathExpr = getExpressionFromFormula(initAssgn.getMath());
// support compartmentSize expressions, warn and bail out.
if (sbmlModel.getCompartment(initAssgnSymbol) != null) {
if (!initAssignMathExpr.isNumeric()) {
logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.CompartmentError, "compartment '" + initAssgnSymbol + "' size has an initial assignment, cannot handle it at this time.");
}
// if init assgn for compartment is numeric, the numeric
// value for size is set in addCompartments().
}
// or other species. Not allowed for species.
if (!bSpatial && sbmlModel.getSpecies(initAssgnSymbol) != null) {
if (initAssignMathExpr.hasSymbol(vcModel.getX().getName()) || initAssignMathExpr.hasSymbol(vcModel.getY().getName()) || initAssignMathExpr.hasSymbol(vcModel.getZ().getName())) {
logger.sendMessage(VCLogger.Priority.HighPriority, VCLogger.ErrorType.SpeciesError, "species '" + initAssgnSymbol + "' initial assignment expression cannot contain 'x', 'y', 'z'.");
}
}
initAssignMathExpr = adjustExpression(initAssignMathExpr, vcModel);
// set the init assgn expr on VCell species init condn or global
// parameter expression
SpeciesContextSpec scs = vcBioModel.getSimulationContext(0).getReactionContext().getSpeciesContextSpec(vcBioModel.getSimulationContext(0).getModel().getSpeciesContext(initAssgnSymbol));
ModelParameter mp = vcBioModel.getSimulationContext(0).getModel().getModelParameter(initAssgnSymbol);
if (scs != null) {
scs.getInitialConditionParameter().setExpression(initAssignMathExpr);
} else if (mp != null) {
mp.setExpression(initAssignMathExpr);
} else {
localIssueList.add(new Issue(new SBMLIssueSource(initAssgn), issueContext, IssueCategory.SBMLImport_UnsupportedAttributeOrElement, "Symbol '" + initAssgnSymbol + "' not a species or global parameter in VCell; initial assignment ignored.", Issue.SEVERITY_WARNING));
// logger.sendMessage(VCLogger.Priority.MediumPriority,
// VCLogger.ErrorType.UnsupportedConstruct,
// "Symbol '"+initAssgnSymbol+"' not a species or global parameter in VCell; initial assignment ignored..");
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new RuntimeException("Error reading InitialAssignment : " + e.getMessage());
}
}
}
use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class SEDMLExporter method getTargetAttributeXPath.
private XPathTarget getTargetAttributeXPath(SymbolTableEntry ste, Map<Pair<String, String>, String> l2gMap) {
// to get Xpath string for variables.
SBMLSupport sbmlSupport = new SBMLSupport();
XPathTarget targetXpath = null;
if (ste instanceof SpeciesContext || ste instanceof SpeciesContextSpecParameter) {
String speciesId = ste.getName();
// can change species initial concentration or amount
String speciesAttr = "";
if (ste instanceof SpeciesContextSpecParameter) {
SpeciesContextSpecParameter scsp = (SpeciesContextSpecParameter) ste;
speciesId = (scsp).getSpeciesContext().getName();
if (scsp.getRole() == SpeciesContextSpec.ROLE_InitialConcentration) {
speciesAttr = scsp.getName();
}
if (scsp.getRole() == SpeciesContextSpec.ROLE_InitialCount) {
speciesAttr = scsp.getName();
}
}
if (speciesAttr.length() < 1) {
targetXpath = new XPathTarget(sbmlSupport.getXPathForCompartment(speciesId));
} else if (speciesAttr.equalsIgnoreCase("initialConcentration") || speciesAttr.equalsIgnoreCase("initConc")) {
targetXpath = new XPathTarget(sbmlSupport.getXPathForSpecies(speciesId, SpeciesAttribute.initialConcentration));
} else if (speciesAttr.equalsIgnoreCase("initialCount")) {
targetXpath = new XPathTarget(sbmlSupport.getXPathForSpecies(speciesId, SpeciesAttribute.initialAmount));
} else {
throw new RuntimeException("Unknown species attribute '" + speciesAttr + "'; cannot get xpath target for species '" + speciesId + "'.");
}
targetXpath = new XPathTarget(sbmlSupport.getXPathForSpecies(speciesId));
} else if (ste instanceof ModelParameter) {
// can only change parameter value.
targetXpath = new XPathTarget(sbmlSupport.getXPathForGlobalParameter(ste.getName(), ParameterAttribute.value));
} else if (ste instanceof Structure || ste instanceof Structure.StructureSize || (ste instanceof StructureMappingParameter && ((StructureMappingParameter) ste).getRole() == StructureMapping.ROLE_Size)) {
String compartmentId = ste.getName();
// can change compartment size or spatial dimension, but in vcell, we cannot change compartment dimension.
String compartmentAttr = "";
if (ste instanceof Structure.StructureSize) {
compartmentId = ((StructureSize) ste).getStructure().getName();
compartmentAttr = ((StructureSize) ste).getName();
}
if (ste instanceof StructureMappingParameter) {
StructureMappingParameter smp = (StructureMappingParameter) ste;
compartmentId = smp.getStructure().getName();
if (smp.getRole() == StructureMapping.ROLE_Size) {
compartmentAttr = smp.getName();
}
}
if (compartmentAttr.length() < 1) {
targetXpath = new XPathTarget(sbmlSupport.getXPathForCompartment(compartmentId));
} else if (compartmentAttr.equalsIgnoreCase("size")) {
targetXpath = new XPathTarget(sbmlSupport.getXPathForCompartment(compartmentId, CompartmentAttribute.size));
} else {
throw new RuntimeException("Unknown compartment attribute '" + compartmentAttr + "'; cannot get xpath target for compartment '" + compartmentId + "'.");
}
} else if (ste instanceof KineticsParameter) {
KineticsParameter kp = (KineticsParameter) ste;
String reactionID = kp.getKinetics().getReactionStep().getName();
String parameterID = kp.getName();
Pair<String, String> key = new Pair(reactionID, parameterID);
String value = l2gMap.get(key);
if (value == null) {
// stays as local parameter
targetXpath = new XPathTarget(sbmlSupport.getXPathForKineticLawParameter(reactionID, parameterID, ParameterAttribute.value));
} else {
// became a global in SBML, we need to refer to that global
targetXpath = new XPathTarget(sbmlSupport.getXPathForGlobalParameter(value, ParameterAttribute.value));
}
} else {
System.err.println("Entity should be SpeciesContext, Structure, ModelParameter : " + ste.getClass());
throw new RuntimeException("Unknown entity in SBML model");
}
return targetXpath;
}
Aggregations