[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4153] contrib/py/scripts/addons/ io_atomblend_utilities:
Clemens Barth
barth at root-1.de
Tue Jan 8 07:38:07 CET 2013
Revision: 4153
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4153
Author: blendphys
Date: 2013-01-08 06:38:02 +0000 (Tue, 08 Jan 2013)
Log Message:
-----------
1. New feature: The ionic radius can now be chosen for the ball radius,
depending on the charge state (-4e ... +7e). Changes of the ball radii are
only done if objects are selected.
2. Code cleaning.
Blendphys.
Modified Paths:
--------------
contrib/py/scripts/addons/io_atomblend_utilities/__init__.py
contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py
Modified: contrib/py/scripts/addons/io_atomblend_utilities/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_atomblend_utilities/__init__.py 2013-01-07 00:55:52 UTC (rev 4152)
+++ contrib/py/scripts/addons/io_atomblend_utilities/__init__.py 2013-01-08 06:38:02 UTC (rev 4153)
@@ -24,7 +24,7 @@
#
# Start of project : 2011-12-01 by Clemens Barth
# First publication in Blender : 2012-11-03
-# Last modified : 2013-01-03
+# Last modified : 2013-01-08
#
# Acknowledgements
# ================
@@ -60,8 +60,7 @@
# -----------------------------------------------------------------------------
# GUI
-# This is the panel, which can be used to prepare the scene.
-# It is loaded after the file has been chosen via the menu 'File -> Import'
+# The panel.
class PreparePanel(Panel):
bl_label = "Atomic Blender Utilities"
bl_space_type = "VIEW_3D"
@@ -72,7 +71,6 @@
scn = context.scene.atom_blend
row = layout.row()
- row.label(text="Custom data file")
box = layout.box()
row = box.row()
row.label(text="Custom data file")
@@ -95,6 +93,9 @@
row = box.row()
row.prop(scn, "radius_type")
row = box.row()
+ row.active = (scn.radius_type == '3')
+ row.prop(scn, "radius_type_ionic")
+ row = box.row()
row.label(text="2. Change atom radii in pm")
row = box.row()
row.prop(scn, "radius_pm_name")
@@ -115,6 +116,7 @@
row.operator( "atom_blend.separate_atom" )
+# The properties of buttons etc. in the panel.
class PanelProperties(bpy.types.PropertyGroup):
def Callback_radius_type(self, context):
@@ -123,7 +125,8 @@
scn.radius_how,
None,
None,
- scn.radius_type)
+ scn.radius_type,
+ scn.radius_type_ionic)
def Callback_radius_pm(self, context):
scn = bpy.context.scene.atom_blend
io_atomblend_utilities.choose_objects("radius_pm",
@@ -131,6 +134,7 @@
None,
[scn.radius_pm_name,
scn.radius_pm],
+ None,
None)
datafile = StringProperty(
@@ -152,12 +156,28 @@
('ALL_IN_LAYER',"all"," in active layer(s)")),
default='ALL_ACTIVE',)
radius_type = EnumProperty(
- name="Type",
+ name="Type of radius",
description="Which type of atom radii?",
items=(('0',"predefined", "Use pre-defined radii"),
('1',"atomic", "Use atomic radii"),
- ('2',"van der Waals","Use van der Waals radii")),
+ ('2',"van der Waals","Use van der Waals radii"),
+ ('3',"ionic radii", "Use ionic radii")),
default='0',update=Callback_radius_type)
+ radius_type_ionic = EnumProperty(
+ name="Charge state",
+ description="Charge state of the ions if existing.",
+ items=(('0',"-4", "Charge state -4"),
+ ('1',"-3", "Charge state -3"),
+ ('2',"-2", "Charge state -2"),
+ ('3',"-1", "Charge state -1"),
+ ('5',"+1", "Charge state +1"),
+ ('6',"+2", "Charge state +2"),
+ ('7',"+3", "Charge state +3"),
+ ('8',"+4", "Charge state +4"),
+ ('9',"+5", "Charge state +5"),
+ ('10',"+6", "Charge state +6"),
+ ('11',"+7", "Charge state +7")),
+ default='3',update=Callback_radius_type)
radius_pm_name = StringProperty(
name="", default="Atom name",
description="Put in the name of the atom (e.g. Hydrogen)")
Modified: contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py
===================================================================
--- contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py 2013-01-07 00:55:52 UTC (rev 4152)
+++ contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py 2013-01-08 06:38:02 UTC (rev 4153)
@@ -20,14 +20,8 @@
import bpy
import bmesh
-# This variable contains the path of the XYZ file.
-# It is used almost everywhere, which explains why it
-# should stay global. First, it is empty and gets 'filled' directly
-# after having chosen the XYZ file (see 'class LoadXYZ' further below).
-
-
# -----------------------------------------------------------------------------
-# Atom and element data
+# Atom and element data
# This is a list that contains some data of all possible elements. The structure
@@ -150,13 +144,12 @@
(106, "Stick", "Stick", ( 0.5, 0.5, 0.5), 1.00, 1.00, 1.00),
)
-# This list here contains all data of the elements and will be used during
-# runtime. It is a list of classes.
-# During executing Atomic Blender, the list will be initialized with the fixed
-# data from above via the class structure below (ElementProp). We
-# have then one fixed list (above), which will never be changed, and a list of
-# classes with same data. The latter can be modified via loading a separate
-# custom data file for instance.
+# The list 'ELEMENTS' contains all data of the elements and will be used during
+# runtime. The list will be initialized with the fixed
+# data from above via the class below (ElementProp). One fixed list (above),
+# which cannot be changed, and a list of classes with same data (ELEMENTS) exist.
+# The list 'ELEMENTS' can be modified by e.g. loading a separate custom
+# data file.
ELEMENTS = []
# This is the class, which stores the properties for one element.
@@ -171,9 +164,6 @@
self.radii_ionic = radii_ionic
-# -----------------------------------------------------------------------------
-# Some small routines
-
# This function measures the distance between two objects (atoms),
# which are active.
def distance():
@@ -212,7 +202,12 @@
return dist
-def choose_objects(how, who, radius_all, radius_pm, radius_type):
+def choose_objects(how,
+ who,
+ radius_all,
+ radius_pm,
+ radius_type,
+ radius_type_ionic):
if who == "ALL_IN_LAYER":
@@ -237,14 +232,16 @@
obj.children[0],
radius_all,
radius_pm,
- radius_type)
+ radius_type,
+ radius_type_ionic)
else:
if obj.type in {'SURFACE', 'MESH', 'META'}:
modify_objects(how,
obj,
radius_all,
radius_pm,
- radius_type)
+ radius_type,
+ radius_type_ionic)
if who == "ALL_ACTIVE":
for obj in bpy.context.selected_objects:
if len(obj.children) != 0:
@@ -253,19 +250,26 @@
obj.children[0],
radius_all,
radius_pm,
- radius_type)
+ radius_type,
+ radius_type_ionic)
else:
if obj.type in {'SURFACE', 'MESH', 'META'}:
modify_objects(how,
obj,
radius_all,
radius_pm,
- radius_type)
+ radius_type,
+ radius_type_ionic)
-# Routine to modify the radii in picometer of a specific type of atom
-def modify_objects(how, obj, radius_all, radius_pm, radius_type):
+# Modifying the radii in picometer of a specific type of atom
+def modify_objects(how,
+ obj,
+ radius_all,
+ radius_pm,
+ radius_type,
+ radius_type_ionic):
# Radius pm
if how == "radius_pm":
@@ -278,12 +282,30 @@
# Radius type
if how == "radius_type":
- for element in ELEMENTS:
+ for element in ELEMENTS:
if element.name in obj.name:
- obj.scale = (element.radii[int(radius_type)],) * 3
+ # For ionic radii
+ if radius_type == '3':
+ charge_states = element.radii_ionic[::2]
+ charge_radii = element.radii_ionic[1::2]
+ charge_state_chosen = int(radius_type_ionic) - 4
+
+ find = (lambda searchList, elem:
+ [[i for i, x in enumerate(searchList) if x == e]
+ for e in elem])
+ index = find(charge_states,[charge_state_chosen])[0]
+ # Is there a charge state?
+ if index != []:
+ #print(element.name, index[0], charge_radii[index[0]])
+ obj.scale = (charge_radii[index[0]],) * 3
+
+ # For atomic and van der Waals radii.
+ else:
+ obj.scale = (element.radii[int(radius_type)],) * 3
-# Read the default element list.
+
+# Initialization of the list 'ELEMENTS'.
def read_elements():
del ELEMENTS[:]
@@ -294,14 +316,14 @@
radii = [item[4],item[5],item[6]]
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list