Skip to content
Snippets Groups Projects
__init__.py 9.28 KiB
Newer Older
  • Learn to ignore specific revisions
  • Campbell Barton's avatar
    Campbell Barton committed
    # ##### BEGIN GPL LICENSE BLOCK #####
    #
    #  This program is free software; you can redistribute it and/or
    #  modify it under the terms of the GNU General Public License
    #  as published by the Free Software Foundation; either version 2
    #  of the License, or (at your option) any later version.
    #
    #  This program is distributed in the hope that it will be useful,
    #  but WITHOUT ANY WARRANTY; without even the implied warranty of
    #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    #  GNU General Public License for more details.
    #
    #  You should have received a copy of the GNU General Public License
    #  along with this program; if not, write to the Free Software Foundation,
    #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
    #
    # ##### END GPL LICENSE BLOCK #####
    
    
    Clemens Barth's avatar
     
    Clemens Barth committed
    #
    #
    #  Authors           : Clemens Barth (Blendphys@root-1.de), ...
    #
    #  Homepage(Wiki)    : http://development.root-1.de/Atomic_Blender.php
    #
    #  Start of project              : 2011-08-31 by Clemens Barth
    #  First publication in Blender  : 2011-11-11
    
    Clemens Barth's avatar
     
    Clemens Barth committed
    #
    
    #  Acknowledgements 
    #  ================
    #
    #  Blender: ideasman, meta_androcto, truman, kilon, CoDEmanX, dairin0d, PKHG, 
    #           Valter, ...
    #  Other: Frank Palmino
    
    Clemens Barth's avatar
     
    Clemens Barth committed
    #
    
    
    Campbell Barton's avatar
    Campbell Barton committed
    bl_info = {
    
    Campbell Barton's avatar
    Campbell Barton committed
        "description": "Loading and manipulating atoms from PDB files",
        "author": "Clemens Barth",
    
    Campbell Barton's avatar
    Campbell Barton committed
        "blender": (2,6),
    
        "location": "File -> Import -> PDB (.pdb)",
    
    Campbell Barton's avatar
    Campbell Barton committed
        "warning": "",
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/"
                    "Py/Scripts/Import-Export/PDB",
    
    Campbell Barton's avatar
    Campbell Barton committed
        "tracker_url": "http://projects.blender.org/tracker/"
    
                       "index.php?func=detail&aid=29226",
    
    Campbell Barton's avatar
    Campbell Barton committed
        "category": "Import-Export"
    }
    
    import bpy
    
    from bpy.types import Operator, Panel
    
    from bpy_extras.io_utils import ImportHelper, ExportHelper
    
    Campbell Barton's avatar
    Campbell Barton committed
    from bpy.props import (StringProperty,
                           BoolProperty,
                           EnumProperty,
                           IntProperty,
                           FloatProperty)
    
    from . import import_pdb
    
    Campbell Barton's avatar
    Campbell Barton committed
    # -----------------------------------------------------------------------------
    #                                                                           GUI
    
    
    Clemens Barth's avatar
     
    Clemens Barth committed
    # This is the class for the file dialog of the importer.
    
    class ImportPDB(Operator, ImportHelper):
    
        bl_idname = "import_mesh.pdb"
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        bl_label  = "Import Protein Data Bank(*.pdb)"
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        bl_options = {'PRESET', 'UNDO'}
    
    Campbell Barton's avatar
    Campbell Barton committed
        filename_ext = ".pdb"
        filter_glob  = StringProperty(default="*.pdb", options={'HIDDEN'},)
    
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        use_camera = BoolProperty(
            name="Camera", default=False,
            description="Do you need a camera?")
        use_lamp = BoolProperty(
            name="Lamp", default=False,
            description = "Do you need a lamp?")
        use_mesh = BoolProperty(
            name = "Mesh balls", default=False,
            description = "Use mesh balls instead of NURBS")
        mesh_azimuth = IntProperty(
            name = "Azimuth", default=32, min=1,
            description = "Number of sectors (azimuth)")
        mesh_zenith = IntProperty(
            name = "Zenith", default=32, min=1,
            description = "Number of sectors (zenith)")
        scale_ballradius = FloatProperty(
            name = "Balls", default=1.0, min=0.0001,
            description = "Scale factor for all atom radii")
        scale_distances = FloatProperty (
            name = "Distances", default=1.0, min=0.0001,
            description = "Scale factor for all distances")
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        atomradius = EnumProperty(
            name="Type of radius",
            description="Choose type of atom radius",
            items=(('0', "Pre-defined", "Use pre-defined radius"),
                   ('1', "Atomic", "Use atomic radius"),
                   ('2', "van der Waals", "Use van der Waals radius")),
                   default='0',)        
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        use_sticks = BoolProperty(
            name="Use sticks", default=True,
            description="Do you want to display the sticks?")
        sticks_sectors = IntProperty(
            name = "Sector", default=20, min=1,
            description="Number of sectors of a stick")
        sticks_radius = FloatProperty(
            name = "Radius", default=0.1, min=0.0001,
            description ="Radius of a stick")
        sticks_unit_length = FloatProperty(
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            name = "Unit", default=0.05, min=0.0001,
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            description = "Length of the unit of a stick in Angstrom")        
        use_sticks_color = BoolProperty(
            name="Color", default=True,
            description="The sticks appear in the color of the atoms")
        use_sticks_smooth = BoolProperty(
            name="Smooth", default=False,
            description="The sticks are round (sectors are not visible)")     
        use_sticks_bonds = BoolProperty(
            name="Bonds", default=False,
            description="Show double and tripple bonds.")
        sticks_dist = FloatProperty(
            name="Distance", default = 1.1, min=1.0, max=3.0,
            description="Distance between sticks measured in stick diameter")        
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        use_center = BoolProperty(
            name = "Object to origin", default=True,
            description = "Put the object into the global origin")           
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        datafile = StringProperty(
            name = "", description="Path to your custom data file",
            maxlen = 256, default = "", subtype='FILE_PATH')
    
    
    Campbell Barton's avatar
    Campbell Barton committed
        def draw(self, context):
    
            layout = self.layout
    
    Campbell Barton's avatar
    Campbell Barton committed
            row = layout.row()
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row.prop(self, "use_camera")
            row.prop(self, "use_lamp")
    
            row = layout.row()
            col = row.column()
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col.prop(self, "use_mesh")
    
            col = row.column(align=True)
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col.active = self.use_mesh
            col.prop(self, "mesh_azimuth")
            col.prop(self, "mesh_zenith")
    
            row = layout.row()
            col = row.column()
    
    Campbell Barton's avatar
    Campbell Barton committed
            col.label(text="Scaling factors")
            col = row.column(align=True)
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col.prop(self, "scale_ballradius")
            col.prop(self, "scale_distances")
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row.prop(self, "atomradius")
            row = layout.row()
    
    Campbell Barton's avatar
    Campbell Barton committed
            col = row.column()
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col.prop(self, "use_sticks")
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row = layout.row()        
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row.active = self.use_sticks
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col = row.column()
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col.prop(self, "sticks_sectors")
            col.prop(self, "sticks_radius")
            col.prop(self, "sticks_unit_length")
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col = row.column(align=True)        
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col.prop(self, "use_sticks_color")        
            col.prop(self, "use_sticks_smooth")
            col.prop(self, "use_sticks_bonds")
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row = layout.row()        
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row.active = self.use_sticks
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col = row.column(align=True)
            col = row.column(align=True)
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            col.active = self.use_sticks and self.use_sticks_bonds 
            col.prop(self, "sticks_dist")
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row.prop(self, "use_center")
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
        def execute(self, context):
    
    Campbell Barton's avatar
    Campbell Barton committed
            # This is in order to solve this strange 'relative path' thing.
    
            filepath_pdb = bpy.path.abspath(self.filepath)
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            # Execute main routine                
    
            atom_number = import_pdb.import_pdb(
    
    Clemens Barth's avatar
     
    Clemens Barth committed
                          self.use_mesh,
                          self.mesh_azimuth,
                          self.mesh_zenith,
                          self.scale_ballradius,
                          self.atomradius,
                          self.scale_distances,
                          self.use_sticks,
                          self.use_sticks_color,
                          self.use_sticks_smooth,
                          self.use_sticks_bonds,
                          self.sticks_unit_length,
                          self.sticks_dist,
                          self.sticks_sectors,
                          self.sticks_radius,
                          self.use_center,
                          self.use_camera,
                          self.use_lamp,
    
    Campbell Barton's avatar
    Campbell Barton committed
    
            return {'FINISHED'}
    
    
    
    Clemens Barth's avatar
     
    Clemens Barth committed
    # This is the class for the file dialog of the exporter.
    
    class ExportPDB(Operator, ExportHelper):
    
        bl_idname = "export_mesh.pdb"
        bl_label  = "Export Protein Data Bank(*.pdb)"
        filename_ext = ".pdb"
    
    Clemens Barth's avatar
     
    Clemens Barth committed
    
        filter_glob  = StringProperty(
            default="*.pdb", options={'HIDDEN'},)
    
        atom_pdb_export_type = EnumProperty(
            name="Type of Objects",
            description="Choose type of objects",
            items=(('0', "All", "Export all active objects"),
    
    Clemens Barth's avatar
     
    Clemens Barth committed
                   ('1', "Elements", "Export only those active objects which have"
                                     " a proper element name")),
    
    Clemens Barth's avatar
     
    Clemens Barth committed
                   default='1',) 
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row = layout.row()
    
    Clemens Barth's avatar
     
    Clemens Barth committed
            row.prop(self, "atom_pdb_export_type")
    
    Clemens Barth's avatar
     
    Clemens Barth committed
    
    
            export_pdb.export_pdb(self.atom_pdb_export_type,
                                  bpy.path.abspath(self.filepath))
    
    Campbell Barton's avatar
    Campbell Barton committed
    # The entry into the menu 'file -> import'
    
    def menu_func_import(self, context):
        self.layout.operator(ImportPDB.bl_idname, text="Protein Data Bank (.pdb)")
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    
    # The entry into the menu 'file -> export'
    
    def menu_func_export(self, context):
        self.layout.operator(ExportPDB.bl_idname, text="Protein Data Bank (.pdb)")
    
    Campbell Barton's avatar
    Campbell Barton committed
    
    def register():
        bpy.utils.register_module(__name__)
    
        bpy.types.INFO_MT_file_import.append(menu_func_import)
        bpy.types.INFO_MT_file_export.append(menu_func_export)
    
    Clemens Barth's avatar
     
    Clemens Barth committed
        
    
    Campbell Barton's avatar
    Campbell Barton committed
    def unregister():
    
        bpy.utils.unregister_module(__name__)
    
        bpy.types.INFO_MT_file_import.remove(menu_func_import)
        bpy.types.INFO_MT_file_export.remove(menu_func_export)
    
    Campbell Barton's avatar
    Campbell Barton committed
    if __name__ == "__main__":
    
    Campbell Barton's avatar
    Campbell Barton committed
        register()