[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2627] contrib/py/scripts/addons/ io_import_pdb_atomic_blender.py:

Clemens Barth barth at root-1.de
Fri Nov 18 22:51:08 CET 2011


Revision: 2627
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2627
Author:   blendphys
Date:     2011-11-18 21:51:08 +0000 (Fri, 18 Nov 2011)
Log Message:
-----------


Dear all.

This is the second major change of the script, but probably the
last one from my side so far. I'm sorry but I had lots of fun
and many ideas during the last days.
In future I will perform only small changes from time to time.
Promised.

To my opinion the script is ready to go. It is a stable version
with lots of nice features. It is completely sufficient to load 
atoms and sticks from PDB files and to modify the atoms afterwards.

Note that the major functionalities and the structure of the script 
have not been changed. Please, read the comments at the end of 
this text!


Changes
=======

1. The file operators have been removed in the panel and an
entry in the menu 'File -> Import' is created after the call
of the script. Its name is 'PDB (.pdb)' what I have adapted 
to what one can see in the Import sub-menu. 

2. The data file: Well, I organized the script such that 
the data file is automatically loaded. The condition is that the
data file is in the same directory as the python script.
Remember that the data file is important: It includes all colors 
and radii of the atoms, which are not included in PDB files.
So far, you need to manually load the script into Blender. Depending
on some decisions (see below) this can be easily changed.
TNa changes in data file.

3. I considered also this 'last active object' issue, Campbell is 
mentioning on the page here: 
http://codereview.appspot.com/5369091/diff/1//dsk/data/src/blender/blender/release/scripts/addons/io_pdb_atomic.py
I changed all and hope that it is fine now.

4. I re-arranged a bit the buttons, in- and outputs. All buttons,
inputs and outputs have now an identifier in Python, which contains 
the string 'atom_pdb'. In future, other scripts refer to all this. 

5. I added some buttons for the scaling of the atom radii. The
meaning is somewhat self-explanatory.

6. I added also some comments in the code. To my opinion it is useful 
for others for understanding the script, but also for newcomers who 
want to understand the meaning of some specific Blender commands.

7. I modified also the camera code. Euler math is quite nice and
finally I could do some mathematics. ... The camera is now in
a better orientation.

8. I removed some bugs and optimized the code.


Comments
========

1. I don't know if I meet the standards of Blender although I have 
given my very best. If there is something not convenient then help 
me, please. Thanks. 

2. To my opinion, all buttons and inputs/outputs in the panel are 
useful for well preparing the objects. It would be nice if they could
stay. I do use them when I charge molecules or crystal structures.
Note that I plan a second, bigger project where I need all this stuff.

3. There needs to be a decision done: In which tab shall the panel 
go? Physics? In fact, a separate tab only for this script would be quite perfect. 
Is this possible? - I couldn't find any code, examples, etc ... .

4. A second decision needs to be done, too: Where shall the script go?
Does it become a part of Blender or is it an add-on or is it simply a 
python script?
Depending on all this, some changes need to be done in the script: If it
is in some directories like .blender/scripts/startup one needs to
change the way for determing the data file. <= Tell me and I change the 
code, it's easy.

5. Which version shall the script obtain? It has 1.1 now, which
is my old way of counting. Normally, it would get version 2.0 because of 
all the major changes I have done. What do you think?

6. Shall we rename the file name (only io_import_pdb.py)? Well, the name 
'PDB - Atomic Blender' can stay in the Panel, if you agree (would be nice). 
In some time there will be 'PDB - Atomic Blender Movie'. ;-)

