Merge branch 'master' into blender2.8
[blender-addons.git] / io_mesh_pdb / __init__.py
blob7ad7d39fb7f92489f9cd7b0ed2936a43ed7cb25e
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
21 # Authors : Clemens Barth (Blendphys@root-1.de), ...
23 # Homepage(Wiki) : http://development.root-1.de/Atomic_Blender.php
25 # Start of project : 2011-08-31 by Clemens Barth
26 # First publication in Blender : 2011-11-11
27 # Last modified : 2014-08-19
29 # Acknowledgements
30 # ================
31 # Blender: ideasman, meta_androcto, truman, kilon, CoDEmanX, dairin0d, PKHG,
32 # Valter, ...
33 # Other : Frank Palmino
37 bl_info = {
38 "name": "Atomic Blender - PDB",
39 "description": "Loading and manipulating atoms from PDB files",
40 "author": "Clemens Barth",
41 "version": (1, 7),
42 "blender": (2, 71, 0),
43 "location": "File -> Import -> PDB (.pdb)",
44 "warning": "",
45 "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
46 "Scripts/Import-Export/PDB",
47 "category": "Import-Export",
51 import bpy
52 from bpy.types import Operator
53 from bpy_extras.io_utils import ImportHelper, ExportHelper
54 from bpy.props import (
55 StringProperty,
56 BoolProperty,
57 EnumProperty,
58 IntProperty,
59 FloatProperty,
62 from . import (
63 import_pdb,
64 export_pdb,
67 # -----------------------------------------------------------------------------
68 # GUI
70 # This is the class for the file dialog of the importer.
71 class ImportPDB(Operator, ImportHelper):
72 bl_idname = "import_mesh.pdb"
73 bl_label = "Import Protein Data Bank(*.pdb)"
74 bl_options = {'PRESET', 'UNDO'}
76 filename_ext = ".pdb"
77 filter_glob = StringProperty(default="*.pdb", options={'HIDDEN'},)
79 use_center = BoolProperty(
80 name = "Object to origin", default=True,
81 description = "Put the object into the global origin")
82 use_camera = BoolProperty(
83 name="Camera", default=False,
84 description="Do you need a camera?")
85 use_light = BoolProperty(
86 name="Lamp", default=False,
87 description = "Do you need a lamp?")
88 ball = EnumProperty(
89 name="Type of ball",
90 description="Choose ball",
91 items=(('0', "NURBS", "NURBS balls"),
92 ('1', "Mesh" , "Mesh balls"),
93 ('2', "Meta" , "Metaballs")),
94 default='0',)
95 mesh_azimuth = IntProperty(
96 name = "Azimuth", default=32, min=1,
97 description = "Number of sectors (azimuth)")
98 mesh_zenith = IntProperty(
99 name = "Zenith", default=32, min=1,
100 description = "Number of sectors (zenith)")
101 scale_ballradius = FloatProperty(
102 name = "Balls", default=1.0, min=0.0001,
103 description = "Scale factor for all atom radii")
104 scale_distances = FloatProperty (
105 name = "Distances", default=1.0, min=0.0001,
106 description = "Scale factor for all distances")
107 atomradius = EnumProperty(
108 name="Type",
109 description="Choose type of atom radius",
110 items=(('0', "Pre-defined", "Use pre-defined radius"),
111 ('1', "Atomic", "Use atomic radius"),
112 ('2', "van der Waals", "Use van der Waals radius")),
113 default='0',)
114 use_sticks = BoolProperty(
115 name="Use sticks", default=True,
116 description="Do you want to display the sticks?")
117 use_sticks_type = EnumProperty(
118 name="Type",
119 description="Choose type of stick",
120 items=(('0', "Dupliverts", "Use dupliverts structures"),
121 ('1', "Skin", "Use skin and subdivision modifier"),
122 ('2', "Normal", "Use simple cylinders")),
123 default='0',)
124 sticks_subdiv_view = IntProperty(
125 name = "SubDivV", default=2, min=1,
126 description="Number of subdivisions (view)")
127 sticks_subdiv_render = IntProperty(
128 name = "SubDivR", default=2, min=1,
129 description="Number of subdivisions (render)")
130 sticks_sectors = IntProperty(
131 name = "Sector", default=20, min=1,
132 description="Number of sectors of a stick")
133 sticks_radius = FloatProperty(
134 name = "Radius", default=0.2, min=0.0001,
135 description ="Radius of a stick")
136 sticks_unit_length = FloatProperty(
137 name = "Unit", default=0.05, min=0.0001,
138 description = "Length of the unit of a stick in Angstrom")
139 use_sticks_color = BoolProperty(
140 name="Color", default=True,
141 description="The sticks appear in the color of the atoms")
142 use_sticks_smooth = BoolProperty(
143 name="Smooth", default=True,
144 description="The sticks are round (sectors are not visible)")
145 use_sticks_bonds = BoolProperty(
146 name="Bonds", default=False,
147 description="Show double and tripple bonds")
148 sticks_dist = FloatProperty(
149 name="", default = 1.1, min=1.0, max=3.0,
150 description="Distance between sticks measured in stick diameter")
151 use_sticks_one_object = BoolProperty(
152 name="One object", default=True,
153 description="All sticks are one object")
154 use_sticks_one_object_nr = IntProperty(
155 name = "No.", default=200, min=10,
156 description="Number of sticks to be grouped at once")
157 datafile = StringProperty(
158 name = "", description="Path to your custom data file",
159 maxlen = 256, default = "", subtype='FILE_PATH')
161 def draw(self, context):
162 layout = self.layout
163 row = layout.row()
164 row.prop(self, "use_camera")
165 row.prop(self, "use_light")
166 row = layout.row()
167 row.prop(self, "use_center")
168 # Balls
169 box = layout.box()
170 row = box.row()
171 row.label(text="Balls / atoms")
172 row = box.row()
173 col = row.column()
174 col.prop(self, "ball")
175 row = box.row()
176 row.active = (self.ball == "1")
177 col = row.column(align=True)
178 col.prop(self, "mesh_azimuth")
179 col.prop(self, "mesh_zenith")
180 row = box.row()
181 col = row.column()
182 col.label(text="Scaling factors")
183 col = row.column(align=True)
184 col.prop(self, "scale_ballradius")
185 col.prop(self, "scale_distances")
186 row = box.row()
187 row.prop(self, "atomradius")
188 # Sticks
189 box = layout.box()
190 row = box.row()
191 row.label(text="Sticks / bonds")
192 row = box.row()
193 row.prop(self, "use_sticks")
194 row = box.row()
195 row.active = self.use_sticks
196 row.prop(self, "use_sticks_type")
197 row = box.row()
198 row.active = self.use_sticks
199 col = row.column()
200 if self.use_sticks_type == '0' or self.use_sticks_type == '2':
201 col.prop(self, "sticks_sectors")
202 col.prop(self, "sticks_radius")
203 if self.use_sticks_type == '1':
204 row = box.row()
205 row.active = self.use_sticks
206 row.prop(self, "sticks_subdiv_view")
207 row.prop(self, "sticks_subdiv_render")
208 row = box.row()
209 row.active = self.use_sticks
210 if self.use_sticks_type == '0':
211 col.prop(self, "sticks_unit_length")
212 col = row.column(align=True)
213 if self.use_sticks_type == '0':
214 col.prop(self, "use_sticks_color")
215 col.prop(self, "use_sticks_smooth")
216 if self.use_sticks_type == '0' or self.use_sticks_type == '2':
217 col.prop(self, "use_sticks_bonds")
218 row = box.row()
219 if self.use_sticks_type == '0':
220 row.active = self.use_sticks and self.use_sticks_bonds
221 row.label(text="Distance")
222 row.prop(self, "sticks_dist")
223 if self.use_sticks_type == '2':
224 row.active = self.use_sticks
225 col = row.column()
226 col.prop(self, "use_sticks_one_object")
227 col = row.column()
228 col.active = self.use_sticks_one_object
229 col.prop(self, "use_sticks_one_object_nr")
232 def execute(self, context):
233 # This is in order to solve this strange 'relative path' thing.
234 filepath_pdb = bpy.path.abspath(self.filepath)
236 # Execute main routine
237 import_pdb.import_pdb(
238 self.ball,
239 self.mesh_azimuth,
240 self.mesh_zenith,
241 self.scale_ballradius,
242 self.atomradius,
243 self.scale_distances,
244 self.use_sticks,
245 self.use_sticks_type,
246 self.sticks_subdiv_view,
247 self.sticks_subdiv_render,
248 self.use_sticks_color,
249 self.use_sticks_smooth,
250 self.use_sticks_bonds,
251 self.use_sticks_one_object,
252 self.use_sticks_one_object_nr,
253 self.sticks_unit_length,
254 self.sticks_dist,
255 self.sticks_sectors,
256 self.sticks_radius,
257 self.use_center,
258 self.use_camera,
259 self.use_light,
260 filepath_pdb)
262 return {'FINISHED'}
265 # This is the class for the file dialog of the exporter.
266 class ExportPDB(Operator, ExportHelper):
267 bl_idname = "export_mesh.pdb"
268 bl_label = "Export Protein Data Bank(*.pdb)"
269 filename_ext = ".pdb"
271 filter_glob = StringProperty(
272 default="*.pdb", options={'HIDDEN'},)
274 atom_pdb_export_type = EnumProperty(
275 name="Type of Objects",
276 description="Choose type of objects",
277 items=(('0', "All", "Export all active objects"),
278 ('1', "Elements", "Export only those active objects which have"
279 " a proper element name")),
280 default='1',)
282 def draw(self, context):
283 layout = self.layout
284 row = layout.row()
285 row.prop(self, "atom_pdb_export_type")
287 def execute(self, context):
288 export_pdb.export_pdb(self.atom_pdb_export_type,
289 bpy.path.abspath(self.filepath))
291 return {'FINISHED'}
294 # The entry into the menu 'file -> import'
295 def menu_func_import(self, context):
296 self.layout.operator(ImportPDB.bl_idname, text="Protein Data Bank (.pdb)")
298 # The entry into the menu 'file -> export'
299 def menu_func_export(self, context):
300 self.layout.operator(ExportPDB.bl_idname, text="Protein Data Bank (.pdb)")
302 def register():
303 bpy.utils.register_module(__name__)
304 bpy.types.INFO_MT_file_import.append(menu_func_import)
305 bpy.types.INFO_MT_file_export.append(menu_func_export)
307 def unregister():
308 bpy.utils.unregister_module(__name__)
309 bpy.types.INFO_MT_file_import.remove(menu_func_import)
310 bpy.types.INFO_MT_file_export.remove(menu_func_export)
312 if __name__ == "__main__":
314 register()