[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3477] contrib/py/scripts/addons/ io_mesh_xyz/import_xyz.py:
Clemens Barth
barth at root-1.de
Sat Jun 9 13:18:59 CEST 2012
Revision: 3477
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3477
Author: blendphys
Date: 2012-06-09 11:18:57 +0000 (Sat, 09 Jun 2012)
Log Message:
-----------
'Security' for a special case: When a xyz file contains frames, in which the
number of atoms monotonously increases (due to any reasons), only the number
of atoms of the first frame is used for the animation - the additional atoms,
which appear in following frames, are not drawn! Remember, that the condition
still is: the total number of atoms of each frame must be constant!
Note that the addon crashes when the number decreases.
In future, I try to allow also varying number of atoms in frames. However, this
takes some time since the whole code needs to be re-structured.
Blendphys.
Modified Paths:
--------------
contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py
Modified: contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py
===================================================================
--- contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py 2012-06-08 17:57:07 UTC (rev 3476)
+++ contrib/py/scripts/addons/io_mesh_xyz/import_xyz.py 2012-06-09 11:18:57 UTC (rev 3477)
@@ -370,17 +370,31 @@
if len(split_list) == 1:
number_atoms = int(split_list[0])
+ #print(number_atoms)
FLAG = True
if FLAG == True:
line = ATOM_XYZ_FILEPATH_p.readline()
line = line.rstrip()
- comment = line
all_atoms= []
for i in range(number_atoms):
-
+
+
+ # This is a guarantee that only the total number of atoms of the
+ # first frame is used. Condition is, so far, that the number of
+ # atoms in a xyz file is constant. However, sometimes the number
+ # may increase (or decrease). If it decreases, the addon crashes.
+ # If it increases, only the tot number of atoms of the first frame
+ # is used.
+ # By time, I will allow varying atom numbers ... but this takes
+ # some time ...
+ if NUMBER_FRAMES != 0:
+ if i >= total_number_atoms:
+ break
+
+
line = ATOM_XYZ_FILEPATH_p.readline()
line = line.rstrip()
split_list = line.rsplit()
@@ -390,7 +404,7 @@
FLAG_FOUND = False
for element in ATOM_XYZ_ELEMENTS:
if str.upper(short_name) == str.upper(element.short_name):
- # Give the atom its proper names, color and radius:
+ # Give the atom its proper name, color and radius:
name = element.name
# int(radiustype) => type of radius:
# pre-defined (0), atomic (1) or van der Waals (2)
@@ -426,6 +440,18 @@
# We note here all elements. This needs to be done only once.
if NUMBER_FRAMES == 0:
+
+ # This is a guarantee that only the total number of atoms of the
+ # first frame is used. Condition is, so far, that the number of
+ # atoms in a xyz file is constant. However, sometimes the number
+ # may increase (or decrease). If it decreases, the addon crashes.
+ # If it increases, only the tot number of atoms of the first frame
+ # is used.
+ # By time, I will allow varying atom numbers ... but this takes
+ # some time ...
+ total_number_atoms = number_atoms
+
+
elements = []
for atom in all_atoms:
FLAG_FOUND = False
@@ -441,6 +467,7 @@
# atom name (e.g. 'Sodium') and its color.
elements.append(atom[1])
+ # Sort the atoms: create lists of atoms of one type
structure = []
for element in elements:
atoms_one_type = []
@@ -467,7 +494,7 @@
print(atom.element + " " + str(atom.location))
print()
"""
- return number_atoms
+ return total_number_atoms
# This reads a custom data file.
@@ -583,7 +610,7 @@
# comparison of names ...
if atom.name in material.name:
# ... and give the atom its material properties.
- # However, before we check, if it is a vacancy
+ # However, before we check if it is a vacancy
# The vacancy is represented by a transparent cube.
if atom.name == "Vacancy":
material.transparency_method = 'Z_TRANSPARENCY'
@@ -628,7 +655,19 @@
sum_vec = Vector((0.0,0.0,0.0))
# Sum of all atom coordinates
- for atoms_of_one_type in frame:
+ for (i, atoms_of_one_type) in enumerate(frame):
+
+ # This is a guarantee that only the total number of atoms of the
+ # first frame is used. Condition is, so far, that the number of
+ # atoms in a xyz file is constant. However, sometimes the number
+ # may increase (or decrease). If it decreases, the addon crashes.
+ # If it increases, only the tot number of atoms of the first frame
+ # is used.
+ # By time, I will allow varying atom numbers ... but this takes
+ # some time ...
+ if i >= Number_of_total_atoms:
+ break
+
sum_vec = sum([atom.location for atom in atoms_of_one_type], sum_vec)
# Then the average is taken
@@ -675,7 +714,7 @@
# ------------------------------------------------------------------------
# CAMERA AND LAMP
- camera_factor = 15.0
+ camera_factor = 20.0
# If chosen a camera is put into the scene.
if use_camera == True:
More information about the Bf-extensions-cvs
mailing list