How can I use for loop (or while loop) in python to move 50 objects with random beginning positions to specific positions I am a beginner of Blender. I want to use the blender to show how proteins form a microtubule. My code creates a piece of microtubule and some proteins on random positions. I want to put the random proteins on the microtubule.
My plan was using python to read the positions of my proteins and changing their positions to wherever I want, but the API is kind of confusing for me to read. I don't know how to express the 3D position of a random target in bpy.
Can someone please show me some material or the code to do this? Thank you very much.
import math
import bpy
from math import cos
from math import sin
from math import radians
from random import randint



#create random tubulins#
n=0
while n &lt; 36:
    x = randint(-3, 3)
    y = randint(-3, 3)
    z = randint(-3, 3)
    bpy.ops.mesh.primitive_cylinder_add(radius=0.12, depth=0.176, enter_editmode=False, location=(x,y,z))
    bpy.context.object.rotation_euler[0] = 1.5708
    n = n + 1

#create microtubule#
for j in range(0, 5):
    for i in range(0,12):
        bpy.ops.mesh.primitive_cylinder_add(radius=0.12, depth=0.176, enter_editmode=False, location=( 0.5*math.cos(math.radians(i*30)), 0.2*2*j, 0.5*math.sin(math.radians(i*30))))
        bpy.context.object.rotation_euler[0] = 1.5708
        
        





for l in range(0,12):
    for k in range(0,4):
        bpy.ops.mesh.primitive_cylinder_add(radius=0.12, depth=0.176, enter_editmode=False, location=( 0.5*math.cos(math.radians(l*30)), 0.2*(2*k+1), 0.5*math.sin(math.radians(l*30))))
        bpy.context.object.rotation_euler[0] = 1.5708






##add tubulins onto the microtubule, aka: adding key frames ##
 
for k in range(15):
    bpy.data.objects[k].select_set(True)
```
This script creates random points and mixes with points of helix. Here i used lerp() from mathutils to mix two points based on frame. You can replace helix points with vertices of cylinder.
import bpy
from random import randint
from mathutils import Vector
from math import sin, cos, pi

# create helix points
def helix(amount, radius, height, twist):
    points = []
    for i in range(amount):
        t = twist * 2 * pi * i/amount
        x = radius * sin(t)
        y = radius * cos(t)
        z = height * radius * t / amount
        points.append(Vector((x,y,z)))
    return points

# generate random points
def random_points(amount, min, max):
    randpoints = []
    for i in range(amount):
        x = randint(min, max)
        y = randint(min, max)
        z = randint(min, max)
        randpoints.append(Vector((x, y, z)))
    return randpoints
 
random_points = random_points(50, -3, 3)
final_points = helix(50, 0.2, 8, 8)

# get objects from collection
coll = bpy.data.collections.get(&quot;spheres&quot;)
objects = coll.objects

# clear previous animation data
for obj in objects:
    obj.animation_data_clear()
        
start = 1
end = 100
for f in range(start, end+1):    
    bpy.context.scene.frame_set(f)
    for i, obj in enumerate(objects):
        obj.scale = (0.1,0.1,0.1)
        obj.location = random_points[i].lerp(final_points[i], f/end) # vector1.lerp(vector2, factor)
        obj.keyframe_insert(&quot;location&quot;, frame = f) # insert location keyframe