Atomic Blender (PDB/XYZ) - for Blender 2.8 and higher

Hello!
First of all I’d like to thank you for this addon as a computational chemist I thank you from the bottom of my heart.

Now to my question: Is there a way to have bonds formation/creation during an animation?

To be more specific, I have a multi frame xyz from a molecular dynamics simulation which I can load using your addon but there are no bonds (of course it’s xyz) . I was wondering if there was a way to add the bonds (I don’t mind doing some python scripting like calculating distances and adding bonds within a cutoff if it’s necessary) for each frame.

Thanks a lot again

Great to read this, thank you.

I’m sorry, I have to disappoint you so far, however, read the end. So, a priori, there is no algorithm included to search for possible bonds, as it is done, e.g., in the Avogadro software. Furthermore, the file format xyz does not describe the bonds as you write yourself. From this, there is no way of including your ‘dynamic’ bonding.

For including this ‘dynamic’ bonding, you have to ‘hard code’ the sticks into your structure after its import. And this needs to be done for each frame. This requires some real hard work and good skills in Blender Python programming! :wink: If you want to try, you need to know how to create the sticks. In the PDB importer (see code), you find the definition build_stick(radius, length, sectors, element_name). Then, you have to iterate over all frames and search the atoms that shall be connected. This is probably the hardest task to do (to find the correct atoms). All this should be possible, but requires some time.

Otherwise, you could write a Python script that imports each structure described in a PDB file (with sticks mentioned via CONECT!) and to assign this structure to a frame. So, when you have 100 frames you need 100 PDB files. All this should be indeed possible and requires only a bit knowledge of the Blender Python environment.
So, what you need to import a PDB structure into Blender is the definition:

import_pdb(Ball_type,
	               Ball_azimuth,
	               Ball_zenith,
	               Ball_radius_factor,
	               radiustype,
	               Ball_distance_factor,
	               use_sticks,
	               use_sticks_type,
	               sticks_subdiv_view,
	               sticks_subdiv_render,
	               use_sticks_color,
	               use_sticks_smooth,
	               use_sticks_bonds,
	               use_sticks_one_object,
	               use_sticks_one_object_nr,
	               Stick_unit, Stick_dist,
	               Stick_sectors,
	               Stick_diameter,
	               put_to_center,
	               use_camera,
	               use_light,
	               filepath_pdb)

I hope that helps, let me know … .

Greetings.

PS: By the way, here is the code for the XYZ import. There you see, how to deal with the frames (def build_frames(frame_delta, frame_skip)).

Thanks a lot for your reply.

I was expecting it so do not worry!

Just to be sure I understood correctly, If I have a xyz file what I should do is:
1)Create a PDB file for each “frame” (it should be easy with openbabel)
2)Import each PDB file as frame via blender python scripting
3) Setting up the scene as I want
4)Render

Am I correct?

Thanks again, really.

P.s. Is there a way I can buy you a coffee?

Good. :wink:

Yes. Step 2) requires some scripting work in Blender Python. You have to import, say, 100 PDB snapshot structures and assign each of them to one frame. The principle definition for the import and the handling of the frames after you have imported the 100 snapshots are mentioned above.

:slight_smile: No, it’s okay, just keep me (us) informed here what you have done. If you have found a solution, then, plz, post the code here in the thread, I and others could possibly use it. Thanks in advance.

By the way. In the Python script, you call the definitions via an operator like:

bpy.ops.import_mesh.pdb(<options>)

In the script, you have to basically do:

list_objects_snapshots = []
for file in list_files:
    bpy.ops.import_mesh.pdb(<options>)
    list_objects_snapshots.apped( <selected object> )

Here then: create frames with `list_objects_snapshots`

… and that’s it.

PS: You can execute a python script via calling blender in the terminal, with Blender -P <script>

Ok! Seems something I may be able to do, If I manage to achieve some decent code I will post it here for future uses

1 Like

Hello again,

Sorry for bothering you but I have some problems using the operators.

After taking a good look at the code I’ve realized that to select types (Ball_type, radiustype … etc) you use strings like ‘0’ ‘1’ and so on, True or False to activate and deactivate functions such as bonds and int/float for the rest.

My code so far is

import glob
pdb_files = glob.glob ('C:/Users/Davide/Desktop/*.pdb')
for snap in pdb_files:
    frame = bpy.ops.import_mesh.pdb(
    Ball_type = "1",
    Ball_azimuth = 32,
    Ball_zenith = 32,
    Ball_radius_factor = 0.6,
    radiustype = "0",
    Ball_distance_factor =1.00,
    use_sticks = True,
    use_sticks_type = "0",
    sticks_subdiv_view = 2,
    sticks_subdiv_render = 2,
    use_sticks_color = True,
    use_sticks_smooth = True,
    use_sticks_bonds = True,
    use_sticks_one_object = False,
    use_sticks_one_object_nr = 200,
    Stick_unit = 0.05, 
    Stick_dist = 1.10,
    Stick_sectors = 20,
    Stick_diameter = 40,
    put_to_center = True, 
    use_camera = False ,
    use_light = False,
    filepath_pdb = snap
    )
    list_objects_snapshots.apped(frame)

