Search in sources :

Example 31 with SurfaceClass

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

the class SimulationContext method refreshSpatialObjects.

public void refreshSpatialObjects() {
    Geometry geometry = getGeometry();
    if (geometry != null && geometry.getGeometrySurfaceDescription() != null && geometry.getGeometrySurfaceDescription().getGeometricRegions() != null) {
        ArrayList<SpatialObject> unmappedSpatialObjects = new ArrayList<SpatialObject>(Arrays.asList(spatialObjects));
        ArrayList<GeometricRegion> mappedRegions = new ArrayList<GeometricRegion>();
        // 
        for (SpatialObject spatialObject : spatialObjects) {
            if (spatialObject instanceof VolumeRegionObject) {
                VolumeRegionObject volRegionObj = (VolumeRegionObject) spatialObject;
                SubVolume existingSubvolume = volRegionObj.getSubVolume();
                Integer existingRegionID = volRegionObj.getRegionID();
                SubVolume newSubvolume = geometry.getGeometrySpec().getSubVolume(existingSubvolume.getName());
                if (newSubvolume != null && geometry.getGeometrySurfaceDescription().getGeometricRegions() != null) {
                    for (GeometricRegion newRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions(newSubvolume)) {
                        VolumeGeometricRegion newVolRegion = (VolumeGeometricRegion) newRegion;
                        if (newVolRegion.getRegionID() == existingRegionID) {
                            ((VolumeRegionObject) spatialObject).setSubVolume(newSubvolume);
                            mappedRegions.add(newVolRegion);
                            unmappedSpatialObjects.remove(spatialObject);
                        }
                    }
                }
            }
            if (spatialObject instanceof SurfaceRegionObject) {
                SurfaceRegionObject surfaceRegionObj = (SurfaceRegionObject) spatialObject;
                SubVolume existingInsideSubvolume = surfaceRegionObj.getInsideSubVolume();
                SubVolume existingOutsideSubvolume = surfaceRegionObj.getOutsideSubVolume();
                Integer existingInsideRegionID = surfaceRegionObj.getInsideRegionID();
                Integer existingOutsideRegionID = surfaceRegionObj.getOutsideRegionID();
                SubVolume newInsideSubvolume = geometry.getGeometrySpec().getSubVolume(existingInsideSubvolume.getName());
                SubVolume newOutsideSubvolume = geometry.getGeometrySpec().getSubVolume(existingOutsideSubvolume.getName());
                if (newInsideSubvolume != null && newOutsideSubvolume != null) {
                    SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(newInsideSubvolume, newOutsideSubvolume);
                    for (GeometricRegion newRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions(surfaceClass)) {
                        SurfaceGeometricRegion newSurfaceRegion = (SurfaceGeometricRegion) newRegion;
                        GeometricRegion[] adjacentRegions = newSurfaceRegion.getAdjacentGeometricRegions();
                        if (adjacentRegions.length == 2 && adjacentRegions[0] instanceof VolumeGeometricRegion && adjacentRegions[1] instanceof VolumeGeometricRegion) {
                            VolumeGeometricRegion adjVolRegion0 = (VolumeGeometricRegion) adjacentRegions[0];
                            VolumeGeometricRegion adjVolRegion1 = (VolumeGeometricRegion) adjacentRegions[1];
                            if (adjVolRegion0.getSubVolume() == newInsideSubvolume && adjVolRegion0.getRegionID() == existingInsideRegionID && adjVolRegion1.getSubVolume() == newOutsideSubvolume && adjVolRegion1.getRegionID() == existingOutsideRegionID) {
                                surfaceRegionObj.setInsideSubVolume(newInsideSubvolume);
                                surfaceRegionObj.setOutsideSubVolume(newOutsideSubvolume);
                                mappedRegions.add(newSurfaceRegion);
                                unmappedSpatialObjects.remove(spatialObject);
                            }
                            if (adjVolRegion0.getSubVolume() == newOutsideSubvolume && adjVolRegion0.getRegionID() == existingOutsideRegionID && adjVolRegion1.getSubVolume() == newInsideSubvolume && adjVolRegion1.getRegionID() == existingInsideRegionID) {
                                surfaceRegionObj.setInsideSubVolume(newInsideSubvolume);
                                surfaceRegionObj.setOutsideSubVolume(newOutsideSubvolume);
                                mappedRegions.add(newSurfaceRegion);
                                unmappedSpatialObjects.remove(spatialObject);
                            }
                        }
                    }
                }
            }
        }
        // 
        // for geometric regions not represented as spatial objects, add them
        // 
        ArrayList<GeometricRegion> unmappedRegions = new ArrayList<GeometricRegion>(Arrays.asList(geometry.getGeometrySurfaceDescription().getGeometricRegions()));
        unmappedRegions.removeAll(mappedRegions);
        for (GeometricRegion unmappedRegion : unmappedRegions) {
            if (unmappedRegion instanceof VolumeGeometricRegion) {
                VolumeGeometricRegion unmappedVolRegion = (VolumeGeometricRegion) unmappedRegion;
                try {
                    VolumeRegionObject vro = new VolumeRegionObject(unmappedVolRegion.getSubVolume(), unmappedVolRegion.getRegionID(), this);
                    addSpatialObject(vro);
                } catch (PropertyVetoException e) {
                    e.printStackTrace();
                }
            } else if (unmappedRegion instanceof SurfaceGeometricRegion) {
                SurfaceGeometricRegion unmappedSurfRegion = (SurfaceGeometricRegion) unmappedRegion;
                GeometricRegion[] adjacentRegions = unmappedSurfRegion.getAdjacentGeometricRegions();
                if (adjacentRegions.length == 2 && adjacentRegions[0] instanceof VolumeGeometricRegion && adjacentRegions[1] instanceof VolumeGeometricRegion) {
                    VolumeGeometricRegion volRegion0 = (VolumeGeometricRegion) adjacentRegions[0];
                    VolumeGeometricRegion volRegion1 = (VolumeGeometricRegion) adjacentRegions[1];
                    SubVolume insideSubVolume = volRegion0.getSubVolume();
                    SubVolume outsideSubVolume = volRegion1.getSubVolume();
                    int insideRegionID = volRegion0.getRegionID();
                    int outsideRegionID = volRegion1.getRegionID();
                    SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(insideSubVolume, outsideSubVolume);
                    try {
                        addSpatialObject(new SurfaceRegionObject(insideSubVolume, insideRegionID, outsideSubVolume, outsideRegionID, this));
                    } catch (PropertyVetoException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        // 
        try {
            for (SpatialObject unmappedSpatialObject : unmappedSpatialObjects) {
                if (unmappedSpatialObject instanceof VolumeRegionObject) {
                    System.err.println("volume region spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, delete.");
                    removeSpatialObject(unmappedSpatialObject);
                }
                if (unmappedSpatialObject instanceof SurfaceRegionObject) {
                    System.err.println("surface region spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, delete.");
                    removeSpatialObject(unmappedSpatialObject);
                }
                if (unmappedSpatialObject instanceof PointObject) {
                    System.err.println("point spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, this is expected.");
                // removeSpatialObject(unmappedSpatialObject);
                }
            }
        } catch (PropertyVetoException e) {
            e.printStackTrace();
        }
    }
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ArrayList(java.util.ArrayList) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) 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) PointObject(cbit.vcell.mapping.spatial.PointObject) SubVolume(cbit.vcell.geometry.SubVolume) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 32 with SurfaceClass

use of cbit.vcell.geometry.SurfaceClass 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)

Example 33 with SurfaceClass

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

the class ParticleMathMapping method refreshVariables.

/**
 * This method was created in VisualAge.
 * @Override
 */
private void refreshVariables() throws MappingException {
    Enumeration<SpeciesContextMapping> enum1 = getSpeciesContextMappings();
    // 
    // non-constant independent variables require either a membrane or volume variable
    // 
    enum1 = getSpeciesContextMappings();
    while (enum1.hasMoreElements()) {
        SpeciesContextMapping scm = (SpeciesContextMapping) enum1.nextElement();
        SpeciesContextSpec scs = getSimulationContext().getReactionContext().getSpeciesContextSpec(scm.getSpeciesContext());
        // if (scm.getDependencyExpression() == null && (!scs.isConstant() || getSimulationContext().hasEventAssignment(scs.getSpeciesContext()))){
        StructureMapping sm = getSimulationContext().getGeometryContext().getStructureMapping(scm.getSpeciesContext().getStructure());
        Structure struct = scm.getSpeciesContext().getStructure();
        Domain domain = null;
        if (sm.getGeometryClass() != null) {
            domain = new Domain(sm.getGeometryClass());
        }
        if (struct instanceof Feature || struct instanceof Membrane) {
            if (sm.getGeometryClass() instanceof SurfaceClass) {
                if (scs.isWellMixed()) {
                    // scm.setVariable(new StochMembraneRegionVariable(scm.getSpeciesContext().getName(),domain));
                    throw new MappingException("stochastic membrane region variables not yet supported");
                } else {
                    scm.setVariable(new MembraneParticleVariable(scm.getSpeciesContext().getName(), domain));
                }
            } else {
                if (scs.isWellMixed()) {
                    throw new MappingException("stochastic volume region variables not yet supported");
                // scm.setVariable(new StochVolumeRegionVariable(scm.getSpeciesContext().getName(),domain));
                } else {
                    scm.setVariable(new VolumeParticleVariable(scm.getSpeciesContext().getName(), domain));
                }
            }
        } else {
            throw new MappingException("class " + scm.getSpeciesContext().getStructure().getClass() + " not supported");
        }
        mathSymbolMapping.put(scm.getSpeciesContext(), scm.getVariable().getName());
    // }
    }
}
Also used : SurfaceClass(cbit.vcell.geometry.SurfaceClass) MembraneParticleVariable(cbit.vcell.math.MembraneParticleVariable) VolumeParticleVariable(cbit.vcell.math.VolumeParticleVariable) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure) CompartmentSubDomain(cbit.vcell.math.CompartmentSubDomain) SubDomain(cbit.vcell.math.SubDomain) Domain(cbit.vcell.math.Variable.Domain) MembraneSubDomain(cbit.vcell.math.MembraneSubDomain) Feature(cbit.vcell.model.Feature)

Example 34 with SurfaceClass

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

the class AbstractMathMapping method getMathSymbol0.

/**
 * Substitutes appropriate variables for speciesContext bindings
 *
 * @return cbit.vcell.parser.Expression
 * @param origExp cbit.vcell.parser.Expression
 * @param structureMapping cbit.vcell.mapping.StructureMapping
 */
protected final String getMathSymbol0(SymbolTableEntry ste, GeometryClass geometryClass) throws MappingException {
    String steName = ste.getName();
    if (ste instanceof Kinetics.KineticsParameter) {
        Integer count = localNameCountHash.get(steName);
        if (count == null) {
            throw new MappingException("KineticsParameter " + steName + " not found in local name count");
        }
        if (count > 1 || steName.equals("J")) {
            return steName + "_" + ste.getNameScope().getName();
        // return getNameScope().getSymbolName(ste);
        } else {
            return steName;
        }
    }
    if (ste instanceof LocalParameter && ((LocalParameter) ste).getNameScope() instanceof ReactionRule.ReactionRuleNameScope) {
        Integer count = localNameCountHash.get(steName);
        if (count == null) {
            throw new MappingException("Reaction Rule Parameter " + steName + " not found in local name count");
        }
        if (count > 1 || steName.equals("J")) {
            return steName + "_" + ste.getNameScope().getName();
        // return getNameScope().getSymbolName(ste);
        } else {
            return steName;
        }
    }
    if (ste instanceof ProbabilityParameter) {
        // be careful here, to see if we need mangle the reaction name
        ProbabilityParameter probParm = (ProbabilityParameter) ste;
        return probParm.getName() + PARAMETER_PROBABLIITY_RATE_SUFFIX;
    }
    if (ste instanceof SpeciesConcentrationParameter) {
        SpeciesConcentrationParameter concParm = (SpeciesConcentrationParameter) ste;
        return concParm.getSpeciesContext().getName() + MATH_FUNC_SUFFIX_SPECIES_CONCENTRATION;
    }
    if (ste instanceof SpeciesCountParameter) {
        SpeciesCountParameter countParm = (SpeciesCountParameter) ste;
        return countParm.getSpeciesContext().getName() + MATH_VAR_SUFFIX_SPECIES_COUNT;
    }
    if (ste instanceof ObservableConcentrationParameter) {
        ObservableConcentrationParameter concParm = (ObservableConcentrationParameter) ste;
        return concParm.getObservable().getName() + MATH_FUNC_SUFFIX_SPECIES_CONCENTRATION;
    }
    if (ste instanceof ObservableCountParameter) {
        ObservableCountParameter countParm = (ObservableCountParameter) ste;
        return countParm.getObservable().getName() + MATH_VAR_SUFFIX_SPECIES_COUNT;
    }
    if (ste instanceof RbmObservable) {
        RbmObservable observable = (RbmObservable) ste;
        return observable.getName() + MATH_FUNC_SUFFIX_SPECIES_CONCENTRATION;
    }
    if (ste instanceof EventAssignmentOrRateRuleInitParameter) {
        EventAssignmentOrRateRuleInitParameter eventInitParm = (EventAssignmentOrRateRuleInitParameter) ste;
        // + MATH_FUNC_SUFFIX_EVENTASSIGN_OR_RATE_INIT;
        return eventInitParm.getName();
    }
    if (ste instanceof RateRuleRateParameter) {
        RateRuleRateParameter rateRuleRateParm = (RateRuleRateParameter) ste;
        // + MATH_FUNC_SUFFIX_RATERULE_RATE;
        return rateRuleRateParm.getName();
    }
    if (ste instanceof Model.ReservedSymbol) {
        return steName;
    }
    if (ste instanceof Membrane.MembraneVoltage) {
        return steName;
    }
    if (ste instanceof Structure.StructureSize) {
        Structure structure = ((Structure.StructureSize) ste).getStructure();
        StructureMapping.StructureMappingParameter sizeParameter = simContext.getGeometryContext().getStructureMapping(structure).getSizeParameter();
        return getMathSymbol(sizeParameter, geometryClass);
    }
    if (ste instanceof ProxyParameter) {
        ProxyParameter pp = (ProxyParameter) ste;
        return getMathSymbol0(pp.getTarget(), geometryClass);
    }
    // 
    if (ste instanceof ModelParameter) {
        ModelParameter mp = (ModelParameter) ste;
        return mp.getName();
    }
    if (ste instanceof SpeciesContextSpec.SpeciesContextSpecParameter) {
        SpeciesContextSpec.SpeciesContextSpecParameter scsParm = (SpeciesContextSpec.SpeciesContextSpecParameter) ste;
        SpeciesContext speciesContext = ((SpeciesContextSpec) (scsParm.getNameScope().getScopedSymbolTable())).getSpeciesContext();
        SpeciesContextMapping scm = getSpeciesContextMapping(speciesContext);
        String speciesContextVarName = null;
        if (scm.getVariable() != null) {
            speciesContextVarName = scm.getVariable().getName();
        } else {
            speciesContextVarName = speciesContext.getName();
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_InitialConcentration) {
            return speciesContextVarName + MATH_FUNC_SUFFIX_SPECIES_INIT_CONC_UNIT_PREFIX + TokenMangler.fixTokenStrict(scsParm.getUnitDefinition().getSymbol());
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_InitialCount) {
            return speciesContextVarName + MATH_FUNC_SUFFIX_SPECIES_INIT_COUNT;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_DiffusionRate) {
            return speciesContextVarName + PARAMETER_DIFFUSION_RATE_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueXm) {
            return speciesContextVarName + PARAMETER_BOUNDARY_XM_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueXp) {
            return speciesContextVarName + PARAMETER_BOUNDARY_XP_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueYm) {
            return speciesContextVarName + PARAMETER_BOUNDARY_YM_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueYp) {
            return speciesContextVarName + PARAMETER_BOUNDARY_YP_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueZm) {
            return speciesContextVarName + PARAMETER_BOUNDARY_ZM_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_BoundaryValueZp) {
            return speciesContextVarName + PARAMETER_BOUNDARY_ZP_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityX) {
            return speciesContextVarName + PARAMETER_VELOCITY_X_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityY) {
            return speciesContextVarName + PARAMETER_VELOCITY_Y_SUFFIX;
        }
        if (scsParm.getRole() == SpeciesContextSpec.ROLE_VelocityZ) {
            return speciesContextVarName + PARAMETER_VELOCITY_Z_SUFFIX;
        }
    }
    if (ste instanceof ElectricalDevice.ElectricalDeviceParameter) {
        ElectricalDevice.ElectricalDeviceParameter edParm = (ElectricalDevice.ElectricalDeviceParameter) ste;
        ElectricalDevice electricalDevice = (ElectricalDevice) edParm.getNameScope().getScopedSymbolTable();
        if (electricalDevice instanceof MembraneElectricalDevice) {
            String nameWithScope = ((MembraneElectricalDevice) electricalDevice).getMembraneMapping().getMembrane().getNameScope().getName();
            if (edParm.getRole() == ElectricalDevice.ROLE_TotalCurrent) {
                return PARAMETER_TOTAL_CURRENT_PREFIX + nameWithScope;
            }
            if (edParm.getRole() == ElectricalDevice.ROLE_TransmembraneCurrent) {
                return PARAMETER_TRANSMEMBRANE_CURRENT_PREFIX + nameWithScope;
            }
        // }else if (electricalDevice instanceof CurrentClampElectricalDevice) {
        // if (edParm.getRole()==ElectricalDevice.ROLE_TotalCurrentDensity){
        // return "I_"+((CurrentClampElectricalDevice)electricalDevice).getCurrentClampStimulus().getNameScope().getName();
        // }
        // if (edParm.getRole()==ElectricalDevice.ROLE_TransmembraneCurrentDensity){
        // return "F_"+((CurrentClampElectricalDevice)electricalDevice).getCurrentClampStimulus().getNameScope().getName();
        // }
        // }else if (electricalDevice instanceof VoltageClampElectricalDevice) {
        // if (edParm.getRole()==ElectricalDevice.ROLE_TotalCurrentDensity){
        // return "I_"+((VoltageClampElectricalDevice)electricalDevice).getVoltageClampStimulus().getNameScope().getName();
        // }
        // if (edParm.getRole()==ElectricalDevice.ROLE_TransmembraneCurrentDensity){
        // return "F_"+((VoltageClampElectricalDevice)electricalDevice).getVoltageClampStimulus().getNameScope().getName();
        // }
        }
    }
    if (ste instanceof LocalParameter && ((LocalParameter) ste).getNameScope() instanceof ElectricalStimulus.ElectricalStimulusNameScope) {
        LocalParameter esParm = (LocalParameter) ste;
        String nameWithScope = esParm.getNameScope().getName();
        if (esParm.getRole() == ElectricalStimulus.ElectricalStimulusParameterType.TotalCurrent) {
            return PARAMETER_TOTAL_CURRENT_PREFIX + nameWithScope;
        } else if (esParm.getRole() == ElectricalStimulus.ElectricalStimulusParameterType.Voltage) {
            return PARAMETER_VOLTAGE_PREFIX + nameWithScope;
        }
    }
    if (ste instanceof StructureMapping.StructureMappingParameter) {
        StructureMapping.StructureMappingParameter smParm = (StructureMapping.StructureMappingParameter) ste;
        Structure structure = ((StructureMapping) (smParm.getNameScope().getScopedSymbolTable())).getStructure();
        String nameWithScope = structure.getNameScope().getName();
        int role = smParm.getRole();
        if (role == StructureMapping.ROLE_InitialVoltage) {
            return smParm.getName();
        } else if (role == StructureMapping.ROLE_SpecificCapacitance) {
            return PARAMETER_SPECIFIC_CAPACITANCE_PREFIX + nameWithScope;
        } else if (role == StructureMapping.ROLE_Size) {
            if (simContext.getGeometry().getDimension() == 0) {
                // if geometry is compartmental, make sure compartment sizes are set if referenced in model.
                if (smParm.getExpression() == null || smParm.getExpression().isZero()) {
                    throw new MappingException("\nIn non-spatial application '" + getSimulationContext().getName() + "', " + "size of structure '" + structure.getName() + "' must be assigned a " + "positive value if referenced in the model.\n\nPlease go to 'Structure Mapping' tab to check the size.");
                }
            }
            return PARAMETER_SIZE_FUNCTION_PREFIX + nameWithScope;
        } else if (role == StructureMapping.ROLE_AreaPerUnitArea) {
            return "AreaPerUnitArea_" + nameWithScope;
        } else if (role == StructureMapping.ROLE_AreaPerUnitVolume) {
            return "AreaPerUnitVolume_" + nameWithScope;
        } else if (role == StructureMapping.ROLE_VolumePerUnitArea) {
            return "VolumePerUnitArea_" + nameWithScope;
        } else if (role == StructureMapping.ROLE_VolumePerUnitVolume) {
            return "VolumePerUnitVolume_" + nameWithScope;
        }
    }
    // 
    if (ste instanceof SpeciesContext) {
        SpeciesContext sc = (SpeciesContext) ste;
        SpeciesContextMapping scm = getSpeciesContextMapping(sc);
        if (scm == null) {
            throw new RuntimeException("Species '" + sc.getName() + "' is referenced in model but may have been deleted. " + "Find its references in '" + GuiConstants.DOCUMENT_EDITOR_FOLDERNAME_BIOMODEL_PARAMETERS + "'.");
        }
        // 
        if (geometryClass instanceof SubVolume) {
            // 
            if (scm.getVariable() != null && !scm.getVariable().getName().equals(steName)) {
                return scm.getVariable().getName();
            }
        // 
        // for reactions within a surface, may need "_INSIDE" or "_OUTSIDE" for jump condition
        // 
        } else if (geometryClass instanceof SurfaceClass) {
            // 
            // if the speciesContext is also within the surface, replace SpeciesContext name with Variable name
            // 
            StructureMapping sm = simContext.getGeometryContext().getStructureMapping(sc.getStructure());
            if (sm.getGeometryClass() == geometryClass) {
                if (scm.getVariable() != null && !(scm.getVariable().getName().equals(ste.getName()))) {
                    return scm.getVariable().getName();
                }
            // 
            // if the speciesContext is "inside" or "outside" the membrane
            // 
            } else if (sm.getGeometryClass() instanceof SubVolume && ((SurfaceClass) geometryClass).isAdjacentTo((SubVolume) sm.getGeometryClass())) {
                SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(sc);
                if (!scs.isConstant()) {
                    if (!scs.isDiffusing() && !scs.isWellMixed()) {
                        throw new MappingException("Enable diffusion in Application '" + simContext.getName() + "'. This must be done for any species (e.g '" + sc.getName() + "') in flux reactions.\n\n" + "To save or run simulations, set the diffusion rate to a non-zero " + "value in Initial Conditions or disable those reactions in Specifications->Reactions.");
                    }
                }
                if (scm.getVariable() != null) {
                    return scm.getVariable().getName();
                }
            } else {
                throw new MappingException("species '" + sc.getName() + "' interacts with surface '" + geometryClass.getName() + "', but is not mapped spatially adjacent");
            }
        }
    }
    return getNameScope().getSymbolName(ste);
}
Also used : SurfaceClass(cbit.vcell.geometry.SurfaceClass) MembraneElectricalDevice(cbit.vcell.mapping.potential.MembraneElectricalDevice) SpeciesContext(cbit.vcell.model.SpeciesContext) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) Structure(cbit.vcell.model.Structure) ElectricalDevice(cbit.vcell.mapping.potential.ElectricalDevice) MembraneElectricalDevice(cbit.vcell.mapping.potential.MembraneElectricalDevice) ReactionRule(cbit.vcell.model.ReactionRule) RbmObservable(cbit.vcell.model.RbmObservable) StructureSize(cbit.vcell.model.Structure.StructureSize) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) ProxyParameter(cbit.vcell.model.ProxyParameter) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage)

