From 3c8282512e45cc5d1c12f33a4ddac162062bb1fe Mon Sep 17 00:00:00 2001 From: mgiulini Date: Wed, 8 Feb 2023 15:27:05 +0100 Subject: [PATCH 01/12] first draft of solution to selaltloc bug --- pdbtools/pdb_selaltloc.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/pdbtools/pdb_selaltloc.py b/pdbtools/pdb_selaltloc.py index 70676721..a8ca489d 100644 --- a/pdbtools/pdb_selaltloc.py +++ b/pdbtools/pdb_selaltloc.py @@ -307,15 +307,30 @@ def flush_resloc_occ(altloc_lines, **kw): # detects which altloc identifier has the highest occupancy for key, lines2flush in altloc_lines.items(): + if key == ' ': + continue # we check only the first line because all atoms in one identifier # should have the same occupancy value occ = float(lines2flush[0][54:60]) + if occ > highest: altloc = key highest = occ - for line2flush in altloc_lines[altloc]: - yield line2flush[:16] + ' ' + line2flush[17:] + if ' ' in altloc_lines.keys(): + # here we concatenate atoms with no altloc with the + # atoms with the highest altloc + output_lines = {' ': altloc_lines[' '] + altloc_lines[altloc]} + sorted_atoms = _get_sort_atoms(output_lines) + for atom, linet in sorted_atoms: + lines = linet[1] + for line in lines: + yield line[:16] + ' ' + line[17:] + else: + # only alternate locations. Just yield all those lines + output_lines = altloc_lines[altloc] + for line2flush in altloc_lines[altloc]: + yield line2flush[:16] + ' ' + line2flush[17:] def flush_resloc_id_same_residue(selloc, altloc_lines): From e172b64d5a3b5fc3620863a2f07842a858db7644 Mon Sep 17 00:00:00 2001 From: mgiulini Date: Wed, 8 Feb 2023 18:13:00 +0100 Subject: [PATCH 02/12] added test to selaltloc --- tests/data/pdb4xoj-small.pdb | 120 +++++++++++++++++++++++++++++++++++ tests/test_pdb_selaltloc.py | 99 +++++++++++++++++++++++++++++ 2 files changed, 219 insertions(+) create mode 100644 tests/data/pdb4xoj-small.pdb diff --git a/tests/data/pdb4xoj-small.pdb b/tests/data/pdb4xoj-small.pdb new file mode 100644 index 00000000..340f13a7 --- /dev/null +++ b/tests/data/pdb4xoj-small.pdb @@ -0,0 +1,120 @@ +ATOM 511 N SER A 81 -2.125 6.104 21.775 1.00 8.48 N +ANISOU 511 N SER A 81 1227 964 1028 -36 224 13 N +ATOM 512 CA SER A 81 -1.772 4.741 22.205 1.00 8.74 C +ANISOU 512 CA SER A 81 1233 1007 1077 11 199 56 C +ATOM 513 C SER A 81 -2.262 3.698 21.215 1.00 8.42 C +ANISOU 513 C SER A 81 1167 989 1041 -75 90 138 C +ATOM 514 O SER A 81 -3.353 3.829 20.638 1.00 9.44 O +ANISOU 514 O SER A 81 1153 1058 1375 -48 41 62 O +ATOM 515 CB SER A 81 -2.424 4.479 23.564 1.00 10.45 C +ANISOU 515 CB SER A 81 1683 1191 1094 -49 249 19 C +ATOM 516 OG SER A 81 -1.889 5.387 24.506 1.00 13.63 O +ANISOU 516 OG SER A 81 2449 1531 1199 -52 258 -6 O +ATOM 517 N AALA A 82 -1.494 2.619 21.079 0.50 8.56 N +ANISOU 517 N AALA A 82 1205 991 1055 55 81 1 N +ATOM 518 N BALA A 82 -1.502 2.619 21.093 0.50 8.57 N +ANISOU 518 N BALA A 82 1221 989 1047 51 73 3 N +ATOM 519 CA AALA A 82 -2.054 1.440 20.442 0.50 8.66 C +ANISOU 519 CA AALA A 82 1292 950 1046 -2 73 22 C +ATOM 520 CA BALA A 82 -2.004 1.455 20.381 0.50 9.05 C +ANISOU 520 CA BALA A 82 1452 961 1024 -102 -44 33 C +ATOM 521 C AALA A 82 -3.189 0.918 21.328 0.50 8.99 C +ANISOU 521 C AALA A 82 1375 993 1045 73 344 138 C +ATOM 522 C BALA A 82 -3.028 0.721 21.197 0.50 9.88 C +ANISOU 522 C BALA A 82 1773 960 1018 -222 -222 -32 C +ATOM 523 O AALA A 82 -3.041 0.736 22.520 0.80 10.64 O +ANISOU 523 O AALA A 82 1631 1389 1020 -117 191 98 O +ATOM 524 O BALA A 82 -2.558 0.035 22.148 0.20 9.90 O +ANISOU 524 O BALA A 82 1963 1076 722 -39 43 189 O +ATOM 525 CB AALA A 82 -0.983 0.385 20.289 0.50 8.83 C +ANISOU 525 CB AALA A 82 1351 1028 974 41 216 30 C +ATOM 526 CB BALA A 82 -0.809 0.503 20.120 0.50 11.15 C +ANISOU 526 CB BALA A 82 1719 1117 1399 107 -281 -110 C +ATOM 527 N SER A 83 -4.261 0.519 20.678 1.00 9.47 N +ANISOU 527 N SER A 83 1432 1102 1061 -125 244 55 N +ATOM 528 CA ASER A 83 -5.308 -0.275 21.345 0.70 10.42 C +ANISOU 528 CA ASER A 83 1524 1180 1256 61 497 220 C +ATOM 529 CA BSER A 83 -5.296 -0.225 21.292 0.30 9.99 C +ANISOU 529 CA BSER A 83 1473 1149 1171 -81 344 -232 C +ATOM 530 C SER A 83 -5.324 -1.728 20.924 1.00 10.39 C +ANISOU 530 C SER A 83 1457 1076 1412 -6 466 118 C +ATOM 531 O SER A 83 -5.811 -2.551 21.683 1.00 12.89 O +ANISOU 531 O SER A 83 2075 1194 1628 -49 830 133 O +ATOM 532 CB ASER A 83 -6.691 0.285 21.121 0.70 11.38 C +ANISOU 532 CB ASER A 83 1538 1167 1615 116 448 25 C +ATOM 533 CB BSER A 83 -6.610 0.424 20.946 0.30 12.23 C +ANISOU 533 CB BSER A 83 1463 1397 1784 -157 274 -151 C +ATOM 534 OG ASER A 83 -6.965 0.397 19.729 0.70 11.09 O +ANISOU 534 OG ASER A 83 1338 1455 1418 106 285 72 O +ATOM 535 OG BSER A 83 -7.621 -0.353 21.495 0.30 20.97 O +ANISOU 535 OG BSER A 83 2290 2191 3486 -53 1535 585 O +ATOM 536 N LYS A 84 -4.827 -2.055 19.735 1.00 9.68 N +ANISOU 536 N LYS A 84 1326 1010 1339 101 429 46 N +ATOM 537 CA ALYS A 84 -4.644 -3.431 19.279 0.70 10.05 C +ANISOU 537 CA ALYS A 84 1522 1007 1287 42 336 144 C +ATOM 538 CA BLYS A 84 -4.643 -3.451 19.329 0.30 10.14 C +ANISOU 538 CA BLYS A 84 1491 993 1368 139 550 68 C +ATOM 539 C LYS A 84 -3.278 -3.508 18.640 1.00 9.20 C +ANISOU 539 C LYS A 84 1375 1055 1064 95 218 67 C +ATOM 540 O LYS A 84 -2.951 -2.592 17.884 1.00 9.59 O +ANISOU 540 O LYS A 84 1298 1105 1241 165 244 147 O +ATOM 541 CB ALYS A 84 -5.744 -3.907 18.283 0.70 10.32 C +ANISOU 541 CB ALYS A 84 1408 1097 1416 -68 49 -77 C +ATOM 542 CB BLYS A 84 -5.751 -3.940 18.359 0.30 11.80 C +ANISOU 542 CB BLYS A 84 1533 1237 1712 95 111 84 C +ATOM 543 CG ALYS A 84 -7.150 -3.728 18.755 0.70 12.75 C +ANISOU 543 CG ALYS A 84 1483 1417 1942 -138 412 254 C +ATOM 544 CG BLYS A 84 -7.189 -3.845 18.791 0.30 12.58 C +ANISOU 544 CG BLYS A 84 1623 1474 1683 204 124 -240 C +ATOM 545 CD ALYS A 84 -8.204 -4.287 17.849 0.70 14.48 C +ANISOU 545 CD ALYS A 84 1679 1886 1936 -324 273 150 C +ATOM 546 CD BLYS A 84 -8.139 -4.069 17.666 0.30 12.72 C +ANISOU 546 CD BLYS A 84 1610 888 2335 -136 -285 -181 C +ATOM 547 CE ALYS A 84 -9.569 -4.039 18.445 0.70 21.19 C +ANISOU 547 CE ALYS A 84 1246 3570 3235 -471 223 759 C +ATOM 548 CE BLYS A 84 -9.604 -4.051 18.097 0.30 16.57 C +ANISOU 548 CE BLYS A 84 2201 1973 2122 -543 402 -985 C +ATOM 549 NZ ALYS A 84 -10.614 -4.841 17.764 0.70 22.64 N +ANISOU 549 NZ ALYS A 84 2289 3604 2707 -1098 686 -21 N +ATOM 550 NZ BLYS A 84 -9.825 -4.761 19.395 0.30 16.91 N +ANISOU 550 NZ BLYS A 84 1927 1989 2508 -957 607 -278 N +ATOM 551 N ASER A 85 -2.563 -4.588 18.881 0.50 9.32 N +ANISOU 551 N ASER A 85 1536 976 1028 171 216 66 N +ATOM 552 N BSER A 85 -2.513 -4.566 18.859 0.50 9.48 N +ANISOU 552 N BSER A 85 1610 922 1068 188 342 63 N +ATOM 553 CA ASER A 85 -1.332 -4.882 18.202 0.50 8.74 C +ANISOU 553 CA ASER A 85 1455 1080 786 116 49 -76 C +ATOM 554 CA BSER A 85 -1.229 -4.752 18.163 0.50 9.42 C +ANISOU 554 CA BSER A 85 1467 1050 1060 398 267 26 C +ATOM 555 C ASER A 85 -1.483 -6.317 17.695 0.50 9.92 C +ANISOU 555 C ASER A 85 1752 836 1179 282 208 -106 C +ATOM 556 C BSER A 85 -1.244 -6.199 17.691 0.50 8.70 C +ANISOU 556 C BSER A 85 1254 1236 813 315 160 171 C +ATOM 557 O ASER A 85 -1.652 -7.279 18.484 0.50 11.61 O +ANISOU 557 O ASER A 85 2551 941 916 222 215 86 O +ATOM 558 O BSER A 85 -1.048 -7.069 18.528 0.50 10.44 O +ANISOU 558 O BSER A 85 1973 1010 981 389 -113 130 O +ATOM 559 CB ASER A 85 -0.160 -4.700 19.129 0.50 12.48 C +ANISOU 559 CB ASER A 85 1350 1725 1666 185 -278 -2 C +ATOM 560 CB BSER A 85 -0.049 -4.451 19.125 0.50 12.99 C +ANISOU 560 CB BSER A 85 2150 1600 1183 804 -217 -517 C +ATOM 561 OG ASER A 85 -0.049 -3.356 19.526 0.50 16.00 O +ANISOU 561 OG ASER A 85 1752 2069 2256 354 -901 -970 O +ATOM 562 OG BSER A 85 -0.099 -3.127 19.634 0.50 16.22 O +ANISOU 562 OG BSER A 85 2356 1937 1869 867 -163 -876 O +ATOM 563 N ILE A 86 -1.504 -6.433 16.390 1.00 7.88 N +ANISOU 563 N ILE A 86 1184 936 872 61 178 65 N +ATOM 564 CA ILE A 86 -1.872 -7.694 15.783 1.00 7.95 C +ANISOU 564 CA ILE A 86 1192 863 963 -21 192 154 C +ATOM 565 C ILE A 86 -0.722 -8.196 14.932 1.00 7.58 C +ANISOU 565 C ILE A 86 1181 748 949 -103 205 87 C +ATOM 566 O ILE A 86 -0.535 -7.767 13.777 1.00 8.17 O +ANISOU 566 O ILE A 86 1249 887 967 -55 242 135 O +ATOM 567 CB ILE A 86 -3.164 -7.571 14.969 1.00 8.30 C +ANISOU 567 CB ILE A 86 1190 920 1043 -32 175 224 C +ATOM 568 CG1 ILE A 86 -4.302 -7.000 15.799 1.00 9.14 C +ANISOU 568 CG1 ILE A 86 1182 1078 1211 15 159 194 C +ATOM 569 CG2 ILE A 86 -3.524 -8.934 14.351 1.00 8.71 C +ANISOU 569 CG2 ILE A 86 1228 984 1097 -91 80 176 C +ATOM 570 CD1 ILE A 86 -5.630 -6.861 15.071 1.00 10.85 C +ANISOU 570 CD1 ILE A 86 1307 1331 1482 31 162 271 C \ No newline at end of file diff --git a/tests/test_pdb_selaltloc.py b/tests/test_pdb_selaltloc.py index 085376ad..59bab979 100644 --- a/tests/test_pdb_selaltloc.py +++ b/tests/test_pdb_selaltloc.py @@ -869,6 +869,105 @@ def test_captures_previous_residue_maxocc_B(self): "ATOM 201 CB GLY A 22 -7.405 -25.428 33.847 0.60 0.00 C ", ] ) + + def test_handle_multiple_residues(self): + """ + pdb_selaltloc data/pdb4xoj-small.pdb. + + The test checks that the SER85 residue is not removed by pdb_selaltloc + as it happened until version 2.5.0. + """ + sys.argv = ['', os.path.join(data_dir, 'pdb4xoj-small.pdb')] + print("executing") + self.exec_module() + self.assertEqual(self.retcode, 0) + self.assertEqual(len(self.stdout), 80) + self.assertEqual(len(self.stderr), 0) + self.assertEqual( + self.stdout, + [ + "ATOM 511 N SER A 81 -2.125 6.104 21.775 1.00 8.48 N ", + "ANISOU 511 N SER A 81 1227 964 1028 -36 224 13 N ", + "ATOM 512 CA SER A 81 -1.772 4.741 22.205 1.00 8.74 C ", + "ANISOU 512 CA SER A 81 1233 1007 1077 11 199 56 C ", + "ATOM 513 C SER A 81 -2.262 3.698 21.215 1.00 8.42 C ", + "ANISOU 513 C SER A 81 1167 989 1041 -75 90 138 C ", + "ATOM 514 O SER A 81 -3.353 3.829 20.638 1.00 9.44 O ", + "ANISOU 514 O SER A 81 1153 1058 1375 -48 41 62 O ", + "ATOM 515 CB SER A 81 -2.424 4.479 23.564 1.00 10.45 C ", + "ANISOU 515 CB SER A 81 1683 1191 1094 -49 249 19 C ", + "ATOM 516 OG SER A 81 -1.889 5.387 24.506 1.00 13.63 O ", + "ANISOU 516 OG SER A 81 2449 1531 1199 -52 258 -6 O ", + "ATOM 517 N ALA A 82 -1.494 2.619 21.079 0.50 8.56 N ", + "ANISOU 517 N ALA A 82 1205 991 1055 55 81 1 N ", + "ATOM 519 CA ALA A 82 -2.054 1.440 20.442 0.50 8.66 C ", + "ANISOU 519 CA ALA A 82 1292 950 1046 -2 73 22 C ", + "ATOM 521 C ALA A 82 -3.189 0.918 21.328 0.50 8.99 C ", + "ANISOU 521 C ALA A 82 1375 993 1045 73 344 138 C ", + "ATOM 523 O ALA A 82 -3.041 0.736 22.520 0.80 10.64 O ", + "ANISOU 523 O ALA A 82 1631 1389 1020 -117 191 98 O ", + "ATOM 525 CB ALA A 82 -0.983 0.385 20.289 0.50 8.83 C ", + "ANISOU 525 CB ALA A 82 1351 1028 974 41 216 30 C ", + "ATOM 527 N SER A 83 -4.261 0.519 20.678 1.00 9.47 N ", + "ANISOU 527 N SER A 83 1432 1102 1061 -125 244 55 N ", + "ATOM 528 CA SER A 83 -5.308 -0.275 21.345 0.70 10.42 C ", + "ANISOU 528 CA SER A 83 1524 1180 1256 61 497 220 C ", + "ATOM 530 C SER A 83 -5.324 -1.728 20.924 1.00 10.39 C ", + "ANISOU 530 C SER A 83 1457 1076 1412 -6 466 118 C ", + "ATOM 531 O SER A 83 -5.811 -2.551 21.683 1.00 12.89 O ", + "ANISOU 531 O SER A 83 2075 1194 1628 -49 830 133 O ", + "ATOM 532 CB SER A 83 -6.691 0.285 21.121 0.70 11.38 C ", + "ANISOU 532 CB SER A 83 1538 1167 1615 116 448 25 C ", + "ATOM 534 OG SER A 83 -6.965 0.397 19.729 0.70 11.09 O ", + "ANISOU 534 OG SER A 83 1338 1455 1418 106 285 72 O ", + "ATOM 536 N LYS A 84 -4.827 -2.055 19.735 1.00 9.68 N ", + "ANISOU 536 N LYS A 84 1326 1010 1339 101 429 46 N ", + "ATOM 537 CA LYS A 84 -4.644 -3.431 19.279 0.70 10.05 C ", + "ANISOU 537 CA LYS A 84 1522 1007 1287 42 336 144 C ", + "ATOM 539 C LYS A 84 -3.278 -3.508 18.640 1.00 9.20 C ", + "ANISOU 539 C LYS A 84 1375 1055 1064 95 218 67 C ", + "ATOM 540 O LYS A 84 -2.951 -2.592 17.884 1.00 9.59 O ", + "ANISOU 540 O LYS A 84 1298 1105 1241 165 244 147 O ", + "ATOM 541 CB LYS A 84 -5.744 -3.907 18.283 0.70 10.32 C ", + "ANISOU 541 CB LYS A 84 1408 1097 1416 -68 49 -77 C ", + "ATOM 543 CG LYS A 84 -7.150 -3.728 18.755 0.70 12.75 C ", + "ANISOU 543 CG LYS A 84 1483 1417 1942 -138 412 254 C ", + "ATOM 545 CD LYS A 84 -8.204 -4.287 17.849 0.70 14.48 C ", + "ANISOU 545 CD LYS A 84 1679 1886 1936 -324 273 150 C ", + "ATOM 547 CE LYS A 84 -9.569 -4.039 18.445 0.70 21.19 C ", + "ANISOU 547 CE LYS A 84 1246 3570 3235 -471 223 759 C ", + "ATOM 549 NZ LYS A 84 -10.614 -4.841 17.764 0.70 22.64 N ", + "ANISOU 549 NZ LYS A 84 2289 3604 2707 -1098 686 -21 N ", + "ATOM 551 N SER A 85 -2.563 -4.588 18.881 0.50 9.32 N ", + "ANISOU 551 N SER A 85 1536 976 1028 171 216 66 N ", + "ATOM 553 CA SER A 85 -1.332 -4.882 18.202 0.50 8.74 C ", + "ANISOU 553 CA SER A 85 1455 1080 786 116 49 -76 C ", + "ATOM 555 C SER A 85 -1.483 -6.317 17.695 0.50 9.92 C ", + "ANISOU 555 C SER A 85 1752 836 1179 282 208 -106 C ", + "ATOM 557 O SER A 85 -1.652 -7.279 18.484 0.50 11.61 O ", + "ANISOU 557 O SER A 85 2551 941 916 222 215 86 O ", + "ATOM 559 CB SER A 85 -0.160 -4.700 19.129 0.50 12.48 C ", + "ANISOU 559 CB SER A 85 1350 1725 1666 185 -278 -2 C ", + "ATOM 561 OG SER A 85 -0.049 -3.356 19.526 0.50 16.00 O ", + "ANISOU 561 OG SER A 85 1752 2069 2256 354 -901 -970 O ", + "ATOM 563 N ILE A 86 -1.504 -6.433 16.390 1.00 7.88 N ", + "ANISOU 563 N ILE A 86 1184 936 872 61 178 65 N ", + "ATOM 564 CA ILE A 86 -1.872 -7.694 15.783 1.00 7.95 C ", + "ANISOU 564 CA ILE A 86 1192 863 963 -21 192 154 C ", + "ATOM 565 C ILE A 86 -0.722 -8.196 14.932 1.00 7.58 C ", + "ANISOU 565 C ILE A 86 1181 748 949 -103 205 87 C ", + "ATOM 566 O ILE A 86 -0.535 -7.767 13.777 1.00 8.17 O ", + "ANISOU 566 O ILE A 86 1249 887 967 -55 242 135 O ", + "ATOM 567 CB ILE A 86 -3.164 -7.571 14.969 1.00 8.30 C ", + "ANISOU 567 CB ILE A 86 1190 920 1043 -32 175 224 C ", + "ATOM 568 CG1 ILE A 86 -4.302 -7.000 15.799 1.00 9.14 C ", + "ANISOU 568 CG1 ILE A 86 1182 1078 1211 15 159 194 C ", + "ATOM 569 CG2 ILE A 86 -3.524 -8.934 14.351 1.00 8.71 C ", + "ANISOU 569 CG2 ILE A 86 1228 984 1097 -91 80 176 C ", + "ATOM 570 CD1 ILE A 86 -5.630 -6.861 15.071 1.00 10.85 C ", + "ANISOU 570 CD1 ILE A 86 1307 1331 1482 31 162 271 C " + ] + ) def test_file_not_found(self): From 9669693bf016bc0430fdf8555692889b091aa686 Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Wed, 29 Mar 2023 12:34:44 +0200 Subject: [PATCH 03/12] Working beta TODO: confirm tests --- pdbtools/pdb_selaltloc.py | 99 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 4 deletions(-) diff --git a/pdbtools/pdb_selaltloc.py b/pdbtools/pdb_selaltloc.py index 70676721..bbcdef02 100644 --- a/pdbtools/pdb_selaltloc.py +++ b/pdbtools/pdb_selaltloc.py @@ -41,6 +41,7 @@ """ import os import sys +from pprint import pprint if sys.version[0] == '2': from collections import OrderedDict as dict @@ -441,11 +442,101 @@ def run(fhandle, option=None): See `pdb_selaltloc.select_by_occupancy` and `pdb_selaltloc.select_by_altloc` for more details. """ - if option is None: - return select_by_occupancy(fhandle) + records = ('ATOM', 'HETATM', 'ANISOU') + register = dict() + chain = None + nline = 0 + for line in fhandle: + nline += 1 - else: - return select_by_altloc(fhandle, option) + if line.startswith(records): + + resnum = line[22:26].strip() + atomname = line[12:16] + altloc = line[16] + chain = line[21:22] + + if chain != prev_chain: + for _line in _flush(register, option): + yield _line + # Python 2.7 compatibility. Do not use .clear() method + del register + register = dict() + + resnum_d = register.setdefault(resnum, {}) + atomname_d = resnum_d.setdefault(atomname, {}) + altloc_d = atomname_d.setdefault(altloc, []) + + altloc_d.append((nline, line)) + + elif line.startswith('MODEL'): + #flush + for _line in _flush(register, option): + yield _line + del register + register = dict() + yield line + + else: # the end of some section + for _line in _flush(register, option): + yield _line + del register + register = dict() + yield line + + prev_chain = chain + + for _line in _flush(register, option): + yield _line + + + + +def _flush(register, option): + lines_to_yield = [] + select_by_occupancy = option is None + + atom_lines = ('ATOM', 'HETATM') + anisou_lines = ('ANISOU',) + + for resnum, atomnames in register.items(): + + for atomname, altlocs in atomnames.items(): + + if select_by_occupancy: + # DONE + + all_lines = [] + for altloc, lines in altlocs.items(): + all_lines.extend(lines) + + new = {} + for line_number, line in all_lines: + if line.startswith(atom_lines): + occupancy_number = line[54:60] + list_ = new.setdefault(occupancy_number, []) + list_.append((line_number, line)) + elif line.startswith(anisou_lines): + list_.append((line_number, line)) + + keys_ = sorted(new.keys(), key=lambda x: float(x.strip()), reverse=True) + lines_to_yield.extend(new[keys_[0]]) + + del all_lines + del new + + # selected by otion: + else: + if option in altlocs: + lines_to_yield.extend(altlocs[option]) + + else: + for altloc, lines in altlocs.items(): + lines_to_yield.extend(lines) + + lines_to_yield.sort(key=lambda x: x[0]) + for line_number, line in lines_to_yield: + yield line def main(): From 580f2925577b378287c3edb084686a18377b5e4a Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Wed, 29 Mar 2023 15:58:52 +0200 Subject: [PATCH 04/12] added function to remove alt loc char --- pdbtools/pdb_selaltloc.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pdbtools/pdb_selaltloc.py b/pdbtools/pdb_selaltloc.py index bbcdef02..8b509b89 100644 --- a/pdbtools/pdb_selaltloc.py +++ b/pdbtools/pdb_selaltloc.py @@ -490,8 +490,6 @@ def run(fhandle, option=None): yield _line - - def _flush(register, option): lines_to_yield = [] select_by_occupancy = option is None @@ -520,7 +518,7 @@ def _flush(register, option): list_.append((line_number, line)) keys_ = sorted(new.keys(), key=lambda x: float(x.strip()), reverse=True) - lines_to_yield.extend(new[keys_[0]]) + lines_to_yield.extend(_remove_altloc(new[keys_[0]])) del all_lines del new @@ -528,7 +526,7 @@ def _flush(register, option): # selected by otion: else: if option in altlocs: - lines_to_yield.extend(altlocs[option]) + lines_to_yield.extend(_remove_altloc(altlocs[option])) else: for altloc, lines in altlocs.items(): @@ -539,6 +537,11 @@ def _flush(register, option): yield line +def _remove_altloc(lines): + for line_num, line in lines: + yield (line_num, line[:16] + ' ' + line[17:]) + + def main(): # Check Input pdbfh, option = check_input(sys.argv[1:]) From ac38e0f28957a96ca7af3a57fa162fb11c265ebe Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Thu, 30 Mar 2023 13:24:06 +0200 Subject: [PATCH 05/12] pass all previous tests --- pdbtools/pdb_selaltloc.py | 17 +- tests/test_pdb_selaltloc.py | 316 +++++++++++------------------------- 2 files changed, 108 insertions(+), 225 deletions(-) diff --git a/pdbtools/pdb_selaltloc.py b/pdbtools/pdb_selaltloc.py index 8b509b89..f87c7424 100644 --- a/pdbtools/pdb_selaltloc.py +++ b/pdbtools/pdb_selaltloc.py @@ -443,8 +443,10 @@ def run(fhandle, option=None): `pdb_selaltloc.select_by_altloc` for more details. """ records = ('ATOM', 'HETATM', 'ANISOU') + # TODO: add terminators to ensure better line control? register = dict() chain = None + prev_chain = None nline = 0 for line in fhandle: nline += 1 @@ -517,8 +519,21 @@ def _flush(register, option): elif line.startswith(anisou_lines): list_.append((line_number, line)) + # sort keys by occupancy keys_ = sorted(new.keys(), key=lambda x: float(x.strip()), reverse=True) - lines_to_yield.extend(_remove_altloc(new[keys_[0]])) + + # address "take first if occ is the same" + # see: https://github.com/haddocking/pdb-tools/issues/153#issuecomment-1488627668 + these_atom_lines = new[keys_[0]] + if len(keys_) == 1 and len(these_atom_lines) > 1: + # when occ are the same + lines_to_yield.extend(_remove_altloc(these_atom_lines[0:1])) + if these_atom_lines[1][1].startswith(('ANISOU',)): + lines_to_yield.extend(_remove_altloc(these_atom_lines[1:2])) + + else: + # when occ are different + lines_to_yield.extend(_remove_altloc(these_atom_lines)) del all_lines del new diff --git a/tests/test_pdb_selaltloc.py b/tests/test_pdb_selaltloc.py index 085376ad..d0646c03 100644 --- a/tests/test_pdb_selaltloc.py +++ b/tests/test_pdb_selaltloc.py @@ -52,208 +52,6 @@ def exec_module(self): return - def test_is_same_group_1(self): - """ - Test function to identify we entered another altloc group. - - This indicates we are in the SAME altloc group. - - previous line: "" # first line of the PDB file - current line: " ALA 1" - - The result of `is_another_altloc_group` should be False. - """ - result = self.module.is_another_altloc_group( - ' ', '', '1', '', 'ALA', '', {}, {}) - - self.assertFalse(result) - - def test_is_same_group_2(self): - """ - Test function to identify we entered another altloc group. - - This indicates we are in the SAME altloc group. - - All `None` case. - - The result of `is_another_altloc_group` should be False. - """ - result = self.module.is_another_altloc_group( - ' ', None, None, None, None, None, {}, {}) - - self.assertFalse(result) - - def test_is_same_group_3(self): - """ - Test function to identify we entered another altloc group. - - This indicates we are in the SAME altloc group. - - Example: all parameters are the same as the previous line. - - previous line: "BALA 12" - current line: "BALA 12" - - The result of `is_another_altloc_group` should be False. - """ - result = self.module.is_another_altloc_group( - 'B', 'B', '12', '12', 'ALA', 'ALA', {'B': None}, - {'B': {('ALA', '12')}} - ) - self.assertFalse(result) - - - def test_is_same_group_4(self): - """ - Test function to identify we entered another altloc group. - - This indicates we are in the SAME altloc group. - - Example: Multiple residue altloc. This considers altloc spanning - several residues. See example dummy_altloc2.pdb. - - previous line: "AGLU 25" - current line: "ALEU 26" - - It is important to note also the dictionary input. - - The result of `is_another_altloc_group` should be False. - """ - result = self.module.is_another_altloc_group( - 'A', 'A', '26', '25', 'LEU', 'GLU', {'A': ['lines']}, - {'A': {('GLU', '25')}} - ) - self.assertFalse(result) - - def test_is_same_group_5(self): - """ - Test function to identify we entered another altloc group. - - This indicates we are in the SAME altloc group. - - Example: Multiple residue altloc. This considers altloc spanning - several residues. See example dummy_altloc2.pdb. - - previous line: " GLU 25" - current line: "AALA 25" - - It is important to note also the dictionary input. - - The result of `is_another_altloc_group` should be False. - """ - result = self.module.is_another_altloc_group( - 'A', ' ', '25', '25', 'ALA', 'GLU', {' ': ['lines']}, - {' ': {('GLU', '25')}} - ) - self.assertFalse(result) - - def test_is_another_group_1(self): - """ - Test function to identify we entered another altloc group. - - This indicates we entered another altloc group. - - previous line: "BPRO 1" - current line: " ALA 2" - - The result of `is_another_altloc_group` should be True. - """ - result = self.module.is_another_altloc_group( - ' ', 'B', '2', '1', 'ALA', 'PRO', {'B': ['lines']}, - {'B': {('PRO', '1')}} - ) - self.assertTrue(result) - - def test_is_another_group_2(self): - """ - Test function to identify we entered another altloc group. - - This indicates we entered another altloc group. - - previous line: " ALA 1" - current line: " ALA 2" - - The result of `is_another_altloc_group` should be True. - """ - result = self.module.is_another_altloc_group( - ' ', ' ', '2', '1', 'ALA', 'ALA', {' ': ['lines']}, - {' ': {('ALA', '1')}} - ) - self.assertTrue(result) - - def test_is_another_group_3(self): - """ - Test function to identify we entered another altloc group. - - This indicates we entered another altloc group. - - previous line: " GLU 1" - current line: " ALA 1" - - The result of `is_another_altloc_group` should be True. - """ - result = self.module.is_another_altloc_group( - ' ', ' ', '1', '1', 'ALA', 'GLU', {' ': ['lines']}, - {' ': {('GLU', '1')}} - ) - self.assertTrue(result) - - def test_is_another_group_4(self): - """ - Test function to identify we entered another altloc group. - - This indicates we entered another altloc group. - - previous line: "AGLU 25" - current line: "ALEU 26" - - The result of `is_another_altloc_group` should be True. - """ - result = self.module.is_another_altloc_group( - 'A', 'A', '26', '25', 'LEU', 'GLU', {' ': ['lines'], 'A': ['lines']}, - {' ': {('LEU', '25')}, 'A': {('GLU', '26')}} - ) - self.assertTrue(result) - - def test_all_same_residue(self): - """Test all same residue.""" - inp = { - ' ': [ - "ATOM 3 N ASN A 1 22.066 40.557 0.420 1.00 0.00 N ", - "ATOM 3 H ASN A 1 21.629 41.305 -0.098 1.00 0.00 H ", - "ATOM 3 H2 ASN A 1 23.236 40.798 0.369 1.00 0.00 H ", - "ATOM 3 H3 ASN A 1 21.866 40.736 1.590 1.00 0.00 H ", - ], - 'B': ["ATOM 3 CA BASN A 1 20.000 30.000 0.005 0.60 0.00 C "], - 'A': ["ATOM 3 CA AASN A 1 21.411 39.311 0.054 0.40 0.00 C "], - } - - result = self.module.all_same_residue(inp) - self.assertTrue(result) - - def test_all_same_residue_false(self): - """Test all same residue.""" - inp = { - 'B': ["ATOM 3 CA BSER A 2 20.000 30.000 0.005 0.60 0.00 C "], 'A': ["ATOM 3 CA AASN A 1 21.411 39.311 0.054 0.40 0.00 C "], } - result = self.module.all_same_residue(inp) - self.assertFalse(result) - - def test_partial_altloc(self): - inp = { - 'A': [ - "ATOM 333 CA AGLU A 26 -10.000 -3.000 -12.000 0.50 4.89 C ", - "ANISOU 333 CA AGLU A 26 576 620 663 31 42 45 C ", - ], - 'B':[ - "ATOM 333 CA CGLU A 26 -10.679 -3.437 -12.387 1.00 4.89 C ", - "ANISOU 333 CA CGLU A 26 576 620 663 31 42 45 C ", - ], - } - - result = self.module.partial_altloc(inp) - self.assertFalse(result) - - def test_default(self): """$ pdb_selaltloc data/dummy_altloc.pdb""" @@ -481,38 +279,56 @@ def test_select_loc_C_2(self): self.assertEqual(observed, expected) - def test_gives_same_dummy_A(self): - """Test dummy.pdb is not altered because there are not altlocs.""" + def test_dummy_A(self): + """Test -A with dummy.pdb.""" sys.argv = ['', '-A', os.path.join(data_dir, 'dummy.pdb')] self.exec_module() self.assertEqual(self.retcode, 0) self.assertEqual(len(self.stdout), 203) self.assertEqual(len(self.stderr), 0) self.assertEqual( - self.stdout[80], + self.stdout[69], "ATOM 3 CA ASN A 1 21.411 39.311 0.054 0.40 0.00 C ") - def test_gives_same_dummy_B(self): - """Test dummy.pdb is not altered because there are not altlocs.""" + def test_dummy_B(self): + """Test -B with dummy.pdb.""" sys.argv = ['', '-B', os.path.join(data_dir, 'dummy.pdb')] self.exec_module() self.assertEqual(self.retcode, 0) self.assertEqual(len(self.stdout), 203) self.assertEqual(len(self.stderr), 0) self.assertEqual( - self.stdout[80], - "ATOM 3 CA ASN A 1 20.000 30.000 0.005 0.60 0.00 C " - ) + self.stdout[69], + "ATOM 3 CA ASN A 1 20.000 30.000 0.005 0.60 0.00 C ") + + def test_gives_the_same_dummy_C(self): + """ + Test -C with dummy.pdb. + + Should output exactly the same PDB because there is not altloc 'C'. + """ + sys.argv = ['', '-C', os.path.join(data_dir, 'dummy.pdb')] + self.exec_module() + self.assertEqual(self.retcode, 0) + self.assertEqual(len(self.stdout), 204) + self.assertEqual(len(self.stderr), 0) + self.assertEqual( + self.stdout[70], + "ATOM 3 CA AASN A 1 21.411 39.311 0.054 0.40 0.00 C ") + + self.assertEqual( + self.stdout[69], + "ATOM 3 CA BASN A 1 20.000 30.000 0.005 0.60 0.00 C ") def test_gives_same_dummy_maxocc(self): - """Test dummy.pdb is not altered because there are not altlocs.""" + """Test select the maximum occurance.""" sys.argv = ['', os.path.join(data_dir, 'dummy.pdb')] self.exec_module() self.assertEqual(self.retcode, 0) self.assertEqual(len(self.stdout), 203) self.assertEqual(len(self.stderr), 0) self.assertEqual( - self.stdout[80], + self.stdout[69], "ATOM 3 CA ASN A 1 20.000 30.000 0.005 0.60 0.00 C " ) @@ -596,14 +412,15 @@ def test_anisou_lines(self): corrected. """ infile = os.path.join(data_dir, 'anisou.pdb') - sys.argv = ['', infile] - self.exec_module() - self.assertEqual(self.retcode, 0) - self.assertEqual(len(self.stdout), 24) - self.assertEqual(len(self.stderr), 0) - with open(infile, "r") as fin: - expected_lines = [l.strip(os.linesep) for l in fin.readlines()] - self.assertEqual(self.stdout, expected_lines) + for opt in ('', '-A', '-B'): + sys.argv = [opt, infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + self.assertEqual(len(self.stdout), 24) + self.assertEqual(len(self.stderr), 0) + with open(infile, "r") as fin: + expected_lines = [l.strip(os.linesep) for l in fin.readlines()] + self.assertEqual(self.stdout, expected_lines) def test_anisou_with_altloc_maxocc(self): """ @@ -735,11 +552,19 @@ def test_anisou_with_altloc_maxocc_B(self): ) def test_anisou_missing(self): - """Test raises error if there are missing anisou lines.""" + """ + Works properly even when there are missing anisou lines. + + In this case, it does not alter the file. + """ infile = os.path.join(data_dir, 'anisou_missing.pdb') - sys.argv = ['', infile] - self.exec_module() - self.assertEqual(self.retcode, 0) + for opt in ('', '-A'): + sys.argv = [opt, infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + with open(infile, "r") as fin: + expected_lines = [l.strip(os.linesep) for l in fin.readlines()] + self.assertEqual(self.stdout, expected_lines) def test_captures_previous_residue_maxocc_A(self): """ @@ -870,6 +695,47 @@ def test_captures_previous_residue_maxocc_B(self): ] ) + def test_take_first(self): + """ + Takes the first occurence when occ is the same and no option is given. + + See: https://github.com/haddocking/pdb-tools/issues/153#issuecomment-1488627668 + """ + sys.argv = ['', os.path.join(data_dir, 'dummy_altloc4.pdb')] + self.exec_module() + self.assertEqual(self.retcode, 0) + self.assertEqual(len(self.stdout), 25) + self.assertEqual(len(self.stderr), 0) + self.assertEqual( + self.stdout, + [ + "ATOM 153 N VAL A 18 -0.264 -17.574 22.788 0.00 0.00 N ", + "ATOM 154 CA VAL A 18 -0.201 -17.901 24.209 0.00 0.00 C ", + "ATOM 155 C VAL A 18 -1.047 -19.150 24.437 0.00 0.00 C ", + "ATOM 156 O VAL A 18 -2.260 -19.144 24.214 0.00 0.00 O ", + "ATOM 157 CB VAL A 18 -0.689 -16.724 25.084 0.00 0.00 C ", + "ATOM 161 N TRP A 19 -0.408 -20.230 24.882 0.00 0.00 N ", + "ATOM 162 CA TRP A 19 -1.091 -21.490 25.161 0.00 0.00 C ", + "ATOM 163 C TRP A 19 -1.303 -21.563 26.667 0.00 0.00 C ", + "ATOM 164 O TRP A 19 -0.357 -21.920 27.375 0.00 0.00 O ", + "ATOM 165 CB TRP A 19 -0.272 -22.670 24.635 0.00 0.00 C ", + "ATOM 176 N TYR A 20 -2.522 -21.226 27.083 0.00 0.00 N ", + "ATOM 177 CA TYR A 20 -2.898 -21.178 28.493 0.00 0.00 C ", + "ATOM 178 C TYR A 20 -3.718 -22.410 28.851 0.00 0.00 C ", + "ATOM 179 O TYR A 20 -4.629 -22.780 28.105 0.00 0.00 O ", + "ATOM 180 CB TYR A 20 -3.681 -19.898 28.795 0.00 0.00 C ", + "ATOM 189 N VAL A 21 -3.396 -23.034 29.982 0.50 0.00 N ", + "ATOM 190 CA VAL A 21 -4.121 -24.205 30.467 0.50 0.00 C ", + "ATOM 191 C VAL A 21 -4.530 -24.072 31.930 0.50 0.00 C ", + "ATOM 192 O VAL A 21 -3.835 -23.461 32.747 0.50 0.00 O ", + "ATOM 193 CB VAL A 21 -3.289 -25.497 30.298 0.50 0.00 C ", + "ATOM 189 N PRO A 22 -3.396 -23.034 29.982 0.50 0.00 N ", + "ATOM 190 CA PRO A 22 -4.121 -24.205 30.467 0.50 0.00 C ", + "ATOM 191 C PRO A 22 -4.530 -24.072 31.930 0.50 0.00 C ", + "ATOM 192 O PRO A 22 -3.835 -23.461 32.747 0.50 0.00 O ", + "ATOM 193 CB PRO A 22 -3.289 -25.497 30.298 0.50 0.00 C ", + ] + ) def test_file_not_found(self): """$ pdb_selaltloc not_existing.pdb""" @@ -897,6 +763,8 @@ def test_file_missing(self): self.assertEqual(self.stderr[0], "ERROR!! No data to process!") + + @unittest.skipIf(os.getenv('SKIP_TTY_TESTS'), 'skip on GHA - no TTY') def test_helptext(self): """$ pdb_selaltloc""" From ad4e66d13256fc28e74e9a125c677fa3455159df Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Thu, 30 Mar 2023 13:38:21 +0200 Subject: [PATCH 06/12] add missing test pdb --- tests/data/dummy_altloc4.pdb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/data/dummy_altloc4.pdb diff --git a/tests/data/dummy_altloc4.pdb b/tests/data/dummy_altloc4.pdb new file mode 100644 index 00000000..f4e29cb3 --- /dev/null +++ b/tests/data/dummy_altloc4.pdb @@ -0,0 +1,35 @@ +ATOM 153 N VAL A 18 -0.264 -17.574 22.788 0.00 0.00 N +ATOM 154 CA VAL A 18 -0.201 -17.901 24.209 0.00 0.00 C +ATOM 155 C VAL A 18 -1.047 -19.150 24.437 0.00 0.00 C +ATOM 156 O VAL A 18 -2.260 -19.144 24.214 0.00 0.00 O +ATOM 157 CB VAL A 18 -0.689 -16.724 25.084 0.00 0.00 C +ATOM 161 N TRP A 19 -0.408 -20.230 24.882 0.00 0.00 N +ATOM 162 CA TRP A 19 -1.091 -21.490 25.161 0.00 0.00 C +ATOM 163 C TRP A 19 -1.303 -21.563 26.667 0.00 0.00 C +ATOM 164 O TRP A 19 -0.357 -21.920 27.375 0.00 0.00 O +ATOM 165 CB TRP A 19 -0.272 -22.670 24.635 0.00 0.00 C +ATOM 176 N TYR A 20 -2.522 -21.226 27.083 0.00 0.00 N +ATOM 177 CA TYR A 20 -2.898 -21.178 28.493 0.00 0.00 C +ATOM 178 C TYR A 20 -3.718 -22.410 28.851 0.00 0.00 C +ATOM 179 O TYR A 20 -4.629 -22.780 28.105 0.00 0.00 O +ATOM 180 CB TYR A 20 -3.681 -19.898 28.795 0.00 0.00 C +ATOM 189 N AVAL A 21 -3.396 -23.034 29.982 0.50 0.00 N +ATOM 197 N BALA A 21 -5.676 -24.647 32.284 0.50 0.00 N +ATOM 190 CA AVAL A 21 -4.121 -24.205 30.467 0.50 0.00 C +ATOM 198 CA BALA A 21 -6.012 -24.814 33.696 0.50 0.00 C +ATOM 191 C AVAL A 21 -4.530 -24.072 31.930 0.50 0.00 C +ATOM 199 C BALA A 21 -4.990 -25.677 34.426 0.50 0.00 C +ATOM 192 O AVAL A 21 -3.835 -23.461 32.747 0.50 0.00 O +ATOM 200 O BALA A 21 -4.494 -26.675 33.897 0.50 0.00 O +ATOM 193 CB AVAL A 21 -3.289 -25.497 30.298 0.50 0.00 C +ATOM 201 CB BALA A 21 -7.405 -25.428 33.847 0.50 0.00 C +ATOM 189 N APRO A 22 -3.396 -23.034 29.982 0.50 0.00 N +ATOM 190 CA APRO A 22 -4.121 -24.205 30.467 0.50 0.00 C +ATOM 191 C APRO A 22 -4.530 -24.072 31.930 0.50 0.00 C +ATOM 192 O APRO A 22 -3.835 -23.461 32.747 0.50 0.00 O +ATOM 193 CB APRO A 22 -3.289 -25.497 30.298 0.50 0.00 C +ATOM 197 N BGLY A 22 -5.676 -24.647 32.284 0.50 0.00 N +ATOM 198 CA BGLY A 22 -6.012 -24.814 33.696 0.50 0.00 C +ATOM 199 C BGLY A 22 -4.990 -25.677 34.426 0.50 0.00 C +ATOM 200 O BGLY A 22 -4.494 -26.675 33.897 0.50 0.00 O +ATOM 201 CB BGLY A 22 -7.405 -25.428 33.847 0.50 0.00 C From ebcffea9fbae05b4da7766a3bcea8a3cd7fb80be Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Thu, 30 Mar 2023 15:50:53 +0200 Subject: [PATCH 07/12] add test from 3B9F suggested by @rvhonorato --- tests/data/altloc_3B9F.pdb | 133 ++++++++++++++++++++++++++++ tests/data/altloc_3B9F_A.pdb | 113 +++++++++++++++++++++++ tests/data/altloc_3B9F_B.pdb | 109 +++++++++++++++++++++++ tests/data/altloc_3B9F_nooption.pdb | 109 +++++++++++++++++++++++ tests/test_pdb_selaltloc.py | 45 ++++++++++ 5 files changed, 509 insertions(+) create mode 100644 tests/data/altloc_3B9F.pdb create mode 100644 tests/data/altloc_3B9F_A.pdb create mode 100644 tests/data/altloc_3B9F_B.pdb create mode 100644 tests/data/altloc_3B9F_nooption.pdb diff --git a/tests/data/altloc_3B9F.pdb b/tests/data/altloc_3B9F.pdb new file mode 100644 index 00000000..98d8b2de --- /dev/null +++ b/tests/data/altloc_3B9F.pdb @@ -0,0 +1,133 @@ +PDBTLS This file was edited to test pdb_selaltloc +PDBTLS Original PDB 3B9F +PDBTLS +HEADER HYDROLASE/HYDROLASE INHIBITOR 05-NOV-07 3B9F +TITLE 1.6 A STRUCTURE OF THE PCI-THROMBIN-HEPARIN COMPLEX +COMPND 21 ENGINEERED: YES +SOURCE MOL_ID: 1; +KEYWDS 4 PROTEASE, ZYMOGEN, HYDROLASE-HYDROLASE INHIBITOR COMPLEX +EXPDTA X-RAY DIFFRACTION +AUTHOR W.LI,T.E.ADAMS,J.A.HUNTINGTON +REVDAT 1 22-APR-08 3B9F 0 +JRNL AUTH W.LI,T.E.ADAMS,J.NANGALIA,C.T.ESMON,J.A.HUNTINGTON +REMARK 2 +REMARK 999 NATURAL VARIANT AT THIS POSITION +DBREF 3B9F I 17 387 UNP P05154 IPSP_HUMAN 36 406 +SEQADV 3B9F ALA H 195 UNP P00734 SER 568 ENGINEERED MUTATION +SEQRES 31 I 395 LYS VAL ASN ARG PRO +MODRES 3B9F ASN H 60G ASN GLYCOSYLATION SITE +HET NAG A 1 14 +HETNAM NAG 2-ACETAMIDO-2-DEOXY-BETA-D-GLUCOPYRANOSE +HETSYN GOL GLYCERIN; PROPANE-1,2,3-TRIOL +FORMUL 14 HOH *523(H2 O) +HELIX 1 1 ASN L 1K GLY L 1F 1 6 +HELIX 20 20 SER I 305 THR I 309 5 5 +SHEET 1 A 7 SER H 20 ASP H 21 0 +SHEET 2 G 2 GLY I 340 ARG I 342 1 O THR I 341 N TRP I 190 +SSBOND 1 CYS L 1 CYS H 122 1555 1555 2.03 +LINK O6 NAG A 1 C1 FUC A 2 1555 1555 1.40 +CISPEP 2 LYS H 185 PRO H 186 0 0.28 +CRYST1 44.055 48.825 97.850 78.72 81.52 77.69 P 1 1 +ORIGX1 1.000000 0.000000 0.000000 0.00000 +ORIGX2 0.000000 1.000000 0.000000 0.00000 +ORIGX3 0.000000 0.000000 1.000000 0.00000 +SCALE1 0.022699 -0.004951 -0.002582 0.00000 +SCALE2 0.000000 0.020963 -0.003616 0.00000 +SCALE3 0.000000 0.000000 0.010485 0.00000 +ATOM 16 N TYR L 1P -35.899 36.071 -57.146 1.00 24.40 N +ATOM 17 CA TYR L 1P -35.533 35.711 -55.782 1.00 22.98 C +ATOM 18 C TYR L 1P -35.689 36.923 -54.879 1.00 22.73 C +ATOM 19 O TYR L 1P -35.212 38.013 -55.199 1.00 24.86 O +ATOM 28 N AGLN L 1O -36.361 36.722 -53.750 0.20 22.43 N +ATOM 29 N BGLN L 1O -36.368 36.734 -53.754 0.80 21.82 N +ATOM 30 CA AGLN L 1O -36.584 37.781 -52.773 0.23 21.92 C +ATOM 31 CA BGLN L 1O -36.567 37.813 -52.796 0.77 21.45 C +ATOM 32 C AGLN L 1O -35.689 37.523 -51.567 0.25 21.18 C +ATOM 33 C BGLN L 1O -35.688 37.528 -51.586 0.65 20.57 C +ATOM 34 O AGLN L 1O -35.816 36.492 -50.908 0.23 20.76 O +ATOM 35 O BGLN L 1O -35.820 36.482 -50.950 0.77 19.47 O +ATOM 46 N THR L 1N -34.783 38.453 -51.279 1.00 20.45 N +ATOM 47 CA THR L 1N -33.885 38.283 -50.143 1.00 20.33 C +ATOM 48 C THR L 1N -34.665 38.284 -48.834 1.00 20.94 C +ATOM 49 O THR L 1N -35.715 38.926 -48.718 1.00 20.47 O +ATOM 101 N THR L 1H -25.711 41.829 -41.231 1.00 16.46 N +ATOM 102 CA THR L 1H -25.418 40.733 -40.321 1.00 14.66 C +ATOM 103 C THR L 1H -25.179 39.417 -41.051 1.00 15.08 C +ATOM 104 O THR L 1H -24.467 38.557 -40.552 1.00 14.35 O +ATOM 123 N ASER L 1E -22.556 39.135 -47.649 0.10 14.32 N +ATOM 124 N BSER L 1E -22.558 39.094 -47.639 0.85 13.30 N +ATOM 125 CA ASER L 1E -23.019 39.209 -49.032 0.16 13.53 C +ATOM 126 CA BSER L 1E -23.010 39.174 -49.023 0.84 12.40 C +ATOM 127 C ASER L 1E -23.259 37.839 -49.653 0.10 13.43 C +ATOM 128 C BSER L 1E -23.296 37.813 -49.635 0.82 12.51 C +ATOM 129 O ASER L 1E -22.829 36.818 -49.115 0.34 12.37 O +ATOM 130 O BSER L 1E -22.933 36.779 -49.072 0.42 11.68 O +ATOM 161 N CYS L 1 -27.779 33.791 -54.663 1.00 11.36 N +ATOM 162 CA CYS L 1 -27.645 32.429 -54.138 1.00 11.72 C +ATOM 163 C CYS L 1 -28.184 31.351 -55.065 1.00 12.46 C +ATOM 164 O CYS L 1 -29.066 31.597 -55.887 1.00 11.13 O +ATOM 167 N GLY L 2 -27.618 30.155 -54.931 1.00 11.94 N +ATOM 168 CA GLY L 2 -28.093 29.010 -55.681 1.00 13.42 C +ATOM 169 C GLY L 2 -27.920 28.936 -57.179 1.00 13.71 C +ATOM 170 O GLY L 2 -28.452 28.010 -57.799 1.00 12.21 O +ATOM 171 N LEU L 3 -27.207 29.893 -57.766 1.00 11.48 N +ATOM 172 CA LEU L 3 -26.960 29.891 -59.207 1.00 12.60 C +ATOM 173 C LEU L 3 -25.462 29.636 -59.346 1.00 13.82 C +ATOM 174 O LEU L 3 -24.649 30.462 -58.944 1.00 14.29 O +TER 378 LEU L 3 +ATOM 498 N AMET H 32 -15.884 21.898 -46.134 0.03 13.63 N +ATOM 499 N BMET H 32 -15.886 21.863 -46.147 0.84 13.45 N +ATOM 500 CA AMET H 32 -15.223 20.827 -45.399 0.10 13.62 C +ATOM 501 CA BMET H 32 -15.262 20.752 -45.438 0.90 14.92 C +ATOM 502 C AMET H 32 -14.910 21.331 -44.004 0.01 14.47 C +ATOM 503 C BMET H 32 -14.862 21.255 -44.046 0.99 15.40 C +ATOM 504 O AMET H 32 -14.280 22.376 -43.844 0.10 14.26 O +ATOM 505 O BMET H 32 -14.125 22.236 -43.935 0.67 14.61 O +ATOM 514 N LEU H 33 -15.346 20.594 -42.992 1.00 15.12 N +ATOM 515 CA LEU H 33 -15.057 20.994 -41.613 1.00 17.37 C +ATOM 516 C LEU H 33 -13.966 20.110 -41.025 1.00 21.15 C +ATOM 517 O LEU H 33 -14.053 18.878 -41.092 1.00 21.77 O +ATOM 544 N LYS H 36 -8.375 20.177 -35.426 1.00 47.23 N +ATOM 545 CA LYS H 36 -6.948 20.457 -35.546 1.00 49.79 C +ATOM 546 C LYS H 36 -6.046 19.727 -34.564 1.00 51.19 C +ATOM 547 O LYS H 36 -6.501 19.201 -33.546 1.00 51.77 O +ATOM 553 N SER H 36A -4.757 19.702 -34.898 0.40 52.14 N +ATOM 554 CA SER H 36A -3.731 19.057 -34.087 0.40 52.58 C +ATOM 555 C SER H 36A -4.254 17.826 -33.356 0.40 52.69 C +ATOM 556 O SER H 36A -4.508 17.868 -32.151 0.40 54.21 O +ATOM 553 N BSER H 36A -4.757 19.702 -34.898 0.60 52.14 N +ATOM 554 CA BSER H 36A -3.731 19.057 -34.087 0.60 52.58 C +ATOM 555 C BSER H 36A -4.254 17.826 -33.356 0.60 52.69 C +ATOM 556 O BSER H 36A -4.508 17.868 -32.151 0.60 54.21 O +ATOM 583 N ALEU H 40 -10.561 15.413 -41.434 0.48 28.25 N +ATOM 584 N BLEU H 40 -10.564 15.370 -41.413 0.48 28.64 N +ATOM 585 CA ALEU H 40 -11.939 15.701 -41.811 0.03 25.33 C +ATOM 586 CA BLEU H 40 -11.952 15.605 -41.789 0.97 26.04 C +ATOM 587 C ALEU H 40 -12.927 15.248 -40.743 0.13 23.56 C +ATOM 588 C BLEU H 40 -12.860 15.301 -40.605 0.61 24.27 C +ATOM 589 O ALEU H 40 -12.964 14.075 -40.371 0.11 23.23 O +ATOM 590 O BLEU H 40 -12.739 14.255 -39.969 0.89 22.89 O +ATOM 599 N ALEU H 41 -13.727 16.191 -40.255 0.44 21.23 N +ATOM 600 N BLEU H 41 -13.774 16.219 -40.316 0.53 22.16 N +ATOM 601 CA ALEU H 41 -14.727 15.903 -39.235 0.04 18.81 C +ATOM 602 CA BLEU H 41 -14.696 16.049 -39.204 0.96 19.96 C +ATOM 603 C ALEU H 41 -16.114 15.742 -39.829 0.60 17.12 C +ATOM 604 C BLEU H 41 -16.124 15.865 -39.697 0.40 18.03 C +ATOM 605 O ALEU H 41 -16.804 14.756 -39.572 0.25 16.40 O +ATOM 606 O BLEU H 41 -16.844 14.976 -39.247 0.61 16.77 O +ATOM 615 N CYS H 42 -16.515 16.722 -40.632 1.00 15.17 N +ATOM 616 CA CYS H 42 -17.854 16.716 -41.198 1.00 14.43 C +ATOM 617 C CYS H 42 -17.965 17.557 -42.446 1.00 13.79 C +ATOM 618 O CYS H 42 -17.003 18.181 -42.892 1.00 13.66 O +ATOM 621 N GLY H 43 -19.183 17.574 -42.976 1.00 12.50 N +ATOM 622 CA GLY H 43 -19.506 18.388 -44.128 1.00 13.66 C +ATOM 623 C GLY H 43 -20.155 19.637 -43.546 1.00 12.41 C +ATOM 624 O GLY H 43 -20.400 19.711 -42.333 1.00 11.38 O +ATOM 625 N ALA H 44 -20.433 20.608 -44.408 1.00 12.66 N +ATOM 626 CA ALA H 44 -21.043 21.876 -44.015 1.00 12.16 C +ATOM 627 C ALA H 44 -21.446 22.558 -45.312 1.00 11.20 C +ATOM 628 O ALA H 44 -21.152 22.052 -46.394 1.00 11.04 O +TER 630 TER H 44 +CONECT 5572 5571 +MASTER 413 0 12 20 38 0 0 6 5736 3 109 55 +END diff --git a/tests/data/altloc_3B9F_A.pdb b/tests/data/altloc_3B9F_A.pdb new file mode 100644 index 00000000..51541b2b --- /dev/null +++ b/tests/data/altloc_3B9F_A.pdb @@ -0,0 +1,113 @@ +PDBTLS This file was edited to test pdb_selaltloc +PDBTLS Original PDB 3B9F +PDBTLS +HEADER HYDROLASE/HYDROLASE INHIBITOR 05-NOV-07 3B9F +TITLE 1.6 A STRUCTURE OF THE PCI-THROMBIN-HEPARIN COMPLEX +COMPND 21 ENGINEERED: YES +SOURCE MOL_ID: 1; +KEYWDS 4 PROTEASE, ZYMOGEN, HYDROLASE-HYDROLASE INHIBITOR COMPLEX +EXPDTA X-RAY DIFFRACTION +AUTHOR W.LI,T.E.ADAMS,J.A.HUNTINGTON +REVDAT 1 22-APR-08 3B9F 0 +JRNL AUTH W.LI,T.E.ADAMS,J.NANGALIA,C.T.ESMON,J.A.HUNTINGTON +REMARK 2 +REMARK 999 NATURAL VARIANT AT THIS POSITION +DBREF 3B9F I 17 387 UNP P05154 IPSP_HUMAN 36 406 +SEQADV 3B9F ALA H 195 UNP P00734 SER 568 ENGINEERED MUTATION +SEQRES 31 I 395 LYS VAL ASN ARG PRO +MODRES 3B9F ASN H 60G ASN GLYCOSYLATION SITE +HET NAG A 1 14 +HETNAM NAG 2-ACETAMIDO-2-DEOXY-BETA-D-GLUCOPYRANOSE +HETSYN GOL GLYCERIN; PROPANE-1,2,3-TRIOL +FORMUL 14 HOH *523(H2 O) +HELIX 1 1 ASN L 1K GLY L 1F 1 6 +HELIX 20 20 SER I 305 THR I 309 5 5 +SHEET 1 A 7 SER H 20 ASP H 21 0 +SHEET 2 G 2 GLY I 340 ARG I 342 1 O THR I 341 N TRP I 190 +SSBOND 1 CYS L 1 CYS H 122 1555 1555 2.03 +LINK O6 NAG A 1 C1 FUC A 2 1555 1555 1.40 +CISPEP 2 LYS H 185 PRO H 186 0 0.28 +CRYST1 44.055 48.825 97.850 78.72 81.52 77.69 P 1 1 +ORIGX1 1.000000 0.000000 0.000000 0.00000 +ORIGX2 0.000000 1.000000 0.000000 0.00000 +ORIGX3 0.000000 0.000000 1.000000 0.00000 +SCALE1 0.022699 -0.004951 -0.002582 0.00000 +SCALE2 0.000000 0.020963 -0.003616 0.00000 +SCALE3 0.000000 0.000000 0.010485 0.00000 +ATOM 16 N TYR L 1P -35.899 36.071 -57.146 1.00 24.40 N +ATOM 17 CA TYR L 1P -35.533 35.711 -55.782 1.00 22.98 C +ATOM 18 C TYR L 1P -35.689 36.923 -54.879 1.00 22.73 C +ATOM 19 O TYR L 1P -35.212 38.013 -55.199 1.00 24.86 O +ATOM 28 N GLN L 1O -36.361 36.722 -53.750 0.20 22.43 N +ATOM 30 CA GLN L 1O -36.584 37.781 -52.773 0.23 21.92 C +ATOM 32 C GLN L 1O -35.689 37.523 -51.567 0.25 21.18 C +ATOM 34 O GLN L 1O -35.816 36.492 -50.908 0.23 20.76 O +ATOM 46 N THR L 1N -34.783 38.453 -51.279 1.00 20.45 N +ATOM 47 CA THR L 1N -33.885 38.283 -50.143 1.00 20.33 C +ATOM 48 C THR L 1N -34.665 38.284 -48.834 1.00 20.94 C +ATOM 49 O THR L 1N -35.715 38.926 -48.718 1.00 20.47 O +ATOM 101 N THR L 1H -25.711 41.829 -41.231 1.00 16.46 N +ATOM 102 CA THR L 1H -25.418 40.733 -40.321 1.00 14.66 C +ATOM 103 C THR L 1H -25.179 39.417 -41.051 1.00 15.08 C +ATOM 104 O THR L 1H -24.467 38.557 -40.552 1.00 14.35 O +ATOM 123 N SER L 1E -22.556 39.135 -47.649 0.10 14.32 N +ATOM 125 CA SER L 1E -23.019 39.209 -49.032 0.16 13.53 C +ATOM 127 C SER L 1E -23.259 37.839 -49.653 0.10 13.43 C +ATOM 129 O SER L 1E -22.829 36.818 -49.115 0.34 12.37 O +ATOM 161 N CYS L 1 -27.779 33.791 -54.663 1.00 11.36 N +ATOM 162 CA CYS L 1 -27.645 32.429 -54.138 1.00 11.72 C +ATOM 163 C CYS L 1 -28.184 31.351 -55.065 1.00 12.46 C +ATOM 164 O CYS L 1 -29.066 31.597 -55.887 1.00 11.13 O +ATOM 167 N GLY L 2 -27.618 30.155 -54.931 1.00 11.94 N +ATOM 168 CA GLY L 2 -28.093 29.010 -55.681 1.00 13.42 C +ATOM 169 C GLY L 2 -27.920 28.936 -57.179 1.00 13.71 C +ATOM 170 O GLY L 2 -28.452 28.010 -57.799 1.00 12.21 O +ATOM 171 N LEU L 3 -27.207 29.893 -57.766 1.00 11.48 N +ATOM 172 CA LEU L 3 -26.960 29.891 -59.207 1.00 12.60 C +ATOM 173 C LEU L 3 -25.462 29.636 -59.346 1.00 13.82 C +ATOM 174 O LEU L 3 -24.649 30.462 -58.944 1.00 14.29 O +TER 378 LEU L 3 +ATOM 498 N MET H 32 -15.884 21.898 -46.134 0.03 13.63 N +ATOM 500 CA MET H 32 -15.223 20.827 -45.399 0.10 13.62 C +ATOM 502 C MET H 32 -14.910 21.331 -44.004 0.01 14.47 C +ATOM 504 O MET H 32 -14.280 22.376 -43.844 0.10 14.26 O +ATOM 514 N LEU H 33 -15.346 20.594 -42.992 1.00 15.12 N +ATOM 515 CA LEU H 33 -15.057 20.994 -41.613 1.00 17.37 C +ATOM 516 C LEU H 33 -13.966 20.110 -41.025 1.00 21.15 C +ATOM 517 O LEU H 33 -14.053 18.878 -41.092 1.00 21.77 O +ATOM 544 N LYS H 36 -8.375 20.177 -35.426 1.00 47.23 N +ATOM 545 CA LYS H 36 -6.948 20.457 -35.546 1.00 49.79 C +ATOM 546 C LYS H 36 -6.046 19.727 -34.564 1.00 51.19 C +ATOM 547 O LYS H 36 -6.501 19.201 -33.546 1.00 51.77 O +ATOM 553 N SER H 36A -4.757 19.702 -34.898 0.40 52.14 N +ATOM 554 CA SER H 36A -3.731 19.057 -34.087 0.40 52.58 C +ATOM 555 C SER H 36A -4.254 17.826 -33.356 0.40 52.69 C +ATOM 556 O SER H 36A -4.508 17.868 -32.151 0.40 54.21 O +ATOM 553 N BSER H 36A -4.757 19.702 -34.898 0.60 52.14 N +ATOM 554 CA BSER H 36A -3.731 19.057 -34.087 0.60 52.58 C +ATOM 555 C BSER H 36A -4.254 17.826 -33.356 0.60 52.69 C +ATOM 556 O BSER H 36A -4.508 17.868 -32.151 0.60 54.21 O +ATOM 583 N LEU H 40 -10.561 15.413 -41.434 0.48 28.25 N +ATOM 585 CA LEU H 40 -11.939 15.701 -41.811 0.03 25.33 C +ATOM 587 C LEU H 40 -12.927 15.248 -40.743 0.13 23.56 C +ATOM 589 O LEU H 40 -12.964 14.075 -40.371 0.11 23.23 O +ATOM 599 N LEU H 41 -13.727 16.191 -40.255 0.44 21.23 N +ATOM 601 CA LEU H 41 -14.727 15.903 -39.235 0.04 18.81 C +ATOM 603 C LEU H 41 -16.114 15.742 -39.829 0.60 17.12 C +ATOM 605 O LEU H 41 -16.804 14.756 -39.572 0.25 16.40 O +ATOM 615 N CYS H 42 -16.515 16.722 -40.632 1.00 15.17 N +ATOM 616 CA CYS H 42 -17.854 16.716 -41.198 1.00 14.43 C +ATOM 617 C CYS H 42 -17.965 17.557 -42.446 1.00 13.79 C +ATOM 618 O CYS H 42 -17.003 18.181 -42.892 1.00 13.66 O +ATOM 621 N GLY H 43 -19.183 17.574 -42.976 1.00 12.50 N +ATOM 622 CA GLY H 43 -19.506 18.388 -44.128 1.00 13.66 C +ATOM 623 C GLY H 43 -20.155 19.637 -43.546 1.00 12.41 C +ATOM 624 O GLY H 43 -20.400 19.711 -42.333 1.00 11.38 O +ATOM 625 N ALA H 44 -20.433 20.608 -44.408 1.00 12.66 N +ATOM 626 CA ALA H 44 -21.043 21.876 -44.015 1.00 12.16 C +ATOM 627 C ALA H 44 -21.446 22.558 -45.312 1.00 11.20 C +ATOM 628 O ALA H 44 -21.152 22.052 -46.394 1.00 11.04 O +TER 630 TER H 44 +CONECT 5572 5571 +MASTER 413 0 12 20 38 0 0 6 5736 3 109 55 +END diff --git a/tests/data/altloc_3B9F_B.pdb b/tests/data/altloc_3B9F_B.pdb new file mode 100644 index 00000000..c36b0e0c --- /dev/null +++ b/tests/data/altloc_3B9F_B.pdb @@ -0,0 +1,109 @@ +PDBTLS This file was edited to test pdb_selaltloc +PDBTLS Original PDB 3B9F +PDBTLS +HEADER HYDROLASE/HYDROLASE INHIBITOR 05-NOV-07 3B9F +TITLE 1.6 A STRUCTURE OF THE PCI-THROMBIN-HEPARIN COMPLEX +COMPND 21 ENGINEERED: YES +SOURCE MOL_ID: 1; +KEYWDS 4 PROTEASE, ZYMOGEN, HYDROLASE-HYDROLASE INHIBITOR COMPLEX +EXPDTA X-RAY DIFFRACTION +AUTHOR W.LI,T.E.ADAMS,J.A.HUNTINGTON +REVDAT 1 22-APR-08 3B9F 0 +JRNL AUTH W.LI,T.E.ADAMS,J.NANGALIA,C.T.ESMON,J.A.HUNTINGTON +REMARK 2 +REMARK 999 NATURAL VARIANT AT THIS POSITION +DBREF 3B9F I 17 387 UNP P05154 IPSP_HUMAN 36 406 +SEQADV 3B9F ALA H 195 UNP P00734 SER 568 ENGINEERED MUTATION +SEQRES 31 I 395 LYS VAL ASN ARG PRO +MODRES 3B9F ASN H 60G ASN GLYCOSYLATION SITE +HET NAG A 1 14 +HETNAM NAG 2-ACETAMIDO-2-DEOXY-BETA-D-GLUCOPYRANOSE +HETSYN GOL GLYCERIN; PROPANE-1,2,3-TRIOL +FORMUL 14 HOH *523(H2 O) +HELIX 1 1 ASN L 1K GLY L 1F 1 6 +HELIX 20 20 SER I 305 THR I 309 5 5 +SHEET 1 A 7 SER H 20 ASP H 21 0 +SHEET 2 G 2 GLY I 340 ARG I 342 1 O THR I 341 N TRP I 190 +SSBOND 1 CYS L 1 CYS H 122 1555 1555 2.03 +LINK O6 NAG A 1 C1 FUC A 2 1555 1555 1.40 +CISPEP 2 LYS H 185 PRO H 186 0 0.28 +CRYST1 44.055 48.825 97.850 78.72 81.52 77.69 P 1 1 +ORIGX1 1.000000 0.000000 0.000000 0.00000 +ORIGX2 0.000000 1.000000 0.000000 0.00000 +ORIGX3 0.000000 0.000000 1.000000 0.00000 +SCALE1 0.022699 -0.004951 -0.002582 0.00000 +SCALE2 0.000000 0.020963 -0.003616 0.00000 +SCALE3 0.000000 0.000000 0.010485 0.00000 +ATOM 16 N TYR L 1P -35.899 36.071 -57.146 1.00 24.40 N +ATOM 17 CA TYR L 1P -35.533 35.711 -55.782 1.00 22.98 C +ATOM 18 C TYR L 1P -35.689 36.923 -54.879 1.00 22.73 C +ATOM 19 O TYR L 1P -35.212 38.013 -55.199 1.00 24.86 O +ATOM 29 N GLN L 1O -36.368 36.734 -53.754 0.80 21.82 N +ATOM 31 CA GLN L 1O -36.567 37.813 -52.796 0.77 21.45 C +ATOM 33 C GLN L 1O -35.688 37.528 -51.586 0.65 20.57 C +ATOM 35 O GLN L 1O -35.820 36.482 -50.950 0.77 19.47 O +ATOM 46 N THR L 1N -34.783 38.453 -51.279 1.00 20.45 N +ATOM 47 CA THR L 1N -33.885 38.283 -50.143 1.00 20.33 C +ATOM 48 C THR L 1N -34.665 38.284 -48.834 1.00 20.94 C +ATOM 49 O THR L 1N -35.715 38.926 -48.718 1.00 20.47 O +ATOM 101 N THR L 1H -25.711 41.829 -41.231 1.00 16.46 N +ATOM 102 CA THR L 1H -25.418 40.733 -40.321 1.00 14.66 C +ATOM 103 C THR L 1H -25.179 39.417 -41.051 1.00 15.08 C +ATOM 104 O THR L 1H -24.467 38.557 -40.552 1.00 14.35 O +ATOM 124 N SER L 1E -22.558 39.094 -47.639 0.85 13.30 N +ATOM 126 CA SER L 1E -23.010 39.174 -49.023 0.84 12.40 C +ATOM 128 C SER L 1E -23.296 37.813 -49.635 0.82 12.51 C +ATOM 130 O SER L 1E -22.933 36.779 -49.072 0.42 11.68 O +ATOM 161 N CYS L 1 -27.779 33.791 -54.663 1.00 11.36 N +ATOM 162 CA CYS L 1 -27.645 32.429 -54.138 1.00 11.72 C +ATOM 163 C CYS L 1 -28.184 31.351 -55.065 1.00 12.46 C +ATOM 164 O CYS L 1 -29.066 31.597 -55.887 1.00 11.13 O +ATOM 167 N GLY L 2 -27.618 30.155 -54.931 1.00 11.94 N +ATOM 168 CA GLY L 2 -28.093 29.010 -55.681 1.00 13.42 C +ATOM 169 C GLY L 2 -27.920 28.936 -57.179 1.00 13.71 C +ATOM 170 O GLY L 2 -28.452 28.010 -57.799 1.00 12.21 O +ATOM 171 N LEU L 3 -27.207 29.893 -57.766 1.00 11.48 N +ATOM 172 CA LEU L 3 -26.960 29.891 -59.207 1.00 12.60 C +ATOM 173 C LEU L 3 -25.462 29.636 -59.346 1.00 13.82 C +ATOM 174 O LEU L 3 -24.649 30.462 -58.944 1.00 14.29 O +TER 378 LEU L 3 +ATOM 499 N MET H 32 -15.886 21.863 -46.147 0.84 13.45 N +ATOM 501 CA MET H 32 -15.262 20.752 -45.438 0.90 14.92 C +ATOM 503 C MET H 32 -14.862 21.255 -44.046 0.99 15.40 C +ATOM 505 O MET H 32 -14.125 22.236 -43.935 0.67 14.61 O +ATOM 514 N LEU H 33 -15.346 20.594 -42.992 1.00 15.12 N +ATOM 515 CA LEU H 33 -15.057 20.994 -41.613 1.00 17.37 C +ATOM 516 C LEU H 33 -13.966 20.110 -41.025 1.00 21.15 C +ATOM 517 O LEU H 33 -14.053 18.878 -41.092 1.00 21.77 O +ATOM 544 N LYS H 36 -8.375 20.177 -35.426 1.00 47.23 N +ATOM 545 CA LYS H 36 -6.948 20.457 -35.546 1.00 49.79 C +ATOM 546 C LYS H 36 -6.046 19.727 -34.564 1.00 51.19 C +ATOM 547 O LYS H 36 -6.501 19.201 -33.546 1.00 51.77 O +ATOM 553 N SER H 36A -4.757 19.702 -34.898 0.60 52.14 N +ATOM 554 CA SER H 36A -3.731 19.057 -34.087 0.60 52.58 C +ATOM 555 C SER H 36A -4.254 17.826 -33.356 0.60 52.69 C +ATOM 556 O SER H 36A -4.508 17.868 -32.151 0.60 54.21 O +ATOM 584 N LEU H 40 -10.564 15.370 -41.413 0.48 28.64 N +ATOM 586 CA LEU H 40 -11.952 15.605 -41.789 0.97 26.04 C +ATOM 588 C LEU H 40 -12.860 15.301 -40.605 0.61 24.27 C +ATOM 590 O LEU H 40 -12.739 14.255 -39.969 0.89 22.89 O +ATOM 600 N LEU H 41 -13.774 16.219 -40.316 0.53 22.16 N +ATOM 602 CA LEU H 41 -14.696 16.049 -39.204 0.96 19.96 C +ATOM 604 C LEU H 41 -16.124 15.865 -39.697 0.40 18.03 C +ATOM 606 O LEU H 41 -16.844 14.976 -39.247 0.61 16.77 O +ATOM 615 N CYS H 42 -16.515 16.722 -40.632 1.00 15.17 N +ATOM 616 CA CYS H 42 -17.854 16.716 -41.198 1.00 14.43 C +ATOM 617 C CYS H 42 -17.965 17.557 -42.446 1.00 13.79 C +ATOM 618 O CYS H 42 -17.003 18.181 -42.892 1.00 13.66 O +ATOM 621 N GLY H 43 -19.183 17.574 -42.976 1.00 12.50 N +ATOM 622 CA GLY H 43 -19.506 18.388 -44.128 1.00 13.66 C +ATOM 623 C GLY H 43 -20.155 19.637 -43.546 1.00 12.41 C +ATOM 624 O GLY H 43 -20.400 19.711 -42.333 1.00 11.38 O +ATOM 625 N ALA H 44 -20.433 20.608 -44.408 1.00 12.66 N +ATOM 626 CA ALA H 44 -21.043 21.876 -44.015 1.00 12.16 C +ATOM 627 C ALA H 44 -21.446 22.558 -45.312 1.00 11.20 C +ATOM 628 O ALA H 44 -21.152 22.052 -46.394 1.00 11.04 O +TER 630 TER H 44 +CONECT 5572 5571 +MASTER 413 0 12 20 38 0 0 6 5736 3 109 55 +END diff --git a/tests/data/altloc_3B9F_nooption.pdb b/tests/data/altloc_3B9F_nooption.pdb new file mode 100644 index 00000000..6c98e5d6 --- /dev/null +++ b/tests/data/altloc_3B9F_nooption.pdb @@ -0,0 +1,109 @@ +PDBTLS This file was edited to test pdb_selaltloc +PDBTLS Original PDB 3B9F +PDBTLS +HEADER HYDROLASE/HYDROLASE INHIBITOR 05-NOV-07 3B9F +TITLE 1.6 A STRUCTURE OF THE PCI-THROMBIN-HEPARIN COMPLEX +COMPND 21 ENGINEERED: YES +SOURCE MOL_ID: 1; +KEYWDS 4 PROTEASE, ZYMOGEN, HYDROLASE-HYDROLASE INHIBITOR COMPLEX +EXPDTA X-RAY DIFFRACTION +AUTHOR W.LI,T.E.ADAMS,J.A.HUNTINGTON +REVDAT 1 22-APR-08 3B9F 0 +JRNL AUTH W.LI,T.E.ADAMS,J.NANGALIA,C.T.ESMON,J.A.HUNTINGTON +REMARK 2 +REMARK 999 NATURAL VARIANT AT THIS POSITION +DBREF 3B9F I 17 387 UNP P05154 IPSP_HUMAN 36 406 +SEQADV 3B9F ALA H 195 UNP P00734 SER 568 ENGINEERED MUTATION +SEQRES 31 I 395 LYS VAL ASN ARG PRO +MODRES 3B9F ASN H 60G ASN GLYCOSYLATION SITE +HET NAG A 1 14 +HETNAM NAG 2-ACETAMIDO-2-DEOXY-BETA-D-GLUCOPYRANOSE +HETSYN GOL GLYCERIN; PROPANE-1,2,3-TRIOL +FORMUL 14 HOH *523(H2 O) +HELIX 1 1 ASN L 1K GLY L 1F 1 6 +HELIX 20 20 SER I 305 THR I 309 5 5 +SHEET 1 A 7 SER H 20 ASP H 21 0 +SHEET 2 G 2 GLY I 340 ARG I 342 1 O THR I 341 N TRP I 190 +SSBOND 1 CYS L 1 CYS H 122 1555 1555 2.03 +LINK O6 NAG A 1 C1 FUC A 2 1555 1555 1.40 +CISPEP 2 LYS H 185 PRO H 186 0 0.28 +CRYST1 44.055 48.825 97.850 78.72 81.52 77.69 P 1 1 +ORIGX1 1.000000 0.000000 0.000000 0.00000 +ORIGX2 0.000000 1.000000 0.000000 0.00000 +ORIGX3 0.000000 0.000000 1.000000 0.00000 +SCALE1 0.022699 -0.004951 -0.002582 0.00000 +SCALE2 0.000000 0.020963 -0.003616 0.00000 +SCALE3 0.000000 0.000000 0.010485 0.00000 +ATOM 16 N TYR L 1P -35.899 36.071 -57.146 1.00 24.40 N +ATOM 17 CA TYR L 1P -35.533 35.711 -55.782 1.00 22.98 C +ATOM 18 C TYR L 1P -35.689 36.923 -54.879 1.00 22.73 C +ATOM 19 O TYR L 1P -35.212 38.013 -55.199 1.00 24.86 O +ATOM 29 N GLN L 1O -36.368 36.734 -53.754 0.80 21.82 N +ATOM 31 CA GLN L 1O -36.567 37.813 -52.796 0.77 21.45 C +ATOM 33 C GLN L 1O -35.688 37.528 -51.586 0.65 20.57 C +ATOM 35 O GLN L 1O -35.820 36.482 -50.950 0.77 19.47 O +ATOM 46 N THR L 1N -34.783 38.453 -51.279 1.00 20.45 N +ATOM 47 CA THR L 1N -33.885 38.283 -50.143 1.00 20.33 C +ATOM 48 C THR L 1N -34.665 38.284 -48.834 1.00 20.94 C +ATOM 49 O THR L 1N -35.715 38.926 -48.718 1.00 20.47 O +ATOM 101 N THR L 1H -25.711 41.829 -41.231 1.00 16.46 N +ATOM 102 CA THR L 1H -25.418 40.733 -40.321 1.00 14.66 C +ATOM 103 C THR L 1H -25.179 39.417 -41.051 1.00 15.08 C +ATOM 104 O THR L 1H -24.467 38.557 -40.552 1.00 14.35 O +ATOM 124 N SER L 1E -22.558 39.094 -47.639 0.85 13.30 N +ATOM 126 CA SER L 1E -23.010 39.174 -49.023 0.84 12.40 C +ATOM 128 C SER L 1E -23.296 37.813 -49.635 0.82 12.51 C +ATOM 130 O SER L 1E -22.933 36.779 -49.072 0.42 11.68 O +ATOM 161 N CYS L 1 -27.779 33.791 -54.663 1.00 11.36 N +ATOM 162 CA CYS L 1 -27.645 32.429 -54.138 1.00 11.72 C +ATOM 163 C CYS L 1 -28.184 31.351 -55.065 1.00 12.46 C +ATOM 164 O CYS L 1 -29.066 31.597 -55.887 1.00 11.13 O +ATOM 167 N GLY L 2 -27.618 30.155 -54.931 1.00 11.94 N +ATOM 168 CA GLY L 2 -28.093 29.010 -55.681 1.00 13.42 C +ATOM 169 C GLY L 2 -27.920 28.936 -57.179 1.00 13.71 C +ATOM 170 O GLY L 2 -28.452 28.010 -57.799 1.00 12.21 O +ATOM 171 N LEU L 3 -27.207 29.893 -57.766 1.00 11.48 N +ATOM 172 CA LEU L 3 -26.960 29.891 -59.207 1.00 12.60 C +ATOM 173 C LEU L 3 -25.462 29.636 -59.346 1.00 13.82 C +ATOM 174 O LEU L 3 -24.649 30.462 -58.944 1.00 14.29 O +TER 378 LEU L 3 +ATOM 499 N MET H 32 -15.886 21.863 -46.147 0.84 13.45 N +ATOM 501 CA MET H 32 -15.262 20.752 -45.438 0.90 14.92 C +ATOM 503 C MET H 32 -14.862 21.255 -44.046 0.99 15.40 C +ATOM 505 O MET H 32 -14.125 22.236 -43.935 0.67 14.61 O +ATOM 514 N LEU H 33 -15.346 20.594 -42.992 1.00 15.12 N +ATOM 515 CA LEU H 33 -15.057 20.994 -41.613 1.00 17.37 C +ATOM 516 C LEU H 33 -13.966 20.110 -41.025 1.00 21.15 C +ATOM 517 O LEU H 33 -14.053 18.878 -41.092 1.00 21.77 O +ATOM 544 N LYS H 36 -8.375 20.177 -35.426 1.00 47.23 N +ATOM 545 CA LYS H 36 -6.948 20.457 -35.546 1.00 49.79 C +ATOM 546 C LYS H 36 -6.046 19.727 -34.564 1.00 51.19 C +ATOM 547 O LYS H 36 -6.501 19.201 -33.546 1.00 51.77 O +ATOM 553 N SER H 36A -4.757 19.702 -34.898 0.60 52.14 N +ATOM 554 CA SER H 36A -3.731 19.057 -34.087 0.60 52.58 C +ATOM 555 C SER H 36A -4.254 17.826 -33.356 0.60 52.69 C +ATOM 556 O SER H 36A -4.508 17.868 -32.151 0.60 54.21 O +ATOM 583 N LEU H 40 -10.561 15.413 -41.434 0.48 28.25 N +ATOM 586 CA LEU H 40 -11.952 15.605 -41.789 0.97 26.04 C +ATOM 588 C LEU H 40 -12.860 15.301 -40.605 0.61 24.27 C +ATOM 590 O LEU H 40 -12.739 14.255 -39.969 0.89 22.89 O +ATOM 600 N LEU H 41 -13.774 16.219 -40.316 0.53 22.16 N +ATOM 602 CA LEU H 41 -14.696 16.049 -39.204 0.96 19.96 C +ATOM 603 C LEU H 41 -16.114 15.742 -39.829 0.60 17.12 C +ATOM 606 O LEU H 41 -16.844 14.976 -39.247 0.61 16.77 O +ATOM 615 N CYS H 42 -16.515 16.722 -40.632 1.00 15.17 N +ATOM 616 CA CYS H 42 -17.854 16.716 -41.198 1.00 14.43 C +ATOM 617 C CYS H 42 -17.965 17.557 -42.446 1.00 13.79 C +ATOM 618 O CYS H 42 -17.003 18.181 -42.892 1.00 13.66 O +ATOM 621 N GLY H 43 -19.183 17.574 -42.976 1.00 12.50 N +ATOM 622 CA GLY H 43 -19.506 18.388 -44.128 1.00 13.66 C +ATOM 623 C GLY H 43 -20.155 19.637 -43.546 1.00 12.41 C +ATOM 624 O GLY H 43 -20.400 19.711 -42.333 1.00 11.38 O +ATOM 625 N ALA H 44 -20.433 20.608 -44.408 1.00 12.66 N +ATOM 626 CA ALA H 44 -21.043 21.876 -44.015 1.00 12.16 C +ATOM 627 C ALA H 44 -21.446 22.558 -45.312 1.00 11.20 C +ATOM 628 O ALA H 44 -21.152 22.052 -46.394 1.00 11.04 O +TER 630 TER H 44 +CONECT 5572 5571 +MASTER 413 0 12 20 38 0 0 6 5736 3 109 55 +END diff --git a/tests/test_pdb_selaltloc.py b/tests/test_pdb_selaltloc.py index f76b35c8..466e2744 100644 --- a/tests/test_pdb_selaltloc.py +++ b/tests/test_pdb_selaltloc.py @@ -836,6 +836,51 @@ def test_take_first(self): ] ) + def test_mixed_occ_and_inserts(self): + """ + Test mixed maximum occurence and insertion codes. + + Test maximum occurence. + """ + infile = os.path.join(data_dir, 'altloc_3B9F.pdb') + result_file = os.path.join(data_dir, 'altloc_3B9F_nooption.pdb') + sys.argv = ['', infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + with open(result_file, "r") as fin: + expected_lines = [l.strip(os.linesep) for l in fin.readlines()] + self.assertEqual(self.stdout, expected_lines) + + def test_mixed_occ_and_inserts_A(self): + """ + Test mixed maximum occurence and insertion codes. + + Test option A. + """ + infile = os.path.join(data_dir, 'altloc_3B9F.pdb') + result_file = os.path.join(data_dir, 'altloc_3B9F_A.pdb') + sys.argv = ['', '-A', infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + with open(result_file, "r") as fin: + expected_lines = [l.strip(os.linesep) for l in fin.readlines()] + self.assertEqual(self.stdout, expected_lines) + + def test_mixed_occ_and_inserts_B(self): + """ + Test mixed maximum occurence and insertion codes. + + Test option B. + """ + infile = os.path.join(data_dir, 'altloc_3B9F.pdb') + result_file = os.path.join(data_dir, 'altloc_3B9F_B.pdb') + sys.argv = ['', '-B', infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + with open(result_file, "r") as fin: + expected_lines = [l.strip(os.linesep) for l in fin.readlines()] + self.assertEqual(self.stdout, expected_lines) + def test_file_not_found(self): """$ pdb_selaltloc not_existing.pdb""" From 66cec871695add3932e498bec5b32b3724a4a1a0 Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Thu, 30 Mar 2023 16:01:21 +0200 Subject: [PATCH 08/12] add MODEL test --- tests/data/dummy_altloc_model.pdb | 55 +++++++++++++++++++++++++++++++ tests/test_pdb_selaltloc.py | 39 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 tests/data/dummy_altloc_model.pdb diff --git a/tests/data/dummy_altloc_model.pdb b/tests/data/dummy_altloc_model.pdb new file mode 100644 index 00000000..fb300106 --- /dev/null +++ b/tests/data/dummy_altloc_model.pdb @@ -0,0 +1,55 @@ +REMARK ORIGINAL DATA FROM PDB ID 3U7T +REMARK test MODEL without the TER ENDMDL or END statements +MODEL 1 +ATOM 308 N ASER A 22 -14.282 -3.023 -15.571 0.53 4.57 N +ANISOU 308 N ASER A 22 594 482 661 7 -42 32 N +ATOM 309 CA ASER A 22 -13.829 -3.816 -14.436 0.53 5.30 C +ANISOU 309 CA ASER A 22 695 586 731 6 -19 117 C +ATOM 310 C ASER A 22 -12.365 -3.540 -14.113 0.53 4.77 C +ANISOU 310 C ASER A 22 582 560 669 34 31 98 C +ATOM 311 O ASER A 22 -11.531 -3.326 -15.003 0.53 5.44 O +ANISOU 311 O ASER A 22 602 786 679 59 46 138 O +ATOM 318 N BPRO A 22 -14.305 -3.040 -15.563 0.47 5.18 N +ANISOU 318 N BPRO A 22 713 566 690 -20 -45 8 N +ATOM 319 CA BPRO A 22 -13.801 -3.851 -14.452 0.47 5.29 C +ANISOU 319 CA BPRO A 22 701 599 711 -19 -20 59 C +ATOM 320 C BPRO A 22 -12.344 -3.583 -14.119 0.47 4.84 C +ANISOU 320 C BPRO A 22 590 585 664 23 27 64 C +ATOM 321 O BPRO A 22 -11.499 -3.414 -15.007 0.47 5.37 O +ANISOU 321 O BPRO A 22 603 762 675 65 45 100 O +ATOM 332 N GLU A 23 -12.046 -3.614 -12.827 1.00 4.76 N +ANISOU 332 N GLU A 23 558 607 642 79 39 69 N +ATOM 333 CA GLU A 23 -10.679 -3.437 -12.387 1.00 4.89 C +ANISOU 333 CA GLU A 23 576 620 663 31 42 45 C +ATOM 334 C GLU A 23 -9.718 -4.412 -13.075 1.00 4.66 C +ANISOU 334 C GLU A 23 509 598 663 8 21 49 C +ATOM 335 O GLU A 23 -8.593 -4.031 -13.405 1.00 5.42 O +ANISOU 335 O GLU A 23 569 765 725 -40 72 -21 O +MODEL 2 +ATOM 308 N ASER A 22 -14.282 -3.023 -15.571 0.53 4.57 N +ANISOU 308 N ASER A 22 594 482 661 7 -42 32 N +ATOM 309 CA ASER A 22 -13.829 -3.816 -14.436 0.53 5.30 C +ANISOU 309 CA ASER A 22 695 586 731 6 -19 117 C +ATOM 310 C ASER A 22 -12.365 -3.540 -14.113 0.53 4.77 C +ANISOU 310 C ASER A 22 582 560 669 34 31 98 C +ATOM 311 O ASER A 22 -11.531 -3.326 -15.003 0.53 5.44 O +ANISOU 311 O ASER A 22 602 786 679 59 46 138 O +ATOM 318 N BPRO A 22 -14.305 -3.040 -15.563 0.47 5.18 N +ANISOU 318 N BPRO A 22 713 566 690 -20 -45 8 N +ATOM 319 CA BPRO A 22 -13.801 -3.851 -14.452 0.47 5.29 C +ANISOU 319 CA BPRO A 22 701 599 711 -19 -20 59 C +ATOM 320 C BPRO A 22 -12.344 -3.583 -14.119 0.47 4.84 C +ANISOU 320 C BPRO A 22 590 585 664 23 27 64 C +ATOM 321 O BPRO A 22 -11.499 -3.414 -15.007 0.47 5.37 O +ANISOU 321 O BPRO A 22 603 762 675 65 45 100 O +ATOM 332 N GLU A 23 -12.046 -3.614 -12.827 1.00 4.76 N +ANISOU 332 N GLU A 23 558 607 642 79 39 69 N +ATOM 333 CA GLU A 23 -10.679 -3.437 -12.387 1.00 4.89 C +ANISOU 333 CA GLU A 23 576 620 663 31 42 45 C +ATOM 334 C GLU A 23 -9.718 -4.412 -13.075 1.00 4.66 C +ANISOU 334 C GLU A 23 509 598 663 8 21 49 C +ATOM 335 O GLU A 23 -8.593 -4.031 -13.405 1.00 5.42 O +ANISOU 335 O GLU A 23 569 765 725 -40 72 -21 O +TER 336 GLU A 23 +ENDMDL +END diff --git a/tests/test_pdb_selaltloc.py b/tests/test_pdb_selaltloc.py index 466e2744..d22ef605 100644 --- a/tests/test_pdb_selaltloc.py +++ b/tests/test_pdb_selaltloc.py @@ -881,6 +881,45 @@ def test_mixed_occ_and_inserts_B(self): expected_lines = [l.strip(os.linesep) for l in fin.readlines()] self.assertEqual(self.stdout, expected_lines) + def test_with_models(self): + """ + Test lines are flushed when new model found. + """ + infile = os.path.join(data_dir, 'dummy_altloc_model.pdb') + sys.argv = ['', infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + self.assertEqual(len(self.stdout), 39) + self.assertEqual(len(self.stderr), 0) + + def test_with_models_A(self): + """ + Test lines are flushed when new model found. + """ + infile = os.path.join(data_dir, 'dummy_altloc_model.pdb') + sys.argv = ['', '-A', infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + self.assertEqual(len(self.stdout), 39) + self.assertEqual(len(self.stderr), 0) + result = set(''.join(self.stdout).split()) + self.assertTrue('SER' in result) + self.assertFalse('PRO' in result) + + def test_with_models_B(self): + """ + Test lines are flushed when new model found. + """ + infile = os.path.join(data_dir, 'dummy_altloc_model.pdb') + sys.argv = ['', '-B', infile] + self.exec_module() + self.assertEqual(self.retcode, 0) + self.assertEqual(len(self.stdout), 39) + result = set(''.join(self.stdout).split()) + self.assertFalse('SER' in result) + self.assertTrue('PRO' in result) + self.assertEqual(len(self.stderr), 0) + def test_file_not_found(self): """$ pdb_selaltloc not_existing.pdb""" From 6c29270113d37ced43d3d797062a89515ddc3b40 Mon Sep 17 00:00:00 2001 From: joaomcteixeira Date: Thu, 30 Mar 2023 16:59:45 +0200 Subject: [PATCH 09/12] clean, docs, test the comments --- pdbtools/pdb_selaltloc.py | 453 +++++++++--------------------------- tests/data/dummy_altloc.pdb | 3 + tests/test_pdb_selaltloc.py | 8 +- 3 files changed, 117 insertions(+), 347 deletions(-) diff --git a/pdbtools/pdb_selaltloc.py b/pdbtools/pdb_selaltloc.py index f87c7424..976467bc 100644 --- a/pdbtools/pdb_selaltloc.py +++ b/pdbtools/pdb_selaltloc.py @@ -26,12 +26,18 @@ are processed by the script. If you select -A and an atom has conformers with altlocs B and C, both B and C will be kept in the output. +Despite not an official format, many times alternative locations are identified +by a blank character ' ' (space), and a character, for example ('A'). In these +cases, to select the alternative location identified by a blank character, +define blank in the command line, see below. + Usage: python pdb_selaltloc.py [-