Exemple #1
0
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()

    # Creation of RNA molecule
    if step in range(0, n_frames // 5 * 2):
        GUANINE.move_to([10, 0, 0])
        ADENINE.move_to([-10, 0, 0])
        CYTOSINE.move_to([0, 10, 0])
        URACIL.move_to([0, -10, 0])

    # # Sphere covering the RNA molecule
    # if step in range(n_frames // 5 * 2, n_frames // 5 * 3):
    #
    # # RNA division
    # if step in range(n_frames // 5 * 3, n_frames // 5 * 4):
    #
    # # Sphere division
    # if step in range(n_frames // 5 * 4, n_frames):

    # Return the Scene object for rendering
    return Scene(models.floor_camera,
                 objects=[models.default_light] + GUANINE.povray_molecule)
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):
    """ Creates a frame of a given frame (step) number. """

    # 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)

    # Calculates rotation positions
    angle_per_frame = math.pi * 2 / nframes  # Calculates how much the angle needs to move per frame
    angle = angle_per_frame * step # Calculates the angle of the frame

    # Gets locations
    x = math.cos(angle) * 20
    z = math.sin(angle) * 20

    # Create objects
    sphere = Sphere([6, 2, -2], 3, models.default_sphere_model)
    cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, models.default_sphere_model)
    legend_1 = legend([-15, 0, 0], 5)
    camera = Camera('location', [x, 8, z], 'look_at', [0, 0, 0])

    # Return the Scene object containing all objects for rendering
    return Scene(camera,
                 objects=[sphere, models.default_light, models.checkered_ground, cylinder] + legend_1)
Exemple #4
0
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)
Exemple #5
0
def main(args):
    """ Main function of this program """
    make_objects()
    logger.info(" Total time: %d (frames: %d)", SETTINGS.Duration,
                eval(SETTINGS.NumberFrames))
    pypovray.render_scene_to_mp4(frame)
    return 0
Exemple #6
0
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)

    # Start- and end-points
    x_start = -10
    x_end = 10
    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

    # Create sphere at calculated x-coordinate using default model
    sphere = Sphere([x_coord, 0, 0], 2, models.default_sphere_model)

    # Return the Scene object containing all objects for rendering
    return Scene(models.default_camera,
                 objects=[sphere, models.default_ground, models.default_light])
Exemple #7
0
def main(args):
    """ Main function performing the rendering """
    logger.info(" Total time: %d (frames: %d)", SETTINGS.Duration,
                eval(SETTINGS.NumberFrames))
    pypovray.render_scene_to_mp4(frame)

    return 0
Exemple #8
0
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)
Exemple #9
0
def frame(step):
    """ Makes an image/frame """
    time_point = (step / TOTAL_FRAMES) * SETTINGS.Duration
    logger.info(" @Time: %.4fs, Step: %d", time_point, step)

    # Declaration of the end times of the scenes
    global TP_END
    TP_END = [4, 8, 11, 15, 18, 26, 32, 38, 44, 50, 58, 64]
    # scene   0  1  2   3   4   5   6   7   8   9   10, 11

    # Globals that change per frame
    global TP_START, TP_DUR, TWITCH1, TWITCH2
    TP_START, TP_DUR = get_time_point_data(TP_END)
    TWITCH1, TWITCH2 = make_random_int()

    if time_point < TP_END[0]:
        scene = s0_intro_text()
    elif time_point < TP_END[1]:
        scene = s1_cell_overview()
    elif time_point < TP_END[2]:
        scene = s2_cell_zoom(step)
    elif time_point < TP_END[3]:
        scene = s3_in_cell()
    elif time_point < TP_END[4]:
        scene = s4_zoom_to_mrna(step)
    elif time_point < TP_END[11]:
        scene = scenes_mrna(step, time_point)
    else:
        text = Text('ttf', '"timrom.ttf"', '"Uh-oh, this ain\'t right"', 0, 0,
                    'translate', [-4, 0, 0], 'scale', [2, 2, 0],
                    models.text_model)
        scene = Scene(models.default_camera,
                      objects=[models.default_light, text])
    return scene
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 main():
    """
    Main function performing the rendering Prints user information to sceen and grabs settings
    from settings file. Starts main render and creates .mp4 file
    """
    logger.info(" Total time: %d (frames: %d)", SETTINGS.Duration,
                eval(SETTINGS.NumberFrames))
    pypovray.SETTINGS = load_config('default.ini')
    pypovray.render_scene_to_mp4(frame)
    return 0
