Search in sources :

Example 26 with Membrane

use of cbit.vcell.model.Membrane in project vcell by virtualcell.

the class TestingFrameworkWindowManager method addTestCases.

/**
 * Insert the method's description here.
 * Creation date: (4/10/2003 11:27:32 AM)
 * @param testCase cbit.vcell.numericstestingframework.TestCase
 */
public String addTestCases(final TestSuiteInfoNew tsInfo, final TestCaseNew[] testCaseArray, int regrRefFlag, ClientTaskStatusSupport pp) {
    if (tsInfo == null) {
        throw new IllegalArgumentException("TestSuiteInfo cannot be null");
    }
    if (testCaseArray == null || testCaseArray.length == 0) {
        throw new IllegalArgumentException("TestCases cannot be null / empty");
    }
    // make modifiable list
    List<TestCaseNew> testCases = new ArrayList<>(Arrays.asList(testCaseArray));
    StringBuffer errors = new StringBuffer();
    // When a testCase (mathmodel/biomodel) is added to a testSuite, a new version of the mathModel/biomodel should be created.
    // Also, the simulations in the original mathmodel/biomodel should be rid of their parent simulation reference.
    pp.setMessage("Getting testSuite");
    pp.setProgress(1);
    TestSuiteNew testSuite = null;
    try {
        testSuite = getRequestManager().getDocumentManager().getTestSuite(tsInfo.getTSKey());
    } catch (Throwable e) {
        throw new RuntimeException("couldn't get test suite " + tsInfo.getTSID() + "\n" + e.getClass().getName() + " mesg=" + e.getMessage() + "\n");
    }
    if (testSuite != null && testSuite.getTSInfoNew().isLocked()) {
        throw new RuntimeException("Cannot addTestCases to locked table");
    }
    if (testSuite != null) {
        // Saving BioModels
        TestCaseNew[] existingTestCases = testSuite.getTestCases();
        java.util.HashMap<KeyValue, BioModel> bioModelHashMap = new java.util.HashMap<KeyValue, BioModel>();
        // if(existingTestCases != null){
        // Find BioModels, Using the same BM reference for sibling Applications
        int pcounter = 0;
        // use iterator to allow removal of test case from collection if exception
        Iterator<TestCaseNew> iter = testCases.iterator();
        while (iter.hasNext()) {
            TestCaseNew testCase = iter.next();
            pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
            pp.setMessage("Checking " + testCase.getVersion().getName());
            try {
                if (testCase instanceof TestCaseNewBioModel) {
                    TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
                    // 
                    if (bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey()) == null) {
                        pp.setMessage("Getting BM " + testCase.getVersion().getName());
                        BioModel bioModel = getRequestManager().getDocumentManager().getBioModel(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
                        if (!bioModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
                            throw new Exception("BioModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
                        }
                        // 
                        // if biomodel already exists in same testsuite, then use this BioModel edition
                        // 
                        BioModel newBioModel = null;
                        if (existingTestCases != null) {
                            for (int j = 0; newBioModel == null && j < existingTestCases.length; j++) {
                                if (existingTestCases[j] instanceof TestCaseNewBioModel) {
                                    TestCaseNewBioModel existingTestCaseBioModel = (TestCaseNewBioModel) existingTestCases[j];
                                    // 
                                    if (existingTestCaseBioModel.getBioModelInfo().getVersion().getBranchID().equals(bioTestCase.getBioModelInfo().getVersion().getBranchID())) {
                                        // 
                                        if (existingTestCaseBioModel.getBioModelInfo().getVersion().getVersionKey().equals(bioTestCase.getBioModelInfo().getVersion().getVersionKey())) {
                                            // 
                                            // same, store this "unchanged" in bioModelHashMap
                                            // 
                                            newBioModel = bioModel;
                                        } else {
                                            // 
                                            throw new Exception("can't add new test case using (" + bioTestCase.getBioModelInfo().getVersion().getName() + " " + bioTestCase.getBioModelInfo().getVersion().getDate() + ")\n" + "a test case already exists with different edition of same BioModel dated " + existingTestCaseBioModel.getBioModelInfo().getVersion().getDate());
                                        }
                                    }
                                }
                            }
                        }
                        if (newBioModel == null) {
                            pp.setMessage("Saving BM " + testCase.getVersion().getName());
                            // 
                            // some older models have membrane voltage variable names which are not unique
                            // (e.g. membranes 'pm' and 'nm' both have membrane voltage variables named 'Voltage_Membrane0')
                            // 
                            // if this is the case, we will try to repair the conflict (for math testing purposes only) by renaming the voltage variables to their default values.
                            // 
                            // Ordinarily, the conflict will be identified as an "Error" issue and the user will be prompted to repair before saving or math generation.
                            // 
                            bioModel.refreshDependencies();
                            boolean bFoundIdentifierConflictUponLoading = hasDuplicateIdentifiers(bioModel);
                            if (bFoundIdentifierConflictUponLoading) {
                                // 
                                // look for two MembraneVoltage instances with same variable name, rename all
                                // 
                                HashSet<String> membraneVoltageVarNames = new HashSet<String>();
                                ArrayList<MembraneVoltage> membraneVoltageVars = new ArrayList<MembraneVoltage>();
                                for (Structure struct : bioModel.getModel().getStructures()) {
                                    if (struct instanceof Membrane) {
                                        MembraneVoltage membraneVoltage = ((Membrane) struct).getMembraneVoltage();
                                        if (membraneVoltage != null) {
                                            membraneVoltageVars.add(membraneVoltage);
                                            membraneVoltageVarNames.add(membraneVoltage.getName());
                                        }
                                    }
                                }
                                if (membraneVoltageVars.size() != membraneVoltageVarNames.size()) {
                                    // rename them all to the default names
                                    for (MembraneVoltage memVoltage : membraneVoltageVars) {
                                        memVoltage.setName(Membrane.getDefaultMembraneVoltageName(memVoltage.getMembrane().getName()));
                                    }
                                }
                            }
                            SimulationContext[] simContexts = bioModel.getSimulationContexts();
                            for (int j = 0; j < simContexts.length; j++) {
                                simContexts[j].clearVersion();
                                GeometrySurfaceDescription gsd = simContexts[j].getGeometry().getGeometrySurfaceDescription();
                                if (gsd != null) {
                                    GeometricRegion[] grArr = gsd.getGeometricRegions();
                                    if (grArr == null) {
                                        gsd.updateAll();
                                    }
                                }
                                MathMapping mathMapping = simContexts[j].createNewMathMapping();
                                // for older models that do not have absolute compartment sizes set, but have relative sizes (SVR/VF); or if there is only one compartment with size not set,
                                // compute absolute compartment sizes using relative sizes and assuming a default value of '1' for one of the compartments.
                                // Otherwise, the math generation will fail, since for the relaxed topology (VCell 5.3 and later) absolute compartment sizes are required.
                                GeometryContext gc = simContexts[j].getGeometryContext();
                                if (simContexts[j].getGeometry().getDimension() == 0 && ((gc.isAllSizeSpecifiedNull() && !gc.isAllVolFracAndSurfVolSpecifiedNull()) || (gc.getModel().getStructures().length == 1 && gc.isAllSizeSpecifiedNull()))) {
                                    // choose the first structure in model and set its size to '1'.
                                    Structure struct = simContexts[j].getModel().getStructure(0);
                                    double structSize = 1.0;
                                    StructureSizeSolver.updateAbsoluteStructureSizes(simContexts[j], struct, structSize, struct.getStructureSize().getUnitDefinition());
                                }
                                simContexts[j].setMathDescription(mathMapping.getMathDescription());
                            }
                            Simulation[] sims = bioModel.getSimulations();
                            String[] simNames = new String[sims.length];
                            for (int j = 0; j < sims.length; j++) {
                                // prevents parent simulation (from the original mathmodel) reference connection
                                // Otherwise it will refer to data from previous (parent) simulation.
                                sims[j].clearVersion();
                                simNames[j] = sims[j].getName();
                            // if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
                            // sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
                            // }
                            }
                            newBioModel = getRequestManager().getDocumentManager().save(bioModel, simNames);
                        }
                        bioModelHashMap.put(bioTestCase.getBioModelInfo().getVersion().getVersionKey(), newBioModel);
                    }
                }
            } catch (Throwable e) {
                String identifier = testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey();
                if (lg.isInfoEnabled()) {
                    lg.info(identifier, e);
                }
                errors.append("Error collecting BioModel for TestCase " + identifier + '\n' + e.getClass().getName() + " " + e.getMessage() + '\n');
                // remove to avoid further processing attempts
                iter.remove();
            }
        }
        // }
        // then process each BioModelTestCase individually
        // if(bioModelHashMap != null){
        pcounter = 0;
        for (TestCaseNew testCase : testCases) {
            pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
            pp.setMessage("Checking " + testCase.getVersion().getName());
            try {
                AddTestCasesOP testCaseOP = null;
                if (testCase instanceof TestCaseNewBioModel) {
                    pp.setMessage("Processing BM " + testCase.getVersion().getName());
                    TestCaseNewBioModel bioTestCase = (TestCaseNewBioModel) testCase;
                    BioModel newBioModel = (BioModel) bioModelHashMap.get(bioTestCase.getBioModelInfo().getVersion().getVersionKey());
                    if (newBioModel == null) {
                        throw new Exception("BioModel not found");
                    }
                    SimulationContext simContext = null;
                    for (int j = 0; j < newBioModel.getSimulationContexts().length; j++) {
                        if (newBioModel.getSimulationContext(j).getName().equals(bioTestCase.getSimContextName())) {
                            simContext = newBioModel.getSimulationContext(j);
                        }
                    }
                    Simulation[] newSimulations = simContext.getSimulations();
                    AddTestCriteriaOPBioModel[] testCriteriaOPs = new AddTestCriteriaOPBioModel[newSimulations.length];
                    for (int j = 0; j < newSimulations.length; j++) {
                        TestCriteriaNewBioModel tcritOrigForSimName = null;
                        for (int k = 0; bioTestCase.getTestCriterias() != null && k < bioTestCase.getTestCriterias().length; k += 1) {
                            if (bioTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
                                tcritOrigForSimName = (TestCriteriaNewBioModel) bioTestCase.getTestCriterias()[k];
                                break;
                            }
                        }
                        KeyValue regressionBioModelKey = null;
                        KeyValue regressionBioModelSimKey = null;
                        if (bioTestCase.getType().equals(TestCaseNew.REGRESSION)) {
                            if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
                                regressionBioModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionBioModelInfo() != null ? tcritOrigForSimName.getRegressionBioModelInfo().getVersion().getVersionKey() : null);
                                regressionBioModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
                            } else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
                                regressionBioModelKey = (tcritOrigForSimName != null ? bioTestCase.getBioModelInfo().getVersion().getVersionKey() : null);
                                regressionBioModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
                            } else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
                                regressionBioModelKey = newBioModel.getVersion().getVersionKey();
                                regressionBioModelSimKey = newSimulations[j].getVersion().getVersionKey();
                            } else {
                                throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) BIOMODEL Unknown Regression Operation Flag");
                            }
                        }
                        testCriteriaOPs[j] = new AddTestCriteriaOPBioModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionBioModelKey, regressionBioModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
                    }
                    testCaseOP = new AddTestCasesOPBioModel(new BigDecimal(tsInfo.getTSKey().toString()), newBioModel.getVersion().getVersionKey(), simContext.getKey(), bioTestCase.getType(), bioTestCase.getAnnotation(), testCriteriaOPs);
                    getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
                }
            } catch (Throwable e) {
                errors.append("Error processing Biomodel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
            }
        }
        // }
        // Process MathModels
        pcounter = 0;
        for (TestCaseNew testCase : testCases) {
            pp.setProgress(Math.max(1, ((int) ((pcounter++ / (double) (testCases.size() * 3)) * 100))));
            pp.setMessage("Checking " + testCase.getVersion().getName());
            try {
                AddTestCasesOP testCaseOP = null;
                if (testCase instanceof TestCaseNewMathModel) {
                    TestCaseNewMathModel mathTestCase = (TestCaseNewMathModel) testCase;
                    pp.setMessage("Getting MathModel " + testCase.getVersion().getName());
                    MathModel mathModel = getRequestManager().getDocumentManager().getMathModel(mathTestCase.getMathModelInfo().getVersion().getVersionKey());
                    if (!mathModel.getVersion().getOwner().equals(getRequestManager().getDocumentManager().getUser())) {
                        throw new Exception("MathModel does not belong to VCELLTESTACCOUNT, cannot proceed with test!");
                    }
                    Simulation[] sims = mathModel.getSimulations();
                    String[] simNames = new String[sims.length];
                    for (int j = 0; j < sims.length; j++) {
                        // prevents parent simulation (from the original mathmodel) reference connection
                        // Otherwise it will refer to data from previous (parent) simulation.
                        sims[j].clearVersion();
                        simNames[j] = sims[j].getName();
                    // if(sims[j].getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)){
                    // sims[j].getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
                    // }
                    }
                    pp.setMessage("Saving MathModel " + testCase.getVersion().getName());
                    MathModel newMathModel = getRequestManager().getDocumentManager().save(mathModel, simNames);
                    Simulation[] newSimulations = newMathModel.getSimulations();
                    AddTestCriteriaOPMathModel[] testCriteriaOPs = new AddTestCriteriaOPMathModel[newSimulations.length];
                    for (int j = 0; j < newSimulations.length; j++) {
                        TestCriteriaNewMathModel tcritOrigForSimName = null;
                        for (int k = 0; mathTestCase.getTestCriterias() != null && k < mathTestCase.getTestCriterias().length; k += 1) {
                            if (mathTestCase.getTestCriterias()[k].getSimInfo().getName().equals(newSimulations[j].getName())) {
                                tcritOrigForSimName = (TestCriteriaNewMathModel) mathTestCase.getTestCriterias()[k];
                                break;
                            }
                        }
                        KeyValue regressionMathModelKey = null;
                        KeyValue regressionMathModelSimKey = null;
                        if (mathTestCase.getType().equals(TestCaseNew.REGRESSION)) {
                            if (regrRefFlag == TestingFrameworkWindowManager.COPY_REGRREF) {
                                regressionMathModelKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionMathModelInfo() != null ? tcritOrigForSimName.getRegressionMathModelInfo().getVersion().getVersionKey() : null);
                                regressionMathModelSimKey = (tcritOrigForSimName != null && tcritOrigForSimName.getRegressionSimInfo() != null ? tcritOrigForSimName.getRegressionSimInfo().getVersion().getVersionKey() : null);
                            } else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNORIGINAL_REGRREF) {
                                regressionMathModelKey = (tcritOrigForSimName != null ? mathTestCase.getMathModelInfo().getVersion().getVersionKey() : null);
                                regressionMathModelSimKey = (tcritOrigForSimName != null ? tcritOrigForSimName.getSimInfo().getVersion().getVersionKey() : null);
                            } else if (regrRefFlag == TestingFrameworkWindowManager.ASSIGNNEW_REGRREF) {
                                regressionMathModelKey = newMathModel.getVersion().getVersionKey();
                                regressionMathModelSimKey = newSimulations[j].getVersion().getVersionKey();
                            } else {
                                throw new IllegalArgumentException(this.getClass().getName() + ".addTestCases(...) MATHMODEL Unknown Regression Operation Flag");
                            }
                        }
                        testCriteriaOPs[j] = new AddTestCriteriaOPMathModel(testCase.getTCKey(), newSimulations[j].getVersion().getVersionKey(), regressionMathModelKey, regressionMathModelSimKey, (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxAbsError() : new Double(1e-16)), (tcritOrigForSimName != null ? tcritOrigForSimName.getMaxRelError() : new Double(1e-9)), null);
                    }
                    testCaseOP = new AddTestCasesOPMathModel(new BigDecimal(tsInfo.getTSKey().toString()), newMathModel.getVersion().getVersionKey(), mathTestCase.getType(), mathTestCase.getAnnotation(), testCriteriaOPs);
                    getRequestManager().getDocumentManager().doTestSuiteOP(testCaseOP);
                }
            } catch (Throwable e) {
                errors.append("Error processing MathModel for TestCase " + (testCase.getVersion() != null ? "Name=" + testCase.getVersion().getName() : "TCKey=" + testCase.getTCKey()) + "\n" + e.getClass().getName() + " " + e.getMessage() + "\n");
            }
        }
    }
    if (errors.length() > 0) {
        return errors.toString();
    }
    return null;
}
Also used : AddTestCriteriaOPBioModel(cbit.vcell.numericstest.AddTestCriteriaOPBioModel) AddTestCasesOPBioModel(cbit.vcell.numericstest.AddTestCasesOPBioModel) ArrayList(java.util.ArrayList) TestCriteriaNewMathModel(cbit.vcell.numericstest.TestCriteriaNewMathModel) GeometryContext(cbit.vcell.mapping.GeometryContext) HashSet(java.util.HashSet) TestSuiteNew(cbit.vcell.numericstest.TestSuiteNew) TestCaseNew(cbit.vcell.numericstest.TestCaseNew) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) AddTestCriteriaOPMathModel(cbit.vcell.numericstest.AddTestCriteriaOPMathModel) MathMapping(cbit.vcell.mapping.MathMapping) MathModel(cbit.vcell.mathmodel.MathModel) AddTestCasesOPMathModel(cbit.vcell.numericstest.AddTestCasesOPMathModel) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel) TestCriteriaNewMathModel(cbit.vcell.numericstest.TestCriteriaNewMathModel) EditTestCriteriaOPMathModel(cbit.vcell.numericstest.EditTestCriteriaOPMathModel) AddTestCriteriaOPMathModel(cbit.vcell.numericstest.AddTestCriteriaOPMathModel) KeyValue(org.vcell.util.document.KeyValue) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) TestCriteriaNewBioModel(cbit.vcell.numericstest.TestCriteriaNewBioModel) AddTestCasesOP(cbit.vcell.numericstest.AddTestCasesOP) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) AddTestCasesOPMathModel(cbit.vcell.numericstest.AddTestCasesOPMathModel) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) SimulationContext(cbit.vcell.mapping.SimulationContext) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) BigDecimal(java.math.BigDecimal) Simulation(cbit.vcell.solver.Simulation) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) TestCaseNewBioModel(cbit.vcell.numericstest.TestCaseNewBioModel) TestCriteriaNewBioModel(cbit.vcell.numericstest.TestCriteriaNewBioModel) AddTestCasesOPBioModel(cbit.vcell.numericstest.AddTestCasesOPBioModel) BioModel(cbit.vcell.biomodel.BioModel) EditTestCriteriaOPBioModel(cbit.vcell.numericstest.EditTestCriteriaOPBioModel) AddTestCriteriaOPBioModel(cbit.vcell.numericstest.AddTestCriteriaOPBioModel) TestCaseNewMathModel(cbit.vcell.numericstest.TestCaseNewMathModel)

