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

Campbell Barton ideasman42 at gmail.com
Mon Nov 21 06:38:41 CET 2011


Hi, while moving the datafile inside the script is OK, you could have
done it 2 other ways.

- You were going about getting the path in a much more complicated way
then was needed.
  use __file__, eg.

  datapath =os.path.join(os.path.dirname(__file__), "mydataname.dat")

- Another way which makes most sense now since you already have the
data formatted as python is to import it from a python script which
only contains the data, this will be faster and simpler then parsing
from a script too.

# relative import of mydatascript.py
from .mydatascript import Data_all_atoms


If something like this seems more complicated then it should be feel
free to ask in bf-python mailing list

On Sun, Nov 20, 2011 at 10:50 PM, Clemens Barth <barth at root-1.de> wrote:
> Revision: 2635
>          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2635
> Author:   blendphys
> Date:     2011-11-20 11:50:31 +0000 (Sun, 20 Nov 2011)
> Log Message:
> -----------
>
>
> During the last days I got quite crazy because of the data file
> and its absolute file path in Blender. It is very difficult to
> determine the absolute path of the data file for any kind of
> operating system and any place of the file on the hard disk.
>
> This is why I have decided to put the whole atom data into
> the python script. With this, we have only one file which is
> the python script itself. No data file anymore. The script works
> well under Linux and Windows.
>
> However, next week I will include an operator (button), with
> which one can load a custom atom data file. I find this quite
> important. Why? Because the user would like to have the possibility
> to load its own color scales, atom radii, etc. ...
>
> 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-20 00:55:01 UTC (rev 2634)
> +++ contrib/py/scripts/addons/io_import_pdb_atomic_blender.py   2011-11-20 11:50:31 UTC (rev 2635)
> @@ -41,7 +41,7 @@
>   "version": (2,0),
>   "blender": (2,6),
>   "api": 31236,
> -  "location": "File > Import => PDB (.pdb)",
> +  "location": "File -> Import -> PDB (.pdb)",
>   "warning": "",
>   "wiki_url": "http://development.root-1.de/Atomic_Blender.php",
>   "tracker_url": "http://projects.blender.org/tracker/?func=detail&atid=467&aid=29226&group_id=153",
> @@ -52,13 +52,14 @@
>  import io
>  import sys
>  import os
> +import inspect
>  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.
> +# These are variables, which contain the name of the PDB file and
> +# the path of the PDB file.
>  # 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'
> @@ -66,71 +67,134 @@
>
>  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 2.0\n==================="
>  Atomic_Blender_panel_name = "PDB - Atomic Blender"
>
> +# Before I had a data file, which included all the following atom data. Well, in fact I prefer
> +# separate files, especially data files.
> +# However, since it was almost impossible to find a mean for determing the path of the data
> +# file for any kind of situation, I finally decided to include all the atom data into the Python
> +# script. The script is now absolutely independent on a second file, and we solved many problems
> +# that come along with the world of file paths under different operating systems.
>
> -
> -# This routine is used to determine the path of the data file. The data file
> -# needs to be in
> -#                    /script
> -#                    /script/addons
> -#                    /script/startup
> -#
> -# either in USER: or SYSTEM:
> +# This is a list that contains some data of all possible atoms. The structure is as follows:
>  #
> -# So, check all these possibilities and return the path of the data file.
> -# The empty return string "" means that no data file could be found. Note that:
> +# 1, "Hydrogen", "H", [0.0,0.0,1.0], 0.32, 0.32, 0.32 , -1 , 1.54   means
>  #
> -# bpy.utils.script_paths()[0]        => system script path
> -# bpy.utils.user_resource('SCRIPTS') => user   script path
> +# Number, name of atom, short name, color, radius (used for Blender), radius (covalent), radius (atomic), ...
>  #
> -def Determine_path_of_data_file():
> +# ... then the charge state: charge state, radius (ionic), charge state, radius (ionic), ... all charge states
> +# for any atom are listed, if existing.
> +
> +Data_all_atoms = [
> +[ 1, "Hydrogen", "H", [0.0,0.0,1.0], 0.32, 0.32, 0.32 , -1 , 1.54 ],
> +[ 2, "Helium", "He", [0.20,0.56,0.20], 0.93, 0.93, 0.93 , 1 , 0.68 ],
> +[ 3, "Beryllium", "Be", [0.44,0.72,0.30], 0.90, 0.90, 0.90 , 1 , 0.44 , 2 , 0.35 ],
> +[ 4, "Boron", "B", [1.0,1.0,1.0], 0.82, 0.82, 0.82 , 1 , 0.35 , 3 , 0.23 ],
> +[ 5, "Carbon", "C", [0.0,0.0,0.0], 0.77, 0.77, 0.77 , -4 , 2.60 , 4 , 0.16 ],
> +[ 6, "Nitrogen", "N", [0.0,0.0,1.0], 0.75, 0.75, 0.75 , -3 , 1.71 , 1 , 0.25 , 3 , 0.16 , 5 , 0.13 ],
> +[ 7, "Oxygen", "O", [1.0,0.0,0.0], 0.73, 0.73, 0.73 , -2 , 1.32 , -1 , 1.76 , 1 , 0.22 , 6 , 0.09 ],
> +[ 8, "Fluorine", "F", [0.0,1.0,0.0], 0.72, 0.72, 0.72 , -1 , 1.33 , 7 , 0.08 ],
> +[ 9, "Neon", "Ne", [0.53,0.60,0.52], 0.71, 0.71, 0.71 , 1 , 1.12 ],
> +[ 10, "Sodium", "Na", [0.0,0.0,1.0], 1.54, 1.54, 1.54 , 1 , 0.97 ],
> +[ 11, "Magnesium", "Mg", [1.0,1.0,1.0], 1.36, 1.36, 1.36 , 1 , 0.82 , 2 , 0.66 ],
> +[ 12, "Aluminium", "Al", [0.70,0.2,0.62], 1.18, 1.18, 1.18 , 3 , 0.51 ],
> +[ 13, "Silicon", "Si", [0.65,0.64,0.27], 1.11, 1.11, 1.11 , -4 , 2.71 , -1 , 3.84 , 1 , 0.65 , 4 , 0.42 ],
> +[ 14, "Phosphorus", "P", [1.0,1.0,0.0], 1.06, 1.06, 1.06 , -3 , 2.12 , 3 , 0.44 , 5 , 0.35 ],
> +[ 15, "Sulfur", "S", [1.0,1.0,0.50], 1.02, 1.02, 1.02 , -2 , 1.84 , 2 , 2.19 , 4 , 0.37 , 6 , 0.30 ],
> +[ 16, "Chlorine", "Cl", [0.0,1.0,0.0], 0.99, 0.99, 0.99 , -1 , 1.81 , 5 , 0.34 , 7 , 0.27 ],
> +[ 17, "Argon", "Ar", [0.31,0.32,0.74], 0.98, 0.98, 0.98 , 1 , 1.54 ],
> +[ 18, "Potassium", "K", [0.81,0.23,0.42], 2.03, 2.03, 2.03 , 1 , 0.81 ],
> +[ 19, "Calcium", "Ca", [1.0,1.0,1.0], 1.74, 1.74, 1.74 , 1 , 1.18 , 2 , 0.99 ],
> +[ 20, "Scandium", "Sc", [0.66,0.44,0.31], 1.44, 1.44, 1.44 , 3 , 0.73 ],
> +[ 21, "Titanium", "Ti", [0.27,0.53,0.68], 1.32, 1.32, 1.32 , 1 , 0.96 , 2 , 0.94 , 3 , 0.76 , 4 , 0.68 ],
> +[ 22, "Vanadium", "V", [0.27,0.24,0.63], 1.22, 1.22, 1.22 , 2 , 0.88 , 3 , 0.74 , 4 , 0.63 , 5 , 0.59 ],
> +[ 23, "Chromium", "Cr", [0.80,0.28,0.81], 1.18, 1.18, 1.18 , 1 , 0.81 , 2 , 0.89 , 3 , 0.63 , 6 , 0.52 ],
> +[ 24, "Manganese", "Mn", [0.75,0.35,0.55], 1.17, 1.17, 1.17 , 2 , 0.80 , 3 , 0.66 , 4 , 0.60 , 7 , 0.46 ],
> +[ 25, "Iron", "Fe", [1.0,0.0,0.0], 1.17, 1.17, 1.17 , 2 , 0.74 , 3 , 0.64 ],
> +[ 26, "Cobalt", "Co", [0.27,0.21,0.75], 1.16, 1.16, 1.16 , 2 , 0.72 , 3 , 0.63 ],
> +[ 27, "Nickel", "Ni", [0.43,0.36,0.86], 1.15, 1.15, 1.15 , 2 , 0.69 ],
> +[ 28, "Copper", "Cu", [0.60,0.0,0.0], 1.17, 1.17, 1.17 , 1 , 0.96 , 2 , 0.72 ],
> +[ 29, "Zinc", "Zn", [0.42,0.36,0.45], 1.25, 1.25, 1.25 , 1 , 0.88 , 2 , 0.74 ],
> +[ 30, "Gallium", "Ga", [0.63,0.72,0.33], 1.26, 1.26, 1.26 , 1 , 0.81 , 3 , 0.62 ],
> +[ 31, "Germanium", "Ge", [0.42,0.75,0.30], 1.22, 1.22, 1.22 , -4 , 2.72 , 2 , 0.73 , 4 , 0.53 ],
> +[ 32, "Arsenic", "As", [0.39,0.77,0.25], 1.20, 1.20, 1.20 , -3 , 2.22 , 3 , 0.58 , 5 , 0.46 ],
> +[ 33, "Selenium", "Se", [0.95,0.27,0.90], 1.16, 1.16, 1.16 , -2 , 1.91 , -1 , 2.32 , 1 , 0.66 , 4 , 0.50 , 6 , 0.42 ],
> +[ 34, "Bromine", "Br", [0.0,0.49,0.0], 1.14, 1.14, 1.14 , -1 , 1.96 , 5 , 0.47 , 7 , 0.39 ],
> +[ 35, "Krypton", "Kr", [0.22,0.43,0.19], 1.31, 1.31, 1.31 , 1 , 1.47 ],
> +[ 36, "Strontium", "Sr", [1.0,1.0,1.0], 1.91, 1.91, 1.91 , 2 , 1.12 ],
> +[ 37, "Yttrium", "Y", [1.0,1.0,1.0], 1.62, 1.62, 1.62 , 3 , 0.89 ],
> +[ 38, "Zirconium", "Zr", [1.0,1.0,1.0], 1.45, 1.45, 1.45 , 1 , 1.09 , 4 , 0.79 ],
> +[ 39, "Niobium", "Nb", [1.0,1.0,1.0], 1.34, 1.34, 1.34 , 1 , 1.00 , 4 , 0.74 , 5 , 0.69 ],
> +[ 40, "Molybdenum", "Mo", [1.0,1.0,1.0], 1.30, 1.30, 1.30 , 1 , 0.93 , 4 , 0.70 , 6 , 0.62 ],
> +[ 41, "Technetium", "Tc", [1.0,1.0,1.0], 1.27, 1.27, 1.27 , 7 , 0.97 ],
> +[ 42, "Ruthenium", "Ru", [1.0,1.0,1.0], 1.25, 1.25, 1.25 , 4 , 0.67 ],
> +[ 43, "Rhodium", "Rh", [1.0,1.0,1.0], 1.25, 1.25, 1.25 , 3 , 0.68 ],
> +[ 44, "Palladium", "Pd", [1.0,1.0,1.0], 1.28, 1.28, 1.28 , 2 , 0.80 , 4 , 0.65 ],
> +[ 45, "Silver", "Ag", [1.0,1.0,1.0], 1.34, 1.34, 1.34 , 1 , 1.26 , 2 , 0.89 ],
> +[ 46, "Cadmium", "Cd", [1.0,1.0,1.0], 1.48, 1.48, 1.48 , 1 , 1.14 , 2 , 0.97 ],
> +[ 47, "Indium", "In", [1.0,1.0,1.0], 1.44, 1.44, 1.44 , 3 , 0.81 ],
> +[ 48, "Tin", "Sn", [1.0,1.0,1.0], 1.41, 1.41, 1.41 , -4 , 2.94 , -1 , 3.70 , 2 , 0.93 , 4 , 0.71 ],
> +[ 49, "Antimony", "Sb", [1.0,1.0,1.0], 1.40, 1.40, 1.40 , -3 , 2.45 , 3 , 0.76 , 5 , 0.62 ],
> +[ 50, "Tellurium", "Te", [1.0,1.0,1.0], 1.36, 1.36, 1.36 , -2 , 2.11 , -1 , 2.50 , 1 , 0.82 , 4 , 0.70 , 6 , 0.56 ],
> +[ 51, "Iodine", "I", [0.0,0.49,0.49], 1.33, 1.33, 1.33 , -1 , 2.20 , 5 , 0.62 , 7 , 0.50 ],
> +[ 52, "Xenon", "Xe", [1.0,1.0,1.0], 1.31, 1.31, 1.31 , 1 , 1.67 ],
> +[ 53, "Barium", "Ba", [1.0,1.0,1.0], 1.98, 1.98, 1.98 , 1 , 1.53 , 2 , 1.34 ],
> +[ 54, "Lanthanum", "La", [1.0,1.0,1.0], 1.69, 1.69, 1.69 , 1 , 1.39 , 3 , 1.06 ],
> +[ 55, "Cerium", "Ce", [1.0,1.0,1.0], 1.65, 1.65, 1.65 , 1 , 1.27 , 3 , 1.03 , 4 , 0.92 ],
> +[ 56, "Praseodymium", "Pr", [1.0,1.0,1.0], 1.65, 1.65, 1.65 , 3 , 1.01 , 4 , 0.90 ],
> +[ 57, "Neodymium", "Nd", [1.0,1.0,1.0], 1.64, 1.64, 1.64 , 3 , 0.99 ],
> +[ 58, "Promethium", "Pm", [1.0,1.0,1.0], 1.63, 1.63, 1.63 , 3 , 0.97 ],
> +[ 59, "Samarium", "Sm", [1.0,1.0,1.0], 1.62, 1.62, 1.62 , 3 , 0.96 ],
> +[ 60, "Europium", "Eu", [1.0,1.0,1.0], 1.85, 1.85, 1.85 , 2 , 1.09 , 3 , 0.95 ],
> +[ 61, "Gadolinium", "Gd", [1.0,1.0,1.0], 1.61, 1.61, 1.61 , 3 , 0.93 ],
> +[ 62, "Terbium", "Tb", [1.0,1.0,1.0], 1.59, 1.59, 1.59 , 3 , 0.92 , 4 , 0.84 ],
> +[ 63, "Dysprosium", "Dy", [1.0,1.0,1.0], 1.59, 1.59, 1.59 , 3 , 0.90 ],
> +[ 64, "Holmium", "Ho", [1.0,1.0,1.0], 1.58, 1.58, 1.58 , 3 , 0.89 ],
> +[ 65, "Erbium", "Er", [0.48,0.48,0.48], 1.57, 1.57, 1.57 , 3 , 0.88 ],
> +[ 66, "Thulium", "Tm", [1.0,1.0,1.0], 1.56, 1.56, 1.56 , 3 , 0.87 ],
> +[ 67, "Ytterbium", "Yb", [1.0,1.0,1.0], 1.74, 1.74, 1.74 , 2 , 0.93 , 3 , 0.85 ],
> +[ 68, "Lutetium", "Lu", [1.0,1.0,1.0], 1.56, 1.56, 1.56 , 3 , 0.85 ],
> +[ 69, "Hafnium", "Hf", [1.0,1.0,1.0], 1.44, 1.44, 1.44 , 4 , 0.78 ],
> +[ 70, "Tantalum", "Ta", [1.0,1.0,1.0], 1.34, 1.34, 1.34 , 5 , 0.68 ],
> +[ 71, "Tungsten", "W", [1.0,1.0,1.0], 1.30, 1.30, 1.30 , 4 , 0.70 , 6 , 0.62 ],
> +[ 72, "Rhenium", "Re", [1.0,1.0,1.0], 1.28, 1.28, 1.28 , 4 , 0.72 , 7 , 0.56 ],
> +[ 73, "Osmium", "Os", [1.0,1.0,1.0], 1.26, 1.26, 1.26 , 4 , 0.88 , 6 , 0.69 ],
> +[ 74, "Iridium", "Ir", [1.0,1.0,1.0], 1.27, 1.27, 1.27 , 4 , 0.68 ],
> +[ 75, "Platinium", "Pt", [1.0,1.0,1.0], 1.30, 1.30, 1.30 , 2 , 0.80 , 4 , 0.65 ],
> +[ 76, "Gold", "Au", [1.0,1.0,1.0], 1.34, 1.34, 1.34 , 1 , 1.37 , 3 , 0.85 ],
> +[ 77, "Mercury", "Hg", [1.0,1.0,1.0], 1.49, 1.49, 1.49 , 1 , 1.27 , 2 , 1.10 ],
> +[ 78, "Thallium", "Tl", [1.0,1.0,1.0], 1.48, 1.48, 1.48 , 1 , 1.47 , 3 , 0.95 ],
> +[ 79, "Lead", "Pb", [0.49,0.49,0.49], 1.47, 1.47, 1.47 , 2 , 1.20 , 4 , 0.84 ],
> +[ 80, "Bismuth", "Bi", [1.0,1.0,1.0], 1.46, 1.46, 1.46 , 1 , 0.98 , 3 , 0.96 , 5 , 0.74 ],
> +[ 81, "Polonium", "Po", [1.0,1.0,1.0], 1.46, 1.46, 1.46 , 6 , 0.67 ],
> +[ 82, "Astatine", "At", [1.0,1.0,1.0], 1.45, 1.45, 1.45 , -3 , 2.22 , 3 , 0.85 , 5 , 0.46 ],
> +[ 83, "Radon", "Rn", [1.0,1.0,1.0], 1.00, 1.00, 1.00 , 1 , 1.80 ],
> +[ 84, "Radium", "Ra", [1.0,1.0,1.0], 1.00, 1.00, 1.00 , 2 , 1.43 ],
> +[ 85, "Actinium", "Ac", [1.0,1.0,1.0], 1.00, 1.00, 1.00 , 3 , 1.18 ],
>
> @@ Diff output truncated at 10240 characters. @@
> _______________________________________________
> Bf-extensions-cvs mailing list
> Bf-extensions-cvs at blender.org
> http://lists.blender.org/mailman/listinfo/bf-extensions-cvs
>



-- 
- Campbell


More information about the Bf-extensions-cvs mailing list