I made molecular cubes using the in-built editor :

i took help from gifguide2code and gskielan wordpress blogs:

# LICENSE : USE FREELY IF CREDITTED
# (c) Abdur-Rahmaan Janhangeer
# https://abdurrahmaanjanhangeer.wordpress.com

from random import * # !
import bpy

x=y=z = 0

def makeMaterial(name, diffuse, specular, alpha):
    mat = bpy.data.materials.new(name)
    mat.diffuse_color = diffuse
    mat.diffuse_shader = 'LAMBERT'
    mat.diffuse_intensity = 1.0
    mat.specular_color = specular
    mat.specular_shader = 'COOKTORR'
    mat.specular_intensity = 0.5
    mat.alpha = alpha
    mat.ambient = 1
    return mat

def setMaterial(ob, mat):
    me = ob.data
    me.materials.append(mat)
    
def randMolCube(px,py):
    global x,y,z
    for i in range(200):
        red = makeMaterial('someNameHere',(random(),random(),random()),(1,1,1),1)
        bpy.ops.mesh.primitive_uv_sphere_add(location=(x,y,z))
        setMaterial(bpy.context.object, red)
        x = randint(px,px+5)
        y = randint(py,py+5)
        z = randint(0,5)

randMolCube(0,0)

in the randMolCube function, i kept z constant !

Note : i added a subdivision surface modifier and smooth shading in the pic above