Search in sources :

Example 16 with ModelException

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;
        }
    }
}
Also used : ReactionRule(cbit.vcell.model.ReactionRule) ModelException(cbit.vcell.model.ModelException) ProductPattern(cbit.vcell.model.ProductPattern) SimulationContext(cbit.vcell.mapping.SimulationContext) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) Structure(cbit.vcell.model.Structure) ReactantPattern(cbit.vcell.model.ReactantPattern)

Example 17 with ModelException

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;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelException(cbit.vcell.model.ModelException) AutoCompleteTableModel(org.vcell.util.gui.AutoCompleteTableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) Model(cbit.vcell.model.Model)

Example 18 with ModelException

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;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelException(cbit.vcell.model.ModelException) AutoCompleteTableModel(org.vcell.util.gui.AutoCompleteTableModel) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) Model(cbit.vcell.model.Model)

Example 19 with ModelException

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();
    }
}
Also used : ModelException(cbit.vcell.model.ModelException) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) List(java.util.List) ParseException(org.vcell.model.bngl.ParseException) Structure(cbit.vcell.model.Structure) Species(cbit.vcell.model.Species) BNGSpecies(cbit.vcell.bionetgen.BNGSpecies)

Example 20 with ModelException

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;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ModelException(cbit.vcell.model.ModelException) VCellSortTableModel(cbit.vcell.client.desktop.biomodel.VCellSortTableModel) AutoCompleteTableModel(org.vcell.util.gui.AutoCompleteTableModel) Model(cbit.vcell.model.Model)

Aggregations

ModelException (cbit.vcell.model.ModelException)27 PropertyVetoException (java.beans.PropertyVetoException)25 Model (cbit.vcell.model.Model)14 Structure (cbit.vcell.model.Structure)12 ExpressionException (cbit.vcell.parser.ExpressionException)12 SpeciesContext (cbit.vcell.model.SpeciesContext)9 SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)9 MappingException (cbit.vcell.mapping.MappingException)8 VCellSortTableModel (cbit.vcell.client.desktop.biomodel.VCellSortTableModel)7 SimulationContext (cbit.vcell.mapping.SimulationContext)7 MathDescription (cbit.vcell.math.MathDescription)7 Expression (cbit.vcell.parser.Expression)7 ArrayList (java.util.ArrayList)7 Vector (java.util.Vector)7 MolecularType (org.vcell.model.rbm.MolecularType)7 BioModel (cbit.vcell.biomodel.BioModel)6 MathException (cbit.vcell.math.MathException)6 MatrixException (cbit.vcell.matrix.MatrixException)5 ModelParameter (cbit.vcell.model.Model.ModelParameter)5 ReactionStep (cbit.vcell.model.ReactionStep)5