Skip to main content

creates smooth gifs of rotating molecules

Project description

molgif

create smooth gifs of rotating molecules

Installation

pip install molgif

Examples

Easily create gif with rot_gif function

import molgif
import ase.build

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

# create rotating gif
molgif.rot_gif(atoms)

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 pca 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,
               anchor=anchor)

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,
               scale=0.9)

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))
np.random.shuffle(chgs)

# add the charges to atoms object
atoms.set_initial_charges(chgs)

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

Requirements

  • ase
  • matplotlib
  • PIL
  • 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.

Source Distribution

molgif-0.2.1.tar.gz (17.8 kB view details)

Uploaded Source

File details

Details for the file molgif-0.2.1.tar.gz.

File metadata

  • Download URL: molgif-0.2.1.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.1

File hashes

Hashes for molgif-0.2.1.tar.gz
Algorithm Hash digest
SHA256 9f35ec2a5a00c4ff3a3cc0c6088e92961a867810028111305d46c024de1285e1
MD5 378cd06587d6a961cd384ecc20607387
BLAKE2b-256 2840ba9de0de8f1f623a74585eab104d09326ae9169e92ef4cd030f033cd5288

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page