use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class SBPAXParameterExtractor method extractParameter.
public static Map<SBOTerm, ModelParameter> extractParameter(ReactionStep reaction, SBMeasurable measurable) throws PropertyVetoException {
Map<SBOTerm, ModelParameter> sboToParameters = new HashMap<SBOTerm, ModelParameter>();
Set<SBOTerm> sboTerms = SBPAXSBOExtractor.extractSBOTerms(measurable);
String symbol = null;
VCUnitDefinition targetUnit = null;
Model model = reaction.getModel();
ModelUnitSystem modelUnitSystem = model.getUnitSystem();
Set<SBOTerm> termsWithUnituM = SetUtil.newSet(SBOList.sbo0000027MichaelisConstant, SBOList.sbo0000322MichaelisConstantForSubstrate);
for (SBOTerm sboTerm : sboTerms) {
if (termsWithUnituM.contains(sboTerm)) {
targetUnit = modelUnitSystem.getVolumeConcentrationUnit();
// targetUnit = VCUnitDefinition.UNIT_uM;
}
if (StringUtil.notEmpty(sboTerm.getSymbol())) {
symbol = sboTerm.getSymbol();
}
for (int i = 0; i < symbol.length(); ++i) {
char charAt = symbol.charAt(i);
if (!Character.isJavaIdentifierPart(charAt)) {
symbol = symbol.replace(charAt, '_');
}
}
}
VCUnitDefinition unit = UOMEUnitExtractor.extractVCUnitDefinition(measurable, modelUnitSystem);
double conversionFactor = 1.0;
if (targetUnit != null && unit != null && unit != modelUnitSystem.getInstance_TBD() && !targetUnit.equals(unit)) {
// if(unit.equals(VCUnitDefinition.UNIT_M) && targetUnit.equals(VCUnitDefinition.UNIT_uM)) {
if (unit.isCompatible(targetUnit)) {
conversionFactor = unit.convertTo(conversionFactor, targetUnit);
unit = targetUnit;
}
}
ArrayList<Double> numbers = measurable.getNumber();
if (StringUtil.isEmpty(symbol)) {
symbol = "p" + (++nParameter);
}
for (Double number : numbers) {
String parameterName = symbol + "_" + reaction.getName();
if (model.getModelParameter(parameterName) != null) {
int count = 0;
while (model.getModelParameter(parameterName + "_" + count) != null) {
++count;
}
parameterName = parameterName + "_" + count;
}
ModelParameter parameter = model.new ModelParameter(parameterName, new Expression(conversionFactor * number.doubleValue()), Model.ROLE_UserDefined, unit);
model.addModelParameter(parameter);
for (SBOTerm sboTerm : sboTerms) {
sboToParameters.put(sboTerm, parameter);
}
}
return sboToParameters;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class RefinementLevel method setRoiExpression.
public void setRoiExpression(String roiExp) throws ExpressionException {
Expression exp = null;
if (roiExp != null) {
roiExp = roiExp.trim();
if (roiExp.length() > 0) {
exp = new Expression(roiExp);
exp.bindExpression(new SimpleSymbolTable(new String[] { "x", "y", "z" }));
}
}
this.roiExpression = exp;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class SimulationContext method createRateRule.
public RateRule createRateRule(SymbolTableEntry varSTE) throws PropertyVetoException {
String rateRuleName = getFreeRateRuleName();
RateRule rateRule = new RateRule(rateRuleName, varSTE, new Expression(0.0), this);
return addRateRule(rateRule);
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class SimulationContext method createSimulationContextParameter.
public SimulationContextParameter createSimulationContextParameter() {
String name = "appParm0";
while (getSimulationContextParameter(name) != null) {
name = TokenMangler.getNextEnumeratedToken(name);
}
Expression expression = new Expression(1.0);
int role = SimulationContext.ROLE_UserDefined;
VCUnitDefinition unit = getModel().getUnitSystem().getInstance_DIMENSIONLESS();
SimulationContextParameter parameter = new SimulationContextParameter(name, expression, role, unit);
try {
addSimulationContextParameter(parameter);
return parameter;
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new RuntimeException("error creating new application parameter: " + e.getMessage(), e);
}
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class SpeciesContextSpec method convertParticlesToConcentration.
public Expression convertParticlesToConcentration(Expression iniParticles) throws ExpressionException, MappingException {
Expression iniConcentrationExpr = null;
Structure structure = getSpeciesContext().getStructure();
double structSize = computeStructureSize();
if (structure instanceof Membrane) {
// iniConcentration(molecules/um2) = particles/size(um2)
try {
iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * 1.0) / structSize);
} catch (ExpressionException e) {
iniConcentrationExpr = Expression.div(iniParticles, new Expression(structSize)).flatten();
}
} else {
// convert concentration(particles/volume) to number of particles
// particles = [iniParticles(uM)/size(um3)]*KMOLE
// @Note : 'kMole' variable here is used only as a var name, it does not represent the previously known ReservedSymbol KMOLE.
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition stochasticToVolSubstance = modelUnitSystem.getVolumeSubstanceUnit().divideBy(modelUnitSystem.getStochasticSubstanceUnit());
double stochasticToVolSubstanceScale = stochasticToVolSubstance.getDimensionlessScale().doubleValue();
try {
iniConcentrationExpr = new Expression((iniParticles.evaluateConstant() * stochasticToVolSubstanceScale / structSize));
} catch (ExpressionException e) {
Expression numeratorExpr = Expression.mult(iniParticles, new Expression(stochasticToVolSubstanceScale));
Expression denominatorExpr = new Expression(structSize);
iniConcentrationExpr = Expression.div(numeratorExpr, denominatorExpr).flatten();
}
}
return iniConcentrationExpr;
}
Aggregations