Author Topic: Theta evolution vs. Frame  (Read 264 times)

akhoursh

  • Newbie
  • *
  • Posts: 13
Theta evolution vs. Frame
« on: September 17, 2018, 09:14:46 PM »
Dear OVITO users,
Hi,

I want to draw the diagram showing the evolution of angle formed by 3 specific atoms, i.e. particle identifier = 3493 , 1805, and 1813 through the time, i.e. Theta vs. Frame. It should probably  be done via Python scripting I guess. I wonder if you could please help me out.

Thanks in advance,
Ali

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 121
Re: Theta evolution vs. Frame
« Reply #1 on: September 18, 2018, 02:37:47 PM »
Hi Ali,

here is one possible example for an OVITO batch script that uses a python modifier function to calculate the angle between three specified particles at every simulation frame and saves that information as a global attribute. Finally the time evolution of the angle is saved in a textfile "theta.txt".
I'll leave it up to you to finish the part with the particle indices since I didn't know which of these atoms was supposed to be the central atom.

Code: [Select]
from ovito.io import *
from ovito.modifiers import *
from ovito.data import *
import numpy as np

#User defined modifier funtion to calculate the angle between particles 3493, 1805 and 1813                                                                                                                                                                                                             
def compute_theta(frame, input, output):
   
    #Get particle indices from Particle Identifiers           
    particle_identifiers = input.particles["Particle Identifier"]                                                                                                                                                                   
    central_particle_index = np.where(particle_identifiers == 3493)[0][0]
    neighbor_1_index = ...
    neighbor_2_index = ...

    #Calculate the distance vectors                                                                                                                                                                 
    positions = input.particles['Position']
    dist_1 =  positions[neighbor_1_index] - positions[central_particle_index]
    dist_2 =  positions[neighbor_2_index] - positions[central_particle_index]

    #Get the angle                                                                                                                                                                                                                 
    cos_theta = np.dot(dist_1,dist_2)/np.linalg.norm(dist_1)/np.linalg.norm(dist_2)
    theta = np.arccos(cos_theta)

    #Save as global attribute                                                                                                                                                                                                     
    output.attributes['theta'] = np.degrees(theta)

# Load the simulation dataset to be analyzed.                                                                                                                                                                                     
pipeline = import_file("simulation.dump")
pipeline.modifiers.append(PythonScriptModifier(function = compute_theta))

# Export calculated theta values to a text file and let OVITO's data pipeline do the rest:                                                                                                                                           
export_file(pipeline, "theta.txt", format = "txt", columns = ["Timestep", "theta"], multiple_frames = True)

Let me know if that works for you and if you have questions.

Edit: Also note that I was assuming you're using OVITO3.

-Constanze

« Last Edit: September 18, 2018, 02:53:28 PM by Constanze Kalcher »