Inspiration

desire to make learning about chemistry more interactive and engaging. The game allows players to explore different molecules and learn their structures while also testing their reaction time and coordination. The use of the RDKit package and Pygame library allows for a more interactive and dynamic experience than simply viewing static images of molecules.

What it does

The above code is a Python program that uses the RDKit and Pygame libraries to create a simple game. The game displays a randomly selected chemical molecule as an image on the screen, and the player can use the mouse and keyboard to rotate, zoom in and out, and click on the molecule to score points. The score is displayed on the screen along with the time left in the game, and the molecule name. When the player clicks on the molecule, a new randomly selected molecule is displayed. The game loop continues until the player quits the game.

How we built it

The code uses the Pygame library to create a game-like interface where a random molecule is displayed and the user can interact with it. Here is a brief overview of the code:

The necessary libraries and modules are imported including rdkit, Pygame, random, time, sys, and BytesIO. Pygame is initialized with pygame.init(). The dimensions for the Pygame window are set with width, height = 800, 600. The clock, font, and screen variables are initialized with pygame.time.Clock(), pygame.font.SysFont(None, 48), and pygame.display.set_mode((width, height)) respectively. The camera_position, camera_zoom, and camera_rotation variables are initialized to control the position, zoom, and rotation of the molecule. The score and time_left variables are initialized. A random molecule is chosen from a list of SMILES strings and converted into an image using RDKit's MolToImage() function. This image is then converted into a Pygame image with pygame.image.load(). The game loop begins with while True:. The Pygame event queue is checked for events such as quitting the game or adjusting the camera with for event in pygame.event.get():. The mouse position is adjusted for the camera and molecule rotation with mouse_x -= camera_position[0], mouse_y -= camera_position[1], mouse_x /= camera_zoom, mouse_y /= camera_zoom, and mouse_x, mouse_y = pygame.math.Vector2(mouse_x, mouse_y).rotate(-camera_rotation). The molecule image is rotated, scaled, and positioned on the screen with img_rotated = pygame.transform.rotate(img_surface, camera_rotation), img_scaled = pygame.transform.scale(img_rotated, (int(img_rotated.get_width() * camera_zoom), int(img_rotated.get_height() * camera_zoom))), and img_rect.center = camera_position. The score is updated when the molecule image is clicked with if img_rect.collidepoint(pygame.mouse.get_pos()): score += 1. The score, time left, and molecule name are displayed on the screen with screen.blit(score_text, (10, 10)), screen.blit(time_left_text, (width - 10 - time_left_text.get_width(), 10)), and screen.blit(mol_name_text, (10, 50)). The Pygame display is updated with pygame.display.flip() and the clock is ticked with clock.tick(60) to control the frame rate.

Challenges we ran into

Learning Pygames very fast integrating RDKIT

Accomplishments that we're proud of

Integrating Pygames and RDKIT together

What we learned

What's next for RDKit Molecule Game

More Molecular reaction to be performend and game will be enhanced

Built With

Share this project:

Updates