Failing to export a system with rotation matrix applied

Hi, I am rotating a system by using the rotation matrix in Affine Tranformation. Everything looks perfect on screen but when I export the file with the expectation of saving the updated(rotated) coordinates of the system, it gives the original system back in that exported file. Is it a bug, or I am doing it incorrectly?
Thank you.

Hi,
The export results will depend on the file format you’ve picked. If you export to any LAMMPS format (dump or data), OVITO will rotate the simulation cell back to an axis-aligned configuration. That’s because the LAMMPS simulation code (and its file formats) are subject to certain restrictions of the cell vectors. The first cell vector, for example, must always be aligned with the x-axis of the simulation coordinate system, see here. In order to produce a valid output file, OVITO will perform an automatic transformation of the simulation cell and the contained atoms during export if necessary. That transformation might exactly reverse the rotation you have previously applied using the Affine Transformation modifier.

Are you saying it is impossible to do this simple task in Ovito? specially when the rotation is 180 degrees ( like a flip in z direction).

The answer depends on what exactly you want to achieve.

In OVITO, the simulation cell is a general parallelepiped formed by an origin point and three vectors (a,b,c) that span the 3d cell. OVITO puts no restrictions on the directions of the three cell vectors. The only requirement is that they must not be collinear.

The most common configuration for the three cell vectors is that vector a points in the positive X-direction, b in the positive Y-direction, and c in the positive Z-direction (of the global Cartesian coordinate system), but OVITO does not really care.

Atom and particle coordinates are always specified in the global Cartesian coordinate system and do not depend on the cell’s geometry.

The Affine Transformation modifier of OVITO lets you apply an arbitrary affine transformation (translate/rotate/scale/shear/mirror) to the simulation cell geometry, the particle coordinates, or both.

So my question to you would be: Do you want to rotate just the particles in the simulation box by 180° or the directions of the cell vectors too? If you rotate the cell too, the cell vector c will point along the negative Z-axis, for example.

I assume you then want to export the result to an output file, for example to run an MD simulation. This is where it gets tricky, because some file formats and simulation codes are limited to certain kinds of simulation cells (mostly for performance reasons).

Back in 2020, when I wrote the forum post above, LAMMPS could only handle restricted triclinic boxes, and the LAMMPS data file format could only store such restricted boxes. You can read what the constraints of restricted triclinic boxes are in this section of the LAMMPS user manual. But LAMMPS nowadays supports general triclinic simulation cells like OVITO does, so things have changed for the better.

OVITO still exports models in this restricted representation by default to be backward compatible with older LAMMPS versions. During the export process, a general OVITO triclinic cell and its contents are automatically rotated in order to make it compatible with the restricted LAMMPS form. This automatic correction may look as if an affine transformation that you have applied in OVITO is being reversed.

After LAMMPS introduced support for general triclinic boxes some time ago, we have adapted the data file exporter of OVITO. It now offers the user a choice between the two formats, and general triclinic cells from OVITO can be exported to LAMMPS as-is. Internally, LAMMPS still works with the restricted cell format, but the conversion happens transparently to the user during the file input and output steps of the MD simulation.