use of org.vcell.model.bngl.ParseException in project vcell by virtualcell.
the class ViewObservablesMapPanel method updateShapeSpecies.
public void updateShapeSpecies(int selectedRow) {
GeneratedSpeciesTableRow speciesTableRow = speciesTableModel.getValueAt(selectedRow);
String inputString = speciesTableRow.getExpression();
// System.out.println(selectedRows[0] + ": " + inputString);
Model tempModel = null;
try {
tempModel = new Model("MyTempModel");
tempModel.addFeature("c0");
} catch (ModelException | PropertyVetoException e1) {
e1.printStackTrace();
}
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);
// we'll just assume there's only one, may want to throw exception if more
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) {
if (owner.getSimulationContext().getModel().getStructure(strStructure).getTypeName().equals(Structure.TYPE_NAME_MEMBRANE)) {
tempModel.addMembrane(strStructure);
} else {
tempModel.addFeature(strStructure);
}
}
structure = tempModel.getStructure(strStructure);
} else {
structure = tempModel.getStructure(0);
}
SpeciesPattern sp = (SpeciesPattern) RbmUtils.parseSpeciesPattern(inputString, tempModel);
sp.resolveBonds();
SpeciesContext sc = new SpeciesContext(new Species("a", ""), structure, sp);
spls = new SpeciesPatternLargeShape(20, 20, -1, sp, shapePanelSpecies, sc, issueManager);
} catch (ParseException | PropertyVetoException | ModelException e1) {
e1.printStackTrace();
// error (red circle)
spls = new SpeciesPatternLargeShape(20, 20, -1, shapePanelSpecies, true, issueManager);
shapePanelSpecies.repaint();
}
int xOffset = spls.getRightEnd() + 45;
Dimension preferredSize = new Dimension(xOffset + 90, 50);
shapePanelSpecies.setPreferredSize(preferredSize);
shapePanelSpecies.repaint();
}
use of org.vcell.model.bngl.ParseException in project vcell by virtualcell.
the class RbmUtils method parseReactionRule.
public static ReactionRule parseReactionRule(String inputString, String name, Structure structure, BioModel bioModel) throws ParseException {
try {
String label = name;
// int labelIndex = inputString.indexOf(':'); // TODO: the way we edit reaction rules now, we have no labels here
// String label = "";
// if(labelIndex>=0) {
// label = inputString.substring(0, labelIndex);
// inputString = inputString.substring(labelIndex+1);
// }
// if(label.isEmpty() || (reactionRuleNames.indexOf(label) != -1)) {
// do { // no label or label in use, we generate new label
// label = generateReactionRuleName();
// } while(reactionRuleNames.indexOf(label) != -1);
// reactionRuleNames.add(label);
// } else {
// reactionRuleNames.add(label);
// }
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 null;
}
// note that the constructor will try to honor the label from the editor but will generate a new one if already in use
ReactionRule reactionRule = bioModel.getModel().getRbmModelContainer().createReactionRule(label, structure, bReversible);
String regex = "[^!]\\+";
String[] patterns = left.split(regex);
for (String sp : patterns) {
SpeciesPattern speciesPattern = parseSpeciesPattern(sp, bioModel.getModel());
reactionRule.addReactant(new ReactantPattern(speciesPattern, reactionRule.getStructure()));
}
patterns = right.split(regex);
for (String sp : patterns) {
SpeciesPattern speciesPattern = parseSpeciesPattern(sp, bioModel.getModel());
reactionRule.addProduct(new ProductPattern(speciesPattern, reactionRule.getStructure()));
}
return reactionRule;
} catch (Throwable ex) {
ex.printStackTrace();
throw new ParseException(ex.getMessage());
}
}
use of org.vcell.model.bngl.ParseException in project vcell by virtualcell.
the class RbmUtils method parseSpeciesPattern.
public static SpeciesPattern parseSpeciesPattern(String originalInputString, Model model) throws ParseException {
String inputString = new String(originalInputString);
try {
if (inputString.startsWith("@") && inputString.contains(":")) {
// throw new ParseException("RbmUtils: Unable to parse SpeciesPattern with compartment information.");
// clean up the compartment information and parse the pure sp expression
inputString = inputString.substring(inputString.lastIndexOf(":") + 1);
}
BNGLParser parser = new BNGLParser(new StringReader(inputString));
ASTSpeciesPattern astSpeciesPattern = parser.SpeciesPattern();
BnglObjectConstructionVisitor constructionVisitor = new BnglObjectConstructionVisitor(model, null, true);
SpeciesPattern speciesPattern = (SpeciesPattern) astSpeciesPattern.jjtAccept(constructionVisitor, null);
return speciesPattern;
} catch (Throwable ex) {
ex.printStackTrace();
throw new ParseException(ex.getMessage());
}
}
use of org.vcell.model.bngl.ParseException in project vcell by virtualcell.
the class SpeciesContext method parseSpeciesPatternString.
public void parseSpeciesPatternString(Model model) {
if (speciesPatternString.equalsIgnoreCase("null")) {
System.out.println("Species Pattern String is 'NULL'.");
return;
}
if (speciesPatternString != null) {
try {
if (speciesPattern != null) {
System.out.println("Species pattern already exists: " + speciesPattern.toString());
return;
}
SpeciesPattern sp = RbmUtils.parseSpeciesPattern(speciesPatternString, model);
setSpeciesPattern(sp);
} catch (ParseException e) {
e.printStackTrace();
throw new RuntimeException("Bad format for repository species pattern string: " + e.getMessage());
}
}
}
Aggregations