Search in sources :

Example 6 with ParseException

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();
}
Also used : ModelException(cbit.vcell.model.ModelException) SpeciesContext(cbit.vcell.model.SpeciesContext) Dimension(java.awt.Dimension) SpeciesPatternLargeShape(cbit.vcell.graph.SpeciesPatternLargeShape) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) Point(java.awt.Point) PropertyVetoException(java.beans.PropertyVetoException) MolecularType(org.vcell.model.rbm.MolecularType) Model(cbit.vcell.model.Model) ObservableTableModel(cbit.vcell.client.desktop.biomodel.ObservableTableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) List(java.util.List) ArrayList(java.util.ArrayList) ParseException(org.vcell.model.bngl.ParseException) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Example 7 with ParseException

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());
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ASTReactionRule(org.vcell.model.bngl.ASTReactionRule) ProductPattern(cbit.vcell.model.ProductPattern) ParseException(org.vcell.model.bngl.ParseException) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) ASTSpeciesPattern(org.vcell.model.bngl.ASTSpeciesPattern) ReactantPattern(cbit.vcell.model.ReactantPattern)

Example 8 with ParseException

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());
    }
}
Also used : ASTSpeciesPattern(org.vcell.model.bngl.ASTSpeciesPattern) BNGLParser(org.vcell.model.bngl.BNGLParser) StringReader(java.io.StringReader) ParseException(org.vcell.model.bngl.ParseException) ParticleSpeciesPattern(cbit.vcell.math.ParticleSpeciesPattern) ASTSpeciesPattern(org.vcell.model.bngl.ASTSpeciesPattern)

Example 9 with ParseException

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());
        }
    }
}
Also used : ParseException(org.vcell.model.bngl.ParseException) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

ParseException (org.vcell.model.bngl.ParseException)9 BNGSpecies (cbit.vcell.bionetgen.BNGSpecies)4 ModelException (cbit.vcell.model.ModelException)4 Species (cbit.vcell.model.Species)4 SpeciesContext (cbit.vcell.model.SpeciesContext)4 Structure (cbit.vcell.model.Structure)4 PropertyVetoException (java.beans.PropertyVetoException)4 ArrayList (java.util.ArrayList)4 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)4 Model (cbit.vcell.model.Model)3 StringReader (java.io.StringReader)3 List (java.util.List)3 BNGLParser (org.vcell.model.bngl.BNGLParser)3 MolecularType (org.vcell.model.rbm.MolecularType)3 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)2 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)2 ParticleSpeciesPattern (cbit.vcell.math.ParticleSpeciesPattern)2 ReactionRule (cbit.vcell.model.ReactionRule)2 Dimension (java.awt.Dimension)2 Point (java.awt.Point)2