Example 27 with Membrane

use of cbit.vcell.model.Membrane in project vcell by virtualcell.

the class DBReactionWizardPanel method setupRX.

/**
 * Insert the method's description here.
 * Creation date: (8/5/2003 2:50:56 PM)
 * @param dbfr cbit.vcell.dictionary.ReactionDescription
 */
private void setupRX(ReactionDescription dbfr) {
    resolvedReaction = dbfr;
    if (resolvedReaction != null) {
        if (speciesAssignmentJCB != null) {
            for (int i = 0; i < speciesAssignmentJCB.length; i += 1) {
                speciesAssignmentJCB[i].removeActionListener(this);
            }
        }
        if (structureAssignmentJCB != null) {
            for (int i = 0; i < structureAssignmentJCB.length; i += 1) {
                structureAssignmentJCB[i].removeActionListener(this);
            }
        }
        getReactionCanvas1().setReactionCanvasDisplaySpec(resolvedReaction.toReactionCanvasDisplaySpec());
        getRXParticipantsJPanel().removeAll();
        // java.awt.Insets zeroInsets = new java.awt.Insets(0,0,0,0);
        java.awt.Insets fourInsets = new java.awt.Insets(4, 4, 4, 4);
        java.awt.GridBagConstraints gbc = new java.awt.GridBagConstraints();
        gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gbc.insets = fourInsets;
        gbc.gridx = 0;
        gbc.gridy = 0;
        javax.swing.JLabel rxjlabel = new javax.swing.JLabel("RX Elements");
        // rxjlabel.setForeground(java.awt.Color.white);
        // rxjlabel.setOpaque(true);
        // rxjlabel.setBackground(java.awt.Color.white);
        getRXParticipantsJPanel().add(rxjlabel, gbc);
        // gbc.insets = zeroInsets;
        for (int i = 0; i < resolvedReaction.elementCount(); i += 1) {
            gbc.gridy = i + 1;
            javax.swing.JLabel jlabel = new javax.swing.JLabel(resolvedReaction.getReactionElement(i).getPreferredName() + (resolvedReaction.isFluxReaction() && resolvedReaction.getFluxIndexOutside() == i ? " (Outside)" : "") + (resolvedReaction.isFluxReaction() && resolvedReaction.getFluxIndexInside() == i ? " (Inside)" : ""));
            // jlabel.setOpaque(true);
            // jlabel.setBackground(java.awt.Color.white);
            // jlabel.setForeground(java.awt.Color.black);
            getRXParticipantsJPanel().add(jlabel, gbc);
        }
        // gbc.insets = fourInsets;
        gbc.gridx = 1;
        gbc.gridy = 0;
        speciesAssignmentJCB = new javax.swing.JComboBox[resolvedReaction.elementCount()];
        DefaultListCellRenderer speciesListCellRenderer = new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                // TODO Auto-generated method stub
                return super.getListCellRendererComponent(list, (value instanceof Species ? "Existing " + ((Species) value).getCommonName() : value), index, isSelected, cellHasFocus);
            }
        };
        javax.swing.JLabel rspjlabel = new javax.swing.JLabel("Assign to Model Species");
        // rspjlabel.setForeground(java.awt.Color.white);
        // rspjlabel.setOpaque(true);
        // rspjlabel.setBackground(java.awt.Color.white);
        getRXParticipantsJPanel().add(rspjlabel, gbc);
        // getRXParticipantsJPanel().add(new javax.swing.JLabel("Resolve to Model Species"),gbc);
        speciesOrder = new Species[getModel().getSpecies().length + 1];
        speciesOrder[0] = null;
        for (int j = 0; j < getModel().getSpecies().length; j += 1) {
            speciesOrder[j + 1] = getModel().getSpecies(j);
        }
        for (int i = 0; i < resolvedReaction.elementCount(); i += 1) {
            javax.swing.JComboBox jcb = new javax.swing.JComboBox();
            jcb.setRenderer(speciesListCellRenderer);
            speciesAssignmentJCB[i] = jcb;
            jcb.addItem("New Species");
            for (int j = 1; j < speciesOrder.length; j += 1) {
                jcb.addItem(/*"Existing "+*/
                speciesOrder[j]);
            }
            gbc.gridy = i + 1;
            getRXParticipantsJPanel().add(jcb, gbc);
            jcb.setEnabled(false);
        }
        gbc.gridx = 2;
        gbc.gridy = 0;
        structureAssignmentJCB = new javax.swing.JComboBox[resolvedReaction.elementCount()];
        DefaultListCellRenderer structureListCellRenderer = new DefaultListCellRenderer() {

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                // TODO Auto-generated method stub
                return super.getListCellRendererComponent(list, (value instanceof Structure ? ((Structure) value).getName() : value), index, isSelected, cellHasFocus);
            }
        };
        javax.swing.JLabel rstjlabel = new javax.swing.JLabel("Assign to Model Compartment");
        // rstjlabel.setForeground(java.awt.Color.white);
        // rstjlabel.setOpaque(true);
        // rstjlabel.setBackground(java.awt.Color.white);
        getRXParticipantsJPanel().add(rstjlabel, gbc);
        // getRXParticipantsJPanel().add(new javax.swing.JLabel("Resolve to Model Compartment"),gbc);
        StructureTopology structTopology = getModel().getStructureTopology();
        for (int i = 0; i < resolvedReaction.elementCount(); i += 1) {
            javax.swing.JComboBox jcb = new javax.swing.JComboBox();
            jcb.setRenderer(structureListCellRenderer);
            structureAssignmentJCB[i] = jcb;
            if (resolvedReaction.isFluxReaction() && resolvedReaction.isFlux(i) && resolvedReaction.getFluxIndexOutside() == i) {
                jcb.addItem(structTopology.getOutsideFeature((Membrane) getStructure()));
                jcb.setEnabled(false);
            } else if (resolvedReaction.isFluxReaction() && resolvedReaction.isFlux(i) && resolvedReaction.getFluxIndexInside() == i) {
                jcb.addItem((structTopology).getInsideFeature((Membrane) getStructure()));
                jcb.setEnabled(false);
            } else {
                jcb.addItem(getStructure());
                if (getStructure() instanceof Membrane) {
                    jcb.addItem(structTopology.getOutsideFeature((Membrane) getStructure()));
                    jcb.addItem(structTopology.getInsideFeature((Membrane) getStructure()));
                } else {
                    jcb.setEnabled(false);
                }
            }
            gbc.gridy = i + 1;
            getRXParticipantsJPanel().add(jcb, gbc);
        }
        for (int i = 0; i < resolvedReaction.elementCount(); i += 1) {
            speciesAssignmentJCB[i].addActionListener(this);
            structureAssignmentJCB[i].addActionListener(this);
        }
    }
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) StructureTopology(cbit.vcell.model.Model.StructureTopology) GridBagConstraints(java.awt.GridBagConstraints) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) DBFormalSpecies(cbit.vcell.model.DBFormalSpecies) Species(cbit.vcell.model.Species) DBNonFormalUnboundSpecies(cbit.vcell.dictionary.DBNonFormalUnboundSpecies) JList(javax.swing.JList)

