use of cbit.vcell.model.ModelException in project vcell by virtualcell.
the class GeneratedReactionTableRow method deriveRule.
private void deriveRule(String inputString, Model tempModel) {
if (owner != null && owner.getSimulationContext() != null) {
List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
try {
tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
}
} else {
// This should not be possible
throw new RuntimeException("Owner or SimulationContext are null.");
}
int arrowIndex = inputString.indexOf("<->");
boolean bReversible = true;
if (arrowIndex < 0) {
arrowIndex = inputString.indexOf("->");
bReversible = false;
}
String left = inputString.substring(0, arrowIndex).trim();
String right = inputString.substring(arrowIndex + (bReversible ? 3 : 2)).trim();
if (left.length() == 0 && right.length() == 0) {
return;
}
String name = reactionObject.getRuleName();
if (name.contains(GeneratedReactionTableModel.reverse)) {
name = name.substring(GeneratedReactionTableModel.reverse.length());
}
if (name.endsWith(ReactionRule.DirectHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.DirectHalf));
}
if (name.endsWith(ReactionRule.InverseHalf)) {
name = name.substring(0, name.indexOf(ReactionRule.InverseHalf));
}
// try to get the name of the original structure from the original rule and make here another structure with the same name
String strStructure = null;
Structure ruleStructure;
SimulationContext sc = owner.getSimulationContext();
ReactionRule rr = sc.getModel().getRbmModelContainer().getReactionRule(name);
if (rr != null && rr.getStructure() != null) {
strStructure = rr.getStructure().getName();
}
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
try {
tempModel.addFeature(strStructure);
} catch (ModelException | PropertyVetoException e) {
e.printStackTrace();
}
}
ruleStructure = tempModel.getStructure(strStructure);
} else {
throw new RuntimeException("Failed to recover a Structure name from the Reaction Rule: " + name);
}
// making the fake rules just for display purpose, actually they are the flattened reactions resulted from bngl
// the name is probably not unique, it's likely that many flattened reactions are derived from the same rule
reactionRule = tempModel.getRbmModelContainer().createReactionRule(name, ruleStructure, bReversible);
String regex = "[^!]\\+";
String[] patterns = left.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
// if compartments are present, we're making some fake compartments in the tempModel just for compartment name display purposes
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
// if nothing explicit for a participant, we use by default the structure of the rule
structure = ruleStructure;
}
reactionRule.addReactant(new ReactantPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
return;
}
}
patterns = right.split(regex);
for (String spString : patterns) {
try {
spString = spString.trim();
SpeciesPattern speciesPattern = (SpeciesPattern) RbmUtils.parseSpeciesPattern(spString, tempModel);
strStructure = RbmUtils.parseCompartment(spString, tempModel);
speciesPattern.resolveBonds();
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
structure = ruleStructure;
}
reactionRule.addProduct(new ProductPattern(speciesPattern, structure));
} catch (Throwable ex) {
ex.printStackTrace();
return;
}
}
}
use of cbit.vcell.model.ModelException in project vcell by virtualcell.
the class GeneratedSpeciesTableModel method getModel.
private Model getModel() {
if (model == null) {
try {
model = new Model("MyTempModel");
model.addFeature("c0");
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
}
}
return model;
}
use of cbit.vcell.model.ModelException in project vcell by virtualcell.
the class GeneratedSpeciesTableModel2 method getModel.
private Model getModel() {
if (model == null) {
try {
model = new Model("MyTempModel");
model.addFeature("c0");
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
}
}
return model;
}
use of cbit.vcell.model.ModelException in project vcell by virtualcell.
the class GeneratedSpeciesTableRow method deriveSpecies.
private void deriveSpecies(String inputString, Model tempModel) {
if (owner != null && owner.getSimulationContext() != null) {
List<MolecularType> mtList = owner.getSimulationContext().getModel().getRbmModelContainer().getMolecularTypeList();
try {
tempModel.getRbmModelContainer().setMolecularTypeList(mtList);
} catch (PropertyVetoException e1) {
e1.printStackTrace();
throw new RuntimeException("Unexpected exception setting " + MolecularType.typeName + " list: " + e1.getMessage(), e1);
}
} else {
System.out.println("something is wrong, we just do nothing rather than crash");
return;
}
try {
String strStructure = null;
if (inputString.contains(RbmUtils.SiteStruct)) {
// we are in the mode where we emulate compartments by adding the compartment name as a fake site
Pair<List<String>, String> p = RbmUtils.extractCompartment(inputString);
strStructure = p.one.get(0);
inputString = p.two;
} else {
// should be the normal @comp:expression format - if it's not it will return null
strStructure = RbmUtils.parseCompartment(inputString, tempModel);
}
Structure structure;
if (strStructure != null) {
if (tempModel.getStructure(strStructure) == null) {
tempModel.addFeature(strStructure);
}
structure = tempModel.getStructure(strStructure);
} else {
structure = tempModel.getStructure(0);
}
SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
sp.resolveBonds();
// System.out.println(sp.toString());
species = new SpeciesContext(new Species("a", ""), structure, sp);
} catch (ParseException | PropertyVetoException | ModelException e1) {
e1.printStackTrace();
}
}
use of cbit.vcell.model.ModelException in project vcell by virtualcell.
the class ObservablesGroupTableModel method getModel.
private Model getModel() {
if (model == null) {
try {
model = new Model("MyTempModel");
model.addFeature("c0");
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
}
}
return model;
}
Aggregations