blender-v3.6-release #104623

Closed
Sebastian Sille wants to merge 20 commits from (deleted):blender-v3.6-release into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
2 changed files with 97 additions and 51 deletions
Showing only changes of commit d0b5970dca - Show all commits

View File

@ -7,7 +7,7 @@
# Start of project : 2011-08-31 by CB
# First publication in Blender : 2011-11-11 by CB
# Fusion of the PDB, XYZ and Panel : 2019-03-22 by CB
# Last modified : 2019-05-17
# Last modified : 2023-05-19
#
# Contributing authors
# ====================

View File

@ -1100,6 +1100,7 @@ def draw_sticks_normal(all_atoms,
center,
Stick_diameter,
Stick_sectors,
Stick_dist,
use_sticks_smooth,
use_sticks_one_object,
use_sticks_one_object_nr,
@ -1117,60 +1118,104 @@ def draw_sticks_normal(all_atoms,
list_group = []
list_group_sub = []
counter = 0
for stick in all_sticks:
for i, stick in enumerate(all_sticks):
# The vectors of the two atoms
atom1 = all_atoms[stick.atom1-1].location-center
atom2 = all_atoms[stick.atom2-1].location-center
# Location
location = (atom1 + atom2) * 0.5
# The difference of both vectors
v = (atom2 - atom1)
# Angle with respect to the z-axis
angle = v.angle(up_axis, 0)
# Cross-product between v and the z-axis vector. It is the
# vector of rotation.
axis = up_axis.cross(v)
# Calculate Euler angles
euler = Matrix.Rotation(angle, 4, axis).to_euler()
# Create stick
stick = bpy.ops.mesh.primitive_cylinder_add(vertices=Stick_sectors,
radius=Stick_diameter,
depth=v.length,
end_fill_type='NGON',
align='WORLD',
enter_editmode=False,
location=location,
rotation=(0, 0, 0))
# Put the stick into the scene ...
stick = bpy.context.view_layer.objects.active
# ... and rotate the stick.
stick.rotation_euler = euler
# ... and name
stick.name = "Stick_Cylinder"
counter += 1
# We treat here single, double and tripple bonds: stick.number <= 3
for repeat in range(stick.number):
# Smooth the cylinder.
if use_sticks_smooth == True:
bpy.ops.object.select_all(action='DESELECT')
stick.select_set(True)
bpy.ops.object.shade_smooth()
# The vectors of the two atoms
atom1 = copy(all_atoms[stick.atom1-1].location)-center
atom2 = copy(all_atoms[stick.atom2-1].location)-center
list_group_sub.append(stick)
dist = Stick_diameter * Stick_dist
if use_sticks_one_object == True:
if counter == use_sticks_one_object_nr:
# The two sticks are on the left and right of the middle connection.
if stick.number == 2:
if repeat == 0:
atom1 += (stick.dist * dist)
atom2 += (stick.dist * dist)
if repeat == 1:
atom1 -= (stick.dist * dist)
atom2 -= (stick.dist * dist)
if stick.number == 3:
if repeat == 0:
atom1 += (stick.dist * dist)
atom2 += (stick.dist * dist)
if repeat == 2:
atom1 -= (stick.dist * dist)
atom2 -= (stick.dist * dist)
# Vector pointing along the stick direction
dv = atom1 - atom2
# The normalized vector of this, with lenght 1
n = dv / dv.length
# Starting point of the stick
location = (atom1 + atom2) * 0.5
# Angle with respect to the z-axis
angle = dv.angle(up_axis, 0)
# Cross-product between v and the z-axis vector. It is the
# vector of rotation.
axis = up_axis.cross(dv)
# Calculate Euler angles
euler = Matrix.Rotation(angle, 4, axis).to_euler()
# Create stick
stick_obj = bpy.ops.mesh.primitive_cylinder_add(vertices=Stick_sectors,
radius=Stick_diameter,
depth=dv.length,
end_fill_type='NGON',
align='WORLD',
enter_editmode=False,
location=location,
rotation=(0, 0, 0))
# Put the stick into the scene ...
stick_obj = bpy.context.view_layer.objects.active
# ... and rotate the stick.
stick_obj.rotation_euler = euler
# ... and name
if stick.number == 1:
stick_obj.name = "Stick_Cylinder_%04d" %(i)
elif stick.number == 2:
if repeat == 0:
stick_obj.name = "Stick_Cylinder_%04d" %(i) + "_left"
elif repeat == 1:
stick_obj.name = "Stick_Cylinder_%04d" %(i) + "_right"
elif stick.number == 3:
if repeat == 0:
stick_obj.name = "Stick_Cylinder_%04d" %(i) + "_left"
elif repeat == 1:
stick_obj.name = "Stick_Cylinder_%04d" %(i) + "_middle"
elif repeat == 2:
stick_obj.name = "Stick_Cylinder_%04d" %(i) + "_right"
# Never occurs:
else:
stick_obj.name = "Stick_Cylinder"
# Never occurs:
else:
stick_obj.name = "Stick_Cylinder"
counter += 1
# Smooth the cylinder.
if use_sticks_smooth == True:
bpy.ops.object.select_all(action='DESELECT')
for stick in list_group_sub:
stick.select_set(True)
bpy.ops.object.join()
list_group.append(bpy.context.view_layer.objects.active)
bpy.ops.object.select_all(action='DESELECT')
list_group_sub = []
counter = 0
else:
# Material ...
stick.active_material = stick_material
stick_obj.select_set(True)
bpy.ops.object.shade_smooth()
list_group_sub.append(stick_obj)
if use_sticks_one_object == True:
if counter == use_sticks_one_object_nr:
bpy.ops.object.select_all(action='DESELECT')
for stick_select in list_group_sub:
stick_select.select_set(True)
bpy.ops.object.join()
list_group.append(bpy.context.view_layer.objects.active)
bpy.ops.object.select_all(action='DESELECT')
list_group_sub = []
counter = 0
else:
# Material ...
stick_obj.active_material = stick_material
if use_sticks_one_object == True:
bpy.ops.object.select_all(action='DESELECT')
@ -1184,7 +1229,7 @@ def draw_sticks_normal(all_atoms,
group.select_set(True)
bpy.ops.object.join()
bpy.ops.object.origin_set(type='ORIGIN_GEOMETRY',
center='MEDIAN')
center='MEDIAN')
sticks = bpy.context.view_layer.objects.active
sticks.active_material = stick_material
@ -1531,6 +1576,7 @@ def import_pdb(Ball_type,
object_center_vec,
Stick_diameter,
Stick_sectors,
Stick_dist,
use_sticks_smooth,
use_sticks_one_object,
use_sticks_one_object_nr,