Skip to main content

creates smooth gifs of rotating molecules

Project description


create smooth gifs of rotating molecules


pip install molgif


Easily create gif with rot_gif function

import molgif

# load in molecule (ase.Atoms object)
c4h4o ='c4h4o')
c4h4o.rotate(60, 'z')

# create rotating gif

Use smart_rotate to find best viewing angle and add a legend

molgif.rot_gif(c4h4o, smart_rotate=True, add_legend=True)

# can also smart_rotate atoms object using function in utils
c4h4o = molgif.utils.smart_rotate_atoms(c4h4o)

Specify the color of each atom

# can be a string for one color or a list of custom colors
rainbow = ['red', 'orange', 'yellow',
           'green', 'blue', 'violet'] * 2

# list length much match number of atoms
rainbow = rainbow[:len(c4h4o)]

molgif.rot_gif(c4h4o, colors=rainbow)

Use a dictionary to quickly color by atom type and add a legend that's ordered by size

# default colors will be used for types not specified
# can also order legend by size
molgif.rot_gif(c4h4o, colors=dict(C='hotpink'),
               add_legend=True, leg_order='size')

Anchor an atom to be at the center of rotation

# define index of atom to anchor
anchor = 3

colors = ['white'] * len(c4h4o)
colors[anchor] = '#0892d0'

molgif.rot_gif(c4h4o, colors=colors,

Adjust loop time and FPS

# loop_time = time to complete one rotation (seconds)
molgif.rot_gif(c4h4o, loop_time=2, fps=60)

Turn off bonds and scale atomic sizes

molgif.rot_gif(c4h4o, add_bonds=False,

Change rotation axis

# switch between x, y (Default), or z
molgif.rot_gif(c4h4o, rot_axis='x')

Switch rotation direction

# "negative" rot_axis = opposite direction
molgif.rot_gif(c4h4o, rot_axis='-x')

Visualize charges

# random charges [-1, 1]
chgs = np.linspace(-1, 1, len(atoms))

# add the charges to atoms object

molgif.rot_gif(atoms, max_px=max_px, use_charges=True)


  • ase
  • matplotlib
  • pillow
  • ImageMagick (command line tools must be installed)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for molgif, version 0.2.5
Filename, size File type Python version Upload date Hashes
Filename, size molgif-0.2.5.tar.gz (17.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page