Example 28 with Membrane

use of cbit.vcell.model.Membrane in project vcell by virtualcell.

the class DBReactionWizardPanel method searchUserReactions.

/**
 * Insert the method's description here.
 * Creation date: (7/12/2003 2:45:44 PM)
 */
private void searchUserReactions(final ReactionQuerySpec reactionQuerySpec) {
    if (getDocumentManager() != null) {
        final DocumentManager docManager = getDocumentManager();
        final JList jlist = getReactionsJList();
        // 
        final String RXSTRING_VALUE_KEY = "rxString";
        // 
        AsynchClientTask searchReactions = new AsynchClientTask("searching reactions", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                try {
                    mapRXStringtoRXIDs.clear();
                    // 
                    ReactionDescription[] dbrd = docManager.getUserReactionDescriptions(reactionQuerySpec);
                    // 
                    if (dbrd != null && !(getStructure() instanceof Membrane)) {
                        Vector<ReactionDescription> noflux = new Vector<ReactionDescription>();
                        for (int i = 0; i < dbrd.length; i += 1) {
                            if (!dbrd[i].isFluxReaction()) {
                                noflux.add(dbrd[i]);
                            }
                        }
                        if (noflux.size() > 0) {
                            dbrd = new ReactionDescription[noflux.size()];
                            noflux.copyInto(dbrd);
                        }
                    }
                    // 
                    String[] dbrdS = null;
                    if (dbrd != null) {
                        // if(mapRXStringtoRXIDs == null){mapRXStringtoRXIDs = new java.util.Hashtable();}
                        for (int i = 0; i < dbrd.length; i += 1) {
                            String rxString = dbrd[i].toString();
                            if (!mapRXStringtoRXIDs.containsKey(rxString)) {
                                mapRXStringtoRXIDs.put(rxString, new Vector<String>());
                            }
                            mapRXStringtoRXIDs.get(rxString).add(dbrd[i].getVCellRXID().toString());
                            mapRXIDtoBMIDs.put(dbrd[i].getVCellRXID(), dbrd[i].getVCellBioModelID());
                            mapRXIDtoStructRefIDs.put(dbrd[i].getVCellRXID(), dbrd[i].getVCellStructRef());
                        }
                        dbrdS = (String[]) mapRXStringtoRXIDs.keySet().toArray(new String[0]);
                    }
                    // 
                    if (dbrd != null && dbrd.length > 0) {
                        hash.put(RXSTRING_VALUE_KEY, dbrdS);
                    }
                } catch (DataAccessException e) {
                    PopupGenerator.showErrorDialog(DBReactionWizardPanel.this, e.getMessage());
                }
            }
        };
        // 
        AsynchClientTask updateRXList = new AsynchClientTask("updateRXList", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hash) {
                String[] dbrdS = (String[]) hash.get(RXSTRING_VALUE_KEY);
                if (dbrdS != null) {
                    jlist.setListData(dbrdS);
                } else {
                    jlist.setListData(new String[0]);
                }
                afterSearchConfigure();
            }
        };
        // 
        Hashtable<String, Object> hashTemp = new Hashtable<String, Object>();
        ClientTaskDispatcher.dispatch(this, hashTemp, new AsynchClientTask[] { searchReactions, updateRXList }, false);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) DocumentManager(cbit.vcell.clientdb.DocumentManager) Membrane(cbit.vcell.model.Membrane) ReactionDescription(cbit.vcell.model.ReactionDescription) Vector(java.util.Vector) JList(javax.swing.JList) DataAccessException(org.vcell.util.DataAccessException)

