Generating geometry for ball and stick molecules

Small molecules typically use CPK space-filling or ball and stick representations, because surface meshes aren’t very informative. It’s more interesting to see structures like benzene rings when present. In order to bring the associated small molecule in with the protein structure I was importing using Molecular Maya, it was necessary to ensure that the HETATMs option was checked in the import options.

For the protein component, I kept the established simplified surface mesh used in the series so far. I decided on a modified ball and stick representation with pinched bonds, which Molecular Maya is capable of generating. The requirements of the animation and rendering process were such that I really needed regular geometry for the atoms and bonds, respectively balls and sticks. However, in the version of the software I was using, these structures were built with spherical particles and geometry instanced to particles. Maya unfortunately doesn’t have a particle instance to regular geometry conversion tool, so I was left to find my own workaround for this task. I’m confident that in the future, either or both of Autodesk Maya and Molecular Maya will have the capability of automatically performing the following, but at the time, this process was not implemented in the software.

First, I needed access to the underlying nodes in the mMaya hierarchy. I did this by selecting the mMaya node prefixed with pdbMolStruc_ and running the below code.

Note: this webpage has likely converted the regular quote marks to “smart quotes”, which will need to be replaced in your script editor with “straight quotes”.

After revealing the particle nodes, I made a simple sphere and also copied the pinch bond geometry as a template for the sticks to be created. Then I ran the following two scripts, which created the geometry for me. The first one creates the atoms. You would have to change the named nodes (e.g. HET_EB4_0_particle) to the name of the particle node in your scene, and name the template sphere “sphereAtom” or change the code accordingly. Again, change the “smart quotes” to “straight quotes”. I didn’t really write the script to be a robust resource so much as a quick fix for myself.

//Ensure the atomSphere has a radius of the “ball and stick vWaals scale” to start

This second script creates the bonds. I had to do some tricky stuff (not that tricky) to get the aim attribute that the particle bonds were using into rotation for the geometry. Again, change the node name at the top, the bond template object “new_geoBondPrim” and make sure there aren’t any “smart quotes”, if you do decide to use this on your own scene.

string $particleBondNode = “HET_EB4_0_particleBonds”; //state the name of the mMaya node
group -em -n “bondGeoGrp”; //new empty group for bond geo

And that gave me the geometry I needed for my animation. In this particular case I wanted to give everything the same shader, not using atom color coding; but if that was that case, you would have to keep track of which atoms were of what type. A future challenge!

2 Comments

Thanks so much Stuart, this was an extremely helpful tutorial. The one thing I found unclear was how to orient the copied pinched geometry for the bonds. I simply recreated the bond using a cylinder I pinch, but did not know which way to orient the bond geometry. So when I used the last set of code to to create the geometry for the bonds, the orientation was incorrect and the bond shape was warped a bit as well.

Have you tried using the instanced bond geo object that molecular Maya generates? If that works, you might be able to figure out how your geo differs, e.g. the pivot point might have to be placed in a particular spot.