Search in sources :

Example 6 with NetworkConstraints

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

the class SimContextTable method readAppComponents.

/**
 * readAppComponents : reads the additional simContext components like bioevents/application related flags (for stochastic, at the moment), if present, and sets them on simContext.
 * @param con
 * @param simContext
 * @return
 * @throws SQLException
 * @throws DataAccessException
 * @throws PropertyVetoException
 */
public void readAppComponents(Connection con, SimulationContext simContext, DatabaseSyntax dbSyntax) throws SQLException, DataAccessException, PropertyVetoException {
    try {
        Element appComponentsElement = getAppComponentsElement(con, simContext.getVersion().getVersionKey(), dbSyntax);
        if (appComponentsElement != null) {
            Element appRelatedFlags = appComponentsElement.getChild(XMLTags.ApplicationSpecificFlagsTag);
            if (appRelatedFlags != null) {
                // for now, only reading the 'randomizeInitCondition' attribute, since 'isStoch' and 'isUsingconcentration' are read in by other means; so not messing with those fields of simContext.
                boolean bRandomizeInitCondition = false;
                if ((appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag) != null) && (appRelatedFlags.getAttributeValue(XMLTags.RandomizeInitConditionTag).equals("true"))) {
                    bRandomizeInitCondition = true;
                }
                simContext.setRandomizeInitConditions(bRandomizeInitCondition);
            }
            if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientIterationsTag).equals("true"))) {
                simContext.setInsufficientIterations(true);
            } else {
                simContext.setInsufficientIterations(false);
            }
            if ((appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag) != null) && (appComponentsElement.getAttributeValue(XMLTags.InsufficientMaxMoleculesTag).equals("true"))) {
                simContext.setInsufficientMaxMolecules(true);
            } else {
                simContext.setInsufficientMaxMolecules(false);
            }
            XmlReader xmlReader = new XmlReader(false);
            NetworkConstraints nc = null;
            Element ncElement = appComponentsElement.getChild(XMLTags.RbmNetworkConstraintsTag);
            if (ncElement != null) {
                // one network constraint element
                nc = xmlReader.getAppNetworkConstraints(ncElement, simContext.getModel());
            }
            simContext.setNetworkConstraints(nc);
            // get spatial objects
            Element spatialObjectsElement = appComponentsElement.getChild(XMLTags.SpatialObjectsTag);
            if (spatialObjectsElement != null) {
                SpatialObject[] spatialObjects = xmlReader.getSpatialObjects(simContext, spatialObjectsElement);
                simContext.setSpatialObjects(spatialObjects);
            }
            // get application parameters
            Element appParamsElement = appComponentsElement.getChild(XMLTags.ApplicationParametersTag);
            if (appParamsElement != null) {
                SimulationContextParameter[] appParams = xmlReader.getSimulationContextParams(appParamsElement, simContext);
                simContext.setSimulationContextParameters(appParams);
            }
            // get bioEvents
            Element bioEventsElement = appComponentsElement.getChild(XMLTags.BioEventsTag);
            if (bioEventsElement != null) {
                BioEvent[] bioEvents = xmlReader.getBioEvents(simContext, bioEventsElement);
                simContext.setBioEvents(bioEvents);
            }
            // get spatial processes
            Element spatialProcessesElement = appComponentsElement.getChild(XMLTags.SpatialProcessesTag);
            if (spatialProcessesElement != null) {
                SpatialProcess[] spatialProcesses = xmlReader.getSpatialProcesses(simContext, spatialProcessesElement);
                simContext.setSpatialProcesses(spatialProcesses);
            }
            // get microscope measurements
            Element element = appComponentsElement.getChild(XMLTags.MicroscopeMeasurement);
            if (element != null) {
                xmlReader.getMicroscopeMeasurement(element, simContext);
            }
            // get rate rules
            Element rateRulesElement = appComponentsElement.getChild(XMLTags.RateRulesTag);
            if (rateRulesElement != null) {
                RateRule[] rateRules = xmlReader.getRateRules(simContext, rateRulesElement);
                simContext.setRateRules(rateRules);
            }
            // get reaction rule specs
            Element reactionRuleSpecsElement = appComponentsElement.getChild(XMLTags.ReactionRuleSpecsTag);
            if (reactionRuleSpecsElement != null) {
                ReactionRuleSpec[] reactionRuleSpecs = xmlReader.getReactionRuleSpecs(simContext, reactionRuleSpecsElement);
                simContext.getReactionContext().setReactionRuleSpecs(reactionRuleSpecs);
            }
        }
    } catch (XmlParseException e) {
        e.printStackTrace(System.out);
        throw new DataAccessException("Error retrieving bioevents : " + e.getMessage());
    }
}
Also used : ReactionRuleSpec(cbit.vcell.mapping.ReactionRuleSpec) Element(org.jdom.Element) XmlReader(cbit.vcell.xml.XmlReader) XmlParseException(cbit.vcell.xml.XmlParseException) SimulationContextParameter(cbit.vcell.mapping.SimulationContext.SimulationContextParameter) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) RateRule(cbit.vcell.mapping.RateRule) BioEvent(cbit.vcell.mapping.BioEvent) DataAccessException(org.vcell.util.DataAccessException) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 7 with NetworkConstraints

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

