| 1 | import unittest |
| 2 | |
| 3 | from shelxfile import Shelxfile |
| 4 | |
| 5 | |
| 6 | class TestRestraintsWarnings(unittest.TestCase): |
| 7 | def setUp(self) -> None: |
| 8 | self.maxDiff = None |
| 9 | self.shx = Shelxfile(debug=True) |
| 10 | |
| 11 | def test_class_and_number_on_restr_and_atoms_but_wrong(self): |
| 12 | self.shx.read_file('tests/resources/restraint_tests/class_and_number_on_restr_and_atoms_but_wrong.res') |
| 13 | result = self.shx._assign_atoms_to_restraints() |
| 14 | expected = ['*** Unknown atoms in restraint: SADI_CCF3 N1 N2_3 C1_0 C2, line 13 ***', |
| 15 | '*** Atom list has no --> C2_1, N2_3 ***'] |
| 16 | self.assertListEqual(expected, result) |
| 17 | |
| 18 | def test_wildcard_on_atom_names(self): |
| 19 | self.shx.read_file('tests/resources/restraint_tests/wildcard_on_atom.res') |
| 20 | result = self.shx._assign_atoms_to_restraints() |
| 21 | expected = ['*** Unknown atoms in restraint: DELU N4_* C7_*, line 15 ***', |
| 22 | '*** Atom list has no --> C7_1, N4_1 ***'] |
| 23 | self.assertListEqual(expected, result) |
| 24 | |
| 25 | def test_class_and_numbers(self): |
| 26 | self.shx.read_file('tests/resources/restraint_tests/class_and_numbers.res') |
| 27 | result = self.shx._assign_atoms_to_restraints() |
| 28 | expected = [] |
| 29 | self.assertListEqual(expected, result) |
| 30 | |
| 31 | def test_class_but_missing_atoms(self): |
| 32 | self.shx.read_file('tests/resources/restraint_tests/class_but_missing_atoms.res') |
| 33 | result = self.shx._assign_atoms_to_restraints() |
| 34 | expected = ['*** Unknown atoms in restraint: SADI_CCF3 N1 N2 C1 C2, line 13 ***', |
| 35 | '*** Atom list has no --> C1_1, C2_1 ***'] |
| 36 | self.assertListEqual(expected, result) |
| 37 | |
| 38 | def test_no_class_or_number(self): |
| 39 | self.shx.read_file('tests/resources/restraint_tests/no_class_or_number.res') |
| 40 | result = self.shx._assign_atoms_to_restraints() |
| 41 | expected = ['*** Unknown atoms in restraint: SADI N1 N2 C1 C2, line 13 ***', |
| 42 | '*** Atom list has no --> N1, N2 ***'] |
| 43 | self.assertListEqual(expected, result) |
| 44 | |
| 45 | def test_number_but_missing_atoms(self): |
| 46 | self.shx.read_file('tests/resources/restraint_tests/number_but_missing_atoms.res') |
| 47 | result = self.shx._assign_atoms_to_restraints() |
| 48 | expected = ['*** Unknown atoms in restraint: SADI_1 N1 N2 C1 C2, line 13 ***', |
| 49 | '*** Atom list has no --> C1_1, C2_1 ***'] |
| 50 | self.assertListEqual(expected, result) |
| 51 | |
| 52 | def test_number_on_restr_and_atoms(self): |
| 53 | self.shx.read_file('tests/resources/restraint_tests/number_on_restr_and_atoms.res') |
| 54 | result = self.shx._assign_atoms_to_restraints() |
| 55 | expected = [] |
| 56 | self.assertListEqual(expected, result) |
| 57 | |
| 58 | def test_number_on_restr_and_atoms_but_wrong(self): |
| 59 | self.shx.read_file('tests/resources/restraint_tests/number_on_restr_and_atoms_but_wrong.res') |
| 60 | result = self.shx._assign_atoms_to_restraints() |
| 61 | expected = ['*** Unknown atoms in restraint: SADI_2 N1 N2_3 C1_0 C2_0, line 13 ***', |
| 62 | '*** Atom list has no --> N1_2, N2_3 ***'] |
| 63 | self.assertListEqual(expected, result) |
| 64 | self.assertEqual(expected, self.shx.restraint_errors) |
| 65 | |
| 66 | def test_only_number_0_on_atoms(self): |
| 67 | shx = Shelxfile() |
| 68 | shx.read_file('tests/resources/restraint_tests/only_number_0_on_atoms.res') |
| 69 | result = shx._assign_atoms_to_restraints() |
| 70 | expected = ['*** Unknown atoms in restraint: SADI N1 N2 C1_0 C2_0, line 13 ***', |
| 71 | '*** Atom list has no --> N1, N2 ***'] |
| 72 | self.assertListEqual(expected, result) |
| 73 | self.assertEqual(expected, shx.restraint_errors) |
| 74 | |
| 75 | def test_class_with_empty_residues_no_false_positives(self): |
| 76 | """ |
| 77 | Residues 1 and 2 of class BF4 are empty (defined by RESI but have no atoms). |
| 78 | Residues 3 and 4 do have the atoms B1, F1, F2, F3, F4. |
| 79 | SHELXL silently ignores empty residues for restraint application, so there |
| 80 | should be no atom-missing warnings — only the dedicated empty-residue notice. |
| 81 | """ |
| 82 | shx = Shelxfile() |
| 83 | shx.read_file('tests/resources/restraint_tests/class_with_empty_residues.res') |
| 84 | result = shx._assign_atoms_to_restraints() |
| 85 | self.assertListEqual(['*** Empty residue(s) detected (no atoms): BF4 1, BF4 2 ***'], result) |
| 86 |