1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493
|
""" PDB parsing class
This module parses PDBs in accordance to PDB Format Description Version 2.2
(1996); it is not very forgiving. Each class in this module corresponds
to a record in the PDB Format Description. Much of the documentation for
the classes is taken directly from the above PDB Format Description.
----------------------------
PDB2PQR -- An automated pipeline for the setup, execution, and analysis of
Poisson-Boltzmann electrostatics calculations
Copyright (c) 2002-2011, Jens Erik Nielsen, University College Dublin;
Nathan A. Baker, Battelle Memorial Institute, Developed at the Pacific
Northwest National Laboratory, operated by Battelle Memorial Institute,
Pacific Northwest Division for the U.S. Department Energy.;
Paul Czodrowski & Gerhard Klebe, University of Marburg.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the names of University College Dublin, Battelle Memorial Institute,
Pacific Northwest National Laboratory, US Department of Energy, or University
of Marburg nor the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
----------------------------
"""
__date__ = "4 August 2008"
__author__ = "Todd Dolinsky, Yong Huang"
import string, sys
import copy ### PC
class END:
""" END class
The END records are paired with MODEL records to group individual
structures found in a coordinate entry.
"""
def __init__(self, line):
"""
Initialize by parsing line (nothing to do)
"""
pass
class MASTER:
""" MASTER class
The MASTER record is a control record for bookkeeping. It lists the
number of lines in the coordinate entry or file for selected record
types.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-------------------------------------------------
11-15 int numRemark Number of REMARK records
21-25 int numHet Number of HET records
26-30 int numHelix Number of HELIX records
31-35 int numSheet Number of SHEET records
36-40 int numTurn Number of TURN records
41-45 int numSite Number of SITE records
46-50 int numXform Number of coordinate transformation
records (ORIGX+SCALE+MTRIX)
51-55 int numCoord Number of atomic coordinate records
(ATOM+HETATM)
56-60 int numTer Number of TER records
61-65 int numConect Number of CONECT records
66-70 int numSeq Number of SEQRES records
"""
record = string.strip(line[0:6])
if record == "MASTER":
self.numRemark = int(string.strip(line[10:15]))
self.numHet = int(string.strip(line[20:25]))
self.numHelix = int(string.strip(line[25:30]))
self.numSheet = int(string.strip(line[30:35]))
self.numTurn = int(string.strip(line[35:40]))
self.numSite = int(string.strip(line[40:45]))
self.numXform = int(string.strip(line[45:50]))
self.numCoord = int(string.strip(line[50:55]))
self.numTer = int(string.strip(line[55:60]))
self.numConect = int(string.strip(line[60:65]))
self.numSeq = int(string.strip(line[65:70]))
else: raise ValueError, record
class CONECT:
""" CONECT class
The CONECT records specify connectivity between atoms for which
coordinates are supplied. The connectivity is described using the atom
serial number as found in the entry. CONECT records are mandatory for
HET groups (excluding water) and for other bonds not specified in the
standard residue connectivity table which involve atoms in standard
residues (see Appendix 4 for the list of standard residues). These
records are generated by the PDB.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------
7-11 int serial Atom serial number
12-16 int serial1 Serial number of bonded atom
17-21 int serial2 Serial number of bonded atom
22-26 int serial3 Serial number of bonded atom
27-31 int serial4 Serial number of bonded atom
32-36 int serial5 Serial number of hydrogen bonded atom
37-41 int serial6 Serial number of hydrogen bonded atom
42-46 int serial7 Serial number of salt bridged atom
47-51 int serial8 Serial number of hydrogen bonded atom
52-56 int serial9 Serial number of hydrogen bonded atom
57-61 int serial10 Serial number of salt bridged atom
"""
record = string.strip(line[0:6])
if record == "CONECT":
self.serial = int(string.strip(line[6:11]))
try: self.serial1 = int(string.strip(line[11:16]))
except ValueError: self.serial1 = None
try: self.serial2 = int(string.strip(line[16:21]))
except ValueError: self.serial2 = None
try: self.serial3 = int(string.strip(line[21:26]))
except ValueError: self.serial3 = None
try: self.serial4 = int(string.strip(line[26:31]))
except ValueError: self.serial4 = None
try: self.serial5 = int(string.strip(line[31:36]))
except ValueError: self.serial5 = None
try: self.serial6 = int(string.strip(line[36:41]))
except ValueError: self.serial6 = None
try: self.serial7 = int(string.strip(line[41:46]))
except ValueError: self.serial7 = None
try: self.serial8 = int(string.strip(line[46:51]))
except ValueError: self.serial8 = None
try: self.serial9 = int(string.strip(line[51:56]))
except ValueError: self.serial9 = None
try: self.serial10 = int(string.strip(line[56:61]))
except ValueError: self.serial10 = None
else: raise ValueError, record
class ENDMDL:
""" ENDMDL class
The ENDMDL records are paired with MODEL records to group individual
structures found in a coordinate entry.
"""
def __init__(self, line):
"""
Initialize by parsing line (nothing to do)
"""
pass
class TER:
""" TER class
The TER record indicates the end of a list of ATOM/HETATM records for a
chain.
"""
def __init__(self, line):
""" Initialize by parsing line:
COLUMNS TYPE FIELD DEFINITION
-------------------------------------------
7-11 int serial Serial number.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Insertion code.
"""
record = string.strip(line[0:6])
if record == "TER":
try: # Not really needed
self.serial = int(string.strip(line[6:11]))
self.resName = string.strip(line[17:20])
self.chainID = string.strip(line[21])
self.resSeq = int(string.strip(line[22:26]))
self.iCode = string.strip(line[26])
except (IndexError, ValueError):
self.serial = None
self.resName = None
self.chainID = None
self.resSeq = None
self.iCode = None
else: raise ValueError, record
class SIGUIJ:
""" SIGUIJ class
The SIGUIJ records present the anisotropic temperature factors.
"""
def __init__(self, line):
"""
Initialize by parsing line:
COLUMNS TYPE FIELD DEFINITION
------------------------------------------------------
7-11 int serial Atom serial number.
13-16 string name Atom name.
17 string altLoc Alternate location indicator.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Insertion code.
29-35 int sig11 Sigma U(1,1)
36-42 int sig22 Sigma U(2,2)
43-49 int sig33 Sigma U(3,3)
50-56 int sig12 Sigma U(1,2)
57-63 int sig13 Sigma U(1,3)
64-70 int sig23 Sigma U(2,3)
73-76 string segID Segment identifier, left-justified.
77-78 string element Element symbol, right-justified.
79-80 string charge Charge on the atom.
"""
record = string.strip(line[0:6])
if record == "SIGUIJ":
self.serial = int(string.strip(line[6:11]))
self.name = string.strip(line[12:16])
self.altLoc = string.strip(line[16])
self.resName = string.strip(line[17:20])
self.chainID = string.strip(line[21])
self.resSeq = int(string.strip(line[22:26]))
self.iCode = string.strip(line[26])
self.sig11 = int(string.strip(line[28:35]))
self.sig22 = int(string.strip(line[35:42]))
self.sig33 = int(string.strip(line[42:49]))
self.sig12 = int(string.strip(line[49:56]))
self.sig13 = int(string.strip(line[56:63]))
self.sig23 = int(string.strip(line[63:70]))
self.segID = string.strip(line[72:76])
self.element = string.strip(line[76:78])
self.charge = string.strip(line[78:80])
else: raise ValueError, record
class ANISOU:
""" ANISOU class
The ANISOU records present the anisotropic temperature factors.
"""
def __init__(self, line):
"""
Initialize by parsing line:
COLUMNS TYPE FIELD DEFINITION
------------------------------------------------------
7-11 int serial Atom serial number.
13-16 string name Atom name.
17 string altLoc Alternate location indicator.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Insertion code.
29-35 int u00 U(1,1)
36-42 int u11 U(2,2)
43-49 int u22 U(3,3)
50-56 int u01 U(1,2)
57-63 int u02 U(1,3)
64-70 int u12 U(2,3)
73-76 string segID Segment identifier, left-justified.
77-78 string element Element symbol, right-justified.
79-80 string charge Charge on the atom.
"""
record = string.strip(line[0:6])
if record == "ANISOU":
self.serial = int(string.strip(line[6:11]))
self.name = string.strip(line[12:16])
self.altLoc = string.strip(line[16])
self.resName = string.strip(line[17:20])
self.chainID = string.strip(line[21])
self.resSeq = int(string.strip(line[22:26]))
self.iCode = string.strip(line[26])
self.u00 = int(string.strip(line[28:35]))
self.u11 = int(string.strip(line[35:42]))
self.u22 = int(string.strip(line[42:49]))
self.u01 = int(string.strip(line[49:56]))
self.u02 = int(string.strip(line[56:63]))
self.u12 = int(string.strip(line[63:70]))
self.segID = string.strip(line[72:76])
self.element = string.strip(line[76:78])
self.charge = string.strip(line[78:80])
else: raise ValueError, record
class SIGATM:
""" SIGATM class
The SIGATM records present the standard deviation of atomic parameters
as they appear in ATOM and HETATM records.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------
7-11 int serial Atom serial number.
13-16 string name Atom name.
17 string altLoc Alternate location indicator.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Code for insertion of residues.
31-38 float sigX Standard devition of orthogonal
coordinates for X in Angstroms.
39-46 float sigY Standard devition of orthogonal
coordinates for Y in Angstroms.
47-54 float sigZ Standard devition of orthogonal
coordinates for Z in Angstroms.
55-60 float sigOcc Standard devition of occupancy.
61-66 float sigTemp Standard devition of temperature factor.
73-76 string segID Segment identifier, left-justified.
77-78 string element Element symbol, right-justified.
79-80 string charge Charge on the atom.
"""
record = string.strip(line[0:6])
if record == "HETATM":
self.serial = int(string.strip(line[6:11]))
self.name = string.strip(line[12:16])
self.altLoc = string.strip(line[16])
self.resName = string.strip(line[17:20])
self.chainID = string.strip(line[21])
self.resSeq = int(string.strip(line[22:26]))
self.iCode = string.strip(line[26])
self.sigX = float(string.strip(line[30:38]))
self.sigY = float(string.strip(line[38:46]))
self.sigZ = float(string.strip(line[46:54]))
self.sigOcc = float(string.strip(line[54:60]))
self.sigTemp = float(string.strip(line[60:66]))
self.segID = string.strip(line[72:76])
self.element = string.strip(line[76:78])
self.charge = string.strip(line[78:80])
else: raise ValueError, record
class HETATM:
""" HETATM class
The HETATM records present the atomic coordinate records for atoms
within "non-standard" groups. These records are used for water
molecules and atoms presented in HET groups.
"""
def __init__(self,line,sybylType="A.aaa",lBonds=[],lBondedAtoms=[]): ### PC
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------
7-11 int serial Atom serial number.
13-16 string name Atom name.
17 string altLoc Alternate location indicator.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Code for insertion of residues.
31-38 float x Orthogonal coordinates for X in
Angstroms.
39-46 float y Orthogonal coordinates for Y in
Angstroms.
47-54 float z Orthogonal coordinates for Z in
Angstroms.
55-60 float occupancy Occupancy.
61-66 float tempFactor Temperature factor.
73-76 string segID Segment identifier, left-justified.
77-78 string element Element symbol, right-justified.
79-80 string charge Charge on the atom.
"""
record = string.strip(line[0:6])
if record == "HETATM":
self.serial = int(string.strip(line[6:11]))
self.name = string.strip(line[12:16])
self.altLoc = string.strip(line[16])
try:
self.resName = string.strip(line[17:20])
self.chainID = string.strip(line[21])
self.resSeq = int(string.strip(line[22:26]))
self.iCode = string.strip(line[26])
except:
raise ValueError, 'Residue name must be less than 4 characters!'
self.x = float(string.strip(line[30:38]))
self.y = float(string.strip(line[38:46]))
self.z = float(string.strip(line[46:54]))
### PC
# self.lAtoms = lAtoms
self.sybylType = sybylType
self.lBondedAtoms = lBondedAtoms
self.lBonds = lBonds
self.radius = 1.0
self.isCterm=0
self.isNterm=0
###
try:
self.occupancy = float(string.strip(line[54:60]))
self.tempFactor = float(string.strip(line[60:66]))
self.segID = string.strip(line[72:76])
self.element = string.strip(line[76:78])
self.charge = string.strip(line[78:80])
except (ValueError, IndexError):
self.occupancy = 0.00
self.tempFactor = 0.00
self.segID = ""
self.element = ""
self.charge = ""
else: raise ValueError, record
def __str__(self):
"""
Print object as string
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------
7-11 int serial Atom serial number.
13-16 string name Atom name.
17 string altLoc Alternate location indicator.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Code for insertion of residues.
31-38 float x Orthogonal coordinates for X in
Angstroms.
39-46 float y Orthogonal coordinates for Y in
Angstroms.
47-54 float z Orthogonal coordinates for Z in
Angstroms.
55-60 float occupancy Occupancy.
61-66 float tempFactor Temperature factor.
73-76 string segID Segment identifier, left-justified.
77-78 string element Element symbol, right-justified.
79-80 string charge Charge on the atom.
"""
str = ""
tstr = "HETATM"
str = str + string.ljust(tstr, 6)[:6]
tstr = "%d" % self.serial
str = str + string.rjust(tstr, 5)[:5]
str = str + " "
tstr = self.name
if len(tstr) == 4:
str = str + string.ljust(tstr, 4)[:4]
else:
str = str + " " + string.ljust(tstr, 3)[:3]
tstr = self.altLoc
str = str + string.ljust(tstr, 1)[:1]
tstr = self.resName
str = str + string.ljust(tstr, 3)[:3]
str = str + " "
tstr = self.chainID
str = str + string.ljust(tstr, 1)[:1]
tstr = "%d" % self.resSeq
str = str + string.rjust(tstr, 4)[:4]
tstr = self.iCode
str = str + string.ljust(tstr, 1)[:1]
str = str + " "
tstr = "%8.3f" % self.x
str = str + string.ljust(tstr, 8)[:8]
tstr = "%8.3f" % self.y
str = str + string.ljust(tstr, 8)[:8]
tstr = "%8.3f" % self.z
str = str + string.ljust(tstr, 8)[:8]
tstr = "%6.2f" % self.occupancy
str = str + string.ljust(tstr, 6)[:6]
tstr = "%6.2f" % self.tempFactor
str = str + string.rjust(tstr, 6)[:6]
tstr = self.segID
str = str + string.ljust(tstr, 4)[:4]
tstr = self.element
str = str + string.ljust(tstr, 2)[:2]
tstr = self.charge
str = str + string.ljust(tstr, 2)[:2]
return str
### PC
# to do: - parse SUBSTRUCTURE
# - avoid/detect blanks in @<TRIPOS>BOND
# - what happens, if no SUBSTRUCTURE present?
# - different order of SUBSTRUCTURE/MOLECULE
# - readlines instead of read -> blanks are avoided (you get a list)
# - (maybe) flag for parsing each RTI
class MOL2BOND:
"""
Bonding of MOL2 files
"""
def __init__(self, frm, to, type, id=0):
self.to = to # bond to this atom
self.frm = frm # bond from atom
self.type = type # 1=single, 2=double, ar=aromatic
self.id = id # bond_id
class MOL2MOLECULE:
"""
Tripos MOL2 molecule
For further information look at (web page exists: 25 August 2005):
http://www.tripos.com/index.php?family=modules,SimplePage,,,&page=sup_mol2&s=0
"""
def __init__(self):
self.lAtoms = [] # all atoms of class <ATOM>
self.lBonds = [] # all bonds of class <BOND>
self.lPDBAtoms = [] # PDB-like list of all atoms
def read(self,file):
"""
Routines for reading MOL2 file
"""
#self.filename = filename
#data = open(self.filename).read()
data = file.read()
data = data.replace("\r\n", "\n")
data = data.replace("\r", "\n")
# ATOM section
start = data.find("@<TRIPOS>ATOM")
stop = data.find("@<TRIPOS>BOND")
# Do some error checking
if start == -1:
raise Exception, "Unable to find '@<TRIPOS>ATOM' in MOL2 file!"
elif stop == -1:
raise Exception, "Unable to find '@<TRIPOS>BOND' in MOL2 file!"
atoms = data[start+14:stop-2].split("\n")
# BOND section
start = data.find("@<TRIPOS>BOND")
stop = data.find("@<TRIPOS>SUBSTRUCTURE")
# More error checking
if stop == -1:
raise Exception, "Unable to find '@<TRIPOS>SUBSTRUCTURE' in MOL2 file!"
bonds = data[start+14:stop-1].split("\n")
self.parseAtoms(atoms)
self.parseBonds(bonds)
self.createlBondedAtoms()
#self.createPDBlineFromMOL2(atoms)
def parseAtoms(self,AtomList):
"""
for parsing @<TRIPOS>ATOM
"""
for AtomLine in AtomList:
SeparatedAtomLine = AtomLine.split()
# Special handling for blank lines
if len(SeparatedAtomLine) == 0:
continue
# Error checking
if len(SeparatedAtomLine) < 8:
raise Exception, "Bad atom entry in MOL2 file: %s" % AtomLine
fakeRecord = "HETATM"
fakeChain = " L"
try:
mol2pdb = '%s%5i%5s%4s%2s%4i %8.3f%8.3f%8.3f' %\
(fakeRecord,int(SeparatedAtomLine[0]),
SeparatedAtomLine[1],SeparatedAtomLine[7][:4],
fakeChain,int(SeparatedAtomLine[6]),
float(SeparatedAtomLine[2]),float(SeparatedAtomLine[3]),
float(SeparatedAtomLine[4]))
except ValueError:
raise Exception, "Bad atom entry in MOL2 file: %s" % AtomLine
thisAtom = HETATM(mol2pdb, SeparatedAtomLine[5],[],[])
if len(SeparatedAtomLine)>8:
charge=SeparatedAtomLine[8]
try:
thisAtom.mol2charge=float(charge)
except:
print 'Warning. Non-float charge in mol2 file.',charge
thisAtom.mol2charge=None
self.lPDBAtoms.append(mol2pdb)
self.lAtoms.append(thisAtom)
def parseBonds(self,BondList):
"""
for parsing @<TRIPOS>BOND
"""
for BondLine in BondList:
SeparatedBondLine = BondLine.split()
# Special handling for blank lines
if len(SeparatedBondLine) == 0:
continue
if len(SeparatedBondLine) < 4:
raise Exception, "Bad bond entry in MOL2 file: %s" % BondLine
try:
thisBond = MOL2BOND(
int(SeparatedBondLine[1]), # bond frm
int(SeparatedBondLine[2]), # bond to
SeparatedBondLine[3], # bond type
int(SeparatedBondLine[0]) # bond id
)
except ValueError:
raise Exception, "Bad bond entry in MOL2 file: %s" % BondLine
self.lBonds.append(thisBond)
def createlBondedAtoms(self):
"""
Creates for each atom a list of the bonded Atoms
This becomes one attribute of MOL2ATOM!
"""
for bond in self.lBonds:
self.lAtoms[bond.frm-1].lBondedAtoms.append(
self.lAtoms[bond.to-1])
self.lAtoms[bond.to-1].lBondedAtoms.append(
self.lAtoms[bond.frm-1])
atbond = copy.deepcopy(bond)
atbond.other_atom=self.lAtoms[bond.to-1]
self.lAtoms[bond.frm-1].lBonds.append(atbond)
atbond = copy.deepcopy(bond)
atbond.other_atom=self.lAtoms[bond.frm-1]
self.lAtoms[bond.to-1].lBonds.append(atbond)
return
def createPDBlineFromMOL2(self):
FakeType = "HETATM"
return ('%s%5i%5s%4s%2s%5s %8.3f%8.3f%8.3f\n' %
(FakeType, self.serial, self.name,
self.resName, ' L', self.resSeq,
self.x,self.y, self.z))
### PC
class ATOM:
""" ATOM class
The ATOM records present the atomic coordinates for standard residues.
They also present the occupancy and temperature factor for each atom.
Heterogen coordinates use the HETATM record type. The element symbol is
always present on each ATOM record; segment identifier and charge are
optional.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------
7-11 int serial Atom serial number.
13-16 string name Atom name.
17 string altLoc Alternate location indicator.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Code for insertion of residues.
31-38 float x Orthogonal coordinates for X in
Angstroms.
39-46 float y Orthogonal coordinates for Y in
Angstroms.
47-54 float z Orthogonal coordinates for Z in
Angstroms.
55-60 float occupancy Occupancy.
61-66 float tempFactor Temperature factor.
73-76 string segID Segment identifier, left-justified.
77-78 string element Element symbol, right-justified.
79-80 string charge Charge on the atom.
"""
record = string.strip(line[0:6])
if record == "ATOM":
self.serial = int(string.strip(line[6:11]))
self.name = string.strip(line[12:16])
self.altLoc = string.strip(line[16])
self.resName = string.strip(line[17:20])
self.chainID = string.strip(line[21])
self.resSeq = int(string.strip(line[22:26]))
self.iCode = string.strip(line[26])
self.x = float(string.strip(line[30:38]))
self.y = float(string.strip(line[38:46]))
self.z = float(string.strip(line[46:54]))
try:
self.occupancy = float(string.strip(line[54:60]))
self.tempFactor = float(string.strip(line[60:66]))
self.segID = string.strip(line[72:76])
self.element = string.strip(line[76:78])
self.charge = string.strip(line[78:80])
except (ValueError, IndexError):
self.occupancy = 0.00
self.tempFactor = 0.00
self.segID = ""
self.element = ""
self.charge = ""
else:
raise ValueError, record
def __str__(self):
"""
Print object as string
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------
7-11 int serial Atom serial number.
13-16 string name Atom name.
17 string altLoc Alternate location indicator.
18-20 string resName Residue name.
22 string chainID Chain identifier.
23-26 int resSeq Residue sequence number.
27 string iCode Code for insertion of residues.
31-38 float x Orthogonal coordinates for X in
Angstroms.
39-46 float y Orthogonal coordinates for Y in
Angstroms.
47-54 float z Orthogonal coordinates for Z in
Angstroms.
55-60 float occupancy Occupancy.
61-66 float tempFactor Temperature factor.
73-76 string segID Segment identifier, left-justified.
77-78 string element Element symbol, right-justified.
79-80 string charge Charge on the atom.
"""
str = ""
tstr = "ATOM"
str = str + string.ljust(tstr, 6)[:6]
tstr = "%d" % self.serial
str = str + string.rjust(tstr, 5)[:5]
str = str + " "
tstr = self.name
if len(tstr) == 4:
str = str + string.ljust(tstr, 4)[:4]
else:
str = str + " " + string.ljust(tstr, 3)[:3]
tstr = self.altLoc
str = str + string.ljust(tstr, 1)[:1]
tstr = self.resName
str = str + string.ljust(tstr, 3)[:3]
str = str + " "
tstr = self.chainID
str = str + string.ljust(tstr, 1)[:1]
tstr = "%d" % self.resSeq
str = str + string.rjust(tstr, 4)[:4]
tstr = self.iCode
str = str + string.ljust(tstr, 1)[:1]
str = str + " "
tstr = "%8.3f" % self.x
str = str + string.ljust(tstr, 8)[:8]
tstr = "%8.3f" % self.y
str = str + string.ljust(tstr, 8)[:8]
tstr = "%8.3f" % self.z
str = str + string.ljust(tstr, 8)[:8]
tstr = "%6.2f" % self.occupancy
str = str + string.ljust(tstr, 6)[:6]
tstr = "%6.2f" % self.tempFactor
str = str + string.ljust(tstr, 6)[:6]
tstr = self.segID
str = str + string.ljust(tstr, 4)[:4]
tstr = self.element
str = str + string.ljust(tstr, 2)[:2]
tstr = self.charge
str = str + string.ljust(tstr, 2)[:2]
return str
class MODEL:
""" MODEL class
The MODEL record specifies the model serial number when multiple
structures are presented in a single coordinate entry, as is often the
case with structures determined by NMR.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
11-14 int serial Model serial number.
"""
record = string.strip(line[0:6])
if record == "MODEL":
self.serial = int(string.strip(line[10:14]))
else: raise ValueError, record
class TVECT:
""" TVECT class
The TVECT records present the translation vector for infinite
covalently connected structures.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
8-10 int serial Serial number
11-20 float t1 Components of translation vector
21-30 float t2 Components of translation vector
31-40 float t2 Components of translation vector
41-70 string text Comments
"""
record = string.strip(line[0:6])
if record == "TVECT":
self.serial = int(string.strip(line[7:10]))
self.t1 = float(string.strip(line[10:20]))
self.t2 = float(string.strip(line[20:30]))
self.t3 = float(string.strip(line[30:40]))
self.text = string.strip(line[40:70])
else: raise ValueError, record
class MTRIX3:
""" MTRIX3 class
The MTRIX3 (n = 1, 2, or 3) records present transformations expressing
non-crystallographic symmetry.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
8-10 int serial Serial number
11-20 float mn1 M31
21-30 float mn2 M32
31-40 float mn3 M33
46-55 float vn V3
60 int iGiven 1 if coordinates for the representations
which are approximately related by the
transformations of the molecule are contained in
the entry. Otherwise, blank.
"""
record = string.strip(line[0:6])
if record == "MTRIX3":
self.serial = int(string.strip(line[7:10]))
self.mn1 = float(string.strip(line[10:20]))
self.mn2 = float(string.strip(line[20:30]))
self.mn3 = float(string.strip(line[30:40]))
self.vn = float(string.strip(line[45:55]))
self.iGiven = int(string.strip(line[59]))
else: raise ValueError, record
class MTRIX2:
""" MTRIX2 class
The MTRIXn (n = 1, 2, or 3) records present transformations expressing
non-crystallographic symmetry.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
8-10 int serial Serial number
11-20 float mn1 M21
21-30 float mn2 M22
31-40 float mn3 M23
46-55 float vn V2
60 int iGiven 1 if coordinates for the representations
which are approximately related by the
transformations of the molecule are contained in
the entry. Otherwise, blank.
"""
record = string.strip(line[0:6])
if record == "MTRIX2":
self.serial = int(string.strip(line[7:10]))
self.mn1 = float(string.strip(line[10:20]))
self.mn2 = float(string.strip(line[20:30]))
self.mn3 = float(string.strip(line[30:40]))
self.vn = float(string.strip(line[45:55]))
self.iGiven = int(string.strip(line[59]))
else: raise ValueError, record
class MTRIX1:
""" MTRIX1 class
The MTRIXn (n = 1, 2, or 3) records present transformations expressing
non-crystallographic symmetry.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
8-10 int serial Serial number
11-20 float mn1 M11
21-30 float mn2 M12
31-40 float mn3 M13
46-55 float vn V1
60 int iGiven 1 if coordinates for the representations
which are approximately related by the
transformations of the molecule are contained in
the entry. Otherwise, blank.
"""
record = string.strip(line[0:6])
if record == "MTRIX1":
self.serial = int(string.strip(line[7:10]))
self.mn1 = float(string.strip(line[10:20]))
self.mn2 = float(string.strip(line[20:30]))
self.mn3 = float(string.strip(line[30:40]))
self.vn = float(string.strip(line[45:55]))
try: self.iGiven = int(string.strip(line[45:55]))
except (ValueError, IndexError): self.iGiven = None
else: raise ValueError, record
class SCALE3:
""" SCALE3 class
The SCALEn (n = 1, 2, or 3) records present the transformation from the
orthogonal coordinates as contained in the entry to fractional
crystallographic coordinates. Non-standard coordinate systems should be
explained in the remarks.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
11-20 float sn1 S31
21-30 float sn2 S32
31-40 float sn3 S33
46-55 float un U3
"""
record = string.strip(line[0:6])
if record == "SCALE3":
self.sn1 = float(string.strip(line[10:20]))
self.sn2 = float(string.strip(line[20:30]))
self.sn3 = float(string.strip(line[30:40]))
self.un = float(string.strip(line[45:55]))
else: raise ValueError, record
class SCALE2:
""" SCALE2 class
The SCALEn (n = 1, 2, or 3) records present the transformation from the
orthogonal coordinates as contained in the entry to fractional
crystallographic coordinates. Non-standard coordinate systems should be
explained in the remarks.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
11-20 float sn1 S21
21-30 float sn2 S22
31-40 float sn3 S23
46-55 float un U2
"""
record = string.strip(line[0:6])
if record == "SCALE2":
self.sn1 = float(string.strip(line[10:20]))
self.sn2 = float(string.strip(line[20:30]))
self.sn3 = float(string.strip(line[30:40]))
self.un = float(string.strip(line[45:55]))
else: raise ValueError, record
class SCALE1:
""" SCALE1 class
The SCALEn (n = 1, 2, or 3) records present the transformation from the
orthogonal coordinates as contained in the entry to fractional
crystallographic coordinates. Non-standard coordinate systems should be
explained in the remarks.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
11-20 float sn1 S11
21-30 float sn2 S12
31-40 float sn3 S13
46-55 float un U1
"""
record = string.strip(line[0:6])
if record == "SCALE1":
self.sn1 = float(string.strip(line[10:20]))
self.sn2 = float(string.strip(line[20:30]))
self.sn3 = float(string.strip(line[30:40]))
self.un = float(string.strip(line[45:55]))
else: raise ValueError, record
class ORIGX2:
""" ORIGX2 class
The ORIGXn (n = 1, 2, or 3) records present the transformation from the
orthogonal coordinates contained in the entry to the submitted
coordinates.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
11-20 float on1 O21
21-30 float on2 O22
31-40 float on3 O23
46-55 float tn T2
"""
record = string.strip(line[0:6])
if record == "ORIGX2":
self.on1 = float(string.strip(line[10:20]))
self.on2 = float(string.strip(line[20:30]))
self.on3 = float(string.strip(line[30:40]))
self.tn = float(string.strip(line[45:55]))
else: raise ValueError, record
class ORIGX3:
""" ORIGX3 class
The ORIGXn (n = 1, 2, or 3) records present the transformation from the
orthogonal coordinates contained in the entry to the submitted
coordinates.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
11-20 float on1 O31
21-30 float on2 O32
31-40 float on3 O33
46-55 float tn T3
"""
record = string.strip(line[0:6])
if record == "ORIGX3":
self.on1 = float(string.strip(line[10:20]))
self.on2 = float(string.strip(line[20:30]))
self.on3 = float(string.strip(line[30:40]))
self.tn = float(string.strip(line[45:55]))
else: raise ValueError, record
class ORIGX1:
""" ORIGX1 class
The ORIGXn (n = 1, 2, or 3) records present the transformation from the
orthogonal coordinates contained in the entry to the submitted
coordinates.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------
11-20 float on1 O11
21-30 float on2 O12
31-40 float on3 O13
46-55 float tn T1
"""
record = string.strip(line[0:6])
if record == "ORIGX1":
self.on1 = float(string.strip(line[10:20]))
self.on2 = float(string.strip(line[20:30]))
self.on3 = float(string.strip(line[30:40]))
self.tn = float(string.strip(line[45:55]))
else: raise ValueError, record
class CRYST1:
""" CRYST1 class
The CRYST1 record presents the unit cell parameters, space group, and Z
value. If the structure was not determined by crystallographic means,
CRYST1 simply defines a unit cube.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------------
7-15 float a a (Angstroms).
16-24 float b b (Angstroms).
25-33 float c c (Angstroms).
34-40 float alpha alpha (degrees).
41-47 float beta beta (degrees).
48-54 float gamma gamma (degrees).
56-66 string sGroup Space group.
67-70 int z Z value.
"""
record = string.strip(line[0:6])
if record == "CRYST1":
self.a = float(string.strip(line[6:15]))
self.b = float(string.strip(line[15:24]))
self.c = float(string.strip(line[24:33]))
self.alpha = float(string.strip(line[33:40]))
self.beta = float(string.strip(line[40:47]))
self.gamma = float(string.strip(line[47:54]))
self.sGroup = string.strip(line[55:65])
self.z = int(string.strip(line[66:70]))
else: raise ValueError, record
class SITE:
""" SITE class
The SITE records supply the identification of groups comprising
important sites in the macromolecule.
"""
def __init__(self, line):
"""
Initialize by parsing the line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------------------------
8-10 int seqNum Sequence number.
12-14 string siteID Site name.
16-17 int numRes Number of residues comprising site.
19-21 string resName1 Residue name for first residue
comprising site.
23 string chainID1 Chain identifier for first residue
comprising site.
24-27 int seq1 Residue sequence number for first
residue comprising site.
28 string iCode1 Insertion code for first residue
comprising site.
30-32 string resName2 Residue name for second residue
comprising site.
34 string chainID2 Chain identifier for second residue
comprising site.
35-38 int seq2 Residue sequence number for second
residue comprising site.
39 string iCode2 Insertion code for second residue
comprising site.
41-43 string resName3 Residue name for third residue
comprising site.
45 string chainID3 Chain identifier for third residue
comprising site.
46-49 int seq3 Residue sequence number for third
residue comprising site.
50 string iCode3 Insertion code for third residue
comprising site.
52-54 string resName4 Residue name for fourth residue
comprising site.
56 string chainID4 Chain identifier for fourth residue
comprising site.
57-60 int seq4 Residue sequence number for fourth
residue comprising site.
61 string iCode4 Insertion code for fourth residue
comprising site.
"""
record = string.strip(line[0:6])
if record == "SITE":
self.seqNum = int(string.strip(line[7:10]))
self.siteID = string.strip(line[11:14])
self.numRes = int(string.strip(line[15:17]))
self.resName1 = string.strip(line[18:21])
self.chainID1 = string.strip(line[22])
self.seq1 = int(string.strip(line[23:27]))
self.iCode1 = string.strip(line[27])
self.resName2 = string.strip(line[29:32])
self.chainID2 = string.strip(line[33])
self.seq2 = int(string.strip(line[34:38]))
self.iCode2 = string.strip(line[38])
self.resName3 = string.strip(line[40:43])
self.chainID3 = string.strip(line[44])
self.seq3 = int(string.strip(line[45:49]))
self.iCode3 = string.strip(line[49])
self.resName4 = string.strip(line[51:54])
self.chainID4 = string.strip(line[55])
self.seq4 = int(string.strip(line[56:60]))
try: self.iCode4 = string.strip(line[60])
except IndexError: self.iCode4 = None
else: raise ValueError, record
class CISPEP:
""" CISPEP field
CISPEP records specify the prolines and other peptides found to be in
the cis conformation. This record replaces the use of footnote records
to list cis peptides.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------------
8-10 int serNum Record serial number.
12-14 string pep1 Residue name.
16 string chainID1 Chain identifier.
18-21 int seqNum1 Residue sequence number.
22 string icode1 Insertion code.
26-28 string pep2 Residue name.
30 string chainID2 Chain identifier.
32-35 int seqNum2 Residue sequence number.
36 string icode2 Insertion code.
44-46 int modNum Identifies the specific model.
54-59 float measure Measure of the angle in degrees.
"""
record = string.strip(line[0:6])
if record == "CISPEP":
self.serNum = int(string.strip(line[7:10]))
self.pep1 = string.strip(line[11:14])
self.chainID1 = string.strip(line[15])
self.seqNum1 = int(string.strip(line[17:21]))
self.icode1 = string.strip(line[21])
self.pep2 = string.strip(line[25:28])
self.chainID2 = string.strip(line[29])
self.seqNum2 = int(string.strip(line[31:35]))
self.icode2 = string.strip(line[35])
self.modNum = int(string.strip(line[43:46]))
self.measure = float(string.strip(line[53:59]))
else: raise ValueError, record
class SLTBRG:
""" SLTBRG field
The SLTBRG records specify salt bridges in the entry.
records and is provided here for convenience in searching.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
13-16 string name1 Atom name.
17 string altLoc1 Alternate location indicator.
18-20 string resName1 Residue name.
22 string chainID1 Chain identifier.
23-26 int resSeq1 Residue sequence number.
27 string iCode1 Insertion code.
43-46 string name2 Atom name.
47 string altLoc2 Alternate location indicator.
48-50 string resName2 Residue name.
52 string chainID2 Chain identifier.
53-56 int resSeq2 Residue sequence number.
57 string iCode2 Insertion code.
60-65 string sym1 Symmetry operator for 1st atom.
67-72 string sym2 Symmetry operator for 2nd atom.
"""
record = string.strip(line[0:6])
if record == "SLTBRG":
self.name1 = string.strip(line[12:16])
self.altLoc1 = string.strip(line[16])
self.resName1 = string.strip(line[17:20])
self.chainID1 = string.strip(line[21])
self.resSeq1 = int(string.strip(line[22:26]))
self.iCode1 = string.strip(line[26])
self.name2 = string.strip(line[42:46])
self.altLoc2 = string.strip(line[46])
self.resName2 = string.strip(line[47:50])
self.chainID2 = string.strip(line[51])
self.resSeq2 = int(string.strip(line[52:56]))
self.iCode2 = string.strip(line[56])
self.sym1 = string.strip(line[59:65])
self.sym2 = string.strip(line[66:72])
else: raise ValueError, record
class HYDBND:
""" HYDBND field
The HYDBND records specify hydrogen bonds in the entry.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------------
13-16 string name1 Atom name.
17 string altLoc1 Alternate location indicator.
18-20 string resName1 Residue name.
22 string Chain1 Chain identifier.
23-27 int resSeq1 Residue sequence number.
28 string ICode1 Insertion code.
30-33 string nameH Hydrogen atom name.
34 string altLocH Alternate location indicator.
36 string ChainH Chain identifier.
37-41 int resSeqH Residue sequence number.
42 string iCodeH Insertion code.
44-47 string name2 Atom name.
48 string altLoc2 Alternate location indicator.
49-51 string resName2 Residue name.
53 string chainID2 Chain identifier.
54-58 int resSeq2 Residue sequence number.
59 string iCode2 Insertion code.
60-65 string sym1 Symmetry operator for 1st
non-hydrogen atom.
67-72 string sym2 Symmetry operator for 2nd
non-hydrogen atom.
"""
record = string.strip(line[0:6])
if record == "HYDBND":
self.name1 = string.strip(line[12:16])
self.altLoc1 = string.strip(line[16])
self.resName1 = string.strip(line[17:20])
self.Chain1 = string.strip(line[21])
self.resSeq1 = string.strip(line[22:27])
self.ICode1 = string.strip(line[27])
self.nameH = string.strip(line[29:33])
self.altLocH = string.strip(line[33])
self.ChainH = string.strip(line[35])
self.resSeqH = string.strip(line[36:41])
self.ICodeH = string.strip(line[41])
self.name2 = string.strip(line[43:47])
self.altLoc2 = string.strip(line[47])
self.resName2 = string.strip(line[48:51])
self.Chain2 = string.strip(line[52])
self.resSeq2 = string.strip(line[53:58])
self.ICode2 = string.strip(line[58])
self.sym1 = string.strip(line[59:65])
self.sym2 = string.strip(line[66:72])
else: raise ValueError, record
class LINK:
""" LINK field
The LINK records specify connectivity between residues that is not
implied by the primary structure. Connectivity is expressed in terms of
the atom names. This record supplements information given in CONECT
records and is provided here for convenience in searching.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
13-16 string name1 Atom name.
17 string altLoc1 Alternate location indicator.
18-20 string resName1 Residue name.
22 string chainID1 Chain identifier.
23-26 int resSeq1 Residue sequence number.
27 string iCode1 Insertion code.
43-46 string name2 Atom name.
47 string altLoc2 Alternate location indicator.
48-50 string resName2 Residue name.
52 string chainID2 Chain identifier.
53-56 int resSeq2 Residue sequence number.
57 string iCode2 Insertion code.
60-65 string sym1 Symmetry operator for 1st atom.
67-72 string sym2 Symmetry operator for 2nd atom.
"""
record = string.strip(line[0:6])
if record == "LINK":
self.name1 = string.strip(line[12:16])
self.altLoc1 = string.strip(line[16])
self.resName1 = string.strip(line[17:20])
self.chainID1 = string.strip(line[21])
self.resSeq1 = int(string.strip(line[22:26]))
self.iCode1 = string.strip(line[26])
self.name2 = string.strip(line[42:46])
self.altLoc2 = string.strip(line[46])
self.resName2 = string.strip(line[47:50])
self.chainID2 = string.strip(line[51])
self.resSeq2 = int(string.strip(line[52:56]))
self.iCode2 = string.strip(line[56])
self.sym1 = string.strip(line[59:65])
self.sym2 = string.strip(line[66:72])
else: raise ValueError, record
class SSBOND:
""" SSBOND field
The SSBOND record identifies each disulfide bond in protein and
polypeptide structures by identifying the two residues involved in the
bond.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
8 - 10 int serNum Serial number.
16 string chainID1 Chain identifier.
18 - 21 int seqNum1 Residue sequence number.
22 string icode1 Insertion code.
30 string chainID2 Chain identifier.
32 - 35 int seqNum2 Residue sequence number.
36 string icode2 Insertion code.
60 - 65 string sym1 Symmetry operator for 1st residue.
67 - 72 string sym2 Symmetry operator for 2nd residue.
"""
record = string.strip(line[0:6])
if record == "SSBOND":
self.serNum = int(string.strip(line[7:10]))
self.chainID1 = string.strip(line[15])
self.seqNum1 = int(string.strip(line[17:21]))
self.icode1 = string.strip(line[21])
self.chainID2 = string.strip(line[29])
self.seqNum2 = int(string.strip(line[31:35]))
self.icode2 = string.strip(line[35])
self.sym1 = string.strip(line[59:65])
self.sym2 = string.strip(line[66:72])
else: raise ValueError, record
class TURN:
""" TURN field
The TURN records identify turns and other short loop turns which
normally connect other secondary structure segments.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------------------
8-10 int seq Turn number; starts with 1 and
increments by one.
12-14 string turnId Turn identifier
16-18 string initResName Residue name of initial residue in
turn.
20 string initChainId Chain identifier for the chain
containing this turn.
21-24 int initSeqNum Sequence number of initial residue in
turn.
25 string initICode Insertion code of initial residue in
turn.
27-29 string endResName Residue name of terminal residue of
turn.
31 string endChainId Chain identifier for the chain
containing this turn.
32-35 int endSeqNum Sequence number of terminal residue of
turn.
36 string endICode Insertion code of terminal residue of
turn.
41-70 string comment Associated comment.
"""
record = string.strip(line[0:6])
if record == "TURN":
self.seq = int(string.strip(line[7:10]))
self.turnId = string.strip(line[11:14])
self.initResName = string.strip(line[15:18])
self.initChainId = string.strip(line[19])
self.initSeqNum = int(string.strip(line[20:24]))
self.initICode = string.strip(line[24])
self.endResName = string.strip(line[26:29])
self.endChainId = string.strip(line[30])
self.endSeqNum = int(string.strip(line[31:35]))
self.endICode = string.strip(line[35])
self.comment = string.strip(line[40:70])
else: raise ValueError, record
class SHEET:
""" SHEET field
SHEET records are used to identify the position of sheets in the
molecule. Sheets are both named and numbered. The residues where the
sheet begins and ends are noted.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-------------------------------------------------
8 - 10 int strand Strand number which starts at 1 for
each strand within a sheet and
increases by one.
12 - 14 string sheetID Sheet identifier.
15 - 16 int numStrands Number of strands in sheet.
18 - 20 string initResName Residue name of initial residue.
22 string initChainID Chain identifier of initial residue in
strand.
23 - 26 int initSeqNum Sequence number of initial residue in
strand.
27 string initICode Insertion code of initial residue in
strand.
29 - 31 string endResName Residue name of terminal residue.
33 string endChainID Chain identifier of terminal residue.
34 - 37 int endSeqNum Sequence number of terminal residue.
38 string endICode Insertion code of terminal residue.
39 - 40 int sense Sense of strand with respect to
previous strand in the sheet. 0 if
first strand, 1 if parallel, -1 if
anti-parallel.
42 - 45 string curAtom Registration. Atom name in current
strand.
46 - 48 string curResName Registration. Residue name in current
strand.
50 string curChainId Registration. Chain identifier in
current strand.
51 - 54 int curResSeq Registration. Residue sequence number
in current strand.
55 string curICode Registration. Insertion code in current
strand.
57 - 60 string prevAtom Registration. Atom name in previous
strand.
61 - 63 string prevResName Registration. Residue name in previous
strand.
65 string prevChainId Registration. Chain identifier in
previous strand.
66 - 69 int prevResSeq Registration. Residue sequence number
in previous strand.
70 string prevICode Registration. Insertion code in
previous strand.
"""
record = string.strip(line[0:6])
if record == "SHEET":
self.strand = int(string.strip(line[7:10]))
self.sheetID = string.strip(line[11:14])
self.numStrands = int(string.strip(line[14:16]))
self.initResName = string.strip(line[17:20])
self.initChainID = string.strip(line[21])
self.initSeqNum = int(string.strip(line[22:26]))
self.initICode = string.strip(line[26])
self.endResName = string.strip(line[28:31])
self.endChainID = string.strip(line[32])
self.endSeqNum = int(string.strip(line[33:37]))
self.endICode = string.strip(line[37])
self.sense = int(string.strip(line[38:40]))
try:
self.curAtom = string.strip(line[41:45])
self.curResName = string.strip(line[45:48])
self.curChainID = string.strip(line[49])
try: self.curResSeq = int(string.strip(line[50:54]))
except ValueError: self.curResSeq = None
self.curICode = string.strip(line[54])
self.prevAtom = string.strip(line[56:60])
self.prevResName = string.strip(line[60:63])
self.prevChainID = string.strip(line[64])
try: self.prevResSeq = int(string.strip(line[65:69]))
except ValueError: self.prevResSeq = None
self.prevICode = string.strip(line[69])
except IndexError:
self.curAtom = None
self.curResName = None
self.curChainID = None
self.curResSeq = None
self.curICode = None
self.prevAtom = None
self.prevResName = None
self.prevChainID = None
self.prevResSeq = None
self.prevICode = None
else: raise ValueError, record
class HELIX:
""" HELIX field
HELIX records are used to identify the position of helices in the
molecule. Helices are both named and numbered. The residues where the
helix begins and ends are noted, as well as the total length.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
------------------------------------------------------
8-10 int serNum Serial number of the helix. This
starts at 1 and increases
incrementally.
12-14 string helixID Helix identifier. In addition to a
serial number, each helix is given an
alphanumeric character helix identifier.
16-18 string initResName Name of the initial residue.
20 string initChainID Chain identifier for the chain
containing this helix.
22-25 int initSeqNum Sequence number of the initial residue.
26 string initICode Insertion code of the initial residue.
28-30 string endResName Name of the terminal residue of
the helix.
32 string endChainID Chain identifier for the chain
containing this helix.
34-37 int endSeqNum Sequence number of the terminal residue.
38 string endICode Insertion code of the terminal residue.
39-40 int helixClass Helix class (see below).
41-70 string comment Comment about this helix.
72-76 int length Length of this helix.
"""
record = string.strip(line[0:6])
if record == "HELIX":
self.serNum = int(string.strip(line[7:10]))
self.helixID = string.strip(line[11:14])
self.initResName = string.strip(line[15:18])
self.initChainID = string.strip(line[19])
self.initSeqNum = int(string.strip(line[21:25]))
self.initICode = string.strip(line[25])
self.endResName = string.strip(line[27:30])
self.endChainID = string.strip(line[31])
self.endSeqNum = int(string.strip(line[33:37]))
self.endICode = string.strip(line[37])
try: self.helixClass = int(string.strip(line[38:40]))
except ValueError: self.helixClass = None
self.comment = string.strip(line[40:70])
try: self.length = int(string.strip(line[71:76]))
except ValueError: self.length = None
else: raise ValueError, record
class FORMUL:
""" FORMUL field
The FORMUL record presents the chemical formula and charge of a
non-standard group.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
9-10 int compNum Component number
13-15 string hetID Het identifier
19 string asterisk * for water
20-70 string text Chemical formula
"""
record = string.strip(line[0:6])
if record == "FORMUL":
self.compNum = int(string.strip(line[8:10]))
self.hetID = string.strip(line[12:15])
self.asterisk = string.strip(line[19])
self.text = string.strip(line[19:70])
else: raise ValueError, record
class HETSYN:
""" HETSYN field
This record provides synonyms, if any, for the compound in the
corresponding (i.e., same hetID) HETNAM record. This is to allow
greater flexibility in searching for HET groups.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
12-14 string hetID Het identifier, right-justified.
16-70 string hetSynonyms List of synonyms
"""
record = string.strip(line[0:6])
if record == "HETSYN":
self.hetID = string.strip(line[11:14])
self.hetSynonyms = string.strip(line[15:70])
else: raise ValueError, record
class HETNAM:
""" HETNAM field
This record gives the chemical name of the compound with the given
hetID.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
12-14 string hetID Het identifier, right-justified.
16-70 string text Chemical name.
"""
record = string.strip(line[0:6])
if record == "HETNAM":
self.hetID = string.strip(line[11:14])
self.text = string.strip(line[15:70])
else: raise ValueError, record
class HET:
""" HET field
HET records are used to describe non-standard residues, such as
prosthetic groups, inhibitors, solvent molecules, and ions for which
coordinates are supplied. Groups are considered HET if they are:
- not one of the standard amino acids, and
- not one of the nucleic acids (C, G, A, T, U, and I), and
- not one of the modified versions of nucleic acids (+C, +G, +A, +T,
+U, and +I), and
- not an unknown amino acid or nucleic acid where UNK is used to
indicate the unknown residue name.
Het records also describe heterogens for which the chemical identity is
unknown, in which case the group is assigned the hetID UNK.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------------------
8-10 string hetID Het identifier, right-justified.
13 string ChainID Chain identifier.
14-17 int seqNum Sequence number.
18 string iCode Insertion code.
21-25 int numHetAtoms Number of HETATM records for the
31-70 string text Text describing Het group.
"""
record = string.strip(line[0:6])
if record == "HET":
self.hetID = string.strip(line[7:10])
self.chainID = string.strip(line[12])
try: self.seqNum = int(string.strip(line[13]))
except ValueError: self.seqNum = None
self.iCode = string.strip(line[17])
self.numHetAtoms = int(string.strip(line[20:25]))
self.text = string.strip(line[30:70])
else: raise ValueError, record
class MODRES:
""" MODRES field
The MODRES record provides descriptions of modifications (e.g.,
chemical or post-translational) to protein and nucleic acid residues.
Included are a mapping between residue names given in a PDB entry and
standard residues.
"""
def __init__(self, line):
"""
Initialize by parsing a line
COLUMNS TYPE FIELD DEFINITION
---------------------------------------
8-11 string idCode ID code of this entry.
13-15 string resName Residue name used in this entry.
17 string chainID Chain identifier.
19-22 int seqNum Sequence number.
23 string iCode Insertion code.
25-27 string stdRes Standard residue name.
30-70 string comment Description of the residue modification.
"""
record = string.strip(line[0:6])
if record == "MODRES":
string.idCode = string.strip(line[7:11])
string.resName = string.strip(line[12:15])
string.chainID = string.strip(line[16])
string.seqNum = int(string.strip(line[18:22]))
string.iCode = string.strip(line[22])
string.stdRes = string.strip(line[24:27])
string.comment = string.strip(line[29:70])
else: raise ValueError, record
class SEQRES:
""" SEQRES field
SEQRES records contain the amino acid or nucleic acid sequence of
residues in each chain of the macromolecule that was studied.
"""
def __init__(self, line):
"""
Initialize by parsing a line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
9-10 int serNum Serial number of the SEQRES record for the
current chain. Starts at 1 and increments
by one each line. Reset to 1 for each
chain.
12 string chainID Chain identifier. This may be any single
legal character, including a blank which is
used if there is only one chain.
14-17 int numRes Number of residues in the chain. This
value is repeated on every record.
20-22 string resName Residue name.
24-26 string resName Residue name.
28-30 string resName Residue name.
32-34 string resName Residue name.
36-38 string resName Residue name.
40-42 string resName Residue name.
44-46 string resName Residue name.
48-50 string resName Residue name.
52-54 string resName Residue name.
56-58 string resName Residue name.
60-62 string resName Residue name.
64-66 string resName Residue name.
68-70 string resName Residue name.
"""
record = string.strip(line[0:6])
if record == "SEQRES":
self.serNum = int(string.strip(line[8:10]))
self.chainID = string.strip(line[11])
self.numRes = int(string.strip(line[13:17]))
self.resName = []
self.resName.append(string.strip(line[19:22]))
self.resName.append(string.strip(line[23:26]))
self.resName.append(string.strip(line[27:30]))
self.resName.append(string.strip(line[31:34]))
self.resName.append(string.strip(line[35:38]))
self.resName.append(string.strip(line[39:42]))
self.resName.append(string.strip(line[43:46]))
self.resName.append(string.strip(line[47:50]))
self.resName.append(string.strip(line[51:54]))
self.resName.append(string.strip(line[55:58]))
self.resName.append(string.strip(line[59:62]))
self.resName.append(string.strip(line[63:66]))
self.resName.append(string.strip(line[67:70]))
else: raise ValueError, record
class SEQADV:
""" SEQADV field
The SEQADV record identifies conflicts between sequence information in
the ATOM records of the PDB entry and the sequence database entry given
on DBREF. Please note that these records were designed to identify
differences and not errors. No assumption is made as to which database
contains the correct data. PDB may include REMARK records in the entry
that reflect the depositor's view of which database has the correct
sequence.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------------
8-11 string idCode ID code of this entry.
13-15 string resName Name of the PDB residue in conflict.
17 string chainID PDB chain identifier.
19-22 int seqNum PDB sequence number.
23 string iCode PDB insertion code.
25-28 string database Sequence database name.
30-38 string dbIdCode Sequence database accession
number.
40-42 string dbRes Sequence database residue name.
44-48 int dbSeq Sequence database sequence number.
50-70 string conflict Conflict comment.
"""
record = string.strip(line[0:6])
if record == "SEQADV":
self.idCode = string.strip(line[7:11])
self.resName = string.strip(line[12:15])
self.chainID = string.strip(line[16])
try: self.seqNum = int(string.strip(line[19:22]))
except ValueError: self.seqNum = None
self.iCode = string.strip(line[22])
self.database = string.strip(line[24:28])
self.dbIdCode = string.strip(line[29:38])
self.dbRes = string.strip(line[39:42])
self.dbSeq = int(string.strip(line[43:48]))
self.conflict = string.strip(line[49:70])
else: raise ValueError, record
class DBREF:
""" DBREF field
The DBREF record provides cross-reference links between PDB sequences
and the corresponding database entry or entries. A cross reference to
the sequence database is mandatory for each peptide chain with a length
greater than ten (10) residues. For nucleic acid entries a DBREF record
pointing to the Nucleic Acid Database (NDB) is mandatory when the
corresponding entry exists in NDB.
"""
def __init__(self, line):
"""
Initialize by parsing a line.
COLUMNS TYPE FIELD DEFINITION
------------------------------------------------------
8-11 string idCode ID code of this entry.
13 string chainID Chain identifier.
15-18 int seqBegin Initial sequence number of the PDB
sequence segment.
19 string insertBegin Initial insertion code of the PDB
sequence segment.
21-24 int seqEnd Ending sequence number of the PDB
sequence segment.
25 string insertEnd Ending insertion code of the PDB
sequence segment.
27-32 string database Sequence database name. "PDB" when
a corresponding sequence database
entry has not been identified.
34-41 string dbAccession Sequence database accession code.
For GenBank entries, this is the
NCBI gi number.
43-54 string dbIdCode Sequence database identification
code. For GenBank entries, this is
the accession code.
56-60 int dbseqBegin Initial sequence number of the
database seqment.
61 string dbinsBeg Insertion code of initial residue
of the segment, if PDB is the
reference.
63-67 int dbseqEnd Ending sequence number of the
database segment.
68 string dbinsEnd Insertion code of the ending
residue of the segment, if PDB is
the reference.
"""
record = string.strip(line[0:6])
if record == "DBREF":
self.idCode = string.strip(line[7:11])
self.chainID = string.strip(line[12])
self.seqBegin = int(string.strip(line[14:18]))
self.insertBegin = string.strip(line[18])
self.seqEnd = int(string.strip(line[20:24]))
self.insertEnd = string.strip(line[24])
self.database = string.strip(line[26:32])
self.dbAccession = string.strip(line[33:41])
self.dbIdCode = string.strip(line[42:54])
self.dbseqBegin = int(string.strip(line[55:60]))
self.dbinsBeg = string.strip(line[60])
self.dbseqEnd = int(string.strip(line[62:67]))
try: self.dbinsEnd = string.strip(line[67])
except IndexError: self.dbinsEnd = None
else: raise ValueError, record
class REMARK:
""" REMARK field
REMARK records present experimental details, annotations, comments, and
information not included in other records. In a number of cases,
REMARKs are used to expand the contents of other record types. A new
level of structure is being used for some REMARK records. This is
expected to facilitate searching and will assist in the conversion to a
relational database.
"""
def __init__(self, line):
"""
Initialize by parsing line
"""
record = string.strip(line[0:6])
if record == "REMARK":
self.remarkNum = int(string.strip(line[7:10]))
self.remarkDict = {}
remarkText = line[11:70]
if self.remarkNum == 1:
subfield = string.strip(line[11:20])
if subfield == "REFERENCE":
self.remarkDict["refNum"] = int(string.strip(line[21:70]))
elif subfield == "AUTH":
self.remarkDict["authorList"] = string.strip(line[19:70])
elif subfield == "TITL":
self.remarkDict["title"] = string.strip(line[19:70])
elif subfield == "EDIT":
self.remarkDict["editorList"] = string.strip(line[19:70])
elif subfield == "REF":
self.remarkDict["ref"] = string.strip(line[19:66])
elif subfield == "PUBL":
self.remarkDict["pub"] = string.strip(line[19:70])
elif subfield == "REFN":
self.remarkDict["refn"] = string.strip(line[19:70])
elif self.remarkNum == 2:
restr = string.strip(line[22:27])
try: self.remarkDict["resolution"] = float(restr)
except ValueError:
self.remarkDict["comment"] = string.strip(line[11:70])
else:
self.remarkDict["text"] = string.strip(line[11:70])
class JRNL:
""" JRNL field
The JRNL record contains the primary literature citation that describes
the experiment which resulted in the deposited coordinate set. There is
at most one JRNL reference per entry. If there is no primary reference,
then there is no JRNL reference. Other references are given in REMARK
1.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------
13-70 string text See Details on web.
"""
record = string.strip(line[0:6])
if record == "JRNL":
self.text = string.strip(line[12:70])
else: raise ValueError, record
class SPRSDE:
""" SPRSDE field
The SPRSDE records contain a list of the ID codes of entries that were
made obsolete by the given coordinate entry and withdrawn from the PDB
release set. One entry may replace many. It is PDB policy that only the
principal investigator of a structure has the authority to withdraw it.
"""
def __init__(self, line):
"""
Initialize by parsing line
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------
12-20 string sprsdeDate Date this entry superseded the
listed entries.
22-25 string idCode ID code of this entry.
32-35 string sIdCode ID code of a superseded entry.
37-40 string sIdCode ID code of a superseded entry.
42-45 string sIdCode ID code of a superseded entry.
47-50 string sIdCode ID code of a superseded entry.
52-55 string sIdCode ID code of a superseded entry.
57-60 string sIdCode ID code of a superseded entry.
62-65 string sIdCode ID code of a superseded entry.
67-70 string sIdCode ID code of a superseded entry.
"""
record = string.strip(line[0:6])
if record == "SPRSDE":
self.sprsdeDate = string.strip(line[11:20])
self.idCode = string.strip(line[21:25])
self.sIdCodes = []
self.sIdCodes.append(string.strip(line[31:35]))
self.sIdCodes.append(string.strip(line[36:40]))
self.sIdCodes.append(string.strip(line[41:45]))
self.sIdCodes.append(string.strip(line[46:50]))
self.sIdCodes.append(string.strip(line[51:55]))
self.sIdCodes.append(string.strip(line[56:60]))
self.sIdCodes.append(string.strip(line[61:65]))
self.sIdCodes.append(string.strip(line[66:70]))
else: raise ValueError, record
class REVDAT:
""" REVDAT field
REVDAT records contain a history of the modifications made to an entry
since its release.
"""
def __init__(self, line):
"""
Initialize by parsing a line.
COLUMNS TYPE FIELD DEFINITION
-------------------------------------------------------
8-10 int modNum Modification number.
14-22 string modDate Date of modification (or release for
new entries).
24-28 string modId Identifies this particular modification.
It links to the archive used internally by
PDB.
32 int modType An integer identifying the type of
modification. In case of revisions
with more than one possible modType,
the highest value applicable will be
assigned.
40-45 string record Name of the modified record.
47-52 string record Name of the modified record.
54-59 string record Name of the modified record.
61-66 string record Name of the modified record.
"""
record = string.strip(line[0:6])
if record == "REVDAT":
self.modNum = int(string.strip(line[7:10]))
self.modDate = string.strip(line[13:22])
self.modId = string.strip(line[23:28])
self.modType = int(string.strip(line[31]))
self.records = []
self.records.append(string.strip(line[39:45]))
self.records.append(string.strip(line[46:52]))
self.records.append(string.strip(line[53:59]))
self.records.append(string.strip(line[60:66]))
else: raise ValueError, record
class AUTHOR:
""" AUTHOR field
The AUTHOR record contains the names of the people responsible for the
contents of the entry.
"""
def __init__(self, line):
"""
Initialize by parsing a line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------------
11-70 string authorList List of the author names, separated by
commas
"""
record = string.strip(line[0:6])
if record == "AUTHOR":
self.authorList = string.strip(line[10:70])
else: raise ValueError, record
class EXPDTA:
""" EXPDTA field
The EXPDTA record identifies the experimental technique used. This may
refer to the type of radiation and sample, or include the spectroscopic
or modeling technique. Permitted values include:
ELECTRON DIFFRACTION
FIBER DIFFRACTION
FLUORESCENCE TRANSFER
NEUTRON DIFFRACTION
NMR
THEORETICAL MODEL
X-RAY DIFFRACTION
"""
def __init__(self, line):
"""
Initialize by parsing a line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------------
11-70 string technique The experimental technique(s) with
optional comment describing the sample
or experiment
"""
record = string.strip(line[0:6])
if record == "EXPDTA":
self.technique = string.strip(line[10:70])
else: raise ValueError, record
class KEYWDS:
""" KEYWDS field
The KEYWDS record contains a set of terms relevant to the entry. Terms
in the KEYWDS record provide a simple means of categorizing entries and
may be used to generate index files. This record addresses some of the
limitations found in the classification field of the HEADER record. It
provides the opportunity to add further annotation to the entry in a
concise and computer-searchable fashion.
"""
def __init__(self, line):
"""
Initialize by parsing a line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------------
11-70 string keywds Comma-separated list of keywords relevant
to the entry
"""
record = string.strip(line[0:6])
if record == "KEYWDS":
self.keywds = string.strip(line[10:70])
else: raise ValueError, record
class SOURCE:
""" SOURCE field
The SOURCE record specifies the biological and/or chemical source of
each biological molecule in the entry. Sources are described by both
the common name and the scientific name, e.g., genus and species.
Strain and/or cell-line for immortalized cells are given when they help
to uniquely identify the biological entity studied.
"""
def __init__(self, line):
"""
Initialize by parsing a line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------------
11-70 string source Identifies the source of the macromolecule
in a token: value format
"""
record = string.strip(line[0:6])
if record == "SOURCE":
self.source = string.strip(line[10:70])
else: raise ValueError, record
class COMPND:
""" COMPND field
The COMPND record describes the macromolecular contents of an entry.
Each macromolecule found in the entry is described by a set of token:
value pairs, and is referred to as a COMPND record component. Since the
concept of a molecule is difficult to specify exactly, PDB staff may
exercise editorial judgment in consultation with depositors in
assigning these names.
For each macromolecular component, the molecule name, synonyms, number
assigned by the Enzyme Commission (EC), and other relevant details are
specified.
"""
def __init__(self, line):
"""
Initialize by parsing a line
COLUMNS TYPE FIELD DEFINITION
--------------------------------------------------
11-70 string compound Description of the molecular list
components.
"""
record = string.strip(line[0:6])
if record == "COMPND":
self.compound = string.strip(line[10:70])
else: raise ValueError, record
class CAVEAT:
""" CAVEAT field
CAVEAT warns of severe errors in an entry. Use caution when using an
entry containing this record.
"""
def __init__(self, line):
"""
Initialize by parsing line.
COLUMNS TYPE FIELD DEFINITION
----------------------------------------------------
12-15 string idCode PDB ID code of this entry.
20-70 string comment Free text giving the reason for the
CAVEAT.
"""
record = string.strip(line[0:6])
if record == "CAVEAT":
self.idCode = string.strip(line[11:15])
self.comment = string.strip(line[19:70])
else: raise ValueError, record
class TITLE:
""" TITLE field
The TITLE record contains a title for the experiment or analysis that
is represented in the entry. It should identify an entry in the PDB in
the same way that a title identifies a paper.
"""
def __init__(self, line):
"""
Initialize by parsing a line.
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------
11-70 string title Title of the experiment
"""
record = string.strip(line[0:6])
if record == "TITLE":
self.title = string.strip(line[10:70])
else: raise ValueError, record
class OBSLTE:
""" OBSLTE field
This record acts as a flag in an entry which has been withdrawn from
the PDB's full release. It indicates which, if any, new entries have
replaced the withdrawn entry.
The format allows for the case of multiple new entries replacing one
existing entry.
"""
def __init__(self, line):
"""
Initialize by parsing a line.
COLUMNS TYPE FIELD DEFINITION
-----------------------------------------------
12-20 string repDate Date that this entry was replaced.
22-25 string idCode ID code of this entry.
32-35 string rIdCode ID code of entry that replaced
this one.
37-40 string rIdCode ID code of entry that replaced
this one.
42-45 string rIdCode ID code of entry that replaced
this one.
47-50 string rIdCode ID code of entry that replaced
this one.
52-55 string rIdCode ID code of entry that replaced
this one.
57-60 string rIdCode ID code of entry that replaced
this one.
62-65 string rIdCode ID code of entry that replaced
this one.
67-70 string rIdCode ID code of entry that replaced
this one.
"""
record = string.strip(line[0:6])
if record == "OBSLTE":
self.repDate = string.strip(line[11:20])
self.idCode = string.strip(line[21:25])
self.rIdCodes = []
self.rIdCodes.append(string.strip(line[31:35]))
self.rIdCodes.append(string.strip(line[36:40]))
self.rIdCodes.append(string.strip(line[41:45]))
self.rIdCodes.append(string.strip(line[46:50]))
self.rIdCodes.append(string.strip(line[51:55]))
self.rIdCodes.append(string.strip(line[56:60]))
self.rIdCodes.append(string.strip(line[61:65]))
self.rIdCodes.append(string.strip(line[67:70]))
else: raise ValueError, record
class HEADER:
""" HEADER field
The HEADER record uniquely identifies a PDB entry through the idCode
field. This record also provides a classification for the entry.
Finally, it contains the date the coordinates were deposited at the
PDB. """
def __init__(self, line):
"""
Initialize by parsing a line.
COLUMNS TYPE FIELD DEFINITION
---------------------------------------------------------
11-50 string classification Classifies the molecule(s)
51-59 string depDate Deposition date. This is the date
the coordinates were received by
the PDB
63-66 string idCode This identifier is unique within PDB
"""
record = string.strip(line[0:6])
if record == "HEADER":
self.classification = string.strip(line[10:50])
self.depDate = string.strip(line[50:59])
self.IDcode = string.strip(line[62:66])
else: raise ValueError, record
def readAtom(line):
"""
If the ATOM/HETATM is not column-formatted, try to get some
information by parsing whitespace from the right. Look for
five floating point numbers followed by the residue number.
Parameters
line: The line to parse(string)
if record == ATOM:
self.serial = int(string.strip(line[6:11]))
self.name = string.strip(line[12:16])
self.altLoc = string.strip(line[16])
self.resName = string.strip(line[17:20])
self.chainID = string.strip(line[21])
self.resSeq = int(string.strip(line[22:26]))
self.iCode = string.strip(line[26])
self.x = float(string.strip(line[30:38]))
self.y = float(string.strip(line[38:46]))
self.z = float(string.strip(line[46:54]))
try:
self.occupancy = float(string.strip(line[54:60]))
self.tempFactor = float(string.strip(line[60:66]))
self.segID = string.strip(line[72:76])
self.element = string.strip(line[76:78])
self.charge = string.strip(line[78:80])
except ValueError, IndexError:
self.occupancy = 0.00
self.tempFactor = 0.00
self.segID = 0
self.element = 0
self.charge = 0
else: raise ValueError, record
"""
# Try to find 5 consecutive floats
words = string.split(line)
size = len(words) - 1
consec = 0
for i in range(size):
entry = words[size - i]
try:
val = float(entry)
consec = consec + 1
if consec == 5:
break
except ValueError:
consec = 0
record = string.strip(line[0:6])
newline = line[0:22]
newline = newline + string.rjust(words[size-i-1],4)
newline = newline + string.rjust("",3)
newline = newline + string.rjust(words[size-i],8)
newline = newline + string.rjust(words[size-i+1],8)
newline = newline + string.rjust(words[size-i+2],8)
newline = newline + string.rjust(words[size-i+3],6)
newline = newline + string.rjust(words[size-i+4],6)
cmdstr = "%s(newline)" % record
obj = eval(cmdstr)
return obj
def readPDB(file):
""" Parse PDB-format data into array of Atom objects.
Parameters
file: open file object
Returns (dict, errlist)
dict: a dictionary indexed by PDB record names
errlist: a list of record names that couldn't be parsed
"""
pdblist = [] # Array of parsed lines (as objects)
errlist = [] # List of records we can't parse
#We can come up with nothing if can't get our file off the web.
if file is None:
return pdblist, errlist
while 1:
line = string.strip(file.readline())
if line == '': break
# We assume we have a method for each PDB record and can therefore
# parse them automatically
try:
record = string.strip(line[0:6])
if record not in errlist:
cmdstr = "%s(line)" % record
obj = eval(cmdstr)
pdblist.append(obj)
except NameError, details:
errlist.append(record)
except StandardError, details:
if record == "ATOM" or record == "HETATM":
try:
obj = readAtom(line)
pdblist.append(obj)
except StandardError, details:
sys.stderr.write("Error parsing line: %s\n" % details)
sys.stderr.write("<%s>\n" % string.strip(line))
elif record == "SITE" or record == "TURN":
pass
elif record == "SSBOND" or record == "LINK":
sys.stderr.write("Warning -- ignoring record: \n")
sys.stderr.write("<%s>\n" % string.strip(line))
else:
sys.stderr.write("Error parsing line: %s\n" % details)
sys.stderr.write("<%s>\n" % string.strip(line))
return pdblist, errlist
def getRandom():
""" Download a random PDB and return the path name.
Returns
path name of downloaded file
"""
import os, random
URL = "ftp://ftp.rcsb.org/pub/pdb/data/structures/all/pdb/"
pdblines = os.popen("ncftpls %s" % URL).readlines()
pdbline = string.join(pdblines)
pdbline = string.replace(pdbline, "\n", "")
pdbline = string.replace(pdbline, "@", "")
pdbline = string.strip(pdbline)
pdblist = string.split(pdbline)
pdbZ = random.choice(pdblist)
os.popen("ncftpget %s/%s" % (URL, pdbZ))
os.popen("uncompress %s" % pdbZ)
return pdbZ[:-2]
def main():
""" Main driver for testing. Parses set number of random PDBs """
npdb = 1
sys.stdout.write("Testing %d PDBs...\n" % npdb)
for i in range(0, npdb):
sys.stdout.write("Getting random PDB...\n")
path = getRandom()
sys.stdout.write("Parsing %s...\n" % path)
pdbdict, errlist = readPDB(open(path, "rU"))
if len(errlist) > 0: sys.stdout.write("\tSkipped records: %s\n" % errlist)
sys.stdout.write("\tNo skipped records.\n")
if __name__ == "__main__": main()
|