Using Blender and make-na to create DNA art

In CINPLA we are developing teaching material for a new course in biology and programming. One topic we’re working on is that of bioinformatics and DNA. I figured that an artistic rendering of the DNA double helix would be nice to have and decided to try and make one in Blender. At first I considered building this from the ground up using its design tools, but I quickly figured that it would be too time consuming and hard to get the proportions right. After all, I’d like it to be as close to the real structure of DNA as possible.

I then remembered that the RCSB Protein Data Bank (PDB) hosts a large number of molecular structures that have been described by researchers over the past decades. The structures can be downloaded freely as long as they are cited properly. I went looking for files with the DNA molecule and found a couple, such as 1BNA and 1D66, but they turned out to be a bit too short or too hard to untangle from the other molecules.

Then I found make-na, a fantastically simple open source tool that will generate a PDB file from any DNA sequence. Just open the make-na server and type in your favorite combination of the letters A, T, C and G. Out comes a PDB file with the corresponding molecular structure of DNA.

To open the PDB file in Blender, click File > User Preferences > Add-ons and search for PDB. Enable this add-on by clicking the check box next to it:

Screenshot from 2016-02-14 17-40-24(You may have to restart Blender after enabling the add-on).

Click File > Import > Protein Data Bank (.pdb):

Screenshot from 2016-02-14 17-43-40Voila! You should now have a DNA molecule ready for rendering in Blender.

I tweaked the material settings, enabled Cycles Render and added a couple of lights to make the image you see below:

duplex14Here is the .blend file used to create the image, if you’d like to modify it to make your own version:

For more technical figures, I’m thinking about using the cartoon style in JSmol or PyMOL which produces ribbon diagrams of proteins. Those make the DNA strands look more like this:


The next step is to load this image into Inkscape and start annotating the different parts of DNA.

The above images and the .blend file are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Recent commit causes Qt3D to fail compilation

A recent commit pushed to the Qt3D repository breaks building Qt3D against Qt version 5.2 and older with the following error message:

painting\qglpainter.cpp:2348:29: error: 'class QOpenGLFunctions' has no member named 'glReadPixels'

Thankfully, rolling back to an older commit still works. Just supply the following command after pulling the Qt3D repository:

git checkout d3338a9 -b older_version

This should enable you to compile Qt3D for Qt5.2 and earlier.

Playing around with Sculpt Mode in Blender

While preparing for a presentation I’m giving on Python scripting in Blender, I figured I’d  also try out some new features . One such feature is in Sculpt Mode, where dynamic topology is now allowing fine-grained control over the level of detail while sculpting. This turned out to be a lot of fun, so I decided to sculpt a human face while at it:


Dynamic topology is such an amazing addition to Blender and exactly what lacked in previous versions. The feature has been around for a while and has truly matured the whole Sculpt Mode since last time I tried it in Blender.

There’s a long list of things I would like to fix in this rendering, but with so much going on in other projects, I will be putting this away for now. Should I pick it up again later, I might even start from scratch and make better use of Blender’s multiresolution features too.

If you want to start learning how to sculpt human faces in Blender (in much greater detail than what I have achieved here), you should take a look at this great video course.

Multiple billboards in Qt3D

While Qt3D has a transform for drawing billboards, it is not very useful if you are drawing thousands of particles. This is because the transform can only be applied to one object at the time, and using thousands of objects is never a good idea in neither OpenGL or Qt. This is simply because the overhead of each object is very large, both in terms of memory and performance.

The solution I found was to write my own custom class that inherits QQuickItem3D and is capable of drawing a list of 3D points as billboards by directly turning each sprite towards the camera at every draw call. This is not very efficient, but it works and is way faster than the options: Drawing spheres or creating one billboard per particle. The ideal option is of course to use geometry shaders, but they are not easily available in Qt3D yet. Most likely because its a new feature in OpenGL 3.2.

The class is available on GitHub and the resulting output is shown in this screenshot:


Using Qt3D today

Qt3D is an amazing library for Qt that gives you the ability to render your own 3D stuff together with your existing widget or QML based GUI. The library was started by the Qt developers a few years back, but has not yet been released with the official Qt SDK. It was announced that it would be bundled with Qt5.0, but because of the state of the library at the time, its release was postponed. Even so, the library is still very mature and appears to work very well in my opinion. So I would urge you to test it out.

Simple install on Ubuntu

To use the library you have a couple of different choices. If you are running Ubuntu, you may just run the following commands:

sudo apt-get install qt3d5-dev qtdeclarative5-qt3d-plugin

And you should be good to go. Look for examples in the Qt3D documentation.

Note that Ubuntu currently doesn’t have QtQuick.Controls available, so you will have to follow the instructions below to combine Qt3D with QtQuick.Controls.

Install Qt3D into the newest Qt release

Currently Qt5.1.1 is the newest stable release of Qt and is the version I’d recommend that you use with Qt3D.

  1. Download and install Qt5.1.1.
  2. Clone Qt3D from Gitorious:
    git clone git:// qt3d
  3. Open QtCreator from your new Qt installation.
  4. Open the file from the cloned repository and configure it to use the platforms on which you want to use Qt3D (desktop, Android, etc.).
  5. Build for each platform you want to use. Set the build to Release instead of Debug mode while building. You should receive about one hundred warnings if you are building for Android. As always, ignore these.
  6. Open the build folder in a terminal and run
    make install

    This will not install to your system, but to your Qt installation, so that it gets the ability to do awesome 3D stuff.

You should now have Qt3D installed in your Qt installation and be ready to run projects that are using Qt3D.

Loading wavefront .obj files in Qt’s OpenGL ES

Note : This method is now easily replaced by the awesome Qt3D module that has support for loading a range of different file formats into an OpenGL context.

Suzanne rendered with Qt and OpenGL ES

I’ve been looking all over the web for a Qt library for loading files exported from Blender into OpenGL. Since I didn’t find anything I figured I would create a library myself.

Even though I didn’t find anything specifically about Blender and Qt’s OpenGL ES implementation, I managed to find something about each of them separately. Loading files from Blender seems to be most easily done by exporting to another format first. A lot of people mentioned Wavefront’s .obj file format as a good candidate. It is a small format, easy to parse and a lot of libraries already exist. At least that’s what they said.

Continue reading Loading wavefront .obj files in Qt’s OpenGL ES