Search in sources :

Example 1 with UniformOutputTimeSpec

use of cbit.vcell.solver.UniformOutputTimeSpec in project vcell by virtualcell.

the class RbmNetworkGenerator method runNFSim.

public static void runNFSim(PrintWriter writer, RbmModelContainer rbmModelContainer, SimulationContext sc, NetworkGenerationRequirements networkGenerationRequirements) {
    // ex: simulate_nf({t_end=>100,n_steps=>50});
    writer.print("simulate_nf({");
    if (sc.getBioModel() == null || sc.getSimulations() == null || sc.getSimulations().length == 0) {
        writer.print("t_end=>100,n_steps=>50");
        writer.println("})");
        return;
    }
    // we just pick whatever the first simulation has, it'll get too complicated to offer the user a list of simulations and ask him to choose
    SolverTaskDescription solverTaskDescription = sc.getSimulations(0).getSolverTaskDescription();
    TimeBounds tb = solverTaskDescription.getTimeBounds();
    double dtime = tb.getEndingTime() - tb.getStartingTime();
    if (solverTaskDescription.getOutputTimeSpec() instanceof UniformOutputTimeSpec) {
        UniformOutputTimeSpec uots = (UniformOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
        double interval = uots.getOutputTimeStep();
        int steps = (int) Math.round(dtime / interval);
        writer.print("t_end=>" + dtime + ",n_steps=>" + steps);
    } else if (solverTaskDescription.getOutputTimeSpec() instanceof DefaultOutputTimeSpec) {
        // currently unsupported, but some old simulations have it
        writer.print("t_end=>" + dtime + ",n_steps=>50");
    } else {
        writer.print("t_end=>100,n_steps=>50");
    }
    writer.println("})");
}
Also used : TimeBounds(cbit.vcell.solver.TimeBounds) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) SolverTaskDescription(cbit.vcell.solver.SolverTaskDescription) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 2 with UniformOutputTimeSpec

use of cbit.vcell.solver.UniformOutputTimeSpec in project vcell by virtualcell.

the class XmlReader method getOutputTimeSpec.

/**
 * This method returns a TimeStep object from a XML Element.
 * Creation date: (5/22/2001 11:45:33 AM)
 * @return cbit.vcell.solver.TimeStep
 * @param param org.jdom.Element
 */
private OutputTimeSpec getOutputTimeSpec(Element param) {
    if (param != null) {
        // get attributes
        if (param.getAttributeValue(XMLTags.KeepEveryAttrTag) != null) {
            int keepEvery = Integer.parseInt(param.getAttributeValue(XMLTags.KeepEveryAttrTag));
            int keepAtMost = Integer.parseInt(param.getAttributeValue(XMLTags.KeepAtMostAttrTag));
            return new DefaultOutputTimeSpec(keepEvery, keepAtMost);
        } else if (param.getAttributeValue(XMLTags.OutputTimeStepAttrTag) != null) {
            double outputStep = Double.parseDouble(param.getAttributeValue(XMLTags.OutputTimeStepAttrTag));
            return new UniformOutputTimeSpec(outputStep);
        } else if (param.getAttributeValue(XMLTags.OutputTimesAttrTag) != null) {
            String line = param.getAttributeValue(XMLTags.OutputTimesAttrTag);
            return ExplicitOutputTimeSpec.fromString(line);
        }
    }
    return null;
}
Also used : UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 3 with UniformOutputTimeSpec

use of cbit.vcell.solver.UniformOutputTimeSpec in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * This methos returns a XML representation of a ErrorTolerance.
 * Creation date: (3/3/2001 12:02:33 AM)
 * @return Element
 * @param param cbit.vcell.solver.ErrorTolerance
 */
