Mercurial > repos > galaxy-australia > alphafold2
comparison docker/alphafold/alphafold/relax/cleanup_test.py @ 1:6c92e000d684 draft
"planemo upload for repository https://github.com/usegalaxy-au/galaxy-local-tools commit a510e97ebd604a5e30b1f16e5031f62074f23e86"
author | galaxy-australia |
---|---|
date | Tue, 01 Mar 2022 02:53:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:7ae9d78b06f5 | 1:6c92e000d684 |
---|---|
1 # Copyright 2021 DeepMind Technologies Limited | |
2 # | |
3 # Licensed under the Apache License, Version 2.0 (the "License"); | |
4 # you may not use this file except in compliance with the License. | |
5 # You may obtain a copy of the License at | |
6 # | |
7 # http://www.apache.org/licenses/LICENSE-2.0 | |
8 # | |
9 # Unless required by applicable law or agreed to in writing, software | |
10 # distributed under the License is distributed on an "AS IS" BASIS, | |
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 # See the License for the specific language governing permissions and | |
13 # limitations under the License. | |
14 | |
15 """Tests for relax.cleanup.""" | |
16 import io | |
17 | |
18 from absl.testing import absltest | |
19 from alphafold.relax import cleanup | |
20 from simtk.openmm.app.internal import pdbstructure | |
21 | |
22 | |
23 def _pdb_to_structure(pdb_str): | |
24 handle = io.StringIO(pdb_str) | |
25 return pdbstructure.PdbStructure(handle) | |
26 | |
27 | |
28 def _lines_to_structure(pdb_lines): | |
29 return _pdb_to_structure('\n'.join(pdb_lines)) | |
30 | |
31 | |
32 class CleanupTest(absltest.TestCase): | |
33 | |
34 def test_missing_residues(self): | |
35 pdb_lines = ['SEQRES 1 C 3 CYS GLY LEU', | |
36 'ATOM 1 N CYS C 1 -12.262 20.115 60.959 1.00 ' | |
37 '19.08 N', | |
38 'ATOM 2 CA CYS C 1 -11.065 20.934 60.773 1.00 ' | |
39 '17.23 C', | |
40 'ATOM 3 C CYS C 1 -10.002 20.742 61.844 1.00 ' | |
41 '15.38 C', | |
42 'ATOM 4 O CYS C 1 -10.284 20.225 62.929 1.00 ' | |
43 '16.04 O', | |
44 'ATOM 5 N LEU C 3 -7.688 18.700 62.045 1.00 ' | |
45 '14.75 N', | |
46 'ATOM 6 CA LEU C 3 -7.256 17.320 62.234 1.00 ' | |
47 '16.81 C', | |
48 'ATOM 7 C LEU C 3 -6.380 16.864 61.070 1.00 ' | |
49 '16.95 C', | |
50 'ATOM 8 O LEU C 3 -6.551 17.332 59.947 1.00 ' | |
51 '16.97 O'] | |
52 input_handle = io.StringIO('\n'.join(pdb_lines)) | |
53 alterations = {} | |
54 result = cleanup.fix_pdb(input_handle, alterations) | |
55 structure = _pdb_to_structure(result) | |
56 residue_names = [r.get_name() for r in structure.iter_residues()] | |
57 self.assertCountEqual(residue_names, ['CYS', 'GLY', 'LEU']) | |
58 self.assertCountEqual(alterations['missing_residues'].values(), [['GLY']]) | |
59 | |
60 def test_missing_atoms(self): | |
61 pdb_lines = ['SEQRES 1 A 1 PRO', | |
62 'ATOM 1 CA PRO A 1 1.000 1.000 1.000 1.00 ' | |
63 ' 0.00 C'] | |
64 input_handle = io.StringIO('\n'.join(pdb_lines)) | |
65 alterations = {} | |
66 result = cleanup.fix_pdb(input_handle, alterations) | |
67 structure = _pdb_to_structure(result) | |
68 atom_names = [a.get_name() for a in structure.iter_atoms()] | |
69 self.assertCountEqual(atom_names, ['N', 'CD', 'HD2', 'HD3', 'CG', 'HG2', | |
70 'HG3', 'CB', 'HB2', 'HB3', 'CA', 'HA', | |
71 'C', 'O', 'H2', 'H3', 'OXT']) | |
72 missing_atoms_by_residue = list(alterations['missing_heavy_atoms'].values()) | |
73 self.assertLen(missing_atoms_by_residue, 1) | |
74 atoms_added = [a.name for a in missing_atoms_by_residue[0]] | |
75 self.assertCountEqual(atoms_added, ['N', 'CD', 'CG', 'CB', 'C', 'O']) | |
76 missing_terminals_by_residue = alterations['missing_terminals'] | |
77 self.assertLen(missing_terminals_by_residue, 1) | |
78 has_missing_terminal = [r.name for r in missing_terminals_by_residue.keys()] | |
79 self.assertCountEqual(has_missing_terminal, ['PRO']) | |
80 self.assertCountEqual([t for t in missing_terminals_by_residue.values()], | |
81 [['OXT']]) | |
82 | |
83 def test_remove_heterogens(self): | |
84 pdb_lines = ['SEQRES 1 A 1 GLY', | |
85 'ATOM 1 CA GLY A 1 0.000 0.000 0.000 1.00 ' | |
86 ' 0.00 C', | |
87 'ATOM 2 O HOH A 2 0.000 0.000 0.000 1.00 ' | |
88 ' 0.00 O'] | |
89 input_handle = io.StringIO('\n'.join(pdb_lines)) | |
90 alterations = {} | |
91 result = cleanup.fix_pdb(input_handle, alterations) | |
92 structure = _pdb_to_structure(result) | |
93 self.assertCountEqual([res.get_name() for res in structure.iter_residues()], | |
94 ['GLY']) | |
95 self.assertEqual(alterations['removed_heterogens'], set(['HOH'])) | |
96 | |
97 def test_fix_nonstandard_residues(self): | |
98 pdb_lines = ['SEQRES 1 A 1 DAL', | |
99 'ATOM 1 CA DAL A 1 0.000 0.000 0.000 1.00 ' | |
100 ' 0.00 C'] | |
101 input_handle = io.StringIO('\n'.join(pdb_lines)) | |
102 alterations = {} | |
103 result = cleanup.fix_pdb(input_handle, alterations) | |
104 structure = _pdb_to_structure(result) | |
105 residue_names = [res.get_name() for res in structure.iter_residues()] | |
106 self.assertCountEqual(residue_names, ['ALA']) | |
107 self.assertLen(alterations['nonstandard_residues'], 1) | |
108 original_res, new_name = alterations['nonstandard_residues'][0] | |
109 self.assertEqual(original_res.id, '1') | |
110 self.assertEqual(new_name, 'ALA') | |
111 | |
112 def test_replace_met_se(self): | |
113 pdb_lines = ['SEQRES 1 A 1 MET', | |
114 'ATOM 1 SD MET A 1 0.000 0.000 0.000 1.00 ' | |
115 ' 0.00 Se'] | |
116 structure = _lines_to_structure(pdb_lines) | |
117 alterations = {} | |
118 cleanup._replace_met_se(structure, alterations) | |
119 sd = [a for a in structure.iter_atoms() if a.get_name() == 'SD'] | |
120 self.assertLen(sd, 1) | |
121 self.assertEqual(sd[0].element_symbol, 'S') | |
122 self.assertCountEqual(alterations['Se_in_MET'], [sd[0].residue_number]) | |
123 | |
124 def test_remove_chains_of_length_one(self): | |
125 pdb_lines = ['SEQRES 1 A 1 GLY', | |
126 'ATOM 1 CA GLY A 1 0.000 0.000 0.000 1.00 ' | |
127 ' 0.00 C'] | |
128 structure = _lines_to_structure(pdb_lines) | |
129 alterations = {} | |
130 cleanup._remove_chains_of_length_one(structure, alterations) | |
131 chains = list(structure.iter_chains()) | |
132 self.assertEmpty(chains) | |
133 self.assertCountEqual(alterations['removed_chains'].values(), [['A']]) | |
134 | |
135 | |
136 if __name__ == '__main__': | |
137 absltest.main() |