use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ITextWriter method writeReactions.
// each reaction has its own table, ordered by the structures.
protected void writeReactions(Chapter physioChapter, Model model) throws DocumentException {
if (model == null) {
return;
}
Paragraph reactionParagraph = new Paragraph();
reactionParagraph.add(new Chunk("Structures and Reactions Diagram").setLocalDestination(model.getName()));
Section reactionDiagramSection = physioChapter.addSection(reactionParagraph, physioChapter.numberDepth() + 1);
try {
addImage(reactionDiagramSection, encodeJPEG(generateDocReactionsImage(model, null)));
} catch (Exception e) {
e.printStackTrace();
throw new DocumentException(e.getClass().getName() + ": " + e.getMessage());
}
for (int i = 0; i < model.getNumStructures(); i++) {
ReactionStep[] reactionSteps = model.getReactionSteps();
ReactionStep rs = null;
Table modifierTable = null;
Table reactionTable = null;
boolean firstTime = true;
Section reactStructSection = null;
for (int j = 0; j < reactionSteps.length; j++) {
if (reactionSteps[j].getStructure() == model.getStructure(i)) {
// can also use structureName1.equals(structureName2)
if (firstTime) {
Paragraph linkParagraph = new Paragraph();
linkParagraph.add(new Chunk("Reaction(s) in " + model.getStructure(i).getName()).setLocalDestination(model.getStructure(i).getName()));
reactStructSection = physioChapter.addSection(linkParagraph, physioChapter.numberDepth() + 1);
firstTime = false;
}
rs = reactionSteps[j];
String type;
if (rs instanceof SimpleReaction) {
type = "Reaction";
} else {
type = "Flux";
}
// write Reaction equation as a table
// Get the image arrow cell depending on type of reactionStep : MassAction => double arrow, otherwise, forward arrow
boolean bReversible = false;
if (rs.getKinetics() instanceof MassActionKinetics) {
bReversible = true;
}
Cell arrowImageCell = getReactionArrowImageCell(bReversible);
// Get reactants and products strings
ReactionCanvas rc = new ReactionCanvas();
rc.setReactionStep(rs);
ReactionCanvasDisplaySpec rcdSpec = rc.getReactionCanvasDisplaySpec();
String reactants = rcdSpec.getLeftText();
String products = rcdSpec.getRightText();
// Create table and add cells for reactants, arrow(s) images, products
int[] widths = { 8, 1, 8 };
reactionTable = getTable(3, 100, 0, 2, 2);
// Add reactants as cell
Cell tableCell = createCell(reactants, getBold());
tableCell.setHorizontalAlignment(Cell.ALIGN_RIGHT);
tableCell.setBorderColor(Color.white);
reactionTable.addCell(tableCell);
// add arrow(s) image as cell
if (arrowImageCell != null) {
arrowImageCell.setHorizontalAlignment(Cell.ALIGN_CENTER);
arrowImageCell.setBorderColor(Color.white);
reactionTable.addCell(arrowImageCell);
}
// add products as cell
tableCell = createCell(products, getBold());
tableCell.setBorderColor(Color.white);
reactionTable.addCell(tableCell);
// reactionTable.setBorderColor(Color.white);
reactionTable.setWidths(widths);
// Identify modifiers,
ReactionParticipant[] rpArr = rs.getReactionParticipants();
Vector<ReactionParticipant> modifiersVector = new Vector<ReactionParticipant>();
for (int k = 0; k < rpArr.length; k += 1) {
if (rpArr[k] instanceof Catalyst) {
modifiersVector.add(rpArr[k]);
}
}
// Write the modifiers in a separate table, if present
if (modifiersVector.size() > 0) {
modifierTable = getTable(1, 50, 0, 1, 1);
modifierTable.addCell(createCell("Modifiers List", getBold(DEF_HEADER_FONT_SIZE), 1, 1, Element.ALIGN_CENTER, true));
StringBuffer modifierNames = new StringBuffer();
for (int k = 0; k < modifiersVector.size(); k++) {
modifierNames.append(((Catalyst) modifiersVector.elementAt(k)).getName() + "\n");
}
modifierTable.addCell(createCell(modifierNames.toString().trim(), getFont()));
modifiersVector.removeAllElements();
}
Section reactionSection = reactStructSection.addSection(type + " " + rs.getName(), reactStructSection.numberDepth() + 1);
// Annotation
VCMetaData vcMetaData = rs.getModel().getVcMetaData();
if (vcMetaData.getFreeTextAnnotation(rs) != null) {
Table annotTable = getTable(1, 100, 1, 3, 3);
annotTable.addCell(createCell("Reaction Annotation", getBold(DEF_HEADER_FONT_SIZE), 1, 1, Element.ALIGN_CENTER, true));
annotTable.addCell(createCell(vcMetaData.getFreeTextAnnotation(rs), getFont()));
reactionSection.add(annotTable);
// reactionSection.add(new Paragraph("\""+rs.getAnnotation()+"\""));
}
// reaction table
if (reactionTable != null) {
reactionSection.add(reactionTable);
// re-set reactionTable
reactionTable = null;
}
if (modifierTable != null) {
reactionSection.add(modifierTable);
modifierTable = null;
}
// Write kinetics parameters, etc. in a table
writeKineticsParams(reactionSection, rs);
}
}
}
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ReactionPropertiesPanel method initKineticChoices.
private void initKineticChoices() {
KineticsDescription[] kineticTypes = reactionStep == null || reactionStep instanceof SimpleReaction ? Simple_Reaction_Kinetic_Types : Flux_Reaction_KineticTypes;
javax.swing.DefaultComboBoxModel model = new DefaultComboBoxModel();
for (int i = 0; i < kineticTypes.length; i++) {
if (!(kineticTypes[i].equals(KineticsDescription.Macroscopic_irreversible) || kineticTypes[i].equals(KineticsDescription.Microscopic_irreversible))) {
model.addElement(kineticTypes[i]);
} else // macroscopic/microscopic irreversible
{
// reactions on membrane in a 3D geometry
if (reactionStep != null && reactionStep.getStructure() != null && reactionStep.getStructure() instanceof Membrane) {
// check if reactants are all on membrane and calculate sum of reactants' stoichiometry
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
int order = 0;
boolean bAllMembraneReactants = true;
for (ReactionParticipant rp : rps) {
if (rp instanceof Reactant) {
if (!(rp.getStructure() instanceof Membrane)) {
bAllMembraneReactants = false;
break;
}
order += rp.getStoichiometry();
}
}
// add only if 2nd order membrane reaction
if (order == 2 && bAllMembraneReactants && !reactionStep.hasCatalyst()) {
model.addElement(kineticTypes[i]);
}
}
}
}
getKineticsTypeComboBox().setModel(model);
return;
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ModelProcessEquation method parseReaction.
public static ReactionParticipant[] parseReaction(ReactionStep reactionStep, Model model, String equationString) throws ExpressionException, PropertyVetoException {
int gotoIndex = equationString.indexOf(REACTION_GOESTO);
if (gotoIndex < 1 && equationString.length() == 0) {
throw new ExpressionException("Syntax error! " + REACTION_GOESTO + " not found. (e.g. a+b->c)");
}
if (reactionStep == null) {
return null;
}
String leftHand = equationString.substring(0, gotoIndex);
String rightHand = equationString.substring(gotoIndex + REACTION_GOESTO.length());
StringTokenizer st = new StringTokenizer(leftHand, "+");
ArrayList<ReactionParticipant> rplist = new ArrayList<ReactionParticipant>();
HashMap<String, SpeciesContext> speciesContextMap = new HashMap<String, SpeciesContext>();
Structure rxnStructure = reactionStep.getStructure();
while (st.hasMoreElements()) {
String nextToken = st.nextToken().trim();
if (nextToken.length() == 0) {
continue;
}
int stoichiIndex = 0;
while (true) {
if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
stoichiIndex++;
} else {
break;
}
}
int stoichi = 1;
String tmp = nextToken.substring(0, stoichiIndex);
if (tmp.length() > 0) {
stoichi = Integer.parseInt(tmp);
}
String var = nextToken.substring(stoichiIndex).trim();
SpeciesContext sc = model.getSpeciesContext(var);
if (sc == null) {
sc = speciesContextMap.get(var);
if (sc == null) {
Species species = model.getSpecies(var);
if (species == null) {
species = new Species(var, null);
}
sc = new SpeciesContext(species, rxnStructure);
sc.setName(var);
speciesContextMap.put(var, sc);
}
}
// if (reactionStep instanceof SimpleReaction) {
rplist.add(new Reactant(null, (SimpleReaction) reactionStep, sc, stoichi));
// } else if (reactionStep instanceof FluxReaction) {
// rplist.add(new Flux(null, (FluxReaction) reactionStep, sc));
// }
}
st = new StringTokenizer(rightHand, "+");
while (st.hasMoreElements()) {
String nextToken = st.nextToken().trim();
if (nextToken.length() == 0) {
continue;
}
int stoichiIndex = 0;
while (true) {
if (Character.isDigit(nextToken.charAt(stoichiIndex))) {
stoichiIndex++;
} else {
break;
}
}
int stoichi = 1;
String tmp = nextToken.substring(0, stoichiIndex);
if (tmp.length() > 0) {
stoichi = Integer.parseInt(tmp);
}
String var = nextToken.substring(stoichiIndex);
SpeciesContext sc = model.getSpeciesContext(var);
if (sc == null) {
sc = speciesContextMap.get(var);
if (sc == null) {
Species species = model.getSpecies(var);
if (species == null) {
species = new Species(var, null);
}
sc = new SpeciesContext(species, rxnStructure);
sc.setName(var);
speciesContextMap.put(var, sc);
}
}
// if (reactionStep instanceof SimpleReaction) {
rplist.add(new Product(null, (SimpleReaction) reactionStep, sc, stoichi));
// } else if (reactionStep instanceof FluxReaction) {
// rplist.add(new Flux(null, (FluxReaction) reactionStep, sc));
// }
}
return rplist.toArray(new ReactionParticipant[0]);
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ReactionCartoonTool method menuAction.
@Override
protected void menuAction(Shape shape, String menuAction) {
if (shape == null) {
return;
}
if (menuAction.equals(CartoonToolMiscActions.Properties.MENU_ACTION)) {
if (shape instanceof FluxReactionShape) {
// showFluxReactionPropertiesDialog((FluxReactionShape) shape);
} else if (shape instanceof SimpleReactionShape) {
// showSimpleReactionPropertiesDialog((SimpleReactionShape) shape);
} else if (shape instanceof ReactantShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showReactantPropertiesDialog((ReactantShape) shape,
// locationOnScreen);
} else if (shape instanceof ProductShape) {
// Point locationOnScreen = shape.getSpaceManager().getAbsLoc();
// Point graphPaneLocation = getGraphPane().getLocationOnScreen();
// locationOnScreen.translate(graphPaneLocation.x,
// graphPaneLocation.y);
// showProductPropertiesDialog((ProductShape) shape,
// locationOnScreen);
} else if (shape instanceof SpeciesContextShape) {
// showEditSpeciesDialog(getGraphPane(), getReactionCartoon()
// .getModel(), ((SpeciesContextShape) shape)
// .getSpeciesContext());
} else if (shape instanceof ReactionContainerShape) {
// ReactionContainerShape rcs = (ReactionContainerShape) shape;
// if (rcs.getStructure() instanceof Feature) {
// //
// // showFeaturePropertyDialog is invoked in two modes:
// //
// // 1) parent!=null and child==null
// // upon ok, it adds a new feature to the supplied parent.
// //
// // 2) parent==null and child!=null
// // upon ok, edits the feature name
// //
// showFeaturePropertiesDialog(getGraphPane(),
// (getReactionCartoon().getModel() == null ? null
// : getReactionCartoon().getModel()), null,
// (Feature) rcs.getStructure());
// } else if (rcs.getStructure() instanceof Membrane) {
// showMembranePropertiesDialog(getGraphPane(), (Membrane) rcs
// .getStructure());
// }
}
} else if (menuAction.equals(CartoonToolMiscActions.AddSpecies.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
getGraphModel().deselectShape(shape);
// showCreateSpeciesContextDialog(getGraphPane(),
// getReactionCartoon().getModel(),
// ((ReactionContainerShape) shape).getStructure(), null);
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) shape).getStructure());
getGraphModel().select(speciesContext);
}
} else if (menuAction.equals(CartoonToolEditActions.Copy.MENU_ACTION)) {
if (shape instanceof SpeciesContextShape || shape instanceof ReactionStepShape || // rule participants whose rule is not selected won't
shape instanceof RuleParticipantSignatureDiagramShape || // be copied since standalone they are meaningless
shape instanceof ReactionRuleDiagramShape) {
SpeciesContext[] spArray = getSelectedSpeciesContextArray();
ReactionStep[] rsArray = getSelectedReactionStepArray();
ReactionRule[] rrArray = getSelectedReactionRuleArray();
MolecularType[] mtArray = getSelectedMolecularTypeArray(rrArray, rsArray, spArray);
Structure[] structArray = getSelectedStructuresArray(rrArray, rsArray, spArray, mtArray);
Structure fromStruct = null;
ReactionContainerShape rcs = null;
Shape parentShape = shape.getParent();
if (parentShape instanceof ReactionContainerShape) {
rcs = (ReactionContainerShape) parentShape;
fromStruct = rcs.getStructure();
}
ReactionSpeciesCopy reactionSpeciesCopy = new ReactionSpeciesCopy(spArray, rsArray, rrArray, mtArray, fromStruct, structArray);
VCellTransferable.sendToClipboard(reactionSpeciesCopy);
}
} else if (/*menuAction.equals(CartoonToolEditActions.Paste.MENU_ACTION)
|| */
menuAction.equals(CartoonToolEditActions.PasteNew.MENU_ACTION)) {
if (shape instanceof ReactionContainerShape) {
pasteReactionsAndSpecies(((ReactionContainerShape) shape).getStructure());
}
} else if (menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
try {
if (getGraphModel().getSelectedShape() instanceof ReactionContainerShape && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
getModel().removeStructure(((ReactionContainerShape) getGraphModel().getSelectedShape()).getStructure());
return;
}
if (getSelectedReactionStepArray() != null || getSelectedSpeciesContextArray() != null) {
deleteReactionsAndSpecies(getGraphPane(), getSelectedReactionStepArray(), getSelectedSpeciesContextArray());
}
if (getSelectedReactionParticipantArray() != null && menuAction.equals(CartoonToolEditActions.Delete.MENU_ACTION)) {
ReactionParticipant[] reactionParticipantArr = getSelectedReactionParticipantArray();
String response = DialogUtils.showWarningDialog(getGraphPane(), "Delete " + reactionParticipantArr.length + " Reaction Stoichiometries", new String[] { RXSPECIES_DELETE, RXSPECIES_CANCEL }, RXSPECIES_CANCEL);
if (response != null && response.equals(RXSPECIES_DELETE)) {
for (int i = 0; i < reactionParticipantArr.length; i++) {
ReactionStep reactionStep = reactionParticipantArr[i].getReactionStep();
reactionStep.removeReactionParticipant(reactionParticipantArr[i]);
}
}
}
} catch (UserCancelException uce) {
return;
} catch (PropertyVetoException e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage());
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.SearchReactions.MENU_ACTION)) {
try {
if (shape instanceof ReactionContainerShape) {
showReactionBrowserDialog(((ReactionContainerShape) shape).getStructure(), null);
}
} catch (Exception e) {
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolSaveAsImageActions.MenuAction.MENU_ACTION)) {
try {
String resType = null;
if (shape instanceof ReactionContainerShape) {
showSaveReactionImageDialog();
}
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
} else if (menuAction.equals(CartoonToolMiscActions.Annotate.MENU_ACTION)) {
if (shape instanceof ReactionStepShape) {
// MIRIAMHelper.showMIRIAMAnnotationDialog(((SimpleReactionShape)shape).getReactionStep());
// System.out.println("Menu action annotate activated...");
ReactionStep rs = ((ReactionStepShape) shape).getReactionStep();
VCMetaData vcMetaData = rs.getModel().getVcMetaData();
try {
String newAnnotation = DialogUtils.showAnnotationDialog(getGraphPane(), vcMetaData.getFreeTextAnnotation(rs));
vcMetaData.setFreeTextAnnotation(rs, newAnnotation);
} catch (UtilCancelException e) {
// Do Nothing
} catch (Throwable exc) {
exc.printStackTrace(System.out);
DialogUtils.showErrorDialog(getGraphPane(), "Failed to edit annotation!\n" + exc.getMessage(), exc);
}
}
} else {
// default action is to ignore
}
}
use of cbit.vcell.model.ReactionParticipant in project vcell by virtualcell.
the class ReactionCartoonTool method getLineTypeFromAttachment.
private LineType getLineTypeFromAttachment(SpeciesContext speciesContext, Point worldPoint) throws Exception {
Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
if (mouseOverShape instanceof ReactionStepShape) {
// check if the ReactionStep already has a ReactionParticipant for
// this SpeciesContext
ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
if (mouseOverShape instanceof SimpleReactionShape) {
switch(mouseOverShape.getAttachmentFromAbs(worldPoint)) {
case Shape.ATTACH_LEFT:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
case Shape.ATTACH_CENTER:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Catalyst && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.CATALYST;
}
case Shape.ATTACH_RIGHT:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Product && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.PRODUCT;
}
}
} else if (mouseOverShape instanceof FluxReactionShape) {
switch(mouseOverShape.getAttachmentFromAbs(worldPoint)) {
case Shape.ATTACH_LEFT:
{
// return LineType.FLUX;
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
case Shape.ATTACH_CENTER:
{
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Catalyst && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.CATALYST;
}
case Shape.ATTACH_RIGHT:
{
for (int i = 0; i < rps.length; i++) {
// return LineType.FLUX;
if (rps[i] instanceof Product && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.PRODUCT;
}
}
}
}
return LineType.NULL;
}
Aggregations