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);
}
}
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());
}
}
}
}
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;
}
Aggregations