Exemple #12
0
def frame(step):
    """ Returns a scene at a step number in which a sphere is visualised. """
    # 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)

    # Calculate the frames per wave
    repeats = 5
    n_frames_wave = n_frames / repeats  # amount of frames per wave

    # Calculates starting coordinates of the sphere
    increase = 4  # amount of increase per wave
    x_start = -10
    x_end = x_start + increase
    y_start = -4
    y_end = 4

    # Calculates total distance and distance per frame
    x_distance = x_end - x_start
    y_distance = y_end - y_start
    x_distance_per_frame = (x_distance / (n_frames_wave / 2))
    y_distance_per_frame = (y_distance / (n_frames_wave / 2))

    # Determine in which wave this step is
    if step // n_frames_wave == 0:
        wave = 0
    else:
        wave = step // n_frames_wave

    # Step has to reset for every wave, so subtract frames of previous wave(s)
    frame_in_wave = step - (wave * n_frames_wave)

    # If it is in the first part of the wave
    if frame_in_wave <= (n_frames_wave / 2):
        x_coord = x_start + (
            wave * increase
        ) + frame_in_wave * x_distance_per_frame  # Increases linear
        y_coord = y_start + frame_in_wave * y_distance_per_frame  # Increases linear
    # Second part of the wave
    else:
        x_coord = x_end + (wave * increase
                           )  # Stays constant and increases 4 for every wave
        y_coord = y_end - (
            frame_in_wave -
            (n_frames_wave / 2)) * y_distance_per_frame  # Decreases linear

    # Makes a sphere at given x- and Y-coordinates with the default style
    sphere = Sphere([x_coord, y_coord, 0], 0.5, models.default_sphere_model)

    # Returns the objects of the scene using the default camera settings
    return Scene(models.default_camera,
                 objects=[sphere, models.default_ground, models.default_light])
