Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
ELEMENTS.append(li)
# Custom data file: changing color and radii by using the list 'ELEMENTS'.
def custom_datafile_change_atom_props():
for atom in bpy.context.selected_objects:
if len(atom.children) != 0:
child = atom.children[0]
if child.type in {'SURFACE', 'MESH', 'META'}:
for element in ELEMENTS:
if element.name in atom.name:
child.scale = (element.radii[0],) * 3
child.active_material.diffuse_color = element.color
else:
if atom.type in {'SURFACE', 'MESH', 'META'}:
for element in ELEMENTS:
if element.name in atom.name:
atom.scale = (element.radii[0],) * 3
atom.active_material.diffuse_color = element.color
# Reading a custom data file and modifying the list 'ELEMENTS'.
def custom_datafile(path_datafile):
if path_datafile == "":
return False
path_datafile = bpy.path.abspath(path_datafile)
if os.path.isfile(path_datafile) == False:
return False
# The whole list gets deleted! We build it new.
del ELEMENTS[:]
# Read the data file, which contains all data
# (atom name, radii, colors, etc.)
data_file_p = open(path_datafile, "r")
for line in data_file_p:
if "Atom" in line:
line = data_file_p.readline()
# Number
line = data_file_p.readline()
number = line[19:-1]
# Name
line = data_file_p.readline()
name = line[19:-1]
# Short name
line = data_file_p.readline()
short_name = line[19:-1]
# Color
line = data_file_p.readline()
color_value = line[19:-1].split(',')
color = [float(color_value[0]),
float(color_value[1]),
float(color_value[2]),
float(color_value[3])]
# Used radius
line = data_file_p.readline()
radius_used = float(line[19:-1])
# Atomic radius
line = data_file_p.readline()
radius_atomic = float(line[19:-1])
# Van der Waals radius
line = data_file_p.readline()
radius_vdW = float(line[19:-1])
radii = [radius_used,radius_atomic,radius_vdW]
radii_ionic = []
element = ElementProp(number,name,short_name,color,
radii, radii_ionic)
ELEMENTS.append(element)
data_file_p.close()
return True