Angle (glitch?) in a crystal structure under periodic boundary conditions

Hello, I’m trying to compute all angles between elements in my (sparse) crystal. The lattice is hexagonal. I compare the angles before and after symmetry transformation of my structure (rotation by 2 * np.pi /3). My assumption is that these angles do not change with the rotation. However, it is not always the case. I attach two structures, for which my code works, and for another it produces strange numbers:

The notebook that demonstrates the issue is available by the link:
https://drive.google.com/open?id=13kxwtgHUwnos4DycB0it7le7W1aH2zzd&authuser=andrey.u%40gmail.com&usp=drive_fs

Essentially the code rotates structure 6 times and prints the computed angles.
In case of one structure the angles always the same and sum up to 180 degrees. In case of another the sum depends on the orientation. Moreover, for zero rotation the sum is 257. For rotation on (2 * np.pi) it is ~370:

0
A (X0+) B (Se) 0.11 0.21 0.17 5.12 [0 1 0]
A (X0+) C (Se) -0.11 0.46 -0.08 12.99 [0 0 0]
B (Se) C (Se) -0.21 0.25 -0.25 11.49 [0 0 0]
Angles_coord: [‘A (X0+): 138.7’, ‘B (Se): 95.2’, ‘C (Se): 23.1’] Sum: 257.0
[PeriodicSite: X0+ (-20.7371, -0.9210, -11.1593) [0.7500, 0.8333, 0.7917], PeriodicSite: Se (-12.7613, 20.2612, -12.7241) [0.8552, 0.0417, 0.9583], PeriodicSite: Se (-12.7613, 9.2096, -9.5944) [0.6448, 0.2917, 0.7083]]
1
A (X0+) B (Se) 0.11 -0.04 -0.21 5.12 [ 0 0 -1]
A (X0+) C (Se) -0.11 0.46 -0.46 12.99 [ 0 0 -1]
B (Se) C (Se) -0.21 -0.50 -0.25 11.49 [0 0 0]
Angles_coord: [‘A (X0+): 61.7’, ‘B (Se): 95.2’, ‘C (Se): 23.1’] Sum: 180.0
[PeriodicSite: X0+ (-14.3564, -17.4983, -11.1593) [0.7500, 0.9583, 0.1667], PeriodicSite: Se (-23.9274, 0.9210, -12.7241) [0.8552, 0.9167, 0.9583], PeriodicSite: Se (-14.3564, 6.4468, -9.5944) [0.6448, 0.4167, 0.7083]]
2
A (X0+) B (Se) 0.11 -0.17 0.04 5.12 [0 0 0]
A (X0+) C (Se) -0.11 0.08 -0.46 12.99 [ 0 0 -1]
B (Se) C (Se) -0.21 0.25 0.50 11.49 [0 0 0]
Angles_coord: [‘A (X0+): 138.7’, ‘B (Se): 95.2’, ‘C (Se): 135.9’] Sum: 369.7
[PeriodicSite: X0+ (-3.1903, -3.6839, -11.1593) [0.7500, 0.2083, 0.0417], PeriodicSite: Se (-1.5952, 0.9210, -12.7241) [0.8552, 0.0417, 0.0833], PeriodicSite: Se (-11.1661, 6.4468, -9.5944) [0.6448, 0.2917, 0.5833]]
3
A (X0+) B (Se) 0.11 0.21 0.17 5.12 [0 1 0]
A (X0+) C (Se) -0.11 0.46 -0.08 12.99 [0 0 0]
B (Se) C (Se) -0.21 0.25 -0.25 11.49 [0 0 0]
Angles_coord: [‘A (X0+): 138.7’, ‘B (Se): 95.2’, ‘C (Se): 135.9’] Sum: 369.7
[PeriodicSite: X0+ (-20.7371, -0.9210, -11.1593) [0.7500, 0.8333, 0.7917], PeriodicSite: Se (-12.7613, 20.2612, -12.7241) [0.8552, 0.0417, 0.9583], PeriodicSite: Se (-12.7613, 9.2096, -9.5944) [0.6448, 0.2917, 0.7083]]

I understand that maybe assumptions about angles under PBC is a bit naive, but if someone could explain it, it will be extremely helpful!

Not sure if this will help you troubleshoot but I quickly exported the rotated structures and checked the angles in VESTA. They all add up to 180 for all cases (even if you use different images), so I’d say that the code you use to calculate the angles might be the issue here.