Newer
Older
atom_mesh.update()
new_atom_mesh = bpy.data.objects.new(atom[0], atom_mesh)
bpy.context.scene.objects.link(new_atom_mesh)
# Now, build a representative sphere (atom)
current_layers=bpy.context.scene.layers
view_align=False, enter_editmode=False,
location=(0.0, 0.0, 0.0),
rotation=(0.0, 0.0, 0.0),
view_align=False, enter_editmode=False,
location=(0,0,0), rotation=(0.0, 0.0, 0.0),
layers=current_layers)
# UV balls
else:
bpy.ops.mesh.primitive_uv_sphere_add(
segments=Ball_azimuth, ring_count=Ball_zenith,
size=1, view_align=False, enter_editmode=False,
location=(0,0,0), rotation=(0, 0, 0),
ball.scale = (atom[3]*Ball_radius_factor,) * 3
if atom[0] == "Vacancy":
ball.name = "Cube_"+atom[0]
else:
ball.name = "Ball (NURBS)_"+atom[0]
ball.active_material = atom[1]
ball.parent = new_atom_mesh
new_atom_mesh.dupli_type = 'VERTS'
# The object is back translated to 'object_center_vec'.
new_atom_mesh.location = object_center_vec
atom_object_list.append(new_atom_mesh)
# ------------------------------------------------------------------------
# DRAWING THE STICKS
if use_stick == True and all_sticks != []:
# Create a new material with the corresponding color. The
# color is taken from the all_atom list, it is the last entry
# in the data file (index -1).
bpy.ops.object.material_slot_add()
stick_material = bpy.data.materials.new(ATOM_PDB_ELEMENTS[-1].name)
vertices = []
faces = []
dl = 0.2
i = 0
# For all sticks, do ...
for stick in all_sticks:
# What follows is school mathematics! :-)
v1 = all_atoms[stick.atom2-1].location
v2 = all_atoms[stick.atom1-1].location
# m = v1 - dv / 2.0 # UNUSED
p1 = g + n_b * Stick_diameter
p2 = g - n_b * Stick_diameter
p3 = g - n_b.cross(n) * Stick_diameter
p4 = g + n_b.cross(n) * Stick_diameter
vertices.append(p1)
vertices.append(p2)
vertices.append(p3)
vertices.append(p4)
faces.append((i*4+0,i*4+2,i*4+1,i*4+3))
mesh = bpy.data.meshes.new("Sticks")
mesh.from_pydata(vertices, [], faces)
mesh.update()
new_mesh = bpy.data.objects.new("Sticks", mesh)
bpy.context.scene.objects.link(new_mesh)
current_layers = bpy.context.scene.layers
stick_cylinder = DEF_atom_pdb_build_stick(Stick_diameter, dl, Stick_sectors)
stick_cylinder.active_material = stick_material
stick_cylinder.parent = new_mesh
new_mesh.dupli_type = 'FACES'
atom_object_list.append(new_mesh)
# ------------------------------------------------------------------------
# SELECT ALL LOADED OBJECTS
bpy.ops.object.select_all(action='DESELECT')
obj = None
for obj in atom_object_list:
obj.select = True
# activate the last selected object (perhaps another should be active?)
if obj:
bpy.context.scene.objects.active = obj
print("\n\nAll atoms (%d) and sticks (%d) have been drawn - finished.\n\n"
% (Number_of_total_atoms,Number_of_sticks))
return Number_of_total_atoms