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 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369
|
/* mmdbapi1.c
* ===========================================================================
*
* PUBLIC DOMAIN NOTICE
* National Center for Biotechnology Information (NCBI)
*
* This software/database is a "United States Government Work" under the
* terms of the United States Copyright Act. It was written as part of
* the author's official duties as a United States Government employee and
* thus cannot be copyrighted. This software/database is freely available
* to the public for use. The National Library of Medicine and the U.S.
* Government do not place any restriction on its use or reproduction.
* We would, however, appreciate having the NCBI and the author cited in
* any work or product based on this material
*
* Although all reasonable efforts have been taken to ensure the accuracy
* and reliability of the software and data, the NLM and the U.S.
* Government do not and cannot warrant the performance or results that
* may be obtained by using this software or data. The NLM and the U.S.
* Government disclaim all warranties, express or implied, including
* warranties of performance, merchantability or fitness for any particular
* purpose.
*
* ===========================================================================
*
* File Name: mmdbapi1.c
*
* Author: Christopher Hogue, Hitomi Ohkawa
*
* Version Creation Date: 03/14/95
*
* $Revision: 6.47 $
*
* File Description:
*
* Modifications:
* --------------------------------------------------------------------------
* Date Name Description of modification
* ------- ---------- -----------------------------------------------------
* 95/08/28 C. Hogue Major change to new Biostruc ASN.1 v4.0,
* Addition of Features, Secondary Structure, Ensembles,
* Model nodes and Dictionaries altered...
* 95/08/28 C. Hogue Put model id into its DValnode choice as it should be.
* 95/08/30 C. Hogue Minor changes.
*
* $Log: mmdbapi1.c,v $
* Revision 6.47 2005/01/25 15:39:07 thiessen
* tweak LoadDict again
*
* Revision 6.46 2005/01/24 20:42:58 thiessen
* fix memory leak; check current dir for dictionary if ProgramPath returns empty string
*
* Revision 6.45 2004/05/06 19:31:09 chenj
* fixed the bug in fnPBSFtoPSA() to use 2 chars for domain id
*
* Revision 6.44 2003/12/03 02:11:28 kans
* added defines missing from Mac OS 10.3 headers
*
* Revision 6.43 2002/05/10 16:33:18 chenj
* fix bugs in fnPBSFtoPSA
*
* Revision 6.41 2001/01/26 15:06:39 lewisg
* use entrez2 to retrieve structures
*
* Revision 6.40 2000/12/05 22:13:06 ywang
* fix bugs for MakePDBSeqId2
*
* Revision 6.39 2000/07/21 18:56:41 thiessen
* allow dynamic slave->master transformation
*
* Revision 6.38 2000/06/09 14:35:16 lewisg
* fix freeing bugs
*
* Revision 6.37 2000/04/20 23:27:44 lewisg
* misc bug fixes
*
* Revision 6.36 2000/03/13 15:51:25 thiessen
* added storage for PARS to each residue for Cn3D; removed unused fields
*
* Revision 6.35 2000/03/09 17:52:56 thiessen
* changes to MSD, MGD for feature implementation in Cn3D
*
* Revision 6.34 2000/03/08 21:46:12 lewisg
* cn3d saves viewport, misc bugs
*
* Revision 6.33 2000/02/14 19:31:03 lewisg
* fix occupancy bug when temperature factors present
*
* Revision 6.32 1999/11/02 23:06:08 lewisg
* fix cn3d to launch correctly if there is no seqentry associated with bioseq
*
* Revision 6.31 1999/10/05 23:18:17 lewisg
* add ddv and udv to cn3d with memory management
*
* Revision 6.30 1999/06/07 21:23:36 ywang
* add iUserDefinedFeatureOld, FeatureOnOld to MGD
*
* Revision 6.29 1999/05/07 20:48:59 kans
* including new name of prunebsc.h
*
* Revision 6.28 1999/05/07 14:07:07 zimmerma
* new code to call prunebiostruc (lines starting at 3807)
*
* InstBSAnnotSet - added params: Boolean Chain, CharPtr Path and
* modified to call PruneBiostruc (KA)
*
* InstallAlignedSlave - added params: Boolean Chain, CharPtr Path and
* modified to call PruneBiostruc (KA)
*
* InstallStrucFeature - added params: Boolean Chain, CharPtr Path and
* propagate to InstallAlignedSlave (KA)
*
* BiostrucAddFeature - added params: Boolean Chain, CharPtr Path and
* propagate to InstallStrucFeature (KA)
*
* Moved isBiopoly and isHet from mkbioseqB.c - DZ
*
* Revision 6.27 1999/04/26 20:49:59 lewisg
* changed arguments named list to fix visual c++ bug
*
* Revision 6.26 1999/03/18 21:04:29 lewisg
* reverse transform for saving
*
* Revision 6.25 1999/03/01 20:22:10 ywang
* add bTurnedOff flag on MGD
*
* Revision 6.24 1999/02/25 23:11:32 ywang
* keep ASN.1 features intact
*
* Revision 6.23 1999/02/24 22:58:09 ywang
* add iMimeType to MSD node and other minor name change
*
* Revision 6.22 1999/02/02 22:27:00 ywang
* add bJustHighlighted flag to MGD for feature edit
*
* Revision 6.21 1998/12/16 19:30:12 ywang
* add flag for highlight status to MGD
*
* Revision 6.20 1998/11/06 23:02:01 ywang
* add FeatureOn to MGD for feature on/off control
*
* Revision 6.19 1998/11/04 00:53:39 ywang
* add iFeature to MGD for modeling control
*
* Revision 6.18 1998/10/21 15:43:21 ywang
* attach the whole vast alignment data to master structure
*
* Revision 6.17 1998/10/01 21:56:33 ywang
* set display flag for object
*
* Revision 6.16 1998/09/22 17:52:20 ywang
* add flag for display control on MM and MG level
*
* Revision 6.15 1998/08/26 18:02:39 kans
* fixed -v -fd warnings
*
* Revision 6.14 1998/08/14 20:24:05 lewisg
* fix fault when retrieving structure by PDB name and database is unavailable
*
* Revision 6.13 1998/07/01 22:22:08 ywang
* set getgi flag as FALSE in function fnPBSFtoPSA when mastersip and slavesip is made by MakePDBSeqId2
*
* Revision 6.12 1998/05/12 21:46:16 lewisg
* stricter conservation coloring
*
* Revision 6.11 1998/05/08 21:19:30 ywang
* make salp->segs as DenseDiag
*
* Revision 6.9 1998/04/28 22:51:13 lewisg
* created separate pointer to master in MGD
*
* Revision 6.8 1998/04/21 22:58:46 lewisg
* eliminate dead code
*
* Revision 6.7 1998/04/10 22:41:42 lewisg
* eliminated dead code and added a visible bit to MSD
*
* Revision 6.6 1998/04/04 06:01:24 lewisg
* got rid of dos line breaks
*
* Revision 6.5 1998/04/04 00:56:46 lewisg
* corrected freeing of MSD
*
* Revision 6.4 1998/03/10 04:30:59 lewisg
* change name of MakePDBSeqId to MakePDBSeqId2 to avoid name conflict
*
* Revision 6.3 1998/03/06 23:17:15 lewisg
* codewarrior fixes
*
* Revision 6.2 1998/03/06 01:15:43 lewisg
* merge
*
* Revision 6.0 1997/08/25 18:10:56 madden
* Revision changed to 6.0
*
* Revision 5.3 1997/04/18 19:18:56 hogue
* Int2 counters for atoms upgraded to Int4's, made ppAsnOrder alloc optional.
*
* Revision 5.2 1997/01/15 18:15:04 hogue
* Changed to abstraction of Entrez calls requiring mmdbentr or equivalent. This abstracts the Entrez (CD/Network) calls from MMDB-API,
* in preparation to fetching MMDB records in alternate ways
* (local filesystem or http GET with MIME-typed Biostrucs) and for
* providing a slot for an MMDB-API caching system.
*
* Revision 5.1 1996/11/18 19:58:51 hogue
* eliminate ALLSIMPLEMDL to obtain performance improvement, Update
* of MMDB data makes ALLSIMPLEMDL obsolete as vectors now stored in
* the ONECOORDATOM model.
*
* Revision 5.0 1996/05/28 14:02:09 ostell
* Set to revision 5.0
*
* Revision 1.25 1996/05/15 17:01:53 hogue
* Fixed compiler warnings
*
* Revision 1.24 1996/05/01 14:39:12 hogue
* Enhanced feature handling, added MakeChemGraphNodeList, added support for domains.
*
* Revision 1.23 1996/04/18 17:40:05 hogue
* Added FETCH_ENTREZ bExtent test to FetchBS to mask EntrezInit/Fini; added mdlLvl BSEVERYTHING support, added a freeer call for pdnmsSlaves.
*
* Revision 1.22 1996/03/29 19:28:02 hogue
* Added pExtra pointer to MSD, fixed PMOD parent pointer
*
* Revision 1.21 1996/01/31 21:35:00 hogue
* Changes to accomodate the free-ing of models, most dramatically is the
* encapuslation of interim free-ers to FreeSurfaceModelAsnList and
* FreeAtomicModelAsnLists. KEEP_ASN no longer supported. PDNSM and its
* kin renamed to PDNML.
*
* Revision 1.20 1995/12/12 23:51:26 kans
* removed include vibrant.h
*
* Revision 1.19 1995/11/30 20:31:24 hogue
* Asn order vector in PMLD contains PALD not PMAD's.
*
* Revision 1.18 1995/11/15 19:15:59 hogue
* Traversers now handle solids on a per-model basis.
*
* Revision 1.17 1995/11/09 22:53:15 hogue
* Links between models and locations added, some new free-ers
*
* Revision 1.16 1995/10/05 17:41:52 hogue
* Added rot/translation matrix free-ers
*
* Revision 1.15 1995/09/21 20:27:00 hogue
* Took out call to StrToLong - inserted it longhand for non-vibrant apps
*
* Revision 1.14 1995/09/19 21:07:22 hogue
* Added to FetchBS() Entrez access via PDB or GI
*
* Revision 1.13 1995/09/18 21:24:37 hogue
* Het names added, and ProgMon calls
*
* Revision 1.12 1995/09/14 14:21:48 hogue
* Fix for Element No's 254 (other) and 255 (unk) put into Int1
*
* Revision 1.11 1995/09/05 19:09:32 hogue
* Changed error severity in conversion routine to SEV_ERROR
*
* Revision 1.10 1995/08/30 19:36:44 kans
* numerous changes
*
* Revision 1.9 1995/08/29 20:03:06 kans
* Entrez-like loading now enabled, models fixed
*
* Revision 1.6 1995/08/28 22:46:40 kans
* moved BiostrucAvail to mmdbapi1.[ch]
*
* Revision 1.5 1995/08/28 20:06:37 kans
* *** empty log message ***
*
* Revision 1.3 1995/08/28 19:31:53 kans
* version 4.1
*
* Revision 1.1 1995/08/02 17:07:15 kans
* Initial revision
*
*
* ==========================================================================
*/
/*****************************************************************************
*
* mmdbapi1.c
*
* UNDER CONSTRUCTION NOTICE.
* SUBJECT TO RADICAL CHANGES...
*
* programmer C.W.V. Hogue
* created: 14 Mar 95
* last mod: 28 AUGUST 95
*****************************************************************************/
#include <ncbi.h>
#include <mmdbdata.h>
#include <sequtil.h>
NLM_EXTERN void VnpHeapSort PROTO ((ValNodePtr PNTR vnp, int (LIBCALLBACK *compar )PROTO ((Nlm_VoidPtr, Nlm_VoidPtr ))));
/* this should be #include <utilpub.h> but this conflicts with mmdbdata.h. fix this. lyg */
#include <mmdbapi.h>
#include <mmdbapi1.h>
#include <matrix.h>
#include "prunebsc.h"
/* Missing from /usr/include/gcc/darwin/3.3/machine/limits.h */
#ifdef __MWERKS__
#ifdef OS_UNIX_DARWIN
#ifndef __SCHAR_MAX__
#define __SCHAR_MAX__ 127
#endif
#endif
#endif
/* End missing from /usr/include/gcc/darwin/3.3/machine/limits.h */
PMBD LIBCALL NewMBD(void)
{
PMBD pmbdNew = NULL;
pmbdNew = (PMBD)MemNew((size_t)(sizeof(MBD)));
if (pmbdNew)
{
pmbdNew->bMe = (Byte) AM_MBD;
pmbdNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME);
}
return pmbdNew;
}
PMOD LIBCALL NewMOD(void)
{
PMOD pmodNew = NULL;
pmodNew = (PMOD)MemNew((size_t)(sizeof(MOD)));
if (pmodNew)
{
pmodNew->bMe = (Byte) AM_MOD;
pmodNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME );
pmodNew->bVisible = 1;
/* turn on object by default -- Yanli */
}
return pmodNew;
}
PMDD LIBCALL NewMDD(void)
{
PMDD pmddNew = NULL;
pmddNew = (PMDD)MemNew((size_t)(sizeof(MDD)));
if (pmddNew)
{
pmddNew->bMe = (Byte) AM_MDD;
pmddNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME );
}
return pmddNew;
}
PMAD LIBCALL NewMAD(void)
{
PMAD pmadNew = NULL;
pmadNew = (PMAD)MemNew((size_t)(sizeof(MAD)));
if (pmadNew)
{
pmadNew->bMe = (Byte) AM_MAD;
pmadNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME );
}
return pmadNew;
}
PALD LIBCALL NewALD(void)
{
PALD paldNew = NULL;
paldNew = (PALD)MemNew((size_t)(sizeof(ALD)));
if (paldNew)
{
paldNew->cAltConf = ' ';
paldNew->bMe = (Byte) AM_ALD;
paldNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME );
}
return paldNew;
}
PMLD LIBCALL NewMLD(void)
{
PMLD pmldNew = NULL;
pmldNew = (PMLD)MemNew((size_t)(sizeof(MLD)));
return pmldNew;
}
PMGD LIBCALL NewMGD(void)
{
PMGD pmgdNew = NULL;
pmgdNew = (PMGD)MemNew((size_t)(sizeof(MGD)));
if (pmgdNew)
{
pmgdNew->bMe = (Byte) AM_MGD;
pmgdNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME );
pmgdNew->bReserved = 0;
pmgdNew->bVisible = 1; /* be displayed by default */
pmgdNew->bHighlighted = 0;
pmgdNew->pbMasterReserved = NULL;
pmgdNew->pvnPARSList = NULL;
}
return pmgdNew;
}
PMMD LIBCALL NewMMD(void)
{
PMMD pmmdNew = NULL;
pmmdNew = (PMMD)MemNew((size_t)(sizeof(MMD)));
if (pmmdNew)
{
pmmdNew->bMe = (Byte) AM_MMD;
pmmdNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME );
pmmdNew->bVisible = 1;
pmmdNew->iTargetRow = -1;
}
return pmmdNew;
}
PMSD LIBCALL NewMSD(void)
{
PMSD pmsdNew = NULL;
pmsdNew = (PMSD)MemNew((size_t)(sizeof(MSD)));
if (pmsdNew)
{
pmsdNew->bMe = (Byte) AM_MSD;
pmsdNew->bUpdate = (Byte) (REG_STYLE | SHOW_ME );
pmsdNew->pfbParent = NULL;
pmsdNew->pGlobalPARS = NULL;
pmsdNew->pdnSlaveToMasterTransforms = NULL;
}
return pmsdNew;
}
PSFF LIBCALL NewSFF(void)
{
PSFF psffNew = NULL;
psffNew = (PSFF) MemNew((size_t)(sizeof(SFF)));
return psffNew;
}
PSFD LIBCALL NewSFD(void)
{
PSFD psfdNew = NULL;
psfdNew = (PSFD) MemNew((size_t)(sizeof(SFD)));
return psfdNew;
}
PSFS LIBCALL NewSFS(void)
{
PSFS psfsNew = NULL;
psfsNew = (PSFS)MemNew((size_t)(sizeof(SFS)));
return psfsNew;
}
PDNSFS LIBCALL NewDNSFS(PDNSFS PNTR ppdnsfsList, Int2 choice)
{
PDNSFS pdnsfsNew = NULL;
PSFS psfsNew = NULL;
psfsNew = NewSFS();
if (!psfsNew) return NULL;
pdnsfsNew = DValNodeAddPointer(ppdnsfsList, choice, (Nlm_VoidPtr) psfsNew);
psfsNew->pdnsfsSet = pdnsfsNew; /* link to parent */
return pdnsfsNew;
}
void LIBCALL FreeSFS(PSFS psfsThis)
{
if (psfsThis)
{
if (psfsThis->pcName) MemFree(psfsThis->pcName);
if (psfsThis->psfdFeats) FreeSFD(psfsThis->psfdFeats);
if (psfsThis->pvnDescr) BiostrucFeatureSetDescrFree(psfsThis->pvnDescr);
if (psfsThis->pbsfsFeatSet)
MsgAlert(KEY_NONE,SEV_ERROR, "Dangling Feature Set",
"\nMemory leaking at FeatureSet\n.");
BiostrucFeatureSetFree(psfsThis->pbsfsFeatSet);
MemFree(psfsThis);
}
return;
}
PVNSFF LIBCALL NewVNSFF(PVNSFF PNTR ppvnsffList, Int2 choice)
{
PVNSFF pvnsffNew = NULL;
PSFF psffNew = NULL;
psffNew = NewSFF();
if (!psffNew) return NULL;
pvnsffNew = ValNodeAddPointer(ppvnsffList, choice, (Nlm_VoidPtr) psffNew);
return pvnsffNew;
}
void LIBCALL FreeListVNSFF(PVNSFF pvnsffList)
{
FreeVNDataFn(pvnsffList, (pFreeFunc)FreeSFF);
return;
}
void LIBCALL FreeSFF(PSFF psffThis)
{
if (psffThis)
{
MemFree(psffThis);
}
return;
}
void LIBCALL FreeSFD(PSFD psfdThis)
{
PSFD psfdNext = NULL;
PSFF psffThis = NULL;
ValNodePtr vnp = NULL;
if (psfdThis)
{
if (psfdThis->next) psfdNext = psfdThis->next;
if (psfdThis->pcName) MemFree(psfdThis->pcName);
if (psfdThis->pData)
{
psffThis = DoesFeatureTypeHaveFuncs(psfdThis->iType);
if (psffThis)
{ /* this uses the installed function to free pData */
(*(psffThis->pFeatToCFn)) ( (Pointer PNTR) &(psfdThis->pData), NULL);
}
else
switch (psfdThis->iType)
{
case Feature_type_transform:
FreeDNTRN((PDNTRN) vnp->data.ptrvalue);
break;
case Feature_type_camera:
vnp = (ValNodePtr) psfdThis->pData;
CameraFree((CameraPtr) vnp->data.ptrvalue);
ValNodeFree(vnp);
break;
case Feature_type_script:
/* lygmerge vnp = (ValNodePtr) psfdThis->pData;
BiostrucScriptFree((BiostrucScriptPtr) vnp->data.ptrvalue);
ValNodeFree(vnp); */
break;
case Feature_type_multalign:
case Feature_type_alignment:
ChemGraphAlignmentFree((ChemGraphAlignmentPtr) psfdThis->pData);
ValNodeFree(vnp);
break;
case Feature_type_similarity:
vnp = (ValNodePtr) psfdThis->pData;
RegionSimilarityFree((RegionSimilarityPtr) vnp->data.ptrvalue);
ValNodeFree(vnp);
break;
case Feature_type_region:
vnp = (ValNodePtr) psfdThis->pData;
RegionPntrsFree((RegionPntrsPtr) vnp->data.ptrvalue);
ValNodeFree(vnp);
break;
/* these don't have sub-alloced parts hanging off pData */
/* case Feature_type_indirect:
case Feature_type_color:
case Feature_type_render:
case Feature_type_helix:
case Feature_type_strand:
case Feature_type_sheet:
case Feature_type_turn:
case Feature_type_site:
case Feature_type_footnote:
case Feature_type_subgraph:
case Feature_type_core:
case Feature_type_supercore:
case Feature_type_other: */
default: ;
} /* switch type */
psfdThis->pData = NULL;
} /* if pData */
if (psfdThis->pbsfFeat)
{
MsgAlert(KEY_NONE,SEV_ERROR, "Dangling Feature",
"\nMemory leaks at Feature\n.");
BiostrucFeatureFree(psfdThis->pbsfFeat);
}
MemFree(psfdThis);
FreeSFD(psfdNext);
}
}
void LIBCALL FreeMBD(PMBD pmbdThis)
{
#ifdef _DEBUG_2
printf("in FreeMBD ");
#endif
if (pmbdThis)
MemFree(pmbdThis);
}
void LIBCALL FreeMOD(PMOD pmodThis)
{
#ifdef _DEBUG_2
printf("in FreeMOD ");
#endif
if (pmodThis->pvnContains) ValNodeFree(pmodThis->pvnContains);
if (pmodThis->ppflObject) FLMatrixFree(pmodThis->ppflObject, 0, 0);
if (pmodThis->pucSwap) UCVectorFree(pmodThis->pucSwap, 0);
if (pmodThis->ppi4Triangles) I4MatrixFree(pmodThis->ppi4Triangles, 0, 0);
if (pmodThis->pi2vColor) I2VectorFree(pmodThis->pi2vColor,0);
if (pmodThis) MemFree(pmodThis);
}
void LIBCALL FreeMDD(PMDD pmddThis)
{
#ifdef _DEBUG_2
printf("in FreeMDD ");
#endif
if (pmddThis->pvnContains) ValNodeFree(pmddThis->pvnContains);
if (pmddThis)
MemFree(pmddThis);
}
void LIBCALL FreeMAD(PMAD pmadThis)
{
#ifdef _DEBUG_2
printf("in FreeMAD ");
#endif
if (pmadThis)
{
if (pmadThis->pvnContainedBy) ValNodeFree(pmadThis->pvnContainedBy);
if (pmadThis->pvnBonds) ValNodeFree(pmadThis->pvnBonds);
if (pmadThis->pvnalLocate) FreeListVNAL(pmadThis->pvnalLocate);
MemFree(pmadThis);
}
}
void LIBCALL FreeALD(PALD paldThis)
{
PALD paldNext;
#ifdef _DEBUG_2
printf("in FreeALD ");
#endif
while (paldThis)
{
paldNext = paldThis->next;
if ((paldThis->iFloatNo) && (paldThis->pflvData))
FLVectorFree(paldThis->pflvData, 0);
MemFree(paldThis);
paldThis = paldNext;
}
}
void LIBCALL FreeMLD(PMLD pmldThis)
{
PMLD pmldNext;
#ifdef _DEBUG_2
printf("in FreeMLD ");
#endif
while (pmldThis)
{
pmldNext = pmldThis->next;
/* models are owned by the Biostruc ptr in pmsd->pbsBS */
if (pmldThis->ppAsnOrder) PTRVectorFree(pmldThis->ppAsnOrder, 0);
if (pmldThis->pcAltConf) MemFree(pmldThis->pcAltConf);
if (pmldThis->pcModelName) MemFree(pmldThis->pcModelName);
MemFree(pmldThis);
pmldThis = pmldNext;
}
}
void LIBCALL FreeKeptFeature(BiostrucFeatureSetPtr pbsfsThis)
{
#ifdef _DEBUG_2
printf("in FreeKeptFeature ");
#endif
if (pbsfsThis) BiostrucFeatureSetFree(pbsfsThis);
}
void LIBCALL FreeMGD(PMGD pmgdThis)
{
#ifdef _DEBUG_2
printf("in FreeMGD ");
#endif
if (pmgdThis)
{
if (pmgdThis->pvnContainedBy) ValNodeFree(pmgdThis->pvnContainedBy);
if (pmgdThis->pcGraphName) MemFree(pmgdThis->pcGraphName);
if (pmgdThis->pcPDBComment) MemFree(pmgdThis->pcPDBComment);
if (pmgdThis->pvnmaAHead) FreeListVNMA(pmgdThis->pvnmaAHead);
if (pmgdThis->pvnmbBHead) FreeListVNMB(pmgdThis->pvnmbBHead);
if (pmgdThis->ppflBoundBox) FLMatrixFree(pmgdThis->ppflBoundBox,0,0);
if (pmgdThis->pcIUPAC) MemFree(pmgdThis->pcIUPAC);
if (pmgdThis->pcGraphNum) MemFree(pmgdThis->pcGraphNum);
MemFree(pmgdThis);
}
}
void LIBCALL FreeMMD(PMMD pmmdThis)
{
#ifdef _DEBUG_2
printf("in FreeMMD ");
#endif
if (pmmdThis)
{
if (pmmdThis->pvnContainedBy) ValNodeFree(pmmdThis->pvnContainedBy);
if (pmmdThis->pcMolName) MemFree(pmmdThis->pcMolName);
if (pmmdThis->pcSeqId) MemFree(pmmdThis->pcSeqId);
if (pmmdThis->pcSequence) MemFree(pmmdThis->pcSequence);
if (pmmdThis->pdnmgHead) FreeListDNMG(pmmdThis->pdnmgHead);
if (pmmdThis->pvnmbIRBHead) FreeListVNMB(pmmdThis->pvnmbIRBHead);
if (pmmdThis->ppflBoundBox) FLMatrixFree(pmmdThis->ppflBoundBox,0,0);
if (pmmdThis->pMolDescr)
AsnGenericChoiceSeqOfFree(pmmdThis->pMolDescr,(AsnOptFreeFunc)BiomolDescrFree);
if (pmmdThis->pSeqId) SeqIdFree(pmmdThis->pSeqId);
MemFree(pmmdThis);
}
}
void LIBCALL FreeMSD(PMSD pmsdThis)
{
#ifdef _DEBUG_2
printf("in FreeMSD ");
#endif
if (pmsdThis)
{
/* ASN.1 parts */
if (pmsdThis->pbsBS) BiostrucFree(pmsdThis->pbsBS);
/* BiostrucFree kills models, features % saved ASN.1 parts ... */
if (pmsdThis->pGraphDescr)
AsnGenericChoiceSeqOfFree(pmsdThis->pGraphDescr,(AsnOptFreeFunc)BiomolDescrFree);
if (pmsdThis->pDictLocal)
AsnGenericUserSeqOfFree(pmsdThis->pDictLocal,(AsnOptFreeFunc)ResidueGraphFree);
/* Structure Strings */
if (pmsdThis->pcSName) MemFree(pmsdThis->pcSName);
if (pmsdThis->pcPDBName) MemFree(pmsdThis->pcPDBName);
if (pmsdThis->pcChemName) MemFree(pmsdThis->pcChemName);
if (pmsdThis->pcPdbClass) MemFree(pmsdThis->pcPdbClass);
if (pmsdThis->pcPdbSource) MemFree(pmsdThis->pcPdbSource);
/* Modelstruc parts */
if (pmsdThis->pdnmmHead) FreeListDNMM(pmsdThis->pdnmmHead);
if (pmsdThis->pvnmbIMBHead) FreeListVNMB(pmsdThis->pvnmbIMBHead);
if (pmsdThis->pdnmlModels) FreeListDNML(pmsdThis->pdnmlModels);
if (pmsdThis->pvnmoHead) FreeListVNMO(pmsdThis->pvnmoHead);
if (pmsdThis->pvnmdHead) FreeListVNMD(pmsdThis->pvnmdHead);
/* if (pmsdThis->pdnsfFeatures) FreeListDNSF(pmsdThis->pdnsfFeatures); */
if (pmsdThis->psaStrucAlignment) BiostrucAnnotSetFree(pmsdThis->psaStrucAlignment);
if (pmsdThis->ppflRotate) FLMatrixFree(pmsdThis->ppflRotate,0,0);
if (pmsdThis->pdnsfsHead) FreeListDNSFS(pmsdThis->pdnsfsHead);
if (pmsdThis->pflTranslate) FLVectorFree(pmsdThis->pflTranslate,0);
if (pmsdThis->ppflBoundBox) FLMatrixFree(pmsdThis->ppflBoundBox,0,0);
if (pmsdThis->pdnmsSlaves) FreeListDNMS(pmsdThis->pdnmsSlaves);
MemFree(pmsdThis);
}
}
/* adds after last node in list if *head not NULL
* otherwise head is new node
*/
PVNMB LIBCALL NewVNMB(PVNMB PNTR ppvnmbList, Int2 choice)
{
PVNMB pvnmbNew = NULL;
PMBD pmbdNew = NULL;
pmbdNew = NewMBD();
if (!pmbdNew) return NULL;
pvnmbNew = ValNodeAddPointer(ppvnmbList, choice, (Nlm_VoidPtr) pmbdNew);
pmbdNew->pvnmbLink = pvnmbNew; /* back link */
return pvnmbNew;
}
PVNMO LIBCALL NewVNMO(PVNMO PNTR ppvnmoList, Int2 choice)
{
PVNMO pvnmoNew = NULL;
PMOD pmodNew = NULL;
pmodNew = NewMOD();
if (!pmodNew) return NULL;
pvnmoNew = ValNodeAddPointer(ppvnmoList, choice, (Nlm_VoidPtr) pmodNew);
pmodNew->pvnmoLink = pvnmoNew; /* back link */
return pvnmoNew;
}
PVNMD LIBCALL NewVNMD(PVNMD PNTR ppvnmdList, Int2 choice)
{
PVNMD pvnmdNew = NULL;
PMDD pmddNew = NULL;
pmddNew = NewMDD();
if (!pmddNew) return NULL;
pvnmdNew = ValNodeAddPointer(ppvnmdList, choice, (Nlm_VoidPtr) pmddNew);
pmddNew->pvnmdLink = pvnmdNew; /* back link */
return pvnmdNew;
}
PVNMA LIBCALL NewVNMA(PVNMA PNTR ppvnmaList, Int2 choice)
{
PVNMA pvnmaNew = NULL;
PMAD pmadNew = NULL;
pmadNew = NewMAD();
if (!pmadNew) return NULL;
pvnmaNew = ValNodeAddPointer(ppvnmaList, choice, (Nlm_VoidPtr) pmadNew);
pmadNew->pvnmaLink = pvnmaNew;
return pvnmaNew;
}
PVNAL LIBCALL NewVNAL(PVNAL PNTR ppvnalList, Int2 choice)
{
/* picks either paldlNew or paldNew as data node */
/* choice is model number - which will end up as a Uint1 */
PVNAL pvnalNew = NULL;
PALD paldNew = NULL;
paldNew = NewALD();
if (!paldNew) return NULL;
pvnalNew = ValNodeAddPointer(ppvnalList, choice, (Nlm_VoidPtr) paldNew);
paldNew->pvnalLink = pvnalNew; /* link to ValNode */
return pvnalNew;
}
PDNMG LIBCALL NewDNMG(PDNMG PNTR ppdnmgList, Int2 choice)
{
PDNMG pdnmgNew = NULL;
PMGD pmgdNew = NULL;
pmgdNew = NewMGD();
if (!pmgdNew) return NULL;
pdnmgNew = DValNodeAddPointer(ppdnmgList, choice, (Nlm_VoidPtr) pmgdNew);
pmgdNew->pdnmgLink = pdnmgNew;
return pdnmgNew;
}
PDNMM LIBCALL NewDNMM(PDNMM PNTR ppdnmmList, Int2 choice)
{
PDNMM pdnmmNew = NULL;
PMMD pmmdNew = NULL;
pmmdNew = NewMMD();
if (!pmmdNew) return NULL;
pdnmmNew = DValNodeAddPointer(ppdnmmList, choice, (Nlm_VoidPtr) pmmdNew);
pmmdNew->pdnmmLink = pdnmmNew;
return pdnmmNew;
}
PDNMS LIBCALL NewDNMS(PDNMS PNTR ppdnmsList, Int2 choice)
{
PDNMS pdnmsNew = NULL;
PMSD pmsdNew = NULL;
pmsdNew = NewMSD();
if (!pmsdNew) return NULL;
pdnmsNew = DValNodeAddPointer(ppdnmsList, choice, (Nlm_VoidPtr) pmsdNew);
pmsdNew->pdnmsLink = pdnmsNew;
return pdnmsNew;
}
/* need to make equivalent function ptr call in a ValNodeFreeDataFn */
ValNodePtr LIBCALL FreeVNDataFn (ValNodePtr vnp, pFreeFunc freefn)
{
ValNodePtr next;
while (vnp)
{
if (freefn)
(*freefn)(vnp->data.ptrvalue);
else
Nlm_MemFree(vnp->data.ptrvalue);
next = vnp->next;
Nlm_MemFree(vnp);
vnp = next;
}
return NULL;
}
void LIBCALL FreeListVNAL(PVNAL pvnalList)
{
#ifdef _DEBUG_2
printf("in FreeListVNAL ");
#endif
FreeVNDataFn(pvnalList, (pFreeFunc)FreeALD);
}
void LIBCALL FreeListDNML(PDNML pdnmlList)
{
#ifdef _DEBUG_2
printf("in FreeListDNML ");
#endif
DValNodeFreeData(pdnmlList, (pFreeFunc)FreeMLD);
}
void LIBCALL FreeListDNSFS(PDNSFS pdnsfsList)
{
#ifdef _DEBUG_2
printf("in FreeListDNSF ");
#endif
DValNodeFreeData(pdnsfsList, (pFreeFunc)FreeSFS); /* don't free Biostruc-dependent features */
}
void LIBCALL FreeListDNSF(PDNSF pdnsfList)
{
#ifdef _DEBUG_2
printf("in FreeListDNSF ");
#endif
DValNodeFree(pdnsfList); /* don't free Biostruc-dependent features */
}
void LIBCALL FreeListVNMB(PVNMB pvnmbList) /* takes out the whole singly-linked list */
{
#ifdef _DEBUG_2
printf("in FreeListVNMB ");
#endif
FreeVNDataFn(pvnmbList, (pFreeFunc)FreeMBD);
}
void LIBCALL FreeListVNMO(PVNMO pvnmoList) /* takes out the whole singly-linked list */
{
#ifdef _DEBUG_2
printf("in FreeListVNMO ");
#endif
FreeVNDataFn(pvnmoList, (pFreeFunc)FreeMOD);
}
void LIBCALL FreeListVNMD(PVNMD pvnmdList) /* takes out the whole singly-linked list */
{
#ifdef _DEBUG_2
printf("in FreeListVNMD ");
#endif
FreeVNDataFn(pvnmdList, (pFreeFunc)FreeMDD);
}
void LIBCALL FreeListVNMA(PVNMA pvnmaList) /* takes out the whole singly-linked list */
{
#ifdef _DEBUG_2
printf("in FreeListVNMA ");
#endif
FreeVNDataFn(pvnmaList, (pFreeFunc)FreeMAD);
}
/* takes out one - at a time ! */
PDNMG LIBCALL FreeDNMG(PDNMG pdnmgList, PDNMG pdnmgThis)
{
#ifdef _DEBUG_2
printf("in FreeDNMG ");
#endif
return DValNodeListDelNode(pdnmgList, pdnmgThis, (pFreeFunc)FreeMGD);
}
void LIBCALL FreeListDNMG(PDNMG pdnmgList)
{
PDNMG pdnmgTemp;
#ifdef _DEBUG_2
printf("in FreeListDNMG ");
#endif
pdnmgTemp = pdnmgList;
while (pdnmgTemp)
{
pdnmgList = FreeDNMG(pdnmgTemp, pdnmgTemp);
pdnmgTemp = pdnmgList;
}
}
PDNMM LIBCALL FreeDNMM(PDNMM pdnmmList, PDNMM pdnmmThis)
{
#ifdef _DEBUG_2
printf("in FreeDNMM ");
#endif
return DValNodeListDelNode(pdnmmList, pdnmmThis, (pFreeFunc)FreeMMD);
}
void LIBCALL FreeListDNMM(PDNMM pdnmmList)
{
PDNMM pdnmmTemp;
#ifdef _DEBUG_2
printf("in FreeListDNMM ");
#endif
pdnmmTemp = pdnmmList;
while (pdnmmTemp)
{
pdnmmList = FreeDNMM(pdnmmTemp, pdnmmTemp);
pdnmmTemp = pdnmmList;
}
}
PDNMS LIBCALL FreeDNMS(PDNMS pdnmsList, PDNMS pdnmsThis)
{
#ifdef _DEBUG_2
printf("in FreeDNMS ");
#endif
return DValNodeListDelNode(pdnmsList, pdnmsThis, (pFreeFunc)FreeMSD);
}
void LIBCALL FreeListDNMS(PDNMS pdnmsList)
{
PDNMS pdnmsTemp;
pdnmsTemp = pdnmsList;
#ifdef _DEBUG_2
printf("in FreeListDNMS ");
#endif
while (pdnmsTemp)
{
pdnmsList = FreeDNMS(pdnmsTemp, pdnmsTemp);
pdnmsTemp = pdnmsList;
}
}
void LIBCALL FreeAtomicModelAsnLists(AtomicCoordinatesPtr pacThis)
{
AlternateConformationIdsPtr paciThis = NULL;
IsotropicTemperatureFactorsPtr pitfThis = NULL;
AnisotropicTemperatureFactorsPtr patfThis = NULL;
AtomicOccupanciesPtr pocThis = NULL;
ModelSpacePointsPtr pmspThis = NULL;
AtomPntrsPtr pappThis = NULL;
CoordinatesPtr pcoThis = NULL;
/* Free data off AtomicCoordinatesPtr pacThis */
if (!pacThis) return;
#ifdef _DEBUG_1
printf("in FreeAtomicModelAsnList\n");
#endif
pappThis = pacThis->atoms; /* AtomPntrsPtr */
pmspThis = pacThis->sites; /* ModelSpacePointsPtr */
pocThis = pacThis->occupancies; /* AtomicOccupanciesPtr */
paciThis = pacThis->alternate_conf_ids; /* AlternateConformationIdsPtr */
if (pacThis->temperature_factors) /* choice of temp factor types */
{
if (pacThis->temperature_factors->choice == AtomicTemperatureFactors_isotropic)
{
pitfThis = (IsotropicTemperatureFactorsPtr) pacThis->temperature_factors->data.ptrvalue;
}
if (pacThis->temperature_factors->choice == AtomicTemperatureFactors_anisotropic)
{
patfThis = (AnisotropicTemperatureFactorsPtr) pacThis->temperature_factors->data.ptrvalue;
}
}
if (pappThis)
{
AtomPntrsFree(pappThis);
pacThis->atoms = NULL;
}
if (pmspThis)
{
ModelSpacePointsFree(pmspThis);
pacThis->sites = NULL;
}
if (pocThis)
{
AtomicOccupanciesFree(pocThis);
pacThis->occupancies = NULL;
}
if (paciThis)
{
AlternateConformationIdsFree(paciThis);
pacThis->alternate_conf_ids = NULL;
}
if (pitfThis)
{
IsotropicTemperatureFactorsFree (pitfThis);
pacThis->temperature_factors->data.ptrvalue = NULL;
}
if (patfThis)
{
AnisotropicTemperatureFactorsFree(patfThis);
pacThis->temperature_factors->data.ptrvalue = NULL;
}
if (pacThis->temperature_factors)
{
ValNodeFree(pacThis->temperature_factors);
pacThis->temperature_factors = NULL;
}
return;
}
PMAD LIBCALL AtomFromMMDBIndex(PDNMS pdnmsList, Int2 iStru, Int2 iMol, Int2 iGraph, Int4 iAtom)
{
PDNMS pdnmsThis;
PMSD pmsdThis;
PDNMM pdnmmThis;
PMMD pmmdThis;
PDNMG pdnmgThis;
PMGD pmgdThis;
PVNMA pvnmaThis;
PMAD pmadThis;
pdnmsThis = (PDNMS) DValNodeFindNext((DValNodePtr)pdnmsList, NULL, iStru);
if (pdnmsThis) pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
else return NULL;
pdnmmThis = (PDNMM) DValNodeFindNext((DValNodePtr)pmsdThis->pdnmmHead, NULL, iMol);
if (pdnmmThis) pmmdThis = (PMMD) pdnmmThis->data.ptrvalue;
else return NULL;
pdnmgThis = (PDNMG) DValNodeFindNext((DValNodePtr)pmmdThis->pdnmgHead, NULL, iGraph);
if (pdnmgThis) pmgdThis = (PMGD) pdnmgThis->data.ptrvalue;
else return NULL;
pvnmaThis = (PVNMA) pmgdThis->pvnmaAHead;
if (pvnmaThis) pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
else return NULL;
while (pvnmaThis)
{
if (pmadThis->iIndex == iAtom)
{
return pmadThis;
}
pvnmaThis = pvnmaThis->next;
if (pvnmaThis) pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
}
return NULL;
}
PMGD LIBCALL GraphFromMMDBIndex(PDNMS pdnmsList, Int2 iStru, Int2 iMol, Int2 iGraph )
{
PDNMS pdnmsThis;
PMSD pmsdThis;
PDNMM pdnmmThis;
PMMD pmmdThis;
PDNMG pdnmgThis;
PMGD pmgdThis;
pdnmsThis = (PDNMS) DValNodeFindNext((DValNodePtr)pdnmsList, NULL, iStru);
if (pdnmsThis) pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
else return NULL;
pdnmmThis = (PDNMM) DValNodeFindNext((DValNodePtr)pmsdThis->pdnmmHead, NULL, iMol);
if (pdnmmThis) pmmdThis = (PMMD) pdnmmThis->data.ptrvalue;
else return NULL;
pdnmgThis = (PDNMG) DValNodeFindNext((DValNodePtr)pmmdThis->pdnmgHead, NULL, iGraph);
if (pdnmgThis)
{
pmgdThis = (PMGD) pdnmgThis->data.ptrvalue;
return pmgdThis;
}
else return NULL;
}
PMMD LIBCALL MolFromMMDBIndex(PDNMS pdnmsList, Int2 iStru, Int2 iMol)
{
PDNMS pdnmsThis;
PMSD pmsdThis;
PDNMM pdnmmThis;
PMMD pmmdThis;
pdnmsThis = (PDNMS) DValNodeFindNext((DValNodePtr)pdnmsList, NULL, iStru);
if (pdnmsThis) pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
else return NULL;
pdnmmThis = (PDNMM) DValNodeFindNext((DValNodePtr)pmsdThis->pdnmmHead, NULL, iMol);
if (pdnmmThis)
{
pmmdThis = (PMMD) pdnmmThis->data.ptrvalue;
return pmmdThis;
}
else return NULL;
}
PRGD LIBCALL LoadDict(CharPtr pcDictName)
{
AsnIoPtr aipr=NULL;
FILE *f;
Char fullpath [PATH_MAX];
CharPtr ptr;
PRGD rgdp;
aipr = NULL;
rgdp = NULL;
ProgramPath (fullpath, sizeof (fullpath) - 1);
ptr = StringRChr (fullpath, DIRDELIMCHR);
if (ptr != NULL) {
*ptr = '\0';
} else {
StrCpy(fullpath, ".");
}
FileBuildPath (fullpath, NULL, pcDictName);
if ((f = FileOpen (fullpath, "rb")) == NULL) {
if (FindPath ("NCBI", "NCBI", "DATA", fullpath, sizeof (fullpath) - 1)) {
FileBuildPath (fullpath, NULL, pcDictName);
aipr = AsnIoOpen (fullpath, "rb");
if (aipr == NULL) {
ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s] in LoadDict", fullpath);
return NULL;
}
} else {
ErrPost(CTX_NCBIOBJ, 1, "FindPath failed in LoadDict");
return NULL;
}
} else {
FileClose (f);
aipr = AsnIoOpen(fullpath, "rb");
if (aipr == NULL) {
ErrPost(CTX_NCBIOBJ, 1, "Couldn't open [%s] in LoadDict", fullpath);
return NULL;
}
}
rgdp = BiostrucResidueGraphSetAsnRead(aipr, NULL);
AsnIoFlush(aipr);
aipr = AsnIoClose(aipr);
return rgdp;
}
BiostrucPtr LIBCALL FetchBS(CharPtr pcFetch, Int2 iType, Int4 mdlLvl,
Int4 maxModels, Byte bExtent)
{ /* mdlLvl = BSEVERYTHING used to denote fetch everything! */
AsnIoPtr paioAIP = NULL; /* aip */
BiostrucPtr pbsThe = NULL;
Boolean bIsNetwork = FALSE;
/* LinkSetPtr plsLink = NULL; */
DocUid duUID = 0;
/* StrToLong stuff */
Nlm_Char ch;
Nlm_Int2 i;
Nlm_Int2 len;
Nlm_Char local [64];
Nlm_Boolean nodigits;
Nlm_Boolean rsult;
long int val;
#ifdef _DEBUG_0
printf("MaxModels=%d ModelLevel=%d\n",(int) maxModels,(int) mdlLvl);
#endif
/* load the parse trees */
if (! (objmmdb1AsnLoad() && objmmdb2AsnLoad() && objmmdb3AsnLoad() ))
{
ErrPostEx(SEV_FATAL,0,0, "Internal - objmmdbNAsnLoad() Failure");
return NULL;
} /* DON'T load any more than necessary */
/* handle the different types of input data */
switch (iType)
{
case INP_ASCII_FILE:
/* open the ASN.1 input file in the right mode */
if ((paioAIP = AsnIoOpen (pcFetch, "r")) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to open ASCII ASN.1 input file:\n %s\n Check if it exists."
,pcFetch);
ErrShow();
return NULL;
}
/* get the pointer to the seq entry */
if (mdlLvl == BSEVERYTHING)
{
if ((pbsThe = BiostrucAsnRead(paioAIP, NULL)) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to read Biostruc in:\n%s\nConfused Binary/ASCII or Wrong File Type!"
,pcFetch);
ErrShow();
return NULL;
}}
else
{ if ((pbsThe = BiostrucAsnGet(paioAIP, NULL, mdlLvl, maxModels)) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to read Biostruc in:\n%s\nConfused Binary/ASCII or Wrong File Type!"
,pcFetch);
ErrShow();
return NULL;
}}
AsnIoClose(paioAIP);
/* printf("Got the ascii biostruc\n"); */
break;
case INP_BINARY_FILE:
/* printf("in Binary input\n"); */
/* open the ASN.1 input file in the right mode */
if ((paioAIP = AsnIoOpen (pcFetch, "rb")) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to open BINARY ASN.1 input file:\n %s\n Check if it exists.",pcFetch);
ErrShow();
return NULL;
}
/* get the pointer to the seq entry */
if (mdlLvl == BSEVERYTHING)
{
if ((pbsThe = BiostrucAsnRead(paioAIP, NULL)) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to read Biostruc in:\n%s\nConfused Binary/ASCII or Wrong File Type!"
,pcFetch);
ErrShow();
return NULL;
}}
else
{ if ((pbsThe = BiostrucAsnGet(paioAIP, NULL, mdlLvl, maxModels)) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to read Biostruc in:\n%s\nConfused Binary/ASCII or Wrong File Type!"
,pcFetch);
ErrShow();
return NULL;
}}
AsnIoClose(paioAIP);
/* printf("Got the binary biostruc\n"); */
break;
case INP_GI:
if (bExtent & (Byte) FETCH_ENTREZ)
if (!MMDBInit())
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to open MMDB input.");
ErrShow();
return NULL;
}
/* this is code from Nlm StrToLong */
rsult = FALSE;
len = (Nlm_Int2) Nlm_StringLen (pcFetch);
if (len != 0) {
rsult = TRUE;
nodigits = TRUE;
for (i = 0; i < len; i++) {
ch = pcFetch [i];
if (ch == ' ' || ch == '+' || ch == '-') {
} else if (ch < '0' || ch > '9') {
rsult = FALSE;
} else {
nodigits = FALSE;
}
}
if (nodigits) {
rsult = FALSE;
}
if (rsult) {
Nlm_StringNCpy (local, pcFetch, sizeof (local));
if (sscanf (local, "%ld", &val) == 1) {
duUID = val;
}
}
}
if (duUID == 0)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "UID - %s - not in structure database, \n Check your input.", pcFetch);
ErrShow();
if (bExtent & (Byte) FETCH_ENTREZ) MMDBFini();
return NULL;
}
if ((pbsThe = MMDBBiostrucGet(duUID, mdlLvl, maxModels)) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to find UID = %ld \nin database.", (long)duUID);
ErrShow();
if (bExtent & (Byte) FETCH_ENTREZ) MMDBFini();
return NULL;
}
if (bExtent & (Byte) FETCH_ENTREZ) MMDBFini();
break;
case INP_PDB_ACCESSION:
if (bExtent & (Byte) FETCH_ENTREZ)
if (!MMDBInit())
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to open MMDB input.");
ErrShow();
return NULL;
}
duUID = MMDBEvalPDB(pcFetch);
if (duUID != 0)
{
if ((pbsThe = MMDBBiostrucGet(duUID, mdlLvl, maxModels)) == NULL)
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Unable to find UID = %ld \nin database.", (long)duUID);
ErrShow();
/* LinkSetFree(plsLink); */
if (bExtent & (Byte) FETCH_ENTREZ) MMDBFini();
return NULL;
}
}
else
{
ErrClear(); /* toolkit fatal */
ErrPostEx(SEV_ERROR,0,0, "Accession - %s - not in structure database, \n Check your input.", pcFetch);
ErrShow();
if (bExtent & (Byte) FETCH_ENTREZ) MMDBFini();
return NULL;
}
if (bExtent & (Byte) FETCH_ENTREZ) MMDBFini();
break;
default:
return NULL;
} /* switch iTYPE */
/* here pbsThe should be valid in-memory Biostruc */
return pbsThe;
}
/* make a GetBSRefictiona */
/**************************/
/*version 4.1 ASN.1 code **/
/**************************/
/* makes ValNode list on MAD, MGD, MDD pvnContainedBy
* and ValNode list on MOD MDD pvnContains.
* ranges are explicitly instantiated,
* but not children.
*/
Boolean LIBCALL AssignSurfaceContents(PDNMS pdnmsList, Int2 iModel, PFB pfbThis, ChemGraphPntrsPtr pcgpContents)
{
AtomPntrsPtr ppaThis = NULL;
ResiduePntrsPtr pprThis = NULL;
ResidueExplicitPntrsPtr ppreThis = NULL;
ResidueIntervalPntrPtr ppriThis = NULL;
MoleculePntrsPtr ppmThis = NULL;
ValNodePtr pvnAtoms = NULL;
ValNodePtr pvnMol = NULL;
ValNodePtr pvnRes = NULL;
ValNodePtr pvnThis = NULL;
PMAD pmadThis = NULL;
PMGD pmgdThis = NULL;
PMMD pmmdThis = NULL;
PMOD pmodThis = NULL;
PMDD pmddThis = NULL;
Int4 iStart = 0;
Int4 iEnd = 0;
#ifdef _DEBUG_1
printf("in AssignSurfaceContents\n ");
#endif
switch (pcgpContents->choice)
{
case ChemGraphPntrs_atoms:
ppaThis = (AtomPntrsPtr) pcgpContents->data.ptrvalue;
pvnMol = ppaThis->molecule_ids;
pvnRes = ppaThis->residue_ids;
pvnAtoms = ppaThis->atom_ids;
while (pvnAtoms)
{
pmadThis = AtomFromMMDBIndex(pdnmsList, (Int2) pdnmsList->choice,
(Int2) pvnMol->data.intvalue, (Int2) pvnRes->data.intvalue,
(Int4) pvnAtoms->data.intvalue);
if (pmadThis)
{
pvnThis = ValNodeAddPointer(&pmadThis->pvnContainedBy, iModel, (Pointer) pfbThis);
if (!pvnThis) return FALSE;
}
else return FALSE;
if (pfbThis->bMe == AM_MOD)
{
pmodThis = (PMOD) pfbThis;
pvnThis = ValNodeAddPointer(&pmodThis->pvnContains, ChemGraphPntrs_atoms, (Pointer) pmadThis);
}
if (pfbThis->bMe == AM_MDD)
{
pmddThis = (PMDD) pfbThis;
pvnThis = ValNodeAddPointer(&pmddThis->pvnContains, ChemGraphPntrs_atoms, (Pointer) pmadThis);
}
pvnAtoms = pvnAtoms->next;
pvnMol = pvnMol->next;
pvnRes = pvnRes->next;
}
return TRUE;
case ChemGraphPntrs_residues:
pprThis = (ResiduePntrsPtr) pcgpContents->data.ptrvalue;
if (pprThis->choice == ResiduePntrs_explicit)
{
ppreThis = (ResidueExplicitPntrsPtr) pprThis->data.ptrvalue;
pvnMol = ppreThis->molecule_ids;
pvnRes = ppreThis->residue_ids;
while (pvnRes)
{
pmgdThis = GraphFromMMDBIndex(pdnmsList, (Int2) pdnmsList->choice,
(Int2) pvnMol->data.intvalue, (Int2) pvnRes->data.intvalue);
if (pmgdThis)
{
pvnThis = ValNodeAddPointer(&pmgdThis->pvnContainedBy, iModel, (Pointer) pfbThis);
if (!pvnThis) return FALSE;
}
else return FALSE;
if (pfbThis->bMe == AM_MOD)
{
pmodThis = (PMOD) pfbThis;
pvnThis = ValNodeAddPointer(&pmodThis->pvnContains, ChemGraphPntrs_residues, (Pointer) pmgdThis);
}
if (pfbThis->bMe == AM_MDD)
{
pmddThis = (PMDD) pfbThis;
pvnThis = ValNodeAddPointer(&pmddThis->pvnContains, ChemGraphPntrs_residues, (Pointer) pmgdThis);
}
pvnMol = pvnMol->next;
pvnRes = pvnRes->next;
}
return TRUE;
}
if (pprThis->choice == ResiduePntrs_interval)
{
ppriThis = (ResidueIntervalPntrPtr) pprThis->data.ptrvalue;
while (ppriThis)
{
iStart = ppriThis->from;
iEnd = ppriThis->to;
if (iStart > ppriThis->to)
{
iStart = ppriThis->to;
iEnd = ppriThis->from;
}
for (;iStart <= iEnd; iStart++)
{
pmgdThis = GraphFromMMDBIndex(pdnmsList, (Int2) pdnmsList->choice,
(Int2) ppriThis->molecule_id, (Int2) iStart);
if (pmgdThis)
{
pvnThis = ValNodeAddPointer(&pmgdThis->pvnContainedBy, iModel, (Pointer) pfbThis);
if (!pvnThis) return FALSE;
}
else return FALSE;
if (pfbThis->bMe == AM_MOD)
{
pmodThis = (PMOD) pfbThis;
pvnThis = ValNodeAddPointer(&pmodThis->pvnContains, ChemGraphPntrs_residues, (Pointer) pmgdThis);
}
if (pfbThis->bMe == AM_MDD)
{
pmddThis = (PMDD) pfbThis;
pvnThis = ValNodeAddPointer(&pmddThis->pvnContains, ChemGraphPntrs_residues, (Pointer) pmgdThis);
}
} /* for start to end of interval */
ppriThis = ppriThis->next;
} /* while intervals */
return TRUE;
}
return FALSE;
case ChemGraphPntrs_molecules:
ppmThis = (MoleculePntrsPtr) pcgpContents->data.ptrvalue;
pvnMol = ppmThis->molecule_ids;
while (pvnMol)
{
pmmdThis = MolFromMMDBIndex(pdnmsList, (Int2) pdnmsList->choice,
(Int2) pvnMol->data.intvalue);
if (pmmdThis)
{
pvnThis = ValNodeAddPointer(&pmmdThis->pvnContainedBy, iModel, (Pointer) pfbThis);
if (!pvnThis) return FALSE;
}
else return FALSE;
if (pfbThis->bMe == AM_MOD)
{
pmodThis = (PMOD) pfbThis;
pvnThis = ValNodeAddPointer(&pmodThis->pvnContains, ChemGraphPntrs_molecules, (Pointer) pmmdThis);
}
if (pfbThis->bMe == AM_MDD)
{
pmddThis = (PMDD) pfbThis;
pvnThis = ValNodeAddPointer(&pmddThis->pvnContains, ChemGraphPntrs_molecules, (Pointer) pmmdThis);
}
pvnMol = pvnMol->next;
}
return TRUE;
}
return FALSE;
}
void LIBCALL FreeSurfaceModelAsnList(SurfaceCoordinatesPtr pscThis)
{
TMeshPtr ptmshThis = NULL;
TrianglesPtr ptriThis = NULL;
ValNodePtr pvnX = NULL;
if (!pscThis) return;
if (!pscThis->Surface_surface) return;
#ifdef _DEBUG_1
printf("in FreeSurfaceModelAsnList\n");
#endif
switch (pscThis->Surface_surface->choice)
{
case Surface_surface_cylinder:
case Surface_surface_brick:
case Surface_surface_sphere:
case Surface_surface_cone:
return; /* nothing to free */
case Surface_surface_tmesh:
ptmshThis = (TMeshPtr) pscThis->Surface_surface->data.ptrvalue;
pvnX = ValNodeFree(ptmshThis->x);
ptmshThis->x = NULL;
pvnX = ValNodeFree(ptmshThis->y);
ptmshThis->y = NULL;
pvnX = ValNodeFree(ptmshThis->z);
ptmshThis->z = NULL;
pvnX = ValNodeFree(ptmshThis->swap);
ptmshThis->swap = NULL;
return;
case Surface_surface_triangles:
ptriThis = (TrianglesPtr) pscThis->Surface_surface->data.ptrvalue;
pvnX = ValNodeFree(ptriThis->x);
ptriThis->x = NULL;
pvnX = ValNodeFree(ptriThis->y);
ptriThis->y = NULL;
pvnX = ValNodeFree(ptriThis->z);
ptriThis->z = NULL;
pvnX = ValNodeFree(ptriThis->v1);
ptriThis->v1 = NULL;
pvnX = ValNodeFree(ptriThis->v2);
ptriThis->v2 = NULL;
pvnX = ValNodeFree(ptriThis->v3);
ptriThis->v3 = NULL;
return;
default:
return;
}
}
Boolean LIBCALL FillSurface(SurfaceCoordinatesPtr pscThis, PMOD pmodThis)
{
CylinderPtr pcylThis = NULL;
BrickPtr pbrkThis = NULL;
ConePtr pconThis = NULL;
TMeshPtr ptmshThis = NULL;
TrianglesPtr ptriThis = NULL;
SpherePtr psphThis = NULL;
ModelSpacePointPtr pmspTop = NULL;
ModelSpacePointPtr pmspBottom = NULL;
ModelSpacePointPtr pmspTemp = NULL;
RealValuePtr prvRadius = NULL;
ValNodePtr pvnSwap = NULL;
ValNodePtr pvnX = NULL;
ValNodePtr pvnY = NULL;
ValNodePtr pvnZ = NULL;
Int4 iCount = 0;
Boolean rsult = FALSE;
#ifdef _DEBUG_1
printf("in FillSurface=");
#endif
if (!pscThis) return FALSE;
if (!pscThis->Surface_surface) return FALSE;
ProgMon("Instantiating Surface");
switch (pscThis->Surface_surface->choice)
{
case Surface_surface_cylinder:
#ifdef _DEBUG_2
printf("cylinder\n ");
#endif
pmodThis->bWhat = (Byte)(pmodThis->bWhat | (Byte) OBJ_CYLINDER);
pcylThis = (CylinderPtr) pscThis->Surface_surface->data.ptrvalue;
pmodThis->ppflObject = FLMatrix(0, 1, 0, 2); /* 2 by 3 matrix */
if (!pmodThis->ppflObject) return FALSE;
pmodThis->iCoordNo = 2;
pmspTop = pcylThis->axis_top;
pmspBottom = pcylThis->axis_bottom;
prvRadius = pcylThis->radius;
pmodThis->ppflObject[0][0] = (FloatLo)((FloatLo)pmspTop->x/pmspTop->scale_factor);
pmodThis->ppflObject[0][1] = (FloatLo)((FloatLo)pmspTop->y/pmspTop->scale_factor);
pmodThis->ppflObject[0][2] = (FloatLo)((FloatLo)pmspTop->z/pmspTop->scale_factor);
pmodThis->ppflObject[1][0] = (FloatLo)((FloatLo)pmspBottom->x/pmspBottom->scale_factor);
pmodThis->ppflObject[1][1] = (FloatLo)((FloatLo)pmspBottom->y/pmspBottom->scale_factor);
pmodThis->ppflObject[1][2] = (FloatLo)((FloatLo)pmspBottom->z/pmspBottom->scale_factor);
pmodThis->flRadius = (FloatLo)((FloatLo)prvRadius->scaled_integer_value/prvRadius->scale_factor);
return TRUE;
case Surface_surface_brick:
#ifdef _DEBUG_2
printf("brick\n ");
#endif
pmodThis->bWhat = (Byte)(pmodThis->bWhat | (Byte) OBJ_BRICK);
pbrkThis = (BrickPtr) pscThis->Surface_surface->data.ptrvalue;
pmodThis->ppflObject = FLMatrix(0, 7, 0, 2); /* 8 by 3 matrix */
if (!pmodThis->ppflObject) return FALSE;
pmodThis->iCoordNo = 8;
pmspTemp = pbrkThis->corner_000;
pmodThis->ppflObject[0][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[0][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[0][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
pmspTemp = pbrkThis->corner_001;
pmodThis->ppflObject[1][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[1][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[1][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
pmspTemp = pbrkThis->corner_010;
pmodThis->ppflObject[2][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[2][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[2][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
pmspTemp = pbrkThis->corner_011;
pmodThis->ppflObject[3][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[3][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[3][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
pmspTemp = pbrkThis->corner_100;
pmodThis->ppflObject[4][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[4][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[4][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
pmspTemp = pbrkThis->corner_101;
pmodThis->ppflObject[5][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[5][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[5][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
pmspTemp = pbrkThis->corner_110;
pmodThis->ppflObject[6][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[6][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[6][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
pmspTemp = pbrkThis->corner_111;
pmodThis->ppflObject[7][0] = (FloatLo)((FloatLo)pmspTemp->x/pmspTemp->scale_factor);
pmodThis->ppflObject[7][1] = (FloatLo)((FloatLo)pmspTemp->y/pmspTemp->scale_factor);
pmodThis->ppflObject[7][2] = (FloatLo)((FloatLo)pmspTemp->z/pmspTemp->scale_factor);
return TRUE;
case Surface_surface_sphere:
#ifdef _DEBUG_2
printf("sphere\n ");
#endif
pmodThis->bWhat = (Byte)(pmodThis->bWhat | (Byte) OBJ_SPHERE);
psphThis = (SpherePtr) pscThis->Surface_surface->data.ptrvalue;
pmodThis->ppflObject = FLMatrix(0, 1, 0, 1); /* 1 by 3 matrix */
if (!pmodThis->ppflObject) return FALSE;
pmodThis->iCoordNo = 1;
pmspTop = psphThis->center;
prvRadius = psphThis->radius;
pmodThis->ppflObject[0][0] = (FloatLo)((FloatLo)pmspTop->x/pmspTop->scale_factor);
pmodThis->ppflObject[0][1] = (FloatLo)((FloatLo)pmspTop->y/pmspTop->scale_factor);
pmodThis->ppflObject[0][2] = (FloatLo)((FloatLo)pmspTop->z/pmspTop->scale_factor);
pmodThis->flRadius = (FloatLo)((FloatLo)prvRadius->scaled_integer_value/prvRadius->scale_factor);
return TRUE;
case Surface_surface_cone:
#ifdef _DEBUG_2
printf("cone\n ");
#endif
pmodThis->bWhat = (Byte)(pmodThis->bWhat | (Byte) OBJ_CONE);
pconThis = (ConePtr) pscThis->Surface_surface->data.ptrvalue;
pmodThis->ppflObject = FLMatrix(0, 1, 0, 2); /* 2 by 3 matrix */
if (!pmodThis->ppflObject) return FALSE;
pmodThis->iCoordNo = 2;
pmspTop = pconThis->axis_top;
pmspBottom = pconThis->axis_bottom;
prvRadius = pconThis->radius_bottom;
pmodThis->ppflObject[0][0] = (FloatLo)((FloatLo)pmspTop->x/pmspTop->scale_factor);
pmodThis->ppflObject[0][1] = (FloatLo)((FloatLo)pmspTop->y/pmspTop->scale_factor);
pmodThis->ppflObject[0][2] = (FloatLo)((FloatLo)pmspTop->z/pmspTop->scale_factor);
pmodThis->ppflObject[1][0] = (FloatLo)((FloatLo)pmspBottom->x/pmspBottom->scale_factor);
pmodThis->ppflObject[1][1] = (FloatLo)((FloatLo)pmspBottom->y/pmspBottom->scale_factor);
pmodThis->ppflObject[1][2] = (FloatLo)((FloatLo)pmspBottom->z/pmspBottom->scale_factor);
pmodThis->flRadius = (FloatLo)((FloatLo)prvRadius->scaled_integer_value/prvRadius->scale_factor);
return TRUE;
case Surface_surface_tmesh:
#ifdef _DEBUG_2
printf("tmesh\n ");
#endif
pmodThis->bWhat = (Byte)(pmodThis->bWhat | (Byte) OBJ_TMESH);
ptmshThis = (TMeshPtr) pscThis->Surface_surface->data.ptrvalue;
pmodThis->ppflObject = FLMatrix(0, ptmshThis->number_of_points, 0, 2); /* N by 3 matrix */
if (!pmodThis->ppflObject) return FALSE;
pmodThis->pucSwap = UCVector(0, ptmshThis->number_of_points); /* N vector for swap flags */
if (!pmodThis->pucSwap) return FALSE;
pvnX = ptmshThis->x;
pvnY = ptmshThis->y;
pvnZ = ptmshThis->z;
pvnSwap = ptmshThis->swap;
iCount = 0;
while (pvnX)
{
ProgMon("Instantiating TMesh");
pmodThis->ppflObject[iCount][0] = (FloatLo)
((FloatLo)pvnX->data.intvalue/ptmshThis->scale_factor);
pmodThis->ppflObject[iCount][1] = (FloatLo)
((FloatLo)pvnY->data.intvalue/ptmshThis->scale_factor);
pmodThis->ppflObject[iCount][2] = (FloatLo)
((FloatLo)pvnZ->data.intvalue/ptmshThis->scale_factor);
if (pvnSwap->data.boolvalue) pmodThis->pucSwap[iCount] = (Uchar) 1;
iCount++;
pvnX = pvnX->next;
pvnY = pvnY->next;
pvnZ = pvnZ->next;
pvnSwap = pvnSwap->next;
}
pmodThis->iCoordNo = iCount;
FreeSurfaceModelAsnList(pscThis);
return TRUE;
case Surface_surface_triangles:
#ifdef _DEBUG_2
printf("triangles\n ");
#endif
pmodThis->bWhat = (Byte)(pmodThis->bWhat | (Byte) OBJ_TRIANGLES);
ptriThis = (TrianglesPtr) pscThis->Surface_surface->data.ptrvalue;
pmodThis->ppflObject = FLMatrix(0, ptriThis->number_of_points, 0, 2); /* N by 3 matrix */
if (!pmodThis->ppflObject) return FALSE;
pmodThis->ppi4Triangles = I4Matrix(0, ptriThis->number_of_triangles,0,2); /* N by 3 matrix */
if (!pmodThis->ppi4Triangles) return FALSE;
pvnX = ptriThis->x;
pvnY = ptriThis->y;
pvnZ = ptriThis->z;
iCount = 0;
while (pvnX)
{
ProgMon("Instantiating Triangles");
pmodThis->ppflObject[iCount][0] = (FloatLo)
((FloatLo)pvnX->data.intvalue/ptriThis->scale_factor);
pmodThis->ppflObject[iCount][1] = (FloatLo)
((FloatLo)pvnY->data.intvalue/ptriThis->scale_factor);
pmodThis->ppflObject[iCount][2] = (FloatLo)
((FloatLo)pvnZ->data.intvalue/ptriThis->scale_factor);
iCount++;
pvnX = pvnX->next;
pvnY = pvnY->next;
pvnZ = pvnZ->next;
}
pmodThis->iCoordNo = iCount;
iCount = 0;
pvnX = ptriThis->v1;
pvnY = ptriThis->v2;
pvnZ = ptriThis->v3;
while (pvnX)
{
pmodThis->ppi4Triangles[iCount][0] = (Int4) pvnX->data.intvalue;
pmodThis->ppi4Triangles[iCount][1] = (Int4) pvnY->data.intvalue;
pmodThis->ppi4Triangles[iCount][2] = (Int4) pvnZ->data.intvalue;
iCount++;
pvnX = pvnX->next;
pvnY = pvnY->next;
pvnZ = pvnZ->next;
}
pmodThis->iTriNo = iCount;
FreeSurfaceModelAsnList(pscThis);
return TRUE;
default:
rsult = FALSE;
}
return rsult;
}
Int2 LIBCALL BiostrucModel2ModelStruc(BiostrucModelPtr pbsmThis, PDNMS pdnmsThis,
Int2 iChoice, Int2 iModelCount, Byte bExtent)
{
PMAD pmadThis = NULL;
PVNMO pvnmoThis = NULL;
PVNMD pvnmdThis = NULL;
PVNAL pvnalThis = NULL;
PVNAL pvnalTemp = NULL;
PALD paldThis = NULL;
PALD paldTemp = NULL;
PMOD pmodThis = NULL;
PMDD pmddThis = NULL;
PMLD pmldThis = NULL;
PMLD pmldFirst = NULL;
PDNML pdnmlModel = NULL;
PMSD pmsdThis = NULL;
IsotropicTemperatureFactorsPtr pitfThis = NULL;
AnisotropicTemperatureFactorsPtr patfThis = NULL;
AlternateConformationIdsPtr paciThis = NULL;
AtomicOccupanciesPtr pocThis = NULL;
ModelSpacePointsPtr pmspThis = NULL;
AtomicCoordinatesPtr pacThis = NULL;
AtomPntrsPtr pappThis = NULL;
CoordinatesPtr pcoThis = NULL;
ModelCoordinateSetPtr pmcsThis = NULL;
SurfaceCoordinatesPtr pscThis = NULL;
DensityCoordinatesPtr pdcThis = NULL;
CharPtr pcThis = NULL;
CharPtr pcTemp = NULL;
ValNodePtr pvnX = NULL;
ValNodePtr pvnY = NULL;
ValNodePtr pvnZ = NULL;
ValNodePtr pvnB11 = NULL;
ValNodePtr pvnB12 = NULL;
ValNodePtr pvnB13 = NULL;
ValNodePtr pvnB22 = NULL;
ValNodePtr pvnB23 = NULL;
ValNodePtr pvnB33 = NULL;
ValNodePtr pvnOcc = NULL;
ValNodePtr pvnAlt = NULL;
ValNodePtr pvnMid = NULL;
ValNodePtr pvnRid = NULL;
ValNodePtr pvnAid = NULL;
ValNodePtr pmdrThis = NULL;
Int4 iCountAtoms = 0;
Int4 iCounter = 0;
Int4 iVectLen = 0;
Int4 iCoordScale = 0;
Int4 iCoordSets = 0;
Int4 iOccScale = 0;
Int4 iTempScale = 0;
CharPtr pcTest = NULL;
Byte bAnisotropy = FALSE;
Byte bAltConf = FALSE;
Boolean bFirstCoordSet = TRUE;
#ifdef _DEBUG_1
printf("Making Model #%d %d \n",iModelCount, (Int2)bExtent);
#endif
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
pmldFirst = NewMLD();
if (!pmldFirst) goto allocerr;
pmldFirst->iType = pbsmThis->type;
pmldFirst->iId = pbsmThis->id;
pmldFirst->bSelected = (Byte) 0x01; /* for saving/conversion */
pmldFirst->pbsmModel = pbsmThis; /* point to the entire model */
pmldFirst->pmsdParent = (PMSD) pdnmsThis->data.ptrvalue;
pmdrThis = ValNodeFindNext(pbsmThis->descr, NULL, ModelDescr_name);
if (pmdrThis)
{
pmldFirst->pcModelName = StringSave((CharPtr) pmdrThis->data.ptrvalue);
}
pmcsThis = pbsmThis->model_coordinates;
while (pmcsThis) /* walk the model-coordinate sets - flattened and instantiated */
{
bAnisotropy = FALSE;
bAltConf = FALSE;
iCoordSets++;
#ifdef _DEBUG_1
printf("Model coord set %d\n ", iCoordSets);
#endif
if (!bFirstCoordSet)
{
pmldThis->next = NewMLD();
if (!pmldThis->next) goto allocerr;
pmldThis = pmldThis->next;
pmldThis->iType = pbsmThis->type;
pmldThis->iId = pbsmThis->id;
pmldThis->pbsmModel = pbsmThis; /* point to the entire model */
pmldThis->iNoCoordSet = pmcsThis->id;
pmldThis->pmsdParent = (PMSD) pdnmsThis->data.ptrvalue;
}
else
{
pmldThis = pmldFirst;
pmldThis->iNoCoordSet = pmcsThis->id;
}
#ifdef _DEBUG_1
printf("Model Type %d\n ", pmldThis->iType);
#endif
bFirstCoordSet = FALSE;
/* NOT BY REFERENCE YET */
if (pmcsThis->Coordinates_coordinates->choice == Coordinates_coordinates_reference) goto skipnext;
/* rest are literals */
pcoThis = (CoordinatesPtr) pmcsThis->Coordinates_coordinates->data.ptrvalue;
/* read in Surface coordinate sets MOD */
if (pcoThis->choice == Coordinates_surface)
{
#ifdef _DEBUG_3
printf("surface\n");
#endif
pmsdThis->iObjCount += 1;
pvnmoThis = NewVNMO(NULL, iModelCount);
if (!pvnmoThis) goto allocerr;
pmodThis = (PMOD) pvnmoThis->data.ptrvalue;
pmodThis->pfbParent = (PFB) pmsdThis;
pscThis = (SurfaceCoordinatesPtr) pcoThis->data.ptrvalue;
if (!(FillSurface(pscThis, pmodThis))) goto allocerr;
if (!(AssignSurfaceContents(pdnmsThis, iModelCount, (PFB) pmodThis, pscThis->contents))) goto allocerr;
if (pmsdThis->pvnmoHead == NULL)
{
pmsdThis->pvnmoHead = pvnmoThis;
}
else
ValNodeListCat(pmsdThis->pvnmoHead, pvnmoThis);
pmodThis->pmldCoordSet = pmldThis;
pmldThis->pmodObject = pmodThis;
goto skipnext;
}
/* read in DENSITY coordinate sets MDD */
if (pcoThis->choice == Coordinates_density)
{
#ifdef _DEBUG_3
printf("density\n");
#endif
pmsdThis->iDensCount += 1;
pvnmdThis = NewVNMD(NULL, iModelCount);
if (!pvnmdThis) goto allocerr;
pmddThis = (PMDD) pvnmdThis->data.ptrvalue;
pdcThis = (DensityCoordinatesPtr) pcoThis->data.ptrvalue;
/* @@@@@@@@@@@@@@@@@@@@@@@convert the density object */
if (!(AssignSurfaceContents(pdnmsThis, iModelCount, (PFB) pmddThis, pdcThis->contents))) goto allocerr;
if (pmsdThis->pvnmdHead == NULL)
{
pmsdThis->pvnmdHead = pvnmdThis;
}
else
ValNodeListCat(pmsdThis->pvnmdHead, pvnmdThis);
pmddThis->pmldCoordSet = pmldThis;
pmldThis->pmddDensity = pmddThis;
goto skipnext;
}
/* NOTE that coordinates by REFERENCE are not yet supported */
pacThis = NULL;
pappThis = NULL;
pmspThis = NULL;
pocThis = NULL;
paciThis = NULL;
if ((pcoThis->choice == Coordinates_atomic) && (bExtent & (Byte) COORDS_DATA))
{
pacThis = (AtomicCoordinatesPtr) pcoThis->data.ptrvalue;
pappThis = pacThis->atoms; /* AtomPntrsPtr */
pmspThis = pacThis->sites; /* ModelSpacePointsPtr */
pocThis = pacThis->occupancies; /* MolOccPtr */
paciThis = pacThis->alternate_conf_ids; /* AlternateConformationIdsPtr */
if ((pacThis->temperature_factors) && (bExtent & (Byte) TEMP_DATA))
{
#ifdef _DEBUG_2
printf("Isotropic Temperature factors \n");
#endif
if (pacThis->temperature_factors->choice == AtomicTemperatureFactors_isotropic)
{
pitfThis = (IsotropicTemperatureFactorsPtr) pacThis->temperature_factors->data.ptrvalue;
if (pitfThis) iTempScale = pitfThis->scale_factor;
pvnB11 = pitfThis->b;
}
if (pacThis->temperature_factors->choice == AtomicTemperatureFactors_anisotropic)
{
patfThis = (AnisotropicTemperatureFactorsPtr) pacThis->temperature_factors->data.ptrvalue;
bAnisotropy = TRUE;
if (patfThis)
{
#ifdef _DEBUG_2
printf("Anisotropic Temperature factors \n");
#endif
iTempScale = patfThis->scale_factor;
pvnB11 = patfThis->b_11;
pvnB12 = patfThis->b_12;
pvnB13 = patfThis->b_13;
pvnB22 = patfThis->b_22;
pvnB23 = patfThis->b_23;
pvnB33 = patfThis->b_33;
}
}
}
/* else deal with anisotropic ones */
} /* if pcoThis */
else
{
goto skipnext;
}
if (pmspThis)
{
pvnX = pmspThis->x;
pvnY = pmspThis->y;
pvnZ = pmspThis->z;
iCoordScale = pmspThis->scale_factor;
#ifdef _DEBUG_2
printf("Coordinates / = %d\n", iCoordScale);
#endif
} else goto erret;
if (pappThis)
{
pvnMid = pappThis->molecule_ids;
pvnRid = pappThis->residue_ids;
pvnAid = pappThis->atom_ids;
iCountAtoms = pappThis->number_of_ptrs;
#ifdef _DEBUG_2
printf("%d ATOMS In Model\n", iCountAtoms);
#endif
} else goto erret;
if ((pocThis) && (bExtent & (Byte) OCC_DATA))
{
pvnOcc = pocThis->o;
iOccScale = pocThis->scale_factor;
#ifdef _DEBUG_2
printf("Occupancies / %d\n", iOccScale);
#endif
}
if ((paciThis) && (bExtent & (Byte) ALTCNF_DATA))
{
pvnAlt = paciThis;
bAltConf = TRUE;
#ifdef _DEBUG_3
printf("Alt conformations found \n");
#endif
}
if (iCoordScale) iVectLen = 2; /* 3 elements 0=X,1=Y,2=Z */
if (iOccScale) iVectLen = 3;
if (iTempScale) iVectLen = 4;
if ((iTempScale) && bAnisotropy) iVectLen = 9;
#ifdef _DEBUG_2
printf("iVectLen = %d\n", iVectLen);
#endif
if ((iCoordScale) && (pappThis && pmspThis)) /* minimum to do the atomic locations */
{
/* do all data collect in one walk-through the vectors to preserve atom loc data */
/* the vector pmdlThis->ppAsnOrder has PALD pointers in it, which begin at */
/* ppAsnOrder[1] and end at ppAsnOrder[iCountAtoms], so ASN.1 indexing is not */
/* shifted by (-1) to match C indexing */
/* ppAsnOrder[iCountAtoms+1] is set to NULL as an end-of matrix indicator */
pmldThis->ppAsnOrder = PTRVector(0, iCountAtoms + 1);
if (pmldThis->ppAsnOrder) /* this should not be fatal - only affects features */
pmldThis->ppAsnOrder[iCountAtoms+1] = NULL;
while (iCounter < iCountAtoms)
{
iCounter++;
ProgMon("Instantiating Atom Locations");
#ifdef _DEBUG_3
printf("[%d] ",iCounter);
#endif
pmadThis = AtomFromMMDBIndex(pdnmsThis, iChoice, (Int2) pvnMid->data.intvalue,
(Int2) pvnRid->data.intvalue, (Int4) pvnAid->data.intvalue);
if (!pmadThis) goto erret;
pvnalThis = NewVNAL(NULL, iModelCount);
if (!pvnalThis) goto allocerr;
paldThis = (PALD) pvnalThis->data.ptrvalue;
paldThis->pfbParent = (PFB) pmadThis; /* back-link to pmad */
paldThis->pflvData = FLVector(0,(Int4) iVectLen); /* alloc the data vector */
if (!paldThis->pflvData) goto allocerr;
paldThis->iCoordSet = (Int1) pmcsThis->id;
paldThis->iFloatNo = (Int1) iVectLen;
if (pmldThis->ppAsnOrder) pmldThis->ppAsnOrder[iCounter] = (Pointer) paldThis; /* add to order array */
if (pmadThis->pvnalLocate)
{ /* the case where models are already present */
#ifdef _DEBUG_3
printf("{%d}", iModelCount);
#endif
pvnalTemp = (PVNAL) ValNodeFindNext(pmadThis->pvnalLocate,NULL,iModelCount);
if (pvnalTemp)
{ /* the case where THIS model has a location already */
#ifdef _DEBUG_3
printf("DISORDER!!\n");
#endif
paldTemp = (PALD) pvnalTemp->data.ptrvalue;
while (paldTemp->next)
{ /* find end of pald list */
paldTemp = paldTemp->next;
}
paldTemp->next = (PALD)pvnalThis->data.ptrvalue; /* attach the new location */
pvnalThis->data.ptrvalue = NULL;
pvnalThis = ValNodeFree(pvnalThis); /* lose the ValNode baggage */
}
else
ValNodeListCat(pmadThis->pvnalLocate, pvnalThis); /* attach to pmadThis */
}
else
pmadThis->pvnalLocate = pvnalThis;
paldThis->pflvData[0] = (FloatLo)((FloatLo)pvnX->data.intvalue/iCoordScale);
paldThis->pflvData[1] = (FloatLo)((FloatLo)pvnY->data.intvalue/iCoordScale);
paldThis->pflvData[2] = (FloatLo)((FloatLo)pvnZ->data.intvalue/iCoordScale);
#ifdef _DEBUG_3
printf("%s X= %f, Y= %f, Z= %f ", pmadThis->pcAName, paldThis->pflvData[0],
paldThis->pflvData[1], paldThis->pflvData[2]);
#endif
if (iOccScale)
{
paldThis->pflvData[3] = (FloatLo)((FloatLo)pvnOcc->data.intvalue/iOccScale) ;
pvnOcc = pvnOcc->next;
#ifdef _DEBUG_3
printf(" Occ = %f ", paldThis->pflvData[3]);
#endif
}
else if(iVectLen >=3 ) paldThis->pflvData[3] = 1.0;
if (bAltConf)
{
pcThis = (CharPtr) pvnAlt->data.ptrvalue;
if (pcThis)
{
paldThis->cAltConf = (Char) pcThis[0];
if (!pmldThis->pcAltConf)
{
pmldThis->pcAltConf = StringSave(pcThis);
}
else
{ /* no alt conf string yet */
pcTest = NULL;
pcTest = StringChr(pmldThis->pcAltConf,(Char) pcThis[0]);
if (!(pcTest))
{ /* char not yet in pmldThis->pcAltConf */
#ifdef _DEBUG_3
printf("\nNEW STRING\n");
#endif
pcTemp = (CharPtr) MemNew((size_t)(StringLen(pmldThis->pcAltConf)+2)); /* more room */
StringCpy(pcTemp, pmldThis->pcAltConf); /* copy old string */
StringCat(pcTemp, pcThis); /* new letter added */
MemFree(pmldThis->pcAltConf); /* lose old string */
pmldThis->pcAltConf = pcTemp; /* new string */
}
}
}
#ifdef _DEBUG_3
printf(" <%s>pmldThis \n",pmldThis->pcAltConf);
printf("%s-\n",pcThis);
printf(" <%c>paldThis \n",(char) paldThis->cAltConf );
#endif
pvnAlt = pvnAlt->next;
}
if (iTempScale)
{
if (bAnisotropy)
{
#ifdef _DEBUG_3
printf("%d %d %d %d %d %d", pvnB11->data.intvalue, pvnB12->data.intvalue,
pvnB13->data.intvalue, pvnB22->data.intvalue,
pvnB23->data.intvalue, pvnB33->data.intvalue);
#endif
paldThis->pflvData[5] = (FloatLo)((FloatLo)pvnB12->data.intvalue/iTempScale);
paldThis->pflvData[6] = (FloatLo)((FloatLo)pvnB13->data.intvalue/iTempScale);
paldThis->pflvData[7] = (FloatLo)((FloatLo)pvnB22->data.intvalue/iTempScale);
paldThis->pflvData[8] = (FloatLo)((FloatLo)pvnB23->data.intvalue/iTempScale);
paldThis->pflvData[9] = (FloatLo)((FloatLo)pvnB33->data.intvalue/iTempScale);
#ifdef _DEBUG_3
printf("B12=%f, B13=%f, B22=%f, B23=%f, B33=%f ",
paldThis->pflvData[5], paldThis->pflvData[6], paldThis->pflvData[7],
paldThis->pflvData[8], paldThis->pflvData[9] );
#endif
pvnB12 = pvnB12->next;
pvnB13 = pvnB13->next;
pvnB22 = pvnB22->next;
pvnB23 = pvnB23->next;
pvnB33 = pvnB33->next;
}
paldThis->pflvData[4] = (FloatLo)((FloatLo)pvnB11->data.intvalue/iTempScale);
#ifdef _DEBUG_3
printf("B11=%f ", paldThis->pflvData[4]);
#endif
pvnB11 = pvnB11->next;
} /* if iTempScale */
#ifdef _DEBUG_3
printf("\n");
#endif
pvnX = pvnX->next;
pvnY = pvnY->next;
pvnZ = pvnZ->next;
pvnMid = pvnMid->next;
pvnRid = pvnRid->next;
pvnAid = pvnAid->next;
} /* while (iCounter < iCountAtoms) */
} /* if pmspThis && pappThis */
skipnext:
#ifdef _DEBUG_3
printf("skipnext");
#endif
/* free the model data leaving the ASN.1 stub */
if (pacThis) FreeAtomicModelAsnLists(pacThis);
pmcsThis = pmcsThis->next;
} /* while pmcsThis - do next coordinate set*/
pdnmlModel = DValNodeAddPointer(&pmsdThis->pdnmlModels, iModelCount, (Nlm_VoidPtr) pmldFirst);
if (!pdnmlModel) goto allocerr;
return 1;
allocerr:
ErrClear();
ErrPostEx(SEV_ERROR,0,0, "Out Of Memory While Loading Model\nTry loading smaller or fewer Models");
ErrShow();
FreeMLD(pmldFirst);
return 0;
erret:
ErrClear();
ErrPostEx(SEV_ERROR,0,0, "Internal Indexing Failure in ASN.1\nCheck ASN.1 Input for integrity");
ErrShow();
FreeMLD(pmldFirst);
return -1;
}
ValNodePtr LIBCALL MakeChemGraphNodeList(PDNMS pdnmsThis, ChemGraphPntrsPtr pcgpThis)
{
ValNodePtr pvnThis = NULL;
ValNodePtr pvnLocList = NULL;
PFB pfbThis = NULL;
ResiduePntrsPtr prpsThis = NULL;
ResidueExplicitPntrsPtr prepThis = NULL;
ResidueIntervalPntrPtr pripThis = NULL;
AtomPntrsPtr pAtoms = NULL;
MoleculePntrsPtr pMolecules = NULL;
ValNodePtr pvnAtom = NULL;
ValNodePtr pvnMol = NULL;
ValNodePtr pvnRes = NULL;
Int4 iCountPtrs = 0;
Int4 iStart = 0;
Int4 iEnd = 0;
if (!pdnmsThis) return NULL;
if (!pcgpThis) return NULL;
if (pcgpThis && pdnmsThis)
{
switch (pcgpThis->choice)
{
case ChemGraphPntrs_atoms:
pAtoms = (AtomPntrsPtr) pcgpThis->data.ptrvalue;
if (!pAtoms) return NULL;
pvnMol = pAtoms->molecule_ids;
pvnRes = pAtoms->residue_ids;
pvnAtom = pAtoms->atom_ids;
if (pAtoms->number_of_ptrs == 0) return NULL;
for (iCountPtrs = 0; iCountPtrs < pAtoms->number_of_ptrs; iCountPtrs++)
{
pfbThis = NULL;
pfbThis = (PFB) AtomFromMMDBIndex(pdnmsThis, (Int2) pdnmsThis->choice,
(Int2) pvnMol->data.intvalue,
(Int2) pvnRes->data.intvalue,
(Int4) pvnAtom->data.intvalue);
if (pfbThis)
{
pvnThis = ValNodeAddPointer(&pvnLocList,
0, (Nlm_VoidPtr) pfbThis);
}
pvnMol = pvnMol->next;
pvnRes = pvnRes->next;
pvnAtom = pvnAtom->next;
}
break;
case ChemGraphPntrs_residues:
prpsThis = (ResiduePntrsPtr) pcgpThis->data.ptrvalue;
if (!prpsThis) return NULL;
if (prpsThis->choice == ResiduePntrs_explicit)
{
prepThis = (ResidueExplicitPntrsPtr) prpsThis->data.ptrvalue;
pvnMol = prepThis->molecule_ids;
pvnRes = prepThis->residue_ids;
while (pvnRes)
{
pfbThis = NULL;
pfbThis = (PFB) GraphFromMMDBIndex(pdnmsThis, (Int2) pdnmsThis->choice,
(Int2) pvnMol->data.intvalue, (Int2) pvnRes->data.intvalue);
if (pfbThis)
{
pvnThis = ValNodeAddPointer(&pvnLocList,
0, (Nlm_VoidPtr) pfbThis);
}
else return NULL;
pvnMol = pvnMol->next;
pvnRes = pvnRes->next;
}
} /* explicit */
if (prpsThis->choice == ResiduePntrs_interval)
{
pripThis = (ResidueIntervalPntrPtr) prpsThis->data.ptrvalue;
while (pripThis)
{
iStart = pripThis->from;
iEnd = pripThis->to;
if (iStart > pripThis->to)
{
iStart = pripThis->to;
iEnd = pripThis->from;
}
for (;iStart <= iEnd; iStart++)
{
pfbThis = NULL;
pfbThis = (PFB) GraphFromMMDBIndex(pdnmsThis, (Int2) pdnmsThis->choice,
(Int2) pripThis->molecule_id, (Int2) iStart);
if (pfbThis)
{
pvnThis = ValNodeAddPointer(&pvnLocList,
0, (Nlm_VoidPtr) pfbThis);
}
else return NULL;
}
pripThis = pripThis->next;
} /* while pripThis */
} /* interval */
break;
case ChemGraphPntrs_molecules:
pMolecules = (MoleculePntrsPtr) pcgpThis->data.ptrvalue;
if (!pMolecules) return NULL;
pvnMol = pMolecules->molecule_ids;
if (pMolecules->number_of_ptrs == 0) return NULL;
for (iCountPtrs = 0; iCountPtrs < pMolecules->number_of_ptrs; iCountPtrs++)
{
pfbThis = NULL;
pfbThis = (PFB) MolFromMMDBIndex(pdnmsThis, (Int2) pdnmsThis->choice,
(Int2) pvnMol->data.intvalue);
if (pfbThis)
{
pvnThis = ValNodeAddPointer(&pvnLocList,
0, (Nlm_VoidPtr) pfbThis);
}
pvnMol = pvnMol->next;
}
break;
default: return NULL;
}
} /* if pcgpThis && pmsdThis*/
return pvnLocList;
}
Int2 SortOn=0;
PDNTRN LIBCALL NewDNTRN(PDNTRN PNTR ppdntrnList, Int2 choice)
{
PDNTRN pdntrnNew = NULL;
FloatLoPtr pflvNew = NULL;
FloatLoPtrPtr ppflmNew = NULL;
if (!choice) return NULL;
if ((int) choice == Move_translate)
{
pflvNew = FLVector(0, 2);
if (!pflvNew) return NULL;
pdntrnNew = DValNodeAddPointer(ppdntrnList, choice, (Nlm_VoidPtr) pflvNew);
}
if ((int) choice == Move_rotate)
{
ppflmNew = FLMatrix(0, 2, 0, 2);
if (!ppflmNew) return NULL;
pdntrnNew = DValNodeAddPointer(ppdntrnList, choice, (Nlm_VoidPtr) ppflmNew);
}
return pdntrnNew;
}
void LIBCALL FreeDNTRN(PDNTRN pdntrnList)
{
PDNTRN pdntrnThis;
PDNTRN pdntrnNext;
FloatLoPtr pflv = NULL;
FloatLoPtrPtr ppflm = NULL;
pdntrnThis = pdntrnList;
while(pdntrnThis)
{
pdntrnNext = pdntrnThis->next;
switch(pdntrnThis->choice)
{
case Move_rotate:
ppflm = (FloatLoPtrPtr) pdntrnThis->data.ptrvalue;
FLMatrixFree(ppflm, 0, 0);
break;
case Move_translate:
pflv = (FloatLoPtr) pdntrnThis->data.ptrvalue;
FLVectorFree(pflv, 0);
break;
}
pdntrnThis->next = NULL;
DValNodeFree(pdntrnThis);
pdntrnThis = pdntrnNext;
}
}
void LIBCALL TransformToDNTRN(PDNTRN PNTR pplist, TransformPtr transform)
{
PDNTRN pdntrnThis = NULL;
PDNTRN pdntrnFirst = NULL;
MovePtr pm = NULL;
RotMatrixPtr prm = NULL;
TransMatrixPtr ptm = NULL;
FloatLoPtr pflv = NULL;
FloatLoPtrPtr ppflm = NULL;
if (!transform) return;
pm = transform->moves;
while (pm)
{
pdntrnThis = NewDNTRN(pplist, (Int2) pm->choice);
if (!pdntrnThis) return ;
if (!pdntrnFirst) pdntrnFirst = pdntrnThis;
if ((int) pm->choice == Move_rotate)
{ /* copy * scale from RotMatrix */
ppflm = (FloatLoPtrPtr) pdntrnThis->data.ptrvalue;
prm = (RotMatrixPtr) pm->data.ptrvalue;
ppflm[0][0] = (FloatLo) ((FloatLo)prm->rot_11 / prm->scale_factor);
ppflm[0][1] = (FloatLo) ((FloatLo)prm->rot_12 / prm->scale_factor);
ppflm[0][2] = (FloatLo) ((FloatLo)prm->rot_13 / prm->scale_factor);
ppflm[1][0] = (FloatLo) ((FloatLo)prm->rot_21 / prm->scale_factor);
ppflm[1][1] = (FloatLo) ((FloatLo)prm->rot_22 / prm->scale_factor);
ppflm[1][2] = (FloatLo) ((FloatLo)prm->rot_23 / prm->scale_factor);
ppflm[2][0] = (FloatLo) ((FloatLo)prm->rot_31 / prm->scale_factor);
ppflm[2][1] = (FloatLo) ((FloatLo)prm->rot_32 / prm->scale_factor);
ppflm[2][2] = (FloatLo) ((FloatLo)prm->rot_33 / prm->scale_factor);
}
if ((int) pm->choice == Move_translate)
{
pflv = (FloatLoPtr) pdntrnThis->data.ptrvalue;
ptm = (TransMatrixPtr) pm->data.ptrvalue;
pflv[0] = (FloatLo) ((FloatLo)ptm->tran_1 / ptm->scale_factor);
pflv[1] = (FloatLo) ((FloatLo)ptm->tran_2 / ptm->scale_factor);
pflv[2] = (FloatLo) ((FloatLo)ptm->tran_3 / ptm->scale_factor);
}
pm = pm->next;
}
}
void LIBCALLBACK DoApplyTransform(PFB pfbThis, Int4 iModel, Int4 iIndex, Pointer ptr)
{
PMAD pmadAtom = NULL;
PMOD pmodThis = NULL;
PALD paldLoc = NULL;
PMSD pmsdThis = NULL;
PDNTRN pdntrnThis = NULL;
FloatLoPtr pflv = NULL;
FloatLoPtr pflvData = NULL;
FloatLoPtrPtr ppflmData = NULL;
FloatLoPtrPtr ppflm = NULL;
FloatLo flX, flY, flZ;
Int2 i, j;
if (!ptr) return;
if (IsAtomNode(pfbThis))
{
pmadAtom = (PMAD) pfbThis;
paldLoc = GetAtomLocs(pmadAtom, iModel);
pmsdThis = (PMSD) ptr;
/* go through each location for this particular atom and model */
while (paldLoc)
{
pdntrnThis = (PDNTRN) ptr; /* reset to head of transformations */
pflvData = paldLoc->pflvData;
while (pdntrnThis)
{
if (pdntrnThis->choice == Move_translate)
{
pflv = (FloatLoPtr) pdntrnThis->data.ptrvalue;
pflvData[0] = pflvData[0] + pflv[0];
pflvData[1] = pflvData[1] + pflv[1];
pflvData[2] = pflvData[2] + pflv[2];
}
if (pdntrnThis->choice == Move_rotate)
{
ppflm = (FloatLoPtrPtr) pdntrnThis->data.ptrvalue;
flX =(pflvData[0] * ppflm[0][0] +
pflvData[1] * ppflm[1][0] +
pflvData[2] * ppflm[2][0]);
flY =(pflvData[0] * ppflm[0][1] +
pflvData[1] * ppflm[1][1] +
pflvData[2] * ppflm[2][1]);
flZ = (pflvData[0] * ppflm[0][2] +
pflvData[1]* ppflm[1][2] +
pflvData[2] * ppflm[2][2]);
pflvData[0] = flX;
pflvData[1] = flY;
pflvData[2] = flZ;
}
pdntrnThis = pdntrnThis->next; /* get next transform */
}
paldLoc = paldLoc->next; /* get next location */
} /* while paldLoc */
} /* if IsAtomNode */
if (IsObjectNode(pfbThis))
{
/* deal with the objects too */
pmodThis = (PMOD) pfbThis;
pdntrnThis = (PDNTRN) ptr; /* reset to head of transformations */
ppflmData = pmodThis->ppflObject;
while (pdntrnThis)
{
switch (pmodThis->bWhat)
{
case OBJ_CYLINDER:
i = 2;
break;
case OBJ_BRICK:
i = 8;
break;
default: i=0;
}
if (pdntrnThis->choice == Move_translate)
{
pflv = (FloatLoPtr) pdntrnThis->data.ptrvalue;
for (j = 0; j<i; j++)
{
pflvData = ppflmData[j];
pflvData[0] = pflvData[0] + pflv[0];
pflvData[1] = pflvData[1] + pflv[1];
pflvData[2] = pflvData[2] + pflv[2];
}
}
if (pdntrnThis->choice == Move_rotate)
{
ppflm = (FloatLoPtrPtr) pdntrnThis->data.ptrvalue;
for (j = 0; j<i; j++)
{
flX =(ppflmData[j][0] * ppflm[0][0] +
ppflmData[j][1] * ppflm[1][0] +
ppflmData[j][2] * ppflm[2][0]);
flY =(ppflmData[j][0] * ppflm[0][1] +
ppflmData[j][1] * ppflm[1][1] +
ppflmData[j][2] * ppflm[2][1]);
flZ = (ppflmData[j][0] * ppflm[0][2] +
ppflmData[j][1]* ppflm[1][2] +
ppflmData[j][2] * ppflm[2][2]);
ppflmData[j][0] = flX;
ppflmData[j][1] = flY;
ppflmData[j][2] = flZ;
}
}
pdntrnThis = pdntrnThis->next; /* get next transform */
} /* while pdntrnThis */
} /* if IsObjectNode */
}
static void TransformMultiply(FloatLoPtr pflvData, FloatLoPtrPtr ppflm)
{
Nlm_Matrix Matrix, Vector, Result, Invert;
Nlm_Uint4 m, n; /* matrix indices */
Matrix = Nlm_MatrixNew(3, 3);
if (!Matrix) return;
Vector = Nlm_MatrixNew(1, 3);
if (!Vector) return;
for(m = 0; m < 3; m++) {
for(n = 0; n < 3; n++) {
Nlm_MatrixSetNode(Matrix, m, n, (Nlm_FloatHi) ppflm[m][n]);
}
}
for(m = 0; m < 3; m++) Nlm_MatrixSetNode(Vector, 0, m, (Nlm_FloatHi) pflvData[m]);
Invert = Nlm_MatrixInvert(Matrix);
Result = Nlm_MatrixMultiply(Vector, Invert);
for(m = 0; m < 3; m++) pflvData[m] = (Nlm_FloatLo) Nlm_MatrixNode(Result, 0, m);
Nlm_MatrixDelete(Matrix);
Nlm_MatrixDelete(Vector);
Nlm_MatrixDelete(Result);
Nlm_MatrixDelete(Invert);
}
void LIBCALLBACK DoReverseTransform(PFB pfbThis, Int4 iModel, Int4 iIndex, Pointer ptr)
{
PMAD pmadAtom = NULL;
PMOD pmodThis = NULL;
PALD paldLoc = NULL;
PMSD pmsdThis = NULL;
PDNTRN pdntrnThis = NULL;
FloatLoPtr pflv = NULL;
FloatLoPtr pflvData = NULL;
FloatLoPtrPtr ppflmData = NULL;
FloatLoPtrPtr ppflm = NULL;
/* FloatLo flX, flY, flZ; */
Int2 i, j;
if (IsAtomNode(pfbThis))
{
pmadAtom = (PMAD) pfbThis;
paldLoc = GetAtomLocs(pmadAtom, iModel);
pmsdThis = (PMSD) ptr;
/* go through each location for this particular atom and model */
while (paldLoc)
{
pdntrnThis = (PDNTRN) ptr; /* reset to head of transformations */
/* then go to the end */
while (pdntrnThis->next) pdntrnThis = pdntrnThis->next;
pflvData = paldLoc->pflvData;
while (pdntrnThis)
{
if (pdntrnThis->choice == Move_translate)
{
pflv = (FloatLoPtr) pdntrnThis->data.ptrvalue;
pflvData[0] = pflvData[0] - pflv[0];
pflvData[1] = pflvData[1] - pflv[1];
pflvData[2] = pflvData[2] - pflv[2];
}
if (pdntrnThis->choice == Move_rotate)
{
ppflm = (FloatLoPtrPtr) pdntrnThis->data.ptrvalue;
TransformMultiply(pflvData, ppflm);
/*
flX =(pflvData[0] * ppflm[0][0] +
pflvData[1] * ppflm[1][0] +
pflvData[2] * ppflm[2][0]);
flY =(pflvData[0] * ppflm[0][1] +
pflvData[1] * ppflm[1][1] +
pflvData[2] * ppflm[2][1]);
flZ = (pflvData[0] * ppflm[0][2] +
pflvData[1]* ppflm[1][2] +
pflvData[2] * ppflm[2][2]);
pflvData[0] = flX;
pflvData[1] = flY;
pflvData[2] = flZ;
*/
}
pdntrnThis = pdntrnThis->last; /* get previous transform */
}
paldLoc = paldLoc->next; /* get next location */
} /* while paldLoc */
} /* if IsAtomNode */
if (IsObjectNode(pfbThis))
{
/* deal with the objects too */
pmodThis = (PMOD) pfbThis;
pdntrnThis = (PDNTRN) ptr; /* reset to head of transformations */
/* then go to the end */
while (pdntrnThis->next) pdntrnThis = pdntrnThis->next;
ppflmData = pmodThis->ppflObject;
while (pdntrnThis)
{
switch (pmodThis->bWhat)
{
case OBJ_CYLINDER:
i = 2;
break;
case OBJ_BRICK:
i = 8;
break;
default: i=0;
}
if (pdntrnThis->choice == Move_translate)
{
pflv = (FloatLoPtr) pdntrnThis->data.ptrvalue;
for (j = 0; j<i; j++)
{
pflvData = ppflmData[j];
pflvData[0] = pflvData[0] - pflv[0];
pflvData[1] = pflvData[1] - pflv[1];
pflvData[2] = pflvData[2] - pflv[2];
}
}
if (pdntrnThis->choice == Move_rotate)
{
ppflm = (FloatLoPtrPtr) pdntrnThis->data.ptrvalue;
for (j = 0; j<i; j++)
{
TransformMultiply(ppflmData[j], ppflm);
/*
flX =(ppflmData[j][0] * ppflm[0][0] +
ppflmData[j][1] * ppflm[1][0] +
ppflmData[j][2] * ppflm[2][0]);
flY =(ppflmData[j][0] * ppflm[0][1] +
ppflmData[j][1] * ppflm[1][1] +
ppflmData[j][2] * ppflm[2][1]);
flZ = (ppflmData[j][0] * ppflm[0][2] +
ppflmData[j][1]* ppflm[1][2] +
ppflmData[j][2] * ppflm[2][2]);
ppflmData[j][0] = flX;
ppflmData[j][1] = flY;
ppflmData[j][2] = flZ;
*/
}
}
pdntrnThis = pdntrnThis->last; /* get next transform */
} /* while pdntrnThis */
} /* if IsObjectNode */
}
PDNMS LIBCALL FindLoadedBiostruc(CharPtr pcPDBID, Int4 iId)
{
/* replace this with caching mechanism */
PDNMS pdnmsThis = NULL;
PMSD pmsdThis = NULL;
if ((pcPDBID == NULL) && (iId == 0)) return NULL;
pdnmsThis = GetFirstModelstruc( );
while (pdnmsThis)
{
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
if (pmsdThis->iMMDBid == iId) return pdnmsThis;
if (!(StringCmp(pcPDBID,pmsdThis->pcPDBName))) return pdnmsThis;
pdnmsThis = pdnmsThis->next;
}
return NULL;
}
Boolean InstBSAnnotSet(BiostrucAnnotSetPtr pbsasThis, CharPtr JobID,
Boolean Chain, CharPtr Path) {
Int2 iTest;
Int4 iMMDBId;
PDNMS pdnmsThis = NULL;
PMSD pmsdThis = NULL;
BiostrucPtr pbsThis = NULL, pbsTemp = NULL;
BiostrucIdPtr pbsidThis = NULL;
BiostrucFeatureSetPtr pbsfsThis = NULL;
BiostrucFeaturePtr pbsfThis = NULL;
PSFS psfsThis = NULL;
CharPtr szTemp; /* NEW - K.A. 5/4/99 for pruning master/slave */
Char szName[5];
Char AsnPath[PATH_MAX];
Char AsnName[10];
Char MasterChain[2];
Char SlaveChain[2];
/* the Feature set either attaches to an in-memory Modelstruc */
/* or, if it specifies a new Modelstruc - attempts a retrieval */
if (pbsasThis == NULL) return FALSE;
MasterChain[0] = '\0';
SlaveChain[0] = '\0';
/* grab the id out of the Biostruc-descr */
pbsidThis = ValNodeFindNext(pbsasThis->id,NULL,BiostrucId_mmdb_id);
if (pbsidThis) /* only deal with the first one */
{
iMMDBId = (Int4) pbsidThis->data.intvalue;
/*printf("iMMDBID=%ld\n", iMMDBId);*//*master MMDB_ID*/
}
pdnmsThis = FindLoadedBiostruc(NULL, iMMDBId);
if (!pdnmsThis) {
szTemp = pbsasThis->features->features->name;
szName[0] = szTemp[0];
szName[1] = szTemp[1];
szName[2] = szTemp[2];
szName[3] = szTemp[3];
szName[4] = '\0';
/* try to load it using all NCBI models */
/* JobID points to dir containing biostruc of a query protein from VAST Search */
/* First get the structure using MMDBBiostrucGet or FetchBS, then prune if needed */
if (JobID == NULL)
pbsThis = MMDBBiostrucGet(iMMDBId, ALLSIMPLEMDL, 3);
else {
AsnName[0]='\0';
StringCpy(AsnName, "/b");
StringCat(AsnName, szName);
AsnPath[0]='\0';
StringCpy(AsnPath, Path);
StringCat(AsnPath, JobID);
StringCat(AsnPath, AsnName);
pbsThis = FetchBS(AsnPath, 0, ALLSIMPLEMDL, 3, POWER_VIEW);
}
if (Chain) {
if (szTemp[4] != ' ') {
MasterChain[0] = szTemp[4];
MasterChain[1] = '\0';
pbsTemp = (BiostrucPtr)PruneBiostruc(pbsThis, MasterChain);
pbsThis = NULL;
pbsThis = pbsTemp;
}
SlaveChain[0] = szTemp[11];
SlaveChain[1] = '\0';
}
if (!pbsThis) goto nogomem;
pdnmsThis = MakeAModelstruc(pbsThis);
/* side effect is that this is now the selected modelstruc too */
if (!pdnmsThis) goto nogomem;
}
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
/****** WARNING: fix this if this code is ever used to recognize Neighbor mode *********/
SetSelectedModelstruc(pdnmsThis); /* set it to selected one */
/* at this point we have annot-set, and its associated Modelstruc */
pbsfsThis = pbsasThis->features;
while (pbsfsThis) /* walk through each feature-set */
{
iTest = BiostrucAddFeature(pbsfsThis,pdnmsThis, Chain, SlaveChain); /* new slave args passed */
if (iTest < 0) goto nogomem; /* a malloc error */
if (!iTest) goto nogo; /* bad feature table error - fatal */
pbsfsThis = pbsfsThis->next;
}
/* given a sucessfully registered Biostruc-annot-set
we can now free it */
BiostrucAnnotSetFree(pbsasThis);
return TRUE;
nogomem:
nogo:
BiostrucAnnotSetFree(pbsasThis);
return FALSE;
}
/************************************************************
produce a sequence alignment from a structure-alignment
:)bug fixed: need two loops to go through master and slave selection with
BiostrucAnnotSetPtr->features (master selection), and
BiostrucAnnotSetPtr->features->features (slave selection)
in order to pick both master and slave with defination
of molecule name, chain, and domain
***********************************************************/
SeqAnnotPtr LIBCALL BiosToSeq (BiostrucAnnotSetPtr set, Boolean usePValue,
Char* pdbname_master, Char* pdbname_slave)
{
BiostrucFeatureSetPtr pbsfs=NULL;
BiostrucFeaturePtr pbsf=NULL;
SeqAnnotPtr sap = NULL;
SeqAlignPtr salp;
ScorePtr scp;
Int2 count;
ObjectIdPtr oid;
DenseSegPtr dsp;
SeqIdPtr mastersip = NULL, slavesip;
SeqIdPtr pdbsip = NULL;
BiostrucFeaturePtr feature;
ChemGraphAlignmentPtr pcga1 = NULL;
ValNodePtr loc1 = NULL;
ValNodePtr vnp = NULL;
SeqAlignPtr tail = NULL;
ChemGraphPntrsPtr cgpp;
ResidueIntervalPntrPtr master;
ResidueIntervalPntrPtr slave;
ResidueIntervalPntrPtr masterseg;
ResidueIntervalPntrPtr slaveseg;
CharPtr pcPDB;
int iDomain;
ValNodePtr pvn;
Char cChain;
Char buf[100];
Char buf2[50];
Int4 nextmasterstart, nextslavestart;
if (set == NULL || set->features == NULL || set->features->features == NULL)
return NULL;
pbsfs=set->features;
while(pbsfs)
{
feature=pbsfs->features;
/*if master name matched*/
if(strcmp((CharPtr)(pbsfs->descr->data.ptrvalue), pdbname_master) == 0)
{
while(feature)
{
/* construct the master SeqId if it hasn't already been constructed */
if (mastersip == NULL) {
pcPDB = StringSave (PDBNAME_DEFAULT);
iDomain = 0;
cChain = ' ';
pcPDB[0] = feature->name[0];
pcPDB[1] = feature->name[1];
pcPDB[2] = feature->name[2];
pcPDB[3] = feature->name[3];
cChain = feature->name[4];
iDomain = atoi ((char *) &feature->name[5]);
mastersip = MakePDBSeqId2 (pcPDB, cChain, iDomain, TRUE);
pdbsip = MakePDBSeqId2 (pcPDB, cChain, iDomain, FALSE);
MemFree (pcPDB);
}
/* get the embedded PDB code of the hit */
pcPDB = StringSave (PDBNAME_DEFAULT);
iDomain = 0;
cChain = '-';
if (StringLen (feature->name) >= 13) {
pcPDB[0] = feature->name[7];
pcPDB[1] = feature->name[8];
pcPDB[2] = feature->name[9];
pcPDB[3] = feature->name[10];
cChain = feature->name[11];
iDomain = atoi ((char *) &feature->name[12]);
slavesip = MakePDBSeqId2 (pcPDB, cChain, iDomain, TRUE);
MemFree (pcPDB);
}
pcPDB[4] = feature->name[11];
pcPDB[5] = feature->name[12];
pcPDB[6]='\0';
if (strcmp(pcPDB, pdbname_slave) == 0)
{
pvn = ValNodeFindNext (feature->Location_location, NULL, Location_location_alignment);
if (pvn)
pcga1 = (ChemGraphAlignmentPtr) pvn->data.ptrvalue;
vnp = pcga1->alignment;
if (vnp->choice != ChemGraphPntrs_residues)
continue;
cgpp = (ChemGraphPntrsPtr) vnp->data.ptrvalue;
if (cgpp->choice != ResiduePntrs_interval)
continue;
master = (ResidueIntervalPntrPtr) cgpp->data.ptrvalue;
cgpp = (ChemGraphPntrsPtr) vnp->next->data.ptrvalue;
slave = (ResidueIntervalPntrPtr) cgpp->data.ptrvalue;
for (nextmasterstart = 1, nextslavestart = 1, count = 0, masterseg = master,
slaveseg = slave; masterseg != NULL && slaveseg != NULL; masterseg = masterseg->next,
slaveseg = slaveseg->next) {
if (count > 0 && nextmasterstart < masterseg->from)
count++;
if (count > 0 && nextslavestart < slaveseg->from)
count++;
count++;
nextmasterstart = masterseg->to + 1;
nextslavestart = slaveseg->to + 1;
}
salp = SeqAlignNew ();
if (sap == NULL) {
sap = SeqAnnotNew ();
sap->type = 2; /* align */
sap->data = salp;
sap->desc = ValNodeNew(NULL);
sap->desc->choice = 2; /* title */
SeqIdWrite (pdbsip, buf2, PRINTID_FASTA_LONG, sizeof(buf2));
sprintf (buf, "VAST structural alignment for %s, mapped to sequence alignment", buf2);
sap->desc->data.ptrvalue = StringSave(buf);
} else {
tail->next = salp;
}
tail = salp;
salp->type = 3 /* partial */ ;
salp->dim = 2;
scp = ScoreNew ();
salp->score = scp;
salp->segtype = 2 /* denseg */ ;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->vast_score) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST score");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->vast_mlogp) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST p-value");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->rmsd) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST root mean square deviation, measured in angstroms");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 1; /* int */
scp->value.intvalue = pcga1->aligndata->align_res;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST aligned residue count");
dsp = DenseSegNew ();
salp->segs = (Pointer) dsp;
dsp->dim = 2;
dsp->numseg = count;
dsp->ids = SeqIdDup (mastersip);
dsp->ids->next = slavesip;
dsp->starts = (Int4Ptr) MemNew (count * sizeof (Int4) * 2);
dsp->lens = (Int4Ptr) MemNew (count * sizeof (Int4));
for (nextmasterstart = 1, nextslavestart = 1, count = 0, masterseg = master, slaveseg = slave; masterseg != NULL && slaveseg != NULL; masterseg = masterseg->next, slaveseg = slaveseg->next) {
if (count > 0 && nextmasterstart < masterseg->from)
{ /* add a gap */
dsp->starts[count * 2] = nextmasterstart - 1;
dsp->starts[count * 2 + 1] = -1;
dsp->lens[count] = masterseg->from - nextmasterstart;
count++;
}
if (count > 0 && nextslavestart < slaveseg->from)
{ /* add a gap */
dsp->starts[count * 2 + 1] = nextslavestart - 1;
dsp->starts[count * 2] = -1;
dsp->lens[count] = slaveseg->from - nextslavestart;
count++;
}
dsp->starts[count * 2] = masterseg->from-1;
dsp->starts[count * 2 + 1] = slaveseg->from-1;
dsp->lens[count] = masterseg->to - masterseg->from + 1;
count++;
nextmasterstart = masterseg->to + 1;
nextslavestart = slaveseg->to + 1;
}
} /*if pdbname matched*/
feature=feature->next;
}/*while feature (pbsf)*/
}/*if pcMaster matches pdbname_master*/
pbsfs=pbsfs->next;
}/*while pbsfs*/
SeqIdFree (mastersip);
SeqIdFree (pdbsip);
return sap;
}
SeqAnnotPtr LIBCALL fnPBSFtoPSA (BiostrucFeaturePtr pbsfSelected)
{
SeqAnnotPtr sap = NULL;
SeqAlignPtr salp;
ScorePtr scp;
Int2 count;
ObjectIdPtr oid;
DenseSegPtr dsp;
ValNodePtr loc1 = NULL;
SeqAlignPtr tail = NULL;
ChemGraphPntrsPtr cgpp;
ResidueIntervalPntrPtr master;
ResidueIntervalPntrPtr slave;
ResidueIntervalPntrPtr masterseg;
ResidueIntervalPntrPtr slaveseg;
Char buf[100];
Char buf2[50];
Int4 nextmasterstart, nextslavestart;
SeqIdPtr mastersip = NULL, slavesip;
SeqIdPtr pdbsip = NULL;
int iDomain;
CharPtr pcPDB;
Char cChain;
ValNodePtr pvnAlignment;
ChemGraphAlignmentPtr pcga1;
Boolean choose_densediag = TRUE;
pvnAlignment = ValNodeFindNext(pbsfSelected->Location_location,NULL,
Location_location_alignment);
pcga1 = (ChemGraphAlignmentPtr) pvnAlignment->data.ptrvalue;
if (pcga1->alignment->choice != ChemGraphPntrs_residues)
return NULL;
cgpp = (ChemGraphPntrsPtr) pcga1->alignment->data.ptrvalue;
pcPDB = StringSave (PDBNAME_DEFAULT);
iDomain = 0;
cChain = '-';
pcPDB[0] = pbsfSelected->name[0];
pcPDB[1] = pbsfSelected->name[1];
pcPDB[2] = pbsfSelected->name[2];
pcPDB[3] = pbsfSelected->name[3];
cChain = pbsfSelected->name[4];
iDomain = atoi ((char *) &pbsfSelected->name[5]);
/*mastersip = MakePDBSeqId2 (pcPDB, cChain, iDomain, TRUE); */
mastersip = MakePDBSeqId2 (pcPDB, cChain, iDomain, FALSE);
pdbsip = MakePDBSeqId2 (pcPDB, cChain, iDomain, FALSE);
MemFree (pcPDB);
/* get the embedded PDB code of the hit */
if (iDomain < 10) {
pcPDB = StringSave (PDBNAME_DEFAULT);
iDomain = 0;
cChain = '-';
pcPDB[0] = pbsfSelected->name[7];
pcPDB[1] = pbsfSelected->name[8];
pcPDB[2] = pbsfSelected->name[9];
pcPDB[3] = pbsfSelected->name[10];
cChain = pbsfSelected->name[11];
iDomain = atoi ((char *) &pbsfSelected->name[12]);
}
else { /* have at least 10 domains in 1 str., added by J. Chen */
pcPDB = StringSave (PDBNAME_DEFAULT);
iDomain = 0;
cChain = '-';
pcPDB[0] = pbsfSelected->name[8];
pcPDB[1] = pbsfSelected->name[9];
pcPDB[2] = pbsfSelected->name[10];
pcPDB[3] = pbsfSelected->name[11];
cChain = pbsfSelected->name[12];
iDomain = atoi ((char *) &pbsfSelected->name[13]);
}
/*slavesip = MakePDBSeqId2 (pcPDB, cChain, iDomain, TRUE); */
slavesip = MakePDBSeqId2 (pcPDB, cChain, iDomain, FALSE);
MemFree (pcPDB);
if (cgpp->choice != ResiduePntrs_interval)
return NULL;
master = (ResidueIntervalPntrPtr) cgpp->data.ptrvalue;
cgpp = (ChemGraphPntrsPtr) pcga1->alignment->next->data.ptrvalue;
slave = (ResidueIntervalPntrPtr) cgpp->data.ptrvalue;
for (nextmasterstart = 1, nextslavestart = 1, count = 0, masterseg = master,
slaveseg = slave; masterseg != NULL && slaveseg != NULL; masterseg = masterseg->next,
slaveseg = slaveseg->next) {
if (count > 0 && nextmasterstart < masterseg->from)
count++;
if (count > 0 && nextslavestart < slaveseg->from)
count++;
count++;
nextmasterstart = masterseg->to + 1;
nextslavestart = slaveseg->to + 1;
}
salp = SeqAlignNew ();
if (sap == NULL) {
sap = SeqAnnotNew ();
sap->type = 2; /* align */
sap->data = salp;
sap->desc = ValNodeNew(NULL);
sap->desc->choice = 2; /* title */
SeqIdWrite (pdbsip, buf2, PRINTID_FASTA_LONG, sizeof(buf2));
sprintf (buf, "VAST structural alignment for %s, mapped to sequence alignment", buf2);
sap->desc->data.ptrvalue = StringSave(buf);
} else {
tail->next = salp;
}
tail = salp;
salp->type = 3 /* partial */ ;
salp->dim = 2;
scp = ScoreNew ();
salp->score = scp;
salp->segtype = 2 /* denseg */ ;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->vast_score) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST score");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->vast_mlogp) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST p-value");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->rmsd) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST root mean square deviation, measured in angstroms");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 1; /* int */
scp->value.intvalue = pcga1->aligndata->align_res;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST aligned residue count");
if(!choose_densediag){
dsp = DenseSegNew ();
salp->segs = (Pointer) dsp;
dsp->dim = 2;
dsp->numseg = count;
dsp->ids = SeqIdDup (mastersip);
/* dsp->ids->next = slavesip; could be a bug, J. Chen */
dsp->ids->next = SeqIdDup(slavesip);
dsp->starts = (Int4Ptr) MemNew (count * sizeof (Int4) * 2);
dsp->lens = (Int4Ptr) MemNew (count * sizeof (Int4));
for (nextmasterstart = 1, nextslavestart = 1, count = 0, masterseg = master, slaveseg = slave; masterseg != NULL && slaveseg != NULL; masterseg = masterseg->next, slaveseg = slaveseg->next) {
if (count > 0 && nextmasterstart < masterseg->from)
{ /* add a gap */
dsp->starts[count * 2] = nextmasterstart - 1;
dsp->starts[count * 2 + 1] = -1;
dsp->lens[count] = masterseg->from - nextmasterstart;
count++;
}
if (count > 0 && nextslavestart < slaveseg->from)
{ /* add a gap */
dsp->starts[count * 2 + 1] = nextslavestart - 1;
dsp->starts[count * 2] = -1;
dsp->lens[count] = slaveseg->from - nextslavestart;
count++;
}
dsp->starts[count * 2] = masterseg->from-1;
dsp->starts[count * 2 + 1] = slaveseg->from-1;
dsp->lens[count] = masterseg->to - masterseg->from + 1;
count++;
nextmasterstart = masterseg->to + 1;
nextslavestart = slaveseg->to + 1;
}
}
else {
DenseDiagPtr ddp, ddp_tmp;
salp->segs = NULL;
salp->type = 3;
salp->segtype = 1 /* densediag */ ;
for(count = 0, masterseg = master, slaveseg = slave; masterseg != NULL && slaveseg != NULL; masterseg = masterseg->next, slaveseg = slaveseg->next) {
ddp = DenseDiagNew();
ddp->dim = 2;
ddp->id = SeqIdDup (mastersip);
/* ddp->id->next = slavesip; bug! fixed by J.Chen */
ddp->id->next = SeqIdDup(slavesip);
ddp->starts = (Int4Ptr) MemNew ((size_t) 4 * sizeof (Int4));
ddp->starts[0] = masterseg->from-1;
ddp->starts[1] = slaveseg->from -1 ;
ddp->len = masterseg->to - masterseg->from + 1;
count++;
if(salp->segs == NULL) salp->segs = (Pointer) ddp;
else {
ddp_tmp = (DenseDiagPtr) salp->segs;
while(ddp_tmp->next) ddp_tmp = ddp_tmp->next;
ddp_tmp->next = ddp;
}
}
}
SeqIdFree (mastersip);
SeqIdFree (pdbsip);
slavesip->next = NULL;
return sap;
}
/************************************************************
Produce sequence annotation set of a master (name, chain, domain)
with all its slaves according to structure alignments.
************************************************************/
/* please don't use this function, use the function above */
SeqAnnotPtr LIBCALL BiostrToSeqAnnotSet (BiostrucAnnotSetPtr set,
Boolean usePValue, Char* pdbname_master)
{
BiostrucFeatureSetPtr pbsfs=NULL;
BiostrucFeaturePtr pbsf=NULL;
SeqAnnotPtr sap = NULL;
SeqAlignPtr salp;
ScorePtr scp;
Int2 count;
ObjectIdPtr oid;
DenseSegPtr dsp;
SeqIdPtr mastersip = NULL, slavesip;
SeqIdPtr pdbsip = NULL;
BiostrucFeaturePtr feature;
ChemGraphAlignmentPtr pcga1 = NULL;
ValNodePtr loc1 = NULL;
ValNodePtr vnp = NULL;
SeqAlignPtr tail = NULL;
ChemGraphPntrsPtr cgpp;
ResidueIntervalPntrPtr master;
ResidueIntervalPntrPtr slave;
ResidueIntervalPntrPtr masterseg;
ResidueIntervalPntrPtr slaveseg;
CharPtr pcPDB;
Char pcMaster[10]; /* fixed lyg */
int iDomain;
ValNodePtr pvn;
Char cChain;
Char buf[100];
Char buf2[50];
Int4 nextmasterstart, nextslavestart;
if (set == NULL || set->features == NULL || set->features->features == NULL)
return NULL;
pbsfs=set->features;
while(pbsfs)
{
feature=pbsfs->features;
strcpy(pcMaster, (char *)pbsfs->descr->data.ptrvalue);
/*if master name matched*/
if(strcmp(pcMaster, pdbname_master) == 0) /* I had this commented out */
{
while(feature)
{
/* construct the master SeqId if it hasn't already been constructed */
if (mastersip == NULL) {
pcPDB = StringSave (PDBNAME_DEFAULT);
iDomain = 0;
cChain = '-';
pcPDB[0] = feature->name[0];
pcPDB[1] = feature->name[1];
pcPDB[2] = feature->name[2];
pcPDB[3] = feature->name[3];
cChain = feature->name[4];
iDomain = atoi ((char *) &feature->name[5]);
mastersip = MakePDBSeqId2 (pcPDB, cChain, iDomain, TRUE);
pdbsip = MakePDBSeqId2 (pcPDB, cChain, iDomain, FALSE);
MemFree (pcPDB);
}
/* get the embedded PDB code of the hit */
pcPDB = StringSave (PDBNAME_DEFAULT);
iDomain = 0;
cChain = '-';
if (StringLen (feature->name) >= 13) {
pcPDB[0] = feature->name[7];
pcPDB[1] = feature->name[8];
pcPDB[2] = feature->name[9];
pcPDB[3] = feature->name[10];
cChain = feature->name[11];
iDomain = atoi ((char *) &feature->name[12]);
slavesip = MakePDBSeqId2 (pcPDB, cChain, iDomain, TRUE);
MemFree (pcPDB);
}
pcPDB[4] = feature->name[11];
pcPDB[5] = feature->name[12];
pcPDB[6]='\0';
pvn = ValNodeFindNext (feature->Location_location, NULL, Location_location_alignment);
if (pvn)
pcga1 = (ChemGraphAlignmentPtr) pvn->data.ptrvalue;
vnp = pcga1->alignment;
if (vnp->choice != ChemGraphPntrs_residues)
continue;
cgpp = (ChemGraphPntrsPtr) vnp->data.ptrvalue;
if (cgpp->choice != ResiduePntrs_interval)
continue;
master = (ResidueIntervalPntrPtr) cgpp->data.ptrvalue;
cgpp = (ChemGraphPntrsPtr) vnp->next->data.ptrvalue;
slave = (ResidueIntervalPntrPtr) cgpp->data.ptrvalue;
for (nextmasterstart = 1, nextslavestart = 1, count = 0, masterseg = master,
slaveseg = slave; masterseg != NULL && slaveseg != NULL; masterseg = masterseg->next,
slaveseg = slaveseg->next) {
if (count > 0 && nextmasterstart < masterseg->from)
count++;
if (count > 0 && nextslavestart < slaveseg->from)
count++;
count++;
nextmasterstart = masterseg->to + 1;
nextslavestart = slaveseg->to + 1;
}
salp = SeqAlignNew ();
if (sap == NULL) {
sap = SeqAnnotNew ();
sap->type = 2; /* align */
sap->data = salp;
sap->desc = ValNodeNew(NULL);
sap->desc->choice = 2; /* title */
SeqIdWrite (pdbsip, buf2, PRINTID_FASTA_LONG, sizeof(buf2));
buf2[10]=pdbname_master[5];
buf2[11]='\0';
sprintf (buf, "VAST structural alignment for %s, mapped to sequence alignment", buf2);
sap->desc->data.ptrvalue = StringSave(buf);
} else {
tail->next = salp;
}
tail = salp;
salp->type = 3 /* partial */ ;
salp->dim = 2;
scp = ScoreNew ();
salp->score = scp;
salp->segtype = 2 /* denseg */ ;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->vast_score) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST score");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->vast_mlogp) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST p-value");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 2; /* real */
scp->value.realvalue = ((FloatHi) pcga1->aligndata->rmsd) / pcga1->aligndata->scale_factor;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST root mean square deviation, measured in angstroms");
scp->next = ScoreNew ();
scp = scp->next;
scp->choice = 1; /* int */
scp->value.intvalue = pcga1->aligndata->align_res;
oid = ObjectIdNew ();
scp->id = oid;
oid->str = StringSave ("VAST aligned residue count");
dsp = DenseSegNew ();
salp->segs = (Pointer) dsp;
dsp->dim = 2;
dsp->numseg = count;
dsp->ids = SeqIdDup (mastersip);
dsp->ids->next = slavesip;
dsp->starts = (Int4Ptr) MemNew (count * sizeof (Int4) * 2);
dsp->lens = (Int4Ptr) MemNew (count * sizeof (Int4));
for (nextmasterstart = 1, nextslavestart = 1, count = 0, masterseg = master, slaveseg = slave; masterseg != NULL && slaveseg != NULL; masterseg = masterseg->next, slaveseg = slaveseg->next) {
if (count > 0 && nextmasterstart < masterseg->from)
{ /* add a gap */
dsp->starts[count * 2] = nextmasterstart - 1;
dsp->starts[count * 2 + 1] = -1;
dsp->lens[count] = masterseg->from - nextmasterstart;
count++;
}
if (count > 0 && nextslavestart < slaveseg->from)
{ /* add a gap */
dsp->starts[count * 2 + 1] = nextslavestart - 1;
dsp->starts[count * 2] = -1;
dsp->lens[count] = slaveseg->from - nextslavestart;
count++;
}
dsp->starts[count * 2] = masterseg->from-1;
dsp->starts[count * 2 + 1] = slaveseg->from-1;
dsp->lens[count] = masterseg->to - masterseg->from + 1;
count++;
nextmasterstart = masterseg->to + 1;
nextslavestart = slaveseg->to + 1;
}
feature=feature->next;
}/*while feature (pbsf)*/
}/*if pcMaster matches pdbname_master*/
pbsfs=pbsfs->next;
}/*while pbsfs*/
SeqIdFree (mastersip);
SeqIdFree (pdbsip);
return sap;
}
void LIBCALL ResolveAlignChain(PDNMS pdnmsThis)
{ /* moves the reserved byte value up to pmmd to indicate
chain is in alignment */
PMSD pmsdThis = NULL;
PDNMM pdnmmThis = NULL;
PMMD pmmdThis = NULL;
PDNMG pdnmgThis = NULL;
PMGD pmgdThis = NULL;
int i, j;
if (!pdnmsThis) return;
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
pdnmmThis = pmsdThis->pdnmmHead;
/*printf("iMMDBid=%ld, iModels=%i\n", pmsdThis->iMMDBid, pmsdThis->iModels);*/
i=1;
while (pdnmmThis)
{
pmmdThis = (PMMD) pdnmmThis->data.ptrvalue;
/*printf("I am at #358, pmmdThis->bReserved=%x\n", pmmdThis->bReserved);*/
pdnmgThis = pmmdThis->pdnmgHead;
j=1;
while(pdnmgThis)
{
/*printf("loop pdnmg=%i, loop pdnmm=%i\n", j, i);*/
pmgdThis = (PMGD) pdnmgThis->data.ptrvalue;
/* printf("I am at #360, %x\n", pmgdThis->bReserved);*/
if (pmgdThis->bReserved)
pmmdThis->bReserved = pmgdThis->bReserved;
/*I added the following two lines
pmmdThis->bReserved = 1;
pmgdThis->bReserved = 1;
*/
pdnmgThis = pdnmgThis->next;
j++;
}
pdnmmThis = pdnmmThis->next;
i++;
}
}
int LIBCALLBACK CompareScores(VoidPtr vp1, VoidPtr vp2)
{
BiostrucFeaturePtr pbf1, pbf2;
ChemGraphAlignmentPtr pcga1 = NULL;
ChemGraphAlignmentPtr pcga2 = NULL;
ValNodePtr loc1 = NULL;
ValNodePtr loc2 = NULL;
ValNodePtr vnp1, vnp2;
ValNodePtr PNTR vnpp1;
ValNodePtr PNTR vnpp2;
vnpp1 = (ValNodePtr PNTR) vp1;
vnpp2 = (ValNodePtr PNTR) vp2;
vnp1 = *vnpp1;
vnp2 = *vnpp2;
pbf1 = (BiostrucFeaturePtr) vnp1->data.ptrvalue;
pbf2 = (BiostrucFeaturePtr) vnp2->data.ptrvalue;
/* First, three cases that should not be, need to be checked for. */
if (pbf1 == NULL && pbf2 != NULL)
return -1;
if (pbf1 != NULL && pbf2 == NULL)
return 1;
if (pbf1 == NULL && pbf2 == NULL)
return 0;
/* get at the appropriate data element */
loc1 = pbf1->Location_location;
loc2 = pbf2->Location_location;
if ((loc1) && (loc1->choice == Location_location_alignment))
pcga1 = (ChemGraphAlignmentPtr) loc1->data.ptrvalue;
if ((loc2) && (loc2->choice == Location_location_alignment))
pcga2 = (ChemGraphAlignmentPtr) loc2->data.ptrvalue;
if (pcga1 == NULL && pcga2 != NULL)
return -1;
if (pcga1 != NULL && pcga2 == NULL)
return 1;
if (pcga1 == NULL && pcga2 == NULL)
return 0;
if (pcga1->aligndata == NULL && pcga2->aligndata != NULL)
return -1;
if (pcga1->aligndata != NULL && pcga2->aligndata == NULL)
return 1;
if (pcga1->aligndata == NULL && pcga2->aligndata == NULL)
return 0;
switch(SortOn)
{
case 0:
case 1: /* Score */
if (pcga1->aligndata->vast_score > pcga2->aligndata->vast_score)
return -1;
else if (pcga1->aligndata->vast_score < pcga2->aligndata->vast_score)
return 1;
else
return 0;
case 2: /* P value (inverse sorting) */
if (pcga1->aligndata->vast_mlogp > pcga2->aligndata->vast_mlogp)
return -1;
else if (pcga1->aligndata->vast_mlogp < pcga2->aligndata->vast_mlogp)
return 1;
else
return 0;
case 3: /* RMSD */
if (pcga1->aligndata->rmsd < pcga2->aligndata->rmsd)
return -1;
else if (pcga1->aligndata->rmsd > pcga2->aligndata->rmsd)
return 1;
else
return 0;
case 4: /* Aligned residues */
if (pcga1->aligndata->align_res > pcga2->aligndata->align_res)
return -1;
else if (pcga1->aligndata->align_res < pcga2->aligndata->align_res)
return 1;
else
return 0;
case 5: /* Identity */
if (pcga1->aligndata->other_score > pcga2->aligndata->other_score)
return -1;
else if (pcga1->aligndata->other_score < pcga2->aligndata->other_score)
return 1;
else
return 0;
default:
return 0;
}
}
void LIBCALL VastTableSort(BiostrucFeatureSetPtr pbsfs, Int2 iSort)
{
ValNodePtr pvnSort = NULL;
ValNodePtr pvnList = NULL;
BiostrucFeaturePtr pbsf = NULL;
BiostrucFeaturePtr pbsfThis = NULL;
if ((!pbsfs)) return;
pbsf = pbsfs->features;
while(pbsf)
{ /* chop out features into a ValNode list */
pvnSort = ValNodeAddPointer(&pvnList, 0, (VoidPtr) pbsf);
pbsfThis = pbsf;
pbsf = pbsf->next;
pbsfThis->next = NULL; /* detach feature */
}
SortOn = iSort;
VnpHeapSort(&pvnList, CompareScores);
/* reassemble in sorted order */
pbsfs->features = (BiostrucFeaturePtr) pvnList->data.ptrvalue;
pbsf = pbsfs->features;
pvnSort = pvnList->next;
while (pvnSort)
{
pbsf->next = (BiostrucFeaturePtr) pvnSort->data.ptrvalue;
pbsf = pbsf->next;
pvnSort = pvnSort->next;
}
ValNodeFree(pvnList);
return;
}
Boolean LIBCALL SetNodeFeatureData(PFB pfbThis, PSFD psfdThis)
{
Int4Ptr pI4vFeat = NULL;
PointerPtr ppvOld = NULL;
int iNum, i;
/* Broadcasts the feature into the node that maps to it.
* This sets the indicator in the PFB that there is a feature
* associated with it. The variable pI4vFeatID in the pfb is
* a vector of pairs of id's where the first id is the feature-set
* ordinal (not its true id), and the second id is the
* true feature-id.
*
* If there is ->pData associated with the node, that pointer
* is put into a parallel vector of pointers
* to the pairs of id's (feature-set, feature),
* ppFeatData. This should be NULL for every feature
* that has no associated data structures.
*
*/
if (!pfbThis) return FALSE;
if (!psfdThis) return FALSE;
iNum = (int) pfbThis->iNumFeats;
if ((pfbThis->pI4vFeatID) &&(iNum > 0))
pI4vFeat = pfbThis->pI4vFeatID;
pfbThis->pI4vFeatID = NULL;
pfbThis->pI4vFeatID = (Int4Ptr) MemNew((size_t) (iNum+1)*2*sizeof(Int4));
if (!pfbThis->pI4vFeatID)
{
pfbThis->pI4vFeatID = pI4vFeat;
return FALSE;
}
if (pI4vFeat)
{ /* copy other id's and destroy */
for (i = 0; i<(iNum*2); i++)
{
pfbThis->pI4vFeatID[i] = pI4vFeat[i];
}
MemFree(pI4vFeat);
}
pfbThis->pI4vFeatID[iNum*2] = (Int4) psfdThis->pdnsfsSet->choice;
pfbThis->pI4vFeatID[(iNum*2)+1] = psfdThis->iId;
if (psfdThis->pData)
{
if (pfbThis->ppvFeatData)
ppvOld = pfbThis->ppvFeatData;
pfbThis->ppvFeatData = NULL;
pfbThis->ppvFeatData = (PointerPtr) MemNew((size_t) (iNum+1)*sizeof(Pointer));
if (!pfbThis->ppvFeatData)
{
pfbThis->ppvFeatData = ppvOld;
return FALSE;
}
if (ppvOld)
{ /* copy other pointers, and free old vector */
for (i = 0; i < (iNum); i++)
pfbThis->ppvFeatData[i] = ppvOld[i];
MemFree(ppvOld);
}
/* assign the data pointer */
pfbThis->ppvFeatData[iNum] = psfdThis->pData;
}
pfbThis->iNumFeats++;
return TRUE;
}
ValNodePtr LIBCALL MakeRegionNodeList(PDNMS pdnmsThis, RegionPntrsPtr prgpThis)
{
/*
This traverses the ASN.1 RegionPntrs list and makes a list of PFB's
prgpThis->model_id;
ValNodeFindNext(prgpThis->region ... );
RegionCoordinates ... (model coord set, - does the lookup )
RegionBoundary... (sphere, cone, cylinder, brick - does the bounding calc
and returns entities within )
*/
return NULL;
}
void LIBCALL InstallAlignedSlave(PDNMS pdnmsMaster, ChemGraphAlignmentPtr pcgaAlign,
PSFD psfdThis, Boolean Chain, CharPtr SlaveChain) {
Int4 iId = 0;
BiostrucPtr pbsSlave = NULL, pbsTemp = NULL;
PDNMS pdnmsSlave = NULL;
PMSD pmsdSlave = NULL;
PFB pfbThis = NULL;
ValNodePtr pvnThis = NULL;
ValNodePtr pvnList = NULL;
ValNodePtr pvnLoc = NULL;
BiostrucIdPtr pbsidThis = NULL;
ChemGraphPntrsPtr pcgpThis = NULL;
PSFS psfsThis = NULL;
Pointer ptr = NULL;
Boolean bTest;
Int2 iTest;
#ifdef _DEBUG_9
printf("in InstallAlignedSlave \n");
#endif
if (!pcgaAlign) return;
if (!pdnmsMaster) return;
SetSlaveModelstruc(NULL);
SetSelectedModelstruc(pdnmsMaster);
SetNeighborOn(); /* sets master to selected */
/* sets slave to first on master's list if slave is null */
if (pcgaAlign->dimension != 2) return;
#ifdef _DEBUG_9
printf("still in InstallAlignedSlave \n");
#endif
/* the second id is the slave */
pbsidThis = ValNodeFindNext(pcgaAlign->biostruc_ids,NULL,BiostrucId_mmdb_id);
if (pbsidThis)
{
pbsidThis = ValNodeFindNext(pcgaAlign->biostruc_ids,pbsidThis,BiostrucId_mmdb_id);
if (pbsidThis) iId = (Int4) pbsidThis->data.intvalue;
}
if (iId == 0)
{
#ifdef _DEBUG_9
printf("Biostruc Slave Fetch failed %d \n", (int) iId);
#endif
return;
}
pbsSlave = MMDBBiostrucGet(iId, ALLSIMPLEMDL, 3);
/*****************************************************************************/
/* This is code added by KA so that we only have to call one MMDBBiostrucGet */
/*****************************************************************************/
if (Chain == TRUE) {
if (SlaveChain[0] != ' ') {
pbsTemp = (BiostrucPtr)PruneBiostruc(pbsSlave, SlaveChain);
pbsSlave = NULL;
pbsSlave = pbsTemp;
}
}
/*****************************************************************************/
if (!pbsSlave) {
SetNeighborOff();
#ifdef _DEBUG_9
printf("Biostruc Slave Fetch failed %d \n", (int) iId);
#endif
return; }
else
{
#ifdef _DEBUG_9
printf("Biostruc Slave Fetched! %d \n", (int) iId);
#endif
}
pdnmsSlave = MakeAModelstruc(pbsSlave);
/* hangs off of master and sets slave and sets selected=master */
SetNeighborOff();
/* resets selected to master only */
if (!pdnmsSlave) {
#ifdef _DEBUG_9
printf("Biostruc Slave Convert failed %d \n", (int) iId);
#endif
return;
}
SetSlaveModelstruc(pdnmsSlave); /* defaults *on* next time SetNeighborOn called */
/* get the master data - > apply alignment CGP to master structure */
/* using SetNodeFeatureData */
pvnThis = NULL;
pvnThis = pcgaAlign->alignment;
if (pvnThis)
{
/********TEMPORARY******/
pcgpThis = ( ChemGraphPntrsPtr ) pvnThis;
pvnList = MakeChemGraphNodeList(pdnmsMaster, pcgpThis);
if (!pvnList) {
#ifdef _DEBUG_9
printf("Master MakeChemGraphNodeList failed \n");
#endif
return; }
pvnLoc = pvnList;
while (pvnLoc)
{
pfbThis = (PFB) pvnLoc->data.ptrvalue;
pfbThis->bReserved++;
pvnLoc = pvnLoc->next;
} /* while pvnLoc */
ValNodeFree(pvnList);
pvnList = NULL;
pcgpThis = ( ChemGraphPntrsPtr ) pvnThis->next;
pvnList = MakeChemGraphNodeList(pdnmsSlave, pcgpThis);
if (!pvnList) {
#ifdef _DEBUG_9
printf("Master MakeChemGraphNodeList failed \n");
#endif
return; }
pvnLoc = pvnList;
while (pvnLoc)
{
pfbThis = (PFB) pvnLoc->data.ptrvalue;
/* register feature in each location */
bTest = SetNodeFeatureData( pfbThis, psfdThis);
psfdThis->bPFBtype = (psfdThis->bPFBtype | pfbThis->bMe);
/********TEMPORARY******/
pfbThis->bReserved++;
if (bTest == FALSE) {
#ifdef _DEBUG_9
printf("Master SetNodeFeatureData failed \n");
#endif
return; }
pvnLoc = pvnLoc->next;
} /* while pvnLoc */
ValNodeFree(pvnList);
pvnList = NULL;
} /* if pvnThis */
TransformToDNTRN((PDNTRN PNTR) &ptr, pcgaAlign->transform );
/* apply the transform to the slave */
iTest = TraverseModels( pdnmsSlave,
TRAVERSE_ATOM,
0, ptr,
(pNodeFunc)(DoApplyTransform));
iTest = TraverseModels( pdnmsSlave,
TRAVERSE_SOLID,
0, ptr,
(pNodeFunc)(DoApplyTransform));
#ifdef _DEBUG_9
printf("Transformed Models \n");
#endif
/* free the transform data */
FreeDNTRN((PDNTRN) ptr);
/* set dirty bit */
pmsdSlave = (PMSD) pdnmsSlave->data.ptrvalue;
pmsdSlave->bUpdate = (Byte) (pmsdSlave->bUpdate | (Byte) AM_CHANGED);
/* enforce an MMDB-ID change */
pmsdSlave->iHashChange = MakeHashChange(pdnmsSlave);
/* Do nothing with the domain data... */
/* that's all folks, now just use SetNeighborOn()... */
/* selected = master after this is through */
return;
}
PSFD LIBCALL InstallStrucFeature(PDNMS pdnmsThis, PDNSFS pdnsfsThis, BiostrucFeaturePtr pbsfThis,
Boolean Chain, CharPtr SlaveChain)
{
/* This procedure adds a new Feature to the Feature-Set registry
* specified. If there is "global" data to be kept (e.g. color,
* render, transform values, camera values, label values
*/
PSFF psffFunc = NULL;
PSFS psfsThis = NULL;
PSFD psfdTemp = NULL;
Uint1 iColor = 0;
ColorPropPtr pcpThis = NULL;
if (!(pdnsfsThis || pbsfThis)) return NULL;
#ifdef _DEBUG_9
printf("in InstallStrucFeature \n");
#endif
psfsThis = (PSFS) pdnsfsThis->data.ptrvalue;
psfdTemp = psfsThis->psfdFeats;
psfsThis->psfdFeats = NewSFD(); /* insert new feature at head LIFO */
if (!psfsThis->psfdFeats)
{
psfsThis->psfdFeats = psfdTemp;
return NULL;
}
psfsThis->psfdFeats->next = psfdTemp; /* attach rest of features */
psfsThis->psfdFeats->iType = pbsfThis->type;
psfsThis->psfdFeats->pdnsfsSet = pdnsfsThis;
psfsThis->psfdFeats->iId = pbsfThis->id;
if (pbsfThis->name) psfsThis->psfdFeats->pcName = StringSave(pbsfThis->name);
psffFunc = DoesFeatureTypeHaveFuncs(pbsfThis->type);
if (psffFunc)
{ /* this uses the installed functions associated with the feature type */
/* to copy from the User-object into a newly-allocated data object */
/* which is owned by psfsThis->psfdFeats */
(*(psffFunc->pFeatToCFn)) ( (Pointer PNTR) &(psfsThis->psfdFeats->pData),
(UserObjectPtr PNTR) &pbsfThis->Property_property->data.ptrvalue);
}
/* this is to instantiate the property data */
switch(pbsfThis->type)
{
case Feature_type_color:
/* register color - gets back index into palette */
pcpThis = (ColorPropPtr) pbsfThis->Property_property->data.ptrvalue;
iColor = Call3DColorProc(pcpThis);
psfsThis->psfdFeats->iColor = iColor;
break;
case Feature_type_render:
/* register render code */
psfsThis->psfdFeats->iRender = (Int4) pbsfThis->Property_property->data.intvalue;
break;
case Feature_type_transform:
TransformToDNTRN((PDNTRN PNTR) &psfsThis->psfdFeats->pData,
(TransformPtr) pbsfThis->Property_property->data.ptrvalue);
break;
case Feature_type_camera:
case Feature_type_script:
/* detach & save the property data in ASN.1 format */
/* psfsThis->psfdFeats->pData = (Pointer) pbsfThis->Property_property; */
/* pbsfThis->Property_property = NULL;*/
break;
case Feature_type_cn3dstate:
case Feature_type_comment:
case Feature_type_label:
/* globally applied user-object in use */
/* the ASN.1 has been converted to the C by registered function */
break;
case Feature_type_other:
break; /* other not allowed to have data... */
case Feature_type_multalign:
case Feature_type_alignment:
#ifdef _DEBUG_9
printf("in alignment case \n");
#endif
/* cast property to alignment ASN.1 type */
/* detach location & save it in ASN.1 format */
psfsThis->psfdFeats->pData = (Pointer) pbsfThis->Location_location->data.ptrvalue;
pbsfThis->Location_location = NULL;
InstallAlignedSlave(pdnmsThis,
(ChemGraphAlignmentPtr) psfsThis->psfdFeats->pData,
psfsThis->psfdFeats, Chain, SlaveChain);
break;
case Feature_type_similarity:
case Feature_type_region:
break;
case Feature_type_indirect:
/* deal with mapping the chem-graph-ptrs and "prototypes" */
break;
/* these don't get put into flag bytes */
/* but they all have subgraph locations */
/* case Feature_type_helix:
case Feature_type_strand:
case Feature_type_sheet:
case Feature_type_turn:
case Feature_type_site:
case Feature_type_footnote:
case Feature_type_subgraph:
case Feature_type_core:
case Feature_type_supercore: */
default: ;
/* these have no special indication other than Type */
} /* switch generic feature-type */
return psfsThis->psfdFeats;
}
Int2 LIBCALL BiostrucAddFeature(BiostrucFeatureSetPtr pbsfsThis, PDNMS pdnmsThis,
Boolean Chain, CharPtr SlaveChain)
{
BiostrucFeaturePtr pbsfThis = NULL;
PDNSFS pdnsfsThis = NULL;
PSFS psfsThis = NULL;
PSFD psfdThis = NULL;
PMSD pmsdThis = NULL;
PMGD pmgdThis = NULL;
PFB pfbThis = NULL;
ValNodePtr pvnThis = NULL;
DValNodePtr pdvnThis = NULL;
ChemGraphPntrsPtr pcgpThis = NULL;
RegionPntrsPtr prgpThis = NULL;
CharPtr pcThis = NULL;
ValNodePtr pvnList = NULL;
ValNodePtr pvnLoc = NULL;
Byte bSet = 0;
Boolean ncbiSS = FALSE;
Boolean pdbSS = FALSE;
Boolean pdbSite = FALSE;
Boolean pdbFootnote = FALSE;
Boolean ncbiDomain = FALSE;
Boolean ncbiVast = FALSE;
Boolean bTest = FALSE;
#ifdef _DEBUG_9
printf("in BiostrucAddFeature \n");
#endif
if (!pbsfsThis) return 0;
if (!pdnmsThis) return 0;
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
/* first chore is to make a new feature-set node off this structure */
pdnsfsThis = NewDNSFS(&pmsdThis->pdnsfsHead, pmsdThis->iFeatures+1);
if (!pdnsfsThis) return 0;
pmsdThis->iFeatures++;
psfsThis = (PSFS) pdnsfsThis->data.ptrvalue;
psfsThis->iId = pbsfsThis->id;
/*psfsThis->pvnDescr = (ValNodePtr) pbsfsThis->descr; */ /* link stub for descr */
/*pbsfsThis->descr = NULL; */ /* detach and save from free-ing descr */
/* yanli comment the above two line out, instead do the following */
psfsThis->pvnDescr = (ValNodePtr)AsnIoMemCopy((ValNodePtr) pbsfsThis->descr, (AsnReadFunc)BiostrucFeatureSetDescrAsnRead, (AsnWriteFunc)BiostrucFeatureSetDescrAsnWrite);
pvnThis = NULL;
pvnThis = ValNodeFindNext(psfsThis->pvnDescr, NULL, BiostrucFeatureSetDescr_name);
if (pvnThis)
{
pcThis = (CharPtr) pvnThis->data.ptrvalue;
psfsThis->pcName = StringSave(pcThis);
/* these strings categorize known feature sets that come bundled
with MMDB data */
if (!(StringCmp(pcThis, STRING_NCBI_SS)))
{
ncbiSS = TRUE;
}
if (!(StringCmp(pcThis, STRING_PDB_SS)))
{
pdbSS = TRUE;
}
if (!(StringCmp(pcThis, STRING_PDB_SITE)))
{
pdbSite = TRUE;
}
if (!(StringCmp(pcThis, STRING_PDB_FOOTNOTE)))
{
pdbFootnote = TRUE;
}
if (!(StringCmp(pcThis, STRING_NCBI_DOMAIN)))
{
ncbiDomain = TRUE;
}
if (!(StringCmp(pcThis, STRING_NCBI_VAST)))
{
/* lyg: this no longer works. The id is simply the mmdb # hash of the 2 proteins */
ncbiVast = TRUE;
}
}
pbsfThis = pbsfsThis->features;
while (pbsfThis)
{ /* walk through each feature */
if (ncbiSS || pdbSS)
{ /* set bytes for secondary strucutre flags */
switch (pbsfThis->type)
{
case Feature_type_helix:
bSet = (Byte) SS_HELIX;
break;
case Feature_type_strand:
bSet = (Byte) SS_STRAND;
break;
case Feature_type_sheet:
bSet = (Byte) (SS_STRAND | SS_SHEET);
break;
case Feature_type_turn:
bSet = (Byte) SS_TURN;
break;
default:
return -1;
}
} /* if bSet - Sec stru to set */
/* Installs feature entry in feature registry */
/* any data is attached and owned by the psfdThis node */
psfdThis = InstallStrucFeature(pdnmsThis, pdnsfsThis, pbsfThis, Chain, SlaveChain);
if (!psfdThis) return 0;
/* this registers the installed feature into the appropriate PFB node(s) */
switch(psfdThis->iType)
{
case Feature_type_alignment:
case Feature_type_multalign:
/* these are already registered */
break;
case Feature_type_similarity:
case Feature_type_region:
case Feature_type_cn3dstate:
case Feature_type_camera:
case Feature_type_script:
/* locations are assumed MSD */
bTest = SetNodeFeatureData((PFB) pmsdThis, psfdThis );
psfdThis->bPFBtype = pmsdThis->bMe; /* set to AM_MSD */
break;
/*
case Feature_type_helix:
case Feature_type_strand:
case Feature_type_sheet:
case Feature_type_turn:
case Feature_type_site:
case Feature_type_footnote:
case Feature_type_subgraph:
case Feature_type_color:
case Feature_type_render:
case Feature_type_comment:
case Feature_type_label:
case Feature_type_transform:
case Feature_type_core:
case Feature_type_supercore:
case Feature_type_other:
*/
default:
/* do chem-graph-pointers */
pvnThis = NULL;
pvnThis = ValNodeFindNext(pbsfThis->Location_location, NULL, Location_location_subgraph);
if (pvnThis)
{
pcgpThis = (ChemGraphPntrsPtr) pvnThis->data.ptrvalue;
pvnList = MakeChemGraphNodeList(pdnmsThis, pcgpThis);
if (!pvnList) return -1;
pvnLoc = pvnList;
while (pvnLoc)
{
pfbThis = (PFB) pvnLoc->data.ptrvalue;
/* register feature in each location node */
bTest = SetNodeFeatureData( pfbThis, psfdThis );
if (bTest == FALSE) return 0;
psfdThis->bPFBtype = (psfdThis->bPFBtype | pfbThis->bMe);
/* special case for Sec Stru - set flag bits & strings */
if (ncbiSS || pdbSS || ncbiDomain)
{
pmgdThis = (PMGD) pfbThis;
if (pmgdThis->bMe != AM_MGD) return -1;
if (ncbiSS)
{
pmgdThis->pcNCBISS = psfdThis->pcName;
pmgdThis->bNCBISecStru = pmgdThis->bNCBISecStru | bSet;
}
if (pdbSS)
{
pmgdThis->pcPDBSS = psfdThis->pcName;
pmgdThis->bPDBSecStru = pmgdThis->bPDBSecStru | bSet;
}
if (ncbiDomain)
{
pmgdThis->iDomain = pbsfThis->id;
}
} /* special cases */
pvnLoc = pvnLoc->next;
} /* while pvnLoc */
ValNodeFree(pvnList);
pvnList = NULL;
} /* if pvnThis */
/* do regions */
pvnThis = NULL;
pvnThis = ValNodeFindNext(pbsfThis->Location_location, NULL, Location_location_region);
if (pvnThis)
{
prgpThis = (RegionPntrsPtr) pvnThis->data.ptrvalue;
pvnList = MakeRegionNodeList(pdnmsThis, prgpThis);
if (!pvnList) return -1;
pvnLoc = pvnList;
while (pvnLoc)
{
pfbThis = (PFB) pvnLoc->data.ptrvalue;
/* register feature in each location */
bTest = SetNodeFeatureData( pfbThis, psfdThis);
psfdThis->bPFBtype = (psfdThis->bPFBtype | pfbThis->bMe);
if (bTest == FALSE) return 0;
pvnLoc = pvnLoc->next;
} /* while pvnLoc */
ValNodeFree(pvnList);
pvnList = NULL;
} /* if pvnThis */
} /* switch generic feature-type */
pbsfThis = pbsfThis->next;
} /* while pbsfThis : next feature in feature-set */
/* now that they are instantiated - the caller can delete the ASN.1 forms */
/* of the features - we have kept the descr and other non-volatile elements */
/* like camera's and tranforms, and null-ed out their pointers */
return TRUE;
}
static Int4 FindGiSeq(ValNodePtr pvnSeqId)
{
ValNodePtr pvn;
pvn = ValNodeFindNext(pvnSeqId, NULL, SEQID_GI);
if (pvn)
return (Int4) pvn->data.intvalue;
else
return 0;
}
Byte LIBCALL SetBondOrder(Byte bThis, Int2 iType)
{
switch (iType)
{
case Bond_order_partial_double:
return (Byte)(bThis | BOND_PDOUBLE);
case Bond_order_aromatic:
return (Byte)(bThis | BOND_PDOUBLE | BOND_DOUBLE);
case Bond_order_double:
return (Byte)(bThis | BOND_DOUBLE);
case Bond_order_triple:
return (Byte)(bThis | BOND_TRIPLE);
case Bond_order_other:
case Bond_order_unknown:
return bThis;
case Bond_order_single:
default:
bThis = (Byte)(bThis | BOND_SINGLE);
}
return bThis;
}
/*
* Biostruc2Modelstruc is the main routine to fetch and convert a
* Biostruc into Modelstruc form - which is a hybrid ASN.1 / hand
* made data structure.
*
*/
PDNMS LIBCALL Biostruc2Modelstruc(PDNMS PNTR ppdnmsList, BiostrucPtr pbsBS, PRGD prgdDict,
Byte bExtent, Int2 iChoice,
CharPtr pcFetch, Int2 iType)
/* pdnmsList is the master list of structures or NULL for first */
/* if pbsBS = NULL - use the pcFetch functions.. */
{
BiostrucModelPtr pbsmThis = NULL;
IntraResidueBondPtr pirbThis = NULL;
InterResidueBondPtr pierbThis = NULL;
ValNodePtr pvnThis = NULL;
AtomPntrPtr papIndex = NULL;
PDNMS pdnmsThis = NULL;
PMSD pmsdThis = NULL;
PDNMM pdnmmThis = NULL;
PDNMM pdnmmPrev = NULL;
PMMD pmmdThis = NULL;
PDNMG pdnmgThis = NULL;
PDNMG pdnmgPrev = NULL;
PMGD pmgdThis = NULL;
PVNMA pvnmaThis = NULL;
PVNMA pvnmaPrev = NULL;
PMAD pmadThis = NULL;
PVNMB pvnmbThis = NULL;
PVNMB pvnmbPrev = NULL;
PMBD pmbdThis = NULL;
Int2 iTest = TRUE;
Int4 iGraphId = 0;
Int4 iMolCount = 0;
Int4 iResCount = 0;
Int4 iAtomCount = 0;
Int4 iBondCount = 0;
Int4 iModelCount = 0;
/* version 4.0 additions */
BiostrucIdPtr pbsidThis = NULL;
BiostrucDescrPtr pbsdrThis = NULL;
BiomolDescrPtr pbmdrThis = NULL;
MoleculeGraphPtr pmgThis = NULL;
ResiduePtr prThis = NULL;
ValNodePtr pvnrgThis = NULL; /* a ValNodePtr */
ResidueGraphPtr prgDict = NULL; /* a ValNodePtr */
ValNodePtr pvnStrings = NULL;
AtomPtr pAtom;
BiostrucFeatureSetPtr pbsfsThis = NULL;
BiostrucResidueGraphSetPntrPtr ppdDict = NULL;
Int4 iMolGraphType = 0;
/* ErrSetFatalLevel - allow malloc failure to return */
#ifdef _DEBUG_0
printf("Biostruc2Modelstruc\n");
#endif
if (!pbsBS) pbsBS = FetchBS(pcFetch,iType, ALLMDL,3000,bExtent);
/* traverse the chemical graph to make C memory
* strucures */
if (pbsBS)
{
pdnmsThis = NewDNMS(ppdnmsList, iChoice);
if (!pdnmsThis) goto allocerror;
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue; /*set the pointer to the data */
pmsdThis->pdnmsSlaves = NULL;
pmsdThis->bAligned = 0; /* nothing aligned to it */
pmsdThis->pbAligned = NULL;
pmsdThis->bMaster = TRUE; /* default to being a master structure */
pmsdThis->iMimeType = 0;
/* non-MMDB dependent info */
pmsdThis->pcSName = StringSave(pcFetch);
pmsdThis->iType = iType; /* copy iType also used in fetch for future ref */
/* MMDB dependent stuff */
pbsidThis = ValNodeFindNext(pbsBS->id,NULL,BiostrucId_mmdb_id);
if (pbsidThis)
{
pmsdThis->iMMDBid = (Int4) pbsidThis->data.intvalue; /* Get MMDB id no (only the first one) */
}
else
{
; /* assign it a hashed ID number based on iChoice?? */
}
pbsdrThis = ValNodeFindNext(pbsBS->descr,NULL,BiostrucDescr_name);
/* just want the first one */
pmsdThis->pcPDBName = StringSave(PDBNAME_DEFAULT);
if (pbsdrThis)
{
StringNCpy(pmsdThis->pcPDBName,(CharPtr) pbsdrThis->data.ptrvalue, sizeof(pmsdThis->pcPDBName));
}
#ifdef _DEBUG_0
printf("[%d]id [%s] pdb\n",pmsdThis->iMMDBid,pmsdThis->pcPDBName);
printf("<%s>\n",pmsdThis->pcSName);
#endif
/* ATTACH THE ENTIRE Biostruc */
pmsdThis->pbsBS = pbsBS;
/* the chemical_graph and model_structure portions are erased at the end */
pmsdThis->pGraphDescr = pbsBS->chemical_graph->descr; /* save the chem-graph descr (ValNode) */
pmsdThis->bVisible = 1; /* can be seen */
pbmdrThis = ValNodeFindNext(pbsBS->chemical_graph->descr, NULL, BiomolDescr_name);
if (pbmdrThis)
{
pmsdThis->pcChemName = StringSave((CharPtr)pbmdrThis->data.ptrvalue);
}
else
{
pmsdThis->pcChemName = StringSave(STRING_UNK_PDB);
}
pbmdrThis = ValNodeFindNext(pbsBS->chemical_graph->descr, NULL, BiomolDescr_pdb_class);
if (pbmdrThis)
{
pmsdThis->pcPdbClass = StringSave((CharPtr)pbmdrThis->data.ptrvalue);
}
else
{
pmsdThis->pcPdbClass = StringSave(STRING_UNK_PDB);
}
pbmdrThis = ValNodeFindNext(pbsBS->chemical_graph->descr, NULL, BiomolDescr_pdb_source);
if (pbmdrThis)
{
pmsdThis->pcPdbSource = StringSave((CharPtr)pbmdrThis->data.ptrvalue);
}
else
{
pmsdThis->pcPdbSource = StringSave(STRING_UNK_PDB);
}
pbmdrThis = ValNodeFindNext(pbsBS->chemical_graph->descr, NULL, BiomolDescr_assembly_type);
if (pbmdrThis)
{
pmsdThis->iPDBType = (Int2) pbmdrThis->data.intvalue;
}
else
{
pmsdThis->iPDBType = Assembly_Type_Other;
}
pbsBS->chemical_graph->descr = NULL; /* stops the free-er from killing it prematurely */
#ifdef _DEBUG_0
printf("{%s} pcChemName \n", pmsdThis->pcChemName);
printf("{%s} pcPdbClass \n", pmsdThis->pcPdbClass);
printf("{%s} pcPdbSource\n", pmsdThis->pcPdbSource);
#endif
/* flesh-out the chemical graph */
pmgThis = pbsBS->chemical_graph->molecule_graphs;
ProgMon("Instantiating Chemical Graph");
while (pmgThis) /* walk up the molecule_graphs */
{
iMolCount++;
iResCount = 0;
pdnmmPrev = pdnmmThis;
pdnmmThis = NewDNMM(NULL, (Int2) pmgThis->id);
if (!pdnmmThis) goto allocerror;
pmmdThis = (PMMD) pdnmmThis->data.ptrvalue; /*set the pointer to the data */
pmmdThis->pfbParent = (PFB) pmsdThis;
/* turn off the selection. lyg */
pmmdThis->pdnmgStartSelect = NULL;
pmmdThis->pdnmgEndSelect = NULL;
/* get the sequence for each one */
pmmdThis->iChainId = pmgThis->id;
#ifdef _DEBUG_0
printf("\n<%d> ChainId ", pmmdThis->iChainId);
#endif
/* this gets chain names, like A,B etc... */
pbmdrThis = ValNodeFindNext(pmgThis->descr, NULL, BiomolDescr_name);
if (pbmdrThis)
{
pmmdThis->pcMolName = StringSave((CharPtr)pbmdrThis->data.ptrvalue);
}
else
{
pmmdThis->pcMolName = StringSave(STRING_UNK_MOL);
}
#ifdef _DEBUG_0
printf("'%s' name \n", pmmdThis->pcMolName);
#endif
pbmdrThis = ValNodeFindNext(pmgThis->descr, NULL, BiomolDescr_molecule_type);
if (pbmdrThis)
{
iMolGraphType = (Int4) pbmdrThis->data.intvalue;
}
else
{
iMolGraphType = Molecule_type_other;
}
pmmdThis->pMolDescr = pmgThis->descr; /* save molecule descr */
pmgThis->descr = NULL; /* stops from premature free-ing when chem-graph turfed */
switch (iMolGraphType)
{
case Molecule_type_dna:
#ifdef _DEBUG_2
printf("dna ");
#endif
pmmdThis->bWhat = (Byte) AM_DNA;
pmsdThis->bWhat = (Byte) (pmsdThis->bWhat | (Byte) AM_DNA);
pmmdThis->iGi = FindGiSeq(pmgThis->seq_id);
break;
case Molecule_type_rna:
#ifdef _DEBUG_2
printf("rna ");
#endif
pmmdThis->bWhat = (Byte) AM_RNA;
pmsdThis->bWhat = (Byte) (pmsdThis->bWhat | (Byte) AM_RNA);
pmmdThis->iGi = FindGiSeq(pmgThis->seq_id);
break;
case Molecule_type_protein:
#ifdef _DEBUG_2
printf("protein ");
#endif
pmmdThis->bWhat = (Byte) AM_PROT;
pmsdThis->bWhat = (Byte) (pmsdThis->bWhat | (Byte) AM_PROT);
pmmdThis->iGi = FindGiSeq(pmgThis->seq_id);
break;
case Molecule_type_other_biopolymer:
#ifdef _DEBUG_2
printf("other biopolymer ");
#endif
pmmdThis->bWhat = (Byte) AM_POLY;
pmsdThis->bWhat = (Byte) (pmsdThis->bWhat | (Byte)AM_POLY);
break;
case Molecule_type_solvent:
#ifdef _DEBUG_2
printf("solvent ");
#endif
pmmdThis->bWhat = (Byte) AM_SOL;
pmsdThis->bWhat = (pmsdThis->bWhat | (Byte) AM_SOL);
break;
case Molecule_type_other_nonpolymer:
#ifdef _DEBUG_2
printf("other ");
#endif
pmmdThis->bWhat = (Byte) AM_HET;
pmsdThis->bWhat = (pmsdThis->bWhat | (Byte) AM_HET);
break;
case Molecule_type_other:
default:
#ifdef _DEBUG_2
printf("unknown ");
#endif
pmmdThis->bWhat = (Byte) AM_UNK;
pmsdThis->bWhat = (pmsdThis->bWhat | (Byte) AM_UNK);
} /*switch*/
pmmdThis->pSeqId = pmgThis->seq_id;
pmgThis->seq_id = NULL; /* copies & protects the ASN.1 seq_id */
prThis = pmgThis->residue_sequence;
while (prThis)
{ /* flesh - out the molecule graphs residue-by-residue */
ProgMon("Instantiating Chemical Graph");
iResCount++;
iAtomCount = 0;
iBondCount = 0;
pdnmgPrev = pdnmgThis;
pdnmgThis = NewDNMG(NULL,(Int2) prThis->id);
if (!pdnmgThis) goto allocerror;
pmgdThis = (PMGD) pdnmgThis->data.ptrvalue; /*set the pointer to the data */
pmgdThis->pfbParent = (PFB) pmmdThis;
pmgdThis->pcGraphNum = StringSave(prThis->name);
#ifdef _DEBUG_1
printf(":%s: PDB No ", pmgdThis->pcGraphNum);
#endif
pvnrgThis = prThis->residue_graph;
/* USE ENTREZ-FETCH TO GET REF-ED BIOSTRUCS */
switch (pvnrgThis->choice)
{
case ResidueGraphPntr_local:
prgDict = pbsBS->chemical_graph->residue_graphs;
iGraphId = (Int4) pvnrgThis->data.intvalue;
pmsdThis->pDictLocal = prgDict;
pmgdThis->bWhat = (Byte) (pmgdThis->bWhat | (Byte) DICT_LOCAL);
break;
case ResidueGraphPntr_standard:
/* get the id of the graph to lookup */
ppdDict = (BiostrucResidueGraphSetPntrPtr) pvnrgThis->data.ptrvalue;
iGraphId = (Int4) ppdDict->residue_graph_id;
pmgdThis->bWhat = (Byte) (pmgdThis->bWhat | (Byte) DICT_GLOBAL);
/* ****use the dictionary id to get the right global dictionary */
prgDict = prgdDict->residue_graphs; /* the one passed as a parameter */
break;
case ResidueGraphPntr_biostruc:
default:
prgDict = NULL;
pmgdThis->bWhat = (Byte) (pmgdThis->bWhat | (Byte) DICT_REF);
}
while (prgDict)
{
if (prgDict->id == iGraphId)
{
/* found the right dictionary entry */
pbmdrThis = ValNodeFindNext(prgDict->descr, NULL, BiomolDescr_name);
if (pbmdrThis)
{
pmgdThis->pcGraphName = StringSave((CharPtr)pbmdrThis->data.ptrvalue);
}
else
{
pmgdThis->pcGraphName = StringSave(STRING_UNK_RES);
}
pbmdrThis = ValNodeFindNext(prgDict->descr, NULL, BiomolDescr_pdb_comment);
if (pbmdrThis)
{
pmgdThis->pcPDBComment = StringSave((CharPtr) pbmdrThis->data.ptrvalue);
}
pvnStrings = prgDict->iupac_code;
if (pvnStrings) /* only interpret the first one!!! */
{
pmgdThis->pcIUPAC = StringSave((CharPtr)pvnStrings->data.ptrvalue);
}
#ifdef _DEBUG_1
printf("@%s@%s@",pmgdThis->pcIUPAC, pmgdThis->pcGraphName);
#endif
switch(prgDict->residue_type)
{
case Residue_deoxyribonucleotide:
pmgdThis->bWhat = (Byte) (pmgdThis->bWhat | (Byte) RES_DNA);
break;
case Residue_ribonucleotide:
pmgdThis->bWhat = (Byte) (pmgdThis->bWhat | (Byte) RES_RNA);
break;
case Residue_amino_acid:
pmgdThis->bWhat = (Byte) (pmgdThis->bWhat | (Byte) RES_AA);
break;
case Residue_other:
default:
;
}
pmgdThis->iIDict = iGraphId;
pAtom = prgDict->atoms;
while (pAtom)
{
iAtomCount++;
pvnmaPrev = pvnmaThis;
if (pAtom->element < 254)
pvnmaThis = NewVNMA(NULL, (Int2) pAtom->element);
else
{
if (pAtom->element == 254)
pvnmaThis = NewVNMA(NULL, 0);
else /* bigger usually is 255 */
pvnmaThis = NewVNMA(NULL, (Int2) INT1_MAX);
}
if (!pvnmaThis) goto allocerror;
pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
pmadThis->pfbParent = (PFB) pmgdThis;
pmadThis->iIndex = (Int2) pAtom->id;
/**/ pmadThis->pcAName = pAtom->name;
/* note the name is still in the dictionary !!*/
/* no link back to dictionary source and
* no link back to the iupac_code valnode list
* as this is redundant with the element lookup table
* and more compact to save an Int1 element number
* for each atom
*/
#ifdef _DEBUG_1
printf(" ^%s^ ", pmadThis->pcAName);
#endif
pAtom = pAtom->next;
if (iAtomCount == 1) pmgdThis->pvnmaAHead = pvnmaThis; /* first case */
else ValNodeListCat(pvnmaPrev, pvnmaThis);
/* faster linking with pvnmaPrev - dosen't have to walk the chain... */
}
/* do intra-residue bonds here */
pirbThis = prgDict->bonds;
while (pirbThis)
{
iBondCount++;
pvnmbPrev = pvnmbThis;
pvnmbThis = NewVNMB(NULL, (Int2) pirbThis->bond_order);
if (!pvnmbThis) goto allocerror;
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
pmbdThis->pfbParent = (PFB) pmgdThis;
pmbdThis->bWhat = SetBondOrder(pmbdThis->bWhat,
(Int2)pirbThis->bond_order);
/* register the bond in both the MBD and MAD */
pvnmaThis = pmgdThis->pvnmaAHead;
while (pvnmaThis)
{
pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
if (pmadThis->iIndex == (Int2) pirbThis->atom_id_1)
{
pmbdThis->pmadFrom = pmadThis;
pvnThis = ValNodeAddPointer(&pmadThis->pvnBonds,
(Int2) pirbThis->bond_order, (Nlm_VoidPtr) pmbdThis);
if (!pvnThis) goto allocerror;
}
if (pmadThis->iIndex == (Int2) pirbThis->atom_id_2)
{
pmbdThis->pmadTo = pmadThis;
pvnThis = ValNodeAddPointer(&pmadThis->pvnBonds,
(Int2) pirbThis->bond_order, (Nlm_VoidPtr) pmbdThis);
if (!pvnThis) goto allocerror;
}
pvnmaThis = pvnmaThis->next;
} /* while (pvnmaThis) */
/* check that pmadFrom and pmadTo are filled */
#ifdef _DEBUG_1
printf("\nbond from %s to %s ", pmbdThis->pmadFrom->pcAName,
pmbdThis->pmadTo->pcAName);
#endif
pirbThis = pirbThis->next;
if (iBondCount == 1) pmgdThis->pvnmbBHead = pvnmbThis; /* first case */
else ValNodeListCat(pvnmbPrev, pvnmbThis);
/* faster linking with pvnmbPrev - dosen't have to walk the chain... */
} /* while (pirbThis) */
break; /* out of while (prgDict) */
}
prgDict = prgDict->next;
} /* while (prgDict) */
if (!pmgdThis->iIDict) goto erret; /* dictionary failed to resolve an ID */
pmgdThis->iAtomCount = iAtomCount;
pmgdThis->iBondCount = iBondCount;
if (iResCount == 1) pmmdThis->pdnmgHead = pdnmgThis; /* link first case */
else DValNodeListCat(pdnmgPrev, pdnmgThis); /* link it on */
prThis = prThis->next;
} /* while (prThis) */
/* put in error messages when not got sequence
*/
pmmdThis->iResCount = iResCount;
if (iMolCount == 1) pmsdThis->pdnmmHead = pdnmmThis;
/* link first case */
else DValNodeListCat(pdnmmPrev,pdnmmThis); /* link it on */
/* the molecule must be linked onto the structure
* or the AtomFromMMDBIndex won't find it...
*/
iBondCount = 0;
pvnmbPrev = NULL;
pierbThis = pmgThis->inter_residue_bonds;
while (pierbThis)
{ /* ... fill in the inter_residue_bonds list... */
iBondCount++;
pvnmbPrev = pvnmbThis;
pvnmbThis = NewVNMB(NULL, (Int2) pierbThis->bond_order);
if (!pvnmbThis) goto allocerror;
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
pmbdThis->pfbParent = (PFB) pmmdThis;
pmbdThis->bWhat = SetBondOrder(pmbdThis->bWhat,
(Int2)pierbThis->bond_order);
/* register the bond in both the MBD and MAD */
papIndex = pierbThis->atom_id_1;
pmadThis = AtomFromMMDBIndex(pdnmsThis, iChoice, papIndex->molecule_id,
papIndex->residue_id, papIndex->atom_id);
if (pmadThis) pmbdThis->pmadFrom = pmadThis;
else goto erret;
pvnThis = ValNodeAddPointer(&pmadThis->pvnBonds,
(Int2) pierbThis->bond_order, (Nlm_VoidPtr) pmbdThis);
if (!pvnThis) goto allocerror;
papIndex = pierbThis->atom_id_2;
pmadThis = AtomFromMMDBIndex(pdnmsThis, iChoice, papIndex->molecule_id,
papIndex->residue_id, papIndex->atom_id);
if (pmadThis) pmbdThis->pmadTo = pmadThis;
else goto erret;
pvnThis = ValNodeAddPointer(&pmadThis->pvnBonds,
(Int2) pierbThis->bond_order, (Nlm_VoidPtr) pmbdThis);
if (!pvnThis) goto allocerror;
/* check that pmadFrom and pmadTo are filled */
#ifdef _DEBUG_1
printf("\nINTER-RES bond from %s to %s ", pmbdThis->pmadFrom->pcAName,
pmbdThis->pmadTo->pcAName);
#endif
if (iBondCount == 1) pmmdThis->pvnmbIRBHead = pvnmbThis; /* first case */
else ValNodeListCat(pvnmbPrev, pvnmbThis);
pierbThis = pierbThis->next;
} /* while (pierbThis) */
pmgThis = pmgThis->next;
pmmdThis->iIRBCount = iBondCount;
} /*while (pmgThis) */
pierbThis = pbsBS->chemical_graph->inter_molecule_bonds;
iBondCount = 0;
pvnmbPrev = NULL;
while (pierbThis)
{ /* ... fill in the inter_molecule_bonds list... */
iBondCount++;
pvnmbPrev = pvnmbThis;
pvnmbThis = NewVNMB(NULL, (Int2) pierbThis->bond_order);
if (!pvnmbThis) goto allocerror;
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
pmbdThis->pfbParent = (PFB) pmsdThis;
pmbdThis->bWhat = SetBondOrder(pmbdThis->bWhat,
(Int2)pierbThis->bond_order);
/* register the bond in both the MBD and MAD */
papIndex = pierbThis->atom_id_1;
pmadThis = AtomFromMMDBIndex(pdnmsThis, iChoice, papIndex->molecule_id,
papIndex->residue_id, papIndex->atom_id);
if (pmadThis) pmbdThis->pmadFrom = pmadThis;
else goto erret;
pvnThis = ValNodeAddPointer(&pmadThis->pvnBonds,
(Int2) pierbThis->bond_order, (Nlm_VoidPtr) pmbdThis);
if (!pvnThis) goto allocerror;
papIndex = pierbThis->atom_id_2;
pmadThis = AtomFromMMDBIndex(pdnmsThis, iChoice, papIndex->molecule_id,
papIndex->residue_id, papIndex->atom_id);
if (pmadThis) pmbdThis->pmadTo = pmadThis;
else goto erret;
pvnThis = ValNodeAddPointer(&pmadThis->pvnBonds,
(Int2) pierbThis->bond_order, (Nlm_VoidPtr) pmbdThis);
if (!pvnThis) goto allocerror;
/* check that pmadFrom and pmadTo are filled */
#ifdef _DEBUG_1
printf("\nINTER-MOL bond from %s to %s ", pmbdThis->pmadFrom->pcAName,
pmbdThis->pmadTo->pcAName);
#endif
if (iBondCount == 1) pmsdThis->pvnmbIMBHead = pvnmbThis; /* first case */
else ValNodeListCat(pvnmbPrev, pvnmbThis);
pierbThis = pierbThis->next;
} /* while (pierbThis) */
pmsdThis->iMolCount = iMolCount;
pmsdThis->iIMBCount = iBondCount;
/* REMOVE ALL BUT THE {id, descr, history} PART OF pbsBS */
/* TURF THE CHEMICAL GRAPH (NOT A SEQUENCE) */
/* keep Local Dict from destruction when I turf the chem graph */
if (pbsBS->chemical_graph->residue_graphs)
pbsBS->chemical_graph->residue_graphs = NULL;
BiostrucGraphFree(pbsBS->chemical_graph);
pbsBS->chemical_graph = NULL;
/* Set up the Internal Feature Set */
pbsfsThis = pbsBS->features;
while (pbsfsThis)
{
iTest = BiostrucAddFeature(pbsfsThis, pdnmsThis, FALSE, NULL);
if (iTest < 0) goto erret;
if (!iTest) goto allocerror;
pbsfsThis=pbsfsThis->next;
}
/* blow away the internal Feature Set ASN.1 */
/* BiostrucFeatureSetFree(pbsfsThis);
pbsBS->features = NULL; */
/* stubs to reconstruc Feature-set descr fields remain */
/* as well as feature-contents */
/* CONVERT all Models one at a time */
pbsmThis = pbsBS->model;
while (pbsmThis)
{
iModelCount++;
iTest = BiostrucModel2ModelStruc(pbsmThis,pdnmsThis,iChoice, iModelCount, bExtent);
if (iTest < 0) goto erret;
if (iTest == 0) goto allocerror;
pmsdThis->iModels++;
pbsmThis = pbsmThis->next;
}
/* The Biostruc owns the models - they are always kept and are always freed at pbsBS level */
/* if not keeping ASN.1 the coordinates are all stripped out in the next routine */
/* but the model stubs still remain */
} /* if pbsBS */
return pdnmsThis;
allocerror:
ErrClear();
ErrPostEx(SEV_ERROR,0,0, "Not enough memory to handle Biostruc\nFreeing Biostruc");
ErrShow();
FreeListDNMS(pdnmsThis);
MsgAlert(KEY_NONE,SEV_ERROR, "Biostruc to Modelstruc Failed",
"\nBiostruc was removed from memory.\nTry again with smaller or fewer Models.");
return NULL;
erret:
ErrClear();
ErrPostEx(SEV_ERROR,0,0, "Biostruc ASN.1 Internal Indexing Failure\nFreeing Biostruc");
ErrShow();
FreeListDNMS(pdnmsThis);
return NULL;
}
/* TraverseAll
*
* Arguments:
* pdnModel = a DValNode pointer USED for MSD, MMD, MGD.
* You cannot begin traversal at terminal nodes
* MAD,MBD,MOD,MDD.
* iIndex = any index to be passed to pfnCallme
*
* ptr = any pointer to be passed to pfnCallme
* pfnCallMe = The callback to be performed at every node.
*
*/
Int2 LIBCALL TraverseAll( DValNodePtr pdnModel, Int4 iModel, Int4 iIndex,
Pointer ptr, pNodeFunc pfnCallMe)
/* Walks the structure children from the current pointer. Performs
(*pfnCallMe)((PFB) pxxxxThis, Int4 iMode, Int4 iIndex, Pointer ptr) at each data node
(as Flags Block). callbacks are void return types.
*/
{
PFB pfbThis;
PDNMS pdnmsThis = NULL;
PMSD pmsdThis = NULL;
PDNMM pdnmmThis = NULL;
PMMD pmmdThis = NULL;
PDNMG pdnmgThis = NULL;
PMGD pmgdThis = NULL;
PVNMA pvnmaThis = NULL;
PMAD pmadThis = NULL;
PVNMB pvnmbThis = NULL;
PMBD pmbdThis = NULL;
PVNMO pvnmoThis = NULL;
PMOD pmodThis = NULL;
PVNMD pvnmdThis = NULL;
PMDD pmddThis = NULL;
if (pdnModel)
pfbThis = (PFB) pdnModel->data.ptrvalue; /* get the data block */
else return FALSE;
switch ((int)pfbThis->bMe) /* set the proper type */
{
case AM_MSD:
pdnmsThis = (PDNMS) pdnModel;
break;
case AM_MMD:
pdnmmThis = (PDNMM) pdnModel;
break;
case AM_MGD:
pdnmgThis = (PDNMM) pdnModel;
break;
default:
return FALSE;
}
if (pdnmgThis)
{
while(pdnmgThis)
{ /*graph*/
pmgdThis = (PMGD) pdnmgThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmgdThis, iModel, iIndex, ptr); /* do the callback */
pvnmaThis = pmgdThis->pvnmaAHead;
while (pvnmaThis)
{ /*atom*/
pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmadThis, iModel, iIndex, ptr); /* do the callback */
pvnmaThis = pvnmaThis->next;
} /*atom*/
pvnmbThis = pmgdThis->pvnmbBHead;
while (pvnmbThis)
{ /*bond*/
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmbdThis, iModel, iIndex, ptr); /* do the callback */
pvnmbThis = pvnmbThis->next;
} /*bond*/
pdnmgThis = pdnmgThis->next;
}/*graph*/
return TRUE;
} /* if pdnmgThis */
if (pdnmmThis)
{
while(pdnmmThis)
{ /*molecule*/
pmmdThis = (PMMD) pdnmmThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmmdThis, iModel, iIndex, ptr); /* do the callback */
pdnmgThis = pmmdThis->pdnmgHead;
while(pdnmgThis)
{ /*graph*/
pmgdThis = (PMGD) pdnmgThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmgdThis, iModel, iIndex, ptr); /* do the callback */
pvnmaThis = pmgdThis->pvnmaAHead;
while (pvnmaThis)
{ /*atom*/
pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmadThis, iModel, iIndex, ptr); /* do the callback */
pvnmaThis = pvnmaThis->next;
} /*atom*/
pvnmbThis = pmgdThis->pvnmbBHead;
while (pvnmbThis)
{ /*bond*/
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmbdThis, iModel, iIndex, ptr); /* do the callback */
pvnmbThis = pvnmbThis->next;
} /*bond*/
pdnmgThis = pdnmgThis->next;
}/*graph*/
/* traverse inter-residue bonds */
pvnmbThis = pmmdThis->pvnmbIRBHead;
while (pvnmbThis)
{ /* inter-residue bonds */
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmbdThis, iModel, iIndex, ptr); /* do the callback */
pvnmbThis = pvnmbThis->next;
}
pdnmmThis = pdnmmThis->next;
} /*molecule*/
return TRUE;
} /* if pdnmmThis */
if (pdnmsThis)
{
pmsdThis = (PMSD) pdnmsThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmsdThis, iModel, iIndex, ptr); /* do the callback */
pdnmmThis = pmsdThis->pdnmmHead;
while(pdnmmThis)
{ /*molecule*/
pmmdThis = (PMMD) pdnmmThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmmdThis, iModel, iIndex, ptr); /* do the callback */
pdnmgThis = pmmdThis->pdnmgHead;
while(pdnmgThis)
{ /*graph*/
pmgdThis = (PMGD) pdnmgThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmgdThis, iModel, iIndex, ptr); /* do the callback */
pvnmaThis = pmgdThis->pvnmaAHead;
while (pvnmaThis)
{ /*atom*/
pmadThis = (PMAD) pvnmaThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmadThis, iModel, iIndex, ptr); /* do the callback */
pvnmaThis = pvnmaThis->next;
} /*atom*/
pvnmbThis = pmgdThis->pvnmbBHead;
while (pvnmbThis)
{ /*bond*/
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmbdThis, iModel, iIndex, ptr); /* do the callback */
pvnmbThis = pvnmbThis->next;
} /*bond*/
pdnmgThis = pdnmgThis->next;
}/*graph*/
/* traverse inter-residue bonds */
pvnmbThis = pmmdThis->pvnmbIRBHead;
while (pvnmbThis)
{ /* inter-residue bonds */
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmbdThis, iModel, iIndex, ptr); /* do the callback */
pvnmbThis = pvnmbThis->next;
}
pdnmmThis = pdnmmThis->next;
} /*molecule*/
/* traverse inter-molecule bonds */
pvnmbThis = pmsdThis->pvnmbIMBHead;
while (pvnmbThis)
{ /* inter-molecule bonds */
pmbdThis = (PMBD) pvnmbThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmbdThis, iModel, iIndex, ptr); /* do the callback */
pvnmbThis = pvnmbThis->next;
}
/* traverse Objects */
pvnmoThis = pmsdThis->pvnmoHead;
while (pvnmoThis)
{
if (pvnmoThis->choice == iModel)
{ /* only those models stated */
pmodThis = (PMOD) pvnmoThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmodThis, iModel, iIndex, ptr);
}
pvnmoThis = pvnmoThis->next;
}
/* traverse Densities */
pvnmdThis = pmsdThis->pvnmdHead;
while (pvnmdThis)
{
if (pvnmdThis->choice == iModel)
{ /* only those models stated */
pmddThis = (PMDD) pvnmdThis->data.ptrvalue;
(*pfnCallMe)((PFB) pmddThis, iModel, iIndex, ptr);
}
pvnmdThis = pvnmdThis->next;
}
return TRUE;
}
return FALSE;
}
/* Function to retrieve Biostrucs from ASN.1 files */
/************************************************************/
/* */
/* BiostrucAsnGet() */
/* */
/* Retrieves Biostruc with a structure model of */
/* choice by ignoring portions of the I/O stream */
/* */
/************************************************************/
BiostrucPtr LIBCALL BiostrucAsnGet(AsnIoPtr aip, AsnTypePtr atp, Int4 mdlLvl, Int4 maxModels)
{
BiostrucPtr retval;
DataVal av;
AsnOptionPtr aop;
av.intvalue = mdlLvl;
aop = AsnIoOptionNew(aip, OP_NCBIOBJSTR, BIOSTRUC_CHECK_MODEL, av, NULL);
av.intvalue = maxModels;
aop = AsnIoOptionNew(aip, OP_NCBIOBJSTR, BIOSTRUC_MAX_MODELS, av, NULL);
if (mdlLvl == ALLSIMPLEMDL)
{ /* this is a reaction to an earlier kludge, when ONECOORDATOM didn't
contain all of the models. Now they do contain all the models, so
by forcing this value here we avoid the unnecessary fetching of
multiple models. J. Epstein per C. Hogue, 11/18/96 */
mdlLvl = ONECOORDATOM;
}
retval = BiostrucAsnRead(aip, atp);
AsnIoOptionFree(aip, OP_NCBIOBJSTR, BIOSTRUC_CHECK_MODEL);
AsnIoOptionFree(aip, OP_NCBIOBJSTR, BIOSTRUC_MAX_MODELS);
if (mdlLvl == ONECOORDATOM || mdlLvl == ONECOORDRES || mdlLvl == VECMODEL)
{ /* we have left AsnIoStream in a hopelessly messed-up state, so reset it */
AsnIoReset(aip);
}
return retval;
}
/* The accmmdbs.c stub has BiostrucAvail returning FALSE,
and empty BiostrucAsn Read and Write functions.
It should not be added to project libraries (Mac), or
will be be overridden on linking (PC or UNIX). */
Boolean LIBCALL BiostrucAvail (void)
{
return TRUE;
}
/* These 2 Bool funs were moved from mkbioseqB.c - DZ 4/27/99 */
/***********************************************************************/
/* isBiopoly() */
/* */
/* Given a molecule id, checks whether the corresponding molecule is */
/* either protein, DNA, or RNA and has coordinates. */
/* */
/***********************************************************************/
Boolean LIBCALL isBiopoly(Int4 molecule_id, MoleculeGraphPtr currentbp)
{
Boolean ret=FALSE;
while (currentbp) {
if (currentbp->id == molecule_id) {
ret = TRUE;
break;
}
currentbp = currentbp->next;
}
return ret;
}
/*************************************************************************/
/* isHet() */
/* */
/* Given a molecule id, checks whether the corresponding molecule is */
/* a heterogen but not solvent or of unknown type, and has coordinates. */
/* */
/*************************************************************************/
Boolean LIBCALL isHet(Int4 molecule_id, MoleculeGraphPtr currenthet)
{
Boolean ret=FALSE;
while (currenthet) {
if (currenthet->id == molecule_id) {
ret = TRUE;
break;
}
currenthet = currenthet->next;
}
return ret;
}
|