Author Topic: Box size in Ovito scripting  (Read 381 times)

Kevin

  • Newbie
  • *
  • Posts: 32
Box size in Ovito scripting
« on: February 08, 2018, 03:33:32 AM »
Dear Dr. Stukowski,

Attached is the image of 'Simulation cell' panel from ovito.
It seems like there is no function(?) to access Box sizes of simulation cell on scripting.
I could calculate this from "Cell geometry" but was wondering if there is a function to retrieve box size directly since it is offered in the OVITO GUI.

-Kevin

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 476
Re: Box size in Ovito scripting
« Reply #1 on: February 08, 2018, 09:00:39 AM »
Kevin,
It is possible to access the cell vectors using the Python scripting interface. See the ovito.data.SimulationCell class and the included code example:

http://ovito.org/manual/python/modules/ovito_data.html#ovito.data.SimulationCell

Kevin

  • Newbie
  • *
  • Posts: 32
Re: Box size in Ovito scripting
« Reply #2 on: February 09, 2018, 04:53:14 PM »
Thank you for the reply.


Yes I could use cell vector and then calculate box size using elements in the cell vector as follows:
I was just wondering if there is a function that directly retrieves box size rather than cell vector.


Code: [Select]
cell = node.source.cell                                               
cellSize = cell.matrix
boxLo = cellSize[2][3]                                         
boxHi = cellSize[2][2]                                 
boxSize = boxHi - boxLo 

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 476
Re: Box size in Ovito scripting
« Reply #3 on: February 09, 2018, 05:31:57 PM »
I see, you are interested in the dimensions of an orthogonal (axis-aligned) simulation cell. In this case, simply take the diagonal elements of the cell matrix:

Code: [Select]
box_size = numpy.diagonal(node.source.cell.matrix)
print("Size X: ", box_size[0])
print("Size Y: ", box_size[1])
print("Size Z: ", box_size[2])

Kevin

  • Newbie
  • *
  • Posts: 32
Re: Box size in Ovito scripting
« Reply #4 on: February 09, 2018, 05:43:27 PM »
Ahh I see. I just have to use the cell vector anyways. (Since Ovito GUI provides 'Width', 'Length' and 'Height' of box, I thought there may be a function that retrieves the box size, which I couldn't locate on the OVITO documentation. I guess the GUI provides box sizes using by calculating elements in the cell vector.)

PS. By the way, I think the cell origin has to be considered to get the exact box size(unless it's 0).

Thank you again for answering this somewhat trivial question.

Alexander Stukowski

  • Administrator
  • Sr. Member
  • *****
  • Posts: 476
Re: Box size in Ovito scripting
« Reply #5 on: February 09, 2018, 05:50:55 PM »
Yes, the box size values ("Width", "Height", "Length") shown in the GUI are implicitly computed from the cell vectors (or, equivalently, the cell matrix). They are not independent parameters.

The cell origin (stored in the 4th column of the extended cell matrix) is not related to the box size nor the three cell vectors. That means you can ignore it if you are just interested in the size of the box. Note that this is different from the convention used by LAMMPS, which uses a "low boundary + high boundary" representation of the box. OVITO uses an "origin+size" representation instead.
« Last Edit: February 09, 2018, 10:01:41 PM by Alexander Stukowski »