Cleanup: quiet float argument to in type warning
[blender-addons.git] / io_mesh_atomic / pdb_export.py
blob6bac0a05cd7fea86cddd07e7f9f4f5bc2965ed9b
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from io_mesh_atomic.pdb_import import ELEMENTS_DEFAULT
6 class AtomPropExport(object):
7 __slots__ = ('element', 'location')
8 def __init__(self, element, location):
9 self.element = element
10 self.location = location
13 def export_pdb(obj_type, filepath_pdb):
15 list_atoms = []
16 for obj in bpy.context.selected_objects:
18 if "STICK" in obj.name.upper():
19 continue
21 if obj.type not in {'MESH', 'SURFACE', 'META'}:
22 continue
24 name = ""
25 for element in ELEMENTS_DEFAULT:
26 if element[1] in obj.name:
27 if element[2] == "Vac":
28 name = "X"
29 else:
30 name = element[2]
32 if name == "":
33 if obj_type == "0":
34 name = "?"
35 else:
36 continue
38 if len(obj.children) != 0:
39 for vertex in obj.data.vertices:
40 location = obj.matrix_world @ vertex.co
41 list_atoms.append(AtomPropExport(name, location))
42 else:
43 if not obj.parent:
44 location = obj.location
45 list_atoms.append(AtomPropExport(name, location))
47 pdb_file_p = open(filepath_pdb, "w")
48 pdb_file_p.write("REMARK This pdb file has been created with Blender "
49 "and the addon Atomic Blender - PDB\n"
50 "REMARK For more details see the wiki pages of Blender.\n"
51 "REMARK\n"
52 "REMARK\n")
54 for i, atom in enumerate(list_atoms):
55 string = "ATOM %6d%3s%24.3f%8.3f%8.3f%6.2f%6.2f%12s\n" % (
56 i, atom.element,
57 atom.location[0],
58 atom.location[1],
59 atom.location[2],
60 1.00, 1.00, atom.element)
61 pdb_file_p.write(string)
63 pdb_file_p.close()
65 return True