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

#### Kevin

• Newbie
• Posts: 33
##### 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

• Hero Member
• Posts: 533
##### 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: 33
##### Re: Box size in Ovito scripting
« Reply #2 on: February 09, 2018, 04:53:14 PM »

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.matrixboxLo = cellSize[2][3]                                          boxHi = cellSize[2][2]                                 boxSize = boxHi - boxLo  `

#### Alexander Stukowski

• Hero Member
• Posts: 533
##### 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: 33
##### 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.