private Element getXML(OutputTimeSpec param) {
    Element outputOptions = new Element(XMLTags.OutputOptionsTag);
    // Add Atributes
    if (param.isDefault()) {
        DefaultOutputTimeSpec dots = (DefaultOutputTimeSpec) param;
        outputOptions.setAttribute(XMLTags.KeepEveryAttrTag, String.valueOf(dots.getKeepEvery()));
        outputOptions.setAttribute(XMLTags.KeepAtMostAttrTag, String.valueOf(dots.getKeepAtMost()));
    } else if (param.isExplicit()) {
        ExplicitOutputTimeSpec eots = (ExplicitOutputTimeSpec) param;
        outputOptions.setAttribute(XMLTags.OutputTimesAttrTag, eots.toCommaSeperatedOneLineOfString());
    } else if (param.isUniform()) {
        UniformOutputTimeSpec uots = (UniformOutputTimeSpec) param;
        outputOptions.setAttribute(XMLTags.OutputTimeStepAttrTag, String.valueOf(uots.getOutputTimeStep()));
    }
    return outputOptions;
}
Also used : ExplicitOutputTimeSpec(cbit.vcell.solver.ExplicitOutputTimeSpec) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) Element(org.jdom.Element) DefaultOutputTimeSpec(cbit.vcell.solver.DefaultOutputTimeSpec)

Example 4 with UniformOutputTimeSpec

use of cbit.vcell.solver.UniformOutputTimeSpec in project vcell by virtualcell.

the class FRAPStudy method createNewRefBioModel.

