OVITO => Support Forum => Topic started by: Dori on January 28, 2019, 01:52:37 AM

Title: add axis labels and ticks
Post by: Dori on January 28, 2019, 01:52:37 AM
Hello everyone,

I have made a trajectory of a particle in a simulation box on OVITO [Fig.1] and I am wondering if I can add axis labels and ticks just like [Fig.2] in OVITO.

Title: Re: add axis labels and ticks
Post by: Constanze Kalcher on January 28, 2019, 10:24:46 AM
Dear Dori,

currently there is no easy way to include tics and axes labels on the simulation cell. Reproducing the appearance of your example figure would require quite some coding on your
part using the "Python-Overlay" function, here's the corresponding manual entry in case you didn't know.
http://ovito.org/manual/viewport_overlays.python_script.html (http://ovito.org/manual/viewport_overlays.python_script.html)

I think it's faster to just export the trajectories as txt files and then plot them with your usual plotting tool. That way you can easily include the axes and have more control.
That being said, if you're absolutely determined to do it in OVITO, I can help you if you run into trouble with the scripting part.

Title: Re: add axis labels and ticks
Post by: Dori on January 29, 2019, 01:00:57 AM
Dear Constanze,
Thank you so much for your helpful comment.

I decided to export a text file and then add axes and labels in Python. However, I faced a problem trying to export the file.
I selected "particle trajectories" from the "object selector". Then:
File>> Export File. Gave a name to the file and save as "Calculation results text file".
In "Export setting", I selected "sequence".For "Destination", I selected "Single file". For "Attributes to export" there was only one option and it was "frame". So I selected that and then pressed ok. However, the text file only includes the frames. May I have your opinion please?

Title: Re: add axis labels and ticks
Post by: Constanze Kalcher on January 29, 2019, 11:26:08 AM
Dear Dori,

sorry my comment about exporting the trajectories might have been misleading - currently it cannot be done through the File-Export function. However, you can simply use np.savetxt() in a python script modifier
to export the trajectories, e.g. like this:

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

def modify(frame, data):
    pos = data.trajectories_.positions_
    id = data.trajectories_.particle_ids_
    np.savetxt("trajectories.txt", np.column_stack((id, pos)), fmt = "%i %f %f %f")

The above modifier will create a file "trajectories.txt" that contains the trajectories of all atoms. Say you have 3 atoms and 5 frames, then the first 5 lines are the positions of atom 1, the next 5 the positions of atom 2 etc.
This is just a suggestions, of course you can alter the script to make it match your desired output format.

https://ovito.org/manual_testing/python/modules/ovito_data.html#ovito.data.TrajectoryLines (https://ovito.org/manual_testing/python/modules/ovito_data.html#ovito.data.TrajectoryLines)

Hope that helps,