Blender 2.81 for N-body simulations: read file and set up frame per frame

Hey!

I’m pretty new to Blender and I’m trying to animate some N-body simulations for one of my courses. Using octrees the coordinates for every star and timestep are written to a file like this:

x1 y1 z1 x2 y2 z2 ...
...

So each line is a frame on itself.
The script I’ve written so far is


import bpy
import bmesh
import numpy as np

N = 3
r = 0.2
scale = 10 ** 11

file = '/home/Documents/test.txt'

data = np.loadtxt(file)

bpy.ops.object.select_all(action='DESELECT')
bpy.ops.mesh.primitive_uv_sphere_add(radius=r)
sphere = bpy.context.object

def makeSphere(x,y,z):
    ob = sphere.copy()
    ob.location.x = x
    ob.location.y = y
    ob.location.z = z

    bpy.context.collection.objects.link(ob)

for row in data:
    for i in range(0, N):
        x = row[3*i]
        y = row[3*i+1]
        z = row[3*i+2]
        makeSphere(scale * x, scale * y, scale * z)

    bpy.context.view_layer.update()

fullpath = '/home/Documents/finalObject.obj'

print("Exporting OBJ");

bpy.ops.export_scene.obj(filepath=fullpath)

But it looks like it just makes all spheres instantaneously at the origin…
It’s actually hard to find any information about such “simple” read ins, especially in Blender 2.81…

Can someone help me with this? Later I would also like to define my own material = star and having a black space as set up.

Thank you for your time!