Визуализации молекул в Blender

  1. from math import degrees, acos
  2. from mathutils import Vector
  3.  
  4. spheres = (Vector((2,3,3)),Vector((1,1,2)),Vector((2,3,4)),Vector((4,5,3)))
  5. edges = ((0,1),(1,2),(2,3))
  6.  
  7. for i in range(0, len(spheres)):
  8.     r1 = spheres[i]
  9.     bpy.ops.mesh.primitive_uv_sphere_add(location=(r1.x, r1.y, r1.z))
  10.  
  11. for i in range(0,len(edges)):
  12.      r1 = spheres[edges[i][0]]
  13.      r2 = spheres[edges[i][1]]
  14.      r3 = (r1+r2)/2
  15.      z = Vector((0,0,1))
  16.      z_desired = (r1-r2).normalized()
  17.      rot_axis = z.cross(z_desired)
  18.      angle = acos(z.dot(z_desired))
  19.      bpy.ops.mesh.primitive_cylinder_add(radius=0.3, depth=(r2-r1).length,location=(r3.x,r3.y,r3.z))
  20.      bpy.ops.transform.rotate(value=(angle,), axis=rot_axis)
Скрипт построения в блендере парочки молекул :gg:

Реклама

Мы в соцсетях

tw tg yt gt