diff options
author | Clemens Barth <barth@root-1.de> | 2019-03-28 12:37:49 +0300 |
---|---|---|
committer | Clemens Barth <barth@root-1.de> | 2019-03-28 12:37:49 +0300 |
commit | 9791bd3a2233ace2d8a588c4f8b7fe6cb4c8fa7e (patch) | |
tree | bfd9c54d67676a8b992dbf50fdfc3ef69c9a1997 /io_mesh_atomic/pdb_export.py | |
parent | 6ee42b89a9cf2fae3320d037c606646c73c66f0d (diff) |
The new ‘Atomic Blender PDB/XYZ’ importer. T62804
Comments
========
This is the fusion of the 3 atomic blender addons from Blender 2.79:
1. PDB (I/O addon for .pdb files, was in trunk before)
2. XYZ (I/O addon for .xyz files, was in contrib before)
3. Utilities (panel for modifying atomic structures, was in contrib before),
into one single addon called ‘Atomic Blender PDB/XYZ’.
Diffstat (limited to 'io_mesh_atomic/pdb_export.py')
-rw-r--r-- | io_mesh_atomic/pdb_export.py | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/io_mesh_atomic/pdb_export.py b/io_mesh_atomic/pdb_export.py new file mode 100644 index 00000000..949ee5e2 --- /dev/null +++ b/io_mesh_atomic/pdb_export.py @@ -0,0 +1,81 @@ +# ##### BEGIN GPL LICENSE BLOCK ##### +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +import bpy +from io_mesh_atomic.pdb_import import ELEMENTS_DEFAULT + +class AtomPropExport(object): + __slots__ = ('element', 'location') + def __init__(self, element, location): + self.element = element + self.location = location + + +def export_pdb(obj_type, filepath_pdb): + + list_atoms = [] + for obj in bpy.context.selected_objects: + + if "STICK" in obj.name.upper(): + continue + + if obj.type not in {'MESH', 'SURFACE', 'META'}: + continue + + name = "" + for element in ELEMENTS_DEFAULT: + if element[1] in obj.name: + if element[2] == "Vac": + name = "X" + else: + name = element[2] + + if name == "": + if obj_type == "0": + name = "?" + else: + continue + + if len(obj.children) != 0: + for vertex in obj.data.vertices: + location = obj.matrix_world @ vertex.co + list_atoms.append(AtomPropExport(name, location)) + else: + if not obj.parent: + location = obj.location + list_atoms.append(AtomPropExport(name, location)) + + pdb_file_p = open(filepath_pdb, "w") + pdb_file_p.write("REMARK This pdb file has been created with Blender " + "and the addon Atomic Blender - PDB\n" + "REMARK For more details see the wiki pages of Blender.\n" + "REMARK\n" + "REMARK\n") + + for i, atom in enumerate(list_atoms): + string = "ATOM %6d%3s%24.3f%8.3f%8.3f%6.2f%6.2f%12s\n" % ( + i, atom.element, + atom.location[0], + atom.location[1], + atom.location[2], + 1.00, 1.00, atom.element) + pdb_file_p.write(string) + + pdb_file_p.close() + + return True |