Search in sources :

Example 51 with ModelUnitSystem

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

the class XmlReader method getModelParameter.

public ModelParameter getModelParameter(Element paramElement, Model model) {
    // get its attributes : name, role and unit definition
    String glParamName = unMangle(paramElement.getAttributeValue(XMLTags.NameAttrTag));
    String role = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
    ModelUnitSystem modelUnitSystem = model.getUnitSystem();
    int glParamRole = -1;
    if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
        glParamRole = Model.ROLE_UserDefined;
    } else {
        throw new RuntimeException("unknown type of model parameter (not user-defined)");
    }
    // 
    // int glParamRole = -1;
    // if (role.equals(XMLTags.ParamRoleUserDefinedTag)) {
    // glParamRole = Model.ROLE_UserDefined;
    // } else	if (role.equals(XMLTags.RoleVariableRateTag)) {
    // glParamRole = Model.ROLE_VariableRate;
    // } else {
    // throw new RuntimeException("unknown type of model parameter (not user-defined or variable rate)");
    // }
    String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
    VCUnitDefinition glParamUnit = null;
    if (unitSymbol != null) {
        glParamUnit = modelUnitSystem.getInstance(unitSymbol);
    }
    // get parameter contents : expression; annotation, if any.
    String glParamExpStr = paramElement.getText();
    Expression glParamExp = unMangleExpression(glParamExpStr);
    String glParamAnnotation = null;
    String annotationText = paramElement.getChildText(XMLTags.AnnotationTag, vcNamespace);
    if (annotationText != null && annotationText.length() > 0) {
        glParamAnnotation = unMangle(annotationText);
    }
    // create new global parameter
    ModelParameter newGlParam = model.new ModelParameter(glParamName, glParamExp, glParamRole, glParamUnit);
    newGlParam.setModelParameterAnnotation(glParamAnnotation);
    return newGlParam;
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 52 with ModelUnitSystem

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

the class VFrapXmlHelper method CreateSaveVFrapDataSymbols.

public static void CreateSaveVFrapDataSymbols(Hashtable<String, Object> hashTable, BioModel bioModel, ExternalDataIdentifier vfrapMisc) {
    String[] channelNames = (String[]) hashTable.get("channelNames");
    DataSymbolType[] channelVFrapImageType = (DataSymbolType[]) hashTable.get("channelVFrapImageType");
    String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
    SimulationContext simContext = bioModel.getSimulationContexts()[0];
    ModelUnitSystem modelUnitSystem = bioModel.getModel().getUnitSystem();
    for (int i = 0; i < channelNames.length; i++) {
        // TODO: construct dataSymbolName from vFrapConstants::nameFromToken()
        // item name postfixed with field data name
        String dataSymbolName = channelNames[i] + "_" + initialFieldDataName;
        DataSymbol dataSymbol = new FieldDataSymbol(dataSymbolName, channelVFrapImageType[i], simContext.getDataContext(), modelUnitSystem.getInstance_TBD(), vfrapMisc, channelNames[i], VariableType.VOLUME.getTypeName(), 0D);
        simContext.getDataContext().addDataSymbol(dataSymbol);
    }
}
Also used : FieldDataSymbol(cbit.vcell.data.FieldDataSymbol) DataSymbol(cbit.vcell.data.DataSymbol) DataSymbolType(cbit.vcell.data.DataSymbol.DataSymbolType) SimulationContext(cbit.vcell.mapping.SimulationContext) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem) FieldDataSymbol(cbit.vcell.data.FieldDataSymbol)

Example 53 with ModelUnitSystem

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

the class ITextWriter method writeStructureMapping.