Example 29 with Membrane

use of cbit.vcell.model.Membrane in project vcell by virtualcell.

the class KineticsTypeTemplatePanel method getKineticsTypeComboBox.

private javax.swing.JComboBox getKineticsTypeComboBox() {
    if (kineticsTypeComboBox == null) {
        try {
            kineticsTypeComboBox = new javax.swing.JComboBox();
            kineticsTypeComboBox.setName("JComboBox1");
            kineticsTypeComboBox.setRenderer(new DefaultListCellRenderer() {

                private static final String MU = "\u03BC";

                private static final String MICROMOLAR = MU + "M";

                private static final String SQUARED = "\u00B2";

                private static final String SQUAREMICRON = MU + "m" + SQUARED;

                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
                    java.awt.Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
                    if (value instanceof KineticsDescription) {
                        KineticsDescription kineticsDescription = (KineticsDescription) value;
                        if (getKinetics() != null && getKinetics().getReactionStep() != null) {
                            if (getKinetics().getReactionStep().getStructure() instanceof Feature) {
                                if (kineticsDescription.equals(KineticsDescription.General)) {
                                    setText("General [" + MICROMOLAR + "/s]");
                                } else if (kineticsDescription.equals(KineticsDescription.MassAction)) {
                                    setText("Mass Action [" + MICROMOLAR + "/s] (recommended for stochastic application)");
                                } else if (kineticsDescription.equals(KineticsDescription.GeneralLumped)) {
                                    setText("General [molecules/s]");
                                } else if (kineticsDescription.equals(KineticsDescription.HMM_irreversible)) {
                                    setText("Henri-Michaelis-Menten (Irreversible) [" + MICROMOLAR + "/s]");
                                } else if (kineticsDescription.equals(KineticsDescription.HMM_reversible)) {
                                    setText("Henri-Michaelis-Menten (Reversible) [" + MICROMOLAR + "/s]");
                                } else {
                                    setText(kineticsDescription.getDescription());
                                }
                            } else if (getKinetics().getReactionStep().getStructure() instanceof Membrane) {
                                if (kineticsDescription.equals(KineticsDescription.General)) {
                                    setText("General [molecules/(" + SQUAREMICRON + " s)]");
                                } else if (kineticsDescription.equals(KineticsDescription.MassAction)) {
                                    setText("Mass Action [molecules/(" + SQUAREMICRON + " s)]");
                                } else if (kineticsDescription.equals(KineticsDescription.GeneralLumped)) {
                                    setText("General [molecules/s)]");
                                } else if (kineticsDescription.equals(KineticsDescription.HMM_irreversible)) {
                                    setText("Henri-Michaelis-Menten (Irreversible) [molecules/(" + SQUAREMICRON + " s)]");
                                } else if (kineticsDescription.equals(KineticsDescription.HMM_reversible)) {
                                    setText("Henri-Michaelis-Menten (Reversible) [molecules/(" + SQUAREMICRON + " s)]");
                                } else if (kineticsDescription.equals(KineticsDescription.Macroscopic_irreversible)) {
                                    setText("Macroscopic (Irreversible) [molecules/(" + SQUAREMICRON + " s)]");
                                } else if (kineticsDescription.equals(KineticsDescription.Microscopic_irreversible)) {
                                    setText("Microscopic (Irreversible) [molecules/(" + SQUAREMICRON + " s)]");
                                } else {
                                    setText(kineticsDescription.getDescription());
                                }
                            }
                        } else {
                            setText(kineticsDescription.getDescription());
                        }
                    }
                    return component;
                }
            });
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    return kineticsTypeComboBox;
}
Also used : KineticsDescription(cbit.vcell.model.KineticsDescription) Feature(cbit.vcell.model.Feature) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) Membrane(cbit.vcell.model.Membrane) Component(java.awt.Component) JList(javax.swing.JList)