the class NetworkConstraintsTableModel method setValueAt.

@Override
public void setValueAt(Object value, int row, int column) {
    if (simContext == null || value == null) {
        return;
    }
    String text = (String) value;
    if (text == null || text.trim().length() == 0) {
        return;
    }
    NetworkConstraints networkConstraints = simContext.getNetworkConstraints();
    if (row == 0) {
        networkConstraints.setMaxIteration(Integer.valueOf(text));
    } else if (row == 1) {
        networkConstraints.setMaxMoleculesPerSpecies(Integer.valueOf(text));
    }
    // remove the combo from map if stoichiometry for that molecular type goes back to trivial
    return;
}
Also used : NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 8 with NetworkConstraints

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

the class EditConstraintsPanel method initialize.

private void initialize() {
    try {
        setName("EditConstraintsPanel");
        setLayout(new GridBagLayout());
        maxIterationTextField = new JTextField();
        maxMolTextField = new JTextField();
        maxIterationTextField.addActionListener(eventHandler);
        maxMolTextField.addActionListener(eventHandler);
        maxIterationTextField.addFocusListener(eventHandler);
        maxMolTextField.addFocusListener(eventHandler);
        maxIterationTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void changedUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void removeUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void insertUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public boolean isChanged() {
                NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
                String s1 = maxIterationTextField.getText();
                String s2 = nc.getMaxIteration() + "";
                if (!s1.equals(s2)) {
                    return true;
                }
                return false;
            }
        });
        maxMolTextField.getDocument().addDocumentListener(new DocumentListener() {

            public void changedUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void removeUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public void insertUpdate(DocumentEvent e) {
                if (isChanged()) {
                    getApplyButton().setEnabled(true);
                } else {
                    getApplyButton().setEnabled(false);
                }
            }

            public boolean isChanged() {
                NetworkConstraints nc = owner.getSimulationContext().getNetworkConstraints();
                String s1 = maxMolTextField.getText();
                String s2 = nc.getMaxMoleculesPerSpecies() + "";
                if (!s1.equals(s2)) {
                    return true;
                }
                return false;
            }
        });
        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(0, 8, 6, 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(0, 0, 6, 10);
        add(maxMolTextField, gbc);
        gridy++;
        gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(6, 8, 8, 2);
        add(getRunButton(), gbc);
        gbc = new GridBagConstraints();
        gbc.gridx = 1;
        gbc.gridy = gridy;
        gbc.weightx = 1.0;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(6, 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);
        maxIterationTextField.setText(owner.getSimulationContext().getNetworkConstraints().getMaxIteration() + "");
        maxMolTextField.setText(owner.getSimulationContext().getNetworkConstraints().getMaxMoleculesPerSpecies() + "");
        getApplyButton().setEnabled(false);
    } catch (java.lang.Throwable ivjExc) {
        handleException(ivjExc);
    }
}
Also used : DocumentListener(javax.swing.event.DocumentListener) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) DocumentEvent(javax.swing.event.DocumentEvent) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 9 with NetworkConstraints

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

the class XmlReader method getRbmNetworkConstraints.

