use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class MembraneStructureAnalyzer method refreshResolvedFluxes.
/**
* This method was created in VisualAge.
*/
void refreshResolvedFluxes() throws Exception {
// System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes()");
GeometryContext geoContext = mathMapping_4_8.getSimulationContext().getGeometryContext();
StructureTopology structTopology = mathMapping_4_8.getSimulationContext().getModel().getStructureTopology();
Vector<ResolvedFlux> resolvedFluxList = new Vector<ResolvedFlux>();
//
// for each reaction, get all fluxReactions associated with this membrane
//
Vector<ReactionStep> fluxList = new Vector<ReactionStep>();
ReactionSpec[] reactionSpecs = mathMapping_4_8.getSimulationContext().getReactionContext().getReactionSpecs();
for (int j = 0; j < reactionSpecs.length; j++) {
if (reactionSpecs[j].isExcluded()) {
continue;
}
ReactionStep rs = reactionSpecs[j].getReactionStep();
if (rs.getStructure() == getMembrane()) {
if (rs instanceof FluxReaction) {
fluxList.addElement(rs);
}
}
}
//
for (int i = 0; i < fluxList.size(); i++) {
FluxReaction fr = (FluxReaction) fluxList.elementAt(i);
Species fluxCarrier = null;
for (ReactionParticipant rp : fr.getReactionParticipants()) {
if (rp instanceof Reactant || rp instanceof Product) {
if (fluxCarrier == null) {
fluxCarrier = rp.getSpecies();
} else {
if (fluxCarrier != rp.getSpecies()) {
throw new Exception("Flux reaction '" + fr.getName() + "' with multiple species not allowed in VCell 4.8.");
}
}
}
}
if (fluxCarrier == null) {
continue;
}
ResolvedFlux rf = null;
for (int j = 0; j < resolvedFluxList.size(); j++) {
ResolvedFlux rf_tmp = (ResolvedFlux) resolvedFluxList.elementAt(j);
if (rf_tmp.getSpecies() == fluxCarrier) {
rf = rf_tmp;
}
}
//
// if "inside" speciesContext is not "fixed", add flux to ResolvedFlux
//
SpeciesContext insideSpeciesContext = mathMapping_4_8.getSimulationContext().getModel().getSpeciesContext(fluxCarrier, structTopology.getInsideFeature(getMembrane()));
SpeciesContextSpec insideSpeciesContextSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(insideSpeciesContext);
// if (!insideSpeciesContextSpec.isConstant()){
if (bNoFluxIfFixed || !insideSpeciesContextSpec.isConstant()) {
if (bNoFluxIfFixed && insideSpeciesContextSpec.isConstant()) {
bNoFluxIfFixedExercised = true;
}
if (rf == null) {
rf = new ResolvedFlux(fluxCarrier, fr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
resolvedFluxList.addElement(rf);
}
FeatureMapping insideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping((structTopology.getInsideFeature((Membrane) fr.getStructure())));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(insideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression insideFluxCorrection = Expression.invert(residualVolumeFraction);
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
insideFluxCorrection = new Expression(1.0);
}
//
if (fr.getKinetics() instanceof DistributedKinetics) {
Expression reactionRateParameter = new Expression(((DistributedKinetics) fr.getKinetics()).getReactionRateParameter(), mathMapping_4_8.getNameScope());
if (rf.inFluxExpression.isZero()) {
rf.inFluxExpression = Expression.mult(reactionRateParameter, insideFluxCorrection).flatten();
} else {
rf.inFluxExpression = Expression.add(rf.inFluxExpression, Expression.mult(reactionRateParameter, insideFluxCorrection).flatten());
}
} else if (fr.getKinetics() instanceof LumpedKinetics) {
throw new RuntimeException("Lumped Kinetics for fluxes not yet supported");
} else {
throw new RuntimeException("unexpected Kinetic type in MembraneStructureAnalyzer.refreshResolvedFluxes()");
}
// rf.inFlux.bindExpression(mathMapping);
}
SpeciesContext outsideSpeciesContext = mathMapping_4_8.getSimulationContext().getModel().getSpeciesContext(fluxCarrier, structTopology.getOutsideFeature(getMembrane()));
SpeciesContextSpec outsideSpeciesContextSpec = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(outsideSpeciesContext);
// if (!outsideSpeciesContextSpec.isConstant()){
if (bNoFluxIfFixed || !outsideSpeciesContextSpec.isConstant()) {
if (bNoFluxIfFixed && outsideSpeciesContextSpec.isConstant()) {
bNoFluxIfFixedExercised = true;
}
if (rf == null) {
rf = new ResolvedFlux(fluxCarrier, fr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
resolvedFluxList.addElement(rf);
}
FeatureMapping outsideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getOutsideFeature((Membrane) fr.getStructure()));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(outsideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression outsideFluxCorrection = Expression.invert(residualVolumeFraction);
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
outsideFluxCorrection = new Expression(1.0);
}
//
if (fr.getKinetics() instanceof DistributedKinetics) {
Expression reactionRateParameter = new Expression(((DistributedKinetics) fr.getKinetics()).getReactionRateParameter(), mathMapping_4_8.getNameScope());
if (rf.outFluxExpression.isZero()) {
rf.outFluxExpression = Expression.mult(Expression.negate(reactionRateParameter), outsideFluxCorrection).flatten();
} else {
rf.outFluxExpression = Expression.add(rf.outFluxExpression, Expression.mult(Expression.negate(reactionRateParameter), outsideFluxCorrection).flatten());
}
} else if (fr.getKinetics() instanceof LumpedKinetics) {
throw new RuntimeException("Lumped Kinetics not yet supported for Flux Reaction: " + fr.getName());
} else {
throw new RuntimeException("unexpected Kinetics type for Flux Reaction " + fr.getName());
}
// rf.outFlux.bindExpression(mathMapping);
}
}
//
// for each reaction, incorporate all reactionSteps involving binding with volumetric species
//
double kMoleValue = Model.reservedConstantsMap.get(ReservedSymbolRole.KMOLE);
for (int i = 0; i < reactionSpecs.length; i++) {
if (reactionSpecs[i].isExcluded()) {
continue;
}
ReactionStep rs = reactionSpecs[i].getReactionStep();
if (rs.getStructure() == getMembrane()) {
if (rs instanceof SimpleReaction) {
SimpleReaction sr = (SimpleReaction) rs;
ReactionParticipant[] rp_Array = sr.getReactionParticipants();
for (int k = 0; k < rp_Array.length; k++) {
if (rp_Array[k] instanceof Reactant || rp_Array[k] instanceof Product) {
SpeciesContextSpec scs = mathMapping_4_8.getSimulationContext().getReactionContext().getSpeciesContextSpec(rp_Array[k].getSpeciesContext());
// if (rp_Array[k].getStructure() instanceof Feature && !scs.isConstant()){
if (rp_Array[k].getStructure() instanceof Feature && (bNoFluxIfFixed || !scs.isConstant())) {
if (bNoFluxIfFixed && scs.isConstant()) {
bNoFluxIfFixedExercised = true;
}
//
// for each Reactant or Product binding to this membrane...
//
//
// get ResolvedFlux for this species
//
ResolvedFlux rf = null;
for (int j = 0; j < resolvedFluxList.size(); j++) {
ResolvedFlux rf_tmp = (ResolvedFlux) resolvedFluxList.elementAt(j);
if (rf_tmp.getSpecies() == rp_Array[k].getSpecies()) {
rf = rf_tmp;
}
}
if (rf == null) {
rf = new ResolvedFlux(rp_Array[k].getSpecies(), sr.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getUnitDefinition());
resolvedFluxList.addElement(rf);
}
Expression reactionRateExpression = getReactionRateExpression(sr, rp_Array[k]).renameBoundSymbols(mathMapping_4_8.getNameScope());
if (rp_Array[k].getStructure() == structTopology.getInsideFeature(getMembrane())) {
//
// for binding on inside, add to ResolvedFlux.inFlux
//
FeatureMapping insideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getInsideFeature(getMembrane()));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(insideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression insideFluxCorrection = Expression.div(new Expression(kMoleValue), residualVolumeFraction).flatten();
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
insideFluxCorrection = new Expression(kMoleValue);
}
if (rf.inFluxExpression.isZero()) {
rf.inFluxExpression = Expression.mult(insideFluxCorrection, reactionRateExpression);
} else {
rf.inFluxExpression = Expression.add(rf.inFluxExpression, Expression.mult(insideFluxCorrection, reactionRateExpression));
}
// rf.inFlux.bindExpression(mathMapping);
} else if (rp_Array[k].getStructure() == structTopology.getOutsideFeature(getMembrane())) {
//
// for binding on outside, add to ResolvedFlux.outFlux
//
FeatureMapping outsideFeatureMapping = (FeatureMapping) geoContext.getStructureMapping(structTopology.getOutsideFeature(getMembrane()));
Expression residualVolumeFraction = mathMapping_4_8.getResidualVolumeFraction(outsideFeatureMapping).renameBoundSymbols(mathMapping_4_8.getNameScope());
Expression outsideFluxCorrection = Expression.div(new Expression(kMoleValue), residualVolumeFraction).flatten();
//
if (bResolvedFluxCorrectionBug && !residualVolumeFraction.compareEqual(new Expression(1.0))) {
bResolvedFluxCorrectionBugExercised = true;
System.out.println("MembraneStructureAnalyzer.refreshResolvedFluxes() ... 'ResolvedFluxCorrection' bug compatability mode");
outsideFluxCorrection = new Expression(kMoleValue);
}
if (rf.outFluxExpression.isZero()) {
rf.outFluxExpression = Expression.mult(outsideFluxCorrection, reactionRateExpression);
} else {
rf.outFluxExpression = Expression.add(rf.outFluxExpression, Expression.mult(outsideFluxCorrection, reactionRateExpression));
}
// rf.outFlux.bindExpression(mathMapping);
} else {
throw new Exception("SpeciesContext " + rp_Array[k].getSpeciesContext().getName() + " doesn't border membrane " + getMembrane().getName() + " but reacts there");
}
}
}
}
}
}
}
//
if (resolvedFluxList.size() > 0) {
resolvedFluxes = new ResolvedFlux[resolvedFluxList.size()];
resolvedFluxList.copyInto(resolvedFluxes);
} else {
resolvedFluxes = null;
}
}
use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class ReactionCartoonFull method refreshAll.
@Override
protected void refreshAll(boolean reallocateShapes) {
try {
if (getModel() == null || getStructureSuite() == null) {
return;
}
System.out.println("ReactionCartoonFull, RefreshAll()");
for (Structure structure : structureSuite.getStructures()) {
Diagram diagram = getModel().getDiagram(structure);
if (diagram != null) {
// Maintain consistency between rule participant nodes, signatures and
// species pattern when a molecule is being modified.
rebindAll(diagram);
}
}
// calculate species context weight (number of reactions for which it's a participant)
Map<SpeciesContext, Integer> scWeightMap = new HashMap<>();
// all the species contexts that are catalysts
Set<SpeciesContext> scCatalystSet = new HashSet<>();
// calculate species context length (number of species patterns it contains, 1 if has no species patterns)
for (ReactionStep rs : getModel().getReactionSteps()) {
ReactionParticipant[] rpList = rs.getReactionParticipants();
for (int i = 0; i < rpList.length; i++) {
ReactionParticipant rp = rpList[i];
SpeciesContext sc = rp.getSpeciesContext();
// int increment = rp.getStoichiometry();
int increment = 1;
if (rp instanceof Catalyst) {
scCatalystSet.add(sc);
}
if (scWeightMap.containsKey(sc)) {
int weight = scWeightMap.get(sc);
weight += increment;
scWeightMap.put(sc, weight);
} else {
scWeightMap.put(sc, increment);
}
}
}
Set<Shape> unwantedShapes = new HashSet<Shape>();
Set<RuleParticipantSignature> unwantedSignatures = new HashSet<RuleParticipantSignature>();
unwantedShapes.addAll(getShapes());
unwantedSignatures.addAll(ruleParticipantSignatures);
ContainerContainerShape containerShape = (ContainerContainerShape) getShapeFromModelObject(getModel());
List<ReactionContainerShape> reactionContainerShapeList = new ArrayList<ReactionContainerShape>();
List<Structure> structureList = new ArrayList<Structure>(getStructureSuite().getStructures());
// create all ReactionContainerShapes (one for each Structure)
for (Structure structure : structureList) {
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
ReactionContainerShape membraneShape = (ReactionContainerShape) getShapeFromModelObject(membrane);
if (membraneShape == null) {
membraneShape = new ReactionContainerShape(membrane, structureSuite, this);
addShape(membraneShape);
membrane.getMembraneVoltage().removePropertyChangeListener(this);
membrane.getMembraneVoltage().addPropertyChangeListener(this);
} else {
membraneShape.setStructureSuite(structureSuite);
}
membrane.removePropertyChangeListener(this);
membrane.addPropertyChangeListener(this);
membraneShape.refreshLabel();
unwantedShapes.remove(membraneShape);
reactionContainerShapeList.add(membraneShape);
} else if (structure instanceof Feature) {
Feature feature = (Feature) structure;
ReactionContainerShape featureShape = (ReactionContainerShape) getShapeFromModelObject(feature);
if (featureShape == null) {
featureShape = new ReactionContainerShape(feature, structureSuite, this);
addShape(featureShape);
} else {
featureShape.setStructureSuite(structureSuite);
}
feature.removePropertyChangeListener(this);
feature.addPropertyChangeListener(this);
featureShape.refreshLabel();
unwantedShapes.remove(featureShape);
reactionContainerShapeList.add(featureShape);
}
}
if (containerShape == null) {
containerShape = new ContainerContainerShape(this, getModel(), reactionContainerShapeList);
addShape(containerShape);
} else {
containerShape.setReactionContainerShapeList(reactionContainerShapeList);
}
containerShape.refreshLabel();
unwantedShapes.remove(containerShape);
// add all species context shapes within the structures
for (Structure structure : getStructureSuite().getStructures()) {
ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
structure.removePropertyChangeListener(this);
structure.addPropertyChangeListener(this);
for (SpeciesContext structSpeciesContext : getModel().getSpeciesContexts(structure)) {
SpeciesContextShape ss = (SpeciesContextShape) getShapeFromModelObject(structSpeciesContext);
if (ss == null) {
ss = new SpeciesContextShape(structSpeciesContext, this);
ss.truncateLabelName(false);
structSpeciesContext.getSpecies().removePropertyChangeListener(this);
structSpeciesContext.getSpecies().addPropertyChangeListener(this);
reactionContainerShape.addChildShape(ss);
addShape(ss);
ss.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
if (speciesSizeOption == SpeciesSizeOptions.weight) {
// this number sets the diameter of the shape
Integer weight = scWeightMap.get(structSpeciesContext);
if (weight != null) {
// we cap the diameter of the shape to something reasonable
weight = Math.min(weight, 16);
}
ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, weight);
} else if (speciesSizeOption == SpeciesSizeOptions.length) {
Integer length = null;
if (structSpeciesContext.getSpeciesPattern() != null && !structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().isEmpty()) {
length = structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().size() * 2;
length = Math.min(length, 16);
}
ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, length);
} else {
ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, null);
}
structSpeciesContext.removePropertyChangeListener(this);
structSpeciesContext.addPropertyChangeListener(this);
ss.refreshLabel();
unwantedShapes.remove(ss);
}
}
// add all reactionSteps that are in this structure (ReactionContainerShape), and draw the lines
getModel().removePropertyChangeListener(this);
getModel().addPropertyChangeListener(this);
//
for (ReactionRule rr : getModel().getRbmModelContainer().getReactionRuleList()) {
rr.removePropertyChangeListener(this);
rr.addPropertyChangeListener(this);
Structure structure = rr.getStructure();
if (getStructureSuite().areReactionsShownFor(structure)) {
ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
ReactionRuleFullDiagramShape rrShape = (ReactionRuleFullDiagramShape) getShapeFromModelObject(rr);
if (rrShape == null) {
rrShape = new ReactionRuleFullDiagramShape(rr, this);
addShape(rrShape);
rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
reactionContainerShape.addChildShape(rrShape);
rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
rrShape.refreshLabel();
unwantedShapes.remove(rrShape);
//
// add reaction participants as edges and SignatureShapes as needed
//
List<ReactionRuleParticipant> participants = rr.getReactionRuleParticipants();
List<RuleParticipantEdgeDiagramShape> ruleEdges = new ArrayList<>();
for (ReactionRuleParticipant participant : participants) {
participant.getSpeciesPattern().removePropertyChangeListener(this);
participant.getSpeciesPattern().addPropertyChangeListener(this);
Structure speciesStructure = participant.getStructure();
Structure reactionStructure = rr.getStructure();
if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
//
// find existing RuleParticipantSignatureShape in cartoon
//
RuleParticipantLongSignature ruleParticipantLongSignature = null;
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantLongSignature && signature.getStructure() == participant.getStructure() && signature.compareByCriteria(participant.getSpeciesPattern(), GroupingCriteria.full)) {
ruleParticipantLongSignature = (RuleParticipantLongSignature) signature;
break;
}
}
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantShortSignature && signature.getStructure() == participant.getStructure()) {
System.out.println("ReactionCartoonFull, refreshAll(), RuleParticipantShortSignature");
}
}
//
// if didn't find signature in cartoons list of signatures, then create one (and create a shape for it).
//
RuleParticipantSignatureFullDiagramShape signatureShape = null;
if (ruleParticipantLongSignature == null) {
ruleParticipantLongSignature = RuleParticipantLongSignature.fromReactionRuleParticipant(participant, this);
ruleParticipantSignatures.add(ruleParticipantLongSignature);
signatureShape = new RuleParticipantSignatureFullDiagramShape(ruleParticipantLongSignature, this);
addShape(signatureShape);
ReactionContainerShape participantContainerShape = (ReactionContainerShape) getShapeFromModelObject(participant.getStructure());
signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
participantContainerShape.addChildShape(signatureShape);
signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
} else {
signatureShape = (RuleParticipantSignatureFullDiagramShape) getShapeFromModelObject(ruleParticipantLongSignature);
}
unwantedShapes.remove(signatureShape);
unwantedSignatures.remove(ruleParticipantLongSignature);
signatureShape.refreshLabel();
signatureShape.setVisible(true);
//
// add edge for ReactionRuleParticipant if not already present.
//
RuleParticipantEdgeDiagramShape ruleParticipantShape = (RuleParticipantEdgeDiagramShape) getShapeFromModelObject(participant);
if (ruleParticipantShape == null || ruleParticipantShape.getRuleParticipantSignatureShape() != signatureShape) {
if (participant instanceof ReactantPattern && signatureShape.isVisible()) {
ruleParticipantShape = new ReactantPatternEdgeDiagramShape((ReactantPattern) participant, rrShape, signatureShape, this);
} else if (participant instanceof ProductPattern && signatureShape.isVisible()) {
ruleParticipantShape = new ProductPatternEdgeDiagramShape((ProductPattern) participant, rrShape, signatureShape, this);
} else {
throw new RuntimeException("unsupported ReactionRuleParticipant " + participant.getClass());
}
addShape(ruleParticipantShape);
}
if (!containerShape.getChildren().contains(ruleParticipantShape)) {
containerShape.addChildShape(ruleParticipantShape);
}
unwantedShapes.remove(ruleParticipantShape);
ruleParticipantShape.refreshLabel();
// all the edges for this rule
ruleEdges.add(ruleParticipantShape);
}
}
// a product edge (a closed loop) between the rule diagram shape and the signature diagram shape
for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
// reset them all
ours.setSibling(false);
}
for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
for (RuleParticipantEdgeDiagramShape theirs : ruleEdges) {
if (ours == theirs) {
// don't compare with self
continue;
}
if (ours.getRuleParticipantSignatureShape() == theirs.getRuleParticipantSignatureShape()) {
ours.setSibling(true);
theirs.setSibling(true);
}
}
}
}
}
ruleParticipantSignatures.removeAll(unwantedSignatures);
for (ReactionStep reactionStep : getModel().getReactionSteps()) {
reactionStep.removePropertyChangeListener(this);
reactionStep.addPropertyChangeListener(this);
Structure structure = reactionStep.getStructure();
if (getStructureSuite().areReactionsShownFor(structure)) {
ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
if (reactionContainerShape == null) {
System.out.println("Reaction container shape is null for structure " + structure + " for reaction step " + reactionStep);
}
ReactionStepShape reactionStepShape = (ReactionStepShape) getShapeFromModelObject(reactionStep);
if (reactionStepShape == null) {
if (reactionStep instanceof SimpleReaction) {
reactionStepShape = new SimpleReactionShape((SimpleReaction) reactionStep, this);
} else if (reactionStep instanceof FluxReaction) {
reactionStepShape = new FluxReactionShape((FluxReaction) reactionStep, this);
} else {
throw new RuntimeException("unknown type of ReactionStep '" + reactionStep.getClass().toString());
}
addShape(reactionStepShape);
reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
reactionContainerShape.addChildShape(reactionStepShape);
reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
reactionStepShape.refreshLabel();
unwantedShapes.remove(reactionStepShape);
// add reaction participants as edges
for (ReactionParticipant participant : reactionStep.getReactionParticipants()) {
participant.removePropertyChangeListener(this);
participant.addPropertyChangeListener(this);
Structure speciesStructure = participant.getStructure();
Structure reactionStructure = reactionStep.getStructure();
if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
SpeciesContext speciesContext = getModel().getSpeciesContext(participant.getSpecies(), speciesStructure);
// add speciesContextShapes that are not in this structure, but are referenced from the reactionParticipants
// these are only when reactionParticipants are from features that are outside of the membrane being displayed
SpeciesContextShape speciesContextShape = (SpeciesContextShape) getShapeFromModelObject(speciesContext);
if (speciesContextShape == null) {
speciesContextShape = new SpeciesContextShape(speciesContext, this);
speciesContextShape.truncateLabelName(false);
reactionContainerShape.addChildShape(speciesContextShape);
addShape(speciesContextShape);
speciesContextShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
speciesContextShape.refreshLabel();
unwantedShapes.remove(speciesContextShape);
ReactionParticipantShape reactionParticipantShape = (ReactionParticipantShape) getShapeFromModelObject(participant);
if (reactionParticipantShape == null) {
if (participant instanceof Reactant) {
reactionParticipantShape = new ReactantShape((Reactant) participant, reactionStepShape, speciesContextShape, this);
} else if (participant instanceof Product) {
reactionParticipantShape = new ProductShape((Product) participant, reactionStepShape, speciesContextShape, this);
} else if (participant instanceof Catalyst) {
reactionParticipantShape = new CatalystShape((Catalyst) participant, reactionStepShape, speciesContextShape, this);
} else {
throw new RuntimeException("unsupported ReactionParticipant " + participant.getClass());
}
addShape(reactionParticipantShape);
}
if (!containerShape.getChildren().contains(reactionParticipantShape)) {
containerShape.addChildShape(reactionParticipantShape);
}
unwantedShapes.remove(reactionParticipantShape);
reactionParticipantShape.refreshLabel();
}
}
}
}
for (Shape unwantedShape : unwantedShapes) {
removeShape(unwantedShape);
}
// update diagrams
for (Structure structure : structureSuite.getStructures()) {
Diagram diagram = getModel().getDiagram(structure);
if (diagram != null) {
applyDefaults(diagram);
}
}
fireGraphChanged(new GraphEvent(this));
} catch (Throwable e) {
handleException(e);
}
}
use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class Xmlproducer method getXML.
/**
* This method returns a XML representation of a Flux Reaction object.
* Creation date: (2/26/2001 12:30:13 PM)
* @return Element
* @param param cbit.vcell.model.FluxReaction
*/
private Element getXML(FluxReaction param) throws XmlParseException {
Element fluxreaction = new Element(XMLTags.FluxStepTag);
// get Attributes
String versionName = (param.getName() != null) ? mangle(param.getName()) : "unnamed_fluxReaction";
fluxreaction.setAttribute(XMLTags.NameAttrTag, versionName);
fluxreaction.setAttribute(XMLTags.StructureAttrTag, mangle(param.getStructure().getName()));
fluxreaction.setAttribute(XMLTags.ReversibleAttrTag, mangle(Boolean.valueOf(param.isReversible()).toString()));
if (param.getPhysicsOptions() == FluxReaction.PHYSICS_ELECTRICAL_ONLY) {
fluxreaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionElectricalOnly);
} else if (param.getPhysicsOptions() == FluxReaction.PHYSICS_MOLECULAR_AND_ELECTRICAL) {
fluxreaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularAndElectrical);
} else if (param.getPhysicsOptions() == FluxReaction.PHYSICS_MOLECULAR_ONLY) {
fluxreaction.setAttribute(XMLTags.FluxOptionAttrTag, XMLTags.FluxOptionMolecularOnly);
}
// If keyFlag is on print the Keyvalue
if (param.getKey() != null && this.printKeysFlag) {
fluxreaction.setAttribute(XMLTags.KeyValueAttrTag, param.getKey().toString());
}
// Add subelements: Reactants/Products/Catalysts
// separate the order of the reactants, products, and modifiers.
ReactionParticipant[] rpArray = param.getReactionParticipants();
ArrayList<Element> products = new ArrayList<Element>();
ArrayList<Element> modifiers = new ArrayList<Element>();
for (int i = 0; i < rpArray.length; i++) {
Element rp = getXML(rpArray[i]);
if (rp != null) {
if (rpArray[i] instanceof Reactant)
fluxreaction.addContent(rp);
else if (rpArray[i] instanceof Product)
products.add(rp);
else if (rpArray[i] instanceof Catalyst)
modifiers.add(rp);
}
}
for (int i = 0; i < products.size(); i++) fluxreaction.addContent((Element) products.get(i));
for (int i = 0; i < modifiers.size(); i++) fluxreaction.addContent((Element) modifiers.get(i));
// Add Kinetics
fluxreaction.addContent(getXML(param.getKinetics()));
return fluxreaction;
}
use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class ReactionCartoonMolecule method refreshAll.
@Override
protected void refreshAll(boolean reallocateShapes) {
try {
if (getModel() == null || getStructureSuite() == null) {
return;
}
System.out.println("ReactionCartoonMolecule, RefreshAll()");
for (Structure structure : structureSuite.getStructures()) {
Diagram diagram = getModel().getDiagram(structure);
if (diagram != null) {
// Maintain consistency between rule participant nodes, signatures and
// species pattern when a molecule is being modified.
rebindAll(diagram);
}
}
// calculate species context weight (number of reactions for which it's a participant)
Map<SpeciesContext, Integer> scWeightMap = new HashMap<>();
// all the species contexts that are catalysts
Set<SpeciesContext> scCatalystSet = new HashSet<>();
// calculate species context length (number of species patterns it contains, 1 if has no species patterns)
for (ReactionStep rs : getModel().getReactionSteps()) {
ReactionParticipant[] rpList = rs.getReactionParticipants();
for (int i = 0; i < rpList.length; i++) {
ReactionParticipant rp = rpList[i];
SpeciesContext sc = rp.getSpeciesContext();
int increment = 1;
if (rp instanceof Catalyst) {
scCatalystSet.add(sc);
}
if (scWeightMap.containsKey(sc)) {
int weight = scWeightMap.get(sc);
weight += increment;
scWeightMap.put(sc, weight);
} else {
scWeightMap.put(sc, increment);
}
}
}
Set<Shape> unwantedShapes = new HashSet<Shape>();
Set<RuleParticipantSignature> unwantedSignatures = new HashSet<RuleParticipantSignature>();
unwantedShapes.addAll(getShapes());
unwantedSignatures.addAll(ruleParticipantSignatures);
ContainerContainerShape containerShape = (ContainerContainerShape) getShapeFromModelObject(getModel());
List<ReactionContainerShape> reactionContainerShapeList = new ArrayList<ReactionContainerShape>();
List<Structure> structureList = new ArrayList<Structure>(getStructureSuite().getStructures());
// create all ReactionContainerShapes (one for each Structure)
for (Structure structure : structureList) {
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
ReactionContainerShape membraneShape = (ReactionContainerShape) getShapeFromModelObject(membrane);
if (membraneShape == null) {
membraneShape = new ReactionContainerShape(membrane, structureSuite, this);
addShape(membraneShape);
membrane.getMembraneVoltage().removePropertyChangeListener(this);
membrane.getMembraneVoltage().addPropertyChangeListener(this);
} else {
membraneShape.setStructureSuite(structureSuite);
}
membrane.removePropertyChangeListener(this);
membrane.addPropertyChangeListener(this);
membraneShape.refreshLabel();
unwantedShapes.remove(membraneShape);
reactionContainerShapeList.add(membraneShape);
} else if (structure instanceof Feature) {
Feature feature = (Feature) structure;
ReactionContainerShape featureShape = (ReactionContainerShape) getShapeFromModelObject(feature);
if (featureShape == null) {
featureShape = new ReactionContainerShape(feature, structureSuite, this);
addShape(featureShape);
} else {
featureShape.setStructureSuite(structureSuite);
}
feature.removePropertyChangeListener(this);
feature.addPropertyChangeListener(this);
featureShape.refreshLabel();
unwantedShapes.remove(featureShape);
reactionContainerShapeList.add(featureShape);
}
}
if (containerShape == null) {
containerShape = new ContainerContainerShape(this, getModel(), reactionContainerShapeList);
addShape(containerShape);
} else {
containerShape.setReactionContainerShapeList(reactionContainerShapeList);
}
containerShape.refreshLabel();
unwantedShapes.remove(containerShape);
// add all species context shapes within the structures
for (Structure structure : getStructureSuite().getStructures()) {
ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
structure.removePropertyChangeListener(this);
structure.addPropertyChangeListener(this);
for (SpeciesContext structSpeciesContext : getModel().getSpeciesContexts(structure)) {
SpeciesContextShape ss = (SpeciesContextShape) getShapeFromModelObject(structSpeciesContext);
if (ss == null) {
ss = new SpeciesContextShape(structSpeciesContext, this);
ss.truncateLabelName(false);
structSpeciesContext.getSpecies().removePropertyChangeListener(this);
structSpeciesContext.getSpecies().addPropertyChangeListener(this);
reactionContainerShape.addChildShape(ss);
addShape(ss);
ss.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
if (speciesSizeOption == SpeciesSizeOptions.weight) {
// this number sets the diameter of the shape
Integer weight = scWeightMap.get(structSpeciesContext);
if (weight != null) {
// we cap the diameter of the shape to something reasonable
weight = Math.min(weight, 16);
}
ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, weight);
} else if (speciesSizeOption == SpeciesSizeOptions.length) {
Integer length = null;
if (structSpeciesContext.getSpeciesPattern() != null && !structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().isEmpty()) {
length = structSpeciesContext.getSpeciesPattern().getMolecularTypePatterns().size() * 2;
length = Math.min(length, 16);
}
ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, length);
} else {
ss.setFilters(highlightCatalystOption ? scCatalystSet.contains(structSpeciesContext) : false, null);
}
structSpeciesContext.removePropertyChangeListener(this);
structSpeciesContext.addPropertyChangeListener(this);
ss.refreshLabel();
unwantedShapes.remove(ss);
}
}
// add all reactionSteps that are in this structure (ReactionContainerShape), and draw the lines
getModel().removePropertyChangeListener(this);
getModel().addPropertyChangeListener(this);
//
for (ReactionRule rr : getModel().getRbmModelContainer().getReactionRuleList()) {
rr.removePropertyChangeListener(this);
rr.addPropertyChangeListener(this);
Structure structure = rr.getStructure();
if (getStructureSuite().areReactionsShownFor(structure)) {
ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
ReactionRuleFullDiagramShape rrShape = (ReactionRuleFullDiagramShape) getShapeFromModelObject(rr);
if (rrShape == null) {
rrShape = new ReactionRuleFullDiagramShape(rr, this);
addShape(rrShape);
rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
reactionContainerShape.addChildShape(rrShape);
rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
rrShape.refreshLabel();
unwantedShapes.remove(rrShape);
//
// add reaction participants as edges and SignatureShapes as needed
//
List<ReactionRuleParticipant> participants = rr.getReactionRuleParticipants();
List<RuleParticipantEdgeDiagramShape> ruleEdges = new ArrayList<>();
for (ReactionRuleParticipant participant : participants) {
participant.getSpeciesPattern().removePropertyChangeListener(this);
participant.getSpeciesPattern().addPropertyChangeListener(this);
Structure speciesStructure = participant.getStructure();
Structure reactionStructure = rr.getStructure();
if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
//
// find existing RuleParticipantSignatureShape in cartoon
//
RuleParticipantShortSignature ruleParticipantShortSignature = null;
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantLongSignature && signature.getStructure() == participant.getStructure()) {
System.out.println("ReactionCartoonMolecule, refreshAll(), RuleParticipantLongSignature");
break;
}
}
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantShortSignature && signature.getStructure() == participant.getStructure() && signature.compareByCriteria(participant.getSpeciesPattern(), GroupingCriteria.molecule)) {
ruleParticipantShortSignature = (RuleParticipantShortSignature) signature;
break;
}
}
//
// if didn't find signature in cartoons list of signatures, then create one (and create a shape for it).
//
RuleParticipantSignatureShortDiagramShape signatureShape = null;
if (ruleParticipantShortSignature == null) {
ruleParticipantShortSignature = RuleParticipantShortSignature.fromReactionRuleParticipant(participant, this);
ruleParticipantSignatures.add(ruleParticipantShortSignature);
signatureShape = new RuleParticipantSignatureShortDiagramShape(ruleParticipantShortSignature, this);
addShape(signatureShape);
ReactionContainerShape participantContainerShape = (ReactionContainerShape) getShapeFromModelObject(participant.getStructure());
signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
participantContainerShape.addChildShape(signatureShape);
signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
} else {
signatureShape = (RuleParticipantSignatureShortDiagramShape) getShapeFromModelObject(ruleParticipantShortSignature);
}
unwantedShapes.remove(signatureShape);
unwantedSignatures.remove(ruleParticipantShortSignature);
signatureShape.refreshLabel();
signatureShape.setVisible(true);
//
// add edge for ReactionRuleParticipant if not already present.
//
RuleParticipantEdgeDiagramShape ruleParticipantShape = (RuleParticipantEdgeDiagramShape) getShapeFromModelObject(participant);
if (ruleParticipantShape == null || ruleParticipantShape.getRuleParticipantSignatureShape() != signatureShape) {
if (participant instanceof ReactantPattern && signatureShape.isVisible()) {
ruleParticipantShape = new ReactantPatternEdgeDiagramShape((ReactantPattern) participant, rrShape, signatureShape, this);
} else if (participant instanceof ProductPattern && signatureShape.isVisible()) {
ruleParticipantShape = new ProductPatternEdgeDiagramShape((ProductPattern) participant, rrShape, signatureShape, this);
} else {
throw new RuntimeException("unsupported ReactionRuleParticipant " + participant.getClass());
}
addShape(ruleParticipantShape);
}
if (!containerShape.getChildren().contains(ruleParticipantShape)) {
containerShape.addChildShape(ruleParticipantShape);
}
unwantedShapes.remove(ruleParticipantShape);
ruleParticipantShape.refreshLabel();
// all the edges for this rule
ruleEdges.add(ruleParticipantShape);
}
}
// a product edge (a closed loop) between the rule diagram shape and the signature diagram shape
for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
// reset them all
ours.setSibling(false);
}
for (RuleParticipantEdgeDiagramShape ours : ruleEdges) {
for (RuleParticipantEdgeDiagramShape theirs : ruleEdges) {
if (ours == theirs) {
// don't compare with self
continue;
}
if (ours.getRuleParticipantSignatureShape() == theirs.getRuleParticipantSignatureShape()) {
ours.setSibling(true);
theirs.setSibling(true);
}
}
}
}
}
ruleParticipantSignatures.removeAll(unwantedSignatures);
for (ReactionStep reactionStep : getModel().getReactionSteps()) {
reactionStep.removePropertyChangeListener(this);
reactionStep.addPropertyChangeListener(this);
Structure structure = reactionStep.getStructure();
if (getStructureSuite().areReactionsShownFor(structure)) {
ReactionContainerShape reactionContainerShape = (ReactionContainerShape) getShapeFromModelObject(structure);
if (reactionContainerShape == null) {
System.out.println("Reaction container shape is null for structure " + structure + " for reaction step " + reactionStep);
}
ReactionStepShape reactionStepShape = (ReactionStepShape) getShapeFromModelObject(reactionStep);
if (reactionStepShape == null) {
if (reactionStep instanceof SimpleReaction) {
reactionStepShape = new SimpleReactionShape((SimpleReaction) reactionStep, this);
} else if (reactionStep instanceof FluxReaction) {
reactionStepShape = new FluxReactionShape((FluxReaction) reactionStep, this);
} else {
throw new RuntimeException("unknown type of ReactionStep '" + reactionStep.getClass().toString());
}
addShape(reactionStepShape);
reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
reactionContainerShape.addChildShape(reactionStepShape);
reactionStepShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
reactionStepShape.refreshLabel();
unwantedShapes.remove(reactionStepShape);
// add reaction participants as edges
for (ReactionParticipant participant : reactionStep.getReactionParticipants()) {
participant.removePropertyChangeListener(this);
participant.addPropertyChangeListener(this);
Structure speciesStructure = participant.getStructure();
Structure reactionStructure = reactionStep.getStructure();
if (getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
SpeciesContext speciesContext = getModel().getSpeciesContext(participant.getSpecies(), speciesStructure);
// add speciesContextShapes that are not in this structure, but are referenced from the reactionParticipants
// these are only when reactionParticipants are from features that are outside of the membrane being displayed
SpeciesContextShape speciesContextShape = (SpeciesContextShape) getShapeFromModelObject(speciesContext);
if (speciesContextShape == null) {
speciesContextShape = new SpeciesContextShape(speciesContext, this);
speciesContextShape.truncateLabelName(false);
reactionContainerShape.addChildShape(speciesContextShape);
addShape(speciesContextShape);
speciesContextShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
}
speciesContextShape.refreshLabel();
unwantedShapes.remove(speciesContextShape);
ReactionParticipantShape reactionParticipantShape = (ReactionParticipantShape) getShapeFromModelObject(participant);
if (reactionParticipantShape == null) {
if (participant instanceof Reactant) {
reactionParticipantShape = new ReactantShape((Reactant) participant, reactionStepShape, speciesContextShape, this);
} else if (participant instanceof Product) {
reactionParticipantShape = new ProductShape((Product) participant, reactionStepShape, speciesContextShape, this);
} else if (participant instanceof Catalyst) {
reactionParticipantShape = new CatalystShape((Catalyst) participant, reactionStepShape, speciesContextShape, this);
} else {
throw new RuntimeException("unsupported ReactionParticipant " + participant.getClass());
}
addShape(reactionParticipantShape);
}
if (!containerShape.getChildren().contains(reactionParticipantShape)) {
containerShape.addChildShape(reactionParticipantShape);
}
unwantedShapes.remove(reactionParticipantShape);
reactionParticipantShape.refreshLabel();
}
}
}
}
for (Shape unwantedShape : unwantedShapes) {
removeShape(unwantedShape);
}
// update diagrams
for (Structure structure : structureSuite.getStructures()) {
Diagram diagram = getModel().getDiagram(structure);
if (diagram != null) {
applyDefaults(diagram);
}
}
fireGraphChanged(new GraphEvent(this));
} catch (Throwable e) {
handleException(e);
}
}
use of cbit.vcell.model.Reactant in project vcell by virtualcell.
the class SBMLImporter method addReactionParticipants.
/**
* addReactionParticipant : Adds reactants and products and modifiers to a
* reaction. Input args are the sbml reaction, vc reaction This method was
* created mainly to handle reactions where there are reactants and/or
* products that appear multiple times in a reaction. Virtual Cell now
* allows the import of such reactions.
*/
private void addReactionParticipants(org.sbml.jsbml.Reaction sbmlRxn, ReactionStep vcRxn, Map<String, String> sbmlToVclNameMap) throws Exception {
Model vcModel = vcBioModel.getSimulationContext(0).getModel();
// if (!(vcRxn instanceof FluxReaction)) {
if (true) {
// reactants in sbmlRxn
HashMap<String, Integer> sbmlReactantsHash = new HashMap<String, Integer>();
for (int j = 0; j < (int) sbmlRxn.getNumReactants(); j++) {
SpeciesReference spRef = sbmlRxn.getReactant(j);
String sbmlReactantSpId = spRef.getSpecies();
if (sbmlModel.getSpecies(sbmlReactantSpId) != null) {
// check
// if
// spRef
// is in
// sbml
// model
// If stoichiometry of speciesRef is not an integer, it is
// not handled in the VCell at this time; no point going
// further
double stoichiometry = 0.0;
if (level < 3) {
// for SBML models < L3, default
// stoichiometry is 1, if field is not
// set.
// default value of stoichiometry,
stoichiometry = 1.0;
// if not set.
if (spRef.isSetStoichiometry()) {
stoichiometry = spRef.getStoichiometry();
if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
// logger.sendMessage(VCLogger.Priority.HighPriority,
// VCLogger.ErrorType.ReactionError,
// "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
}
}
} else {
if (spRef.isSetStoichiometry()) {
stoichiometry = spRef.getStoichiometry();
if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
// logger.sendMessage(VCLogger.Priority.HighPriority,
// VCLogger.ErrorType.ReactionError,
// "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
// logger.sendMessage(VCLogger.Priority.HighPriority,
// VCLogger.ErrorType.ReactionError,
// "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
}
} else {
throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the reactant '" + sbmlReactantSpId + "' and no default value can be assumed.");
// logger.sendMessage(VCLogger.Priority.HighPriority,
// VCLogger.ErrorType.ReactionError,
// "This is a SBML level 3 model, stoichiometry is not set for the reactant '"
// + spRef.getSpecies() +
// "' and no default value can be assumed.");
}
}
if (sbmlReactantsHash.get(sbmlReactantSpId) == null) {
// if sbmlReactantSpId is NOT in sbmlReactantsHash, add
// it with its stoichiometry
sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf((int) stoichiometry));
} else {
// if sbmlReactantSpId IS in sbmlReactantsHash, update
// its stoichiometry value to (existing-from-hash +
// stoichiometry) and put it back in hash
int intStoich = sbmlReactantsHash.get(sbmlReactantSpId).intValue();
intStoich += (int) stoichiometry;
sbmlReactantsHash.put(sbmlReactantSpId, Integer.valueOf(intStoich));
}
} else {
// spRef is not in model, throw exception
throw new SBMLImportException("Reactant '" + sbmlReactantSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
}
// end - if (spRef is species in model)
}
// sbmlReactionParticipantsHash as reactants to vcRxn
for (Entry<String, Integer> es : sbmlReactantsHash.entrySet()) {
String sbmlReactantSpId = es.getKey();
String vcSpeciesName = sbmlReactantSpId;
if (sbmlToVclNameMap.get(sbmlReactantSpId) != null) {
vcSpeciesName = sbmlToVclNameMap.get(sbmlReactantSpId);
}
SpeciesContext speciesContext = vcModel.getSpeciesContext(vcSpeciesName);
int stoich = es.getValue();
vcRxn.addReactant(speciesContext, stoich);
}
/*
Iterator<String> sbmlReactantsIter = sbmlReactantsHash.keySet()
.iterator();
while (sbmlReactantsIter.hasNext()) {
String sbmlReactantStr = sbmlReactantsIter.next();
SpeciesContext speciesContext = vcModel
.getSpeciesContext(sbmlReactantStr);
int stoich = sbmlReactantsHash.get(sbmlReactantStr).intValue();
((SimpleReaction) vcRxn).addReactant(speciesContext, stoich);
}
*/
// products in sbmlRxn
HashMap<String, Integer> sbmlProductsHash = new HashMap<String, Integer>();
for (int j = 0; j < (int) sbmlRxn.getNumProducts(); j++) {
SpeciesReference spRef = sbmlRxn.getProduct(j);
String sbmlProductSpId = spRef.getSpecies();
if (sbmlModel.getSpecies(sbmlProductSpId) != null) {
/* check if spRef is in sbml model
If stoichiometry of speciesRef is not an integer, it is
not handled in the VCell at this time; no point going
further */
double stoichiometry = 0.0;
if (level < 3) {
// for sBML models < L3, default
// stoichiometry is 1, if field is not
// set.
// default value of stoichiometry,
stoichiometry = 1.0;
// if not set.
if (spRef.isSetStoichiometry()) {
stoichiometry = spRef.getStoichiometry();
if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
// logger.sendMessage(VCLogger.Priority.HighPriority,
// VCLogger.ErrorType.ReactionError,
// "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
}
}
} else {
if (spRef.isSetStoichiometry()) {
stoichiometry = spRef.getStoichiometry();
if (((int) stoichiometry != stoichiometry) || spRef.isSetStoichiometryMath()) {
throw new SBMLImportException("Non-integer stoichiometry ('" + stoichiometry + "' for product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "') or stoichiometryMath not handled in VCell at this time.", Category.NON_INTEGER_STOICH);
// logger.sendMessage(VCLogger.Priority.HighPriority,
// VCLogger.ErrorType.ReactionError,
// "Non-integer stoichiometry or stoichiometryMath not handled in VCell at this time.");
}
} else {
throw new SBMLImportException("This is a SBML level 3 model, stoichiometry is not set for the product '" + sbmlProductSpId + "' and no default value can be assumed.");
// logger.sendMessage(VCLogger.Priority.HighPriority,
// VCLogger.ErrorType.ReactionError,
// "This is a SBML level 3 model, stoichiometry is not set for the product '"
// + spRef.getSpecies() +
// "' and no default value can be assumed.");
}
}
if (sbmlProductsHash.get(sbmlProductSpId) == null) {
// if sbmlProductSpId is NOT in sbmlProductsHash, add it
// with its stoichiometry
sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf((int) stoichiometry));
} else {
// if sbmlProductSpId IS in sbmlProductsHash, update its
// stoichiometry value to (existing-value-from-hash +
// stoichiometry) and put it back in hash
int intStoich = sbmlProductsHash.get(sbmlProductSpId).intValue();
intStoich += (int) stoichiometry;
sbmlProductsHash.put(sbmlProductSpId, Integer.valueOf(intStoich));
}
} else {
// spRef is not in model, throw exception
throw new SBMLImportException("Product '" + sbmlProductSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
}
// end - if (spRef is species in model)
}
// as products to vcRxn
for (Entry<String, Integer> es : sbmlProductsHash.entrySet()) {
String sbmlProductSpId = es.getKey();
String vcSpeciesName = sbmlProductSpId;
if (sbmlToVclNameMap.get(sbmlProductSpId) != null) {
vcSpeciesName = sbmlToVclNameMap.get(sbmlProductSpId);
}
SpeciesContext speciesContext = vcModel.getSpeciesContext(vcSpeciesName);
int stoich = es.getValue();
vcRxn.addProduct(speciesContext, stoich);
}
/*
Iterator<String> sbmlProductsIter = sbmlProductsHash.keySet()
.iterator();
while (sbmlProductsIter.hasNext()) {
String sbmlProductStr = sbmlProductsIter.next();
SpeciesContext speciesContext = vcModel
.getSpeciesContext(sbmlProductStr);
int stoich = sbmlProductsHash.get(sbmlProductStr).intValue();
((SimpleReaction) vcRxn).addProduct(speciesContext, stoich);
}
*/
// proxy.addProducts(sbmlProductsHash);
}
// modifiers
for (int j = 0; j < (int) sbmlRxn.getNumModifiers(); j++) {
ModifierSpeciesReference spRef = sbmlRxn.getModifier(j);
String sbmlSpId = spRef.getSpecies();
String vcSpeciesName = sbmlSpId;
if (sbmlToVclNameMap.get(sbmlSpId) != null) {
vcSpeciesName = sbmlToVclNameMap.get(sbmlSpId);
}
if (sbmlModel.getSpecies(sbmlSpId) != null) {
// check if this modifier species is preesent in vcRxn (could
// have been added as reactamt/product/catalyst).
// If alreay a catalyst in vcRxn, do nothing
ArrayList<ReactionParticipant> vcRxnParticipants = getVCReactionParticipantsFromSymbol(vcRxn, vcSpeciesName);
SpeciesContext speciesContext = vcModel.getSpeciesContext(vcSpeciesName);
if (vcRxnParticipants == null || vcRxnParticipants.size() == 0) {
// If not in reactionParticipantList of vcRxn, add as
// catalyst.
vcRxn.addCatalyst(speciesContext);
} else {
for (ReactionParticipant rp : vcRxnParticipants) {
if (rp instanceof Reactant || rp instanceof Product) {
// If already a reactant or product in vcRxn, add
// warning to localIssuesList, don't do anything
localIssueList.add(new Issue(speciesContext, issueContext, IssueCategory.SBMLImport_Reaction, "Species " + speciesContext.getName() + " was already added as a reactant and/or product to " + vcRxn.getName() + "; Cannot add it as a catalyst also.", Issue.SEVERITY_INFO));
break;
}
}
}
} else {
// spRef is not in model, throw exception
throw new SBMLImportException("Modifier '" + sbmlSpId + "' in reaction '" + sbmlRxn.getId() + "' not found as species in SBML model.");
}
// end - if (spRef is species in model)
}
// end - for modifiers
}
Aggregations