Search in sources :

Example 16 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class RbmNetworkGenerator method generateModel.

public static void generateModel(BioModel bioModel, String netfile) throws Exception {
    Model model = bioModel.getModel();
    Map<String, SpeciesContext> speciesMap = new HashMap<String, SpeciesContext>();
    Map<String, ReactionStep> reactionMap = new HashMap<String, ReactionStep>();
    List<ReactionLine> reactionLineList = new ArrayList<ReactionLine>();
    BufferedReader br = new BufferedReader(new StringReader(netfile));
    int reversibleCount = 0;
    int reactionCount = 0;
    while (true) {
        String line = br.readLine();
        if (line == null) {
            break;
        }
        line = line.trim();
        if (line.equals(BEGIN_PARAMETERS)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_PARAMETERS)) {
                    break;
                }
                StringTokenizer st = new StringTokenizer(line2);
                String token1 = st.nextToken();
                String token2 = st.nextToken();
                String token3 = st.nextToken();
                ModelParameter mp = model.new ModelParameter(token2, new Expression(token3), Model.ROLE_UserDefined, bioModel.getModel().getUnitSystem().getInstance_TBD());
                model.addModelParameter(mp);
            }
        } else if (line.equals(BEGIN_SPECIES)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_SPECIES)) {
                    break;
                }
                StringTokenizer st = new StringTokenizer(line2);
                // no
                String token1 = st.nextToken();
                // pattern
                String token2 = st.nextToken();
                // initial condition
                String token3 = st.nextToken();
                String newname = token2.replaceAll("\\.", "_");
                newname = newname.replaceAll("[\\(,][a-zA-Z]\\w*", "");
                newname = newname.replaceAll("~|!\\d*", "");
                newname = newname.replaceAll("\\(\\)", "");
                newname = newname.replaceAll("\\)", "");
                SpeciesContext sc = model.createSpeciesContext(model.getStructure(0));
                sc.setName(newname);
                bioModel.getVCMetaData().setFreeTextAnnotation(sc, token2);
                bioModel.getVCMetaData().setFreeTextAnnotation(sc.getSpecies(), token2);
                speciesMap.put(token1, sc);
            }
        } else if (line.equals(BEGIN_REACTIONS)) {
            while (true) {
                String line2 = br.readLine();
                line2 = line2.trim();
                if (line2.length() == 0) {
                    continue;
                }
                if (line2.equals(END_REACTIONS)) {
                    break;
                }
                ++reactionCount;
                StringTokenizer st = new StringTokenizer(line2);
                String token1 = st.nextToken();
                // reactants
                String token2 = st.nextToken();
                // products
                String token3 = st.nextToken();
                // rate
                String token4 = st.nextToken();
                String token5 = st.nextToken();
                boolean bFoundReversible = false;
                Expression rate = new Expression(token4);
                for (ReactionLine rl : reactionLineList) {
                    if (token2.equals(rl.products) && token3.equals(rl.reactants) && token5.equals(rl.ruleLabel + "r")) {
                        ReactionStep rs = reactionMap.get(rl.no);
                        ((MassActionKinetics) rs.getKinetics()).getReverseRateParameter().setExpression(rate);
                        reactionLineList.remove(rl);
                        bFoundReversible = true;
                        break;
                    }
                }
                if (bFoundReversible) {
                    ++reversibleCount;
                    continue;
                }
                ReactionLine rl = new ReactionLine(token1, token2, token3, token5);
                reactionLineList.add(rl);
                SimpleReaction reaction = model.createSimpleReaction(model.getStructure(0));
                reactionMap.put(token1, reaction);
                reaction.setModel(model);
                bioModel.getVCMetaData().setFreeTextAnnotation(reaction, line2);
                MassActionKinetics kinetics = new MassActionKinetics(reaction);
                reaction.setKinetics(kinetics);
                st = new StringTokenizer(token2, ",");
                while (st.hasMoreTokens()) {
                    String t = st.nextToken();
                    SpeciesContext sc = speciesMap.get(t);
                    if (sc != null) {
                        boolean bExists = false;
                        for (ReactionParticipant rp : reaction.getReactionParticipants()) {
                            if (rp instanceof Reactant && rp.getSpeciesContext() == sc) {
                                rp.setStoichiometry(rp.getStoichiometry() + 1);
                                bExists = true;
                                break;
                            }
                        }
                        if (!bExists) {
                            reaction.addReactant(sc, 1);
                        }
                    }
                }
                st = new StringTokenizer(token3, ",");
                while (st.hasMoreTokens()) {
                    String t = st.nextToken();
                    SpeciesContext sc = speciesMap.get(t);
                    if (sc != null) {
                        boolean bExists = false;
                        for (ReactionParticipant rp : reaction.getReactionParticipants()) {
                            if (rp instanceof Product && rp.getSpeciesContext() == sc) {
                                rp.setStoichiometry(rp.getStoichiometry() + 1);
                                bExists = true;
                                break;
                            }
                        }
                        if (!bExists) {
                            reaction.addProduct(sc, 1);
                        }
                    }
                }
                kinetics.getForwardRateParameter().setExpression(rate);
            }
        }
    }
    System.out.println(model.getNumSpecies() + " species added");
    System.out.println(model.getNumReactions() + " reactions added");
    System.out.println(reversibleCount + " reversible reactions found");
    if (reactionCount != model.getNumReactions() + reversibleCount) {
        throw new RuntimeException("Reactions are not imported correctly!");
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(cbit.vcell.model.Product) SpeciesContext(cbit.vcell.model.SpeciesContext) Reactant(cbit.vcell.model.Reactant) ModelParameter(cbit.vcell.model.Model.ModelParameter) StringTokenizer(java.util.StringTokenizer) Expression(cbit.vcell.parser.Expression) ReactionStep(cbit.vcell.model.ReactionStep) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) MassActionKinetics(cbit.vcell.model.MassActionKinetics) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Example 17 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class BioModelEditorRightSideTableModel method bioModelChange.

