Search in sources :

Example 26 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class StructureMappingTableRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    setIcon(null);
    if (table.getModel() instanceof StructureMappingTableModel) {
        StructureMappingTableModel structureMappingTableModel = (StructureMappingTableModel) table.getModel();
        String toolTip = structureMappingTableModel.getToolTip(row, column);
        if (value instanceof Structure) {
            Structure structure = (Structure) value;
            setText(structure.getName());
        } else if (value instanceof Double && structureMappingTableModel.isNewSizeColumn(column)) {
            StructureMapping structureMapping = structureMappingTableModel.getStructureMapping(row);
            if (structureMappingTableModel.isNonSpatial()) {
                VCUnitDefinition unitDefinition = structureMapping.getStructure().getStructureSize().getUnitDefinition();
                TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                if (sizeIcon == null) {
                    sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                    unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                }
                setIcon(sizeIcon);
            } else {
                // spatial
                if (structureMapping.getUnitSizeParameter() != null) {
                    VCUnitDefinition unitDefinition = structureMapping.getUnitSizeParameter().getUnitDefinition();
                    TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                    if (sizeIcon == null) {
                        sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                        unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                    }
                    setIcon(sizeIcon);
                }
            }
        }
        if (structureMappingTableModel.isSubdomainColumn(column)) {
            // can be null
            if (value == null) {
                setText("Unmapped");
                setForeground(Color.red);
                setIcon(null);
            } else {
                if (value instanceof GeometryClass) {
                    setText(((GeometryClass) value).getName());
                    if (value instanceof SubVolume) {
                        SubVolume subVolume = (SubVolume) value;
                        java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
                        // small square icon with subdomain color
                        Icon icon = new ColorIcon(10, 10, handleColor, true);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                        setIcon(icon);
                    } else if (value instanceof SurfaceClass) {
                        SurfaceClass sc = (SurfaceClass) value;
                        Set<SubVolume> sv = sc.getAdjacentSubvolumes();
                        Iterator<SubVolume> iterator = sv.iterator();
                        SubVolume sv1 = iterator.next();
                        SubVolume sv2 = iterator.next();
                        java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
                        java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
                        Icon icon = new ColorIconEx(10, 10, c1, c2);
                        setIcon(icon);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                    }
                } else {
                    setText(value.toString());
                    setIcon(null);
                }
            }
        }
        if (value instanceof BoundaryConditionType) {
            // we get here only for spatial
            Object candidate = structureMappingTableModel.getValueAt(row, StructureMappingTableModel.SPATIAL_COLUMN_SUBDOMAIN);
            if (candidate instanceof SurfaceClass) {
                SurfaceClass surfaceClass = (SurfaceClass) candidate;
                cbit.vcell.model.Model model = structureMappingTableModel.getGeometryContext().getModel();
                SimulationContext simContext = structureMappingTableModel.getGeometryContext().getSimulationContext();
                Pair<SubVolume, SubVolume> ret = DiffEquMathMapping.computeBoundaryConditionSource(model, simContext, surfaceClass);
                SubVolume innerSubVolume = ret.one;
                java.awt.Color handleColor = new java.awt.Color(colormap[innerSubVolume.getHandle()]);
                // small square icon with subdomain color
                Icon icon = new ColorIcon(8, 8, handleColor, true);
                setHorizontalTextPosition(SwingConstants.LEFT);
                setIcon(icon);
                setText("from");
                // override default tooltip
                toolTip = "Boundary condition inherited from Subdomain '" + innerSubVolume.getName() + "'";
                setToolTipText(toolTip);
            } else {
                setText(((BoundaryConditionType) value).boundaryTypeStringValue());
            }
        }
        List<Issue> issueList = structureMappingTableModel.getIssues(row, column, Issue.SEVERITY_ERROR);
        if (issueList.size() > 0) {
            // override default tooltip
            setToolTipText(Issue.getHtmlIssueMessage(issueList));
            if (column == 0) {
                setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
            } else if (column == table.getColumnCount() - 1) {
                setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
            } else {
                setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
            }
        } else {
            setToolTipText(toolTip);
            setBorder(DEFAULT_GAP);
        }
    }
    return this;
}
Also used : Color(java.awt.Color) GeometryClass(cbit.vcell.geometry.GeometryClass) Set(java.util.Set) Issue(org.vcell.util.Issue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) AttributedString(java.text.AttributedString) StructureMapping(cbit.vcell.mapping.StructureMapping) MatteBorder(javax.swing.border.MatteBorder) SubVolume(cbit.vcell.geometry.SubVolume) Iterator(java.util.Iterator) Structure(cbit.vcell.model.Structure) ColorIconEx(org.vcell.util.gui.ColorIconEx) ColorIcon(org.vcell.util.gui.ColorIcon) Color(java.awt.Color) SimulationContext(cbit.vcell.mapping.SimulationContext) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon)