Example 35 with SurfaceClass

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

the class SimulationWorkspaceModelInfo method getMembraneName.

/**
 * Insert the method's description here.
 * Creation date: (9/19/2005 1:30:44 PM)
 * @return java.lang.String
 * @param subVolumeIdIn int
 * @param subVolumeIdOut int
 */
public String getMembraneName(int subVolumeIdIn, int subVolumeIdOut, boolean bFromGeometry) {
    String results = null;
    if (simulationOwner instanceof MathModel) {
        MathModel mathModel = (MathModel) simulationOwner;
        final GeometrySpec geometrySpec = mathModel.getMathDescription().getGeometry().getGeometrySpec();
        if (geometrySpec.getSubVolume(subVolumeIdIn) != null && geometrySpec.getSubVolume(subVolumeIdOut) != null) {
            SubVolume svIn = geometrySpec.getSubVolume(subVolumeIdIn);
            SubVolume svOut = geometrySpec.getSubVolume(subVolumeIdOut);
            SurfaceClass membrane = mathModel.getMathDescription().getGeometry().getGeometrySurfaceDescription().getSurfaceClass(svIn, svOut);
            results = membrane.getName();
        }
    } else if (simulationOwner instanceof SimulationContext) {
        SimulationContext simContext = (SimulationContext) simulationOwner;
        SubVolume svIn = simContext.getGeometry().getGeometrySpec().getSubVolume(subVolumeIdIn);
        SubVolume svOut = simContext.getGeometry().getGeometrySpec().getSubVolume(subVolumeIdOut);
        if (bFromGeometry) {
            SurfaceClass membrane = simContext.getMathDescription().getGeometry().getGeometrySurfaceDescription().getSurfaceClass(svIn, svOut);
            results = membrane.getName();
        } else {
            if (svIn != null && svOut != null) {
                GeometryClass[] geometryClasses = simContext.getGeometry().getGeometryClasses();
                for (int i = 0; i < geometryClasses.length; i++) {
                    if (geometryClasses[i] instanceof SurfaceClass) {
                        SurfaceClass surface = (SurfaceClass) geometryClasses[i];
                        if (surface.isAdjacentTo(svIn) && surface.isAdjacentTo(svOut)) {
                            StructureMapping[] structureMappings = simContext.getGeometryContext().getStructureMappings(surface);
                            if (structureMappings != null && structureMappings.length > 0) {
                                results = surface.getName() + "(";
                                for (int j = 0; j < structureMappings.length; j++) {
                                    results += structureMappings[j].getStructure().getName() + " ";
                                }
                                results += ")";
                                return results;
                            }
                        }
                    }
                }
            }
        }
    }
    return results;
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) MathModel(cbit.vcell.mathmodel.MathModel) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

SurfaceClass (cbit.vcell.geometry.SurfaceClass)48 SubVolume (cbit.vcell.geometry.SubVolume)42 GeometryClass (cbit.vcell.geometry.GeometryClass)19 Expression (cbit.vcell.parser.Expression)19 Geometry (cbit.vcell.geometry.Geometry)15 Feature (cbit.vcell.model.Feature)13 MathDescription (cbit.vcell.math.MathDescription)12 Model (cbit.vcell.model.Model)12 SpeciesContext (cbit.vcell.model.SpeciesContext)12 VCImage (cbit.image.VCImage)11 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)11 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)11 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)11 Membrane (cbit.vcell.model.Membrane)11 Structure (cbit.vcell.model.Structure)11 FeatureMapping (cbit.vcell.mapping.FeatureMapping)10 ArrayList (java.util.ArrayList)10 ImageException (cbit.image.ImageException)9 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)8 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)8