use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class RbmNetworkGenerator method generateModel.
public static void generateModel(BioModel bioModel, String netfile) throws Exception {
Model model = bioModel.getModel();
Map<String, SpeciesContext> speciesMap = new HashMap<String, SpeciesContext>();
Map<String, ReactionStep> reactionMap = new HashMap<String, ReactionStep>();
List<ReactionLine> reactionLineList = new ArrayList<ReactionLine>();
BufferedReader br = new BufferedReader(new StringReader(netfile));
int reversibleCount = 0;
int reactionCount = 0;
while (true) {
String line = br.readLine();
if (line == null) {
break;
}
line = line.trim();
if (line.equals(BEGIN_PARAMETERS)) {
while (true) {
String line2 = br.readLine();
line2 = line2.trim();
if (line2.length() == 0) {
continue;
}
if (line2.equals(END_PARAMETERS)) {
break;
}
StringTokenizer st = new StringTokenizer(line2);
String token1 = st.nextToken();
String token2 = st.nextToken();
String token3 = st.nextToken();
ModelParameter mp = model.new ModelParameter(token2, new Expression(token3), Model.ROLE_UserDefined, bioModel.getModel().getUnitSystem().getInstance_TBD());
model.addModelParameter(mp);
}
} else if (line.equals(BEGIN_SPECIES)) {
while (true) {
String line2 = br.readLine();
line2 = line2.trim();
if (line2.length() == 0) {
continue;
}
if (line2.equals(END_SPECIES)) {
break;
}
StringTokenizer st = new StringTokenizer(line2);
// no
String token1 = st.nextToken();
// pattern
String token2 = st.nextToken();
// initial condition
String token3 = st.nextToken();
String newname = token2.replaceAll("\\.", "_");
newname = newname.replaceAll("[\\(,][a-zA-Z]\\w*", "");
newname = newname.replaceAll("~|!\\d*", "");
newname = newname.replaceAll("\\(\\)", "");
newname = newname.replaceAll("\\)", "");
SpeciesContext sc = model.createSpeciesContext(model.getStructure(0));
sc.setName(newname);
bioModel.getVCMetaData().setFreeTextAnnotation(sc, token2);
bioModel.getVCMetaData().setFreeTextAnnotation(sc.getSpecies(), token2);
speciesMap.put(token1, sc);
}
} else if (line.equals(BEGIN_REACTIONS)) {
while (true) {
String line2 = br.readLine();
line2 = line2.trim();
if (line2.length() == 0) {
continue;
}
if (line2.equals(END_REACTIONS)) {
break;
}
++reactionCount;
StringTokenizer st = new StringTokenizer(line2);
String token1 = st.nextToken();
// reactants
String token2 = st.nextToken();
// products
String token3 = st.nextToken();
// rate
String token4 = st.nextToken();
String token5 = st.nextToken();
boolean bFoundReversible = false;
Expression rate = new Expression(token4);
for (ReactionLine rl : reactionLineList) {
if (token2.equals(rl.products) && token3.equals(rl.reactants) && token5.equals(rl.ruleLabel + "r")) {
ReactionStep rs = reactionMap.get(rl.no);
((MassActionKinetics) rs.getKinetics()).getReverseRateParameter().setExpression(rate);
reactionLineList.remove(rl);
bFoundReversible = true;
break;
}
}
if (bFoundReversible) {
++reversibleCount;
continue;
}
ReactionLine rl = new ReactionLine(token1, token2, token3, token5);
reactionLineList.add(rl);
SimpleReaction reaction = model.createSimpleReaction(model.getStructure(0));
reactionMap.put(token1, reaction);
reaction.setModel(model);
bioModel.getVCMetaData().setFreeTextAnnotation(reaction, line2);
MassActionKinetics kinetics = new MassActionKinetics(reaction);
reaction.setKinetics(kinetics);
st = new StringTokenizer(token2, ",");
while (st.hasMoreTokens()) {
String t = st.nextToken();
SpeciesContext sc = speciesMap.get(t);
if (sc != null) {
boolean bExists = false;
for (ReactionParticipant rp : reaction.getReactionParticipants()) {
if (rp instanceof Reactant && rp.getSpeciesContext() == sc) {
rp.setStoichiometry(rp.getStoichiometry() + 1);
bExists = true;
break;
}
}
if (!bExists) {
reaction.addReactant(sc, 1);
}
}
}
st = new StringTokenizer(token3, ",");
while (st.hasMoreTokens()) {
String t = st.nextToken();
SpeciesContext sc = speciesMap.get(t);
if (sc != null) {
boolean bExists = false;
for (ReactionParticipant rp : reaction.getReactionParticipants()) {
if (rp instanceof Product && rp.getSpeciesContext() == sc) {
rp.setStoichiometry(rp.getStoichiometry() + 1);
bExists = true;
break;
}
}
if (!bExists) {
reaction.addProduct(sc, 1);
}
}
}
kinetics.getForwardRateParameter().setExpression(rate);
}
}
}
System.out.println(model.getNumSpecies() + " species added");
System.out.println(model.getNumReactions() + " reactions added");
System.out.println(reversibleCount + " reversible reactions found");
if (reactionCount != model.getNumReactions() + reversibleCount) {
throw new RuntimeException("Reactions are not imported correctly!");
}
}
use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class XmlReader method getModelParams.
public ModelParameter[] getModelParams(Element globalParams, Model model) throws XmlParseException {
Iterator<Element> globalsIterator = globalParams.getChildren(XMLTags.ParameterTag, vcNamespace).iterator();
Vector<ModelParameter> modelParamsVector = new Vector<ModelParameter>();
while (globalsIterator.hasNext()) {
org.jdom.Element paramElement = (Element) globalsIterator.next();
modelParamsVector.add(getModelParameter(paramElement, model));
}
return ((ModelParameter[]) BeanUtils.getArray(modelParamsVector, ModelParameter.class));
}
use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class KineticContext method getParameter.
public ModelParameter getParameter(SBOSet sboSet) {
ModelParameter param = sboSetToParam.get(sboSet);
if (param == null) {
for (Map.Entry<SBOTerm, ModelParameter> entry : termToParam.entrySet()) {
SBOTerm sboTerm = entry.getKey();
if (sboSet.includes(sboTerm)) {
param = entry.getValue();
sboSetToParam.put(sboSet, param);
break;
}
}
}
return param;
}
use of cbit.vcell.model.Model.ModelParameter in project vcell by virtualcell.
the class SBPAXHMMIrrevLawBuilder method addKinetics.
public void addKinetics(KineticContext context) {
try {
ReactionStep reaction = context.getReaction();
HMM_IRRKinetics kinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
NameScope modelScope = reaction.getModel().getNameScope();
ModelParameter kMichaelis = context.getParameter(SBOList.MICHAELIS_CONST_FORW);
if (kMichaelis != null) {
KineticsParameter kmParameter = kinetics.getKmParameter();
kmParameter.setExpression(new Expression(kMichaelis, modelScope));
kmParameter.setUnitDefinition(kMichaelis.getUnitDefinition());
}
ModelParameter kcat = context.getParameter(SBOList.CATALYTIC_RATE_CONST_FORW);
if (kcat != null && context.getCatalysts().size() == 1) {
KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
Catalyst catalyst = context.getCatalysts().iterator().next();
vmaxParameter.setExpression(Expression.mult(new Expression(kcat, modelScope), new Expression(catalyst.getSpeciesContext(), modelScope)));
// vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
} else {
ModelParameter vMax = context.getParameter(SBOList.MAXIMAL_VELOCITY_FORW);
if (vMax != null) {
KineticsParameter vmaxParameter = kinetics.getVmaxParameter();
vmaxParameter.setExpression(new Expression(vMax, modelScope));
vmaxParameter.setUnitDefinition(vMax.getUnitDefinition());
}
}
} catch (ExpressionException e) {
e.printStackTrace();
}
}
use of cbit.vcell.model.Model.ModelParameter 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;
}
Aggregations