Skip to main content

creates smooth gifs of rotating molecules

Project description

molgif

create smooth gifs of rotating molecules

Installation

root@host:~$ pip install molgif

Easily create visuals in 3 different ways

  • Functional

    molgif.rot_gif
    
  • Object-oriented

    molgif.Molecule
    
  • Scripting

    root@host:~$ molgif --help
    

Examples

Easily create gifs of rotating molecules

Can take geometry file (e.g. "c4h4o.xyz") or ase.Atoms object

import molgif
import ase.build

# load in molecule (ase.Atoms object)
# can also use geometry file path!
c4h4o = ase.build.molecule('c4h4o')
c4h4o.rotate(60, 'z')
  • Functional

    molgif.rot_gif(c4h4o)
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.save_rot_gif()
    
  • Scripting

    root@host:~$ molgif c4h4o.xyz
    

Use smart_rotate to find best viewing angle and add a legend

  • Functional

    molgif.rot_gif(c4h4o, smart_rotate=True, add_legend=True)
    
    # can also smart_rotate ase.Atoms object using function in utils
    c4h4o = molgif.utils.smart_rotate_atoms(c4h4o)
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.smart_rotate()
    mol.draw_legend()
    mol.save_rot_gif()
    
  • Scripting

    root@host:~$ molgif c4h4o.xyz --smart-rotate --legend
    

Specify the color of each atom

# can be a string of a single color
colors = 'blue'

# or a list of custom colors
# (list length much match number of atoms)
rainbow = ['red', 'orange', 'yellow',
           'green', 'blue', 'violet',
           'red', 'orange', 'yellow']

colors = rainbow
  • Functional

    molgif.rot_gif(c4h4o, colors=colors)
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.colors = colors
    mol.save_rot_gif()
    
  • Scripting

    Specify single color

    root@host:~$ molgif c4h4o.xyz --colors yellow
    

    Separate multiple colors using "-" (length must match # atoms)

    root@host:~$ molgif c4h4o.xyz --colors r-orange-yellow-g-b-violet-r-orange-yellow
    

Use a dictionary to quickly color by atom type and add a legend

Default colors will be used for types not specified

  • Functional

    molgif.rot_gif(c4h4o, colors={'C': 'hotpink', 'O': 'dodgerblue'},
                   add_legend=True)
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.colors = {'C': 'hotpink', 'O': 'dodgerblue'}
    mol.draw_legend()
    mol.save_rot_gif()
    
  • Scripting

    Color dict can be defined as (symbol-color)- pairs

    root@host:~$ molgif c4h4o.xyz --colors C-hotpink-O-dodgerblue --legend
    

Anchor an atom to be at the center of rotation

Can define:

  • atom index (based on order of atoms)
  • atomic symbol (first matching atom type selected based on order)
  • "center" (selects closest atom to center of molecule)
# define index of atom to anchor
anchor = 3

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

    molgif.rot_gif(c4h4o, colors=colors,
                   anchor=anchor)
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.colors = colors
    mol.anchor(anchor)
    mol.save_rot_gif()
    
  • Scripting

    root@host:~$ molgif c4h4o.xyz --anchor 3 --colors w-w-w-#0892d0-w-w-w-w-w
    

Adjust loop time and FPS

loop_time = time to complete one rotation (seconds)

  • Functional

    molgif.rot_gif(c4h4o, loop_time=2, fps=60)
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.save_rot_gif(loop_time=2, fps=60)
    
  • Scripting

    root@host:~$ molgif c4h4o.xyz --loop-time 2 --fps 60
    

Turn off bonds and scale atomic sizes

  • Functional

    molgif.rot_gif(c4h4o, add_bonds=False,
                   scale=0.9)
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.remove_bonds()
    mol.scale = 0.9
    mol.save_rot_gif()
    
  • Scripting

    root@host:~$ molgif c4h4o.xyz --no-bonds --scale 0.9
    

Change rotation axis

  • x: top-to-bottom
  • y: left-to-right (Default)
  • z: counterclockwise

Examples changing to 'x':

  • Functional

    molgif.rot_gif(c4h4o, rot_axis='x')
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.rot_axis = 'x'
    mol.save_rot_gif()
    
  • Scripting

    root@host:~$ molgif c4h4o.xyz --rot-axis x
    

Switch rotation direction

negative rot_axis (e.g. "-x") reverses direction

  • Functional

    molgif.rot_gif(c4h4o, rot_axis='-x')
    
  • Object-oriented

    mol = molgif.Molecule(c4h4o)
    mol.rot_axis = '-x'
    mol.save_rot_gif()
    
  • Scripting

    root@host:~$ molgif c4h4o.xyz --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)

# also works with xyz files if saved from an
# ase.Atoms object with inital_charges defined
atoms.write('c4h4o.xyz')
  • Functional

    Use charges automatically centers cmap around 0

    molgif.rot_gif(atoms, max_px=max_px, use_charges=True)
    
  • Object-oriented

    Colors can be defined as values, which uses a cmap to specify atom colors

    mol = molgif.Molecule(c4h4o)
    
    # manually center cmap around 0
    mol.center_data = True
    
    mol.colors = mol.atoms.get_initial_charges()
    mol.save_rot_gif()
    
  • Scripting

    Assumes that initial_charges are defined in xyz file (using ase)

    root@host:~$ molgif c4h4o.xyz --use-charges
    

Requirements

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

Source Distribution

molgif-0.3.0.tar.gz (23.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: molgif-0.3.0.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3.post20200330 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.1

File hashes

Hashes for molgif-0.3.0.tar.gz
Algorithm Hash digest
SHA256 598deda578d55121b9f598122b30c878307282cd7637b07c364b0beec144b7b6
MD5 b9057aaa1ce7ff25bd5c0097c1c8d641
BLAKE2b-256 b36f39a97c8258de03c90fe94b9bd2e183f855d2d27830dcb8ed1093a7ea12e4

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