// boundary types ignored.
protected void writeStructureMapping(Section simContextSection, SimulationContext sc) throws DocumentException {
    GeometryContext gc = sc.getGeometryContext();
    if (gc == null) {
        return;
    }
    Section structMappSection = null;
    /*try {
			ByteArrayOutputStream bos = generateStructureMappingImage(sc);
			com.lowagie.text.Image structMapImage = com.lowagie.text.Image.getInstance(Toolkit.getDefaultToolkit().createImage(bos.toByteArray()), null);
			structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
			structMappSection.add(structMapImage);
		} catch (Exception e) {
			System.err.println("Unable to add structure mapping image to report.");
			e.printStackTrace();
		}*/
    StructureMapping[] structMap = gc.getStructureMappings();
    Table structMapTable = null;
    ModelUnitSystem modelUnitSystem = sc.getModel().getUnitSystem();
    for (int i = 0; i < structMap.length; i++) {
        if (!(structMap[i] instanceof FeatureMapping)) {
            continue;
        }
        if (i == 0) {
            structMapTable = getTable(5, 100, 1, 3, 3);
            structMapTable.addCell(createCell("Structure Mapping", getBold(DEF_HEADER_FONT_SIZE), 5, 1, Element.ALIGN_CENTER, true));
            structMapTable.addCell(createHeaderCell("Structure", getBold(), 1));
            structMapTable.addCell(createHeaderCell("Subdomain", getBold(), 1));
            structMapTable.addCell(createHeaderCell("Resolved (T/F)", getBold(), 1));
            structMapTable.addCell(createHeaderCell("Surf/Vol", getBold(), 1));
            structMapTable.addCell(createHeaderCell("VolFract", getBold(), 1));
            structMapTable.endHeaders();
        }
        String structName = structMap[i].getStructure().getName();
        SubVolume subVol = (SubVolume) ((FeatureMapping) structMap[i]).getGeometryClass();
        String subDomain = "";
        if (subVol != null) {
            subDomain = subVol.getName();
        }
        // ((FeatureMapping)structMap[i]).getResolved();
        boolean isResolved = false;
        String surfVolStr = "", volFractStr = "";
        MembraneMapping mm = (MembraneMapping) gc.getStructureMapping(sc.getModel().getStructureTopology().getParentStructure(structMap[i].getStructure()));
        if (mm != null) {
            StructureMapping.StructureMappingParameter smp = mm.getSurfaceToVolumeParameter();
            if (smp != null) {
                Expression tempExp = smp.getExpression();
                VCUnitDefinition tempUnit = smp.getUnitDefinition();
                if (tempExp != null) {
                    surfVolStr = tempExp.infix();
                    if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
                        // no need to add '1' for dimensionless unit
                        surfVolStr += " " + tempUnit.getSymbolUnicode();
                    }
                }
            }
            smp = mm.getVolumeFractionParameter();
            if (smp != null) {
                Expression tempExp = smp.getExpression();
                VCUnitDefinition tempUnit = smp.getUnitDefinition();
                if (tempExp != null) {
                    volFractStr = tempExp.infix();
                    if (tempUnit != null && !modelUnitSystem.getInstance_DIMENSIONLESS().compareEqual(tempUnit)) {
                        volFractStr += " " + tempUnit.getSymbolUnicode();
                    }
                }
            }
        }
        structMapTable.addCell(createCell(structName, getFont()));
        structMapTable.addCell(createCell(subDomain, getFont()));
        structMapTable.addCell(createCell((isResolved ? " T " : " F "), getFont()));
        structMapTable.addCell(createCell(surfVolStr, getFont()));
        structMapTable.addCell(createCell(volFractStr, getFont()));
    }
    if (structMapTable != null) {
        if (structMappSection == null) {
            structMappSection = simContextSection.addSection("Structure Mapping For " + sc.getName(), simContextSection.numberDepth() + 1);
        }
        structMappSection.add(structMapTable);
    }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) Table(com.lowagie.text.Table) Section(com.lowagie.text.Section) StructureMapping(cbit.vcell.mapping.StructureMapping) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) FeatureMapping(cbit.vcell.mapping.FeatureMapping) Expression(cbit.vcell.parser.Expression) SubVolume(cbit.vcell.geometry.SubVolume) GeometryContext(cbit.vcell.mapping.GeometryContext) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Aggregations

ModelUnitSystem (cbit.vcell.model.ModelUnitSystem)53 Expression (cbit.vcell.parser.Expression)41 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)36 ModelParameter (cbit.vcell.model.Model.ModelParameter)17 ExpressionException (cbit.vcell.parser.ExpressionException)17 SpeciesContext (cbit.vcell.model.SpeciesContext)16 PropertyVetoException (java.beans.PropertyVetoException)16 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)14 Membrane (cbit.vcell.model.Membrane)12 Model (cbit.vcell.model.Model)12 Parameter (cbit.vcell.model.Parameter)12 BioModel (cbit.vcell.biomodel.BioModel)11 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)11 Feature (cbit.vcell.model.Feature)11 Structure (cbit.vcell.model.Structure)11 ArrayList (java.util.ArrayList)11 ReactionStep (cbit.vcell.model.ReactionStep)10 Kinetics (cbit.vcell.model.Kinetics)9 SubVolume (cbit.vcell.geometry.SubVolume)7 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)7