Towards a more realistic-looking scene in POV-Ray for molecular rendering
I’m a strong believer in the power of good figures. Everyone knows the tired phrase “a picture says a thousand words”. In scientific papers, where page charges and editors place restrictions on the amount of text and a color figure might run you $1000, it’s critical to make sure that your figures are absolutely as good as they can be.
One of the best programs for generating images of 3D objects is POV-Ray. This is a raytracing program - it simulates rays of light and their interactions with a scene. It’s an incredibly powerful program (just take a look at some of the results in the Hall of Fame), but also fairly complex and not user-friendly. Some molecular graphics packages have built-in simplified POV-Ray interfaces (pymol and VMD are two that I’m aware of), however the renders produced by these programs just don’t look good enough for me most of the time.
I’m going to try to work out a more “realistic” rendering scene geared mainly towards the visualization of protein structures. I’ll say from the outset that as of now I’m sort of inspired by the work of David Goodsell, and I’m going to try to incorporate some of that simplicity into the render.
There are a few things that many POV-Ray renders of molecules get “wrong” in my opinion, with the main two being lighting and texture. This usually leads to sort of plastic-looking things with very harsh lighting and shadows. Let’s see if we can work on a model system first to try and improve this.
First of all, installing POV-Ray on Ubuntu:
sudo apt-get install povray povray-includes
Gotta love software installations with aptitude.
In order to render a scene, you need an input file. POV-Ray will read the input file and parse it accordingly to render the image. Let’s set up a simple scene to get started, with a green sphere and a single light:
#include "colors.inc"
// Lights
background{White}
// Main room light
light_source {
<-700,700,-700>*1000
color White
}
// Camera
camera {
location <0, 0, -700>
look_at <0,0,0>
}
// Action
sphere {
0,200
pigment {rgb<0.27,0.55,0>}
normal {
dents 1.5 scale 50
}
scale y*1.5
}
Some basics:
- Anything preceded by double forward slashes is a comment
- The colors.inc file lets us refer to some basic colors by name, as in the background field where we call “White” rather than listing the actual RGB code
- The coordinate system is: Negative to Positive X is left to right; negative to positive Y is bottom to top, and negative to positive Z is back to forward. This places our camera at 0 units left, 0 units up, and 700 units back
The sphere object is just to give us something to look at. It’s just centered at the origin with a 200 unit radius, scaled 1.5x in the Y dimension to make an ellipse. The “normal” section makes it a bit bumpy.
I saved this file as “blobtest.pov”, and rendered it from the command line with:
povray +V +W640 +H480 +am2 +a0.1 +Iblobtest.pov +FN +Oblobtest.png
Let me walk through the command flags. +V triggers verbose output. +W and +H are the width and height of the rendered image. +am2 and +a0.1 control antialiasing. +I is the input file. +FN is a flag for making PNG images. +O is the output file. This image renders in a few seconds on my laptop, and looks like this:

Now, let’s add a few more bells and whistles to see if we can improve this image. First, add these three lines to the main light, just below the “color White” line:
area_light <5,0,0>,<0,0,5>,5,5 adaptive 1 jitter
These will change our light from a point to an array as well as lead to softer shadows.
Another thing we can do is put a spotlight onto the object. Add this section below the main light:
// Spotlight for strenghtening shadows
light_source {
<-700,700,-700>
color White/2
spotlight
point_at<0,0,0>
radius 30
falloff 15
tightness 0
area_light <1,0,0>,<0,0,1>,2,2
}
Finally (for now), add these three lines to the camera:
focal_point <0,0,0> aperture 0.4 blur_samples 20
These will give us a focal plane, more like a real camera, and will add realism to the image.
You can render the image using the same command as before (although since we’ve turned on focal blur the antialiasing settings won’t matter). The new image looks like this:

The spotlight brightens up the surface and softens the shadows a bit. In my mind, however, the darkened areas are too obscured here. We could raise the overall light using the ambient parameter, but I’d rather have a bit more control. To bring the shadows up a little better, let’s add a weak third light to the bottom right. Also, we can use a #declare to combine the position of the first two lights:
// Lights
background{White}
#declare light_position = <-700,700,-700>;
// Main room light
light_source {
light_position*1000
color White*1.5
area_light <5,0,0>,<0,0,5>,5,5
adaptive 1
jitter
}
// Spotlight
light_source {
light_position
color White/2
spotlight
point_at<0,0,0>
radius 30
falloff 15
tightness 0
area_light <1,0,0>,<0,0,1>,2,2
}
// Weak light to soften shadows
light_source {
<700,-700,-700>
color White/4
area_light <3,0,0>,<0,0,3>,3,3
}
The rendered product:

To me, this is starting to look pretty good. Let’s add one more line to the texture of the sphere:
normal { wrinkles 0.15 scale 0.9 }
And here we have our nice green egg:

Next I’ll work on actually integrating this with a biological macromolecule and tweaking the scene accordingly.

