def bind_phosphorus(frame, size): """ Animating the process of phosfor binding to the Tyr """ phosphorus_model = Texture(Pigment('color', [1, 0, 1], ), Finish('reflection', 0)) text_model = Texture(Pigment('color', [1, 1, 0], ), Finish('reflection', 0)) phosphorus = [] s = size # frame 480 -> 570 x_locs = [[-20, -5], [20, 5], [-20, -5], [20, 5]] y_locs = [13, 13, 10, 10] for _ in range(4): if frame < 570: x = (frame - 480) * ((x_locs[_][1]*s - x_locs[_][0]*s) / 90) + x_locs[_][0]*s y = 0 - y_locs[_] * s else: x = x_locs[_][1]*s y = 0 - y_locs[_]*s phosphorus.append(Sphere([x, y, 2], s * 1.2, phosphorus_model)) phosphorus.append(Text('ttf', '"timrom.ttf"', '"{}"'.format(str('P')), 0.5, [0, 0, 0], text_model, 'scale', 7, 'translate', [x - 0.2*s, y-0.5*s, -1.5*s])) return phosphorus
def bind_schematic(frame, size): """ Animating the binding part schematicly """ insuline_model = Texture(Pigment('color', [0, 1, 0.5], ), Finish('reflection', 0)) text_model = Texture(Pigment('color', [1, 1, 0], ), Finish('reflection', 0)) insuline = [] s = size # frame 30 -> 120 if frame < 120: x = (frame - 30) * (24.5*s / 90) - 30*s y = (frame - 30) * (-15*s / 90) + 20*s else: x = -5*s y = 5*s insuline.append(Sphere([x, y, 0], s * 1.5, insuline_model)) insuline.append(Text('ttf', '"timrom.ttf"', '"{}"'.format(str('Insulin')), 0.5, [0, 0, 0], text_model, 'scale', 5, 'translate', [x - s, y-0.5*s, -2*s])) insuline.append(Sphere([0-x, y, 0], s * 1.5, insuline_model)) insuline.append(Text('ttf', '"timrom.ttf"', '"{}"'.format(str('Insulin')), 0.5, [0, 0, 0], text_model, 'scale', 5, 'translate', [0-x -1.4*s, y-0.5*s, -2*s])) return insuline
def scene(step): ''' Returns the scene at step number (1 step per frame) ''' A = np.array([-10, 8, 0]) B = np.array([5, 2, -20]) # Find a point with distance 3 from A BA = B-A # Vector B->A d = math.sqrt(sum(np.power(BA, 2))) # distance BA = BA / d # Normalize by its length; BA / ||BA|| scale = 4 N = A + scale * BA # Scale and add to A l = Cylinder(A, B, 0.05, Pigment('color', [0, 1, 0])) s1 = Sphere(N, 0.5, Texture(Pigment('color', [0.9, 0.05, 0.05]))) scale = 15 N = A + scale * BA # Scale and add to A s2 = Sphere(N, 0.5, Texture(Pigment('color', [0.9, 0.05, 0.05]))) scale = 24 N = A + scale * BA # Scale and add to A s3 = Sphere(N, 0.5, Texture(Pigment('color', [0.9, 0.05, 0.05]))) return Scene(povray.floor_camera, objects=[povray.default_light, povray.checkered_ground, l, s1, s2, s3], included=['colors.inc'])
def frame(step): """ Creates a frame of 4 cones, 4 boxes, 1 sphere and a legend """ # Define textures for different models sphere_model = Texture(Pigment('color', [1, 0, 1], ), Finish('reflection', 0.5)) box_model = Texture(Pigment('color', [0, 1, 1], ), Finish('reflection', 0)) cone_model = Texture(Pigment('color', [1, 0, 1], ), Finish('reflection', 0)) # Create objects sphere = Sphere([0, 0, 0], 3, sphere_model) box_1 = Box([-5, -5, -4], [-3, 5, 4], box_model) box_2 = Box([3, -5, -4], [5, 5, 4], box_model) box_3 = Box([-5, 4, -4], [5, 6, 4], box_model) box_4 = Box([-5, -5, -4], [5, -3, 4], box_model) cone_1 = Cone([0, 6, 0], 3, [0, 10, 0], 0, cone_model) cone_2 = Cone([0, -6, 0], 3, [0, -10, 0], 0, cone_model) cone_3 = Cone([-5, 0, 0], 3, [-9, 0, 0], 0, cone_model) cone_4 = Cone([5, 0, 0], 3, [9, 0, 0], 0, cone_model) light_1 = LightSource([0, 10, -25], 'color', [1, 1, 1]) light_2 = LightSource([0, 8, -7], 'color', [1, 1, 1]) xyz_legend = legend([-15, 0, 0], 5) camera = Camera('location', [0, 7, -30], 'look_at', [0, 2, 1]) # Return the Scene object for rendering return Scene(camera, objects=[sphere, box_1, box_2, box_3, box_4, cone_1, cone_2, cone_3, cone_4, light_1, light_2] + xyz_legend)
def legend(loc, length): """ Creates a legend in a given location. Usage: legend([x, y, z], length) """ # Defining textures for each axis x_model = Texture(Pigment( 'color', [1, 0, 0], ), Finish('reflection', 0)) z_model = Texture(Pigment( 'color', [0, 0, 1], ), Finish('reflection', 0)) y_model = Texture(Pigment( 'color', [0, 1, 0], ), Finish('reflection', 0)) # Create objects x_cyl = Cylinder(loc, [loc[0] + length, loc[1], loc[2]], 0.1, x_model) x_cone = Cone([loc[0] + length, loc[1], loc[2]], 0.3, [loc[0] + length + 1, loc[1], loc[2]], 0, x_model) z_cyl = Cylinder(loc, [loc[0], loc[1], loc[2] + length], 0.1, y_model) z_cone = Cone([loc[0], loc[1], loc[2] + length], 0.3, [loc[0], loc[1], loc[2] + length + 1], 0, y_model) y_cyl = Cylinder(loc, [loc[0], loc[1] + length, loc[2]], 0.1, z_model) y_cone = Cone([loc[0], loc[1] + length, loc[2]], 0.3, [loc[0], loc[1] + length + 1, loc[2]], 0, z_model) return [x_cyl, x_cone, y_cyl, y_cone, z_cyl, z_cone]
def frame(step): """ Creates a sphere and 4 boxes, places this in a scene """ lichtje = LightSource([2, 8, -5], 5.0) default_camera = Camera('location', [0, 4, -40], 'look_at', [0, 2, -5]) stylebox = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) boxright = Box([3, -2, -3], [5, 6, 4], stylebox) boxleft = Box([-5, -2, -3], [-3, 6, 4], stylebox) boxupper = Box([-5, 6, -3], [5, 8, 4], stylebox) boxbottom = Box([-5, -4, -3], [5, -2, 4], stylebox) styleball = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7)) centerball = Sphere([0, 2, 0], 3, styleball) conetop = Cone([0, 8, 0], 3, [0, 12, 0], 0, stylebox) conebottom = Cone([0, -4, 0], 3, [0, -8, 0], 0, stylebox) coneleft = Cone([-5, 2, 0], 3, [-11, 2, 0], 0, stylebox) coneright = Cone([5, 2, 0], 3, [11, 2, 0], 0, stylebox) # Return the Scene object for rendering return Scene(default_camera, objects=[ lichtje, centerball, boxright, boxleft, boxupper, boxbottom, conetop, conebottom, coneleft, coneright ])
def main(): lookfrom = (13 / 1.5, 2 / 1.5, -5 / 1.5) lookat = (0, 0, 0) # dist_to_focus = 10.0 # aperture = 0.1 step = 1 # camera camera = Camera('location', lookfrom, 'look_at', lookat) # background light = LightSource((0, 20, 0), 'color', (1, 1, 1)) bg = Background('color', (0.5, 0.7, 1.0)) base = Sphere((0, -1000, 0), 1000, Texture(Pigment('color', (0.5, 0.5, 0.5)))) htlist = [bg, base, light] for a in range(-11, 11, step): for b in range(-11, 11, step): choose_mat = random.random() center = (a + 0.9 * random.random(), 0.2, b + 0.9 * random.random()) if distance(center, (4, 0.2, 0)) < 0.9: continue if choose_mat < 0.8: # diffuse color = (random.random() * random.random(), random.random() * random.random(), random.random() * random.random()) htlist.append( Sphere(center, 0.2, Texture(Finish('diffuse', 1), Pigment('color', color)))) elif choose_mat < 0.95: # metal color = (0.5 * (1 + random.random()), 0.5 * (1 + random.random()), 0.5 * (1 + random.random())) # p1 = 0.5 * random.random() htlist.append( Sphere(center, 0.2, Texture(Finish('Metal'), Pigment('color', color)))) else: # glass htlist.append(Sphere(center, 0.2, Material('M_Glass'))) # main 3 sphere htlist.append( Sphere((0, 1, 0), 1.0, Material('M_Glass'))) htlist.append( Sphere((-4, 1, 0), 1.0, Texture(Finish('diffuse', 1), Pigment('color', (0.4, 0.2, 0.2))))) htlist.append(Sphere((4, 1, 0), 1.0, Texture('Chrome_Texture'))) scene = Scene(camera, objects=htlist, included=[ 'metals.inc', 'glass.inc', 'textures.inc', 'colors.inc']) with open("where-next.pov", "w") as ofp: print(str(scene), file=ofp) scene.render('where-next.png', width=800, height=600, antialiasing=0.1, quality=10)
def make_membrane(loc, amount, size=5): """ Create the membrane and returns the object """ sphere_model = Texture(Pigment('color', [1, 0, 0], ), Finish('reflection', 0)) cyl_model = Texture(Pigment('color', [0.7, 0.3, 0], ), Finish('reflection', 0)) x_position = loc[0] y_position = loc[0] - size * 6 objects = [] for index in range(1, amount + 1): # Create top spheres objects.append(Sphere([x_position, loc[1], loc[2]], size, sphere_model)) objects.append(Sphere([0 - x_position, loc[1], loc[2]], size, sphere_model)) # Create top cylinders location = [x_position - size/3, loc[1], loc[2]], [x_position - size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [x_position + size/3, loc[1], loc[2]], [x_position + size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position - size/3, loc[1], loc[2]], [0-x_position - size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position + size/3, loc[1], loc[2]], [0-x_position + size/3, loc[1] - size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) # Create bottom spheres objects.append(Sphere([x_position, y_position, loc[2]], size, sphere_model)) objects.append(Sphere([0 - x_position, y_position, loc[2]], size, sphere_model)) # Create bottom cylinders location = [x_position - size/3, y_position, loc[2]], [x_position - size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [x_position + size/3, y_position, loc[2]], [x_position + size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position - size/3, y_position, loc[2]], [0-x_position - size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) location = [0-x_position + size/3, y_position, loc[2]], [0-x_position + size/3, y_position + size*2.5, loc[2]] objects.append(Cylinder(location[0], location[1], size/6, cyl_model)) x_position += size * 2 return objects
def scene(step): # Storing the cylinders cylinders = [] n = 7 for i in range(n): cylinders.append( Cylinder([0, 0, 0], [1.2, 0, 0], 1.0, 1.0, 'scale', [1, 0.25, 1], 'rotate', [-30, 0, 0], 'translate', [1.25, 0, 0], 'rotate', [0, i * 360 / n, 0], Texture('Chrome_Texture'), Pigment('color', [0.1, 0.1, 0.1]), Finish('phong', 1, 'reflection', 1))) # Reset color for the center sphere degrees = (360 / (SETTINGS.Duration * SETTINGS.RenderFPS)) * step prop = Blob( 'threshold', 0.65, # Add a Sphere with radius and strength = 1 Sphere( [0, 0, 0], 1.00, 1.00, # Double the heigth of the Sphere 'scale', [1, 2, 1], # Make it shine Texture('Chrome_Texture', Pigment('color', [0.1, 0.1, 0.1]), Finish('phong', 0.5, 'reflection', 0.5))), # unpack cylinders *cylinders, # Scale the whole objects (enlarge) 'scale', 1.8, # rotate counter-clockwise 'rotate', [90, 0, degrees], # re-center 'translate', [0, 0.5, 0]) camera = Camera('location', [5, 10, -8], 'look_at', [0, 0, 0]) xyz_legend = legend([-10, 0, 0], 3) return Scene( camera, objects=[prop] + xyz_legend + povray.default_spots, # The 'Chrome_Texture comes from the 'textures.inc' file included=['textures.inc'])
def make_receptor(loc, size=5): """ Creates the receptor and returns the object """ rec_model = Texture(Pigment('color', [0, 1, 1], ), Finish('reflection', 0)) x = loc[0] y = loc[1] z = loc[2] rec = list() rec.append(Cylinder([x - size * 1.2, y - size * 15, z], [x - size * 1.2, y + size*2, z], size, rec_model)) rec.append(Cylinder([x + size * 1.2, y - size * 15, z], [x + size * 1.2, y + size*2, z], size, rec_model)) rec.append(Cylinder([x - size * 1.2, y + size * 1.2, z], [x - size * 5, y + size * 4, z], size, rec_model)) rec.append(Cylinder([x - size * 7.2, y + size * 4, z - size/2], [x - size * 3.2, y + size * 4, z - size/2], size / 1.321, rec_model)) rec.append(Cylinder([x + size * 1.2, y + size * 1.2, z], [x + size * 5, y + size * 4, z], size, rec_model)) rec.append(Cylinder([x + size * 7.2, y + size * 4, z - size/2], [x + size * 3.2, y + size * 4, z - size/2], size / 1.321, rec_model)) rec.append(Sphere([x, y - size * 6, z], size * 3, rec_model)) return rec
def frame(step): curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) nframes = eval(SETTINGS.NumberFrames) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, style) sphere = Sphere([6, 2, -2], 3, style) leg = legend([-15, 0, 0], 5) radius = 25 z_start = -25 x_start = 0 alpha = (-pi / 2) + (step * 2 * pi / nframes) x_coord = radius * cos(alpha) z_coord = radius * sin(alpha) x = x_start + x_coord z = z_start - z_coord camera_x = 0 camera_z = -25 # x gaat links en rechts en z verder de diepte in en terug -25? camera = Camera('location', [camera_x, 8, camera_z], 'look_at', [0, 0, 0]) return Scene( camera, objects=[ cylinder, sphere, models.default_light, models.checkered_ground ] + shapes, included=['colors.inc'])
def frame(step): """ Returns the scene at step number (1 step per frame) """ curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) nframes = eval(SETTINGS.NumberFrames) n_frames_loop = nframes / 5 # 16 frames per wave stylebox = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) x_start = -10 x_end = 10 x_distance = x_end - x_start distance_per_frame = x_distance / nframes y_start = 0 y_end = 4 y_distance = y_end - y_start y_distance_per_frame = y_distance / n_frames_loop iteratie = step // n_frames_loop x_coord = x_start + step * distance_per_frame correctie = iteratie * n_frames_loop print(iteratie) step = step - correctie if step <= (n_frames_loop / 2): y_coord = y_start + step * y_distance_per_frame else: y_coord = y_end - step * y_distance_per_frame box = Box([x_coord, y_coord, 0], [x_coord + 2, y_coord + 2, 2], stylebox) return Scene(models.default_camera, objects=[box, models.default_ground, models.default_light])
def frame(step): """ Returns the scene at step number (1 step per frame) """ # Show some information about how far we are with rendering curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) # Getting the total number of frames, see the configuration file nframes = eval(SETTINGS.NumberFrames) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, style) sphere = Sphere([6, 2, -2], 3, style) leg = legend([-15, 0, 0], 5) radius = 25 z_start = 0 x_start = 0 #werkt allbei # alpha = (-pi/2) + (step * 2 * pi / nframes) alpha = pi / (nframes / 2) * step + 1 x_coord = radius * cos(alpha) z_coord = radius * sin(alpha) x = x_start + x_coord z = z_start - z_coord return Scene( Camera('location', [x, 8, z], 'look_at', [0, 0, 0]), objects=[ models.checkered_ground, models.default_light, cylinder, sphere ] + leg)
def legend(start_position, axis_length): """ Legend function for calling importable legend""" # Reduce the AXIS_LENGTH by the length of the Cone (1) so that # the total length is exactly the AXIS_LENGTH axis_length -= 1 # Initialize the Cylinder END-position to a COPY of the start position cylinder_coords_end = { 'x': list(start_position), 'y': list(start_position), 'z': list(start_position) } # Add the AXIS_LENGTHs to the corresponding coordinate cylinder_coords_end['x'][0] += axis_length cylinder_coords_end['y'][1] += axis_length cylinder_coords_end['z'][2] += axis_length # creation of the Cylinders style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) linex = Cylinder(start_position, cylinder_coords_end['x'], 0.1, style) liney = Cylinder(start_position, cylinder_coords_end['y'], 0.1, style) linez = Cylinder(start_position, cylinder_coords_end['z'], 0.1, style) cylinders = {'x': linex, 'y': liney, 'z': linez} # Cone START is the same as the Cylinder END, so we COPY these lists cones_coords_start = { 'x': list(cylinder_coords_end['x']), 'y': list(cylinder_coords_end['y']), 'z': list(cylinder_coords_end['z']) } # Copy the START as END coordinate cones_coords_end = { 'x': list(cones_coords_start['x']), 'y': list(cones_coords_start['y']), 'z': list(cones_coords_start['z']) } # Extend the tip of the cones with length 1 cones_coords_end['x'][0] += 1 cones_coords_end['y'][1] += 1 cones_coords_end['z'][2] += 1 # Creation of the Cones conex = Cone(cones_coords_start['x'], 0.5, cones_coords_end['x'], 0, style) coney = Cone(cones_coords_start['y'], 0.5, cones_coords_end['y'], 0, style) conez = Cone(cones_coords_start['z'], 0.5, cones_coords_end['z'], 0, style) cones = {'x': conex, 'y': coney, 'z': conez} # Add ALL objects to a LIST and return legend_objects = list(cylinders.values()) + list(cones.values()) return legend_objects
def frame(step): """ Returns the scene at step number (1 step per frame) """ curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) nframes = eval(SETTINGS.NumberFrames) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, style) sphere = Sphere([6, 2, -2], 3, style) leg = legend([-15, 0, 0], 5) radius = 25 z_start = 0 x_start = 0 alpha = (-pi / 2) + (step * 2 * pi / nframes) # For each step, de difference in the x and z positions is equal to the radius time the sin and cos of alpha. x_coord = radius * cos(alpha) z_coord = radius * sin(alpha) # Adding or subtracting the difference of the position for each step from the original camera position. x = x_start + x_coord z = z_start - z_coord return Scene( Camera('location', [x, 8, z], 'look_at', [0, 0, 0]), objects=[ models.checkered_ground, models.default_light, cylinder, sphere ] + leg)
def make_tyrine(loc, size): """ Creates the tyrine molecules """ text_model = Texture(Pigment('color', [1, 1, 0], ), Finish('reflection', 0)) cyl_model = Texture(Pigment('color', [0, 1, 0.5], ), Finish('reflection', 0)) tyr = [] y_always = [13, 13, 10, 10] x_text = [-3, 5, -3, 5] x_end = [-5, 5, -5, 5] x = loc[0] y = loc[1] z = loc[2] + 7 for _ in range(4): tyr.append(Cylinder([x, y-size * y_always[_], z], [x-size*x_end[_], y-size*y_always[_], z], size, cyl_model)) text = Text('ttf', '"timrom.ttf"', '"{}"'.format(str('Tyr')), 2, [0, 0, 0], text_model, 'scale', 5, 'translate', [x-size*x_text[_], y-size*y_always[_], z - 7]) tyr.append(text) return tyr
def save_frame_image(self, path): meshes = [Background("color", [self.bk_r, self.bk_g, self.bk_b])] tex = Texture(Pigment('color', [self.cc_r, self.cc_g, self.cc_b]), Finish('specular', self.specular)) texo = Texture(Pigment('color', [self.cco_r, self.cco_g, self.cco_b]), Finish('specular', self.specularo)) for i in xrange(-1, self.expert.nr_obstacles_c()): vss, nss, iss = self.save_frame_mesh(i) meshes += [ClothMesh(vss, iss, nss, tex if i == -1 else texo)] #render scene = Scene(Camera('location', [self.cx, self.cy, self.cz], 'sky', [self.ux, self.uy, self.uz], 'look_at', [self.fx, self.fy, self.fz], 'right', [1, 0, 0], 'up', [0, -1, 0], 'angle', self.fovy), objects=self.lights + meshes) scene.render(path, width=self.w, height=self.h, antialiasing=self.aa if hasattr(self, "aa") else 0.0)
def rdmb_povray_save(out_file, vs, ucs, vcs, width=800, height=600, rotx=0, roty=0, rotz=0, angle=14): """Render and save RD results using Pov-Ray Render and save RD results using Pov-Ray Args: out_file: output file vs: vertices ucs, vcs: u/v conc. width, height: width and height of output image rotx, roty, rotz: rotation angle angle: camera angle """ ucmax = 6.0 ucs = ucs / ucmax ucs[ucs > 1.0] = 1.0 # ucs = ucs / np.max(ucs) rot1 = [rotx, 0, 0] rot2 = [0, roty, 0] rot3 = [0, 0, rotz] camera = Camera('location', [0, 0, -25], 'look_at', [0, 0, 0], 'angle', angle, 'right x*image_width/image_height') light = LightSource([-3, 2, -6], 'color', [1.0, 1.0, 1.0], 'parallel') light2 = LightSource([2, -2, -6], 'color', [0.6, 0.6, 0.6], 'parallel') background = Background('color', [1, 1, 1, 1]) spheres = [Sphere(v, 0.02, Finish('ambient', 0.2, 'diffuse', 0.8, 'phong', 1.0), Texture(Pigment('color', [0.3+uc*0.7, 0.2+uc*0.8, 0.2+uc*0.8])), 'rotate', rot1, 'rotate', rot2, 'rotate', rot3) for v, uc in zip(vs, ucs)] objects = [light, light2, background] + spheres scene = Scene(camera, objects=objects) scene.render(out_file, width=width, height=height, output_alpha=True, antialiasing=0.001, tempfile=out_file+"__temp__.pov")
def sphere_circle(): """ Creates a circle made up of 20 small spheres. A list of Sphere objects is returnded ready for rendering. """ spheres = 20 # number of spheres to create ring = [] ring_node_size = 0.6 smodel = Texture(Pigment('color', [1, 0, 0], 'filter', 0.5), Finish('phong', 0.8, 'reflection', 0.5)) for i in range(spheres): ring.append(Sphere([0, 0, 0], ring_node_size, smodel, 'translate', [RADIUS, 0, 0], 'rotate', [0, 360/spheres * i, 0])) return ring
def bind_IRS(frame, size): """ Animating the process of IRS binding to the phosfor """ IRS_model = Texture(Pigment('color', [1, 0, 1], ), Finish('reflection', 0)) text_model = Texture(Pigment('color', [1, 1, 0], ), Finish('reflection', 0)) IRS = [] s = size # frame 570 -> 630 if frame < 630: x = (frame - 570) * ((7*s-30*s) / 60) + 30*s y = -12*s else: x = 7*s y = -12*s IRS.append(Sphere([x, y, 0], s * 2, IRS_model)) IRS.append(Text('ttf', '"timrom.ttf"', '"{}"'.format(str('IRS')), 0.5, [0, 0, 0], text_model, 'scale', 5, 'translate', [x - s, y, -2*s])) return IRS
def frame(step): """ Creates the objects and places this in a scene """ # Creates the lines in each directions x_cylinder = Cylinder([-15, 0, 0], [-10, 0, 0], 0.1, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))) y_cylinder = Cylinder([-15, 0, 0], [-15, 5, 0], 0.1, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))) z_cylinder = Cylinder([-15, 0, 0], [-15, 0, 5], 0.1, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))) # Creates the arrows of each directions x_cone = Cone([-10, 0, 0], 0.3, [-9, 0, 0], 0, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))) y_cone = Cone([-15, 5, 0], 0.3, [-15, 6, 0], 0, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))) z_cone = Cone([-15, 0, 5], 0.3, [-15, 0, 6], 0, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))) # Return the Scene object for rendering return Scene(models.default_camera, objects=[LightSource([2, 8, -20], 2), x_cylinder, y_cylinder, z_cylinder, x_cone, y_cone, z_cone])
def render_povray(vs, rotx=0, roty=0, rotz=0, width=400, height=400, angle=14, antialiasing=0.001): """Render vertices using Pov-Ray (Vapory) Render vertices using Pov-Ray (Vapory) Args: vs: vertices rotx, roty, rotz: rotation angle width, height: angle: camera angle Returns: rendered_scene: """ rot1 = [rotx, 0, 0] rot2 = [0, roty, 0] rot3 = [0, 0, rotz] camera = Camera('location', [0, 0, -25], 'look_at', [0, 0, 0], 'angle', angle, 'right x*image_width/image_height') light = LightSource([-3, 2, -6], 'color', [1.0, 1.0, 1.0], 'parallel') light2 = LightSource([2, -2, -6], 'color', [0.6, 0.6, 0.6], 'parallel') background = Background('color', [1, 1, 1]) spheres = [Sphere(v, 0.05, Finish('ambient', 0.2, 'diffuse', 0.8, 'phong', 1.0), Texture(Pigment('color', [1.0, 1.0, 1.0])), 'rotate', rot1, 'rotate', rot2, 'rotate', rot3) for v in vs] objects = [light, light2, background] + spheres scene = Scene(camera, objects=objects) return scene.render('ipython', width=width, height=height, antialiasing=antialiasing)
def render_frame(self, step, outn): particles = [] for i in range(self.sm.NUM_PARTICLES): clr = speed2color(speed=self.speeds[step][i], speed_limit=self.maxspeed, alpha=False) p = Sphere( [ self.r_vecs[step][i][1], self.r_vecs[step][i][2], self.r_vecs[step][i][0] ], self.sm.RADIUS_PARTICLE, Texture(Pigment("color", clr)), ) particles.append(p) self.scene = Scene(self.camera, objects=self.objects + particles) self.scene.render(f"{self.sm.png_path}/img{outn:06}.png", width=600, height=400)
def frame(step): lichtje = LightSource([2, 8, -5], 5.0) default_camera = Camera('location', [-5, 8, -20], 'look_at', [-5, 0, -5]) style = Texture(Pigment('color', [0.80, 0.00, 1.00], 'filter', 0.7), Finish('phong', 0.6, 'reflection', 0.4)) linex = Cylinder([-15, 0, 0], [-10, 0, 0.5],0.1, style) liney = Cylinder([-15, 0, 0], [-15, 5, 0.2],0.1, style) linez = Cylinder([-15, 0, 0], [-15, 0.2, 5],0.1, style) conex = Cone([-10, 0, 0.5], 0.5, [-9, 0, 0.5], 0, style) coney = Cone([-15, 5, 0], 0.5, [-15, 6, 0], 0, style) conez = Cone([-15, 0, 5], 0.5, [-15, 0, 6], 0, style) # Return the Scene object for rendering return Scene(default_camera, objects=[lichtje,linex,liney,linez,conex,coney,conez])
def frame(step): """ Returns the scene at step number (1 step per frame) """ sphere_model = Texture(Pigment( 'color', [250, 0, 0], ), Finish('reflection', 0.5)) # Show some information about how far we are with rendering curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) # Getting the total number of frames, see the configuration file nframes = eval(SETTINGS.NumberFrames) # Start- and end-points x_start = -5 x_end = 5 distance = x_end - x_start # Calculate distance to move at each step distance_per_frame = (distance / nframes) * 2 # Calculate new x-coordinate if step < (nframes / 2): # Move from left to right (starting at x = -10) x_coord = x_start + step * distance_per_frame else: # Move from right to left (starting at x = 10) x_coord = x_end - (step - (nframes / 2)) * distance_per_frame y_coord = 2 * math.sin((2 * math.pi / 2) * (x_coord - 1)) + 0.5 # Create sphere at calculated x-coordinate using default model sphere = Sphere([x_coord, y_coord, 0], 1, sphere_model) # Return the Scene object containing all objects for rendering return Scene(models.default_camera, objects=[sphere, models.default_light])
def frame(step): """ """ # Feedback to user in terminal about render status curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime) logger.info(" @Time: %.3fs, Step: %d", curr_time, step) # Calculates the total frames n_frames = eval(SETTINGS.NumberFrames) full_circle = 2 * pi # One full circle equals exactly 2 times pi # obtain molecules from function create_molecules() step_in_frame = step two_fifth_of_animation = n_frames // 5 * 2 three_fifth_of_animation = n_frames // 5 * 3 VESICLE = Sphere([100, 0, 0], 20, Texture(Pigment('color', [0.7, 1, 1], 'filter', 0.6), Finish('phong', 0.4, 'reflection', 0.2))) camera_z = -100 # Creation of RNA molecule if step in range(0, two_fifth_of_animation): create_first_part(step_in_frame, two_fifth_of_animation + 1) # Sphere covering the RNA molecule if step in range(two_fifth_of_animation, three_fifth_of_animation + 1): NUCL_1.move_offset([50, 0, 0]) NUCL_2.move_offset([50, 0, 0]) NUCL_3.move_offset([50, 0, 0]) NUCL_4.move_offset([50, 0, 0]) NUCL_5.move_offset([50, 0, 0]) NUCL_6.move_offset([50, 0, 0]) NUCL_7.move_offset([50, 0, 0]) step_in_frame = step - two_fifth_of_animation x_start = 100 x_end = -50 distance_x = x_end - x_start distance_per_frame_x = (distance_x / three_fifth_of_animation) * 2 x_coord = x_start + step_in_frame * distance_per_frame_x y_coord = 2 * sin(x_coord/5) print(y_coord) VESICLE = Sphere([x_coord, y_coord, 0], 20, Texture(Pigment('color', [0.7, 1, 1], 'filter', 0.6), Finish('phong', 0.4, 'reflection', 0.2))) # Vesicle growth if step in range(n_frames // 5 * 3, n_frames // 5 * 4 + 1): NUCL_1.move_offset([50, 0, 0]) NUCL_2.move_offset([50, 0, 0]) NUCL_3.move_offset([50, 0, 0]) NUCL_4.move_offset([50, 0, 0]) NUCL_5.move_offset([50, 0, 0]) NUCL_6.move_offset([50, 0, 0]) NUCL_7.move_offset([50, 0, 0]) VESICLE = Sphere([0, 0, 0], 20, Texture(Pigment('color', [0.7, 1, 1], 'filter', 0.6), Finish('phong', 0.4, 'reflection', 0.2))) # camere movement if step in range(n_frames // 5 * 3, n_frames // 5 * 4 // 2): camera_z_start = -100 camera_z_end = -150 distance_camera_z = camera_z_end - camera_z_start z_camera_coord = step_in_frame * distance_per_frame - camera_z_start # # Sphere division # if step in range(n_frames // 5 * 4, n_frames): # Return the Scene object for rendering return Scene(Camera('location', [0, 0, camera_z], 'look_at', [0, 0, 0]), objects=[models.default_light, VESICLE] + NUCL_1.povray_molecule + NUCL_2.povray_molecule + NUCL_3.povray_molecule + NUCL_4.povray_molecule + NUCL_5.povray_molecule + NUCL_6.povray_molecule + NUCL_7.povray_molecule)
def legend(start_position, axis_length): """ Returns the objects of a legend :param start_position: the position where the legend is rendered :param axis_length: the length of each line+arrow in the x, y and z direction :return legend_objects: the objects of a legend """ # Reduce the AXIS_LENGTH by the length of the Cone (1) so that # the total length is exactly the AXIS_LENGTH axis_length -= 1 # Initialize the Cylinder END-position to a COPY of the start position cylinder_coords_end = { 'x': list(start_position), 'y': list(start_position), 'z': list(start_position) } # Add the AXIS_LENGTHs to the corresponding coordinate cylinder_coords_end['x'][0] += axis_length cylinder_coords_end['y'][1] += axis_length cylinder_coords_end['z'][2] += axis_length ''' CREATE THE CYLINDERS''' cylinders = { 'x': Cylinder(start_position, cylinder_coords_end['x'], 0.1, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))), 'y': Cylinder(start_position, cylinder_coords_end['y'], 0.1, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))), 'z': Cylinder(start_position, cylinder_coords_end['z'], 0.1, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))) } # Cone START is the same as the Cylinder END, so we COPY these lists cones_coords_start = { 'x': list(cylinder_coords_end['x']), 'y': list(cylinder_coords_end['y']), 'z': list(cylinder_coords_end['z']) } # Copy the START as END coordinate cones_coords_end = { 'x': list(cones_coords_start['x']), 'y': list(cones_coords_start['y']), 'z': list(cones_coords_start['z']) } # Extend the tip of the cones with length 1 cones_coords_end['x'][0] += 1 cones_coords_end['y'][1] += 1 cones_coords_end['z'][2] += 1 ''' CREATE THE CONES ''' cones = { 'x': Cone(cones_coords_start['x'], 0.3, cones_coords_end['x'], 0, Texture(Pigment('color', [1, 0, 0]), Finish('reflection', 1))), 'y': Cone(cones_coords_start['y'], 0.3, cones_coords_end['y'], 0, Texture(Pigment('color', [0, 0, 1]), Finish('reflection', 1))), 'z': Cone(cones_coords_start['z'], 0.3, cones_coords_end['z'], 0, Texture(Pigment('color', [0, 1, 0]), Finish('reflection', 1))), } # Add ALL objects to a LIST and return legend_objects = list(cylinders.values()) + list(cones.values()) return legend_objects
def _render_structure(self, change=None): """Render the structure with POVRAY.""" if not isinstance(self.structure, Atoms): return self.render_btn.disabled = True omat = np.array(self._viewer._camera_orientation).reshape( 4, 4).transpose() zfactor = norm(omat[0, 0:3]) omat[0:3, 0:3] = omat[0:3, 0:3] / zfactor bb = deepcopy(self.structure) bb.pbc = (False, False, False) for i in bb: ixyz = omat[0:3, 0:3].dot(np.array([i.x, i.y, i.z]) + omat[0:3, 3]) i.x, i.y, i.z = -ixyz[0], ixyz[1], ixyz[2] vertices = [] cell = bb.get_cell() vertices.append(np.array([0, 0, 0])) vertices.extend(cell) vertices.extend([ cell[0] + cell[1], cell[0] + cell[2], cell[1] + cell[2], cell[0] + cell[1] + cell[2], ]) for n, i in enumerate(vertices): ixyz = omat[0:3, 0:3].dot(i + omat[0:3, 3]) vertices[n] = np.array([-ixyz[0], ixyz[1], ixyz[2]]) bonds = [] cutOff = neighborlist.natural_cutoffs( bb) # Takes the cutoffs from the ASE database neighborList = neighborlist.NeighborList(cutOff, self_interaction=False, bothways=False) neighborList.update(bb) matrix = neighborList.get_connectivity_matrix() for k in matrix.keys(): i = bb[k[0]] j = bb[k[1]] v1 = np.array([i.x, i.y, i.z]) v2 = np.array([j.x, j.y, j.z]) midi = v1 + (v2 - v1) * Radius[i.symbol] / (Radius[i.symbol] + Radius[j.symbol]) bond = Cylinder( v1, midi, 0.2, Pigment("color", np.array(Colors[i.symbol])), Finish("phong", 0.8, "reflection", 0.05), ) bonds.append(bond) bond = Cylinder( v2, midi, 0.2, Pigment("color", np.array(Colors[j.symbol])), Finish("phong", 0.8, "reflection", 0.05), ) bonds.append(bond) edges = [] for x, i in enumerate(vertices): for j in vertices[x + 1:]: if (norm(np.cross(i - j, vertices[1] - vertices[0])) < 0.001 or norm(np.cross(i - j, vertices[2] - vertices[0])) < 0.001 or norm(np.cross(i - j, vertices[3] - vertices[0])) < 0.001): edge = Cylinder( i, j, 0.06, Texture( Pigment("color", [212 / 255.0, 175 / 255.0, 55 / 255.0])), Finish("phong", 0.9, "reflection", 0.01), ) edges.append(edge) camera = Camera( "perspective", "location", [0, 0, -zfactor / 1.5], "look_at", [0.0, 0.0, 0.0], ) light = LightSource([0, 0, -100.0], "color", [1.5, 1.5, 1.5]) spheres = [ Sphere( [i.x, i.y, i.z], Radius[i.symbol], Texture(Pigment("color", np.array(Colors[i.symbol]))), Finish("phong", 0.9, "reflection", 0.05), ) for i in bb ] objects = ( [light] + spheres + edges + bonds + [Background("color", np.array(to_rgb(self._viewer.background)))]) scene = Scene(camera, objects=objects) fname = bb.get_chemical_formula() + ".png" scene.render( fname, width=2560, height=1440, antialiasing=0.000, quality=11, remove_temp=False, ) with open(fname, "rb") as raw: payload = base64.b64encode(raw.read()).decode() self._download(payload=payload, filename=fname) self.render_btn.disabled = False
def single_virus_gen(): """ single_virus_gen() Generates a virus object. :return virus object """ object_texture = Texture(Pigment('color', [1, 1, 1], 'transmit', 0), Finish('phong', 0.5, 'reflection', 0.9)) helix_test = 'f_helix1(x, y, z, 1, 1 * 4 * pi, 0.07, 0.8, 1, 0.3, 0)' iso_spine = Isosurface(Function(helix_test), ContainedBy(Box(-5, 5)), 'translate', [0, 0, 0], models.default_sphere_model) # spine helix cyl = Cylinder([0, -5, 0], [0, 5, 0], 0.5, object_texture) # spine cylinder icosahedral = 'abs(x)+abs(y)+abs(z)-4.9' ico_head = Isosurface(Function(icosahedral), ContainedBy(Box(-3.5, 3.5)), 'max_gradient', 5, 'translate', [0, 7, 0], object_texture) # head object ring = Torus(1.2, 0.3, 'translate', [0, -5, 0], object_texture) # hip ring spine # berelem radian, bijv: 1.05 * math.cos(radian * 3) 3 = step, 1.05 = straal radian = (360 / 6) * (math.pi / 180) x_tail_list = [] for coordinate_offset in range(1, 7, 2): coordinate_offset += 0.05 x_tail_list.append(coordinate_offset) # [1.05, 3.05, 5.05] x_axis_tail_list = [] z_axis_tail_list = [] for tail_nr in range(1, 7): tail_steps = tail_nr for coordinate in x_tail_list: x_axis_tail_list.append(coordinate * math.cos(radian * tail_steps)) z_axis_tail_list.append(coordinate * math.sin(radian * tail_steps)) tails = [] for tail_coordinate in range(0, len(x_axis_tail_list), 3): tails.append( SphereSweep('linear_spline', 3, [ x_axis_tail_list[tail_coordinate], -5.00, z_axis_tail_list[tail_coordinate] ], 0.1, [ x_axis_tail_list[tail_coordinate + 1], -1.00, z_axis_tail_list[tail_coordinate + 1] ], 0.15, [ x_axis_tail_list[tail_coordinate + 2], -9.00, z_axis_tail_list[tail_coordinate + 2] ], 0.1, object_texture)) # 6 tails virus_object = Merge(iso_spine, ico_head, ring, cyl) for tail in tails: virus_object.args.append(tail) return virus_object
def sph(vs, ucs, A, C, x, y, z, rotx=0, roty=0, rotz=0, mode="C"): """Colored spheres for rendering RD results Colored spheres for rendering RD results Args: vs: vertices ucs: u conc. A, C: RD parameters x, y, z: translation rotx, roty, rotz: rotation angle mode: color mode for parameters """ sph = [] if mode == "A": nA = (A-0.07)/(0.12-0.07) nC = (C+0.1)/(0.31+0.1) elif mode == "C": nA = (A-0.07)/(0.12-0.07) nC = C/0.307 elif mode == "AC": nA = (A-0.07)/(0.12-0.07) nC = (C+0.1)/(0.31+0.1) else: nA = (A-0.07)/(0.12-0.07) nC = C/0.307 if (type(nA) is np.float64): nA = np.full(len(vs), nA) if (type(nC) is np.float64): nC = np.full(len(vs), nC) for v, uc, a, c in zip(vs, ucs, nA, nC): if mode == "A": H0 = a L0 = 1/(1+np.exp((-2.8*((a-0.52)*2.4)))) # R0, G0, B0 = colorsys.hls_to_rgb(0.02+H0*0.35, 0.5-L0*0.4, 1.0) R0, G0, B0 = colorsys.hls_to_rgb(1.0-H0*0.40, 0.5-L0*0.4, 1.0) elif mode == "C": H0 = c L0 = 1/(1+np.exp((-2.8*((c-0.52)*2.4)))) R0, G0, B0 = colorsys.hls_to_rgb(0.02+H0*0.35, 0.5-L0*0.4, 1.0) elif mode == "AC": R0 = a*1.0 # G0 = max(0.8-(max(a+c, 0)), 0) G0 = 0.0 B0 = c*1.0 else: R0 = 0.3 G0 = 0.2 B0 = 0.2 R1 = 1.0 - R0 G1 = 1.0 - G0 B1 = 1.0 - B0 sph.append(Sphere(v, 0.022, Texture(Pigment('color', [R0+uc*R1, G0+uc*G1, B0+uc*B1]), Finish('phong', 0.7, 'specular', 0.2, 'diffuse', 0.9, 'ambient', 0.1)), 'rotate', [rotx, 0, 0], 'rotate', [0, roty, 0], 'rotate', [0, 0, rotz], 'translate', [x, y, z], 'no_shadow')) return sph