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
|
// -*- Mode: C++; tab-width: 2; -*-
// vi: set ts=2:
//
#include <BALL/FORMAT/PDBFile.h>
#include <BALL/NMR/empiricalHSShiftProcessor.h>
#include <BALL/KERNEL/bond.h>
#include <BALL/FORMAT/parameterSection.h>
#include <BALL/STRUCTURE/peptides.h>
#include <BALL/KERNEL/PTE.h>
#include <BALL/MATHS/analyticalGeometry.h>
#include <map>
#include <set>
#include <BALL/SYSTEM/path.h>
#include <BALL/MATHS/cubicSpline1D.h>
#include <BALL/MATHS/cubicSpline2D.h>
#define FLOAT_VALUE_NA 3600.
// This value signifies that the evaluation should return 0. This is a very ugly hack,
// but the best way I can think of to prevent spline evaluation for non-existing h-bonds
#define FLOAT_VALUE_IGNORE 3700.
#define STRING_VALUE_NA "BADVAL"
#define CHAR_VALUE_NA '?'
//#define DEBUG
#undef DEBUG
using namespace std;
namespace BALL
{
const int EmpiricalHSShiftProcessor::VERBOSITY_LEVEL_CRITICAL = 5;
const int EmpiricalHSShiftProcessor::VERBOSITY_LEVEL_DEBUG = 10;
const char* EmpiricalHSShiftProcessor::Option::VERBOSITY = "empirical_HS_shift_processor";
const int EmpiricalHSShiftProcessor::Default::VERBOSITY = EmpiricalHSShiftProcessor::VERBOSITY_LEVEL_CRITICAL;
const char* EmpiricalHSShiftProcessor::PROPERTY__EHS_SHIFT= "EmpiricalHSShift";
EmpiricalHSShiftProcessor::EmpiricalHSShiftProcessor()
: ShiftModule()
{
setDefaultOptions();
}
EmpiricalHSShiftProcessor::~EmpiricalHSShiftProcessor()
{
}
void EmpiricalHSShiftProcessor::init()
{
verbosity_ = options.getInteger(Option::VERBOSITY);
//for TEST ing
//verbosity_ = 10;
// By default, we assume the worst...
valid_ = false;
// If no parameters are assigned, abort immediately.
if (parameters_ == 0)
{
return;
}
// Do we have correction factors for SSBonds?
ParameterSection parameter_section_ssbond;
parameter_section_ssbond.extractSection(*parameters_, "SSBondCorrection");
if ( !parameter_section_ssbond.hasVariable("atomtype")
||!parameter_section_ssbond.hasVariable("correction") )
{
return;
}
// Extract the column indices.
Position atomtype_column = parameter_section_ssbond.getColumnIndex("atomtype");
Position correction_column = parameter_section_ssbond.getColumnIndex("correction");
int index = -1;
for (Position counter = 0; counter < parameter_section_ssbond.getNumberOfKeys(); counter++)
{
String atomtype = parameter_section_ssbond.getValue(counter, atomtype_column);
float correction = parameter_section_ssbond.getValue(counter, correction_column).toFloat();
ssbond_correction_[atomtype] = correction;
}
// Check that the parameter file contains the correct section...
ParameterSection parameter_section;
parameter_section.extractSection(*parameters_, "EmpiricalShiftHyperSurfaces");
// ...and that this section contains the correct column names
if ( !parameter_section.hasVariable("name") || !parameter_section.hasVariable("property")
|| !parameter_section.hasVariable("file") )
{
return;
}
// Check for the options.
int verbosity = options.getInteger(Option::VERBOSITY);
if (parameter_section.options.has("verbosity"))
{
verbosity = parameter_section.options.getInteger("verbosity");
}
options.setInteger(Option::VERBOSITY, verbosity);
verbosity_ = verbosity;
exclude_prolins_ = false;
if (parameter_section.options.has("exclude_prolins"))
{
exclude_prolins_ = parameter_section.options.getBool("exclude_prolins");
}
// Clear the arrays of the targets, the targets names and the target_properties.
targets_.clear();
target_names_.clear();
target_property_names_.clear();
// Extract the column indices.
Position name_column = parameter_section.getColumnIndex("name");
Position property_column = parameter_section.getColumnIndex("property");
Position file_column = parameter_section.getColumnIndex("file");
// Insert per (!) target atom type the necessay properties (in a set)
// and in a map the property pairs and the corresponding
// hypersurface/spline files.
// E.g. an entry in ShiftX.ini could look like this
// 1 CA PHI/PSI file1
// so we need to store:
// - CA as a target name
// - PHI and PSI as target_property_name__s__ for CA
// - file1 in a map with the key pair (PHI,PSI) (for CA)
// - and the pair (PHI, PSI) (for CA) .
index = -1;
String old_target_name = "";
for (Position counter = 0; counter < parameter_section.getNumberOfKeys(); counter++)
{
String target_name = parameter_section.getValue(counter, name_column);
// Create a new vector entry for each new target atom.
if (target_name != old_target_name)
{
index +=1;
old_target_name = target_name;
// Store the atom type we need to look fro in this processor.
target_names_.push_back(target_name);
// Create some dummy entries for
// - target_property_names_
// - property_files_
// - property_pairs_ .
std::set< String> empty;
target_property_names_.push_back(empty);
std::map< std::pair<String, String>, String> empty2;
property_files_.push_back(empty2);
vector<std::pair<String, String> > empty3;
property_pairs_[target_name] = empty3;
}
// Split the string at "/" and store the property_names.
String string = parameter_section.getValue(counter, property_column);
std::vector<String> props;
string.split(props, "/");
if (props.size()!=2)
{
continue;
}
// Store the property names.
target_property_names_[index].insert(props[0]);
target_property_names_[index].insert(props[1]);
// Create a key tuple and insert the filename.
std::pair<String, String> tuple(props[0], props[1]);
// Store the file name.
property_files_[index][tuple] = parameter_section.getValue(counter, file_column);
// Store the property pair.
property_pairs_[target_name].push_back(tuple);
}
// For each property pair
// create a hypersurface in hypersurfaces_.
// For all atom types...
for (Position i = 0; i < property_files_.size(); i++)
{
std::map< std::pair<String, String>, String >::iterator it = property_files_[i].begin();
for (; it != property_files_[i].end(); it++)
{
String atom_type = target_names_[i];
String first_property = (*it).first.first ;
String second_property = (*it).first.second;
ShiftHyperSurface_ shs( (*it).second, atom_type, first_property, second_property, verbosity_);
if (shs.isvalid())
{
// ... insert in the map of hypersurfaces.
std::pair<String, String> tuple(first_property, second_property);
hypersurfaces_[atom_type][tuple]= shs;
}
}
}
// Mark the module as initialized.
valid_ = true;
}
bool EmpiricalHSShiftProcessor::start()
{
// If the module is invalid, abort!
if (!isValid())
{
return false;
}
// Clear the target list.
targets_.clear();
return true;
}
bool EmpiricalHSShiftProcessor::finish()
{
// If the module is in an invalid state, abort!
if (!isValid())
{
return false;
}
//printParameters_();
//printTargets_();
// If there were no targets, return immediately.
if (targets_.empty())
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.info() << "EmpiricalHSShiftProcessor: no targets found!" << std::endl;
}
return true;
}
// If there are no hypersurfaces, return immediately.
if (hypersurfaces_.empty())
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.info() << "EmpiricalHSShiftProcessor: no hypersurfaces created!" << std::endl;
}
return true;
}
float EHS_shift = 0.;
// For all targets compute the shift.
for (Position i = 0; i < targets_.size(); i++)
{
EHS_shift = 0.;
PropertiesForShift_ target = targets_[i];
String atom_type = target.current_atom->getName();
// Do we have to exclude prolins?
if (target.current_atom->getResidue()->getName() == "PRO" && target.current_atom->getName() == "N")
{
target.current_atom->setProperty(PROPERTY__EHS_SHIFT, EHS_shift);
continue;
}
// For all property pairs of the targets atom type.
for (Position j = 0; j < property_pairs_[atom_type].size(); j++)
{
if (hypersurfaces_[atom_type][property_pairs_[atom_type][j]].isvalid())
EHS_shift += hypersurfaces_[atom_type][property_pairs_[atom_type][j]](target);
}
// Correction for ssbonds.
if (target.current_atom->getResidue()->hasProperty(Residue::PROPERTY__HAS_SSBOND))
{
if (ssbond_correction_.find(atom_type) != ssbond_correction_.end())
EHS_shift += ssbond_correction_[atom_type];
}
// Set the shift contribution as a property
target.current_atom->setProperty(PROPERTY__EHS_SHIFT, EHS_shift);
// Add the empirical hypersurface shift to the total shift.
float old_shift = target.current_atom->getProperty(ShiftModule::PROPERTY__SHIFT).getFloat();
target.current_atom->setProperty(ShiftModule::PROPERTY__SHIFT, (old_shift + EHS_shift));
}
//printTargets_();
//printParameters_();
return true;
}
Processor::Result EmpiricalHSShiftProcessor::operator () (Composite& composite)
{
// Here, we collect all target atoms, specified in the section
// "EmpiricalShiftHyperSurfaces" of the {\tt ShiftX.ini} - file,
// and computes the corresponding atoms properties which are likewise specified
// in the ShiftX.ini-file. Since there is no object in BALL to
// store the type of a property in init() and then use it directly here to
// compute and store these properties, we store the _type_ of the
// property as a string in init() and hardcode here for each
// string the corresponding property computation.
// If the composite is an atom ...
if (RTTI::isKindOf<Atom>(&composite))
{
Atom* atom = dynamic_cast<Atom*>(&composite);
// ...clear the property ...
atom->clearProperty(PROPERTY__EHS_SHIFT);
// ... and compute all demanded properties for this atom type
for (Position i = 0; i < target_names_.size(); i++)
{
if (atom->getName() == target_names_[i])
{
PropertiesForShift_ property(verbosity_);
if( property.computeProperties_(atom, target_property_names_[i]))
targets_.push_back(property);
}
}
}
return Processor::CONTINUE;
}
void EmpiricalHSShiftProcessor::printParameters_()
{
Log.info() << "********* \n EHS: list of parameters" << std::endl;
Log.info() << "exclude prolins: " << exclude_prolins_ << std::endl;
Log.info() << "\n EHS: target names \t--\ttarget properties \t--\tfiles " << std::endl;
for (Position i = 0; i < target_names_.size(); i++)
{
Log.info() << "\t\t" << target_names_[i] << "\t--\t";
for (std::set<String>::iterator it = target_property_names_[i].begin();
it != target_property_names_[i].end(); it++)
{
Log.info() << (*it) << ", ";
}
Log.info() << "\t--\t";
for (std::map< std::pair<String, String>, String >::iterator it = property_files_[i].begin();
it != property_files_[i].end(); it++ )
{
Log.info() << "(" << (*it).first.first << "," << (*it).first.second << ") " ;
}
Log.info() << "------------------------------\n" << std::endl;
}
}
void EmpiricalHSShiftProcessor::printTargets_()
{
Log.info() << "********* \n EHS: list of targets and their values" << std::endl;
Log.info() << " atom\tFR\tAA\tSS\tPSI\tPHI\tCHI\tCHI2\tHAL\tHA\tHA2L\tHA2\tHNL\tHN\tOHL\tOH\tDisulfid" << std::endl;
for (Position i = 0; i < targets_.size(); i++)
{
PropertiesForShift_ p = targets_[i];
Log.info()<< " " << p.current_atom->getName() << "\t" << p["FR"].second << "\t" << p["AA"].second << "\t"
<< p["SS"].second << "\t" << p["PSI"].first << "\t" << p["PHI"].first << "\t"
<< p["CHI"].first << "\t" << p["CHI2"].second << "\t" << p["HA1L"].first << "\t"
<< p["HA1"].first << "\t" << p["HA2L"].first << "\t" << p["HA2"].second << "\t"
<< p["HNL"].first << "\t" << p["HN"].second << "\t"
<< p["OHL"].first << "\t" << p["OH"].second << "\t"
<< p["DISULFIDE"].second << std::endl;
}
Log.info() << "------------------------------\n" << std::endl;
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:PropertiesForShift_:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EmpiricalHSShiftProcessor::PropertiesForShift_::PropertiesForShift_(int verbosity)
: verbosity_(verbosity)
{
}
float EmpiricalHSShiftProcessor::PropertiesForShift_::getChiAngle_(Residue* residue)
{
Atom* N = 0;
Atom* CA = 0;
Atom* CB = 0;
Atom* X = 0;
int num_of_atoms = 0;
float angle = FLOAT_VALUE_NA;
// SHIFTX requires that ALA has no typical CHI - angle
if ( (residue->getName() == "ALA")
|| (residue->getName() == "GLY" ) )
return angle;
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
if (name == "N")
{
N = &(*r_it);
num_of_atoms += 1;
}
else if (name == "CA")
{
CA = &(*r_it);
num_of_atoms += 1;
}
else if (name == "CB")
{
CB = &(*r_it);
num_of_atoms += 1;
}
}
if (num_of_atoms != 3)
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.info() << "EmpiricalHSShiftProcessor: torsion angle of " << residue->getName() << " could not be computed!" << std::endl;
}
return FLOAT_VALUE_NA;
}
// determine the missing atom X
/* Sidechain dihedral angle chi1 is defined
(for non-Gly residues) as follows:
Chi1: N(i)-CA(i)-CB(i)-X(i)
where X is the following atom for the following
residue types:
X Residue type
---- ____________
HB1 Ala (for models with protons,labelled 1HB in PDB files).
SG Cys
CG Asp, Glu, Phe, His, Lys, Leu, Met,
Asn, Pro, Gln, Arg, Trp, Tyr
CG1 Ile, Val
OG Ser
OG1 Thr
In order to be conform with ShiftX we leave out GLY and ALA
*/
String residue_name = residue->getName();
if (residue_name == "GLY")
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.info() << "EmpiricalHSShiftProcessor: torsion angle of a glycine could not be computed!" << std::endl;
}
return FLOAT_VALUE_NA;
}
else if (residue_name == "ALA")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "HB1" || r_it->getName() == "1HB")
{
X = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if (residue_name == "CYS")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "SG")
{
X = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if (residue_name == "ASP" || residue_name == "GLU" ||
residue_name == "PHE" || residue_name == "HIS" ||
residue_name == "LYS" || residue_name == "LEU" ||
residue_name == "MET" || residue_name == "ASN" ||
residue_name == "PRO" || residue_name == "GLN" ||
residue_name == "ARG" || residue_name == "TRP" || residue_name == "TYR")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "CG")
{
X = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if (residue_name == "VAL" || residue_name == "ILE")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "CG1")
{
X = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if (residue_name == "SER")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "OG")
{
X = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if (residue_name == "THR")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "OG1")
{
X = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
if (num_of_atoms != 4)
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.info() << "EmpiricalHSShiftProcessor: chi torsion angle of " << residue->getID() << "-"<< residue->getName() << " could not be computed!" << std::endl;
}
return FLOAT_VALUE_NA;
}
Vector3 a = N->getPosition();
Vector3 b = CA->getPosition();
Vector3 c = CB->getPosition();
Vector3 d = X->getPosition();
angle = getTorsionAngle(a.x, a.y, a.z, b.x, b.y, b.z,
c.x, c.y, c.z, d.x, d.y, d.z)*180./Constants::PI;
while (angle < 0.)
{
angle = angle + 360.;
}
return angle;
}
float EmpiricalHSShiftProcessor::PropertiesForShift_::getChi2Angle_(Residue* residue)
{
// NOTE: for compatibility with ShiftX,
// in case of C, S, G and A we have to take the fourth column of the input table, which is symbolized by ALA
float angle = FLOAT_VALUE_NA;
int num_of_atoms = 0;
Atom* CA = 0;
Atom* CB = 0;
Atom* CG = 0;
Atom* XG = 0;
String residue_name = residue->getName();
// GLY, ALA, SER and CYS have no typical CHI2 - angle
if ( (residue->getName() == "ALA")
|| (residue->getName() == "GLY")
|| (residue->getName() == "SER")
|| (residue->getName() == "CYS"))
return angle;
// Sidechain dihedral angle chi2 is defined as follows:
//
// Chi2: CA(i)-CB(i)-CG(i)-XG(i)
// where XG is the following atom for the following
// residue types:
//
// CG XG residue
// -------------------------------------
// CG CD PRO, GLN, GLU, LYS, ARG
// CD1 LEU,TRP,PHE,TYR,
// OD1 ASN, ASP
// ND1 HIS
// SD MET
// CG1 CD1 ILE
// 1HG1 VAL
// CG2 (1HG2 VAL)
// 1HG2 THR
//
// TO DO: (is that true? implement : ok :-))
// Note: in some amino acids the atom names can be switched, i.e.
// for chi2 in amino acids PHE: CD1 <-> CD2
// TYR: CD1 <-> CD2
// ASP: OD1 <-> OD2
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
if (name == "CA")
{
CA = &(*r_it);
num_of_atoms += 1;
}
else if (name == "CB")
{
CB = &(*r_it);
num_of_atoms += 1;
}
if (name == "CG")
{
CG = &(*r_it);
num_of_atoms += 1;
}
}
//look for XG
if ( (residue_name == "ARG") || (residue_name == "GLN")
|| (residue_name == "GLU") || (residue_name == "LYS")
|| (residue_name == "PRO"))
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "CD")
{
XG = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if ( (residue_name == "ASN") || (residue_name == "ASP") )
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "OD1")
{
XG = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if ( (residue_name == "LEU") || (residue_name == "TRP")
||(residue_name == "PHE") || (residue_name == "TYR") )
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "CD1")
{
XG = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if (residue_name == "HIS")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "ND1")
{
XG = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
else if(residue_name == "MET")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "SD")
{
XG = &(*r_it);
num_of_atoms += 1;
break;
}
}
}
// we have to take special care about ILE, VAL and THR
else if(residue_name == "ILE")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "CG1")
{
CG = &(*r_it);
num_of_atoms += 1;
}
else if (r_it->getName() == "CD1")
{
XG = &(*r_it);
num_of_atoms += 1;
}
}
}
else if(residue_name == "VAL")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "1HG1")
{
XG = &(*r_it);
num_of_atoms += 1;
}
else if (r_it->getName() == "CG1")
{
CG = &(*r_it);
num_of_atoms += 1;
}
}
}
else if(residue_name == "THR")
{
r_it = residue->beginAtom();
for (;r_it != residue->endAtom(); ++r_it)
{
if (r_it->getName() == "1HG2")
{
XG = &(*r_it);
num_of_atoms += 1;
}
else if (r_it->getName() == "CG2")
{
CG = &(*r_it);
num_of_atoms += 1;
}
}
}
if (num_of_atoms != 4)
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.info() << "EmpiricalHSShiftProcessor: chi2 torsion angle of " << residue->getID() << "-" << residue->getName() << " could not be computed!" << std::endl;
}
return FLOAT_VALUE_NA;
}
Vector3 a = CA->getPosition();
Vector3 b = CB->getPosition();
Vector3 c = CG->getPosition();
Vector3 d = XG->getPosition();
angle = getTorsionAngle(a.x, a.y, a.z, b.x, b.y, b.z,
c.x, c.y, c.z, d.x, d.y, d.z)*180./Constants::PI;
while (angle < 0.)
{
angle = angle + 360.;
}
return angle;
}
char EmpiricalHSShiftProcessor::PropertiesForShift_::getSecondaryStructure_(Residue* residue)
{
char ret = CHAR_VALUE_NA;
if (!(residue->getSecondaryStructure()))
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.info() << "EmpiricalHSShiftProcessor: no secondary structure available. Consider precomputing!" << std::endl;
}
}
else if (residue->getSecondaryStructure()->getType() == SecondaryStructure::COIL)
{
ret = 'C';
}
else if (residue->getSecondaryStructure()->getType() == SecondaryStructure::HELIX)
{
ret = 'H';
}
else if (residue->getSecondaryStructure()->getType() == SecondaryStructure::STRAND)
{
ret = 'B';
}
return ret;
}
char EmpiricalHSShiftProcessor::PropertiesForShift_::getAminoAcid_(Residue* residue)
{
char ret = CHAR_VALUE_NA;
if (residue->isAminoAcid())
{
ret = Peptides::OneLetterCode(residue->getName());
}
return ret;
}
float EmpiricalHSShiftProcessor::PropertiesForShift_::getHA_HBondLen_(Residue* residue)
{
//float len = FLOAT_VALUE_NA;
float len = FLOAT_VALUE_IGNORE;
Atom* HA = 0;
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
if (name == "HA")
{
HA = &(*r_it);
}
}
if (HA)
{
Atom::BondIterator bi = HA->beginBond();
for (;+bi;++bi)
{
if(bi->getType() == Bond::TYPE__HYDROGEN)
{
len = bi->getLength();
}
}
}
return len;
}
float EmpiricalHSShiftProcessor::PropertiesForShift_::getHA2_HBondLen_(Residue* residue)
{
//float len = FLOAT_VALUE_NA ;
float len = FLOAT_VALUE_IGNORE;
Atom* HA2 = 0;
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
if (name == "HA2" || name == "2HA")
{
HA2 = &(*r_it);
}
}
if (HA2)
{
Atom::BondIterator bi = HA2->beginBond();
for (;+bi;++bi)
{
if(bi->getType() == Bond::TYPE__HYDROGEN)
{
len = bi->getLength();
}
}
}
return len;
}
float EmpiricalHSShiftProcessor::PropertiesForShift_::getHN_HBondLen_(Residue* residue)
{
//float len = FLOAT_VALUE_NA;
float len = FLOAT_VALUE_IGNORE;
Atom* HN = 0;
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
if (name == "H")
{
HN = &(*r_it);
}
}
if (HN)
{
Atom::BondIterator bi = HN->beginBond();
for (;+bi;++bi)
{
if(bi->getType() == Bond::TYPE__HYDROGEN)
{
len = bi->getLength();
}
}
}
return len;
}
float EmpiricalHSShiftProcessor::PropertiesForShift_::getO_HBondLen_(Residue* residue)
{
// float len = FLOAT_VALUE_NA;
float len = FLOAT_VALUE_IGNORE;
Atom* O = 0;
// this works since FLOAT_VALUE_IGNORE is much larger than any possible bond length
// find the oxygen with smallest bond length
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
if (r_it->getElement() == PTE[Element::O])
//if (r_it->getName() == "O")
{
O = &(*r_it);
Atom::BondIterator bi = O->beginBond();
for (;+bi;++bi)
{
if(bi->getType() == Bond::TYPE__HYDROGEN)
{
// for backbone "N", shiftx ignores partners that are not backbone "O"
if ((bi->getPartner(*O)->getName() == "H") && (O->getName() != "O"))
continue;
len = std::min(len,bi->getLength());
}
}
}
}
return len;
}
bool EmpiricalHSShiftProcessor::PropertiesForShift_::hasDisulfidBond_(Residue* residue)
{
return residue->hasProperty(Residue::PROPERTY__HAS_SSBOND);
}
bool EmpiricalHSShiftProcessor::PropertiesForShift_::hasHA_HBond_(Residue* residue)
{
bool ret= false;
Atom* HA = 0;
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
if ( (name == "HA") || (name == "1HA") || (name == "HA1") )
{
HA = &(*r_it);
}
}
if (HA)
{
Atom::BondIterator bi = HA->beginBond();
for (;+bi;++bi)
{
if(bi->getType() == Bond::TYPE__HYDROGEN)
{
ret = true;
}
}
}
return ret;
}
bool EmpiricalHSShiftProcessor::PropertiesForShift_::hasHA2_HBond_(Residue* residue)
{
bool ret = false;
Atom* HA2 = 0;
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
if (name == "HA2" || name == "2HA")
{
HA2 = &(*r_it);
}
}
if (HA2)
{
Atom::BondIterator bi = HA2->beginBond();
for (;+bi;++bi)
{
if(bi->getType() == Bond::TYPE__HYDROGEN)
{
ret = true;
}
}
}
return ret;
}
bool EmpiricalHSShiftProcessor::PropertiesForShift_::hasHN_HBond_(Residue* residue)
{
bool ret = false;
Atom* HN = 0;
AtomIterator r_it = residue->beginAtom();
for (; r_it != residue->endAtom(); ++r_it)
{
String name = r_it->getName();
// the H atom iuapc named HN is called H in BALL!!!
if (name == "H")
{
HN = &(*r_it);
}
}
if (HN)
{
Atom::BondIterator bi = HN->beginBond();
for (;+bi;++bi)
{
if (bi->getType() == Bond::TYPE__HYDROGEN)
{
ret = true;
}
}
}
return ret;
}
bool EmpiricalHSShiftProcessor::PropertiesForShift_::computeProperties_(Atom* a, std::set<String> properties)
{
// Set the atom pointer.
current_atom = a;
Residue* residue = current_atom->getResidue();
// If the atom is not part on a residue, return false.
if (!residue)
{
return false;
}
// Determine the predecessor and successor.
Residue* prev_residue = current_atom->getAncestor(*residue)->getPrevious(*residue);
Residue* next_residue = current_atom->getAncestor(*residue)->getNext(*residue);
// All properties as specified in "properties" are computed.
// NOTE: if a certain property value is not available, the property gets
// the value FLOAT_VALUE_NA or STRING_VALUE_NA.
// Thus we can evaluate unknown values
// by assinging them the average value
// (which is the way ShiftX works :-) )
for (std::set<String>::iterator it = properties.begin();
it != properties.end(); it++)
{
// If there is no predecessor, set the "Unknown values"
// FLOAT_VALUE_NA and STRING_VALUE_NA.
if (!prev_residue)
{
properties_real_[("PSI_P")] = FLOAT_VALUE_NA;
properties_real_[("PHI_P")] = FLOAT_VALUE_NA;
properties_real_[("CHI_P")] = FLOAT_VALUE_NA;
properties_real_[("CHI2_P")] = FLOAT_VALUE_NA;
properties_real_[("HA1L_P")] = FLOAT_VALUE_NA;
properties_real_[("HA2L_P")] = FLOAT_VALUE_NA;
properties_real_[("HNL_P")] = FLOAT_VALUE_NA;
properties_real_[("OHL_P")] = FLOAT_VALUE_NA;
properties_string_[("AA_P")] = STRING_VALUE_NA;
properties_string_[("SS_P")] = STRING_VALUE_NA;
properties_string_[("HA1_P")] = STRING_VALUE_NA;
properties_string_[("HA2_P")] = STRING_VALUE_NA;
properties_string_[("HN_P")] = STRING_VALUE_NA;
properties_string_[("OH_P")] = STRING_VALUE_NA;
properties_string_[("DISULFIDE_P")] = STRING_VALUE_NA;
properties_string_[("CHI_P")] = "Unknown";
properties_string_[("CHI2_P")] = "Unknown";
properties_string_[("FR_P")] = STRING_VALUE_NA;
}
else // Otherwise compute!
{
if ((*it) == "FR_P" )
{
properties_string_[(*it)]= (prev_residue->isNTerminal() ? "Y": "N");
}
else if ((*it) == "AA_P" )
{
properties_string_[(*it)]= getAminoAcid_(prev_residue);
}
else if ((*it) == "SS_P" )
{
properties_string_[(*it)]= getSecondaryStructure_(prev_residue);
}
else if ((*it) == "PSI_P")
{
if (prev_residue->hasTorsionPsi())
{
properties_real_[(*it)]= prev_residue->getTorsionPsi().toDegree();
if (properties_real_[(*it)] > 180)
properties_real_[(*it)] -= 360;
else if (properties_real_[(*it)] < -180)
properties_real_[(*it)] += 360;
}else
{
properties_real_[(*it)] = FLOAT_VALUE_NA;
}
}
else if ((*it) == "PHI_P")
{
if (prev_residue->hasTorsionPhi())
{
properties_real_[(*it)]= prev_residue->getTorsionPhi().toDegree();
if (properties_real_[(*it)] > 180)
properties_real_[(*it)] -= 360;
else if (properties_real_[(*it)] < -180)
properties_real_[(*it)] += 360;
}else
{
properties_real_[(*it)] = FLOAT_VALUE_NA;
}
}
else if ((*it) == "CHI_P")
{ // This simulates the ShiftX behaviour!
properties_string_[(*it)] = STRING_VALUE_NA;
properties_real_[(*it)] = getChiAngle_(prev_residue);
if (properties_real_[(*it)] == FLOAT_VALUE_NA)
{
if ( (prev_residue->getName() == "ALA")
|| (prev_residue->getName() == "GLY") )
{
properties_string_[(*it)] = (prev_residue->getName());
}
else
{
properties_string_[(*it)] = "Unknown";
}
}
}
else if ((*it) == "CHI2_P")
{
properties_string_[(*it)] = STRING_VALUE_NA;
properties_real_[(*it)] = getChi2Angle_(prev_residue);
if (properties_real_[(*it)] == FLOAT_VALUE_NA)
{
if ( (prev_residue->getName() == "ALA")
|| (prev_residue->getName() == "GLY")
|| (prev_residue->getName() == "SER")
|| (prev_residue->getName() == "CYS") )
{
properties_string_[(*it)] = "ALA";
}
else
{
properties_string_[(*it)] = "Unknown";
}
}
}
else if ((*it) == "HA1L_P" )
{
properties_real_[(*it)]= getHA_HBondLen_(prev_residue);
}
else if ((*it) == "HA1_P" )
{
properties_string_[(*it)]= (hasHA_HBond_(prev_residue)? "Y": "N");
}
else if ((*it) == "HA2L_P" )
{
properties_real_[(*it)]= getHA2_HBondLen_(prev_residue);
}
else if ((*it) == "HA2_P" )
{
properties_string_[(*it)]= (hasHA2_HBond_(prev_residue) ? "Y": "N");
}
else if ((*it) == "HNL_P" )
{
properties_real_[(*it)]= getHN_HBondLen_(prev_residue);
}
else if ((*it) == "HN_P" )
{
properties_string_[(*it)] = (hasHN_HBond_(prev_residue)? "Y": "N");
}
else if ((*it) == "OHL_P" )
{
properties_real_[(*it)] = getO_HBondLen_(prev_residue);
}
else if ((*it) == "OH_P" )
{
properties_string_[(*it)] = (getO_HBondLen_(prev_residue) != FLOAT_VALUE_IGNORE) ? "Y": "N";
}
else if ((*it) == "DISULFIDE_P" )
{
properties_string_[(*it)]= (hasDisulfidBond_(prev_residue) ? "Y": "N");
}
}
// // If there is no predecessor, set the "Unknown values"
// FLOAT_VALUE_NA and STRING_VALUE_NA.
if (!next_residue)
{
properties_real_[("PSI_N")] = FLOAT_VALUE_NA;
properties_real_[("PHI_N")] = FLOAT_VALUE_NA;
properties_real_[("CHI_N")] = FLOAT_VALUE_NA;
properties_real_[("CHI2_N")] = FLOAT_VALUE_NA;
properties_real_[("HA1L_N")] = FLOAT_VALUE_NA;
properties_real_[("HA2L_N")] = FLOAT_VALUE_NA;
properties_real_[("HNL_N")] = FLOAT_VALUE_NA;
properties_real_[("OHL_N")] = FLOAT_VALUE_NA;
properties_string_[("AA_N")] = STRING_VALUE_NA;
properties_string_[("SS_N")] = STRING_VALUE_NA;
properties_string_[("HA1_N")] = STRING_VALUE_NA;
properties_string_[("HA2_N")] = STRING_VALUE_NA;
properties_string_[("HN_N")] = STRING_VALUE_NA;
properties_string_[("OH_N")] = STRING_VALUE_NA;
properties_string_[("DISULFIDE_N")] = STRING_VALUE_NA;
properties_string_[("CHI_N")] = "Unknown";// STRING_VALUE_NA;
properties_string_[("CHI2_N")] = "Unknown";//STRING_VALUE_NA;
//properties_string_[("FR_N")] = STRING_VALUE_NA;'N';
properties_string_[("FR_N")] = 'N';
}
else // Otherwise: compute!
{
if ((*it) == "FR_N" )
{
properties_string_[(*it)]= (next_residue->isNTerminal()? "Y": "N");
}
else if ((*it) == "AA_N" )
{
properties_string_[(*it)]= getAminoAcid_(next_residue);
}
else if ((*it) == "SS_N" )
{
properties_string_[(*it)]= getSecondaryStructure_(next_residue);
}
else if ((*it) == "PSI_N")
{
if (next_residue->hasTorsionPsi())
{
properties_real_[(*it)]= next_residue->getTorsionPsi().toDegree();
if (properties_real_[(*it)] > 180)
properties_real_[(*it)] -= 360;
else if (properties_real_[(*it)] < -180)
properties_real_[(*it)] += 360;
}
else
{
properties_real_[("PSI_N")] = FLOAT_VALUE_NA;
}
}
else if ((*it) == "PHI_N")
{
if (next_residue->hasTorsionPhi())
{
properties_real_[(*it)]= next_residue->getTorsionPhi().toDegree();
if (properties_real_[(*it)] > 180)
properties_real_[(*it)] -= 360;
else if (properties_real_[(*it)] < -180)
properties_real_[(*it)] += 360;
}
else
{
properties_real_[("PHI_N")] = FLOAT_VALUE_NA;
}
}
else if ((*it) == "CHI_N")
{ // Simulate ShiftX behaviour!
properties_string_[(*it)] = STRING_VALUE_NA;
properties_real_[(*it)] = getChiAngle_(next_residue);
if (properties_real_[(*it)] == FLOAT_VALUE_NA)
{
if ( (next_residue->getName() == "ALA")
|| (next_residue->getName() == "GLY") )
{
properties_string_[(*it)] = (next_residue->getName());
}
else
{
properties_string_[(*it)] = "Unknown";
}
}
}
else if ((*it) == "CHI2_N")
{
properties_string_[(*it)] = STRING_VALUE_NA;
properties_real_[(*it)] = getChi2Angle_(next_residue);
if (properties_real_[(*it)] == FLOAT_VALUE_NA)
{
if ( (next_residue->getName() == "ALA")
|| (next_residue->getName() == "GLY")
|| (next_residue->getName() == "SER")
|| (next_residue->getName() == "CYS") )
{
properties_string_[(*it)] = ("ALA");
}
else
{
properties_string_[(*it)] = "Unknown";
}
}
}
else if ((*it) == "HA1L_N" )
{
properties_real_[(*it)]= getHA_HBondLen_(next_residue) ;
}
else if((*it) == "HA1_N")
{
properties_string_[(*it)]= (hasHA_HBond_(next_residue)? "Y": "N");
}
else if ((*it) == "HA2L_N" )
{
properties_real_[(*it)]= getHA2_HBondLen_(next_residue);
}
else if ((*it) == "HA2_N" )
{
properties_string_[(*it)]= (hasHA2_HBond_(next_residue)? "Y": "N");
}
else if ((*it) == "HNL_N" )
{
properties_real_[(*it)]= getHN_HBondLen_(next_residue);
}
else if ((*it) == "HN_N" )
{
properties_string_[(*it)]= (hasHN_HBond_(next_residue)? "Y": "N");
}
else if ((*it) == "OHL_N" )
{
properties_real_[(*it)]= getO_HBondLen_(next_residue);
}
else if ((*it) == "OH_N" )
{
properties_string_[(*it)] = (getO_HBondLen_(next_residue) != FLOAT_VALUE_IGNORE) ? "Y": "N";
}
else if ((*it) == "DISULFIDE_N" )
{
properties_string_[(*it)]= (hasDisulfidBond_(next_residue)? "Y": "N");
}
}
// Now compute the properties of the actual residue!
if ((*it) == "FR" )
{
properties_string_[(*it)]= (residue->isNTerminal() ? "Y": "N");
}
else if ((*it) == "AA" )
{
properties_string_[(*it)]= getAminoAcid_(residue);
}
else if ((*it) == "SS" )
{
properties_string_[(*it)]= getSecondaryStructure_(residue);
}
else if ((*it) == "PSI")
{
if (residue->hasTorsionPsi())
{
properties_real_[(*it)]= residue->getTorsionPsi().toDegree();
if (properties_real_[(*it)] > 180)
properties_real_[(*it)] -= 360;
else if (properties_real_[(*it)] < -180)
properties_real_[(*it)] += 360;
}
else
{
properties_real_[(*it)] = FLOAT_VALUE_NA;
}
}
else if ((*it) == "PHI")
{
if (residue->hasTorsionPhi())
{
properties_real_[(*it)]= residue->getTorsionPhi().toDegree();
if (properties_real_[(*it)] > 180)
properties_real_[(*it)] -= 360;
else if (properties_real_[(*it)] < -180)
properties_real_[(*it)] += 360;
}
else
{
properties_real_[(*it)] = FLOAT_VALUE_NA;
}
}
else if ((*it) == "CHI")
{ // Simlulate ShiftX behaviour!
properties_string_[(*it)] = STRING_VALUE_NA;
properties_real_[(*it)] = getChiAngle_(residue);
if (properties_real_[(*it)] == FLOAT_VALUE_NA)
{
if ( (residue->getName() == "ALA")
|| (residue->getName() == "GLY") )
{
properties_string_[(*it)] = (residue->getName());
}
else
{
properties_string_[(*it)] = "Unknown";
}
}
}
else if ((*it) == "CHI2")
{
properties_string_[(*it)] = STRING_VALUE_NA;
properties_real_[(*it)] = getChi2Angle_(residue);
if (properties_real_[(*it)] == FLOAT_VALUE_NA)
{
if ( (residue->getName() == "ALA")
|| (residue->getName() == "GLY")
|| (residue->getName() == "SER")
|| (residue->getName() == "CYS") )
{
properties_string_[(*it)] = ("ALA");
}
else
{
properties_string_[(*it)] = "Unknown";
}
}
}
else if ((*it) == "HA1L" )
{
properties_real_[(*it)]= getHA_HBondLen_(residue);
}
else if ((*it) == "HA1" )
{
properties_string_[(*it)]=(hasHA_HBond_(residue)? "Y": "N");
}
else if ((*it) == "HA2L" )
{
properties_real_[(*it)]= getHA2_HBondLen_(residue) ;
}
else if ((*it) == "HA2" )
{
properties_string_[(*it)]= (hasHA2_HBond_(residue)? "Y": "N");
}
else if ((*it) == "HNL" )
{
properties_real_[(*it)]= getHN_HBondLen_(residue) ;
}
else if ((*it) == "HN" )
{
properties_string_[(*it)]= (hasHN_HBond_(residue)? "Y": "N");
}
else if ((*it) == "OHL" )
{
properties_real_[(*it)]= getO_HBondLen_(residue);
}
else if ((*it) == "OH" )
{
properties_string_[(*it)] = (getO_HBondLen_(residue) != FLOAT_VALUE_IGNORE) ? "Y": "N";
}
else if ((*it) == "DISULFIDE" )
{
properties_string_[(*it)]= (hasDisulfidBond_(residue)? "Y": "N");
}
// The following both cases are due to SHIFTX:
else if ((*it) == "ROW")
{
properties_string_[(*it)] = "N";
}
else if ((*it) == "HBONDSTAT")
{
// The first position reflects existence of HA1 HBond (Length > 0.)
// The second position reflects existence of HA2 HBond "
// The third position reflects HN HBond Length "
// The fourth position reflects O_Bond length
//
properties_string_[(*it)] = "YYYY";
properties_string_[(*it)][0] = (hasHA_HBond_(residue)? 'Y': 'N');
properties_string_[(*it)][1] = (hasHA2_HBond_(residue)? 'Y': 'N');
properties_string_[(*it)][2] = (hasHN_HBond_(residue)? 'Y': 'N');
properties_string_[(*it)][3] = (getO_HBondLen_(residue) != FLOAT_VALUE_IGNORE) ? 'Y': 'N';
}
}
return true;
}
// Returns true, if the property type is alphanumeric/discrete.
bool EmpiricalHSShiftProcessor::PropertiesForShift_::isDiscrete(String property)
{
return !(property.hasSubstring("PSI") || property.hasSubstring("PHI")
|| property.hasSubstring("HA2L") || property.hasSubstring("HA1L")
|| property.hasSubstring("HNL") || property.hasSubstring("OHL")
|| property.hasSubstring("CHI"));
}
bool EmpiricalHSShiftProcessor::PropertiesForShift_::isMixed(String property)
{
return property.hasSubstring("CHI") || property.hasSubstring("CHI2");
}
std::pair<float, String> EmpiricalHSShiftProcessor::PropertiesForShift_::operator [] (const String& property_name)
{
// Initialize the return value pair.
std::pair<float, String> p(FLOAT_VALUE_NA , STRING_VALUE_NA);
// Take care of the special case chi:
// can be a string (ALA, GLY, Unkown) or have an angle (float) e (-180, 180)
if (property_name.hasSubstring("CHI"))
{
p.first = properties_real_[property_name];
p.second = properties_string_[property_name];
}
else if (properties_real_.find(property_name) != properties_real_.end())
{
p.first = properties_real_[property_name];
}
else if (properties_string_.find(property_name) != properties_string_.end())
{
p.second = properties_string_[property_name];
}
return p;
}
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:ShiftHyperSurface_:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
EmpiricalHSShiftProcessor::ShiftHyperSurface_::ShiftHyperSurface_(int verbosity)
: type_(),
first_property_(),
second_property_(),
s2d_(),
s1d_(),
table_(),
row_averages_(),
col_averages_(),
row_spacing_(),
col_spacing_(),
invalid_(),
average_(),
verbosity_(verbosity),
y_axis_values_(),
x_axis_values_(),
sample_values_()
{
}
EmpiricalHSShiftProcessor::ShiftHyperSurface_::ShiftHyperSurface_(String filename, String /* atomtype */,
String firstproperty, String secondproperty, int verbosity)
: type_(),
first_property_(),
second_property_(),
s2d_(),
s1d_(),
table_(),
row_averages_(),
col_averages_(),
row_spacing_(),
col_spacing_(),
invalid_(),
average_(),
verbosity_(verbosity),
y_axis_values_(),
x_axis_values_(),
sample_values_()
{
// Find the data file.
BALL::Path p;
String file_name = p.find("NMR/"+filename) ;// "NMR/splinedata/hat_PSI_DISULFIDE-1.dat");
if (file_name == "")
{
invalid_ = true;
throw(Exception::FileNotFound(__FILE__, __LINE__, "NMR/"+filename ));
return;
}
// The hypersurface is valid.
invalid_ = false;
// Set the x and y property type.
first_property_ = firstproperty;
second_property_ = secondproperty;
// Set the hypersurface type.
setType_(firstproperty, secondproperty);
//
// Read and Store the data.
//
BALL::File file(file_name, std::ios::in);
// Parse the data file.
parseDataFile_(file, filename);
// Case single 1D spline.
if (type_ == SINGLE__REAL)
{
// Create a 1D spline.
vector<float> x_axis;
convertToReal_(x_axis_values_[0], x_axis);
CubicSpline1D s(x_axis, sample_values_[0], average_);
s.setVerbosity(verbosity_);
// Set the lower and upper bounds of the 1D spline.
// TODO: in den Construktor
if (row_spacing_ != FLOAT_VALUE_NA)
{
s.setLowerBound(x_axis[0] - row_spacing_);
s.setUpperBound(x_axis[x_axis.size()-1] + row_spacing_);
}
// Store the 1D spline in the 1D spline map.
s1d_[first_property_] = s;
}
// Case single look-up table line.
else if (type_ == SINGLE__CHI || type_ == SINGLE__DISCRETE)
{
// In order to save storage, the data is compressed
// into a single look-up line!
// NOTE: in the datafile the values are stored diagonally!
for (Position i = 0; i < x_axis_values_[0].size(); i++)
{
table_[first_property_][x_axis_values_[0][i]] = sample_values_[i][i];
}
}
// Otherwise we have a 2D hypersurface.
else
{
// Depending on the property types, create
// a 2D bicubic spline,
// a map of 1D bicubic splines, or
// a lookUpTable (map of map)
//
// Case 2D bicubic spline.
if (type_ == REAL__REAL)
{
// We have a 2D bicubic spline.
// Convert the values.
vector<float> y_axis;
convertToReal_(y_axis_values_, y_axis);
vector<vector<float> > x_axis;
for (Position i=0; i < y_axis.size(); i++)
{
vector<float> v;
convertToReal_(x_axis_values_[i], v);
x_axis.push_back(v);
}
// Create and store a bicubic spline.
s2d_ = CubicSpline2D(x_axis, y_axis, sample_values_);
s2d_.setVerbosity(verbosity_);
// Build the lower and upper bounds like SHIFTX.
for (Position i=0; i < s2d_.getNumberOfSplines(); i++)
{
// For each 1D spline...
CubicSpline1D& cs = s2d_.getSpline(i);
// ...set the bounds...
if (row_spacing_ != FLOAT_VALUE_NA)
{
cs.setLowerBound(x_axis[i][0] - row_spacing_);
cs.setUpperBound(x_axis[i][x_axis[i].size()-1] + row_spacing_);
}
// ...and set the average as default-value.
cs.setDefaultValue(row_averages_[y_axis_values_[i]]);
}
// For all 1D splines in the second direction...
if (col_spacing_ != FLOAT_VALUE_NA)
{
//...set the bounds.
s2d_.setYLowerBound(y_axis[0] - col_spacing_);
s2d_.setYUpperBound(y_axis[y_axis.size()-1] + col_spacing_);
}
} // Case 1D splines.
else if (type_ == REAL__DISCRETE)
{
// !!!! C A U T I O N !!!!
// When accessing the data, one has to switch X and Y,
// since for each discrete value a 1D bicubic spline is stored
// For all 1D splines...
for (Position i = 0; i < y_axis_values_.size(); i++)
{
// ..convert the x-axis data...
vector<float> x_axis;
convertToReal_(x_axis_values_[i], x_axis);
// ...create the 1D cubic spline...
CubicSpline1D s(x_axis, sample_values_[i], row_averages_[y_axis_values_[i]]);
s.setVerbosity(verbosity_);
//...and the set bounds as read from the datafile.
if (row_spacing_ != FLOAT_VALUE_NA)
{
s.setLowerBound(x_axis[0] - row_spacing_);
s.setUpperBound(x_axis[x_axis.size()-1] + row_spacing_);
}
// Finally store the 1D spline in the 1D spline map.
s1d_[y_axis_values_[i]] = s;
}
} // Case 1D CHI spline.
else if (type_ == REAL__CHI)
{
// !!!! C A U T I O N !!!!
// When accessing the data, one has to switch X and Y,
// since for each discrete value a 1D bicubic spline is stored
// For all 1D splines...
for (Position i = 0; i < y_axis_values_.size(); i++)
{
// ...convert the data,...
vector<float> x_axis;
convertToReal_(x_axis_values_[i], x_axis);
// ...create a 1D bicubic spline...
CubicSpline1D s(x_axis, sample_values_[i], true); //TODo: wieso hat der keine defaultwerte??
s.setVerbosity(verbosity_);
//...and set the bounds as read from the datafile.
if (row_spacing_ != FLOAT_VALUE_NA)
{
s.setLowerBound(x_axis[0] - row_spacing_);
s.setUpperBound(x_axis[x_axis.size()-1] + row_spacing_);
}
// Finally store the 1D spline in the 1D spline map.
s1d_[y_axis_values_[i]] = s;
}
}
else if ( (type_ == DISCRETE__REAL )
&& (verbosity_ >= VERBOSITY_LEVEL_CRITICAL))
{
Log.error() << "EmpiricalHSShiftProcessor: case DISCRETE__REAL is not implemented ("
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
} // Case look-up table
else if ( (type_ == DISCRETE__DISCRETE) || (type_ == CHI__DISCRETE)|| (type_ == DISCRETE__CHI) || (type_ == CHI__CHI) )
{
if ( (x_axis_values_.size() != y_axis_values_.size())
&& (verbosity_ >= VERBOSITY_LEVEL_CRITICAL))
{
Log.error() << "EmpiricalHSShiftProcessor: invalid hypersuface table in file "
<< filename << "! ("
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
else // If the file is valid...
{
// ...no data has to be converted and
// a look-up table is created.
// NOTE: access of the look--up table: first the discrete key x, second the numerical key y.
for (Position i = 0; i < y_axis_values_.size(); i++) // y
{
for (Position j = 0; j < x_axis_values_[i].size(); j++) // x
{
table_[x_axis_values_[i][j]][y_axis_values_[i]] = sample_values_[i][j];
}
}
}
}
else if ( (type_ == CHI__REAL)
&& (verbosity_ >= VERBOSITY_LEVEL_CRITICAL))
{
// Fortunately this case does not occur -> this method should not be send.
Log.error() << "EmpiricalHSShiftProcessor: case CHI__REAL is not implemented ("
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
else if ( (type_ == CHI__CHI)
&& (verbosity_ >= VERBOSITY_LEVEL_CRITICAL))
{
// Fortunately this case does not occur -> this method should not be send.
Log.error() << "EmpiricalHSShiftProcessor: case CHI__CHI is not implemented ("
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
}
}
EmpiricalHSShiftProcessor::ShiftHyperSurface_::~ShiftHyperSurface_()
{
}
void EmpiricalHSShiftProcessor::ShiftHyperSurface_::setType_(String firstproperty, String secondproperty)
{
// Is the first property of type "CHI"?
if(PropertiesForShift_::isMixed(firstproperty))
{
// Is the second property of type "CHI"?
if (PropertiesForShift_::isMixed(secondproperty))
{
if (firstproperty == secondproperty)
type_ = SINGLE__CHI;
else
type_ = CHI__CHI;
}
// Is the second property discrete?
else if (PropertiesForShift_::isDiscrete(secondproperty))
{
type_ = CHI__DISCRETE;
}
else // Or is it real?
{
type_ = CHI__REAL;
}
} // Is the first proptery discrete?
else if (PropertiesForShift_::isDiscrete(firstproperty))
{
// Is the second property discrete too?
if (PropertiesForShift_::isDiscrete(secondproperty))
{
if (firstproperty == secondproperty)
type_ = SINGLE__DISCRETE;
else
type_ = DISCRETE__DISCRETE;
} // or is the second property of type "CHI"?
else if (PropertiesForShift_::isMixed(secondproperty))
type_ = DISCRETE__CHI;
else
type_ = DISCRETE__REAL;
}
else // Otherwise the first property is real!
{ // The second property is of discrete type.
if (PropertiesForShift_::isDiscrete(secondproperty))
{
type_ = REAL__DISCRETE;
} // The second property has type "CHI".
else if (PropertiesForShift_::isMixed(secondproperty))
{
type_ = REAL__CHI;
}
else // Or both are real.
{
if (firstproperty == secondproperty)
type_ = SINGLE__REAL;
else
type_ = REAL__REAL;
}
}
return;
}
void EmpiricalHSShiftProcessor::ShiftHyperSurface_::convertToReal_(const vector<String>& input, vector<float>& output)
{
// Clear the output vector.
output.clear();
// Convert all string entries into floats and store them in output.
for (Position i=0; i < input.size(); i++)
output.push_back(input[i].toFloat());
}
// Structure of all input files:
//
// atomtype factorx factory
// total_average
// (row_average_1;row_average_2;...;row_average_n|N/A)
// (col_averages_1;col_averages_2;...;col_averages_n|N/A)
// (row_spacing|N/A)
// (col_spacing|N/A)
// (y_axis_1;...;y_axis_n|N/A)
// x_axis_11;...;x_axis_1m
// value_11;...;value_1m
// ...
// x_axis_n1;...;x_axis_nm
// value_n1;...;value_nm
void EmpiricalHSShiftProcessor::ShiftHyperSurface_::parseDataFile_(BALL::File& file, String filename)
{
String line;
std::vector<BALL::String> fields;
row_averages_.clear();
col_averages_.clear();
try {
// Read over the first line. We don't need the information currently.
line.getline(file);
// Now read the total average. This is contained in _all_ datafiles, so we can depend on it being there.
line.getline(file);
average_ = line.toFloat();
// Test for row averages.
line.getline(file);
String testline = line;
testline.toUpper();
// Are we given row averages?
std::vector<float> row_average_values;
if (!testline.hasSubstring("N/A"))
{
// Yes -> parse the row averages.
line.split(fields, ";");
for (Position i=0; i<fields.size(); i++)
row_average_values.push_back(fields[i].toFloat());
}
// Test for col averages
line.getline(file);
testline = line;
testline.toUpper();
// Are we given column averages?
std::vector<float> col_average_values;
if (!testline.hasSubstring("N/A"))
{
// Yes -> parse the row averages.
line.split(fields, ";");
for (Position i=0; i<fields.size(); i++)
col_average_values.push_back(fields[i].toFloat());
}
// Test for row spacing.
line.getline(file);
testline = line;
testline.toUpper();
// Is the row spacing set?
if (!testline.hasSubstring("N/A"))
row_spacing_ = testline.toFloat();
else
row_spacing_ = FLOAT_VALUE_NA;
// Test for col spacing.
line.getline(file);
testline = line;
testline.toUpper();
// Is the column spacing set?
if (!testline.hasSubstring("N/A"))
col_spacing_ = testline.toFloat();
else
col_spacing_ = FLOAT_VALUE_NA;
// Test for y_axis.
line.getline(file);
testline = line;
testline.toUpper();
if (!testline.hasSubstring("N/A"))
{
// Parse the row averages.
testline.split(fields, ";");
for (Position i=0; i<fields.size(); i++)
y_axis_values_.push_back(fields[i]);
}
// Finally, read the consecutive x_axis / value lines.
Size number_of_lines = std::max((size_t)1, y_axis_values_.size());
x_axis_values_.clear();
x_axis_values_.resize(number_of_lines);
sample_values_.clear();
sample_values_.resize(number_of_lines);
// Read the values...
for (Position i=0; i<number_of_lines; i++)
{
line.getline(file);
line.toUpper();
line.split(fields, ";");
for (Position j = 0; j < fields.size(); j++)
x_axis_values_[i].push_back(fields[j]);
line.getline(file);
line.split(fields, ";");
for (Position j = 0; j < fields.size(); j++)
sample_values_[i].push_back(fields[j].toFloat());
}
// ...and build the row_ and col_averages if applicable.
for (Position i=0; i<row_average_values.size(); i++)
row_averages_[y_axis_values_[i]] = row_average_values[i];
for (Position i=0; i<col_average_values.size(); i++)
col_averages_[x_axis_values_[0][i]] = col_average_values[i];
} catch (...)
{
std::cerr<< "format error in " << filename << std::endl;
}
}
float EmpiricalHSShiftProcessor::ShiftHyperSurface_::operator() (EmpiricalHSShiftProcessor::PropertiesForShift_& properties)
{
// This method evaluates the empirical hypersurface given
// the properties of an atom.
// From all properties of that atom, we extract the two
// property values defining the hypersurface and evaluate
// the hypersurface at that value(s) called accessor(s).
// Since hypersurfaces can be spliny or look-up-tably , we
// have to take special care about the two accessors.
// In particular there are two special cases: CHI-type
// and SINGLE-type properties.
float shift = 0.;
// First, for the cases
// DISCRETE__DISCRETE
// CHI__DISCRETE
// DISCRETE__CHI
// SINGLE__DISCRETE
// SINGLE__CHI
// we precompute the access string.
//
// NOTE: properties of type "CHI" have a "mixed" nature.
// The property can have a numeric or alphanumeric (= discrete) value.
// Since the alphanumeric values are treated as
// a bin, we convert the alphanumeric value into a string
// representing the bin :-).
// NOTE: for the single properties (SINGLE__CHI, SINGLE__DISCRETE)
// we take the property type string itself (like "PHI") as first access string.
String string1 = properties[first_property_].second;
String string2 = properties[second_property_].second;
// Our first special case: CHI - types as first property.
if (PropertiesForShift_::isMixed(first_property_))
{
string1 = properties[first_property_].second;
string1.toUpper();
// Is the property value numeric?
if (properties[first_property_].first != FLOAT_VALUE_NA)
{
float chi_value = properties[first_property_].first;
if (chi_value < 120.)
string1 = "60.000000";
else if (chi_value < 240.)
string1 = "180.000000";
else if (chi_value < 360.)
string1 = "300.000000";
else
{
if (verbosity_ >= VERBOSITY_LEVEL_CRITICAL)
{
Log.error() << "EmpiricalHSShiftProcessor: " << properties.current_atom->getName() << ": "
<< second_property_ << "-value is not valid! ("
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
}
}
}
// CHI - types as second property.
if (PropertiesForShift_::isMixed(second_property_))
{
string2 = properties[second_property_].second;
string2.toUpper();
// Is the property value numeric?
if (properties[second_property_].first != FLOAT_VALUE_NA)
{
float chi_value = properties[second_property_].first;
if (chi_value < 120.)
string2 = "60.000000";
else if (chi_value < 240.)
string2 = "180.000000";
else if (chi_value < 360.)
string2 = "300.000000";
else
{
if (verbosity_ >= VERBOSITY_LEVEL_CRITICAL)
{
Log.error() << "EmpiricalHSShiftProcessor: " << properties.current_atom->getName() << ": "
<< second_property_ << "-value is not valid! ("
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
}
}
}
// Now we can assume that for CHI-types the correct alphanumeric string is set!
// Special case 2: SINGLE__??
// The property type string itself is the first accessor.
if (type_ == SINGLE__DISCRETE || type_ == SINGLE__CHI)
{
string1 = first_property_;
}
//
// Now we access the hypersurface according to its type.
//
// In case of look-up-tably types...
if ( type_ == SINGLE__DISCRETE || type_ == SINGLE__CHI || type_ == CHI__CHI
|| type_ == CHI__DISCRETE || type_ == DISCRETE__CHI || type_ == DISCRETE__DISCRETE)
{
// ...find out, if the first property is contained in the table.
tabletype::iterator first_it = table_.find(string1);
if (first_it != table_.end())
{
// Yes it is :-)
// Check if the second property is contained in the table.
std::map<String, float>::iterator second_it = first_it->second.find(string2);
if (second_it != first_it->second.end())
{ // So both accessors are valid: we can just return the value.
shift = second_it->second; // = table_[string1][string2];
}
else
shift = average_;
}
else // If the first accessor is not valid...
{
// ...does the second property occur at all?
if (tableHasColumn_(string2))
{ // Yes -> return the column average.
shift = average_;
}
else // Both accessores are invalid.
{
// We don't have the value at all... average over the whole table.
shift = average_;
}
}
} // In case of two identical properties of type real.
else if (type_ == SINGLE__REAL)
{
// Remember: the property type string is first
// accessor and returns a 1D spline.
// Check, if the first property was set?
if (s1d_.find(first_property_) != s1d_.end())
{
// No -> take average.
if (properties[first_property_].first == FLOAT_VALUE_NA)
shift = average_;
else // Yes -> evaluate the 1D spline.
shift = s1d_[first_property_](properties[first_property_].first);
}
else
shift = 0.;
}// Case of a 2D bicubic spline.
else if (type_ == REAL__REAL)
{
// Both properties valid?
// No -> return something by default.
// This simulates SHIFTX behaviour:
// if only one factor is out of bounds, we
// return the all-values average.
if ((properties[first_property_].first == FLOAT_VALUE_NA) || (properties[second_property_].first == FLOAT_VALUE_NA))
{
shift = average_;
}
else // Yes -> evaluate.
shift = s2d_(properties[first_property_].first, properties[second_property_].first);
}// Case of 1D splines -- part 1:
else if (type_ == REAL__DISCRETE)
{
// Both properties valid?
// No -> return something by default.
// This simulates SHIFTX behaviour: if only one
// factor is out of bounds, we return the all-values
// average.
// TODO: For some reason, SHIFTX does not seem to use the row_averages here! Find out why!!!
if ( (properties[first_property_].first == FLOAT_VALUE_NA)
||(properties[second_property_].second == STRING_VALUE_NA) )
{
// Return the total average over the whole map.
shift = average_;
}
else // Yes -> evaluate.
{
shift = s1d_[properties[second_property_].second](properties[first_property_].first);
}
}// Case of 1D splines -- part 2:
else if (type_ == DISCRETE__REAL)
{
// Both properties valid?
// No -> return something by default.
// This simulates SHIFTX behaviour: if only one factor is
// out of bounds, we return the all-values average.
if ( (properties[second_property_].first == FLOAT_VALUE_NA)
||(properties[first_property_].second == STRING_VALUE_NA) )
{
// We have to compute the average of
// all 1D spline averages!
shift = 0;
std::map<String, CubicSpline1D>::iterator ci;
for (ci = s1d_.begin(); ci != s1d_.end(); ci++)
shift += ci->second.getDefaultValue();
shift /= s1d_.size();
}
else // Yes -> evaluate.
shift = s1d_[properties[first_property_].second](properties[second_property_].first);
}
else if ( (type_ == CHI__REAL)
&& (verbosity_ >= VERBOSITY_LEVEL_CRITICAL))
{
Log.error() << "EmpiricalHSShiftProcessor: CHI REAL should NEVER be called (at "
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
else if (type_ == REAL__CHI)
{
// This simulates SHIFTX behaviour:
// if only one factor is out of bounds, we return the all-values average.
if (properties[first_property_].first == FLOAT_VALUE_NA)
shift = average_;
else
{ // Everything ok?
if (s1d_.find(string2) != s1d_.end())
{ // Yes -> evaluate!
shift = s1d_[string2](properties[first_property_].first);
}
else // Otherwise return average!
{
shift = average_; // TODO: is this the way SHIFTX does? Seems so!
}
}
}
else
{
if (verbosity_ >= VERBOSITY_LEVEL_CRITICAL)
{
Log.error() << "EmpiricalHSShiftProcessor: Unknown type of properties! (at "
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
}
// if one of the values is FLOAT_VALUE_IGNORE, we will _in all cases_ return zero
if ( (properties[first_property_].first == FLOAT_VALUE_IGNORE)
|| (properties[second_property_].first == FLOAT_VALUE_IGNORE) )
{
shift = 0.;
}
#ifdef DEBUG
std::cout << "_operator (): ";
std::cout << properties.current_atom->getName() << " " << properties.current_atom->getResidue()->getID()<< " "
<< properties.current_atom->getResidue()->getName()<< " " << first_property_ << ":" << second_property_<< " -- "
<< properties[first_property_].first << "/" << properties[first_property_].second<< ":"
<< properties[second_property_].first << "/" << properties[second_property_].second << " -- " << shift << std::endl;
#endif
return shift;
}
float EmpiricalHSShiftProcessor::ShiftHyperSurface_::getTableAverage_()
{
float average = 0.;
int count = 0;
// Run over all rows...
tabletype::iterator row = table_.begin();
for (; row != table_.end(); ++row)
{
// ...and all columns...
std::map<String, float>::iterator column = row->second.begin();
for (; column != row->second.end(); ++column)
{
// ...to compute the average.
average += column->second;
count++;
}
}
if (count > 0)
average /= count;
return average;
}
float EmpiricalHSShiftProcessor::ShiftHyperSurface_::getTableRowAverage_(const std::map<String, float>& row)
{
float average = 0.;
int count = 0;
// Run over all entries of the given row ...
std::map<String, float>::const_iterator column = row.begin();
for (; column != row.end(); ++column)
{
// ...to compute the average.
average += column->second;
count++;
}
if (count > 0)
average /= count;
return average;
}
float EmpiricalHSShiftProcessor::ShiftHyperSurface_::getTableColumnAverage_(const String& name)
{
float average = 0.;
int count = 0;
// Run over all rows...
tabletype::iterator row = table_.begin();
for (; row!=table_.end(); ++row)
{
// ...look for the column named "name"...
std::map<String, float>::iterator column = row->second.find(name);
if (column != row->second.end())
{
// ...and compute the average.
average += column->second;
count++;
}
}
if (count > 0)
average /= count;
return average;
}
bool EmpiricalHSShiftProcessor::ShiftHyperSurface_::tableHasColumn_(const String& name)
{
// Method to check if the hypersurface's look--up table
// has a column named "name".
tabletype::iterator row = table_.begin();
for (; row!=table_.end(); ++row)
if (row->second.find(name) != row->second.end())
return true;
return false;
}
void EmpiricalHSShiftProcessor::postprocessing_()
{
// Get the system.
System* system = NULL;
for (Position i = 0; i < targets_.size(); i++)
{
if (RTTI::isKindOf<System>(&targets_[i].current_atom->getRoot()))
{
system = dynamic_cast<System*>(&(targets_[i].current_atom->getRoot()));
}
}
// If we found a system...
if (system)
{
// ...add for all CA 0.2 times the values of HA.
for (BALL::ResidueIterator r_it = system->beginResidue(); r_it != system->endResidue(); ++r_it)
{
Atom* CA = 0;
Atom* HA = 0;
for (BALL::AtomIterator at_it = r_it->beginAtom(); +at_it; ++at_it)
{
if (at_it->getName() == "CA")
CA = &(*at_it);
if (at_it->getName() == "HA")
HA = &(*at_it);
}
if (CA && HA)
{
float total = CA->getProperty(ShiftModule::PROPERTY__SHIFT).getFloat();
float ca_shift = CA->getProperty(BALL::EmpiricalHSShiftProcessor::PROPERTY__EHS_SHIFT).getFloat();
float ha_shift = HA->getProperty(BALL::EmpiricalHSShiftProcessor::PROPERTY__EHS_SHIFT).getFloat();
CA->setProperty(BALL::EmpiricalHSShiftProcessor::PROPERTY__EHS_SHIFT, ca_shift + 0.2*ha_shift);
CA->setProperty(ShiftModule::PROPERTY__SHIFT, total+ 0.2*ha_shift );
}
}
}
else
{
if (verbosity_ >= VERBOSITY_LEVEL_DEBUG)
{
Log.error() << "Error in EmpiricalHSShiftProcessor: no system found for postprocessing. ("
<< __FILE__ << " " << __LINE__ << ")" << std::endl;
}
}
}
void EmpiricalHSShiftProcessor::setDefaultOptions()
{
options.setDefaultInteger(EmpiricalHSShiftProcessor::Option::VERBOSITY,
EmpiricalHSShiftProcessor::Default::VERBOSITY);
}
} // namespace BALL
|