Search in sources :

Example 1 with NetworkConstraints

use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.

the class ValidateConstraintsPanel method initialize.

private void initialize() {
    try {
        setName("ValidateConstraintsPanel");
        setLayout(new GridBagLayout());
        maxIterationTextField = new JLabel();
        maxMolTextField = new JLabel();
        speciesLimitTextField = new JLabel();
        reactionsLimitTextField = new JLabel();
        somethingInsufficientLabel = new JLabel();
        NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
        maxIterationTextField.setText(nc.getTestMaxIteration() + "");
        maxMolTextField.setText(nc.getTestMaxMoleculesPerSpecies() + "");
        speciesLimitTextField.setText(nc.getTestSpeciesLimit() + "");
        reactionsLimitTextField.setText(nc.getTestReactionsLimit() + "");
        int gridy = 0;
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.fill = GridBagConstraints.BOTH;
        // top, left, bottom, right
        gbc.insets = new Insets(6, 8, 0, 0);
        add(new JLabel("Max. Iterations"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 10);
        add(maxIterationTextField, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 0, 0);
        add(new JLabel("Max. Molecules / Species"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 0);
        add(maxMolTextField, gbc);
        // ------------------------------------------------------
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 0, 0);
        add(new JLabel("Species Limit"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 0, 0);
        add(speciesLimitTextField, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        // gbc.weighty = 1.0;
        gbc.gridwidth = 8;
        gbc.fill = java.awt.GridBagConstraints.BOTH;
        gbc.insets = new Insets(6, 8, 4, 0);
        add(new JLabel("Reactions Limit"), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.anchor = GridBagConstraints.EAST;
        gbc.insets = new Insets(6, 0, 4, 0);
        add(reactionsLimitTextField, gbc);
        // ------------------------------------------------------
        if (showStoichiometryTable) {
            stoichiometryTable = new EditorScrollTable();
            stoichiometryTableModel = new StoichiometryTableModel(stoichiometryTable);
            stoichiometryTable.setModel(stoichiometryTableModel);
            stoichiometryTableModel.setSimulationContext(owner.getSimulationContext());
            stoichiometryTableModel.displayTestMaxStoichiometry();
            // we disable editing for the Value column
            stoichiometryTableModel.setValueEditable(false);
            JScrollPane sp = new JScrollPane(stoichiometryTable);
            sp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            gridy++;
            gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = gridy;
            gbc.weightx = gbc.weighty = 1.0;
            gbc.fill = GridBagConstraints.BOTH;
            gbc.anchor = GridBagConstraints.WEST;
            gbc.gridwidth = 4;
            gbc.insets = new Insets(5, 8, 4, 10);
            add(sp, gbc);
        }
        // -------------------------------------------------------
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.gridwidth = 4;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(2, 8, 4, 10);
        add(somethingInsufficientLabel, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(4, 2, 8, 2);
        add(getApplyButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 2;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(6, 2, 8, 10);
        add(getCancelButton(), gbc);
        String s = "none";
        TaskCallbackProcessor tcbp = owner.getSimulationContext().getTaskCallbackProcessor();
        if (tcbp.getPreviousIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() != tcbp.getPreviousIterationSpecies()) {
            s = "<font color=#8C001A>" + SimulationContext.IssueInsufficientIterations + "</font>";
        } else if (tcbp.getPreviousIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() > 0 && tcbp.getCurrentIterationSpecies() == tcbp.getPreviousIterationSpecies()) {
            if (tcbp.isNeedAdjustMaxMolecules()) {
                s = "<font color=#8C001A>" + SimulationContext.IssueInsufficientMolecules + "</font>";
            }
        }
        somethingInsufficientLabel.setText("<html>Warning:  " + s + "</html>");
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : JScrollPane(javax.swing.JScrollPane) StoichiometryTableModel(cbit.vcell.mapping.gui.StoichiometryTableModel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) TaskCallbackProcessor(cbit.vcell.mapping.TaskCallbackProcessor) JLabel(javax.swing.JLabel) EditorScrollTable(org.vcell.util.gui.EditorScrollTable) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 2 with NetworkConstraints

use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.

the class NetworkConstraintsTableModel method computeData.

protected ArrayList<NetworkConstraintsEntity> computeData() {
    ArrayList<NetworkConstraintsEntity> nceList = new ArrayList<NetworkConstraintsEntity>();
    Model model = simContext.getModel();
    RbmModelContainer rbmModelContainer = model.getRbmModelContainer();
    if (rbmModelContainer == null) {
        return nceList;
    }
    String s1, s2, s3, s4;
    NetworkConstraintsEntity nce;
    NetworkConstraints networkConstraints = simContext.getNetworkConstraints();
    if (networkConstraints != null) {
        s1 = networkConstraints.getMaxIteration() + "";
        s2 = networkConstraints.getMaxMoleculesPerSpecies() + "";
        s3 = networkConstraints.getSpeciesLimit() + "";
        s4 = networkConstraints.getReactionsLimit() + "";
    } else {
        s1 = "?";
        s2 = "?";
        s3 = "?";
        s4 = "?";
    }
    nce = new NetworkConstraintsEntity(sMaxIterationName, s1, NetworkTransformer.defaultMaxIteration + "");
    nceList.add(nce);
    nce = new NetworkConstraintsEntity(sMaxMoleculesName, s2, NetworkTransformer.defaultMaxMoleculesPerSpecies + "");
    nceList.add(nce);
    nce = new NetworkConstraintsEntity(sSpeciesLimitName, s3, NetworkTransformer.defaultSpeciesLimit + "");
    nceList.add(nce);
    nce = new NetworkConstraintsEntity(sReactionsLimitName, s4, NetworkTransformer.defaultReactionsLimit + "");
    nceList.add(nce);
    Map<MolecularType, Integer> stoichiometryMap = networkConstraints.getMaxStoichiometry(simContext);
    Iterator<Entry<MolecularType, Integer>> it = stoichiometryMap.entrySet().iterator();
    while (it.hasNext()) {
        // first clean any entry that doesn't exist anymore (should never happen!)
        MolecularType mt = it.next().getKey();
        if (rbmModelContainer.getMolecularType(mt.getName()) == null) {
            it.remove();
        }
    }
    for (MolecularType mt : rbmModelContainer.getMolecularTypeList()) {
        // add any new molecule that's not already there, with the default max stoichiometry
        if (!stoichiometryMap.containsKey(mt)) {
            stoichiometryMap.put(mt, NetworkConstraints.defaultMaxStoichiometry);
        }
    }
    for (Map.Entry<MolecularType, Integer> entry : stoichiometryMap.entrySet()) {
        MolecularType mt = entry.getKey();
        Integer value = entry.getValue();
        nce = new NetworkConstraintsEntity("Max molecules " + mt.getDisplayName() + " / Species", value + "", NetworkConstraints.defaultMaxStoichiometry + "");
        nceList.add(nce);
    }
    return nceList;
}
Also used : ArrayList(java.util.ArrayList) NetworkConstraintsEntity(org.vcell.model.rbm.common.NetworkConstraintsEntity) MolecularType(org.vcell.model.rbm.MolecularType) Entry(java.util.Map.Entry) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) BioModelEditorRightSideTableModel(cbit.vcell.client.desktop.biomodel.BioModelEditorRightSideTableModel) Model(cbit.vcell.model.Model) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 3 with NetworkConstraints

use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.

the class NetworkConstraintsTableModel method getValueAt.

@Override
public Object getValueAt(int row, int column) {
    if (simContext == null) {
        return null;
    }
    NetworkConstraintsEntity nce = getValueAt(row);
    String colName = nce.getName();
    String colValue = nce.getValue();
    String colDefault = nce.getDefaultValue();
    NetworkConstraints networkConstraints = simContext.getNetworkConstraints();
    if (row == 0) {
        colValue = networkConstraints.getMaxIteration() + "";
    } else if (row == 1) {
        colValue = networkConstraints.getMaxMoleculesPerSpecies() + "";
    } else if (row == 2) {
        colValue = networkConstraints.getSpeciesLimit() + "";
    } else if (row == 3) {
        colValue = networkConstraints.getReactionsLimit() + "";
    }
    if (nce != null) {
        switch(column) {
            case iColName:
                return colName;
            case iColValue:
                return colValue;
            case iColDefault:
                return colDefault;
        }
    }
    return null;
}
Also used : NetworkConstraintsEntity(org.vcell.model.rbm.common.NetworkConstraintsEntity) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 4 with NetworkConstraints

use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.

the class StoichiometryTableModel method displayTestMaxStoichiometry.

public void displayTestMaxStoichiometry() {
    ArrayList<MaxStoichiometryEntity> nceList = new ArrayList<MaxStoichiometryEntity>();
    Model model = simContext.getModel();
    RbmModelContainer rbmModelContainer = model.getRbmModelContainer();
    if (rbmModelContainer == null) {
        setData(nceList);
        return;
    }
    NetworkConstraints networkConstraints = simContext.getNetworkConstraints();
    Map<MolecularType, Integer> smTest = networkConstraints.getTestMaxStoichiometry(simContext);
    Map<MolecularType, Integer> smOld = networkConstraints.getMaxStoichiometry(simContext);
    for (Map.Entry<MolecularType, Integer> entry : smTest.entrySet()) {
        MolecularType mt = entry.getKey();
        Integer valueTest = entry.getValue();
        Integer valueOld = smOld.get(mt);
        MaxStoichiometryEntity nce = new MaxStoichiometryEntity(mt, valueTest);
        if (valueTest != valueOld) {
            // not in use
            nce.setChanged(true);
        }
        nceList.add(nce);
    }
    setData(nceList);
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) MaxStoichiometryEntity(org.vcell.model.rbm.common.MaxStoichiometryEntity) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) ArrayList(java.util.ArrayList) BioModelEditorRightSideTableModel(cbit.vcell.client.desktop.biomodel.BioModelEditorRightSideTableModel) Model(cbit.vcell.model.Model) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 5 with NetworkConstraints

use of org.vcell.model.rbm.NetworkConstraints in project vcell by virtualcell.

the class BNGExecutorServiceMultipass method preprocessInput.

// parse the compartmental bngl file and produce the "trick"
// where each molecule has an extra Site with the compartments as possible States
// a reserved name will be used for this Site
// 
private String preprocessInput(String cBngInputString) throws ParseException, PropertyVetoException, ExpressionBindingException {
    // take the cBNGL file (as string), parse it to recover the rules (we'll need them later)
    // and create the bngl string with the extra, fake site for the compartments
    BioModel bioModel = new BioModel(null);
    bioModel.setName("BngBioModel");
    model = new Model("model");
    bioModel.setModel(model);
    model.createFeature();
    simContext = bioModel.addNewSimulationContext("BioNetGen app", SimulationContext.Application.NETWORK_DETERMINISTIC);
    List<SimulationContext> appList = new ArrayList<SimulationContext>();
    appList.add(simContext);
    // set convention for initial conditions in generated application for seed species (concentration or count)
    BngUnitSystem bngUnitSystem = new BngUnitSystem(BngUnitOrigin.DEFAULT);
    InputStream is = new ByteArrayInputStream(cBngInputString.getBytes());
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    ASTModel astModel = RbmUtils.importBnglFile(br);
    if (astModel.hasCompartments()) {
        Structure struct = model.getStructure(0);
        if (struct != null) {
            try {
                model.removeStructure(struct);
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            }
        }
    }
    BnglObjectConstructionVisitor constructionVisitor = null;
    constructionVisitor = new BnglObjectConstructionVisitor(model, appList, bngUnitSystem, true);
    astModel.jjtAccept(constructionVisitor, model.getRbmModelContainer());
    int numCompartments = model.getStructures().length;
    if (numCompartments == 0) {
        throw new RuntimeException("No structure present in the bngl file.");
    } else if (numCompartments == 1) {
        // for single compartment we don't need the 'trick'
        compartmentMode = CompartmentMode.hide;
    } else {
        compartmentMode = CompartmentMode.asSite;
    }
    // extract all polymer observables for special treatment at the end
    for (RbmObservable oo : model.getRbmModelContainer().getObservableList()) {
        if (oo.getSequence() == RbmObservable.Sequence.PolymerLengthEqual) {
            polymerEqualObservables.add(oo);
        } else if (oo.getSequence() == RbmObservable.Sequence.PolymerLengthGreater) {
            polymerGreaterObservables.add(oo);
        }
    }
    for (RbmObservable oo : polymerEqualObservables) {
        model.getRbmModelContainer().removeObservable(oo);
    }
    for (RbmObservable oo : polymerGreaterObservables) {
        model.getRbmModelContainer().removeObservable(oo);
    }
    // replace all reversible rules with 2 direct rules
    List<ReactionRule> newRRList = new ArrayList<>();
    for (ReactionRule rr : model.getRbmModelContainer().getReactionRuleList()) {
        if (rr.isReversible()) {
            ReactionRule rr1 = ReactionRule.deriveDirectRule(rr);
            newRRList.add(rr1);
            ReactionRule rr2 = ReactionRule.deriveInverseRule(rr);
            newRRList.add(rr2);
        } else {
            newRRList.add(rr);
        }
        model.getRbmModelContainer().removeReactionRule(rr);
    }
    // model.getRbmModelContainer().getReactionRuleList().clear();
    model.getRbmModelContainer().setReactionRules(newRRList);
    StringWriter bnglStringWriter = new StringWriter();
    PrintWriter writer = new PrintWriter(bnglStringWriter);
    writer.println(RbmNetworkGenerator.BEGIN_MODEL);
    writer.println();
    // RbmNetworkGenerator.writeCompartments(writer, model, null);
    RbmNetworkGenerator.writeParameters(writer, model.getRbmModelContainer(), false);
    RbmNetworkGenerator.writeMolecularTypes(writer, model, compartmentMode);
    RbmNetworkGenerator.writeSpeciesSortedAlphabetically(writer, model, simContext, compartmentMode);
    RbmNetworkGenerator.writeObservables(writer, model.getRbmModelContainer(), compartmentMode);
    // RbmNetworkGenerator.writeFunctions(writer, rbmModelContainer, ignoreFunctions);
    RbmNetworkGenerator.writeReactions(writer, model.getRbmModelContainer(), null, false, compartmentMode);
    writer.println(RbmNetworkGenerator.END_MODEL);
    writer.println();
    // we parse the real numbers from the bngl file provided by the caller, the nc in the simContext has the default ones
    NetworkConstraints realNC = extractNetworkConstraints(cBngInputString);
    String maxStoichiometry = extractMaxStoichiometry(cBngInputString);
    simContext.getNetworkConstraints().setMaxMoleculesPerSpecies(realNC.getMaxMoleculesPerSpecies());
    simContext.getNetworkConstraints().setMaxIteration(realNC.getMaxIteration());
    ModelParameter speciesLimitParam = model.getModelParameter(NetworkConstraints.SPECIES_LIMIT_PARAMETER);
    if (speciesLimitParam != null) {
        // if it's not there we are already using the default
        String s = speciesLimitParam.getExpression().infix();
        // extract speciesLimit
        simContext.getNetworkConstraints().setSpeciesLimit((int) Float.parseFloat(s));
    }
    ModelParameter reactionsLimitParam = model.getModelParameter(NetworkConstraints.REACTIONS_LIMIT_PARAMETER);
    if (reactionsLimitParam != null) {
        String r = reactionsLimitParam.getExpression().infix();
        // extract reactionsLimit
        simContext.getNetworkConstraints().setReactionsLimit((int) Float.parseFloat(r));
    }
    simContext.getNetworkConstraints().setTestConstraints(simContext.getNetworkConstraints().getMaxIteration(), simContext.getNetworkConstraints().getMaxMoleculesPerSpecies(), simContext.getNetworkConstraints().getSpeciesLimit(), simContext.getNetworkConstraints().getReactionsLimit(), // we don't need a testMaxStoichiometryMap (I guess)
    null);
    // RbmNetworkGenerator.generateNetworkEx(1, simContext.getNetworkConstraints().getMaxMoleculesPerSpecies(), false, writer, model.getRbmModelContainer(), simContext, NetworkGenerationRequirements.AllowTruncatedStandardTimeout);
    generateNetworkLocal(1, simContext.getNetworkConstraints().getMaxMoleculesPerSpecies(), maxStoichiometry, writer);
    String sInputString = bnglStringWriter.toString();
    return sInputString;
}
Also used : InputStreamReader(java.io.InputStreamReader) ReactionRule(cbit.vcell.model.ReactionRule) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) ModelParameter(cbit.vcell.model.Model.ModelParameter) BngUnitSystem(org.vcell.model.bngl.BngUnitSystem) BnglObjectConstructionVisitor(org.vcell.model.rbm.RbmUtils.BnglObjectConstructionVisitor) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) BioModel(cbit.vcell.biomodel.BioModel) ASTModel(org.vcell.model.bngl.ASTModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) BufferedReader(java.io.BufferedReader) Structure(cbit.vcell.model.Structure) ASTModel(org.vcell.model.bngl.ASTModel) PrintWriter(java.io.PrintWriter) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Aggregations

NetworkConstraints (org.vcell.model.rbm.NetworkConstraints)19 MolecularType (org.vcell.model.rbm.MolecularType)7 Element (org.jdom.Element)6 AssignmentRule (cbit.vcell.mapping.AssignmentRule)5 BioEvent (cbit.vcell.mapping.BioEvent)5 RateRule (cbit.vcell.mapping.RateRule)5 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)5 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)5 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)5 SimulationContext (cbit.vcell.mapping.SimulationContext)4 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)4 Model (cbit.vcell.model.Model)4 BioModelEditorRightSideTableModel (cbit.vcell.client.desktop.biomodel.BioModelEditorRightSideTableModel)3 ReactionRuleSpec (cbit.vcell.mapping.ReactionRuleSpec)3 ArrayList (java.util.ArrayList)3 Geometry (cbit.vcell.geometry.Geometry)2 StructureMapping (cbit.vcell.mapping.StructureMapping)2 StoichiometryTableModel (cbit.vcell.mapping.gui.StoichiometryTableModel)2 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)2 AnalysisTask (cbit.vcell.modelopt.AnalysisTask)2