Fixed branch for Blender 3.6 release #104626

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

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 # Start of project : 2011-08-31 by CB
# First publication in Blender : 2011-11-11 by CB # First publication in Blender : 2011-11-11 by CB
# Fusion of the PDB, XYZ and Panel : 2019-03-22 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 # Contributing authors
# ==================== # ====================

View File

@ -1100,6 +1100,7 @@ def draw_sticks_normal(all_atoms,
center, center,
Stick_diameter, Stick_diameter,
Stick_sectors, Stick_sectors,
Stick_dist,
use_sticks_smooth, use_sticks_smooth,
use_sticks_one_object, use_sticks_one_object,
use_sticks_one_object_nr, use_sticks_one_object_nr,
@ -1117,52 +1118,96 @@ def draw_sticks_normal(all_atoms,
list_group = [] list_group = []
list_group_sub = [] list_group_sub = []
counter = 0 counter = 0
for stick in all_sticks: for i, stick in enumerate(all_sticks):
# We treat here single, double and tripple bonds: stick.number <= 3
for repeat in range(stick.number):
# The vectors of the two atoms # The vectors of the two atoms
atom1 = all_atoms[stick.atom1-1].location-center atom1 = copy(all_atoms[stick.atom1-1].location)-center
atom2 = all_atoms[stick.atom2-1].location-center atom2 = copy(all_atoms[stick.atom2-1].location)-center
# Location
dist = Stick_diameter * Stick_dist
# 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 location = (atom1 + atom2) * 0.5
# The difference of both vectors
v = (atom2 - atom1)
# Angle with respect to the z-axis # Angle with respect to the z-axis
angle = v.angle(up_axis, 0) angle = dv.angle(up_axis, 0)
# Cross-product between v and the z-axis vector. It is the # Cross-product between v and the z-axis vector. It is the
# vector of rotation. # vector of rotation.
axis = up_axis.cross(v) axis = up_axis.cross(dv)
# Calculate Euler angles # Calculate Euler angles
euler = Matrix.Rotation(angle, 4, axis).to_euler() euler = Matrix.Rotation(angle, 4, axis).to_euler()
# Create stick # Create stick
stick = bpy.ops.mesh.primitive_cylinder_add(vertices=Stick_sectors, stick_obj = bpy.ops.mesh.primitive_cylinder_add(vertices=Stick_sectors,
radius=Stick_diameter, radius=Stick_diameter,
depth=v.length, depth=dv.length,
end_fill_type='NGON', end_fill_type='NGON',
align='WORLD', align='WORLD',
enter_editmode=False, enter_editmode=False,
location=location, location=location,
rotation=(0, 0, 0)) rotation=(0, 0, 0))
# Put the stick into the scene ... # Put the stick into the scene ...
stick = bpy.context.view_layer.objects.active stick_obj = bpy.context.view_layer.objects.active
# ... and rotate the stick. # ... and rotate the stick.
stick.rotation_euler = euler stick_obj.rotation_euler = euler
# ... and name # ... and name
stick.name = "Stick_Cylinder" 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 counter += 1
# Smooth the cylinder. # Smooth the cylinder.
if use_sticks_smooth == True: if use_sticks_smooth == True:
bpy.ops.object.select_all(action='DESELECT') bpy.ops.object.select_all(action='DESELECT')
stick.select_set(True) stick_obj.select_set(True)
bpy.ops.object.shade_smooth() bpy.ops.object.shade_smooth()
list_group_sub.append(stick) list_group_sub.append(stick_obj)
if use_sticks_one_object == True: if use_sticks_one_object == True:
if counter == use_sticks_one_object_nr: if counter == use_sticks_one_object_nr:
bpy.ops.object.select_all(action='DESELECT') bpy.ops.object.select_all(action='DESELECT')
for stick in list_group_sub: for stick_select in list_group_sub:
stick.select_set(True) stick_select.select_set(True)
bpy.ops.object.join() bpy.ops.object.join()
list_group.append(bpy.context.view_layer.objects.active) list_group.append(bpy.context.view_layer.objects.active)
bpy.ops.object.select_all(action='DESELECT') bpy.ops.object.select_all(action='DESELECT')
@ -1170,7 +1215,7 @@ def draw_sticks_normal(all_atoms,
counter = 0 counter = 0
else: else:
# Material ... # Material ...
stick.active_material = stick_material stick_obj.active_material = stick_material
if use_sticks_one_object == True: if use_sticks_one_object == True:
bpy.ops.object.select_all(action='DESELECT') bpy.ops.object.select_all(action='DESELECT')
@ -1531,6 +1576,7 @@ def import_pdb(Ball_type,
object_center_vec, object_center_vec,
Stick_diameter, Stick_diameter,
Stick_sectors, Stick_sectors,
Stick_dist,
use_sticks_smooth, use_sticks_smooth,
use_sticks_one_object, use_sticks_one_object,
use_sticks_one_object_nr, use_sticks_one_object_nr,