Tuesday, October 1, 2013

Indexing an Emacs Macro

This post is about how to increment and paste a counter while executing an emacs macro. For some reason, this is not easy to find on the Internet. So I'll write it down on my blog since I keep forgetting.


  1. Set the start point of the counter
    M-: (setq i 1)
  2. Start recording macro with
    C-x (
  3. Insert index as needed with
    C-u M-: i
  4. Increment index when finished with macro
    M-: (setq i (+ i 1))
  5. Complete macro with
    C-x )
  6. Execute Macro with
    C-x e
To execute the macro multiple times, use ALT-(# of times) C-x e.

Thursday, May 16, 2013

Extending Radial Distributions

Radial distribution functions are one of the most important quantities to calculate when running a molecular dynamics simulation. They give good insight into the phase and pair potentials between molecules. Practically, they are calculated according to the following equation:

Tuesday, April 30, 2013

Cube-Sphere Intersection Volume

This week's math problem was particularly difficult. I wanted to know the intersection volume between a cube and a sphere. Imagine a sphere contained in a cube. The sphere will first touch the cube when its radius is equal to half the width of the cube. Until that point, its volume is just the formula for the volume of a sphere. Once the sphere's radius is 2 sqrt(3) times the width of the cube, then it completely engulfs the cube and the intersection of the 2 objects is just the volume of a cube. In between, I've found it looks like this:


Thursday, April 25, 2013

Bacteria in Blender

I made this while drinking my morning coffee. I just stretched a UV Sphere, stuck two layers of hair on it (flagella, cilia) and added a few modifiers to get it bumpy. The texture is just some glass, Voronoi textures, and diffuse shaders. Meh, it's OK.


Wednesday, April 24, 2013

Generating n-Dimensional Lattice Coordinates

It comes up sometimes in my research that I need to generate coordinates along a lattice. For example, when generating an initial structure for a molecular dynamics simulation. I thought I share my code for this. The code works by recursively enumerating each dimension in a lattice and calling a given function each time it reaches a point. So, it could be used to execute any function along a lattice. Here's what it looks like for a 2D and 3D example. In the 3D example I didn't choose a cubic number of points on the lattice, so that it sort of stops in the middle.



Tuesday, April 23, 2013

Category Colors in R

I thought I'd write down the color palette I use for categories. I've seen many discussions about gradient color choices, but category colors are less often discussed. I have a function given below which generates colors where there is not meant to be an ordering to the color. It is important when data points are near, that they are easy to distinguish with the eye. It makes more sense to see it:


Monday, April 22, 2013

ggplot Style in Classic R Plots

ggplot is a highly acclaimed R package for plotting. I have had very little experience with the library because I've mostly memorized all the quirks of normal R plots. I like the ggplot default style though, so I thought write down how to replicate it in R plots. The distinctive feature of ggplot is the gray rectangle and white grid lines. This may be replicated like so:



Here's an example