7. Last thing: Somebody asked me if one could also read files from
some quantum chemical simulation programs like VASP (http://cms.mpi.univie.ac.at/vasp/),
SIESTA (http://www.icmab.es/siesta-joomla/) etc. I can deal with this, too, 
but I need some time for this. Is there some demand from your side, 
do you have an interest?

8. If you have any other fancy ideas or changes to do, feel free to
modify the script!


So far ... I have no clue what follows now. So what is coming next? 
What are your comments? 


All the best and cheers,

Blendphys.




     

Modified Paths:
--------------
    contrib/py/scripts/addons/io_import_pdb_atomic_blender.py

Modified: contrib/py/scripts/addons/io_import_pdb_atomic_blender.py
===================================================================
--- contrib/py/scripts/addons/io_import_pdb_atomic_blender.py	2011-11-18 21:20:11 UTC (rev 2626)
+++ contrib/py/scripts/addons/io_import_pdb_atomic_blender.py	2011-11-18 21:51:08 UTC (rev 2627)
@@ -1,3 +1,15 @@
+#
+#
+#  Authors           : Clemens Barth (Blendphys at root-1.de), ...
+#
+#  Homepage(Wiki)    : http://development.root-1.de/Atomic_Blender.php
+#  Tracker           : http://projects.blender.org/tracker/index.php?func=detail&aid=29226&group_id=153&atid=467
+#
+#  Start of project              : 2011-08-31 by Clemens Barth
+#  First publication in Blender  : 2011-11-11
+#  Last modified                 : 2011-11-18
+#
+#
 # ##### BEGIN GPL LICENSE BLOCK #####
 #
 #  This program is free software; you can redistribute it and/or
@@ -10,13 +22,17 @@
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #  GNU General Public License for more details.
 #
-#  The main author of the script is Dr. Clemens Barth.
-#
 #  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 #####
+#
+#
+#
+#
+#
+#
 
 bl_info = {
   "name": "Atomic Blender",
@@ -39,238 +55,388 @@
 from math import *
 import mathutils, math
 from mathutils import Vector
+
+
+# These are variables, which contain the name of the PDB file,
+# the path of the PDB file and, finally, the path to the DATAFILEPATH.
+# They are used almost everywhere, which is the reason why they 
+# should stay global. First, they are empty and get 'filled' directly
+# after having chosen the PDB file (see discussion at 'class LoadPDB'
+# further below).
 #
-PDBFILE   = "PATH TO PDB FILE"
-DATAFILE  = "PATH TO DATA FILE"
+# Note that the treatment of the data filepath needs to be adjusted for 
+# the case that the script shall be called during startup (see discussion 
+# in the class LoadPDB further below).
 
-Atomic_Blender_string     = "Atomic Blender 1.1 -- Dr. Clemens Barth -- November 2011\n========================================================"
+PDBFILEPATH       = ""
+PDBFILENAME       = ""
+DATAFILEPATH      = ""
+
+# The name of this script and the data file. This is used in the class 
+# LoadPDB, for determining the path of the data file. For further details 
+# see below.
+SCRIPTNAME   = "io_import_pdb_atomic_blender.py"
+DATAFILENAME = "io_import_pdb_atomic_blender.dat"
+
+
+# Some string stuff for the console.
+Atomic_Blender_string     = "Atomic Blender 1.11\n==================="
 Atomic_Blender_panel_name = "PDB - Atomic Blender"
 
 
-class OBJECT_PDB_Panel(bpy.types.Panel):
+
+
+
+# The panel, which is loaded after the file has been
+# chosen via the menu 'File -> Import'
+class CLASS_PDB_Panel(bpy.types.Panel):
     bl_label       = Atomic_Blender_panel_name
     bl_space_type  = "PROPERTIES"
     bl_region_type = "WINDOW"
     bl_context     = "physics"
+    # This could be also an option ... :
+    #bl_space_type  = "VIEW_3D"
+    #bl_region_type = "TOOL_PROPS"
 
+    # This 'poll thing' has taken 3 hours of a hard search and understanding.
+    # I explain it in the following from my point of view:
+    #
+    # Before this class is entirely treaten (here: drawing the panel) the
+    # poll method is called first. Basically, some conditions are 
+    # checked before other things in the class are done afterwards. If a 
+    # condition is not valid, one returns 'False' such that nothing further 
+    # is done. 'True' means: 'Go on'
+    #
+    # In the case here, it is verified if the PDBFILEPATH variable contains
+    # a name. If not - and this is the case directly after having started the
+    # script - the panel does not appear because 'False' is returned. However,
+    # as soon as a file has been chosen, the panel appears because PDBFILEPATH
+    # contains a name.
+    #
+    # Please, correct me if I'm wrong. 
+    @classmethod
+    def poll(self, context):
+        if PDBFILEPATH == "":
+            return False
+        else:
+            return True
+
     def draw(self, context):
         layout = self.layout
         scn    = bpy.context.scene
 
         row = layout.row()
-        layout.prop(scn, "pdb_filepath")
-        layout.prop(scn, "data_filepath")
+        col = row.column(align=True)
+        col.prop(scn, "atom_pdb_PDB_filename") 
+        col.prop(scn, "atom_pdb_PDB_file")
         row = layout.row()
+        row = layout.row() 
+  
+        row.prop(scn, "atom_pdb_group_atoms_yesno")
+        row.prop(scn, "atom_pdb_group_atoms_dn")
 
-
         row = layout.row()
-        row.prop(scn, "entry_group_atoms_yesno")
-        row.prop(scn, "entry_group_atoms_dn")
-
-        row = layout.row()
         col = row.column(align=True)        
-        col.prop(scn, "entry_mesh_yesno")
-        col.prop(scn, "entry_sectors_azimuth")
-        col.prop(scn, "entry_sectors_zenith")        
+        col.prop(scn, "atom_pdb_mesh_yesno")
+        col.prop(scn, "atom_pdb_mesh_azimuth")
+        col.prop(scn, "atom_pdb_mesh_zenith")        
         col = row.column(align=True)        
         col.label(text="Scaling factors")
-        col.prop(scn, "entry_ball_radius")
-        col.prop(scn, "entry_distances")
+        col.prop(scn, "atom_pdb_scale_ballradius")
+        col.prop(scn, "atom_pdb_scale_distances")
         col = row.column(align=True) 
-        col.prop(scn, "entry_sticks_yesno")
-        col.prop(scn, "entry_sticks_sectors")
-        col.prop(scn, "entry_sticks_radius")
+        col.prop(scn, "atom_pdb_sticks_yesno")
+        col.prop(scn, "atom_pdb_sticks_sectors")
+        col.prop(scn, "atom_pdb_sticks_radius")
 
         row = layout.row()        
         col = row.column(align=True)  
-        col.prop(scn, "entry_scene_x")
-        col.prop(scn, "entry_scene_y")
-        col.prop(scn, "entry_scene_z")
+        col.prop(scn, "atom_pdb_offset_x")
+        col.prop(scn, "atom_pdb_offset_y")
+        col.prop(scn, "atom_pdb_offset_z")
         col = row.column()         
-        col.prop(scn, "entry_center_yesno")
+        col.prop(scn, "atom_pdb_center_yesno")
 
+        layout.separator()  
         row = layout.row(align=True)        
         col = row.column()
-        col.prop(scn, "entry_cam_yesno")
-        col.prop(scn, "entry_lamp_yesno")        
+        col.prop(scn, "atom_pdb_cam_yesno")
+        col.prop(scn, "atom_pdb_lamp_yesno")        
         col = row.column() 
-        col.operator( "fp.button_start" )
+        col.operator( "atom_pdb.button_start" )
         row2 = col.row()
         row2.label(text="Number of atoms")
-        row2.prop(scn, "entry_start_number_atoms")
+        row2.prop(scn, "atom_pdb_start_number_atoms")
+        layout.separator()
+              
+        if scn.atom_pdb_group_atoms_yesno == False:        
 
-        
-        
-        if scn.entry_group_atoms_yesno == False:        
-
             row = layout.row()             
-            row.operator( "fp.button_distance")
-            row.prop(scn, "entry_distance") 
+            row.operator( "atom_pdb.button_distance")
+            row.prop(scn, "atom_pdb_distance") 
+            layout.separator()
             
             row = layout.row()                   
-            row.label(text="Modification of the radii of one type of atom")
-            row = layout.row()
-            col = row.column()            
-            col.prop(scn, "entry_mod_pm_yesno")
-            col.prop(scn, "entry_mod_pm_radius")
-            col = row.column()  
-            col.prop(scn, "entry_mod_rel_yesno")
-            col.prop(scn, "entry_mod_rel_radius")
-            col = row.column()
-            col.prop(scn, "entry_mod_atomname")
-            col.operator( "fp.button_modify" )            
-
+            row.label(text="Modification of the radii of one type of atom")            
+            
+            row = layout.row()     
+            split = row.split(percentage=0.40)
+            col = split.column()
+            col.prop(scn, "atom_pdb_mod_atomname") 
+            split = split.split(percentage=0.50)
+            col = split.column()
+            col.prop(scn, "atom_pdb_mod_pm_radius")
+            split = split.split(percentage=1.0)
+            col = split.column()
+            col.operator("atom_pdb.button_modify_single")
+            
+            row = layout.row()     
+            split = row.split(percentage=0.40)
+            col = split.column()
+            split = split.split(percentage=0.50)
+            col = split.column()
+            col.prop(scn, "atom_pdb_mod_rel_radius")
+            split = split.split(percentage=1.0)
+            col = split.column(align=True)
+            col.operator( "atom_pdb.button_bigger_single" )            
+            col.operator( "atom_pdb.button_smaller_single" ) 
+                                             
             row = layout.row()            
             row.label(text="Modification of all atom radii")
             row = layout.row()
-            row.prop(scn, "entry_mod_all_radii")
-            row.operator( "fp.button_modify_2" )
-            row = layout.row()
-            row.prop(scn, "entry_mod_all_radii_inv")
-            row.operator( "fp.button_modify_3" )
+            col = row.column() 
+            col.prop(scn, "atom_pdb_mod_all_radii")
+            col = row.column(align=True) 
+            col.operator( "atom_pdb.button_modify_all" )
+            col.operator( "atom_pdb.button_invert_all" )
 
 
-class Input_Output(bpy.types.PropertyGroup):
-    bpy.types.Scene.pdb_filepath              = bpy.props.StringProperty(name = "PDB  File", description="Path to the PDB file", maxlen = 256, default = PDBFILE, subtype='FILE_PATH', options={'HIDDEN'})
-    bpy.types.Scene.data_filepath             = bpy.props.StringProperty(name = "DATA File", description="Path to the dat file", maxlen = 256, default = DATAFILE, subtype='FILE_PATH')
-    bpy.types.Scene.entry_group_atoms_yesno   = bpy.props.BoolProperty  (name = "Group atoms", default=False, description = "Grouping same type of atoms speeds up the loading of large-atom-PDB files")    
-    bpy.types.Scene.entry_group_atoms_dn      = bpy.props.IntProperty   (name = "Delta N", default=200, min=0, description = "")

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list