public static BioModel createNewRefBioModel(FRAPStudy sourceFrapStudy, String baseDiffusionRate, TimeStep tStep, KeyValue simKey, User owner, FieldDataIdentifierSpec psfFDIS, int startingIndexForRecovery) throws Exception {
    if (owner == null) {
        throw new Exception("Owner is not defined");
    }
    ROI cellROI_2D = sourceFrapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
    Extent extent = sourceFrapStudy.getFrapData().getImageDataset().getExtent();
    TimeBounds timeBounds = FRAPOptData.getEstimatedRefTimeBound(sourceFrapStudy);
    double timeStepVal = FRAPOptData.REFERENCE_DIFF_DELTAT;
    int numX = cellROI_2D.getRoiImages()[0].getNumX();
    int numY = cellROI_2D.getRoiImages()[0].getNumY();
    int numZ = cellROI_2D.getRoiImages().length;
    short[] shortPixels = cellROI_2D.getRoiImages()[0].getPixels();
    byte[] bytePixels = new byte[numX * numY * numZ];
    final byte EXTRACELLULAR_PIXVAL = 0;
    final byte CYTOSOL_PIXVAL = 1;
    for (int i = 0; i < bytePixels.length; i++) {
        if (shortPixels[i] != 0) {
            bytePixels[i] = CYTOSOL_PIXVAL;
        }
    }
    VCImage maskImage;
    try {
        maskImage = new VCImageUncompressed(null, bytePixels, extent, numX, numY, numZ);
    } catch (ImageException e) {
        e.printStackTrace();
        throw new RuntimeException("failed to create mask image for geometry");
    }
    Geometry geometry = new Geometry("geometry", maskImage);
    if (geometry.getGeometrySpec().getNumSubVolumes() != 2) {
        throw new Exception("Cell ROI has no ExtraCellular.");
    }
    int subVolume0PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(0)).getPixelValue();
    geometry.getGeometrySpec().getSubVolume(0).setName((subVolume0PixVal == EXTRACELLULAR_PIXVAL ? EXTRACELLULAR_NAME : CYTOSOL_NAME));
    int subVolume1PixVal = ((ImageSubVolume) geometry.getGeometrySpec().getSubVolume(1)).getPixelValue();
    geometry.getGeometrySpec().getSubVolume(1).setName((subVolume1PixVal == CYTOSOL_PIXVAL ? CYTOSOL_NAME : EXTRACELLULAR_NAME));
    geometry.getGeometrySurfaceDescription().updateAll();
    BioModel bioModel = new BioModel(null);
    bioModel.setName("unnamed");
    Model model = new Model("model");
    bioModel.setModel(model);
    Feature extracellular = model.addFeature(EXTRACELLULAR_NAME);
    Feature cytosol = model.addFeature(CYTOSOL_NAME);
    Membrane plasmaMembrane = model.addMembrane(PLASMAMEMBRANE_NAME);
    String roiDataName = FRAPStudy.ROI_EXTDATA_NAME;
    final int ONE_DIFFUSION_SPECIES_COUNT = 1;
    final int MOBILE_SPECIES_INDEX = 0;
    Expression[] diffusionConstants = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
    Species[] species = new Species[ONE_DIFFUSION_SPECIES_COUNT];
    SpeciesContext[] speciesContexts = new SpeciesContext[ONE_DIFFUSION_SPECIES_COUNT];
    Expression[] initialConditions = new Expression[ONE_DIFFUSION_SPECIES_COUNT];
    // Mobile Species
    diffusionConstants[MOBILE_SPECIES_INDEX] = new Expression(baseDiffusionRate);
    species[MOBILE_SPECIES_INDEX] = new Species(SPECIES_NAME_PREFIX_MOBILE, "Mobile bleachable species");
    speciesContexts[MOBILE_SPECIES_INDEX] = new SpeciesContext(null, species[MOBILE_SPECIES_INDEX].getCommonName(), species[MOBILE_SPECIES_INDEX], cytosol);
    FieldFunctionArguments postBleach_first = new FieldFunctionArguments(roiDataName, "postbleach_first", new Expression(0), VariableType.VOLUME);
    FieldFunctionArguments prebleach_avg = new FieldFunctionArguments(roiDataName, "prebleach_avg", new Expression(0), VariableType.VOLUME);
    Expression expPostBleach_first = new Expression(postBleach_first.infix());
    Expression expPreBleach_avg = new Expression(prebleach_avg.infix());
    initialConditions[MOBILE_SPECIES_INDEX] = Expression.div(expPostBleach_first, expPreBleach_avg);
    SimulationContext simContext = new SimulationContext(bioModel.getModel(), geometry);
    bioModel.addSimulationContext(simContext);
    FeatureMapping cytosolFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(cytosol);
    FeatureMapping extracellularFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(extracellular);
    MembraneMapping plasmaMembraneMapping = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(plasmaMembrane);
    SubVolume cytSubVolume = geometry.getGeometrySpec().getSubVolume(CYTOSOL_NAME);
    SubVolume exSubVolume = geometry.getGeometrySpec().getSubVolume(EXTRACELLULAR_NAME);
    SurfaceClass pmSurfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(exSubVolume, cytSubVolume);
    cytosolFeatureMapping.setGeometryClass(cytSubVolume);
    extracellularFeatureMapping.setGeometryClass(exSubVolume);
    plasmaMembraneMapping.setGeometryClass(pmSurfaceClass);
    cytosolFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    extracellularFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    plasmaMembraneMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    for (int i = 0; i < initialConditions.length; i++) {
        model.addSpecies(species[i]);
        model.addSpeciesContext(speciesContexts[i]);
    }
    for (int i = 0; i < speciesContexts.length; i++) {
        SpeciesContextSpec scs = simContext.getReactionContext().getSpeciesContextSpec(speciesContexts[i]);
        scs.getInitialConditionParameter().setExpression(initialConditions[i]);
        scs.getDiffusionParameter().setExpression(diffusionConstants[i]);
    }
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathDescription mathDesc = mathMapping.getMathDescription();
    // Add PSF function
    mathDesc.addVariable(new Function(Simulation.PSF_FUNCTION_NAME, new Expression(psfFDIS.getFieldFuncArgs().infix()), null));
    simContext.setMathDescription(mathDesc);
    SimulationVersion simVersion = new SimulationVersion(simKey, "sim1", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
    Simulation newSimulation = new Simulation(simVersion, simContext.getMathDescription());
    newSimulation.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
    simContext.addSimulation(newSimulation);
    newSimulation.getSolverTaskDescription().setTimeBounds(timeBounds);
    newSimulation.getSolverTaskDescription().setOutputTimeSpec(new UniformOutputTimeSpec(timeStepVal));
    newSimulation.getMeshSpecification().setSamplingSize(cellROI_2D.getISize());
    newSimulation.getSolverTaskDescription().setTimeStep(new TimeStep(timeStepVal, timeStepVal, timeStepVal));
    return bioModel;
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) ImageException(cbit.image.ImageException) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) SurfaceClass(cbit.vcell.geometry.SurfaceClass) MathDescription(cbit.vcell.math.MathDescription) VCImage(cbit.image.VCImage) SpeciesContext(cbit.vcell.model.SpeciesContext) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Feature(cbit.vcell.model.Feature) TimeBounds(cbit.vcell.solver.TimeBounds) Function(cbit.vcell.math.Function) GroupAccessNone(org.vcell.util.document.GroupAccessNone) TimeStep(cbit.vcell.solver.TimeStep) SimulationVersion(org.vcell.util.document.SimulationVersion) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) Membrane(cbit.vcell.model.Membrane) Species(cbit.vcell.model.Species) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) VCImageUncompressed(cbit.image.VCImageUncompressed) SimulationContext(cbit.vcell.mapping.SimulationContext) ROI(cbit.vcell.VirtualMicroscopy.ROI) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) MathMapping(cbit.vcell.mapping.MathMapping)