Example 30 with Membrane

use of cbit.vcell.model.Membrane in project vcell by virtualcell.

the class SimpleReactionPanel method setTornOffSimpleReaction.

/**
 * Set the TornOffSimpleReaction to a new value.
 * @param newValue cbit.vcell.model.SimpleReaction
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void setTornOffSimpleReaction(SimpleReaction newValue) {
    if (ivjTornOffSimpleReaction != newValue) {
        try {
            SimpleReaction oldValue = getTornOffSimpleReaction();
            /* Stop listening for events from the current object */
            if (ivjTornOffSimpleReaction != null) {
                ivjTornOffSimpleReaction.removePropertyChangeListener(ivjEventHandler);
            }
            ivjTornOffSimpleReaction = newValue;
            /* Listen for events from the new object */
            if (ivjTornOffSimpleReaction != null) {
                ivjTornOffSimpleReaction.addPropertyChangeListener(ivjEventHandler);
            }
            connPtoP1SetSource();
            getReactionCanvas().setReactionStep(ivjTornOffSimpleReaction);
            if (ivjTornOffSimpleReaction != null) {
                getSimpleReactionNameTextField().setText(getTornOffSimpleReaction().getName());
            }
            getReactionElectricalPropertiesPanel1().setKinetics(ivjTornOffSimpleReaction.getKinetics());
            boolean electricalPropertiesVisible = ivjTornOffSimpleReaction != null && ivjTornOffSimpleReaction.getStructure() instanceof Membrane;
            getReactionElectricalPropertiesPanel1().setVisible(electricalPropertiesVisible);
            getKineticsTypeTemplatePanel().setReactionStep(getSimpleReaction());
            firePropertyChange("simpleReaction", oldValue, newValue);
        // user code begin {1}
        // user code end
        } catch (java.lang.Throwable ivjExc) {
            // user code begin {2}
            // user code end
            handleException(ivjExc);
        }
    }
    ;
// user code begin {3}
// user code end
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Membrane(cbit.vcell.model.Membrane)

Aggregations

Membrane (cbit.vcell.model.Membrane)77 Feature (cbit.vcell.model.Feature)50 Structure (cbit.vcell.model.Structure)47 Expression (cbit.vcell.parser.Expression)31 SpeciesContext (cbit.vcell.model.SpeciesContext)25 MembraneMapping (cbit.vcell.mapping.MembraneMapping)20 StructureTopology (cbit.vcell.model.Model.StructureTopology)19 ExpressionException (cbit.vcell.parser.ExpressionException)18 PropertyVetoException (java.beans.PropertyVetoException)17 FluxReaction (cbit.vcell.model.FluxReaction)16 Model (cbit.vcell.model.Model)16 ReactionStep (cbit.vcell.model.ReactionStep)16 SimpleReaction (cbit.vcell.model.SimpleReaction)16 ArrayList (java.util.ArrayList)14 StructureMapping (cbit.vcell.mapping.StructureMapping)12 ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)12 ReactionParticipant (cbit.vcell.model.ReactionParticipant)12 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)12 SubVolume (cbit.vcell.geometry.SubVolume)11 SurfaceClass (cbit.vcell.geometry.SurfaceClass)11