Ångström

A Python package for basic molecular operations with low-dependency and easy-integration.

KBS - Home
Ångström
Visualization

Visualization

Ångström offers several ways to visualize molecules and create animations. Current selections are using Blender, OpenBabel, VMD, and Nglview for visualization. You can render images of molecules using Blender and OpenBabel, render animations using Blender and VMD and visualize molecules in Jupyter Notebook using Nglview.

Currently, only images can be rendered using Blender and OpenBabel and nglview in Jupyter notebook. The animation future will be implemented soon…

Command-line interface

Ångström comes with a command-line interface (angstrom) which you can use to visualize molecules:

angstrom tests/C60.pdb

To see options:

angstrom --help

Library usage

You can also use the rendering capabilities as a part of the Python library:

from angstrom.visualize import render
from angstrom import Molecule


mol = Molecule(read='molecule.xyz')

# Blender rendering
render(mol, 'molecule.png', renderer='blender')

# OpenBabel rendering
render(mol, 'molecule.svg', renderer='openbabel')

Blender

Setup

Make sure you install Blender 2.8 first. Ångström requires Blender 2.8 or higher. To use Blender with Ångström you need to make sure the blender executable is accessible. For Linux blender executable is added to PATH after installation, however in Windows or Mac this might not be the case. Ångström attempts to find the executable in possible locations, however if this does not work look here to figure out where you can find the blender executable.

After you locate the blender executable you can provide it to the command line interface as follows:

angstrom molecule.pdb -exe /path/to/blender

You can also setup the executable as follows:

from angstrom.visualize.blender import Blender


# Mac OS example
blend = Blender()
blend.config['executable'] = './blender.app/Contents/MacOS/blender'

# Windows example
blend.config['executable'] = 'C:\\Program Files\\Blender Foundation\\Blender\\blender.exe'

If you want to permanently add the executable then you can modify the source code. Go to angstrom/cli/tools.py and add your executable to the blender_paths list.

Usage and customization

from angstrom.visualize import render
from angstrom.visualize.blender import Blender
from angstrom import Molecule


mol = Molecule(read='molecule.xyz')

blend = Blender()
blend.configure(model='space_filling', camera_zoom=30, camera_type='ORTHO',
                brightness=1.2, resolution=[3000, 2000])

# Render using above configuration
render(mol, 'molecule.png', renderer=blend)

OpenBabel

Setup

To be able to use OpenBabel rendering you need to install OpenBabel first. Ångström uses openbabel executable in order to run OpenBabel for saving images. Make sure you can run openbabel in a terminal in Linux and Mac OS or in command prompt in Windows.

The default command in Ångström runs the following line using Python subprocess library.

obabel molecule.pdb -O molecule.svg -xS -xd xb none

where molecule.pbd is the pdb file to be visualized and molecule.svg is the image file to be saved.

Usage and customization

from angstrom.visualize import render
from angstrom.visualize.openbabel import OpenBabel
from angstrom import Molecule


mol = Molecule(read='molecule.xyz')

ob = OpenBabel()
ob.executable = 'obabel
ob.config = ['-xS', '-xd', 'xb', 'none']

# Render using above configuration
render(mol, 'molecule.svg', renderer=ob)

Rendering Animations

Making a gif (Linux)

From a list of images:

convert -delay 20 -loop 0 *.jpg my_gif.gif

where -delay is the time between each frame in 10 ms. So -delay 20 means there would be 0.2 seconds between each frame.

From a video:

ffmpeg -i my_video.avi -r 25 -f image2pipe -vcodec ppm - | convert -delay 4 -loop 0 - my_gif.gif

See more info here.

VMD

vmd -dispdev text -eofexit < vis-state.vmd

Jupyter Notebook

Nglview

Browser

Three.js

HTML Embed