Example 5 with UniformOutputTimeSpec

use of cbit.vcell.solver.UniformOutputTimeSpec in project vcell by virtualcell.

the class ClientTaskManager method changeEndTime.

public static void changeEndTime(JComponent requester, SolverTaskDescription solverTaskDescription, double newEndTime) throws PropertyVetoException {
    TimeBounds oldTimeBounds = solverTaskDescription.getTimeBounds();
    TimeBounds timeBounds = new TimeBounds(oldTimeBounds.getStartingTime(), newEndTime);
    solverTaskDescription.setTimeBounds(timeBounds);
    if (solverTaskDescription.getOutputTimeSpec() instanceof UniformOutputTimeSpec) {
        UniformOutputTimeSpec uniformOutputTimeSpec = (UniformOutputTimeSpec) solverTaskDescription.getOutputTimeSpec();
        if (timeBounds.getEndingTime() < uniformOutputTimeSpec.getOutputTimeStep()) {
            double outputTime = solverTaskDescription.getTimeBounds().getEndingTime() / 20.0;
            String ret = PopupGenerator.showWarningDialog(requester, "Output Interval", "Output interval(" + uniformOutputTimeSpec.getOutputTimeStep() + "s) is greater than end time(" + timeBounds.getEndingTime() + "s) which will not output any results. Do you want to change " + "output interval to every " + outputTime + "s (20 time points)?\n\nIf not, output interval will change to " + timeBounds.getEndingTime() + "s(the end time).", new String[] { UserMessage.OPTION_YES, UserMessage.OPTION_NO }, UserMessage.OPTION_YES);
            if (ret.equals(UserMessage.OPTION_YES)) {
                solverTaskDescription.setOutputTimeSpec(new UniformOutputTimeSpec(outputTime));
            } else {
                solverTaskDescription.setOutputTimeSpec(new UniformOutputTimeSpec(timeBounds.getEndingTime()));
            }
        }
    }
}
Also used : TimeBounds(cbit.vcell.solver.TimeBounds) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec)

Aggregations

UniformOutputTimeSpec (cbit.vcell.solver.UniformOutputTimeSpec)34 Simulation (cbit.vcell.solver.Simulation)18 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)17 TimeBounds (cbit.vcell.solver.TimeBounds)15 DefaultOutputTimeSpec (cbit.vcell.solver.DefaultOutputTimeSpec)14 BioModel (cbit.vcell.biomodel.BioModel)13 SimulationContext (cbit.vcell.mapping.SimulationContext)13 SpeciesContextSpec (cbit.vcell.mapping.SpeciesContextSpec)10 MathDescription (cbit.vcell.math.MathDescription)10 KeyValue (org.vcell.util.document.KeyValue)10 Expression (cbit.vcell.parser.Expression)9 TimeStep (cbit.vcell.solver.TimeStep)9 IOException (java.io.IOException)9 ImageException (cbit.image.ImageException)8 Model (cbit.vcell.model.Model)8 SimulationVersion (org.vcell.util.document.SimulationVersion)8 Geometry (cbit.vcell.geometry.Geometry)7 MathMapping (cbit.vcell.mapping.MathMapping)7 ErrorTolerance (cbit.vcell.solver.ErrorTolerance)7 ExplicitOutputTimeSpec (cbit.vcell.solver.ExplicitOutputTimeSpec)7