Example 27 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class SimulationContextDbDriver method getSimulationContextSQL.

/**
 * getModel method comment.
 */
private SimulationContext getSimulationContextSQL(QueryHashtable dbc, Connection con, User user, KeyValue simContextKey) throws /*, ReactStepDbDriver reactStepDB*/
SQLException, DataAccessException, IllegalMappingException, PropertyVetoException {
    SimulationContext simContext = null;
    String sql;
    Field[] f = { new cbit.sql.StarField(simContextTable), userTable.userid };
    Table[] t = { simContextTable, userTable };
    String condition = simContextTable.id.getQualifiedColName() + " = " + simContextKey + " AND " + simContextTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
    sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
    // System.out.println(sql);
    Statement stmt = con.createStatement();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        if (rset.next()) {
            simContext = simContextTable.getSimContext(dbc, con, user, rset, geomDB, modelDB, mathDescDB);
        } else {
            throw new ObjectNotFoundException("SimulationContext id=" + simContextKey + " not found for user '" + user + "'");
        }
    } finally {
        stmt.close();
    }
    DataSymbolTable.table.populateDataSymbols(con, simContextKey, simContext.getDataContext(), user, simContext.getModel().getUnitSystem());
    ArrayList<AnnotatedFunction> outputFunctionList = ApplicationMathTable.table.getOutputFunctionsSimcontext(con, simContextKey, dbSyntax);
    if (outputFunctionList != null) {
        OutputFunctionContext outputFnContext = simContext.getOutputFunctionContext();
        outputFnContext.setOutputFunctions(outputFunctionList);
    }
    SimContextTable.table.readAppComponents(con, simContext, dbSyntax);
    assignStimuliSQL(con, simContextKey, simContext);
    assignStructureMappingsSQL(dbc, con, simContextKey, simContext);
    assignSpeciesContextSpecsSQL(con, simContextKey, simContext);
    assignReactionSpecsSQL(con, simContextKey, simContext);
    for (GeometryClass gc : simContext.getGeometry().getGeometryClasses()) {
        try {
            StructureSizeSolver.updateUnitStructureSizes(simContext, gc);
        } catch (Exception e) {
            e.printStackTrace(System.out);
        }
    }
    simContext.getGeometryContext().enforceHierarchicalBoundaryConditions(simContext.getModel().getStructureTopology());
    simContext.getModel().refreshDependencies();
    assignAnalysisTasksSQL(con, simContextKey, simContext);
    // really needed to calculate MembraneMapping parameters that are not stored (inside/outside flux correction factors).
    simContext.refreshDependencies();
    return simContext;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Table(cbit.sql.Table) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) SimulationContext(cbit.vcell.mapping.SimulationContext) PropertyVetoException(java.beans.PropertyVetoException) DependencyException(org.vcell.util.DependencyException) RecordChangedException(cbit.sql.RecordChangedException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) PermissionException(org.vcell.util.PermissionException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) SQLException(java.sql.SQLException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) MathException(cbit.vcell.math.MathException) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) Field(cbit.sql.Field) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) OuterJoin(cbit.vcell.modeldb.DatabasePolicySQL.OuterJoin) ResultSet(java.sql.ResultSet) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 28 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class StructureMappingTableModel method updateSubdomainComboBox.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void updateSubdomainComboBox() {
    GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
    DefaultComboBoxModel aModel = new DefaultComboBoxModel();
    for (GeometryClass gc : geometryClasses) {
        aModel.addElement(gc);
    }
    JComboBox subdomainComboBoxCellEditor = new JComboBox();
    subdomainComboBoxCellEditor.setRenderer(new DefaultListCellRenderer() {

        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setHorizontalTextPosition(SwingConstants.LEFT);
            if (value instanceof GeometryClass) {
                GeometryClass gc = (GeometryClass) value;
                setText(gc.getName());
                if (value instanceof SubVolume) {
                    SubVolume subVolume = (SubVolume) value;
                    java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
                    // small square icon with subdomain color
                    Icon icon = new ColorIcon(10, 10, handleColor, true);
                    setHorizontalTextPosition(SwingConstants.RIGHT);
                    setIcon(icon);
                } else if (value instanceof SurfaceClass) {
                    SurfaceClass sc = (SurfaceClass) value;
                    Set<SubVolume> sv = sc.getAdjacentSubvolumes();
                    Iterator<SubVolume> iterator = sv.iterator();
                    SubVolume sv1 = iterator.next();
                    SubVolume sv2 = iterator.next();
                    java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
                    java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
                    Icon icon = new ColorIconEx(10, 10, c1, c2);
                    setIcon(icon);
                    setHorizontalTextPosition(SwingConstants.RIGHT);
                }
            }
            return this;
        }
    });
    subdomainComboBoxCellEditor.setModel(aModel);
    ownerTable.getColumnModel().getColumn(SPATIAL_COLUMN_SUBDOMAIN).setCellEditor(new DefaultCellEditor(subdomainComboBoxCellEditor));
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) ColorIcon(org.vcell.util.gui.ColorIcon) JComboBox(javax.swing.JComboBox) SurfaceClass(cbit.vcell.geometry.SurfaceClass) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultCellEditor(javax.swing.DefaultCellEditor) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) SubVolume(cbit.vcell.geometry.SubVolume) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon) Component(java.awt.Component) ColorIconEx(org.vcell.util.gui.ColorIconEx) JList(javax.swing.JList)

