@Override public Reaction<Object> createReaction(final RandomGenerator rand, final Environment<Object> env, final Node<Object> node, final TimeDistribution<Object> time, final String param) { LangUtils.requireNonNull(node, time); final boolean isSend = "send".equalsIgnoreCase(param); final Reaction<Object> result = isSend ? new ChemicalReaction<>(node, time) : new Event<>(node, time); if (param != null) { result.setActions(Lists.newArrayList(createAction(rand, env, node, time, result, param))); } if (isSend) { result.setConditions(Lists.newArrayList(createCondition(rand, env, node, time, result, null))); } return result; }
@Override public Reaction<Double> visitJunctionReaction(final BiochemistrydslParser.JunctionReactionContext ctx) { visit(ctx.junctionReactionLeft()); visit(ctx.junctionReactionRight()); if (ctx.customConditions() != null) { visit(ctx.customConditions()); } if (ctx.customReactionType() != null) { visit(ctx.customReactionType()); } junctionList.forEach((j -> { if (node instanceof CellNode) { actionList.add(new RemoveJunctionInCell(env, (CellNode) node, j, rand)); actionList.add(new RemoveJunctionInNeighbor(env, (CellNode) node, reverseJunction(j), rand)); } else { throw new UnsupportedOperationException("Junctions are supported ONLY in CellNodes, not in " + node.getClass().getName()); } })); reaction.setConditions(conditionList); reaction.setActions(actionList); return reaction; }
@Override public Reaction<Double> visitBiochemicalReaction(final BiochemistrydslParser.BiochemicalReactionContext ctx) { visit(ctx.biochemicalReactionLeft()); visit(ctx.biochemicalReactionRight()); if (ctx.customConditions() != null) { visit(ctx.customConditions()); } if (ctx.customReactionType() != null) { visit(ctx.customReactionType()); } /* * if the reaction has at least one neighbor action but no neighbor condition * add the neighborhoodPresent condition. * This is necessary because if the node which contain this reaction don't have * a neighborhood and the reaction is valid (all conditions are valid) the neighbor action * is undefined, and can lead to unwanted behavior. */ if (neighborActionPresent && biomolConditionsInNeighbor.isEmpty()) { conditionList.add(new NeighborhoodPresent<>(env, node)); } if (envActionPresent && !envConditionPresent) { conditionList.add(new EnvPresent(env, node)); } reaction.setConditions(conditionList); reaction.setActions(actionList); return reaction; }
@Override public Reaction<Double> visitCreateJunction(final BiochemistrydslParser.CreateJunctionContext ctx) { visit(ctx.createJunctionLeft()); visit(ctx.createJunctionRight()); if (ctx.customConditions() != null) { visit(ctx.customConditions()); } if (ctx.customReactionType() != null) { visit(ctx.customReactionType()); } reaction.setConditions(conditionList); reaction.setActions(actionList); return reaction; }