It raises me different errors if I leave the name of the arguments as written above it raises me errors like:
"keyword “Ball_type” unrecognized.

If I remove the name it raises different argv errors.

I tried my best how to figure it out but I couldn’t , Do you have any suggestion?

Thanks, really.

Hi Nekkrad.

Strange … hmmm, I will have a look the next days, I’m somewhat busy atm. May be tomorrow. Meanwhile, post in your message all kind of errors. Thx.

Cheers.

Yes. Here is the code:

import glob
import bpy

pdb_files = glob.glob ('C:/Users/Davide/Desktop/*.pdb')
list_objects_snapshots = []

for snap in pdb_files:

    frame = bpy.ops.import_mesh.pdb(
        filepath=snap,
        filter_glob="*.pdb",
        use_center=True,
        use_camera=False,
        use_light=False,
        ball='0',
        mesh_azimuth=32,
        mesh_zenith=32,
        scale_ballradius=1,
        scale_distances=1,
        atomradius='0',
        use_sticks=True,
        use_sticks_type='0',
        sticks_subdiv_view=2,
        sticks_subdiv_render=2,
        sticks_sectors=20,
        sticks_radius=0.2,
        sticks_unit_length=0.05,
        use_sticks_color=True,
        use_sticks_smooth=True,
        use_sticks_bonds=False,
        sticks_dist=1.1,
        use_sticks_one_object=False,
        use_sticks_one_object_nr=200,
        datafile="")

    list_objects_snapshots.apped(frame)

You just have to change the options … .

Cheers.

PS: By the way, in the Python console of Blender, typing bpy. and then pressing the key ‘TAB’ shows you all possible sub commands and its options with some explanations if existant. <= This is very useful !!!

Oh Thank you very much!

Yes I saw that python is really well implemented but I am still learning blender and its python enviroment.

Thanks again

Hi Nekkrad.

Does it work?

Hi!
Yes! Now I am trying to loop over the many pdb files to recreate my simulations using blender frames.

I will post the code If I will ever manage

Thanks again!

Note: 2022-01-24

For the Blender version 3.1, which will appear in the first week of March 2022 (see here) , the add-on has been entirely revised such that a full functionality of the add-on can be guaranteed. Current bug removal, improvements and changes can be followed here: Link. The current manual for the add-on can be found here: manual

All the best, Blendphys.

1 Like

Hello,

Is it possible to select the residue or atom names/numbers within atomic blender?

ChemHG. I know this is like years later, but I had the same issue and I was able to solve it. You just need to either type n while you have blender open to open that utility panel or, in the topright of the screen, you will see a little < sign. It will be right by the datum that shows the axis. It’s very small. Then open the Create tab to get the Utilities panel open.

@German_Barcenas: I have the same issue, but I still don’t succeed in making the Atomic Blender Utilities Panel visible.
If I press n or click the < sign as you described, I just get the usual sidebar opened at the right side of the 3D Viewport window, but nothing similar to the panel which is shown here.
You wrote that the Create tab should be opened, but I’m unable (or maybe too dumb) to find that either. The sidebar has only the tabs Item, Tool and View.

BTW, I’m using Blender version 3.1.2, and installing and activating both addons (Atomic Blender PDB/XYZ and Atomic Blender - Utilities) went smoothly. They both show up in the preferences. I can import PDB or XYZ format structures, but even with such a structure imported in blender, I don’t get the panel.

Thanks for any further help.
German_Chemist

I can’t post pictures unfortunately. When you open that panel with n or by clicking <, you’ll see some column pop up right? There will be some new Active Tool panel that opens. Look to the right of that panel. You will see 3 tabs that are vertical with letters that are sideways. It will be open on Tools already. Look down a couple of tabs and you will see Create. Select that tab. A new panel will open up with the Atomic Blender Utilities. Open it. For some reason it is created close. That’s it(: Hope I could help.

thanks a lot for the kind explanation. I have opened up a new panel with the Atomic Blender Utilities. But the problem is I am still not able to import a pdb file…

Dear all,

sorry for being late. - I think that you all now know how to find the Atomic Blender panel … so far so good. In future, I will put some text into the documentation, remember, the latter is here.

Xuefepan, please, can you supply the PDB file? Otherwise, it is almost impossible to find out where the problem is. Thanks.

Please, what do you mean by residue and atom numbers?