Atomic Geometry - Importing CSV to Geonodes

I have a lot of projects on the go for CGFigures. More than I could possibly hope to keep up with. One of them has a very special place in my heart though and that is the effort to import CSVs into a usable format in geometry nodes. This has big implications for the ability to work with data. It's also a precursor to my eventual goal of creating a geometry nodes equivalent of atomic blender, which is probably the greatest single contribution anyone has made to the chemistry corner of the Blender scientific community (thank you Dr. Barth).

 

Atomic Geometry (the name I'm giving this capability) would ideally allow for Houdini-like control over molecular structures in Blender. One need look no further than the awesome work of Stuart Jantzen (biocinematics) to see what that would mean for scientific visualization of molecules in Blender.

 

Now, fantastic resources already exist to parse through pdb files. I will likely end up making use of biopython to work through the files but first I wanted to tackle importing simpler subjects. Just a single list of coordinates along with some qualifiers such as atom type or number in the sequence.

 

To the best of my knowledge there is currently no way to read a csv directly into the geometry nodes spreadsheet. That would be an incredible feature, and if it exists, please tell me. For now I have written a script that creates a point cloud of vertices based on xyz coordinates in a csv. This creates the verts that Blender needs to place the 'atoms' for geometry nodes. The real trick is getting the atom types and the connections between atoms, all information encoded in the pdb.

 

This is crudely possible using vertex groups. I was originally inspired here by Erindale's use of simple math to create a 0 to 1 (fac) output from a line in geometry nodes. Simply put, for each row in the csv you assign a vertex weight. 0 to the first value, 1 to the last. The division in between depends on the length of the csv. To get the index of each 'atom' you can create a new attribute (index) by multiplying the fac by the length. This gives the index for every atom in the file. We can use this for operations. If atom #3 in the list has atom #7 in it's bond list we can use vector math to create a path between them. Though you might be able to just create edges between connected verts I don't think this would solve the problem of double or triple bonds so I view it as an incomplete solution. Needless to say, this is an area that requires further development.

 

Vertex groups also give you the ability to assign 'types' of atoms. Every time a new atom label is detected in the pdb, you can create a vertex group for it. Thus, when an atom comes up, if it has the label 'Carbon' you can assign it a value of 1 in the Carbon vertex group.

 

Already we've accomplished some key points (at least conceptually). Use the 3D coordinates to create a point cloud of verts. Assign a sequence factor, index, and type to each 'atom'. At this stage I have manually entered the coordinates from a pdb file for Benzene and created the associated vertex groups. I'll link that file for people who want to play with it (https://drive.google.com/file/d/1N8WOeX724PjjbeknQeYn-rBq-s5rTTN_/view?usp=sharing). There are much better ways to do almost everything about this, especially the basic geometry nodes. But it is just an experiment for now.

 

Right now I am working on creating the fac and index through the script instead of having to enter it by hand. Coding in Blender is not always the most intuitive process and I need to find out how to work in edit mode with the most recently added vert.  From there, it will be on to parsing pdb files themselves and building in the more complex features. Once that is done it will be open for exploration. Of course, if someone can beat me to the punch I would be happy to hear of it.

Previous
Previous

A Little Order

Next
Next

Remesh - Easy Cleanup and Stylization