Dupligroups and instancing


I’m writing a script to import protein database files into blender. I wanted to try to take advantage of the new raytrace instancing feature so I thought that using dupligroups to create instances of the thousands of atoms in a typical molecule would be the best way.

However I quickly discovered that assigning dupligroups by script (rather than simply using mesh instances) is a massive performance kill. I really have no idea why. The worst part about it is that the script runs slower and slower the further along it goes. Once it reaches the 3000 atom mark, it clunks along at a rate of about 1 atom a second, which is ridiculous.

Is there any other way for me to take advantage of instancing without dupligroups? I need to be able to precisely define the location of the instances at the very least. Or perhaps I am doing something wrong?

The tiny section of code that is causing the slowdown goes like this

cur_atom.dupli_type = ‘GROUP’
cur_atom.dupli_group = element_group

For my 800 atom test, the script completes in 4.5s
If I leave out one or the other line, the script takes 3s, while if I leave out the lines completely it takes just 1.5s

Well it seems Blender hates having thousands of objects. I’m taking a different approach and trying to use particles and lone vertices to spawn the atoms.