%%capture
! pip install -U ovito
Recipe 3: Color coding grain boundary atoms
How to Script with OVITO
When you have grain boundaries it is convenient to be able to distinguish those atoms from the bulk. One way to do so is using a order or structural parameter that captures some information about the local environment. OVITO has a few different options built in that enable characterize whether an atom is in an FCC, BCC, HCP, or other structure. Here I’ll be working with the LAMMPS dump file from the example in (Bringuier 2015) which reproduces the results from (Cahn, Mishin, and Suzuki 2006).
Import OVITO modules
from ovito.io import import_file
from ovito.vis import Viewport
from ovito.modifiers import CommonNeighborAnalysisModifier, CalculateDisplacementsModifier
from ovito.modifiers import ExpressionSelectionModifier, DeleteSelectedModifier, InvertSelectionModifier
from ovito.modifiers import AssignColorModifier
from ovito.vis import VectorVis
from ovito.vis import OSPRayRenderer
Step 1: Download and import file
This LAMMPS dump file was from a 2D simulation but the symmetry is 3D so we reset the PBC for all directions. I’m doing this because I want to maintain the correct structural analysis results.
%%capture
! wget 'https://drive.google.com/uc?id=1Id0D6rfHxJOTuPx2RVAYkm2yRBBgIzSE&export=download' -O dump.Cu_Bicrystal_Shear_298K.gz
= import_file('dump.Cu_Bicrystal_Shear_298K.gz',input_format='lammps/dump')
pipeline = (True, True, True) pipeline.source.data.cell_.pbc
Step 2: Perform structural analysis and calculate displacement vectors
I will use the CommonNeighborAnalysisModifier which provides standard structural analysis to identify the closed-packing of the crystal (e.g., FCC, BCC, HCP, ICO).
Once the structure modifier is used, I will color code just the atoms that are of StructureType ==
which corresponds to “Other”. To do this we can use the modifier to select these atoms and then color code.
pipeline.modifiers.append(CommonNeighborAnalysisModifier())
# Select particles based on structure type and position
= 'StructureType != 0 || (Position.Z > CellSize.Z-5 || Position.Z < 5.0 )'
expression =expression))
pipeline.modifiers.append(ExpressionSelectionModifier(expression
# Color the selected particles
=(0.0, 0.5, 1.0)))
pipeline.modifiers.append(AssignColorModifier(color
pipeline.modifiers.append(InvertSelectionModifier())# Now color the GB atoms
=(0.8, 0.5, 0.2)))
pipeline.modifiers.append(AssignColorModifier(color
pipeline.modifiers.append(InvertSelectionModifier())
pipeline.add_to_scene()
Step 3: Render first animation
= Viewport(type=Viewport.Type.Ortho)
vp = [-1, 0, 0]
vp.camera_dir
vp.zoom_all()= OSPRayRenderer(
renderer =True,
ambient_light_enabled=True,
denoising_enabled=True,
direct_light_enabled=1.0,
direct_light_intensity=10.0,
material_shininess=0.02
material_specular_brightness
)
= "Cu_Bicrystal_Shear_298K_ColorCoding.gif"
fname =(600,400),
vp.render_anim(size=fname,
filename=renderer) renderer
The code below is to allow for displaying rendered images in Google Colab.
try:
import google.colab
from IPython.display import Image
open(fname, 'rb').read())
Image(except ImportError:
"Assuming local run."
Step 4: Displacement vectors
We may want to show how the atoms at the grain boundary are moving with respect to the shear force. We can do this with the displacement vectors. The displacement vectors are taken with respect to an previous frame offset of 25. This is used to showcase how the grain boundary atoms are moving, what you’ll see is that its in a cork-screw like manner.
Since we already have a pipeline and all we want to do is add the displacement vectors and then disable visualizing the particles themselves. I also just want to so the displacement vectors for the grain boundary atoms, so I need to delete the selected particles and then we just need to add a few additional lines of code and then re-render to a new animation file.
# Visualization object for vector arrows
= VectorVis(width=0.1,
vec_vis =1.5,
scaling=False,
flat_shading=(1,0,0))
color
= CalculateDisplacementsModifier(frame_offset=-25,
displacement_mod =True,
use_frame_offset=vec_vis)
vis= True
displacement_mod.vis.enabled
pipeline.modifiers.append(displacement_mod)
# Need this line to turn off particle visibility
# Delete elected particles
={'particles'}))
pipeline.modifiers.append(DeleteSelectedModifier(operate_on=25).particles.vis.enabled = False pipeline.compute(frame
Step 5: Render second animation
= Viewport(type=Viewport.Type.Ortho)
vp2 = [-1, 0, 0]
vp2.camera_dir
vp2.zoom_all()= "Cu_Bicrystal_Shear_298K_DisplacementVectors.gif"
fname = pipeline.source.num_frames
nframes =(600,400),
vp2.render_anim(size=fname,
filenamerange=(25,nframes),
=renderer) renderer
try:
import google.colab
from IPython.display import Image
open(fname, 'rb').read())
Image(except ImportError:
"Assuming local run."
References
Citation
@online{bringuier2024,
author = {Bringuier, Stefan},
publisher = {Github Pages},
title = {Recipe 3: {Color} Coding Grain Boundary Atoms},
date = {2024-02-22},
url = {https://stefanbringuier.github.io/HowToSOVITO},
langid = {en}
}