I fixed these file convention problems of the first version.
Now you should be able to import pdb files from databases like PDB (http://www.rcsb.org) properly.
Please try it out and report bugs!
For those who didn’t read the first thread:
It’s more a wizard than a conversion tool as the pdb-files only provides atom types and positions and connectivity tables. The script builds balls of different sizes for any atom with materials linked to the atom types. When chosen the atoms are connected by sticks with rounded ends.
Thanks for the update, the previous one didn’t work for me at all. This works here in Blender 242a, Python 2.3, SuSE Linux 9.2. Whatever code in this is responsible for it being backward compatible with Python 2.3, please don’t change this
Now I have a highly flexible way of working with PDB models in addition to exporting RIB’s from VMD, and POVRay variants like POVChem, Grasp4POV, POVscript, and PyMOL and Jmol.
Hello, thanks for your script. It imports pdbs from CORINA (http://www.molecular-networks.com/online_demos/corina_demo.html ) with the right positions but it appears it can only recognize one atom type. Is this a problem with the pdbs? I’m using Blender 2.42a. Regards, rwst
P.S. I just see the pdbs work if you remove and everything after ’ 0.00 0.00’ in the ATOM lines. Thanks anyway!
I remember years ago having to parse the PDB file format for an online Shockwave 3D viewer ( interactive ) - as the file only stores positiions, it was challenging figuring out how to recreate structures such as bonds etc from them optimally - also, some of the PDB files stored huge amounts of data.
You can specify PDB ids and load them directly - they will stream from the main server ( you’ll probably get a security alert, as it tries to load the data from a different server, the main one in the US ).
Keep up the great work with the Blender plugin - I’m sure we’ll see some great renders of molecules with lots of fancy rendering features ( AO, NPR etc )
for a very fast way to build a structure in blender i use a small script which makes a vertex for each ATOM entry in a pdb file. This takes about 1 second for a file with 7000 atoms.
After that i add a sphere as child to that mesh and use DupliVert to display it at each vertex. The advantage is that you still have control over the appearance of balls after creation.
For anyone who has problems with some pdb files, Babel or OpenBabel solves a lot of them. http://openbabel.sourceforge.net/wiki/Guides
Thanks for your comments and bug reports!
I will try to improve pdb2blend according all of your suggestions and to eliminate the reported bugs!
I was thinking about this strategy too - especially for big structures.
Not yet. It should be possible to build such surfaces from structures in blender. However if the programs you use store those surfaces in special file formats it should be possible to extract the information one needs too build up a surface in blender.
Whats about starting your script with building vertices for ATOMs and edges for CONECTs. And in a 2nd run you assign Meshes to these.
For the Atoms you can DupliVert everything you love to but I am not sure how easy it is to handle the connections.
sorry for not answering your mail yet. I had a lot of work and so it left my mind too fast.
However - why not? I will mail you a concept of the way I think this script could be improved.
This is indeed the way I want to go. However my idea is to place two additional vertices at the middle of the connection and use vertex groups for atom types. This way multimaterial meshes can be built leading to simple stick-models when using wire-materials.
I want to separate import- and modelling routines, making it easier to handle molecules and even to change the 3d structure in blender.
This is a great script, just what I needed for my current project! But, I am having a problem. It doesn’t make the sticks connecting all the spheres. I downloaded this .pdb and can import it correctly into Blender with this script. However, when you compare what you get in Blender with the view of it here, you can see that there is a big difference. Only a few atoms are connected thanks to the CONECT tags at the botton of the .pdb file, but not all of them like they are shown in the WebMol viewer. I would really like all of the sticks to be made, but do not know how to do this. Thanks for your help and work on this script!
By definition, PDB files must only contain atom coordinates, not bond records (which, as you correctly noticed, are defined as CONECT records). PDB files CAN contain extra info though. Most molecular viewers draw bonds between atoms by making the assumption that atoms with a certain distance must be bonded. Usually this assumption is sufficient to draw a reasonable molecule, for things like DNA, proteins and peptides. But for drugs, co-factors, and other small and strained molecules, it is not always a safe assumption that atoms are bound if they are close together. This is really a general limitation in the PDB file format.
You have at least two choices to draw bonds correctly: 1) explicitly write them out as CONECT records in the PDB file then load that file, or 2) draw them after the PDB file has been interpreted, by making the distance assumption. Roughly speaking, you can assume that a useful distance to assume is when d is less than the sum of the van der Waals radii of the atoms in question (that is, draw a bond when there is interpenetration of vdW spheres). Van der Waals radii can be looked up all over the web, or in the classical reference (A.Bondi, J. Phys. Chem., 68, 441-452, 1964).
I guess another alternative would be to import your PDB file into some molecular modeling program, and have it write out explicit CONECT records. I can’t think of any free program that will do so reliably, off the top of my head. It really shouldn’t be too terribly tedious to edit the CONECT records manually for a single file.
The PRODRG server ( davapc1.bioch.dundee.ac.uk/prodrg ) generates PDBs with CONECT statements for small molecules, and it’s free for non-profit use. Like Omega says, you can infer the bonds in case of proteins and DNA.