Atomic Blender for loading XYZ files into Blender

2019-12-24:

The add-on got modified starting with Blender 2.8. Please, post any comments and questions in the thread here:

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

Thank you! Blendphys.

.
.
.
.
Dear all.

So this is my second project and importer for Blender: Atomic Blender - XYZ

Tracker
Introduction
Wiki1

Wiki2

Atomic Blender - XYZ imports all atoms, which are described in a xyz file (.xyz). It even imports all frames and links each frame to a shape key such that nice animations can be done with Blender.

The importer is very useful for scientists (especially theorists) who store atom positions and snapshots of calculations into these type of files.

Watch these examples to get a feeling what the script is doing:Examples 1

Examples 2
Or here:

Have fun!

Cheers,

Blendphys

This is an awesome tool. Thank you so much for releasing this. I’m using it in conjunction with Octane Render. Excellent work.

Great to hear this, thanks. BTW, if you need PDB file import/export, look here: http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/PDB

PS: If you have some nice examples, please, show them here in the forum. Thanks!

Hey Blendphys,
First of all thanks for this awesome tool :slight_smile: I’ll probably use it for creating some images for my final project for my bachelor degree in chemistry :slight_smile:
I do have two questions:

  1. When I import frames (5k to be precise, for a simulation of 32 water molecules) and I try to run this animation, it becomes very slow. I can understand that 96 atoms with 5k keys might be a little too much too ask for, but I want to be sure that this actually normal and not some wrong doing on my part, so is it?
  2. With just a frame imported it has both the base oxygen and hydrogen sphere in the origin, which I don’t want is there anyway to delete it without deleting the, which I assume to be, instances or something as well?

Thanks again for taking the time to write this script, and I hope to hear from you soon.

… see next comment …

Thanks Month.

5000 frames (96 balls) is already a lot. Note that you can also load only each 2nd or 3rd frame. More details about the addon can be found here - Well, depending on the computer power it might get slow, yes.
Note further that what you see are your atoms moving in the 3D scene. You still need to render the whole thing. For 5000 frames it may take a while depending on how you further change/modify the scene. I wouldn’t wonder if your computer calculates over night.

This is only visible in the 3D scene, and you cannot remove it so far. However, when you render the scene, they certainly disappear.

Just ask if you have further questions. And, btw: if you have some cool animations done with this addon, show it here, thanks.

yeah I was afraid that 5k frames would be too much. Thanks for clearing it up :slight_smile:
and good to hear there won’t be any problem with those spheres in the origin.

I’ll have to do several illustrations for my bachelor thesis, as well as some actual animations for my presentation :slight_smile: so I’ll probably have something to show (it has to be finished in 2 months, but I’ll probably have some pictures as soon as next week)

Thanks for the quick and elaborate response! It’s appreciated

some pictures as promised.






I’ll probably do a proper animation as well for my presentations, so I’ll probably have that in a couple of weeks :slight_smile:

Month,

these are very cool images, congratulations! I’m really keen on watching the animation … .

Dear Blendphys,

Thank you very much for this Add-on! I were looking for this tool long time ago, but I did not find anything.
I’ve got a question. Is there a way to compute bondings between atoms? In Month’s pictures there are bondings between oxygen and hydrogen, but I don’t know how to compute or create that bondings during the importation process.

Thank you!

Dear Basie.

Sorry for being late, I’m quite busy atm.

Thanks a lot.

I’ve got a question. Is there a way to compute bondings between atoms? In Month’s pictures there are bondings between oxygen and hydrogen, but I don’t know how to compute or create that bondings during the importation process.
Well, xyz files do not include sticks, and there is no such computing in the code of the addon at the moment. I think that Month has put in the sticks manually.
For one frame in a xyz file: If you want to have sticks, load your xyz into Avogadro, it normally calculates and displays sticks. After, store your structure into PDB, which you then load with the PDB Importer.

I hope that this helps.

Thank you for your response. I’ve been busy and did not check the forum.

For a static image, using Avogadro could be an option, but what I’m looking for is using Blender as a GUI for another software (called tetr) for creating and manipulating different inputs.
At the moment that software has a text-based interface and I am using Jmol for visualice the xyz file generated by tetr, but my idea is to create a python script that glues both programs and edit the inputs directly from blender calling to the other program’s functions (tetr’s functions) using python and importing the resulting xyz files every each modification using your script (or maybe a modified version adapted for editing the atoms individually).

Maybe it is not the best option, it is only an idea in progress.

As far as I have understood, you load your xyz into Blender and use the 3D modeler for modifying your atoms (positions). Then, you want to store this as an XYZ file for instance to read it into your Jmol, right?

In fact, you can save a scene into a PDB file by exporting selected objects with the PDB exporter. PDB Exporter - I will see, exporting selected objects from Blender into XYZ should be quite easy. But before, plz, tell me if all this is what you want. I then deal with the exporter during the weekend.

However, I have the feeling that you want to do even more, programming an interface between programs. Hmmm, this asks for a new addon.

In any case, describe precisely what shall be done. Which program is producing which kind of file (XYZ …) and what shall be done in each program, especially in Blender.

More or less. I want to load the xyz file into Blender, but in principle I do not need to export another modified xyz file. Let me explain more precisely (sorry for confusing you, but english is not my lenguage).

You have an input file (a file with parameters for a calculation and the geometry of your system).
Tetr is a text-based software which reads that input files and modify the geometry. After each modification, tetr generates a xyz file for visualize the new geometry. Up to now , I use Jmol for view that xyz files and check which atoms I have to select for editing, so I have to go to tetr, select the atoms in tetr and perform the modification, and reload the xyz file in Jmol.