private void getRbmNetworkConstraints(Element e, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    NetworkConstraints nc = new NetworkConstraints();
    this.legacyNetworkConstraints = nc;
    String s = e.getAttributeValue(XMLTags.RbmMaxIterationTag);
    if (s != null && !s.isEmpty()) {
        int maxIteration = Integer.parseInt(s);
        nc.setMaxIteration(maxIteration);
    }
    s = e.getAttributeValue(XMLTags.RbmMaxMoleculesPerSpeciesTag);
    if (s != null && !s.isEmpty()) {
        int maxMoleculesPerSpecies = Integer.parseInt(s);
        nc.setMaxMoleculesPerSpecies(maxMoleculesPerSpecies);
    }
    List<Element> children = e.getChildren(XMLTags.RbmMaxStoichiometryTag, vcNamespace);
    for (Element element : children) {
        Integer i = 1;
        MolecularType mt = null;
        s = element.getAttributeValue(XMLTags.RbmIntegerAttrTag);
        if (s != null && !s.isEmpty()) {
            i = Integer.getInteger(s);
        }
        s = element.getAttributeValue(XMLTags.RbmMolecularTypeTag);
        if (s != null && !s.isEmpty()) {
            mt = mc.getMolecularType(s);
        }
        if (mt != null) {
            nc.setMaxStoichiometry(mt, i);
        }
    }
}
Also used : ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Element(org.jdom.Element) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Example 10 with NetworkConstraints

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

the class XmlReader method getAppNetworkConstraints.

// public because it's being called in simcontexttable to read from the app components element
public NetworkConstraints getAppNetworkConstraints(Element e, Model newModel) {
    RbmModelContainer mc = newModel.getRbmModelContainer();
    NetworkConstraints nc = new NetworkConstraints();
    String s = e.getAttributeValue(XMLTags.RbmMaxIterationTag);
    if (s != null && !s.isEmpty()) {
        int maxIteration = Integer.parseInt(s);
        nc.setMaxIteration(maxIteration);
    }
    s = e.getAttributeValue(XMLTags.RbmMaxMoleculesPerSpeciesTag);
    if (s != null && !s.isEmpty()) {
        int maxMoleculesPerSpecies = Integer.parseInt(s);
        nc.setMaxMoleculesPerSpecies(maxMoleculesPerSpecies);
    }
    List<Element> children = e.getChildren(XMLTags.RbmMaxStoichiometryTag, vcNamespace);
    for (Element element : children) {
        Integer i = 1;
        MolecularType mt = null;
        s = element.getAttributeValue(XMLTags.RbmIntegerAttrTag);
        if (s != null && !s.isEmpty()) {
            i = Integer.getInteger(s);
        }
        s = element.getAttributeValue(XMLTags.RbmMolecularTypeTag);
        if (s != null && !s.isEmpty()) {
            mt = mc.getMolecularType(s);
        }
        if (mt != null) {
            nc.setMaxStoichiometry(mt, i);
        }
    }
    return nc;
}
Also used : ParticleMolecularType(cbit.vcell.math.ParticleMolecularType) MolecularType(org.vcell.model.rbm.MolecularType) RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) Element(org.jdom.Element) NetworkConstraints(org.vcell.model.rbm.NetworkConstraints)

Aggregations

NetworkConstraints (org.vcell.model.rbm.NetworkConstraints)14 Element (org.jdom.Element)6 BioEvent (cbit.vcell.mapping.BioEvent)5 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)5 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)5 RateRule (cbit.vcell.mapping.RateRule)4 SimulationContext (cbit.vcell.mapping.SimulationContext)4 SimulationContextParameter (cbit.vcell.mapping.SimulationContext.SimulationContextParameter)4 ReactionRuleSpec (cbit.vcell.mapping.ReactionRuleSpec)3 RbmModelContainer (cbit.vcell.model.Model.RbmModelContainer)3 MolecularType (org.vcell.model.rbm.MolecularType)3 Geometry (cbit.vcell.geometry.Geometry)2 StructureMapping (cbit.vcell.mapping.StructureMapping)2 MathDescription (cbit.vcell.math.MathDescription)2 ParticleMolecularType (cbit.vcell.math.ParticleMolecularType)2 Model (cbit.vcell.model.Model)2 RbmObservable (cbit.vcell.model.RbmObservable)2 ReactionRule (cbit.vcell.model.ReactionRule)2 Structure (cbit.vcell.model.Structure)2 AnalysisTask (cbit.vcell.modelopt.AnalysisTask)2