use of cbit.vcell.model.FluxReaction in project vcell by virtualcell.
the class ReactionCartoonTool method lineActon.
private void lineActon(Structure startStructure, ReactionStep reactionEnd) throws Exception {
Structure endStructure = reactionEnd.getStructure();
if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
// if reactionStart is a SimpleRxn OR FluxRxn without a product, add speciesContext as reactant
if ((reactionEnd instanceof SimpleReaction) || ((reactionEnd instanceof FluxReaction) && !reactionEnd.hasReactant())) {
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
reactionEnd.addReactant(speciesContext, 1);
positionShapeForObject(startStructure, speciesContext, edgeShape.getStart());
}
if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
// ============ change kinetics to lumped or warn user ?????????
// simpleReaction.setKinetics(new GeneralLumpedKinetics(simpleReaction));
}
getReactionCartoon().notifyChangeEvent();
}
}
use of cbit.vcell.model.FluxReaction in project vcell by virtualcell.
the class ReactionCartoonTool method getLineTypeFromDirection.
private LineType getLineTypeFromDirection(Shape startingShape, Point worldPoint) throws Exception {
Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
if (mouseOverShape instanceof ReactionStepShape) {
if (startingShape instanceof SpeciesContextShape) {
SpeciesContext speciesContext = (SpeciesContext) startingShape.getModelObject();
// check if the ReactionStep already has a Product for this SpeciesContext
ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
if ((mouseOverShape instanceof SimpleReactionShape) || (mouseOverShape instanceof FluxReactionShape)) {
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
// else if (mouseOverShape instanceof FluxReactionShape){
// for (int i = 0; i < rps.length; i++){
// if ((rps[i] instanceof Reactant || rps[i] instanceof Product) && rps[i].getSpeciesContext() == speciesContext) {
// return LineType.NULL;
// }
// }
// return LineType.FLUX;
// }
}
} else if (mouseOverShape instanceof SpeciesContextShape) {
SpeciesContext speciesContext = (SpeciesContext) mouseOverShape.getModelObject();
if (startingShape instanceof SpeciesContextShape) {
// straight from one species to another ... will create a reaction upon release
return LineType.PRODUCT;
} else if (startingShape instanceof ReactionStepShape) {
ReactionStep reactionStep = (ReactionStep) startingShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
// } else
if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
}
}
return LineType.NULL;
}
use of cbit.vcell.model.FluxReaction in project vcell by virtualcell.
the class ReactionCartoonTool method mouseClicked.
@Override
public void mouseClicked(MouseEvent event) {
Point screenPoint = new Point(event.getX(), event.getY());
Point worldPoint = screenToWorld(screenPoint);
try {
if (event.getButton() != MouseEvent.BUTTON1) {
return;
}
switch(mode) {
case SELECT:
{
if (event.getClickCount() == 2) {
final Shape selectedShape = getReactionCartoon().getSelectedShape();
if (selectedShape instanceof ReactionContainerShape || selectedShape instanceof SpeciesContextShape || selectedShape instanceof SimpleReactionShape || selectedShape instanceof FluxReactionShape || selectedShape instanceof ReactionRuleDiagramShape || selectedShape instanceof RuleParticipantSignatureDiagramShape) {
editInPlace(selectedShape, worldPoint);
}
if (selectedShape != null) {
menuAction(selectedShape, CartoonToolMiscActions.Properties.MENU_ACTION);
}
}
break;
}
case STEP:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (getReactionCartoon().getStructureSuite().areReactionsShownFor(structure)) {
ReactionStep reactionStep = getReactionCartoon().getModel().createSimpleReaction(structure);
positionShapeForObject(structure, reactionStep, worldPoint);
saveDiagram();
}
}
break;
}
case FLUX:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
FluxReaction fluxReaction = getReactionCartoon().getModel().createFluxReaction(membrane);
ReactionStepShape frShape = (ReactionStepShape) getReactionCartoon().getShapeFromModelObject(fluxReaction);
Point parentLocation = frShape.getParent().getSpaceManager().getAbsLoc();
frShape.getSpaceManager().setRelPos(worldPoint.x - parentLocation.x, worldPoint.y - parentLocation.y);
saveDiagram();
// setMode(SELECT_MODE);
} else {
// setMode(SELECT_MODE);
// throw new Exception("fluxes only applicable to membranes");
}
}
break;
}
case SPECIES:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) pickedShape).getStructure());
reactionCartoon.clearSelection();
getGraphModel().select(speciesContext);
positionShapeForObject(speciesContext.getStructure(), speciesContext, worldPoint);
// showCreateSpeciesContextDialog(getGraphPane(), getReactionCartoon().getModel(), ((ReactionContainerShape) pickedShape).getStructure(), scShapeLocation);
saveDiagram();
}
}
default:
break;
}
} catch (Exception e) {
System.out.println("CartoonTool.mouseClicked: uncaught exception");
e.printStackTrace(System.out);
Point canvasLoc = getGraphPane().getLocationOnScreen();
canvasLoc.x += screenPoint.x;
canvasLoc.y += screenPoint.y;
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
}
use of cbit.vcell.model.FluxReaction in project vcell by virtualcell.
the class ReactionCartoonTool method lineAction.
private void lineAction(SpeciesContext speciesContextStart, ReactionStep reactionEnd) throws Exception {
Structure endStructure = reactionEnd.getStructure();
Structure startStructure = speciesContextStart.getStructure();
if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
int stoichiometry = 1;
Reactant reactant = null;
for (ReactionParticipant participant : reactionEnd.getReactionParticipants()) {
if (participant instanceof Reactant && participant.getSpeciesContext().equals(speciesContextStart)) {
reactant = (Reactant) participant;
}
}
if (reactant != null) {
// only increase stoichiometry if reaction is SimpleReaction
if (reactionEnd instanceof SimpleReaction) {
reactant.setStoichiometry(reactant.getStoichiometry() + 1);
}
Shape shape = getReactionCartoon().getShapeFromModelObject(reactant);
if (shape != null) {
shape.refreshLabel();
}
} else {
// add speciesContextEnd as pdt to reactionStart only if reactionStart is a SimpleRxn or if it is a FluxRxn and doesn't have a pdt.
if (reactionEnd instanceof SimpleReaction || ((reactionEnd instanceof FluxReaction) && !(reactionEnd.hasReactant()))) {
reactionEnd.addReactant(speciesContextStart, stoichiometry);
}
}
if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
// ============ change kinetics to lumped or warn user ?????????
// simpleReactionEnd.setKinetics(new GeneralLumpedKinetics(simpleReactionEnd));
}
getReactionCartoon().notifyChangeEvent();
}
}
use of cbit.vcell.model.FluxReaction in project vcell by virtualcell.
the class TransformMassActions method transformOne.
public TransformedReaction transformOne(ReactionStep origRS) throws PropertyVetoException, IOException, ClassNotFoundException {
TransformedReaction transformedRS = new TransformedReaction();
if (origRS instanceof SimpleReaction) {
// we separate mass action and general law, because if it passes, mass action uses label 'ok' and general uses label 'stochastic capable'
if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.MassAction)) {
Expression rateExp = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getExpression();
try {
Parameter forwardRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KForward);
Parameter reverseRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KReverse);
MassActionSolver.MassActionFunction maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, origRS);
// set transformed reaction step
transformedRS.setTransformType(TransformedReaction.TRANSFORMABLE_WITH_NOCHANGE);
transformedRS.setTransformRemark(TransformedReaction.Label_Ok);
transformedRS.setMassActionFunction(maFunc);
} catch (Exception e) {
// Mass Action Solver failed to parse the rate expression
transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_Failed + " " + e.getMessage());
}
} else if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.General)) {
Expression rateExp = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getExpression();
try {
Parameter forwardRateParameter = null;
Parameter reverseRateParameter = null;
MassActionSolver.MassActionFunction maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, origRS);
// set transformed reaction step
transformedRS.setMassActionFunction(maFunc);
// if number of reactant is 0, or number of product is 0, we can not transform it to mass action law
if (((SimpleReaction) origRS).getNumReactants() == 0 || ((SimpleReaction) origRS).getNumProducts() == 0) {
transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE_STOCHCAPABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_StochForm_NotTransformable);
} else {
transformedRS.setTransformType(TransformedReaction.TRANSFORMABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_Transformable);
}
} catch (Exception e) {
// Mass Action Solver failed to parse the rate expression
transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_Failed + " " + e.getMessage());
}
} else // other kinetic rate laws other than MassAction and General
{
transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_Failed + TransformedReaction.Label_FailedOtherReacLaw);
}
} else // flux
{
if (origRS instanceof FluxReaction) {
// fluxes which are described by general density function/permeability
if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.General) || origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
Expression rateExp = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate).getExpression();
try {
// forward and reverse rate parameters may be null
Parameter forwardRateParameter = null;
Parameter reverseRateParameter = null;
if (origRS.getKinetics().getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
forwardRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
reverseRateParameter = origRS.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
}
MassActionSolver.MassActionFunction maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, origRS);
// set transformed reaction step
transformedRS.setMassActionFunction(maFunc);
transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE_STOCHCAPABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_StochForm_NotTransformable);
} catch (Exception e) {
// Mass Action Solver failed to parse the rate expression
transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_Failed + " " + e.getMessage());
}
} else // other fluxes which are not described by general density function or general permeability
{
transformedRS.setMassActionFunction(new MassActionSolver.MassActionFunction());
transformedRS.setTransformType(TransformedReaction.NOTRANSFORMABLE);
transformedRS.setTransformRemark(TransformedReaction.Label_Failed + TransformedReaction.Label_FailedOtherFluxLaw);
}
}
}
return transformedRS;
}
Aggregations