Draft

A wiggling lattice protein

Draft of 2016.11.21

May include: visualizationprogramming&c.

This is a bit of a work-in-progress report:

I’ve spent a few days (in the few moments when I’m not focused on the rise of Actual Fascism in the US) working through some simple ways to represent and draw the lattice proteins I spoke about the other day. This morning I threw several versions away, and Ron and I paired for a couple of hours and built this little sketch:

What’s happening here is this:

  1. there are about 80 “beads” in this lattice protein simulation
  2. the initial configuration (which you can reset by reloading the page in your browser) is a valid, self-avoiding layout of the “beads” on a simple square lattice
  3. in each tick of the clock, one of the beads is chosen at random (with uniform probability), and the direction it “points” to the next bead in the chain is changed to a random direction
  4. if (and only if) the resulting configuration does not result in any colliding beads then the change is accepted; otherwise, the chain is not moved

So for example, suppose the configuration started as a chain of five beads arranged initially [:east :east :east :east]. This first heuristic just picks one of those four items (with uniform probability) and changes it to a random direction: for example, it might become [:east :east :north :east]. Then we try laying out a chain in that path, and find that it doesn’t contain any collisions, so we accept the change and the animation is updated.

If the next random change attempted produces a chain [:east :west :north :east], when we lay out a chain with those directions we get a collision (the :east followed by :west) in which two beads occupy the same lattice positions. So we discard the random change and the chain remains in the [:east :east :north :east] position, and another random change is attempted next time.

The result is a self-avoiding chain sort of “stumbling around” on the lattice. One end is tied down in the center of the sketch. The longer delays you are probably seeing between changes in configuration are the times when many random changes are checked before a valid one is discovered.

Note, there’s no particular “energy” here in this simple sketch. Every configuration is equally likely, as long as it doesn’t create a collision. And this may not be the “best” algorithm for exploring the configuration space for a lattice protein, either. Just something I could get working here in a browser and show you.

Next I’ll show you a slightly different algorithm and representation, so we can compare the way the dynamics differ. And also I’ll share the source code—it’s just not quite refactored for peak readability yet.