Newer
Older
cube.hide_set(True)
lamp.hide_set(True)
Clemens Barth
committed
# F+ center
if atom_shape == '2':
cube.name = atom.name + "_F2+_vac"
# New material for this cube
material_new = bpy.data.materials.new(atom.name + "_F2+_vac")
material_new.use_nodes = True
mat_P_BSDF = material_new.node_tree.nodes['Principled BSDF']
mat_P_BSDF.inputs['Base Color'].default_value = [0.0, 0.0, 0.8, 1.0]
mat_P_BSDF.inputs['Metallic'].default_value = 0.7
mat_P_BSDF.inputs['Specular'].default_value = 0.0
mat_P_BSDF.inputs['Roughness'].default_value = 0.65
mat_P_BSDF.inputs['Clearcoat Roughness'].default_value = 0.0
mat_P_BSDF.inputs['IOR'].default_value = 1.45
mat_P_BSDF.inputs['Transmission'].default_value = 0.6
mat_P_BSDF.inputs['Transmission Roughness'].default_value = 0.5
mat_P_BSDF.inputs['Alpha'].default_value = 0.6
# Some additional stuff for eevee.
material_new.blend_method = 'HASHED'
material_new.shadow_method = 'HASHED'
material_new.use_backface_culling = False
cube.active_material = material_new
# Create now an electron
scale = atom.scale / 10.0
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
enter_editmode=False,
location=(0.0, 0.0, 0.0),
rotation=(0.0, 0.0, 0.0))
electron = bpy.context.view_layer.objects.active
electron.scale = scale
electron.name = atom.name + "_F+_electron"
electron.parent = cube
# New material for the electron
material_electron = bpy.data.materials.new(atom.name + "_F+-center")
material_electron.use_nodes = True
mat_P_BSDF = material_electron.node_tree.nodes['Principled BSDF']
mat_P_BSDF.inputs['Base Color'].default_value = [0.0, 0.0, 0.8, 1.0]
mat_P_BSDF.inputs['Metallic'].default_value = 0.8
mat_P_BSDF.inputs['Specular'].default_value = 0.0
mat_P_BSDF.inputs['Roughness'].default_value = 0.3
mat_P_BSDF.inputs['Clearcoat Roughness'].default_value = 0.0
mat_P_BSDF.inputs['IOR'].default_value = 1.45
mat_P_BSDF.inputs['Transmission'].default_value = 0.6
mat_P_BSDF.inputs['Transmission Roughness'].default_value = 0.5
mat_P_BSDF.inputs['Alpha'].default_value = 1.0
# Some additional stuff for eevee.
material_electron.blend_method = 'OPAQUE'
material_electron.shadow_method = 'OPAQUE'
material_electron.use_backface_culling = False
electron.active_material = material_electron
# Put a point lamp inside the electron
lamp_data = bpy.data.lights.new(name=atom.name + "_F+_lamp", type="POINT")
lamp_data.distance = atom.scale[0] * 2.0
lamp_data.energy = 100000.0
lamp_data.color = (0.0, 0.0, 0.8)
lamp = bpy.data.objects.new(atom.name + "_F+_lamp", lamp_data)
lamp.location = Vector((scale[0]*1.5, 0.0, 0.0))
bpy.context.collection.objects.link(lamp)
lamp.parent = cube
# The new 'atom' is the F+ defect complex + lamp
new_atom = cube
# Note the collection where all the new objects were placed into.
# We use only one object, the cube
coll_ori = get_collection_object(cube)
Clemens Barth
committed
# If it is not the same collection then ...
if coll_ori != coll_new:
# Put all new objects into the new collection and ...
coll_new.objects.link(cube)
coll_new.objects.link(electron)
coll_new.objects.link(lamp)
# ... unlink them from their original collection.
coll_ori.objects.unlink(cube)
coll_ori.objects.unlink(electron)
coll_ori.objects.unlink(lamp)
coll_new.name = atom.name + "_F+_center"
Clemens Barth
committed
if atom.parent != None:
cube.parent = atom.parent
cube.hide_set(True)
electron.hide_set(True)
lamp.hide_set(True)
# F0 center
if atom_shape == '3':
cube.name = atom.name + "_F2+_vac"
# New material for this cube
material_new = bpy.data.materials.new(atom.name + "_F2+_vac")
material_new.use_nodes = True
mat_P_BSDF = material_new.node_tree.nodes['Principled BSDF']
mat_P_BSDF.inputs['Base Color'].default_value = [0.8, 0.0, 0.0, 1.0]
mat_P_BSDF.inputs['Metallic'].default_value = 0.7
mat_P_BSDF.inputs['Specular'].default_value = 0.0
mat_P_BSDF.inputs['Roughness'].default_value = 0.65
mat_P_BSDF.inputs['Clearcoat Roughness'].default_value = 0.0
mat_P_BSDF.inputs['IOR'].default_value = 1.45
mat_P_BSDF.inputs['Transmission'].default_value = 0.6
mat_P_BSDF.inputs['Transmission Roughness'].default_value = 0.5
mat_P_BSDF.inputs['Alpha'].default_value = 0.6
# Some additional stuff for eevee.
material_new.blend_method = 'HASHED'
material_new.shadow_method = 'HASHED'
material_new.use_backface_culling = False
cube.active_material = material_new
# Create now two electrons ... .
scale = atom.scale / 10.0
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
enter_editmode=False,
location=(scale[0]*1.5,0.0,0.0),
rotation=(0.0, 0.0, 0.0))
electron1 = bpy.context.view_layer.objects.active
electron1.scale = scale
electron1.name = atom.name + "_F0_electron_1"
electron1.parent = cube
bpy.ops.surface.primitive_nurbs_surface_sphere_add(
enter_editmode=False,
location=(-scale[0]*1.5,0.0,0.0),
rotation=(0.0, 0.0, 0.0))
electron2 = bpy.context.view_layer.objects.active
electron2.scale = scale
electron2.name = atom.name + "_F0_electron_2"
electron2.parent = cube
# Create a new material for the two electrons.
material_electron = bpy.data.materials.new(atom.name + "_F0-center")
material_electron.use_nodes = True
mat_P_BSDF = material_electron.node_tree.nodes['Principled BSDF']
mat_P_BSDF.inputs['Base Color'].default_value = [0.0, 0.0, 0.8, 1.0]
mat_P_BSDF.inputs['Metallic'].default_value = 0.8
mat_P_BSDF.inputs['Specular'].default_value = 0.0
mat_P_BSDF.inputs['Roughness'].default_value = 0.3
mat_P_BSDF.inputs['Clearcoat Roughness'].default_value = 0.0
mat_P_BSDF.inputs['IOR'].default_value = 1.45
mat_P_BSDF.inputs['Transmission'].default_value = 0.6
mat_P_BSDF.inputs['Transmission Roughness'].default_value = 0.5
mat_P_BSDF.inputs['Alpha'].default_value = 1.0
# Some additional stuff for eevee.
material_electron.blend_method = 'OPAQUE'
material_electron.shadow_method = 'OPAQUE'
material_electron.use_backface_culling = False
# We assign the materials to the two electrons.
electron1.active_material = material_electron
electron2.active_material = material_electron
# Put two point lamps inside the electrons.
lamp1_data = bpy.data.lights.new(name=atom.name + "_F0_lamp_1", type="POINT")
lamp1_data.distance = atom.scale[0] * 2.0
lamp1_data.energy = 20000.0
lamp1_data.color = (0.8, 0.0, 0.0)
lamp1 = bpy.data.objects.new(atom.name + "_F0_lamp", lamp1_data)
lamp1.location = Vector((scale[0]*1.5, 0.0, 0.0))
bpy.context.collection.objects.link(lamp1)
lamp1.parent = cube
lamp2_data = bpy.data.lights.new(name=atom.name + "_F0_lamp_2", type="POINT")
lamp2_data.distance = atom.scale[0] * 2.0
lamp2_data.energy = 20000.0
lamp2_data.color = (0.8, 0.0, 0.0)
lamp2 = bpy.data.objects.new(atom.name + "_F0_lamp", lamp2_data)
lamp2.location = Vector((-scale[0]*1.5, 0.0, 0.0))
bpy.context.collection.objects.link(lamp2)
lamp2.parent = cube
# The new 'atom' is the F0 defect complex + lamps
new_atom = cube
# Note the collection where all the new objects were placed into.
# We use only one object, the cube
coll_ori = get_collection_object(cube)
Clemens Barth
committed
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
# If it is not the same collection then ...
if coll_ori != coll_new:
# Put all new objects into the collection of 'atom' and ...
coll_new.objects.link(cube)
coll_new.objects.link(electron1)
coll_new.objects.link(electron2)
coll_new.objects.link(lamp1)
coll_new.objects.link(lamp2)
# ... unlink them from their original collection.
coll_ori.objects.unlink(cube)
coll_ori.objects.unlink(electron1)
coll_ori.objects.unlink(electron2)
coll_ori.objects.unlink(lamp1)
coll_ori.objects.unlink(lamp2)
coll_new.name = atom.name + "_F0_center"
if atom.parent != None:
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
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:
FLAG = False
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:
obj = child
e = element
FLAG = True
else:
if atom.type in {'SURFACE', 'MESH', 'META'}:
for element in ELEMENTS:
if element.name in atom.name:
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
obj = atom
e = element
FLAG = True
if FLAG:
obj.scale = (e.radii[0],) * 3
mat = obj.active_material
mat_P_BSDF = mat.node_tree.nodes['Principled BSDF']
mat_P_BSDF.inputs['Base Color'].default_value = e.color
mat_P_BSDF.subsurface_method = e.mat_P_BSDF.Subsurface_method
mat_P_BSDF.distribution = e.mat_P_BSDF.Distribution
mat_P_BSDF.inputs['Subsurface'].default_value = e.mat_P_BSDF.Subsurface
mat_P_BSDF.inputs['Subsurface Color'].default_value = e.mat_P_BSDF.Subsurface_color
mat_P_BSDF.inputs['Subsurface Radius'].default_value = e.mat_P_BSDF.Subsurface_radius
mat_P_BSDF.inputs['Metallic'].default_value = e.mat_P_BSDF.Metallic
mat_P_BSDF.inputs['Specular'].default_value = e.mat_P_BSDF.Specular
mat_P_BSDF.inputs['Specular Tint'].default_value = e.mat_P_BSDF.Specular_tilt
mat_P_BSDF.inputs['Roughness'].default_value = e.mat_P_BSDF.Roughness
mat_P_BSDF.inputs['Anisotropic'].default_value = e.mat_P_BSDF.Anisotropic
mat_P_BSDF.inputs['Anisotropic Rotation'].default_value = e.mat_P_BSDF.Anisotropic_rotation
mat_P_BSDF.inputs['Sheen'].default_value = e.mat_P_BSDF.Sheen
mat_P_BSDF.inputs['Sheen Tint'].default_value = e.mat_P_BSDF.Sheen_tint
mat_P_BSDF.inputs['Clearcoat'].default_value = e.mat_P_BSDF.Clearcoat
mat_P_BSDF.inputs['Clearcoat Roughness'].default_value = e.mat_P_BSDF.Clearcoat_rough
mat_P_BSDF.inputs['IOR'].default_value = e.mat_P_BSDF.IOR
mat_P_BSDF.inputs['Transmission'].default_value = e.mat_P_BSDF.Trans
mat_P_BSDF.inputs['Transmission Roughness'].default_value = e.mat_P_BSDF.Trans_rough
mat_P_BSDF.inputs['Emission'].default_value = e.mat_P_BSDF.Emission
mat_P_BSDF.inputs['Emission Strength'].default_value = e.mat_P_BSDF.Emission_strength
mat_P_BSDF.inputs['Alpha'].default_value = e.mat_P_BSDF.Alpha
mat.use_backface_culling = e.mat_Eevee.use_backface
mat.blend_method = e.mat_Eevee.blend_method
mat.shadow_method = e.mat_Eevee.shadow_method
mat.alpha_threshold = e.mat_Eevee.clip_threshold
mat.use_screen_refraction = e.mat_Eevee.use_screen_refraction
mat.refraction_depth = e.mat_Eevee.refraction_depth
mat.use_sss_translucency = e.mat_Eevee.use_sss_translucency
mat.pass_index = e.mat_Eevee.pass_index
FLAG = False
bpy.ops.object.select_all(action='DESELECT')
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
# 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 "#" == line[0]:
continue
if "Atom" in line:
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
list_radii_ionic = []
while True:
if len(line) in [0,1]:
break
# Number
if "Number :" in line:
pos = line.rfind(':') + 1
number = line[pos:].strip()
# Name
if "Name :" in line:
pos = line.rfind(':') + 1
name = line[pos:].strip()
# Short name
if "Short name :" in line:
pos = line.rfind(':') + 1
short_name = line[pos:].strip()
# Color
if "Color :" in line:
pos = line.rfind(':') + 1
color_value = line[pos:].strip().split(',')
color = [float(color_value[0]),
float(color_value[1]),
float(color_value[2]),
float(color_value[3])]
# Used radius
if "Radius used :" in line:
pos = line.rfind(':') + 1
radius_used = float(line[pos:].strip())
# Covalent radius
if "Radius, covalent :" in line:
pos = line.rfind(':') + 1
radius_covalent = float(line[pos:].strip())
# Atomic radius
if "Radius, atomic :" in line:
pos = line.rfind(':') + 1
radius_atomic = float(line[pos:].strip())
if "Charge state :" in line:
pos = line.rfind(':') + 1
charge_state = float(line[pos:].strip())
line = data_file_p.readline()
pos = line.rfind(':') + 1
radius_ionic = float(line[pos:].strip())
list_radii_ionic.append(charge_state)
list_radii_ionic.append(radius_ionic)
# Some Principled BSDF properties
if "P BSDF Subsurface method :" in line:
pos = line.rfind(':') + 1
P_BSDF_subsurface_method = line[pos:].strip()
if "P BSDF Distribution :" in line:
pos = line.rfind(':') + 1
P_BSDF_distribution = line[pos:].strip()
if "P BSDF Subsurface :" in line:
pos = line.rfind(':') + 1
P_BSDF_subsurface = float(line[pos:].strip())
if "P BSDF Subsurface Color :" in line:
pos = line.rfind(':') + 1
color_value = line[pos:].strip().split(',')
P_BSDF_subsurface_color = [float(color_value[0]),
float(color_value[1]),
float(color_value[2]),
float(color_value[3])]
if "P BSDF Subsurface Radius :" in line:
pos = line.rfind(':') + 1
radii_values = line[pos:].strip().split(',')
P_BSDF_subsurface_radius = [float(color_value[0]),
float(color_value[1]),
float(color_value[2])]
if "P BSDF Metallic :" in line:
pos = line.rfind(':') + 1
P_BSDF_metallic = float(line[pos:].strip())
if "P BSDF Specular :" in line:
pos = line.rfind(':') + 1
P_BSDF_specular = float(line[pos:].strip())
if "P BSDF Specular Tilt :" in line:
pos = line.rfind(':') + 1
P_BSDF_specular_tilt = float(line[pos:].strip())
if "P BSDF Roughness :" in line:
pos = line.rfind(':') + 1
P_BSDF_roughness = float(line[pos:].strip())
if "P BSDF Anisotropic :" in line:
pos = line.rfind(':') + 1
P_BSDF_anisotropic = float(line[pos:].strip())
if "P BSDF Anisotropic Rotation :" in line:
pos = line.rfind(':') + 1
P_BSDF_anisotropic_rotation = float(line[pos:].strip())
if "P BSDF Sheen : " in line:
pos = line.rfind(':') + 1
P_BSDF_sheen = float(line[pos:].strip())
if "P BSDF Sheen Tint : " in line:
pos = line.rfind(':') + 1
P_BSDF_sheen_tint = float(line[pos:].strip())
if "P BSDF Clearcoat :" in line:
pos = line.rfind(':') + 1
P_BSDF_clearcoat = float(line[pos:].strip())
if "P BSDF Clearcoat Rough :" in line:
pos = line.rfind(':') + 1
P_BSDF_clearcoat_roughness = float(line[pos:].strip())
if "P BSDF IOR :" in line:
pos = line.rfind(':') + 1
P_BSDF_IOR = float(line[pos:].strip())
if "P BSDF Trans :" in line:
pos = line.rfind(':') + 1
P_BSDF_transparency = float(line[pos:].strip())
if "P BSDF Trans Roughness :" in line:
pos = line.rfind(':') + 1
P_BSDF_transparency_roughness = float(line[pos:].strip())
if "P BSDF Emisssion : " in line:
pos = line.rfind(':') + 1
color_value = line[pos:].strip().split(',')
P_BSDF_emission = [float(color_value[0]),
float(color_value[1]),
float(color_value[2]),
float(color_value[3])]
if "P BSDF Emission Strength :" in line:
pos = line.rfind(':') + 1
P_BSDF_emission_strength = float(line[pos:].strip())
if "P BSDF Alpha :" in line:
pos = line.rfind(':') + 1
P_BSDF_alpha = float(line[pos:].strip())
if "Eevee Use Backface Culling :" in line:
pos = line.rfind(':') + 1
line = line[pos:].strip()
if line.lower() in ("yes", "true", "1"):
Eevee_use_backface = True
else:
Eevee_use_backface = False
if "Eevee Blend Method :" in line:
pos = line.rfind(':') + 1
Eevee_blend_method = line[pos:].strip()
if "Eevee Shadow Method :" in line:
pos = line.rfind(':') + 1
Eevee_shadow_method = line[pos:].strip()
if "Eevee Clip Threshold :" in line:
pos = line.rfind(':') + 1
Eevee_clip_threshold = float(line[pos:].strip())
if "Eevee Use Screen Refraction :" in line:
pos = line.rfind(':') + 1
line = line[pos:].strip()
if line.lower() in ("yes", "true", "1"):
Eevee_use_screen_refraction = True
else:
Eevee_use_screen_refraction = False
if "Eevee Refraction depth : " in line:
pos = line.rfind(':') + 1
Eevee_refraction_depth = float(line[pos:].strip())
if "Eevee Use SSS Translucency :" in line:
pos = line.rfind(':') + 1
line = line[pos:].strip()
if line.lower() in ("yes", "true", "1"):
Eevee_use_sss_translucency = True
else:
Eevee_use_sss_translucency = False
if "Eevee Pass Index :" in line:
pos = line.rfind(':') + 1
Eevee_pass_index = int(line[pos:].strip())
line = data_file_p.readline()
list_radii = [radius_used, radius_covalent, radius_atomic]
Eevee_material = EeveeProp(Eevee_use_backface,
Eevee_blend_method,
Eevee_shadow_method,
Eevee_clip_threshold,
Eevee_use_screen_refraction,
Eevee_refraction_depth,
Eevee_use_sss_translucency,
Eevee_pass_index)
P_BSDF_material = PBSDFProp(P_BSDF_subsurface_method,
P_BSDF_distribution,
P_BSDF_subsurface,
P_BSDF_subsurface_color,
P_BSDF_subsurface_radius,
P_BSDF_metallic,
P_BSDF_specular,
P_BSDF_specular_tilt,
P_BSDF_roughness,
P_BSDF_anisotropic,
P_BSDF_anisotropic_rotation,
P_BSDF_sheen,
P_BSDF_sheen_tint,
P_BSDF_clearcoat,
P_BSDF_clearcoat_roughness,
P_BSDF_IOR,
P_BSDF_transparency,
P_BSDF_transparency_roughness,
P_BSDF_emission,
P_BSDF_emission_strength,
P_BSDF_alpha)
element = ElementProp(number,
name,
short_name,
color,
list_radii,
list_radii_ionic,
P_BSDF_material,
Eevee_material)
ELEMENTS.append(element)
data_file_p.close()
return True