Last active
August 31, 2019 02:10
-
-
Save jwz-ecust/96616e44eabd054dbce1a54a4b663d32 to your computer and use it in GitHub Desktop.
ase traj to pov input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
from glob import glob | |
from ase.io import read, write | |
from ase import Atoms | |
import numpy as np | |
from ase.utils import natural_cutoffs | |
from ase.build import molecule | |
import matplotlib.pyplot as plt | |
def attachbonds(atoms): | |
bondatoms = [] | |
symbols = atoms.get_chemical_symbols() | |
cutoffs = np.array(natural_cutoffs(atoms)) + 0.15 | |
num = len(symbols) | |
for i in range(num): | |
for j in range(i): | |
ni = cutoffs[i] | |
nj = cutoffs[j] | |
disij = atoms.get_distance(i, j) | |
if ni + nj > disij: | |
bondatoms.append((i, j)) | |
return bondatoms | |
rot = '-90x' # found using ag: 'view -> rotate' | |
kwargs = { | |
'rotation' : rot, # text string with rotation (default='' ) | |
"radii": .85, # float, or a list with one float per atom | |
'colors': None, # List: one (r, g, b) tuple per atom | |
'show_unit_cell': 2, # 0, 1, or 2 to not show, show, and show all of cell | |
} | |
kwargs.update({ | |
'run_povray': True, # Run povray or just write .pov + .ini files | |
'display': False, # Display while rendering | |
'pause': True, # Pause when done rendering (only if display) | |
'transparent': False, # Transparent background | |
'canvas_width': None, # Width of canvas in pixels | |
'canvas_height': None, # Height of canvas in pixels | |
'camera_dist': 20., # Distance from camera to front atom | |
'image_plane': None, # Distance from front atom to image plane | |
'camera_type': 'perspective', # perspective, ultra_wide_angle | |
'point_lights': [], # [[loc1, color1], [loc2, color2],...] | |
'area_light': [(2., 3., 40.), # location | |
'White', # color | |
.7, .7, 3, 3], # width, height, Nlamps_x, Nlamps_y | |
'background': 'White', # color | |
'textures': None, # Length of atoms list of texture names | |
'celllinewidth': 0.03, # Radius of the cylinders representing the cell}) | |
tj = sys.argv[1] # traj file | |
atoms = read(tj) | |
bondatoms = attachbonds(atoms) | |
cell = atoms.get_cell() | |
ads = 'test.pov' | |
kwargs.update( | |
{ | |
'bondatoms': bondatoms, | |
'bondlinewidth': 0.2, | |
}) | |
write(ads, atoms, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment