Search in sources :

Example 11 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class Model method getLocalEntries.

public void getLocalEntries(Map<String, SymbolTableEntry> entryMap) {
    for (SymbolTableEntry ste : fieldSpeciesContexts) {
        entryMap.put(ste.getName(), ste);
    }
    for (Structure s : fieldStructures) {
        Structure.StructureSize structureSize = s.getStructureSize();
        entryMap.put(structureSize.getName(), structureSize);
        if (s instanceof Membrane) {
            Membrane.MembraneVoltage membraneVoltage = ((Membrane) s).getMembraneVoltage();
            entryMap.put(membraneVoltage.getName(), membraneVoltage);
        }
    }
    for (SymbolTableEntry ste : fieldModelParameters) {
        entryMap.put(ste.getName(), ste);
    }
    for (Model.ModelFunction ste : fieldModelFunctions) {
        entryMap.put(ste.getName(), ste);
    }
    for (ReservedSymbol rs : fieldReservedSymbols) {
        if ((rs != getX()) || (rs != getY()) || (rs != getZ())) {
            entryMap.put(rs.getName(), rs);
        }
    }
    for (RbmObservable observable : rbmModelContainer.getObservableList()) {
        entryMap.put(observable.getName(), (SymbolTableEntry) observable);
    }
}
Also used : MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) StructureSize(cbit.vcell.model.Structure.StructureSize)

Example 12 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class Model method propertyChange.

/**
 * This method gets called when a bound property is changed.
 * @param evt A PropertyChangeEvent object describing the event source
 *   	and the property that has changed.
 */