protected void bioModelChange(java.beans.PropertyChangeEvent evt) {
    BioModel oldValue = (BioModel) evt.getOldValue();
    if (oldValue != null) {
        oldValue.removePropertyChangeListener(this);
        oldValue.getModel().removePropertyChangeListener(this);
    }
    BioModel newValue = (BioModel) evt.getNewValue();
    refreshData();
    if (newValue != null) {
        newValue.addPropertyChangeListener(this);
        newValue.getModel().addPropertyChangeListener(this);
    }
}
Also used : BioModel(cbit.vcell.biomodel.BioModel)

Example 18 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class BioModelEditorStructureTableModel method bioModelChange.

@Override
protected void bioModelChange(PropertyChangeEvent evt) {
    super.bioModelChange(evt);
    BioModel oldValue = (BioModel) evt.getOldValue();
    if (oldValue != null) {
        for (Structure s : oldValue.getModel().getStructures()) {
            s.removePropertyChangeListener(this);
        }
    }
    BioModel newValue = (BioModel) evt.getNewValue();
    if (newValue != null) {
        for (Structure s : newValue.getModel().getStructures()) {
            s.addPropertyChangeListener(this);
        }
    }
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) Structure(cbit.vcell.model.Structure)

Example 19 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class BioModelParametersPanel method changeUnitsButtonPressed.

public void changeUnitsButtonPressed() {
    UnitSystemSelectionPanel unitSystemSelectionPanel = new UnitSystemSelectionPanel();
    unitSystemSelectionPanel.initialize(bioModel.getModel().getUnitSystem());
    int retcode = DialogUtils.showComponentOKCancelDialog(this, unitSystemSelectionPanel, "select new unit system");
    while (retcode == JOptionPane.OK_OPTION) {
        ModelUnitSystem forcedModelUnitSystem;
        try {
            forcedModelUnitSystem = unitSystemSelectionPanel.createModelUnitSystem();
            BioModel newBioModel = ModelUnitConverter.createBioModelWithNewUnitSystem(bioModel, forcedModelUnitSystem);
            this.bioModelWindowManager.resetDocument(newBioModel);
            break;
        } catch (Exception e) {
            e.printStackTrace(System.out);
            DialogUtils.showErrorDialog(this, e.getMessage(), e);
            retcode = DialogUtils.showComponentOKCancelDialog(this, unitSystemSelectionPanel, "select new unit system");
        }
    }
}
Also used : BioModel(cbit.vcell.biomodel.BioModel) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 20 with BioModel

use of cbit.vcell.biomodel.BioModel in project vcell by virtualcell.

the class DocumentEditor method treeSelectionChanged0.

private void treeSelectionChanged0(TreeSelectionEvent treeSelectionEvent) {
    try {
        treeSelectionChanged();
        Object selectedNode = documentEditorTree.getLastSelectedPathComponent();
        if (selectedNode != null && (selectedNode instanceof BioModelNode)) {
            Object selectedObject = ((BioModelNode) selectedNode).getUserObject();
            DocumentEditorTreeFolderClass folderClass = null;
            if (selectedObject instanceof DocumentEditorTreeFolderNode) {
                folderClass = ((DocumentEditorTreeFolderNode) selectedObject).getFolderClass();
            }
            ActiveView activeView = new ActiveView(getSelectedSimulationContext(), folderClass, null);
            selectionManager.setActiveView(activeView);
            if (/*selectedObject instanceof SimulationContext 
					|| */
            selectedObject instanceof BioModel || selectedObject instanceof MathModel) {
                selectionManager.setSelectedObjects(new Object[] { selectedObject });
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    }
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) BioModel(cbit.vcell.biomodel.BioModel) DocumentEditorTreeFolderNode(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderNode) BioModelNode(cbit.vcell.desktop.BioModelNode) DocumentEditorTreeFolderClass(cbit.vcell.client.desktop.biomodel.DocumentEditorTreeModel.DocumentEditorTreeFolderClass) ActiveView(cbit.vcell.client.desktop.biomodel.SelectionManager.ActiveView)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)158 SimulationContext (cbit.vcell.mapping.SimulationContext)72 Simulation (cbit.vcell.solver.Simulation)53 XMLSource (cbit.vcell.xml.XMLSource)37 KeyValue (org.vcell.util.document.KeyValue)36 MathModel (cbit.vcell.mathmodel.MathModel)33 DataAccessException (org.vcell.util.DataAccessException)29 XmlParseException (cbit.vcell.xml.XmlParseException)28 File (java.io.File)28 Model (cbit.vcell.model.Model)27 BioModelInfo (org.vcell.util.document.BioModelInfo)25 MathDescription (cbit.vcell.math.MathDescription)24 IOException (java.io.IOException)24 BigString (org.vcell.util.BigString)22 Geometry (cbit.vcell.geometry.Geometry)21 UserCancelException (org.vcell.util.UserCancelException)20 User (org.vcell.util.document.User)20 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)19 SpeciesContext (cbit.vcell.model.SpeciesContext)17 VCDocument (org.vcell.util.document.VCDocument)16