Exemple #13
0
def frame(step):
    """ Renders an ATP molecule centered in the scene """
    # 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)

    # Calculates distance per frame for the to be splitted molecule parts
    x_start = 0
    x_end = 8
    x_distance = x_end - x_start
    x_distance_per_frame = (x_distance / (n_frames / 2))

    # Variables used for rotating of molecules
    full_circle = 2 * pi  # One full circle equals exactly 2 times pi
    rotation_per_frame = full_circle / (n_frames / 2)

    # creating the nucleotide
    gtp = pdb.PDBMolecule('{}/pdb/gtp.pdb'.format(SETTINGS.AppLocation),
                          center=True)
    gtp.rotate([1, 1, 1], [pi * 1.5, pi, pi / 2])
    gtp.divide([11, 12, 13, 14, 15, 16, 17, 18], 'phosphate', offset=[
        0, 0, 0
    ])  # removes two phosphate groups to create guanine nucleotide
    guanine = gtp.divide(
        [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 28, 29, 34, 35],
        'base',
        offset=[4, 0, 0])  # splits into ribose-phosphate and the gaunine base

    # In the first half of the animation: split the guanine nucleotide into guanine and ribose-phosphate
    if step in range(0, n_frames // 2):
        gtp.move_to([-step * x_distance_per_frame, 0, 0])
        guanine.move_to([step * x_distance_per_frame, 0, 0])

    # In the second half of the animation: rotate both molecules one full circle
    if step in range(n_frames // 2, n_frames):
        gtp.rotate([0, 1, 0], rotation_per_frame * (step - (n_frames / 2)))
        guanine.rotate([1, 0, 0], rotation_per_frame * (step - (n_frames / 2)))
        gtp.move_to([-n_frames // 2 * x_distance_per_frame, 0, 0])
        guanine.move_to([n_frames // 2 * x_distance_per_frame, 0, 0])

    # Return the Scene object for rendering
    return Scene(models.floor_camera,
                 objects=[models.default_light] + gtp.povray_molecule +
                 guanine.povray_molecule)
def frame(step):
    """ Returns the scene at step number (1 step per frame) """

    # Rotate the molecules updating its orientation (a persistent modification)
    ETHANOL.rotate([1, 1, 0], RAD_PER_SCENE)
    VIAGRA.rotate([1, 0, 1], RAD_PER_SCENE)
    BENZENE.rotate([0, 1, 1], RAD_PER_SCENE)

    # Combine molecule objects (an object.povray_molecule is a list of atoms, they need
    # to be concatenated to be added to the scene)
    molecules = ETHANOL.povray_molecule + VIAGRA.povray_molecule + BENZENE.povray_molecule

    logger.info(' @Step: %s', step)
    # Return a 'Scene' object containing -all- objects to render, i.e. the camera,
    # light(s) and in this case, molecules too.
    return Scene(models.default_camera,
                 objects=[models.default_light, FRONT_LIGHT] + molecules,
                 included=['colors.inc'])
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()
    new_molecule = pdb(pdb=None, atoms= GUANINE , ADENINE)
    print(new_molecule)

    # Creation of RNA molecule
    step_in_frame = step
    two_fifth_of_animation = n_frames // 5 * 2
Exemple #16
0
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)

    # Create molecule
    atp = pdb.PDBMolecule('{}/pdb/ATP_ideal.pdb'.format(SETTINGS.AppLocation),
                          center=True)
    atp.move_to([0, 5, 0])

    # Creates phospate sliced molecule
    phosphate = atp.divide([0, 1, 2, 3, 7, 31, 32], 'phosphate')

    # Creates other objects
    camera = Camera('location', [25, 5, 10], 'look_at', [0, 5, 0])
    light = LightSource([25, 5, 10], 'color', [1, 1, 1])

    # Splicing the molecules animation
    if step <= 20 and step > 5:
        y = (0 - 4 / 15) * (step - 5)  # Moves for 15 frames, -4x in total
        phosphate.move_offset([0, y, 0])

    # Keeping the phospate in it's position after it moved
    elif step > 5:
        y = (0 - 4 / 15) * (
            20 - 5)  # Moves it like the 20th frame to keep it's position
        phosphate.move_offset([0, y, 0])

        # Rotating the molecules
        if step >= 30 and step < 70:
            phosphate.rotate([1, 0, 0], np.pi * 2 / 40 *
                             (step - 30))  # Rotates it for 40 frames, 1 - 2pi
            atp.rotate([0, 1, 0], np.pi * 2 / 40 * (step - 30))

    # Return the Scene object containing all objects for rendering
    return Scene(
        camera,
        objects=[models.checkered_ground, models.default_light, light] +
        atp.povray_molecule + phosphate.povray_molecule)
Exemple #17
0
    def __init__(self,
                 pdb_file,
                 center=True,
                 offset=[0, 0, 0],
                 atoms=False,
                 model=None):
        """ Parses and renders the molecule given a PDB file """

        # If a list of atoms is provided, use these instead of a PDB file
        # This allows dividing the molecule in segments, see divide()
        if atoms:
            self.atoms = atoms
        else:
            self._parse_pdb(pdb_file)
            self.povray_molecule = []

        # Molecule name
        self.molecule = pdb_file
        self.warnings = set()
        # If an offset is provided, apply this
        self.offset = np.array(offset)
        if np.count_nonzero(self.offset) > 0:
            self._recenter_molecule()
        self.center = self._center_of_mass()

        # Center the molecule based on the 'pseudo' center of mass
        if center:
            self.center_molecule()
            self.center = self._center_of_mass()
        logger.info(
            "Created a molecule from '%s' placed at [%s] (centered is %d)",
            pdb_file,
            ', '.join([str(coord)
                       for coord in np.around(self.center, 2)]), center)

        # Required for the labels
        self.show_name = False
        self.show_index = False
        self.camera = None

        self.model = model
        self.render_molecule(offset)
def _run_ffmpeg():
    """ Builds the ffmpeg command to render an MP4 movie file using the
    h.x264 codex and yuv420p format """
    ff = ffmpy.FFmpeg(
        # Input is a pattern for all image files ordered by number (padded)
        inputs={
            '':
            '-framerate {} -pattern_type glob -i {}/{}_*.png'.format(
                SETTINGS.RenderFPS, SETTINGS.OutputImageDir,
                SETTINGS.OutputPrefix)
        },
        outputs={
            '{}/{}.mp4'.format(SETTINGS.OutputMovieDir, SETTINGS.OutputPrefix):
            '-c:v libx264 -r {} -crf 2 -pix_fmt yuv420p -loglevel warning'.
            format(SETTINGS.MovieFPS)
        })
    # Run ffmpeg and create output movie file
    logger.info('["%s"] - ffmpeg command: "%s"',
                sys._getframe().f_code.co_name, ff.cmd)
    ff.run()
Exemple #19
0
def frame(step):
    """ Returns a scene at a step number while camera is moving """
    # 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)

    # Calculates coordinates for the camera position
    radius = 25
    degrees = pi / (n_frames / 2) * (step + 1)
    x_coord = radius * sin(degrees)
    z_coord = radius * cos(degrees)

    # Returns the objects of the scene using the default camera settings
    return Scene(
        Camera('location', [x_coord, 8, z_coord], 'look_at', [0, 0, 0]),
        objects=[LightSource([2, 8, -20], 2), models.checkered_ground] +
        SPHERE + CYLINDER + LEGEND)
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)

    # Getting the total number of frames, see the configuration file
    nframes = eval(SETTINGS.NumberFrames)

    x_start = -10
    x_end = 10

    distance_x = x_end - x_start

    distance_per_frame_x = (distance_x / nframes) * 2

    x_coord = x_start + step * distance_per_frame_x
    y_coord = sin(x_coord)

    sphere = (Sphere([x_coord, y_coord, 0], 3, models.default_sphere_model))
    return Scene(models.default_camera,
                 objects=[sphere, models.default_ground, models.default_light])
def frame(step):
    """ Renders an animation in which the molecules are split
    and rotate one full circle around its axis """
    # 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)

    # Calculates distance per frame for the two molecules
    x_start = 0
    x_end = 8
    x_distance = x_end - x_start
    x_distance_per_frame = (x_distance / (n_frames / 2))

    # Variables used for rotating of molecules
    full_circle = 2 * pi  # One full circle equals exactly 2 times pi
    rotation_per_frame = full_circle / (n_frames / 2)

    # obtain molecules from function
    create_molecules()

    # In the 1st half of animation: split the guanine nucleotide into guanine and ribose-phosphate
    if step in range(0, n_frames // 2):
        GTP.move_to([-step * x_distance_per_frame, 0, 0])
        GUANINE.move_to([step * x_distance_per_frame, 0, 0])

    # In the 2nd half of animation: rotate both molecules one full circle
    if step in range(n_frames // 2, n_frames):
        GTP.rotate([0, 1, 0], rotation_per_frame * (step - (n_frames / 2)))
        GUANINE.rotate([1, 0, 0], rotation_per_frame * (step - (n_frames / 2)))
        GTP.move_to([-n_frames // 2 * x_distance_per_frame, 0, 0])
        GUANINE.move_to([n_frames // 2 * x_distance_per_frame, 0, 0])

    # Return the Scene object for rendering
    return Scene(models.floor_camera,
                 objects=[models.default_light] + GTP.povray_molecule +
                 GUANINE.povray_molecule)
Exemple #22
0
def frame(step):
    """ Returns the scene at step number (1 step per frame) """
    logger.info("@ Step %d", step)

    # The Ethanol molecule is moved on a trajectory representing a 'figure 8' or the infinity
    # symbol by calculating the x- and y-coordinates using the lemniscate of Bernoulli.
    alpha = 9
    scale = alpha * math.sqrt(2)
    radians = step * RAD_PER_SCENE

    x = scale * math.cos(radians) / \
        (math.sin(radians) ** 2 + 1)

    y = scale * math.cos(radians) * \
        math.sin(radians) / \
        (math.sin(radians)**2 + 1)

    # Draws spheres on each of the calculated x,y coordinates
    TRACER.append(Sphere([x, y, -4], 0.2, models.default_sphere_model))

    # Copying the full molecule - only needed for multithreading
    # This is required for multithreading
    ethanol = copy.deepcopy(ETHANOL)

    # Move the molecule to the calculated coordinates
    ethanol.move_to([x, y, -5])

    # Rotate the molecule on x- and y-axes
    # NOTE: default rotate does NOT work when using a thread-pool,
    # use the molecule.rotate_by_step method instead
    ethanol.rotate_by_step([1, 0, 0], RAD_PER_SCENE, step)

    # Return a 'Scene' object containing -all- objects to render, i.e. the camera,
    # lights and in this case, a molecule and a list of spheres (TRACER).
    return Scene(models.default_camera,
                 objects=[models.default_light, FRONT_LIGHT] +
                 ethanol.povray_molecule + TRACER,
                 included=['colors.inc'])
def frame(step):
    """ Returns the scene at the given step  """
    # Show some information about how far we are with rendering
    curr_time = step * eval(SETTINGS.FrameTime)
    logger.info(" @Time: %.3fs, Step: %d", curr_time, step)

    ## Rotating sphere, placed in the center
    sphere_rad = 1.8
    sphere = Sphere([0, 0, 0], sphere_rad,
                    Pigment('color', [0.9, 0.05, 0.05], 'filter', 0.7),
                    Interior('ior', 1), Finish('phong', 0.6, 'reflection', 0.4))

    # Intersecting cylinder object
    rod = Cylinder([0, 0, 3], [0, 0, -3],
                   1.0, 'open', Pigment('color', [1, 0, 0], 'filter', 0.8),
                   Interior('ior', 1), Finish('phong', 0, 'reflection', 0))

    # 'Hollow out' the rotating sphere with the intersecting cylinder using the Difference,
    # move to a spot on the circle (top) and rotate on the x-axis
    traveller = Difference(sphere, rod, 'translate', [RADIUS, 0, 0],
                           'rotate', [0, 360/eval(SETTINGS.NumberFrames)*step*2, 0])

    return Scene(CAMERA, objects=[GROUND, MAIN_LIGHT, BACK_LIGHT, traveller] + RING)
Exemple #24
0
def frame(step):
    curr_time = step / eval(SETTINGS.NumberFrames) * eval(SETTINGS.FrameTime)
    logger.info(" @Time: %.3fs, Step: %d", curr_time, step)

    n_frames = eval(SETTINGS.NumberFrames)
    n_frames_loop = n_frames / 5  # amount of frames per loop

    x_start = -10
    x_end = x_start + 4
    x_distance = x_end - x_start
    x_distance_per_frame = (x_distance / (n_frames_loop / 2))

    y_start = -4
    y_end = 4
    y_distance = y_end - y_start
    y_distance_per_frame = (y_distance / (n_frames_loop / 2))

    # determine loop step
    if step - 1 // n_frames_loop == 0:
        loop = 0
    else:
        loop = step // n_frames_loop

    frame_in_loop = step - (loop * n_frames_loop)

    if frame_in_loop <= (n_frames_loop / 2):
        x_coord = x_start + (loop * 4) + frame_in_loop * x_distance_per_frame
        y_coord = y_start + frame_in_loop * y_distance_per_frame
    else:
        x_coord = x_end + (loop * 4)
        y_coord = y_end - (frame_in_loop -
                           (n_frames_loop / 2)) * y_distance_per_frame

    sphere = Sphere([x_coord, y_coord, 0], 0.5, models.default_sphere_model)

    return Scene(models.default_camera,
                 objects=[sphere, models.default_ground, models.default_light])
Exemple #25
0
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)

    # obtain molecules from function
    create_molecules()

    # Creation of RNA molecule
    step_in_frame = step
    two_fifth_of_animation = n_frames // 5 * 2

    if step in range(0, two_fifth_of_animation):
        create_first_part(step_in_frame, two_fifth_of_animation)

    # Return the Scene object for rendering
    return Scene(Camera('location', [0, 0, -50], 'look_at', [0, 0, 0]),
                 objects=[models.default_light] + URACIL_ONE.povray_molecule +
                 ADENINE.povray_molecule + ADENINE_TWO.povray_molecule +
                 GUANINE.povray_molecule + CYTOSINE.povray_molecule)
Exemple #26
0
def frame(step):
    """ Returns a scene at a step number while camera is moving. """
    # 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)

    # Calculates coordinates for the camera position
    radius = 25
    degrees = pi / (n_frames / 2) * (step + 1)
    x_coord = radius * sin(degrees)
    z_coord = radius * cos(degrees)

    # Makes objects at given coordinates
    sphere = Sphere([6, 2, -2], 3, models.default_sphere_model)
    cylinder = Cylinder([-6, -1, 4], [-6, 7, 4], 3, models.default_sphere_model)
    xyz_legend = legend([-15, 0, 0], 5)

    # Returns the objects of the scene using the default camera settings
    return Scene(Camera('location', [x_coord, 8, z_coord], 'look_at', [0, 0, 0]),
                 objects=[LightSource([2, 8, -20], 2),
                          models.checkered_ground, sphere, cylinder] + xyz_legend)
Exemple #27
0
def frame(step):
    """ Returns the scene at step number (1 step per frame) """

    cylinder = Cylinder([-6, -1, 4], [-6, 8, 4], 4,
                        models.default_sphere_model)
    sphere = Sphere([6, 2, -2], 3, models.default_sphere_model)
    xyz_legend = legend([-15, 0, 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)

    distance_per_frame = 50 / nframes
    z_start = -25
    z_end = 25

    if step < (nframes / 2):

        z = z_start + step * distance_per_frame
        x = math.sqrt(25**2 - z**2)
    else:

        z = z_end - step * distance_per_frame
        x = -1 * math.sqrt(25**2 - z**2)

    camera = Camera('location', [x, 8, z], 'look_at', [0, 0, 0])

    # Return the Scene object containing all objects for rendering
    return Scene(camera,
                 objects=[
                     sphere, cylinder, models.checkered_ground,
                     models.default_light
                 ])
def main(args):
    """ Main function that will run other functions """
    logger.info(" Total time: %d (frames: %d)", SETTINGS.Duration, eval(SETTINGS.NumberFrames))
    pypovray.render_scene_to_gif(frame)
    return 0
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)
Exemple #30
0
    if time_point < TP_END[0]:
        scene = s0_intro_text()
    elif time_point < TP_END[1]:
        scene = s1_cell_overview()
    elif time_point < TP_END[2]:
        scene = s2_cell_zoom(step)
    elif time_point < TP_END[3]:
        scene = s3_in_cell()
    elif time_point < TP_END[4]:
        scene = s4_zoom_to_mrna(step)
    elif time_point < TP_END[11]:
        scene = scenes_mrna(step, time_point)
    else:
        text = Text('ttf', '"timrom.ttf"', '"Uh-oh, this ain\'t right"', 0, 0,
                    'translate', [-4, 0, 0], 'scale', [2, 2, 0],
                    models.text_model)
        scene = Scene(models.default_camera,
                      objects=[models.default_light, text])
    return scene


if __name__ == "__main__":
    logger.info(" Total time: %ds (frames: %d)", SETTINGS.Duration,
                TOTAL_FRAMES)

    time_points = [56, 64]
    render_frames = [int(i * SETTINGS.RenderFPS) for i in time_points]

    pypovray.render_scene_to_mp4(frame)
    # pypovray.render_scene_to_mp4(frame, range(render_frames[0], render_frames[1]))