创建旋转分子的平滑gif
molgif的Python项目详细描述
molgif
创建旋转分子的平滑gif
示例
使用自动旋转找到最佳视角
import molgif
import ase.build
# load in molecule (ase.Atoms object)
molecule = ase.build.molecule('biphenyl')
# create rotating gif with rot_gif function
molgif.rot_gif(molecule, auto_rotate=True)
添加图例
molgif.rot_gif(molecule, add_legend=True)
指定每个原子的颜色
# can be a string for one color or a list of custom colors
rainbow = ['red', 'orange', 'yellow',
'green', 'blue', 'violet'] * 4
# list much match number of atoms
rainbow = rainbow[:len(molecule)]
molgif.rot_gif(molecule, colors=rainbow)
使用字典按原子类型快速着色
# default colors will be used for types not specified
molgif.rot_gif(molecule, colors=dict(C='hotpink'),
add_legend=True)
把原子固定在旋转中心
# define index of atom to anchor
anchor = 3
colors = ['white'] * len(molecule)
colors[anchor] = '#0892d0'
molgif.rot_gif(molecule, colors=colors,
anchor=anchor)
调整循环时间和fps
# loop_time = time to complete one rotation (seconds)
molgif.rot_gif(molecule, loop_time=2, fps=60)
关闭键和标度原子大小
molgif.rot_gif(molecule, add_bonds=False,
scale=0.9)
< H3>改变旋转轴< EH3># switch between x, y (Default), or z
molgif.rot_gif(molecule, rot_axis='z')
开关旋转方向
# counterclockwise (ccw)[Default] or clockwise (cw)
# based on rot_axis
# 'x': view from left
# 'y': view from top
# 'z': view into screen
molgif.rot_gif(molecule, direction='cw')
可视化费用
import random
# random charges [-1, 1]
chgs = [-1 + 2 * random.random() for i in molecule]
# manually set the colorbar range (optional)
cb_range = (-1, 1)
molecule.set_initial_charges(chgs)
molgif.rot_gif(molecule, use_charges=True,
cb_range=cb_range)
要求
- ase
- matplotlib
- imagemagick(必须安装命令行工具)