Newer
Older
cube.parent = atom.parent
cube.hide_set(True)
electron1.hide_set(True)
electron2.hide_set(True)
lamp1.hide_set(True)
lamp2.hide_set(True)
Clemens Barth
committed
# Deselect everything
bpy.ops.object.select_all(action='DESELECT')
# Make the old atom visible.
atom.hide_set(True)
# Select the old atom.
atom.select_set(True)
# Remove the parent if necessary.
atom.parent = None
# Unlink the old object from the collection.
coll_atom.objects.unlink(atom)
# Delete the old atom
bpy.ops.object.delete()
Clemens Barth
committed
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
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
return new_atom
# Initialization of the list 'ELEMENTS'.
def read_elements():
del ELEMENTS[:]
for item in ELEMENTS_DEFAULT:
# All three radii into a list
radii = [item[4],item[5],item[6]]
# The handling of the ionic radii will be done later. So far, it is an
# empty list.
radii_ionic = item[7:]
li = ElementProp(item[0],item[1],item[2],item[3],
radii,radii_ionic)
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