forked from blender/blender-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpdb_export.py
67 lines (53 loc) · 2.05 KB
/
pdb_export.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# SPDX-FileCopyrightText: 2019-2022 Blender Foundation
#
# SPDX-License-Identifier: GPL-2.0-or-later
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