use of cbit.vcell.model.ReactantPattern in project vcell by virtualcell.
the class ViewGeneratedReactionsPanel method initialize.
private void initialize() {
try {
setName("ViewGeneratedReactionsPanel");
setLayout(new GridBagLayout());
shapePanel = new RulesShapePanel() {
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (AbstractComponentShape stls : reactantPatternShapeList) {
stls.paintSelf(g);
}
for (AbstractComponentShape stls : productPatternShapeList) {
stls.paintSelf(g);
}
}
};
Border loweredEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
Border loweredBevelBorder = BorderFactory.createLoweredBevelBorder();
shapePanel.setLayout(new GridBagLayout());
shapePanel.setBackground(Color.white);
// don't show the brown contour even though it's not editable
shapePanel.setEditable(true);
shapePanel.setShowMoleculeColor(true);
shapePanel.setShowNonTrivialOnly(true);
JScrollPane scrollPane = new JScrollPane(shapePanel);
scrollPane.setBorder(loweredBevelBorder);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
JPanel optionsPanel = new JPanel();
optionsPanel.setLayout(new GridBagLayout());
getZoomSmallerButton().setEnabled(true);
getZoomLargerButton().setEnabled(false);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(0, 0, 0, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomLargerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 1;
gbc.insets = new Insets(2, 0, 4, 10);
gbc.anchor = GridBagConstraints.WEST;
optionsPanel.add(getZoomSmallerButton(), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.insets = new Insets(4, 4, 4, 10);
optionsPanel.add(new JLabel(""), gbc);
JPanel containerOfScrollPanel = new JPanel();
containerOfScrollPanel.setLayout(new BorderLayout());
containerOfScrollPanel.add(optionsPanel, BorderLayout.WEST);
containerOfScrollPanel.add(scrollPane, BorderLayout.CENTER);
Dimension dim = new Dimension(500, 140);
// dimension of shape panel
containerOfScrollPanel.setPreferredSize(dim);
containerOfScrollPanel.setMinimumSize(dim);
containerOfScrollPanel.setMaximumSize(dim);
// -----------------------------------------------------------------------------
table = new EditorScrollTable();
tableModel = new GeneratedReactionTableModel(table, owner);
table.setModel(tableModel);
table.getSelectionModel().addListSelectionListener(eventHandler);
table.getModel().addTableModelListener(eventHandler);
DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
// table.getColumnModel().getColumn(GeneratedReactionTableModel.iColIndex).setCellRenderer(rightRenderer); // right align first table column
// table.getColumnModel().getColumn(GeneratedReactionTableModel.iColIndex).setMaxWidth(60); // left column wide enough for 6-7 digits
int gridy = 0;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridwidth = 8;
gbc.fill = GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
// table.setPreferredScrollableViewportSize(new Dimension(400,200));
add(table.getEnclosingScrollPane(), gbc);
// add toolTipText for each table cell
table.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
Point p = e.getPoint();
int row = table.rowAtPoint(p);
int column = table.columnAtPoint(p);
table.setToolTipText(String.valueOf(table.getValueAt(row, column)));
}
});
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(4, 4, 4, 4);
add(new JLabel("Search "), gbc);
textFieldSearch = new JTextField(70);
textFieldSearch.addActionListener(eventHandler);
textFieldSearch.getDocument().addDocumentListener(eventHandler);
textFieldSearch.putClientProperty("JTextField.variant", "search");
gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.gridwidth = 3;
gbc.anchor = GridBagConstraints.LINE_START;
gbc.fill = java.awt.GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 0, 4, 4);
add(textFieldSearch, gbc);
gbc = new GridBagConstraints();
gbc.gridx = 4;
gbc.gridy = gridy;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.insets = new Insets(4, 4, 4, 10);
add(totalReactionsLabel, gbc);
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
// gbc.weightx = 1.0;
// gbc.weighty = 1.0;
gbc.gridwidth = 8;
gbc.anchor = GridBagConstraints.LINE_END;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.insets = new Insets(4, 4, 4, 4);
add(containerOfScrollPanel, gbc);
// rendering the small shapes of a fake rule in the Depiction column of this viewer table)
// TODO: this renderer is almost identical with the one in BioModelEditorModelPanel (which paints the small shapes
// of a rule in the Depiction column of the reaction table)
DefaultScrollTableCellRenderer rbmReactionShapeDepictionCellRenderer = new DefaultScrollTableCellRenderer() {
List<SpeciesPatternSmallShape> spssList = new ArrayList<SpeciesPatternSmallShape>();
SpeciesPatternSmallShape spss = null;
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (table.getModel() instanceof VCellSortTableModel<?>) {
Object selectedObject = null;
if (table.getModel() == tableModel) {
selectedObject = tableModel.getValueAt(row);
}
if (selectedObject != null) {
if (selectedObject instanceof GeneratedReactionTableRow) {
ReactionRule rr = ((GeneratedReactionTableRow) selectedObject).getReactionRule();
Graphics panelContext = table.getGraphics();
BioModel bioModel = owner.getSimulationContext().getBioModel();
spssList.clear();
List<ReactantPattern> rpList = rr.getReactantPatterns();
int xPos = 4;
for (int i = 0; i < rpList.size(); i++) {
SpeciesPattern sp = rr.getReactantPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
if (i < rpList.size() - 1) {
spss.addEndText("+");
} else {
if (rr.isReversible()) {
spss.addEndText("<->");
xPos += 7;
} else {
spss.addEndText("->");
}
}
xPos += spss.getWidth() + 14;
spssList.add(spss);
}
List<ProductPattern> ppList = rr.getProductPatterns();
xPos += 7;
for (int i = 0; i < ppList.size(); i++) {
SpeciesPattern sp = rr.getProductPattern(i).getSpeciesPattern();
spss = new SpeciesPatternSmallShape(xPos, 2, sp, null, panelContext, rr, isSelected, issueManager);
if (i < ppList.size() - 1) {
spss.addEndText("+");
}
xPos += spss.getWidth() + 14;
spssList.add(spss);
}
}
} else {
spssList.clear();
}
}
setText("");
return this;
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
for (SpeciesPatternSmallShape spss : spssList) {
if (spss == null) {
continue;
}
spss.paintSelf(g);
}
}
};
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setCellRenderer(rbmReactionShapeDepictionCellRenderer);
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setPreferredWidth(400);
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDepiction).setMinWidth(400);
table.getColumnModel().getColumn(GeneratedReactionTableModel.iColDefinition).setPreferredWidth(30);
table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
}
}
use of cbit.vcell.model.ReactantPattern in project vcell by virtualcell.
the class RulebasedMathMapping method addStrictMassActionParticleJumpProcess.
private void addStrictMassActionParticleJumpProcess(VariableHash varHash, GeometryClass geometryClass, SubDomain subDomain, ReactionRule reactionRule, String jpName, ArrayList<ParticleVariable> reactantParticles, ArrayList<ParticleVariable> productParticles, ArrayList<Action> forwardActions, ArrayList<Action> reverseActions) throws ExpressionException, ExpressionBindingException, PropertyVetoException, MathException, MappingException {
String reactionRuleName = reactionRule.getName();
RbmKineticLaw kinetics = reactionRule.getKineticLaw();
RulebasedTransformation ruleBasedTransformation = ((RulebasedTransformation) getTransformation());
if (kinetics.getRateLawType() != RbmKineticLaw.RateLawType.MassAction) {
throw new RuntimeException("expecting mass action kinetics for reaction rule " + reactionRuleName);
}
//
// construct stochastic forward or reverse rate expression (separately). Transform from
// original expression of "concentrationRate" in terms of rateParameter and reactants/products in concentrations
// to
// new stochastic expression of "molecularRate" in terms of forwardRateParameter, reactants/products in molecules, structure sizes, and unit conversions.
//
// (1) concentrationRate = K * [s0] * [s1] [uM.s-1] or [molecules.um-3.s-1] or [molecules.um-2.s-1] (or other)
// (2) molecularRate = P * <s0> * <s1> [molecules.s-1]
//
// in this math description, we are using <s_i> [molecules], but original kinetics were in [s_i] [uM or molecules.um-2].
// so through a change in variable to get things in terms of <s_i>. <<<< Here P is the desired stochastic rate coefficient. >>>
//
// (3) let [s_i] = <s_i>/structsize(s_i)*unitConversionFactor(substanceunit([s_i])/substanceunit(<s_i>))
//
// in addition to the change in variables, we need to transform the entire expression from concentration/time to molecules/time
//
// (4) let molecularRate = concentrationRate * structSize(reaction) * unitConversionFactor(substanceunit(molecularRate)/substanceunit(concentrationRate))
//
// (5) in general, concentationRate = K * PRODUCT([s_i])
//
// change of variables into stochastic variables used in MathDescription, substituting (3) into (5)
//
// (6) concentrationRate = K * PRODUCT(<s_i>/structsize(s_i)*unitConversionFactor(substanceunit([s_i])/substanceunit(<s_i>)))
//
// reordering to separate the sizes, the unit conversions and the <s_i>
//
// (7) concentrationRate = K * PRODUCT(<s_i>) * PRODUCT(1/structsize(s_i)) * unitConversionFactor(PRODUCT(substanceunit([s_i])/substanceunit(<s_i>)))
//
// combining (4) and (7)
//
// (8) molecularRate = K * PRODUCT(<s_i>) * PRODUCT(1/structsize(s_i)) * unitConversionFactor(PRODUCT(substanceunit([s_i])/substanceunit(<s_i>))) * structSize(reaction) * unitConversionFactor(substanceunit(molecularRate)/substanceunit(concentrationRate))
//
// collecting terms of sizes and unit conversions
//
// (9) molecularRate = K * PRODUCT(<s_i>) * structSize(reaction) / PRODUCT(structsize(s_i)) * unitConversionFactor(substanceunit(molecularRate)/substanceunit(concentrationRate) * PRODUCT(substanceunit([s_i])/substanceunit(<s_i>)))
//
// (10) molecularRate = K * PRODUCT(<s_i>) * sizeFactor * unitConversionFactor(substanceConversionUnit)
//
// where
//
// (11) sizeFactor = structSize(reaction) / PRODUCT(structsize(s_i))
// (12) substanceConversionUnit = substanceunit(molecularRate)/substanceunit(concentrationRate) * PRODUCT(substanceunit([s_i])/substanceunit(<s_i>))
//
// The ParticleJumpCondition wants a single new rate stochastic, P from equation (2). Note that PRODUCT(<s_i>) will be captured separately the the reactantPatterns.
// comparing (2) and (10) we have found P.
//
// (13) P = K * sizeFactor * unitConversionFactor(substanceConversionUnit)
//
// the framework also needs the proper unit for P
//
// (14) Unit(P) = Unit(K) * Unit(sizeFactor) * substanceConversionUnit
//
//
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
VCUnitDefinition stochasticSubstanceUnit = modelUnitSystem.getStochasticSubstanceUnit();
VCUnitDefinition reactionRuleSubstanceUnit = modelUnitSystem.getSubstanceUnit(reactionRule.getStructure());
int forwardRuleIndex = 0;
//
// get forward rate parameter and make sure it is constant valued.
//
Parameter forward_rateParameter = kinetics.getLocalParameter(RbmKineticLawParameterType.MassActionForwardRate);
Expression substitutedForwardRate = MathUtilities.substituteModelParameters(forward_rateParameter.getExpression(), reactionRule.getNameScope().getScopedSymbolTable());
if (!substitutedForwardRate.flatten().isNumeric()) {
throw new MappingException("forward rate constant for reaction rule " + reactionRule.getName() + " is not constant");
}
//
// create forward sizeExp and forward unitFactor
//
VCUnitDefinition forward_substanceConversionUnit = stochasticSubstanceUnit.divideBy(reactionRuleSubstanceUnit);
VCUnitDefinition forward_sizeFactorUnit = reactionRule.getStructure().getStructureSize().getUnitDefinition();
Expression forward_sizeFactor = new Expression(reactionRule.getStructure().getStructureSize(), getNameScope());
for (ReactantPattern reactantPattern : reactionRule.getReactantPatterns()) {
Expression reactantSizeExp = new Expression(reactantPattern.getStructure().getStructureSize(), getNameScope());
VCUnitDefinition reactantSizeUnit = reactantPattern.getStructure().getStructureSize().getUnitDefinition();
VCUnitDefinition reactantSubstanceUnit = modelUnitSystem.getSubstanceUnit(reactantPattern.getStructure());
forward_sizeFactor = Expression.div(forward_sizeFactor, reactantSizeExp);
forward_sizeFactorUnit = forward_sizeFactorUnit.divideBy(reactantSizeUnit);
forward_substanceConversionUnit = forward_substanceConversionUnit.multiplyBy(reactantSubstanceUnit).divideBy(stochasticSubstanceUnit);
}
// simplify sizeFactor (often has size/size/size)
try {
forward_sizeFactor = RationalExpUtils.getRationalExp(forward_sizeFactor).simplifyAsExpression();
forward_sizeFactor.bindExpression(getSimulationContext().getModel());
} catch (ParseException e) {
e.printStackTrace();
}
Expression forward_rateExp = Expression.mult(new Expression(forward_rateParameter, getNameScope()), forward_sizeFactor, getUnitFactor(forward_substanceConversionUnit)).flatten();
VCUnitDefinition forward_rateUnit = forward_rateParameter.getUnitDefinition().multiplyBy(forward_sizeFactorUnit).multiplyBy(forward_substanceConversionUnit);
ProbabilityParameter forward_probParm = addProbabilityParameter(PARAMETER_PROBABILITYRATE_PREFIX + jpName, forward_rateExp, PARAMETER_ROLE_P, forward_rateUnit, reactionRule);
// add probability to function or constant
varHash.addVariable(newFunctionOrConstant(getMathSymbol(forward_probParm, geometryClass), getIdentifierSubstitutions(forward_rateExp, forward_rateUnit, geometryClass), geometryClass));
// add forward ParticleJumpProcess
String forward_name = reactionRuleName;
Expression forward_rate = getIdentifierSubstitutions(new Expression(forward_probParm, getNameScope()), forward_probParm.getUnitDefinition(), geometryClass);
JumpProcessRateDefinition forward_rateDefinition = new MacroscopicRateConstant(forward_rate);
ReactionRuleAnalysisReport rrarBiomodelForward = ruleBasedTransformation.getRulesForwardMap().get(reactionRule);
ProcessSymmetryFactor forwardSymmetryFactor = new ProcessSymmetryFactor(rrarBiomodelForward.getSymmetryFactor());
ParticleJumpProcess forward_particleJumpProcess = new ParticleJumpProcess(forward_name, reactantParticles, forward_rateDefinition, forwardActions, forwardSymmetryFactor);
subDomain.addParticleJumpProcess(forward_particleJumpProcess);
//
for (ReactionRule rr : getSimulationContext().getModel().getRbmModelContainer().getReactionRuleList()) {
if (rr == reactionRule) {
break;
}
forwardRuleIndex++;
if (rr.isReversible()) {
forwardRuleIndex++;
}
}
//
if (reactionRule.isReversible()) {
Parameter reverse_rateParameter = kinetics.getLocalParameter(RbmKineticLawParameterType.MassActionReverseRate);
if (reverse_rateParameter == null || reverse_rateParameter.getExpression() == null) {
throw new MappingException("reverse rate constant for reaction rule " + reactionRule.getName() + " is missing");
}
{
Expression substitutedReverseRate = MathUtilities.substituteModelParameters(reverse_rateParameter.getExpression(), reactionRule.getNameScope().getScopedSymbolTable());
if (!substitutedReverseRate.flatten().isNumeric()) {
throw new MappingException("reverse rate constant for reaction rule " + reactionRule.getName() + " is not constant");
}
}
//
// create reverse sizeExp and reverse unitFactor
//
VCUnitDefinition reverse_substanceConversionUnit = stochasticSubstanceUnit.divideBy(reactionRuleSubstanceUnit);
VCUnitDefinition reverse_sizeFactorUnit = reactionRule.getStructure().getStructureSize().getUnitDefinition();
Expression reverse_sizeFactor = new Expression(reactionRule.getStructure().getStructureSize(), getNameScope());
for (ProductPattern productPattern : reactionRule.getProductPatterns()) {
Expression reactantSizeExp = new Expression(productPattern.getStructure().getStructureSize(), getNameScope());
VCUnitDefinition reactantSizeUnit = productPattern.getStructure().getStructureSize().getUnitDefinition();
VCUnitDefinition reactantSubstanceUnit = modelUnitSystem.getSubstanceUnit(productPattern.getStructure());
reverse_sizeFactor = Expression.div(reverse_sizeFactor, reactantSizeExp);
reverse_sizeFactorUnit = reverse_sizeFactorUnit.divideBy(reactantSizeUnit);
reverse_substanceConversionUnit = reverse_substanceConversionUnit.multiplyBy(reactantSubstanceUnit).divideBy(stochasticSubstanceUnit);
}
// simplify sizeFactor (often has size/size/size)
try {
reverse_sizeFactor = RationalExpUtils.getRationalExp(reverse_sizeFactor).simplifyAsExpression();
reverse_sizeFactor.bindExpression(getSimulationContext().getModel());
} catch (ParseException e) {
e.printStackTrace();
}
Expression reverse_rateExp = Expression.mult(new Expression(reverse_rateParameter, getNameScope()), reverse_sizeFactor, getUnitFactor(reverse_substanceConversionUnit)).flatten();
VCUnitDefinition reverse_rateUnit = reverse_rateParameter.getUnitDefinition().multiplyBy(reverse_sizeFactorUnit).multiplyBy(reverse_substanceConversionUnit);
// if the reaction has forward rate (Mass action,HMMs), or don't have either forward or reverse rate (some other rate laws--like general)
// we process it as forward reaction
// get jump process name
ProbabilityParameter reverse_probParm = addProbabilityParameter(PARAMETER_PROBABILITYRATE_PREFIX + jpName + "_reverse", reverse_rateExp, PARAMETER_ROLE_P_reverse, reverse_rateUnit, reactionRule);
// add probability to function or constant
varHash.addVariable(newFunctionOrConstant(getMathSymbol(reverse_probParm, geometryClass), getIdentifierSubstitutions(reverse_rateExp, reverse_rateUnit, geometryClass), geometryClass));
// add reverse ParticleJumpProcess
Expression reverse_rate = getIdentifierSubstitutions(new Expression(reverse_probParm, getNameScope()), reverse_probParm.getUnitDefinition(), geometryClass);
String reverse_name = reactionRuleName + "_reverse";
JumpProcessRateDefinition reverse_rateDefinition = new MacroscopicRateConstant(reverse_rate);
ReactionRuleAnalysisReport rrarBiomodelReverse = ruleBasedTransformation.getRulesReverseMap().get(reactionRule);
ProcessSymmetryFactor reverseSymmetryFactor = new ProcessSymmetryFactor(rrarBiomodelReverse.getSymmetryFactor());
ParticleJumpProcess reverse_particleJumpProcess = new ParticleJumpProcess(reverse_name, productParticles, reverse_rateDefinition, reverseActions, reverseSymmetryFactor);
subDomain.addParticleJumpProcess(reverse_particleJumpProcess);
//
// check reverse direction mapping and operations with RuleAnalysis.
//
int reverseRuleIndex = forwardRuleIndex + 1;
ReactionRuleAnalysisReport rrar = ruleBasedTransformation.getRulesReverseMap().get(reactionRule);
jumpProcessMap.put(reverse_particleJumpProcess, rrar);
}
}
use of cbit.vcell.model.ReactantPattern in project vcell by virtualcell.
the class SpeciesPatternLargeShape method getStructure.
public Structure getStructure() {
Structure structure = null;
if (owner instanceof ReactionRule) {
ReactionRule rr = (ReactionRule) owner;
ReactantPattern rp = rr.getReactantPattern(sp);
ProductPattern pp = rr.getProductPattern(sp);
if (rp != null) {
structure = rp.getStructure();
} else if (pp != null) {
structure = pp.getStructure();
} else {
structure = ((ReactionRule) owner).getStructure();
}
} else if (owner instanceof SpeciesContext && ((SpeciesContext) owner).hasSpeciesPattern()) {
structure = ((SpeciesContext) owner).getStructure();
} else if (owner instanceof RbmObservable) {
structure = ((RbmObservable) owner).getStructure();
}
return structure;
}
use of cbit.vcell.model.ReactantPattern 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.ReactantPattern 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);
}
}
Aggregations