public void propertyChange(java.beans.PropertyChangeEvent evt) {
    if (evt.getSource() instanceof ReactionStep && evt.getPropertyName().equals("kinetics")) {
        Kinetics oldKinetics = (Kinetics) evt.getOldValue();
        Kinetics newKinetics = (Kinetics) evt.getNewValue();
        if (oldKinetics != null) {
            oldKinetics.removePropertyChangeListener(this);
            oldKinetics.removeVetoableChangeListener(this);
        }
        if (newKinetics != null) {
            newKinetics.addPropertyChangeListener(this);
            newKinetics.addVetoableChangeListener(this);
        }
    }
    if (evt.getSource() instanceof SpeciesContext && evt.getPropertyName().equals("name")) {
        for (int i = 0; i < fieldDiagrams.length; i++) {
            fieldDiagrams[i].renameNode((String) evt.getOldValue(), (String) evt.getNewValue());
        }
    }
    if (evt.getSource() instanceof ReactionStep && evt.getPropertyName().equals("name")) {
        for (int i = 0; i < fieldDiagrams.length; i++) {
            fieldDiagrams[i].renameNode((String) evt.getOldValue(), (String) evt.getNewValue());
        }
    }
    // if we can't find any candidate or we find too many candidates we wisely (and silently) do nothing
    if (evt.getSource() instanceof MolecularType && evt.getPropertyName().equals("name")) {
        List<RbmObservable> candidates = new ArrayList<RbmObservable>();
        String oldName = (String) evt.getOldValue();
        String newName = (String) evt.getNewValue();
        for (RbmObservable candidate : getRbmModelContainer().getObservableList()) {
            if (candidate.getName().contains(oldName) && candidate.getName().startsWith("O") && candidate.getName().endsWith("_tot")) {
                candidates.add(candidate);
            }
        }
        if (candidates.isEmpty()) {
            System.out.println("no candidates to rename");
        } else if (candidates.size() > 1) {
            System.out.println("too many candidates to rename");
        } else {
            RbmObservable candidate = candidates.get(0);
            System.out.println("renaming --- " + candidate.getName());
            try {
                String prefix = candidate.getName().substring(0, candidate.getName().indexOf("_"));
                candidate.setName(prefix + "_" + newName + "_tot");
            } catch (PropertyVetoException e) {
                System.out.println("Cannot rename observable " + candidate.getName() + ", " + e.getMessage());
                e.printStackTrace();
            }
        }
    }
    // 
    if ((evt.getSource() instanceof ModelParameter || evt.getSource() instanceof SpeciesContext || evt.getSource() instanceof RbmObservable || evt.getSource() instanceof MembraneVoltage || evt.getSource() instanceof StructureSize) && evt.getPropertyName().equals("name")) {
        for (int i = 0; i < fieldModelParameters.length; i++) {
            try {
                Expression exp = fieldModelParameters[i].getExpression();
                Expression renamedExp = exp.renameBoundSymbols(getNameScope());
                if (!renamedExp.compareEqual(exp)) {
                    fieldModelParameters[i].setExpression(renamedExp);
                }
            } catch (ExpressionBindingException e) {
                e.printStackTrace(System.out);
                throw new RuntimeException(e.getMessage());
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) StructureSize(cbit.vcell.model.Structure.StructureSize) MolecularType(org.vcell.model.rbm.MolecularType) PropertyVetoException(java.beans.PropertyVetoException) MembraneVoltage(cbit.vcell.model.Membrane.MembraneVoltage) Expression(cbit.vcell.parser.Expression)

Example 13 with StructureSize

use of cbit.vcell.model.Structure.StructureSize in project vcell by virtualcell.

the class SEDMLExporter method getTargetAttributeXPath.

private XPathTarget getTargetAttributeXPath(SymbolTableEntry ste, Map<Pair<String, String>, String> l2gMap) {
    // to get Xpath string for variables.
    SBMLSupport sbmlSupport = new SBMLSupport();
    XPathTarget targetXpath = null;
    if (ste instanceof SpeciesContext || ste instanceof SpeciesContextSpecParameter) {
        String speciesId = ste.getName();
        // can change species initial concentration or amount
        String speciesAttr = "";
        if (ste instanceof SpeciesContextSpecParameter) {
            SpeciesContextSpecParameter scsp = (SpeciesContextSpecParameter) ste;
            speciesId = (scsp).getSpeciesContext().getName();
            if (scsp.getRole() == SpeciesContextSpec.ROLE_InitialConcentration) {
                speciesAttr = scsp.getName();
            }
            if (scsp.getRole() == SpeciesContextSpec.ROLE_InitialCount) {
                speciesAttr = scsp.getName();
            }
        }
        if (speciesAttr.length() < 1) {
            targetXpath = new XPathTarget(sbmlSupport.getXPathForCompartment(speciesId));
        } else if (speciesAttr.equalsIgnoreCase("initialConcentration") || speciesAttr.equalsIgnoreCase("initConc")) {
            targetXpath = new XPathTarget(sbmlSupport.getXPathForSpecies(speciesId, SpeciesAttribute.initialConcentration));
        } else if (speciesAttr.equalsIgnoreCase("initialCount")) {
            targetXpath = new XPathTarget(sbmlSupport.getXPathForSpecies(speciesId, SpeciesAttribute.initialAmount));
        } else {
            throw new RuntimeException("Unknown species attribute '" + speciesAttr + "'; cannot get xpath target for species '" + speciesId + "'.");
        }
        targetXpath = new XPathTarget(sbmlSupport.getXPathForSpecies(speciesId));
    } else if (ste instanceof ModelParameter) {
        // can only change parameter value.
        targetXpath = new XPathTarget(sbmlSupport.getXPathForGlobalParameter(ste.getName(), ParameterAttribute.value));
    } else if (ste instanceof Structure || ste instanceof Structure.StructureSize || (ste instanceof StructureMappingParameter && ((StructureMappingParameter) ste).getRole() == StructureMapping.ROLE_Size)) {
        String compartmentId = ste.getName();
        // can change compartment size or spatial dimension, but in vcell, we cannot change compartment dimension.
        String compartmentAttr = "";
        if (ste instanceof Structure.StructureSize) {
            compartmentId = ((StructureSize) ste).getStructure().getName();
            compartmentAttr = ((StructureSize) ste).getName();
        }
        if (ste instanceof StructureMappingParameter) {
            StructureMappingParameter smp = (StructureMappingParameter) ste;
            compartmentId = smp.getStructure().getName();
            if (smp.getRole() == StructureMapping.ROLE_Size) {
                compartmentAttr = smp.getName();
            }
        }
        if (compartmentAttr.length() < 1) {
            targetXpath = new XPathTarget(sbmlSupport.getXPathForCompartment(compartmentId));
        } else if (compartmentAttr.equalsIgnoreCase("size")) {
            targetXpath = new XPathTarget(sbmlSupport.getXPathForCompartment(compartmentId, CompartmentAttribute.size));
        } else {
            throw new RuntimeException("Unknown compartment attribute '" + compartmentAttr + "'; cannot get xpath target for compartment '" + compartmentId + "'.");
        }
    } else if (ste instanceof KineticsParameter) {
        KineticsParameter kp = (KineticsParameter) ste;
        String reactionID = kp.getKinetics().getReactionStep().getName();
        String parameterID = kp.getName();
        Pair<String, String> key = new Pair(reactionID, parameterID);
        String value = l2gMap.get(key);
        if (value == null) {
            // stays as local parameter
            targetXpath = new XPathTarget(sbmlSupport.getXPathForKineticLawParameter(reactionID, parameterID, ParameterAttribute.value));
        } else {
            // became a global in SBML, we need to refer to that global
            targetXpath = new XPathTarget(sbmlSupport.getXPathForGlobalParameter(value, ParameterAttribute.value));
        }
    } else {
        System.err.println("Entity should be SpeciesContext, Structure, ModelParameter : " + ste.getClass());
        throw new RuntimeException("Unknown entity in SBML model");
    }
    return targetXpath;
}
Also used : ModelParameter(cbit.vcell.model.Model.ModelParameter) KineticsParameter(cbit.vcell.model.Kinetics.KineticsParameter) SpeciesContext(cbit.vcell.model.SpeciesContext) StructureMappingParameter(cbit.vcell.mapping.StructureMapping.StructureMappingParameter) XPathTarget(org.jlibsedml.XPathTarget) Structure(cbit.vcell.model.Structure) StructureSize(cbit.vcell.model.Structure.StructureSize) SBMLSupport(org.jlibsedml.modelsupport.SBMLSupport) SpeciesContextSpecParameter(cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter) Pair(org.vcell.util.Pair)

Aggregations

StructureSize (cbit.vcell.model.Structure.StructureSize)13 MembraneVoltage (cbit.vcell.model.Membrane.MembraneVoltage)8 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)7 Expression (cbit.vcell.parser.Expression)6 SpeciesContext (cbit.vcell.model.SpeciesContext)5 Structure (cbit.vcell.model.Structure)5 PropertyVetoException (java.beans.PropertyVetoException)5 Vector (java.util.Vector)5 KineticsParameter (cbit.vcell.model.Kinetics.KineticsParameter)4 ModelParameter (cbit.vcell.model.Model.ModelParameter)4 SpeciesContextSpecParameter (cbit.vcell.mapping.SpeciesContextSpec.SpeciesContextSpecParameter)3 StructureMappingParameter (cbit.vcell.mapping.StructureMapping.StructureMappingParameter)3 Feature (cbit.vcell.model.Feature)3 Membrane (cbit.vcell.model.Membrane)3 StructureTopology (cbit.vcell.model.Model.StructureTopology)3 GeometryClass (cbit.vcell.geometry.GeometryClass)2 SubVolume (cbit.vcell.geometry.SubVolume)2 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 Model (cbit.vcell.model.Model)2 ReactionStep (cbit.vcell.model.ReactionStep)2