Example 29 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class SimulationContext method copySimulationContext.

public static SimulationContext copySimulationContext(SimulationContext srcSimContext, String newSimulationContextName, boolean bSpatial, Application simContextType) throws java.beans.PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException {
    Geometry newClonedGeometry = new Geometry(srcSimContext.getGeometry());
    newClonedGeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
    // if stoch copy to ode, we need to check is stoch is using particles. If yes, should convert particles to concentraton.
    // the other 3 cases are fine. ode->ode, ode->stoch, stoch-> stoch
    SimulationContext destSimContext = new SimulationContext(srcSimContext, newClonedGeometry, simContextType);
    if (srcSimContext.getApplicationType() == Application.NETWORK_STOCHASTIC && !srcSimContext.isUsingConcentration() && simContextType == Application.NETWORK_DETERMINISTIC) {
        try {
            destSimContext.convertSpeciesIniCondition(true);
        } catch (MappingException e) {
            e.printStackTrace();
            throw new java.beans.PropertyVetoException(e.getMessage(), null);
        }
    }
    if (srcSimContext.getGeometry().getDimension() > 0 && !bSpatial) {
        // copy the size over
        destSimContext.setGeometry(new Geometry("nonspatial", 0));
        StructureMapping[] srcStructureMappings = srcSimContext.getGeometryContext().getStructureMappings();
        StructureMapping[] destStructureMappings = destSimContext.getGeometryContext().getStructureMappings();
        for (StructureMapping destStructureMapping : destStructureMappings) {
            for (StructureMapping srcStructureMapping : srcStructureMappings) {
                if (destStructureMapping.getStructure() == srcStructureMapping.getStructure()) {
                    if (srcStructureMapping.getUnitSizeParameter() != null) {
                        Expression sizeRatio = srcStructureMapping.getUnitSizeParameter().getExpression();
                        GeometryClass srcGeometryClass = srcStructureMapping.getGeometryClass();
                        GeometricRegion[] srcGeometricRegions = srcSimContext.getGeometry().getGeometrySurfaceDescription().getGeometricRegions(srcGeometryClass);
                        if (srcGeometricRegions != null) {
                            double size = 0;
                            for (GeometricRegion srcGeometricRegion : srcGeometricRegions) {
                                size += srcGeometricRegion.getSize();
                            }
                            destStructureMapping.getSizeParameter().setExpression(Expression.mult(sizeRatio, new Expression(size)));
                        }
                    }
                    break;
                }
            }
        }
        // If changing spatial to non-spatial
        // set diffusion to 0, velocity and boundary to null
        // srcSimContext.getReactionContext().getspe
        Parameter[] allParameters = destSimContext.getAllParameters();
        if (allParameters != null && allParameters.length > 0) {
            for (int i = 0; i < allParameters.length; i++) {
                if (allParameters[i] instanceof SpeciesContextSpecParameter) {
                    SpeciesContextSpecParameter speciesContextSpecParameter = (SpeciesContextSpecParameter) allParameters[i];
                    int role = speciesContextSpecParameter.getRole();
                    if (role == SpeciesContextSpec.ROLE_DiffusionRate) {
                        speciesContextSpecParameter.setExpression(new Expression(0));
                    } else if (role == SpeciesContextSpec.ROLE_BoundaryValueXm || role == SpeciesContextSpec.ROLE_BoundaryValueXp || role == SpeciesContextSpec.ROLE_BoundaryValueYm || role == SpeciesContextSpec.ROLE_BoundaryValueYp || role == SpeciesContextSpec.ROLE_BoundaryValueZm || role == SpeciesContextSpec.ROLE_BoundaryValueZp) {
                        speciesContextSpecParameter.setExpression(null);
                    } else if (role == SpeciesContextSpec.ROLE_VelocityX || role == SpeciesContextSpec.ROLE_VelocityY || role == SpeciesContextSpec.ROLE_VelocityZ) {
                        speciesContextSpecParameter.setExpression(null);
                    }
                }
            }
        }
    }
    destSimContext.fixFlags();
    destSimContext.setName(newSimulationContextName);
    return destSimContext;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) GeometryThumbnailImageFactoryAWT(cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT) Expression(cbit.vcell.parser.Expression) Parameter(cbit.vcell.model.Parameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)