You are right. It requires a new addon. In fact, what I want to do is a GUI for tetr. I would like to create an addon which loads into blender the xyz generated by tetr (the xyz file is only_for_visualiztion ), select the atoms you want to modify and call to tetr to perform such modifications on the selected atoms ( in fact you are modifying the original input file which was read by tetr) and reload the new xyz file for view the modified file. After all the modifications tetr will save the final file for the diferent calculation softwares.

But what I’m thinking now is that maybe it is not as good idea as I thought because manage interatomic distances into blender is not so confortable, every atoms should be a different object, bondings between atoms shall be static (i mean, you’ll move an atom, but the stick will remain at the same place).

As you can see I have no idea about how to create a GUI. Sorry for using your thread for this, maybe is a better idea to create a new thread.

In short, for improve your importer, computing bonds between atoms could be a very good point for making good images and animations!

Okay, I see.

I would like to create an addon which loads into blender the xyz generated by tetr (the xyz file is only_for_visualiztion ), select the atoms you want to modify and call to tetr to perform such modifications on the selected atoms ( in fact you are modifying the original input file which was read by tetr) and reload the new xyz file for view the modified file. After all the modifications tetr will save the final file for the diferent calculation softwares.
Yep, this asks for a new addon. Note that Blender would produce ‘a modified XYZ file’ since you have to tell tetr about the changes etc. The XYZ files do not foresee this (well, files I have seen).

But what I’m thinking now is that maybe it is not as good idea as I thought because manage interatomic distances into blender is not so confortable, every atoms should be a different object, bondings between atoms shall be static (i mean, you’ll move an atom, but the stick will remain at the same place).
That is possible. You can move a single atom by moving the single vertex in the Edit Mode. The same applies for the sticks (if present).

As you can see I have no idea about how to create a GUI. Sorry for using your thread for this, maybe is a better idea to create a new thread.
No, no. No problem. :evilgrin:

In short, for improve your importer, computing bonds between atoms could be a very good point for making good images and animations!
Well, okay I agree. This asks for some effort however. Some chemistry input has to be included: One could cross-check an options such that he shows sticks between C and H, C=C, O-H and so on … . May be, there is already some code available. Let’s see.

I have a general question about the XYZ import addon: Is there any way to separate all of my spheres into individual NURBs? Right now they’re all grouped together. Thanks!

Hi kedmond.

Sorry, for being late … .

Yes there is. First, de-select all objects and after, select all those objects (molecular structures etc.) with the mouse, which shall be transformed into real objects. Then push ‘Ctrl-Shift-A’. => All balls are individual objects.

After, in the outliner, delete all ‘objects’ called ‘hydrogen’, ‘nitrogen’, etc. The latter are the remaining dupliverts structures, which you don’t need anymore.

I hope this helps … if not ask …

Hi there,

your extensions looks very interesting for me, as we are dealing with xyz files through povray up to now.
But trying to get it to work with Blender 2.62 in Ubuntu 12.04 I have some problems: Only the first frame of a multiframe xyz file gets imported. With option ‘Load all frames’ I receive the following error message:

File "~/.blender/2.62/scripts/addons/io_mesh_xyz/__init__.py", line 196, in
 execute self.skip_frames)
File "~/.blender/2.62/scripts/addons/io_mesh_xyz/import_xyz.py", line 678, in build_frames
  bpy.ops.object.shape_key_add(True)
File "/usr/lib/blender/scripts/modules/bpy/ops.py", line 178, in __call__ 
  ret = op_call(self.idname_py(), C_dict, kw, C_exec)
TypeError: Calling operator "bpy.ops.object_shape_key_add" error, custom context expected a dict or None, got a bool
location:<unknown location>:-1

(Not sure if these CODE-Tags make it easier to read)

So my questions would be

Does anyone have an idea what to do?
How can I copy the text of the error message so that I don’t have to type it in manually each time? :wink:

Any help much appreciated!

Cheerz,
Mboy

Hi Mboy.

your extensions looks very interesting for me, as we are dealing with xyz files through povray up to now. But trying to get it to work with Blender 2.62 in Ubuntu 12.04 I have some problems: Only the first frame of a multiframe xyz file gets imported. With option ‘Load all frames’ I receive the following error message:

You should use the newest version of Blender: version 2.64. Here, you can read how you can always have the latest version of Blender, in particular for Ubuntu. For more information read the Wiki page.

File "~/.blender/2.62/scripts/addons/io_mesh_xyz/__init__.py", line 196, in
 execute self.skip_frames)
File "~/.blender/2.62/scripts/addons/io_mesh_xyz/import_xyz.py", line 678, in build_frames
  bpy.ops.object.shape_key_add(True)
File "/usr/lib/blender/scripts/modules/bpy/ops.py", line 178, in __call__ 
  ret = op_call(self.idname_py(), C_dict, kw, C_exec)
TypeError: Calling operator "bpy.ops.object_shape_key_add" error, custom context expected a dict or None, got a bool
location:<unknown location>:-1

So my questions would be Does anyone have an idea what to do?

This error code is very difficult to analyse since you use an old version of Blender. I guess that it is due to some slight changes of the coding in Blender, which I had to adapt. It produces this error message with older Blender versions. - So, please, install version 2.64.

However, would it be possible that you send us or me the xyz file? - I’m curious if your xyz file works with the new version of Blender and the addon. Thanks.

PS:

(Not sure if these CODE-Tags make it easier to read)

Yes, they do. :slight_smile:

How can I copy the text of the error message so that I don’t have to type it in manually each time? :wink:

Start Blender in a terminal. The error code is also printed in the terminal, and you can copy and paste the message easily.

I’m trying to use xyz import in 2.65 and it seems to only load one frame from the example provided at http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/XYZ Am I missing something?