Tutorial: Making interactive CPMs in the browser with Artistoo

8. More complex constraints

The constraint we built in the last two exercises was not yet very complicated. In some cases, you may want to keep track of certain variables after every copy attempt or after every MCS. This exercise will show how this works.

Using listeners: postSetpixListener and postMCSListener

Please open 8-focaladhesions.html in a text editor and your browser. In the browser, you should see a bunch of Act-cells moving.

Now have a look at the code in the text editor, in the class FocalAdhesions. The goal of this constraint is to let protruding cells generate adhesion sites with some probability padh, and to forbid any retracting copy attempts into cell pixels at or next to such an adhesion (implemented in fulfilled()).

Pay attention to two important functions:

  • postSetpixListener(i, cid_old, cid_new)
  • postMCSListener()
When a constraint is added to the CPM by C.add(), it looks if these two functions are implemented. The CPM then automatically executes anything in postSetpixListener after every copy attempt, and anything in postMCSListener after every MCS. Because these are called automatically from within the CPM, they must always have the same input arguments (i,cid_old,cid_new for the postSetpixListener, and none for the postMCSListener).

Exercise
The cells in this simulation already have the new FocalAdhesions constraint added, but it does not work yet because the adhesions are never generated.

Can you implement the postSetpixListener such that it lets new adhesions spawn with probability padh after every copy attempt? (Hint: also check out the setup() function to see which parameters this constraint gets.)

Check out 8-focaladhesions-answer.html for comparison.

Final notes

This tutorial has covered most of the basic principles of building interactive CPMs with Artistoo. For further inspiration, have a look at:

  • The source code of the constraints that come with the library, which you can find here (look under "Hamiltonian")
  • The gallery of examples
  • The bonus examples in this repository: pseudopods.html (based on Ariotti et al ) and active-adhesion.html (based on Van Steijn et al, 2022.).

Good luck!