Fix #100973: Node Wrangler: Previewing node if hierarchy not active
[blender-addons.git] / io_mesh_atomic / pdb_export.py
blob8888c062f0a2af58bcb2831c4b6cbf19e65c1b2a
1 # SPDX-FileCopyrightText: 2019-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
5 import bpy
6 from io_mesh_atomic.pdb_import import ELEMENTS_DEFAULT
8 class AtomPropExport(object):
9 __slots__ = ('element', 'location')
10 def __init__(self, element, location):
11 self.element = element
12 self.location = location
15 def export_pdb(obj_type, filepath_pdb):
17 list_atoms = []
18 for obj in bpy.context.selected_objects:
20 if "STICK" in obj.name.upper():
21 continue
23 if obj.type not in {'MESH', 'SURFACE', 'META'}:
24 continue
26 name = ""
27 for element in ELEMENTS_DEFAULT:
28 if element[1] in obj.name:
29 if element[2] == "Vac":
30 name = "X"
31 else:
32 name = element[2]
34 if name == "":
35 if obj_type == "0":
36 name = "?"
37 else:
38 continue
40 if len(obj.children) != 0:
41 for vertex in obj.data.vertices:
42 location = obj.matrix_world @ vertex.co
43 list_atoms.append(AtomPropExport(name, location))
44 else:
45 if not obj.parent:
46 location = obj.location
47 list_atoms.append(AtomPropExport(name, location))
49 pdb_file_p = open(filepath_pdb, "w")
50 pdb_file_p.write("REMARK This pdb file has been created with Blender "
51 "and the addon Atomic Blender - PDB\n"
52 "REMARK For more details see the wiki pages of Blender.\n"
53 "REMARK\n"
54 "REMARK\n")
56 for i, atom in enumerate(list_atoms):
57 string = "ATOM %6d%3s%24.3f%8.3f%8.3f%6.2f%6.2f%12s\n" % (
58 i, atom.element,
59 atom.location[0],
60 atom.location[1],
61 atom.location[2],
62 1.00, 1.00, atom.element)
63 pdb_file_p.write(string)
65 pdb_file_p.close()
67 return True