use of cbit.vcell.model.RbmKineticLaw.RateLawType in project vcell by virtualcell.
the class ReactionRuleKineticsPropertiesPanel method updateKineticChoice.
private void updateKineticChoice() {
RateLawType newRateLawType = (RateLawType) getKineticsTypeComboBox().getSelectedItem();
// if same as current kinetics, don't create new one
if (reactionRule == null || reactionRule.getKineticLaw().getRateLawType().equals(newRateLawType)) {
return;
}
RbmKineticLaw newRbmKineticLaw = new RbmKineticLaw(reactionRule, newRateLawType);
reactionRule.setKineticLaw(newRbmKineticLaw);
if (newRateLawType != RateLawType.MassAction) {
reactionRule.setReversible(false);
isReversibleCheckBox.setSelected(reactionRule.isReversible());
isReversibleCheckBox.setEnabled(false);
} else {
isReversibleCheckBox.setSelected(reactionRule.isReversible());
isReversibleCheckBox.setEnabled(true);
}
}
use of cbit.vcell.model.RbmKineticLaw.RateLawType in project vcell by virtualcell.
the class RulebasedTransformer method transform.
private void transform(SimulationContext originalSimContext, SimulationContext transformedSimulationContext, ArrayList<ModelEntityMapping> entityMappings, MathMappingCallback mathMappingCallback) throws PropertyVetoException {
Model newModel = transformedSimulationContext.getModel();
Model originalModel = originalSimContext.getModel();
ModelEntityMapping em = null;
// list of rules created from the reactions; we apply the symmetry factor computed by bionetgen only to these
Set<ReactionRule> fromReactions = new HashSet<>();
for (SpeciesContext newSpeciesContext : newModel.getSpeciesContexts()) {
final SpeciesContext originalSpeciesContext = originalModel.getSpeciesContext(newSpeciesContext.getName());
// map new and old species contexts
em = new ModelEntityMapping(originalSpeciesContext, newSpeciesContext);
entityMappings.add(em);
if (newSpeciesContext.hasSpeciesPattern()) {
// it's perfect already and can't be improved
continue;
}
try {
MolecularType newmt = newModel.getRbmModelContainer().createMolecularType();
newModel.getRbmModelContainer().addMolecularType(newmt, false);
MolecularTypePattern newmtp_sc = new MolecularTypePattern(newmt);
SpeciesPattern newsp_sc = new SpeciesPattern();
newsp_sc.addMolecularTypePattern(newmtp_sc);
newSpeciesContext.setSpeciesPattern(newsp_sc);
RbmObservable newo = new RbmObservable(newModel, "O0_" + newmt.getName() + "_tot", newSpeciesContext.getStructure(), RbmObservable.ObservableType.Molecules);
MolecularTypePattern newmtp_ob = new MolecularTypePattern(newmt);
SpeciesPattern newsp_ob = new SpeciesPattern();
newsp_ob.addMolecularTypePattern(newmtp_ob);
newo.addSpeciesPattern(newsp_ob);
newModel.getRbmModelContainer().addObservable(newo);
// map new observable to old species context
em = new ModelEntityMapping(originalSpeciesContext, newo);
entityMappings.add(em);
} catch (ModelException e) {
e.printStackTrace();
throw new RuntimeException("unable to transform species context: " + e.getMessage());
} catch (PropertyVetoException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
ReactionSpec[] reactionSpecs = transformedSimulationContext.getReactionContext().getReactionSpecs();
for (ReactionSpec reactionSpec : reactionSpecs) {
if (reactionSpec.isExcluded()) {
// we create rules only from those reactions which are not excluded
continue;
}
ReactionStep rs = reactionSpec.getReactionStep();
String name = rs.getName();
String mangled = TokenMangler.fixTokenStrict(name);
mangled = newModel.getReactionName(mangled);
Kinetics k = rs.getKinetics();
if (!(k instanceof MassActionKinetics)) {
throw new RuntimeException("Only Mass Action Kinetics supported at this time, reaction \"" + rs.getName() + "\" uses kinetic law type \"" + rs.getKinetics().getName() + "\"");
}
boolean bReversible = rs.isReversible();
ReactionRule rr = new ReactionRule(newModel, mangled, rs.getStructure(), bReversible);
fromReactions.add(rr);
MassActionKinetics massActionKinetics = (MassActionKinetics) k;
List<Reactant> rList = rs.getReactants();
List<Product> pList = rs.getProducts();
// counting the stoichiometry - 2A+B means 3 reactants
int numReactants = 0;
for (Reactant r : rList) {
numReactants += r.getStoichiometry();
if (numReactants > 2) {
String message = "NFSim doesn't support more than 2 reactants within a reaction: " + name;
throw new RuntimeException(message);
}
}
int numProducts = 0;
for (Product p : pList) {
numProducts += p.getStoichiometry();
if (bReversible && numProducts > 2) {
String message = "NFSim doesn't support more than 2 products within a reversible reaction: " + name;
throw new RuntimeException(message);
}
}
RateLawType rateLawType = RateLawType.MassAction;
RbmKineticLaw kineticLaw = new RbmKineticLaw(rr, rateLawType);
try {
String forwardRateName = massActionKinetics.getForwardRateParameter().getName();
Expression forwardRateExp = massActionKinetics.getForwardRateParameter().getExpression();
String reverseRateName = massActionKinetics.getReverseRateParameter().getName();
Expression reverseRateExp = massActionKinetics.getReverseRateParameter().getExpression();
LocalParameter fR = kineticLaw.getLocalParameter(RbmKineticLawParameterType.MassActionForwardRate);
fR.setName(forwardRateName);
LocalParameter rR = kineticLaw.getLocalParameter(RbmKineticLawParameterType.MassActionReverseRate);
rR.setName(reverseRateName);
if (rs.hasReactant()) {
kineticLaw.setParameterValue(fR, forwardRateExp, true);
}
if (rs.hasProduct()) {
kineticLaw.setParameterValue(rR, reverseRateExp, true);
}
//
for (KineticsParameter reaction_p : massActionKinetics.getKineticsParameters()) {
if (reaction_p.getRole() == Kinetics.ROLE_UserDefined) {
LocalParameter rule_p = kineticLaw.getLocalParameter(reaction_p.getName());
if (rule_p == null) {
//
// after lazy parameter creation we didn't find a user-defined rule parameter with this same name.
//
// there must be a global symbol with the same name, that the local reaction parameter has overridden.
//
ParameterContext.LocalProxyParameter rule_proxy_parameter = null;
for (ProxyParameter proxyParameter : kineticLaw.getProxyParameters()) {
if (proxyParameter.getName().equals(reaction_p.getName())) {
rule_proxy_parameter = (LocalProxyParameter) proxyParameter;
}
}
if (rule_proxy_parameter != null) {
// we want to convert to local
boolean bConvertToGlobal = false;
kineticLaw.convertParameterType(rule_proxy_parameter, bConvertToGlobal);
} else {
// could find neither local parameter nor proxy parameter
throw new RuntimeException("user defined parameter " + reaction_p.getName() + " from reaction " + rs.getName() + " didn't map to a reactionRule parameter");
}
} else if (rule_p.getRole() == RbmKineticLawParameterType.UserDefined) {
kineticLaw.setParameterValue(rule_p, reaction_p.getExpression(), true);
rule_p.setUnitDefinition(reaction_p.getUnitDefinition());
} else {
throw new RuntimeException("user defined parameter " + reaction_p.getName() + " from reaction " + rs.getName() + " mapped to a reactionRule parameter with unexpected role " + rule_p.getRole().getDescription());
}
}
}
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException("Problem attempting to set RbmKineticLaw expression: " + e.getMessage());
}
rr.setKineticLaw(kineticLaw);
KineticsParameter[] kpList = k.getKineticsParameters();
ModelParameter[] mpList = rs.getModel().getModelParameters();
ModelParameter mp = rs.getModel().getModelParameter(kpList[0].getName());
ReactionParticipant[] rpList = rs.getReactionParticipants();
for (ReactionParticipant p : rpList) {
if (p instanceof Reactant) {
int stoichiometry = p.getStoichiometry();
for (int i = 0; i < stoichiometry; i++) {
SpeciesPattern speciesPattern = new SpeciesPattern(rs.getModel(), p.getSpeciesContext().getSpeciesPattern());
ReactantPattern reactantPattern = new ReactantPattern(speciesPattern, p.getStructure());
rr.addReactant(reactantPattern);
}
} else if (p instanceof Product) {
int stoichiometry = p.getStoichiometry();
for (int i = 0; i < stoichiometry; i++) {
SpeciesPattern speciesPattern = new SpeciesPattern(rs.getModel(), p.getSpeciesContext().getSpeciesPattern());
ProductPattern productPattern = new ProductPattern(speciesPattern, p.getStructure());
rr.addProduct(productPattern);
}
}
}
// commented code below is probably obsolete, we verify (above) in the reaction the number of participants,
// no need to do it again in the corresponding rule
// if(rr.getReactantPatterns().size() > 2) {
// String message = "NFSim doesn't support more than 2 reactants within a reaction: " + name;
// throw new RuntimeException(message);
// }
// if(rr.getProductPatterns().size() > 2) {
// String message = "NFSim doesn't support more than 2 products within a reaction: " + name;
// throw new RuntimeException(message);
// }
newModel.removeReactionStep(rs);
newModel.getRbmModelContainer().addReactionRule(rr);
}
for (ReactionRuleSpec rrs : transformedSimulationContext.getReactionContext().getReactionRuleSpecs()) {
if (rrs == null) {
continue;
}
ReactionRule rr = rrs.getReactionRule();
if (rrs.isExcluded()) {
// delete those rules which are disabled (excluded) in the Specifications / Reaction table
newModel.getRbmModelContainer().removeReactionRule(rr);
continue;
}
}
// now that we generated the rules we can delete the reaction steps they're coming from
for (ReactionStep rs : newModel.getReactionSteps()) {
newModel.removeReactionStep(rs);
}
try {
// we invoke bngl just for the purpose of generating the xml file, which we'll then use to extract the symmetry factor
generateNetwork(transformedSimulationContext, fromReactions, mathMappingCallback);
} catch (ClassNotFoundException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Finished RuleBased Transformer.");
}
use of cbit.vcell.model.RbmKineticLaw.RateLawType in project vcell by virtualcell.
the class BNGOutputFileParser method createBngOutputSpec.
public static BNGOutputSpec createBngOutputSpec(String inputString) {
String newLineDelimiters = "\n\r";
StringTokenizer lineTokenizer = new StringTokenizer(inputString, newLineDelimiters);
String token1 = new String("");
String token2 = new String("");
String blankDelimiters = " \t";
String commaDelimiters = ",";
RbmKineticLaw.RateLawType rateLawType = RateLawType.MassAction;
//
// Each token is a line from the output (net) file generated by BioNetGen.
// We have to distinguish the Parameters list, Species list, Reactions list, Obeservable groups list and store them in a BNGOutputSpec object
// Each list XXX above has a 'begin XXXs' and an 'end XXXs' delimiter.
//
// Need to track which type of list we are reading in from the list delimiter. For convenience, have a separate variable for each.
int PARAM_LIST = 1;
int MOLECULE_LIST = 2;
int SPECIES_LIST = 3;
int RXN_RULES_LIST = 4;
int RXN_LIST = 5;
int OBS_GPS_LIST = 6;
int list = 0;
Vector<BNGParameter> paramVector = new Vector<BNGParameter>();
Vector<BNGMolecule> moleculesVector = new Vector<BNGMolecule>();
Vector<BNGSpecies> speciesVector = new Vector<BNGSpecies>();
// Vector rxnRulesVector = new Vector();
Vector<BNGReaction> rxnVector = new Vector<BNGReaction>();
Vector<ObservableGroup> obsGroupsVector = new Vector<ObservableGroup>();
while (lineTokenizer.hasMoreTokens()) {
token1 = lineTokenizer.nextToken();
// Identify type of list ...
if (token1.equals("begin parameters")) {
list = PARAM_LIST;
continue;
} else if (token1.equals("begin molecule types")) {
list = MOLECULE_LIST;
continue;
} else if (token1.equals("begin species")) {
list = SPECIES_LIST;
continue;
} else if (token1.equals("begin reaction rules")) {
list = RXN_RULES_LIST;
continue;
} else if (token1.equals("begin reactions")) {
list = RXN_LIST;
continue;
} else if (token1.equals("begin groups")) {
list = OBS_GPS_LIST;
continue;
} else if (token1.equals("end parameters") || token1.equals("end molecule types") || token1.equals("end species") || token1.equals("end reaction rules") || token1.equals("end reactions") || token1.equals("end groups")) {
list = 0;
continue;
}
StringTokenizer nextLine = null;
// Fill in list of parameters
if (list == PARAM_LIST) {
nextLine = new StringTokenizer(token1, blankDelimiters);
int i = 0;
String paramName = null;
double paramVal = 0.0;
// 'nextLine' is the line with a parameter and its value (there is an index, but it can be ignored).
while (nextLine.hasMoreTokens()) {
token2 = nextLine.nextToken();
if (token2 != null) {
token2 = token2.trim();
}
// First token is index number, ignore for now.
if (i == 0) {
i++;
continue;
} else if (i == 1) {
paramName = token2;
} else if (i == 2) {
paramVal = Double.parseDouble(token2);
}
i++;
}
// After parsing parameter from the line, create a new BNGParameter and add it to paramVector.
if (paramName != null) {
paramVector.addElement(new BNGParameter(paramName, paramVal));
}
}
// Fill in list of molecule types
if (list == MOLECULE_LIST) {
nextLine = new StringTokenizer(token1, blankDelimiters);
int i = 0;
// int speciesNtwkFileIndx = 0;
String moleculeName = null;
// 'nextLine' is the line with a molecule (the index can be ignored).
while (nextLine.hasMoreTokens()) {
token2 = nextLine.nextToken();
if (token2 != null) {
token2 = token2.trim();
}
// First token is index number, second is the name, last token is the concentration.
if (i == 0) {
i++;
continue;
} else if (i == 1) {
moleculeName = token2;
}
i++;
}
// After parsing molecules from the line, create a new BNGMolecule and add it to speciesVector.
if (moleculeName != null) {
moleculesVector.addElement(new BNGMolecule(moleculeName));
}
}
// Fill in list of species
if (list == SPECIES_LIST) {
nextLine = new StringTokenizer(token1, blankDelimiters);
int i = 0;
int speciesNtwkFileIndx = 0;
String speciesName = null;
Expression speciesConcExpr = null;
// 'nextLine' is the line with a species and its concentration; the index is necessary to build the reactions.
while (nextLine.hasMoreTokens()) {
token2 = nextLine.nextToken();
if (token2 != null) {
token2 = token2.trim();
}
// First token is index number, second is the name, last token is the concentration.
if (i == 0) {
speciesNtwkFileIndx = Integer.parseInt(token2);
} else if (i == 1) {
speciesName = token2;
} else if (i == 2) {
try {
speciesConcExpr = new Expression(token2);
} catch (ExpressionException e) {
throw new RuntimeException("Error in reading expression for species concentration \"" + speciesName + "\"");
}
}
i++;
}
// After parsing species from the line, create a new BNGSpecies and add it to speciesVector.
if (speciesName != null && speciesConcExpr != null && speciesNtwkFileIndx > 0) {
BNGSpecies newSpecies = null;
if (speciesName.indexOf(".") >= 0) {
newSpecies = new BNGComplexSpecies(speciesName, speciesConcExpr, speciesNtwkFileIndx);
} else if ((speciesName.indexOf("(") > 0) && (speciesName.indexOf(".") < 0)) {
newSpecies = new BNGMultiStateSpecies(speciesName, speciesConcExpr, speciesNtwkFileIndx);
} else {
newSpecies = new BNGSingleStateSpecies(speciesName, speciesConcExpr, speciesNtwkFileIndx);
}
speciesVector.addElement(newSpecies);
}
}
// Fill in list of reaction rules
if (list == RXN_RULES_LIST) {
// For now, we can ignore the reaction rules in the network file, since its information has already consumed while generating reactions.
}
// Fill in list of reactions
if (list == RXN_LIST) {
nextLine = new StringTokenizer(token1, blankDelimiters);
int i = 0;
String reactantsSubkey = null;
String productsSubkey = null;
BNGSpecies[] reactantsArray = null;
BNGSpecies[] productsArray = null;
Expression paramExpression = null;
String paramExpressionString = null;
String ruleName = null;
boolean ruleReversed = false;
// 'nextLine' is the line with a reaction : reactants, products, rate consts.; the index can be ignored (for now)
while (nextLine.hasMoreTokens()) {
token2 = nextLine.nextToken();
if (token2 != null) {
token2 = token2.trim();
}
// First token is index number, can be ignored for a reaction.
if (i == 0) {
i++;
continue;
} else if (i == 1) {
reactantsSubkey = token2;
// This string is a list of numbers (denoting species index) separated by commas, representing the reactant(s)
StringTokenizer nextPart = new StringTokenizer(token2, commaDelimiters);
String token3 = null;
int specNo = 0;
Vector<BNGSpecies> reactantVector = new Vector<BNGSpecies>();
while (nextPart.hasMoreTokens()) {
token3 = nextPart.nextToken();
if (token3 != null) {
token3 = token3.trim();
}
// Get the species index from token and extract the corresponding species from speciesVector as a reactant
specNo = Integer.parseInt(token3);
if (speciesVector.size() > 0) {
reactantVector.addElement(getSpecies(specNo, speciesVector));
}
}
reactantsArray = (BNGSpecies[]) org.vcell.util.BeanUtils.getArray(reactantVector, BNGSpecies.class);
} else if (i == 2) {
// This string is a list of numbers (species indices) separated by commas, representing the product(s)
productsSubkey = token2;
StringTokenizer nextPart = new StringTokenizer(token2, commaDelimiters);
String token3 = null;
int specNo = 0;
Vector<BNGSpecies> productVector = new Vector<BNGSpecies>();
while (nextPart.hasMoreTokens()) {
token3 = nextPart.nextToken();
if (token3 != null) {
token3 = token3.trim();
}
// Get the species index from token and extract the corresponding species from speciesVector as a product
specNo = Integer.parseInt(token3);
if (speciesVector.size() > 0) {
productVector.addElement(getSpecies(specNo, speciesVector));
}
}
productsArray = (BNGSpecies[]) org.vcell.util.BeanUtils.getArray(productVector, BNGSpecies.class);
} else if (i == 3) {
if (!(token2 + "(").contains(RbmUtils.MM_Prefix)) {
try {
paramExpression = new Expression(token2);
} catch (ExpressionException e) {
throw new RuntimeException("Could not create parameter expression for reaction; " + e.getMessage());
}
} else {
StringTokenizer tokkenizer = new StringTokenizer(token2, "*");
String tokken = tokkenizer.nextToken();
if (RbmUtils.MM_Prefix.contains(tokken)) {
rateLawType = RateLawType.MichaelisMenten;
paramExpressionString = RbmUtils.MM_Prefix;
} else {
if (tokkenizer.hasMoreTokens()) {
tokken = tokkenizer.nextToken();
if (RbmUtils.MM_Prefix.contains(tokken)) {
rateLawType = RateLawType.MichaelisMenten;
paramExpressionString = RbmUtils.MM_Prefix;
} else {
throw new RuntimeException("Could not parse Michaelis Menten kinetic law for reaction");
}
} else {
throw new RuntimeException("Could not parse Michaelis Menten kinetic law for reaction");
}
}
}
} else if (i == 4) {
switch(rateLawType) {
case MassAction:
if (!token2.startsWith("#")) {
throw new RuntimeException("Unrecognized prefix for the rule name field: " + token2);
}
ruleName = token2.substring(1);
if (ruleName.startsWith("_reverse_")) {
ruleReversed = true;
ruleName = ruleName.substring("_reverse_".length());
} else {
ruleReversed = false;
}
break;
case MichaelisMenten:
paramExpressionString += token2;
break;
case Saturable:
default:
throw new RuntimeException("Unsupported rate law type '" + rateLawType.getDefaultName() + "' for '" + ruleName + "'");
}
} else if (i == 5) {
switch(rateLawType) {
case MichaelisMenten:
paramExpressionString += ",";
paramExpressionString += token2;
break;
case MassAction:
case Saturable:
default:
throw new RuntimeException("Unexpected argument '" + token2 + "' for '" + ruleName + "'");
}
} else if (i == 6) {
switch(rateLawType) {
case MichaelisMenten:
if (!token2.startsWith("#")) {
throw new RuntimeException("Unrecognized prefix for the rule name field: " + token2);
}
ruleName = token2.substring(1);
break;
case MassAction:
case Saturable:
default:
throw new RuntimeException("Unexpected argument '" + token2 + "' for '" + ruleName + "'");
}
}
i++;
}
if (rateLawType == RateLawType.MichaelisMenten && paramExpressionString != null) {
paramExpressionString += ")";
try {
paramExpression = new Expression(paramExpressionString);
} catch (ExpressionException e) {
throw new RuntimeException("Could not create parameter expression for reaction; " + e.getMessage());
}
}
// After parsing reaction participants from the line, create a new BNGReaction and add it to rxnVector.
if (reactantsArray.length > 0 && productsArray.length > 0 && paramExpression != null) {
BNGReaction newRxn = new BNGReaction(reactantsSubkey, productsSubkey, reactantsArray, productsArray, paramExpression, ruleName, ruleReversed);
rxnVector.addElement(newRxn);
}
}
// Fill in list of observables (groups)
if (list == OBS_GPS_LIST) {
nextLine = new StringTokenizer(token1, blankDelimiters);
int i = 0;
String observableName = null;
Vector<BNGSpecies> obsSpeciesVector = new Vector<BNGSpecies>();
Vector<Integer> obsMultiplicityVector = new Vector<Integer>();
// 'nextLine' is the line with an observable group and the species that satisfy the observable rule in the input file
while (nextLine.hasMoreTokens()) {
token2 = nextLine.nextToken();
if (token2 != null) {
token2 = token2.trim();
}
// First token is index number - ignore, second is the observable name, last token is the set of species that satisfy observable rule.
if (i == 0) {
i++;
continue;
} else if (i == 1) {
observableName = token2;
} else if (i == 2) {
// This string is a list of numbers (species indices) with a multiplicity factor (# of molecules) separated by commas
StringTokenizer nextPart = new StringTokenizer(token2, commaDelimiters);
String token3 = null;
while (nextPart.hasMoreTokens()) {
token3 = nextPart.nextToken();
if (token3 != null) {
token3 = token3.trim();
}
if (token3.indexOf("*") > 0) {
//
// If the observable group corresponds to a molecule observable rule, the species list in the group
// could have a multiplicity factor, and occurs as : 'x*yy' where 'x' is the # of molecules
// and 'yy' is the index of the species in the list of species that appears in the beginning of the
// network file. Strip out the multiplicity factor from 'token3' and store it in the 'obsMultiplicityVector';
// strip out the species # and get the corresponding species and store it in 'obsSpeciesVector'.
//
int ii = token3.indexOf("*");
String indx = token3.substring(0, ii);
Integer obsSpeciesIndx = new Integer(indx);
obsMultiplicityVector.addElement(obsSpeciesIndx);
String specNoStr = token3.substring(ii + 1);
BNGSpecies species = getSpecies(Integer.parseInt(specNoStr), speciesVector);
obsSpeciesVector.addElement(species);
} else {
//
// If the observable group corresponds to a species observable rule, the species list in the group
// occurs as 'x' where x is the species index in the list of species that appears in the beginning of the
// network file. Store the species corresponding to the index in the 'obsSpeciesVector' and store a
// multiplicity of 1 for the corresponding species in the 'obsMultiplicityVector'.
//
int specIndx = Integer.parseInt(token3);
BNGSpecies species = getSpecies(specIndx, speciesVector);
obsSpeciesVector.addElement(species);
obsMultiplicityVector.addElement(new Integer(1));
}
}
}
i++;
}
// After parsing observable group from the line, create a new ObservableGroup and add it to observable group vector.
if (observableName != null && obsMultiplicityVector.size() > 0 && obsSpeciesVector.size() > 0) {
BNGSpecies[] obsSpeciesArray = (BNGSpecies[]) org.vcell.util.BeanUtils.getArray(obsSpeciesVector, BNGSpecies.class);
Integer[] obsMultiplicityArray = (Integer[]) org.vcell.util.BeanUtils.getArray(obsMultiplicityVector, Integer.class);
int[] obsMultiplicityFactors = new int[obsMultiplicityArray.length];
for (int k = 0; k < obsMultiplicityFactors.length; k++) {
obsMultiplicityFactors[k] = obsMultiplicityArray[k].intValue();
}
ObservableGroup newObsGroup = new ObservableGroup(observableName, obsSpeciesArray, obsMultiplicityFactors);
obsGroupsVector.addElement(newObsGroup);
}
}
}
// Create the BNGOutputSpec from the parsed BNG .net (output) file and return.
BNGParameter[] paramsArray = (BNGParameter[]) org.vcell.util.BeanUtils.getArray(paramVector, BNGParameter.class);
BNGMolecule[] moleculesArray = (BNGMolecule[]) org.vcell.util.BeanUtils.getArray(moleculesVector, BNGMolecule.class);
BNGSpecies[] speciesArray = (BNGSpecies[]) org.vcell.util.BeanUtils.getArray(speciesVector, BNGSpecies.class);
BNGReaction[] rxnsArray = (BNGReaction[]) org.vcell.util.BeanUtils.getArray(rxnVector, BNGReaction.class);
ObservableGroup[] observableGpsArray = (ObservableGroup[]) org.vcell.util.BeanUtils.getArray(obsGroupsVector, ObservableGroup.class);
BNGOutputSpec bngOutput = new BNGOutputSpec(paramsArray, moleculesArray, speciesArray, null, rxnsArray, observableGpsArray);
return bngOutput;
}
use of cbit.vcell.model.RbmKineticLaw.RateLawType in project vcell by virtualcell.
the class ReactionRule method clone.
public static ReactionRule clone(Model newModel, ReactionRule oldRule, Structure newStructure, Map<Structure, String> structuresMap, ReactionSpeciesCopy rsCopy) throws ExpressionBindingException {
boolean reversible = oldRule.isReversible();
String newName = oldRule.getName();
while (true) {
if (Model.isNameUnused(newName, newModel)) {
break;
}
newName = org.vcell.util.TokenMangler.getNextEnumeratedToken(newName);
if (rsCopy.getReactionRuleArr() != null) {
for (ReactionRule from : rsCopy.getReactionRuleArr()) {
if (from.getName().equalsIgnoreCase(newName)) {
// make another new name if current new name is used elsewhere
newName = org.vcell.util.TokenMangler.getNextEnumeratedToken(newName);
break;
}
}
}
if (rsCopy.getReactStepArr() != null) {
for (ReactionStep from : rsCopy.getReactStepArr()) {
if (from.getName().equalsIgnoreCase(newName)) {
newName = org.vcell.util.TokenMangler.getNextEnumeratedToken(newName);
break;
}
}
}
if (rsCopy.getSpeciesContextArr() != null) {
for (SpeciesContext from : rsCopy.getSpeciesContextArr()) {
if (from.getName().equalsIgnoreCase(newName)) {
newName = org.vcell.util.TokenMangler.getNextEnumeratedToken(newName);
break;
}
}
}
}
ReactionRule newRule = new ReactionRule(newModel, newName, newStructure, reversible);
for (ReactantPattern oldrp : oldRule.getReactantPatterns()) {
SpeciesPattern newsp = new SpeciesPattern(newModel, oldrp.getSpeciesPattern());
Structure os = oldrp.getStructure();
Structure ns = newModel.getStructure(structuresMap.get(os));
ReactantPattern newrp = new ReactantPattern(newsp, ns);
// don't try to resolve matches or bonds, we want to mirror whatever is in the old rule
newRule.addReactant(newrp, false, false);
}
for (ProductPattern oldpp : oldRule.getProductPatterns()) {
SpeciesPattern newsp = new SpeciesPattern(newModel, oldpp.getSpeciesPattern());
Structure os = oldpp.getStructure();
Structure ns = newModel.getStructure(structuresMap.get(os));
ProductPattern newpp = new ProductPattern(newsp, ns);
newRule.addProduct(newpp, false, false);
}
RateLawType rateLawType = oldRule.getKineticLaw().getRateLawType();
if (rateLawType != RateLawType.MassAction) {
throw new RuntimeException("Only Mass Action Kinetics supported at this time, " + ReactionRule.typeName + " \"" + oldRule.getName() + "\" uses kinetic law type \"" + rateLawType.toString() + "\"");
}
RbmKineticLaw newKineticLaw = new RbmKineticLaw(newRule, rateLawType);
// RbmKineticLaw.duplicate(kineticLaw, oldRule);
RbmKineticLaw.clone(newKineticLaw, oldRule, newRule);
newRule.setKineticLaw(newKineticLaw);
newKineticLaw.bind(newRule);
return newRule;
}
use of cbit.vcell.model.RbmKineticLaw.RateLawType in project vcell by virtualcell.
the class ReactionRule method deriveDirectRule.
public static ReactionRule deriveDirectRule(ReactionRule oldRule) throws ExpressionBindingException, PropertyVetoException {
Model m = oldRule.getModel();
Structure s = oldRule.getStructure();
boolean bR = false;
String newName = oldRule.getDisplayName() + DirectHalf;
ReactionRule newRule = new ReactionRule(m, newName, s, bR);
RbmKineticLaw oldLaw = oldRule.getKineticLaw();
RateLawType rateLawType = oldLaw.getRateLawType();
if (rateLawType != RateLawType.MassAction) {
throw new RuntimeException("Only Mass Action Kinetics supported at this time, " + ReactionRule.typeName + " \"" + oldRule.getName() + "\" uses kinetic law type \"" + rateLawType.toString() + "\"");
}
RbmKineticLaw newLaw = new RbmKineticLaw(newRule, rateLawType);
newRule.setKineticLaw(newLaw);
LocalParameter oldfr = oldLaw.getLocalParameter(RbmKineticLawParameterType.MassActionForwardRate);
Expression exp = new Expression(oldfr.getExpression());
newLaw.setLocalParameterValue(RbmKineticLawParameterType.MassActionForwardRate, exp);
for (ReactantPattern oldrp : oldRule.getReactantPatterns()) {
SpeciesPattern newsp = new SpeciesPattern(m, oldrp.getSpeciesPattern());
ReactantPattern newrp = new ReactantPattern(newsp, oldrp.getStructure());
// don't try to resolve matches or bonds, we want to mirror whatever is in the old rule
newRule.addReactant(newrp, false, false);
}
for (ProductPattern oldpp : oldRule.getProductPatterns()) {
SpeciesPattern newsp = new SpeciesPattern(m, oldpp.getSpeciesPattern());
ProductPattern newpp = new ProductPattern(newsp, oldpp.getStructure());
newRule.addProduct(newpp, false, false);
}
newLaw.bind(newRule);
return newRule;
}
Aggregations