1 # SPDX-License-Identifier: GPL-2.0-or-later
4 from bpy
.types
import Operator
, AddonPreferences
5 from bpy_extras
.io_utils
import ImportHelper
, ExportHelper
6 from bpy
.props
import (
14 from io_mesh_atomic
.pdb_import
import import_pdb
15 from io_mesh_atomic
.pdb_export
import export_pdb
17 # -----------------------------------------------------------------------------
20 # This is the class for the file dialog of the importer.
21 class IMPORT_OT_pdb(Operator
, ImportHelper
):
22 bl_idname
= "import_mesh.pdb"
23 bl_label
= "Import Protein Data Bank(*.pdb)"
24 bl_options
= {'PRESET', 'UNDO'}
27 filter_glob
: StringProperty(default
="*.pdb", options
={'HIDDEN'},)
29 use_center
: BoolProperty(
30 name
= "Object to origin", default
=True,
31 description
= "Put the object into the global origin")
32 use_camera
: BoolProperty(
33 name
="Camera", default
=False,
34 description
="Do you need a camera?")
35 use_light
: BoolProperty(
36 name
="Lamp", default
=False,
37 description
= "Do you need a lamp?")
40 description
="Choose ball",
41 items
=(('0', "NURBS", "NURBS balls"),
42 ('1', "Mesh" , "Mesh balls"),
43 ('2', "Meta" , "Metaballs")),
45 mesh_azimuth
: IntProperty(
46 name
= "Azimuth", default
=32, min=1,
47 description
= "Number of sectors (azimuth)")
48 mesh_zenith
: IntProperty(
49 name
= "Zenith", default
=32, min=1,
50 description
= "Number of sectors (zenith)")
51 scale_ballradius
: FloatProperty(
52 name
= "Balls", default
=1.0, min=0.0001,
53 description
= "Scale factor for all atom radii")
54 scale_distances
: FloatProperty (
55 name
= "Distances", default
=1.0, min=0.0001,
56 description
= "Scale factor for all distances")
57 atomradius
: EnumProperty(
59 description
="Choose type of atom radius",
60 items
=(('0', "Pre-defined", "Use pre-defined radius"),
61 ('1', "Atomic", "Use atomic radius"),
62 ('2', "van der Waals", "Use van der Waals radius")),
64 use_sticks
: BoolProperty(
65 name
="Use sticks", default
=True,
66 description
="Do you want to display the sticks?")
67 use_sticks_type
: EnumProperty(
69 description
="Choose type of stick",
70 items
=(('0', "Dupliverts", "Use dupliverts structures"),
71 ('1', "Skin", "Use skin and subdivision modifier"),
72 ('2', "Normal", "Use simple cylinders")),
74 sticks_subdiv_view
: IntProperty(
75 name
= "SubDivV", default
=2, min=1,
76 description
="Number of subdivisions (view)")
77 sticks_subdiv_render
: IntProperty(
78 name
= "SubDivR", default
=2, min=1,
79 description
="Number of subdivisions (render)")
80 sticks_sectors
: IntProperty(
81 name
= "Sector", default
=20, min=1,
82 description
="Number of sectors of a stick")
83 sticks_radius
: FloatProperty(
84 name
= "Radius", default
=0.2, min=0.0001,
85 description
="Radius of a stick")
86 sticks_unit_length
: FloatProperty(
87 name
= "Unit", default
=0.05, min=0.0001,
88 description
= "Length of the unit of a stick in Angstrom")
89 use_sticks_color
: BoolProperty(
90 name
="Color", default
=True,
91 description
="The sticks appear in the color of the atoms")
92 use_sticks_smooth
: BoolProperty(
93 name
="Smooth", default
=True,
94 description
="The sticks are round (sectors are not visible)")
95 use_sticks_bonds
: BoolProperty(
96 name
="Bonds", default
=False,
97 description
="Show double and triple bonds")
98 sticks_dist
: FloatProperty(
99 name
="", default
= 1.1, min=1.0, max=3.0,
100 description
="Distance between sticks measured in stick diameter")
101 use_sticks_one_object
: BoolProperty(
102 name
="One object", default
=False,
103 description
="All sticks are one object")
104 use_sticks_one_object_nr
: IntProperty(
105 name
= "No.", default
=200, min=10,
106 description
="Number of sticks to be grouped at once")
107 datafile
: StringProperty(
108 name
= "", description
="Path to your custom data file",
109 maxlen
= 256, default
= "", subtype
='FILE_PATH')
111 # This thing here just guarantees that the menu entry is not active when the
112 # check box in the addon preferences is not activated! See __init__.py
114 def poll(cls
, context
):
115 pref
= context
.preferences
116 return pref
.addons
[__package__
].preferences
.bool_pdb
118 def draw(self
, context
):
121 row
.prop(self
, "use_camera")
122 row
.prop(self
, "use_light")
124 row
.prop(self
, "use_center")
128 row
.label(text
="Balls / atoms")
131 col
.prop(self
, "ball")
133 row
.active
= (self
.ball
== "1")
134 col
= row
.column(align
=True)
135 col
.prop(self
, "mesh_azimuth")
136 col
.prop(self
, "mesh_zenith")
139 col
.label(text
="Scaling factors")
140 col
= row
.column(align
=True)
141 col
.prop(self
, "scale_ballradius")
142 col
.prop(self
, "scale_distances")
144 row
.prop(self
, "atomradius")
148 row
.label(text
="Sticks / bonds")
150 row
.prop(self
, "use_sticks")
152 row
.active
= self
.use_sticks
153 row
.prop(self
, "use_sticks_type")
155 row
.active
= self
.use_sticks
157 if self
.use_sticks_type
== '0' or self
.use_sticks_type
== '2':
158 col
.prop(self
, "sticks_sectors")
159 col
.prop(self
, "sticks_radius")
160 if self
.use_sticks_type
== '1':
162 row
.active
= self
.use_sticks
163 row
.prop(self
, "sticks_subdiv_view")
164 row
.prop(self
, "sticks_subdiv_render")
166 row
.active
= self
.use_sticks
167 if self
.use_sticks_type
== '0':
168 col
.prop(self
, "sticks_unit_length")
169 col
= row
.column(align
=True)
170 if self
.use_sticks_type
== '0':
171 col
.prop(self
, "use_sticks_color")
172 col
.prop(self
, "use_sticks_smooth")
173 if self
.use_sticks_type
== '0' or self
.use_sticks_type
== '2':
174 col
.prop(self
, "use_sticks_bonds")
176 if self
.use_sticks_type
== '0':
177 row
.active
= self
.use_sticks
and self
.use_sticks_bonds
178 row
.label(text
="Distance")
179 row
.prop(self
, "sticks_dist")
180 if self
.use_sticks_type
== '2':
181 row
.active
= self
.use_sticks
183 col
.prop(self
, "use_sticks_one_object")
185 col
.active
= self
.use_sticks_one_object
186 col
.prop(self
, "use_sticks_one_object_nr")
189 def execute(self
, context
):
190 # Switch to 'OBJECT' mode when in 'EDIT' mode.
191 if bpy
.context
.mode
== 'EDIT_MESH':
192 bpy
.ops
.object.mode_set(mode
='OBJECT', toggle
=False)
194 # This is in order to solve this strange 'relative path' thing.
195 filepath_pdb
= bpy
.path
.abspath(self
.filepath
)
197 # Execute main routine
198 import_pdb(self
.ball
,
201 self
.scale_ballradius
,
203 self
.scale_distances
,
205 self
.use_sticks_type
,
206 self
.sticks_subdiv_view
,
207 self
.sticks_subdiv_render
,
208 self
.use_sticks_color
,
209 self
.use_sticks_smooth
,
210 self
.use_sticks_bonds
,
211 self
.use_sticks_one_object
,
212 self
.use_sticks_one_object_nr
,
213 self
.sticks_unit_length
,
225 # This is the class for the file dialog of the exporter.
226 class EXPORT_OT_pdb(Operator
, ExportHelper
):
227 bl_idname
= "export_mesh.pdb"
228 bl_label
= "Export Protein Data Bank(*.pdb)"
229 filename_ext
= ".pdb"
231 filter_glob
: StringProperty(
232 default
="*.pdb", options
={'HIDDEN'},)
234 atom_pdb_export_type
: EnumProperty(
235 name
="Type of Objects",
236 description
="Choose type of objects",
237 items
=(('0', "All", "Export all active objects"),
238 ('1', "Elements", "Export only those active objects which have"
239 " a proper element name")),
242 # This thing here just guarantees that the menu entry is not active when the
243 # check box in the addon preferences is not activated! See __init__.py
245 def poll(cls
, context
):
246 pref
= context
.preferences
247 return pref
.addons
[__package__
].preferences
.bool_pdb
249 def draw(self
, context
):
252 row
.prop(self
, "atom_pdb_export_type")
254 def execute(self
, context
):
255 export_pdb(self
.atom_pdb_export_type
,
256 bpy
.path
.abspath(self
.filepath
))