Example 30 with GeometryClass

use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.

the class SimulationContext method isPDERequired.

/**
 * Insert the method's description here.
 * Creation date: (8/8/01 3:46:23 PM)
 * @param speciesContext cbit.vcell.model.SpeciesContext
 * @return boolean
 */
public boolean isPDERequired(SpeciesContext speciesContext) {
    // 
    // compartmental models never need diffusion
    // 
    int dimension = getGeometryContext().getGeometry().getDimension();
    if (dimension == 0) {
        return false;
    }
    StructureMapping structureMapping = getGeometryContext().getStructureMapping(speciesContext.getStructure());
    GeometryClass geometryClass = structureMapping.getGeometryClass();
    if (geometryClass instanceof SubVolume) {
        if (dimension < 1) {
            return false;
        }
    } else if (geometryClass instanceof SurfaceClass) {
        if (dimension < 2) {
            return false;
        }
    } else {
        throw new RuntimeException("structure " + speciesContext.getStructure().getName() + " not mapped, or unsupported GeometryClass " + geometryClass);
    }
    // 
    // check speciesContext needs diffusion/advection
    // 
    SpeciesContextSpec scs = getReactionContext().getSpeciesContextSpec(speciesContext);
    if (scs.isDiffusing() || scs.isAdvecting()) {
        return true;
    }
    return false;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume)

Aggregations

GeometryClass (cbit.vcell.geometry.GeometryClass)43 SubVolume (cbit.vcell.geometry.SubVolume)21 SurfaceClass (cbit.vcell.geometry.SurfaceClass)19 Expression (cbit.vcell.parser.Expression)18 ExpressionException (cbit.vcell.parser.ExpressionException)14 PropertyVetoException (java.beans.PropertyVetoException)13 Structure (cbit.vcell.model.Structure)12 StructureMapping (cbit.vcell.mapping.StructureMapping)8 MathDescription (cbit.vcell.math.MathDescription)7 MathException (cbit.vcell.math.MathException)7 Variable (cbit.vcell.math.Variable)7 SpeciesContext (cbit.vcell.model.SpeciesContext)7 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)7 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)7 MappingException (cbit.vcell.mapping.MappingException)6 Domain (cbit.vcell.math.Variable.Domain)6 ModelException (cbit.vcell.model.ModelException)6 Parameter (cbit.vcell.model.Parameter)6 ArrayList (java.util.ArrayList)6 Geometry (cbit.vcell.geometry.Geometry)5