| 1 | from unittest import TestCase |
| 2 | |
| 3 | from shelxfile import Shelxfile |
| 4 | from shelxfile.misc.dsrmath import Array |
| 5 | from shelxfile.misc.misc import frac_to_cart |
| 6 | |
| 7 | |
| 8 | class TestOrthogonalMatrix(TestCase): |
| 9 | def setUp(self) -> None: |
| 10 | self.shx = Shelxfile(debug=True) |
| 11 | self.shx.read_file('tests/resources/jkd77.res') |
| 12 | |
| 13 | def test_frac_to_cart(self): |
| 14 | atom = self.shx.atoms.all_atoms[2] |
| 15 | self.assertListEqual(list(atom.cart_coords), |
| 16 | list(frac_to_cart(atom.frac_coords, list(self.shx.cell)))) |
| 17 | |
| 18 | def test_cart_to_frac(self): |
| 19 | self.assertListEqual(list(self.shx.atoms.all_atoms[2].frac_coords), |
| 20 | [round(x, 8) for x in |
| 21 | self.shx.cell.o.m.inversed * Array(self.shx.atoms.all_atoms[2].cart_coords)]) |
| 22 | |
| 23 | def test_frac_to_cart_all(self): |
| 24 | for atom in self.shx.atoms.all_atoms: |
| 25 | self.assertListEqual(list(atom.cart_coords), |
| 26 | list(frac_to_cart(atom.frac_coords, list(self.shx.cell)))) |
| 27 | |
| 28 | def test_cart_to_frac_all(self): |
| 29 | for atom in self.shx.atoms.all_atoms: |
| 30 | self.assertListEqual(list(atom.frac_coords), |
| 31 | [round(x, 9) for x in list(self.shx.cell.o.m.inversed * Array(atom.cart_coords))]) |