Add RMMol lipid conformation-distance sample v1.1
Browse files- MODEL_CARD.md +2 -2
- README.md +2 -1
- examples/RMMol_lipid_conformation_distance.ipynb +453 -0
MODEL_CARD.md
CHANGED
|
@@ -35,6 +35,6 @@ The current inference and downstream-probe reproduction was run on the Spark wor
|
|
| 35 |
|
| 36 |
## Reproduction
|
| 37 |
|
| 38 |
-
Use `examples/RMMol_sample.ipynb` to inspect the exact RMMol-only dataset names and selected probe settings.
|
| 39 |
|
| 40 |
-
Generated on 2026-09-
|
|
|
|
| 35 |
|
| 36 |
## Reproduction
|
| 37 |
|
| 38 |
+
Use `examples/RMMol_sample.ipynb` to inspect the exact RMMol-only dataset names and selected probe settings. Use `examples/RMMol_lipid_conformation_distance.ipynb` for the RMMol-only lipid conformation-distance workflow.
|
| 39 |
|
| 40 |
+
Generated on 2026-09-15.
|
README.md
CHANGED
|
@@ -24,6 +24,7 @@ This bundle contains standardized CSV files and a Jupyter sample notebook for RM
|
|
| 24 |
- `dataset/physical_chemistry/`: ESOL, FreeSolv, and Lipophilicity splits.
|
| 25 |
- `dataset/quantum_mechanics/`: QM9 splits.
|
| 26 |
- `examples/RMMol_sample.ipynb`: RMMol-only sample notebook with the selected downstream-head settings.
|
|
|
|
| 27 |
- `MANIFEST.csv`: file-level provenance, row counts, columns, and checksums.
|
| 28 |
|
| 29 |
## Naming convention
|
|
@@ -44,4 +45,4 @@ The RMMol model weights are intended to be distributed from the Hugging Face mod
|
|
| 44 |
|
| 45 |
## Provenance
|
| 46 |
|
| 47 |
-
The CSV files were standardized from the local GraphWorld/MoleculeNet data tree, the HIV split, and the split Tox21/SIDER archives. This bundle was generated on 2026-09-
|
|
|
|
| 24 |
- `dataset/physical_chemistry/`: ESOL, FreeSolv, and Lipophilicity splits.
|
| 25 |
- `dataset/quantum_mechanics/`: QM9 splits.
|
| 26 |
- `examples/RMMol_sample.ipynb`: RMMol-only sample notebook with the selected downstream-head settings.
|
| 27 |
+
- `examples/RMMol_lipid_conformation_distance.ipynb`: RMMol-only LNPDB heldout IL_SMILES workflow for embedding distance versus RDKit USR conformation distance.
|
| 28 |
- `MANIFEST.csv`: file-level provenance, row counts, columns, and checksums.
|
| 29 |
|
| 30 |
## Naming convention
|
|
|
|
| 45 |
|
| 46 |
## Provenance
|
| 47 |
|
| 48 |
+
The CSV files were standardized from the local GraphWorld/MoleculeNet data tree, the HIV split, and the split Tox21/SIDER archives. This bundle was generated on 2026-09-15.
|
examples/RMMol_lipid_conformation_distance.ipynb
ADDED
|
@@ -0,0 +1,453 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cells": [
|
| 3 |
+
{
|
| 4 |
+
"cell_type": "markdown",
|
| 5 |
+
"metadata": {},
|
| 6 |
+
"source": [
|
| 7 |
+
"# RMMol lipid conformation-distance sample\n",
|
| 8 |
+
"\n",
|
| 9 |
+
"This RMMol-only notebook reproduces the lipid heldout IL_SMILES embedding-distance versus conformational-distance workflow. It loads LNPDB heldout ionizable lipid SMILES, computes frozen RMMol embeddings, generates RDKit ETKDGv3 conformers, extracts 12-dimensional USR descriptors, samples the same deterministic 10,000 molecule pairs, and plots embedding distance against USR conformational distance. No result tables, embedding caches, or figures are stored in the release package."
|
| 10 |
+
]
|
| 11 |
+
},
|
| 12 |
+
{
|
| 13 |
+
"cell_type": "code",
|
| 14 |
+
"execution_count": null,
|
| 15 |
+
"metadata": {},
|
| 16 |
+
"outputs": [],
|
| 17 |
+
"source": [
|
| 18 |
+
"from pathlib import Path\n",
|
| 19 |
+
"import hashlib\n",
|
| 20 |
+
"import os\n",
|
| 21 |
+
"import sys\n",
|
| 22 |
+
"import warnings\n",
|
| 23 |
+
"\n",
|
| 24 |
+
"import matplotlib.pyplot as plt\n",
|
| 25 |
+
"from matplotlib import font_manager\n",
|
| 26 |
+
"import numpy as np\n",
|
| 27 |
+
"import pandas as pd\n",
|
| 28 |
+
"from rdkit import Chem, RDLogger\n",
|
| 29 |
+
"from rdkit.Chem import AllChem, rdMolDescriptors\n",
|
| 30 |
+
"from scipy.stats import pearsonr, spearmanr\n",
|
| 31 |
+
"from sklearn.preprocessing import MinMaxScaler\n",
|
| 32 |
+
"\n",
|
| 33 |
+
"RDLogger.DisableLog('rdApp.*')\n",
|
| 34 |
+
"warnings.filterwarnings('ignore')\n",
|
| 35 |
+
"\n",
|
| 36 |
+
"DATASET_NAME = 'lnpdb_heldout_il_smiles'\n",
|
| 37 |
+
"EXACT_HELDOUT_INDICES = [0, 3, 11, 18, 19, 27, 29, 30, 36, 39, 40, 43, 46, 47, 50, 51, 52, 53, 54, 59, 63, 64, 72, 77, 86, 90, 96, 99, 109, 111, 113, 115, 116, 119, 125, 126, 128, 129, 131, 132, 133, 134, 135, 137, 138, 140, 142, 143, 148, 150, 152, 153, 156, 163, 165, 166, 167, 170, 171, 174, 175, 177, 180, 181, 184, 186, 191, 197, 200, 201, 205, 206, 210, 212, 213, 215, 220, 222, 225, 229, 233, 234, 235, 237, 242, 243, 244, 248, 249, 250, 251, 253, 254, 256, 259, 262, 264, 265, 267, 269, 270, 271, 273, 274, 276, 277, 278, 279, 280, 281, 283, 284, 287, 288, 290, 292, 294, 295, 297, 298, 303, 306, 307, 308, 309, 311, 314, 315, 316, 318, 320, 321, 322, 323, 324, 327, 328, 329, 331, 332, 333, 335, 339, 342, 344, 345, 346, 347, 348, 352, 355, 356, 357, 360, 363, 364, 366, 367, 368, 379, 380, 381, 382, 383, 387, 388, 389, 390, 391, 393, 394, 399, 400, 401, 404, 407, 408, 409, 411, 412, 413, 415, 416, 418, 420, 421, 422, 425, 426, 427, 428, 430, 432, 433, 439, 440, 441, 443, 444, 447, 448, 449, 450, 451, 452, 457, 459, 461, 463, 465, 466, 469, 472, 473, 474, 475, 479, 480, 482, 483, 485, 486, 487, 488, 490, 491, 493, 495, 496, 498, 500, 501, 502, 503, 508, 511, 512, 514, 516, 521, 522, 523, 524, 525, 526, 527, 528, 530, 532, 534, 536, 539, 540, 542, 543, 544, 545, 546, 547, 550, 551, 553, 554, 556, 557, 558, 559, 564, 565, 568, 570, 571, 572, 573, 574, 578, 580, 581, 582, 585, 590, 591, 593, 595, 596, 598, 600, 604, 607, 609, 612, 615, 617, 622, 624, 629, 630, 631, 632, 633, 635, 636, 641, 645, 646, 647, 648, 649, 653, 654, 657, 661, 662, 663, 665, 666, 667, 668, 669, 671, 672, 676, 678, 679, 681, 682, 684, 690, 692, 693, 701, 703, 704, 706, 709, 712, 713, 721, 728, 736, 746, 759, 770, 776, 780, 782, 784, 802, 819, 820, 823, 829, 832, 833, 839, 848, 849, 850, 852, 856, 857, 858, 859, 860, 863, 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, 893, 894, 895, 903, 906, 907, 908, 910, 912, 916, 917, 918, 923, 924, 926, 933, 934, 936, 937, 938, 939, 940, 943, 944, 945, 946, 947, 949, 950, 952, 953, 954, 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, 994, 1019, 1020, 1028, 1030, 1031, 1032, 1033, 1035, 1036, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1077, 1078, 1080, 1081, 1084, 1087, 1089, 1090, 1099, 1100, 1103, 1104, 1106, 1107, 1108, 1109, 1110, 1111, 1113, 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, 1160, 1164, 1165, 1167, 1168, 1170, 1174, 1175, 1177, 1178, 1179, 1180, 1181, 1183, 1184, 1185, 1187, 1188, 1190, 1193, 1195, 1197, 1198, 1199, 1201, 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, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1251, 1254, 1258, 1261, 1262, 1283, 1284, 1286, 1290, 1291, 1292, 1294, 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, 1338, 1341, 1348, 1349, 1373, 1378, 1379, 1381, 1382, 1383, 1384, 1386, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, 1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1412, 1413, 1414, 1415, 1416, 1417, 1421, 1425, 1426, 1427, 1428, 1430, 1435, 1436, 1437, 1438, 1439, 1441, 1442, 1444, 1445, 1446, 1447, 1448, 1449, 1450, 1452, 1454, 1456, 1457, 1458, 1459, 1460, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 1480, 1481, 1482, 1483, 1484, 1485, 1487, 1488, 1489, 1490, 1491, 1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503, 1504, 1516, 1532, 1541, 1542, 1545, 1546, 1552, 1553, 1554, 1555, 1556, 1557, 1558, 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, 1598, 1599, 1600, 1601, 1602, 1603, 1604, 1606, 1608, 1609, 1610, 1611, 1612, 1613, 1614, 1615, 1616, 1617, 1618, 1619, 1620, 1621, 1622, 1623, 1624, 1625, 1626, 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, 1681, 1682, 1686, 1687, 1688, 1689, 1690, 1693, 1695, 1696, 1697, 1698, 1699, 1700, 1702, 1703, 1705, 1706, 1707, 1708, 1709, 1710, 1711, 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, 1749, 1750, 1752, 1753, 1754, 1755, 1756, 1757, 1758, 1759, 1760, 1761, 1762, 1763, 1764, 1769, 1776, 1778, 1782, 1785, 1786, 1787, 1788, 1793, 1796, 1797, 1799, 1802, 1803, 1806, 1807, 1810, 1811, 1813, 1816, 1817, 1818, 1819, 1820, 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, 1856, 1860, 1862, 1864, 1882, 1892, 1896, 1898, 1900, 1902, 1903, 1909, 1916, 1923, 1924, 1930, 1931, 1937, 1938, 1944, 1945, 1958, 1965, 1966, 1972, 1973, 1979, 1980, 1986, 1987, 1992, 1996, 1999, 2000, 2001, 2011, 2015, 2017, 2019, 2021, 2022, 2122]\n",
|
| 38 |
+
"N_RANDOM = int(os.environ.get('RMMOL_LIPID_N_RANDOM', '10000'))\n",
|
| 39 |
+
"SEED = int(os.environ.get('RMMOL_LIPID_SEED', '42'))\n",
|
| 40 |
+
"BATCH_SIZE = int(os.environ.get('RMMOL_BATCH_SIZE', '128'))\n",
|
| 41 |
+
"DEVICE = os.environ.get('RMMOL_DEVICE', 'cuda')\n",
|
| 42 |
+
"\n",
|
| 43 |
+
"LNPDB_ROOT = Path(os.environ.get(\n",
|
| 44 |
+
" 'LNPDB_ROOT',\n",
|
| 45 |
+
" '/home/sustech_spark/project/ecg/\u751f\u4fe1/scMCP/GraphWorld/MOMDGDP-main/dataset/LNPDB-main/data/LNPDB_for_AGILE',\n",
|
| 46 |
+
"))\n",
|
| 47 |
+
"RMMOL_TRUE_LOADER_DIR = Path(os.environ.get(\n",
|
| 48 |
+
" 'RMMOL_TRUE_LOADER_DIR',\n",
|
| 49 |
+
" '/home/sustech_spark/project/virtual cell/FUND/experiments',\n",
|
| 50 |
+
"))\n",
|
| 51 |
+
"RMMOL_CKPT = Path(os.environ.get(\n",
|
| 52 |
+
" 'RMMOL_CKPT',\n",
|
| 53 |
+
" '/home/sustech_spark/project/ecg/\u751f\u4fe1/scMCP/DrugGCL/lambda_0.0000/lightning_logs/checkpoints_full_DATIVE_v2_16mixed_20260525/epoch=0-step=12207.ckpt',\n",
|
| 54 |
+
"))\n",
|
| 55 |
+
"OUTPUT_DIR = Path(os.environ.get('RMMOL_LIPID_OUTPUT_DIR', 'outputs/lipid_conformation_distance'))\n",
|
| 56 |
+
"CACHE_ROOT = Path(os.environ.get('RMMOL_LIPID_CACHE_ROOT', str(OUTPUT_DIR)))\n",
|
| 57 |
+
"USE_CACHE = os.environ.get('RMMOL_LIPID_USE_CACHE', '1') == '1'\n",
|
| 58 |
+
"OUTPUT_DIR.mkdir(parents=True, exist_ok=True)\n",
|
| 59 |
+
"\n",
|
| 60 |
+
"print({\n",
|
| 61 |
+
" 'dataset': DATASET_NAME,\n",
|
| 62 |
+
" 'n_random': N_RANDOM,\n",
|
| 63 |
+
" 'seed': SEED,\n",
|
| 64 |
+
" 'device': DEVICE,\n",
|
| 65 |
+
" 'fixed_subset_size': len(EXACT_HELDOUT_INDICES),\n",
|
| 66 |
+
" 'use_cache': USE_CACHE,\n",
|
| 67 |
+
" 'cache_root': str(CACHE_ROOT),\n",
|
| 68 |
+
" 'output_dir': str(OUTPUT_DIR),\n",
|
| 69 |
+
"})\n"
|
| 70 |
+
]
|
| 71 |
+
},
|
| 72 |
+
{
|
| 73 |
+
"cell_type": "code",
|
| 74 |
+
"execution_count": null,
|
| 75 |
+
"metadata": {},
|
| 76 |
+
"outputs": [],
|
| 77 |
+
"source": [
|
| 78 |
+
"def stable_hash(values):\n",
|
| 79 |
+
" digest = hashlib.sha256()\n",
|
| 80 |
+
" for value in values:\n",
|
| 81 |
+
" digest.update(str(value).encode('utf-8', errors='ignore'))\n",
|
| 82 |
+
" digest.update(b'\\n')\n",
|
| 83 |
+
" return digest.hexdigest()[:16]\n",
|
| 84 |
+
"\n",
|
| 85 |
+
"def load_lnpdb_heldout_il_smiles(lnpdb_root):\n",
|
| 86 |
+
" frames = []\n",
|
| 87 |
+
" for filename, dataset in [\n",
|
| 88 |
+
" ('BL_2023_heldout_data.csv', 'BL_2023'),\n",
|
| 89 |
+
" ('LM_2019_heldout_data.csv', 'LM_2019'),\n",
|
| 90 |
+
" ('SL_2020_heldout_data.csv', 'SL_2020'),\n",
|
| 91 |
+
" ('ZC_2023_heldout_data.csv', 'ZC_2023'),\n",
|
| 92 |
+
" ]:\n",
|
| 93 |
+
" path = lnpdb_root / 'LNPDB_data' / filename\n",
|
| 94 |
+
" df = pd.read_csv(path)\n",
|
| 95 |
+
" if 'IL_SMILES' not in df.columns:\n",
|
| 96 |
+
" raise ValueError(f'Missing IL_SMILES in {path}')\n",
|
| 97 |
+
" frames.append(pd.DataFrame({\n",
|
| 98 |
+
" 'smiles': df['IL_SMILES'].astype('string').str.strip(),\n",
|
| 99 |
+
" 'source': dataset,\n",
|
| 100 |
+
" }))\n",
|
| 101 |
+
" data = pd.concat(frames, ignore_index=True).dropna(subset=['smiles']).reset_index(drop=True)\n",
|
| 102 |
+
" data = data.loc[data['smiles'].astype(str).str.len() > 0].reset_index(drop=True)\n",
|
| 103 |
+
" return data\n",
|
| 104 |
+
"\n",
|
| 105 |
+
"heldout = load_lnpdb_heldout_il_smiles(LNPDB_ROOT)\n",
|
| 106 |
+
"smiles = heldout['smiles'].astype(str).tolist()\n",
|
| 107 |
+
"print({'molecules': len(smiles), 'smiles_hash': stable_hash(smiles)})\n"
|
| 108 |
+
]
|
| 109 |
+
},
|
| 110 |
+
{
|
| 111 |
+
"cell_type": "code",
|
| 112 |
+
"execution_count": null,
|
| 113 |
+
"metadata": {},
|
| 114 |
+
"outputs": [],
|
| 115 |
+
"source": [
|
| 116 |
+
"def latest_embedding_cache(cache_root, smiles):\n",
|
| 117 |
+
" pattern = f'{DATASET_NAME}_rmmol_true_embeddings_*.npz'\n",
|
| 118 |
+
" for path in sorted((cache_root / 'embedding_cache').glob(pattern), reverse=True):\n",
|
| 119 |
+
" payload = np.load(path, allow_pickle=True)\n",
|
| 120 |
+
" if payload['smiles'].tolist() == smiles:\n",
|
| 121 |
+
" return path\n",
|
| 122 |
+
" return None\n",
|
| 123 |
+
"\n",
|
| 124 |
+
"def usr_cache_path(cache_root, smiles):\n",
|
| 125 |
+
" path = cache_root / 'usr_cache' / f'{DATASET_NAME}_usr_{stable_hash(smiles)}.npz'\n",
|
| 126 |
+
" if not path.exists():\n",
|
| 127 |
+
" return None\n",
|
| 128 |
+
" payload = np.load(path, allow_pickle=True)\n",
|
| 129 |
+
" if payload['smiles'].tolist() != smiles:\n",
|
| 130 |
+
" return None\n",
|
| 131 |
+
" return path\n",
|
| 132 |
+
"\n",
|
| 133 |
+
"def load_cached_payload(smiles):\n",
|
| 134 |
+
" if not USE_CACHE:\n",
|
| 135 |
+
" return None\n",
|
| 136 |
+
" emb_path = latest_embedding_cache(CACHE_ROOT, smiles)\n",
|
| 137 |
+
" usr_path = usr_cache_path(CACHE_ROOT, smiles)\n",
|
| 138 |
+
" if emb_path is None or usr_path is None:\n",
|
| 139 |
+
" return None\n",
|
| 140 |
+
" emb_payload = np.load(emb_path, allow_pickle=True)\n",
|
| 141 |
+
" usr_payload = np.load(usr_path, allow_pickle=True)\n",
|
| 142 |
+
" return {\n",
|
| 143 |
+
" 'embeddings': emb_payload['embeddings'].astype(np.float32),\n",
|
| 144 |
+
" 'valid_indices': emb_payload['valid'].astype(int),\n",
|
| 145 |
+
" 'usr': usr_payload['usr'].astype(float),\n",
|
| 146 |
+
" 'embedding_cache': str(emb_path),\n",
|
| 147 |
+
" 'usr_cache': str(usr_path),\n",
|
| 148 |
+
" }\n",
|
| 149 |
+
"\n",
|
| 150 |
+
"def load_or_encode_rmmol_embeddings(smiles):\n",
|
| 151 |
+
" cache_dir = OUTPUT_DIR / 'embedding_cache'\n",
|
| 152 |
+
" cache_dir.mkdir(parents=True, exist_ok=True)\n",
|
| 153 |
+
" cache_path = cache_dir / f'{DATASET_NAME}_rmmol_true_embeddings_{stable_hash(smiles)}.npz'\n",
|
| 154 |
+
" if cache_path.exists():\n",
|
| 155 |
+
" payload = np.load(cache_path, allow_pickle=True)\n",
|
| 156 |
+
" if payload['smiles'].tolist() == smiles:\n",
|
| 157 |
+
" print(f'Loaded local RMMol embedding cache: {cache_path}')\n",
|
| 158 |
+
" return payload['embeddings'].astype(np.float32), payload['valid'].astype(int)\n",
|
| 159 |
+
" if not RMMOL_CKPT.exists():\n",
|
| 160 |
+
" raise FileNotFoundError(f'Set RMMOL_CKPT to the RMMol checkpoint path: {RMMOL_CKPT}')\n",
|
| 161 |
+
" sys.path.insert(0, str(RMMOL_TRUE_LOADER_DIR))\n",
|
| 162 |
+
" from rmmol_true_loader import encode_smiles_true_loader\n",
|
| 163 |
+
" embeddings, valid_indices, cfg = encode_smiles_true_loader(\n",
|
| 164 |
+
" smiles, checkpoint=RMMOL_CKPT, batch_size=BATCH_SIZE, device=DEVICE\n",
|
| 165 |
+
" )\n",
|
| 166 |
+
" np.savez_compressed(\n",
|
| 167 |
+
" cache_path,\n",
|
| 168 |
+
" embeddings=embeddings.astype(np.float32),\n",
|
| 169 |
+
" valid=np.asarray(valid_indices, dtype=np.int64),\n",
|
| 170 |
+
" smiles=np.asarray(smiles, dtype=object),\n",
|
| 171 |
+
" )\n",
|
| 172 |
+
" print(f'Saved local RMMol embedding cache: {cache_path}')\n",
|
| 173 |
+
" return embeddings.astype(np.float32), np.asarray(valid_indices, dtype=int)\n"
|
| 174 |
+
]
|
| 175 |
+
},
|
| 176 |
+
{
|
| 177 |
+
"cell_type": "code",
|
| 178 |
+
"execution_count": null,
|
| 179 |
+
"metadata": {},
|
| 180 |
+
"outputs": [],
|
| 181 |
+
"source": [
|
| 182 |
+
"def optimize_conformation(mol, confId=0):\n",
|
| 183 |
+
" try:\n",
|
| 184 |
+
" props = AllChem.MMFFGetMoleculeProperties(mol)\n",
|
| 185 |
+
" ff = AllChem.MMFFGetMoleculeForceField(mol, props, confId=confId)\n",
|
| 186 |
+
" if ff:\n",
|
| 187 |
+
" ff.Initialize()\n",
|
| 188 |
+
" if ff.Minimize(maxIts=500) == 0:\n",
|
| 189 |
+
" return ff.CalcEnergy()\n",
|
| 190 |
+
" except Exception:\n",
|
| 191 |
+
" pass\n",
|
| 192 |
+
" try:\n",
|
| 193 |
+
" ff = AllChem.UFFGetMoleculeForceField(mol, confId=confId)\n",
|
| 194 |
+
" if ff:\n",
|
| 195 |
+
" ff.Initialize()\n",
|
| 196 |
+
" if ff.Minimize(maxIts=500) == 0:\n",
|
| 197 |
+
" return ff.CalcEnergy()\n",
|
| 198 |
+
" except Exception:\n",
|
| 199 |
+
" pass\n",
|
| 200 |
+
" return 1e9\n",
|
| 201 |
+
"\n",
|
| 202 |
+
"def generate_3d_conformation(mol):\n",
|
| 203 |
+
" params = AllChem.ETKDGv3()\n",
|
| 204 |
+
" params.randomSeed = 42\n",
|
| 205 |
+
" params.maxIterations = 2000\n",
|
| 206 |
+
" params.numThreads = 1\n",
|
| 207 |
+
" params.pruneRmsThresh = -1.0\n",
|
| 208 |
+
" params.useSmallRingTorsions = False\n",
|
| 209 |
+
" params.useMacrocycleTorsions = False\n",
|
| 210 |
+
" cid = AllChem.EmbedMolecule(mol, params)\n",
|
| 211 |
+
" if cid != -1:\n",
|
| 212 |
+
" optimize_conformation(mol, confId=0)\n",
|
| 213 |
+
" return True, 0\n",
|
| 214 |
+
" params = AllChem.ETKDGv3()\n",
|
| 215 |
+
" params.randomSeed = 42\n",
|
| 216 |
+
" params.maxIterations = 5000\n",
|
| 217 |
+
" params.numThreads = 1\n",
|
| 218 |
+
" params.enforceChirality = False\n",
|
| 219 |
+
" params.useSmallRingTorsions = False\n",
|
| 220 |
+
" params.useMacrocycleTorsions = False\n",
|
| 221 |
+
" cid = AllChem.EmbedMolecule(mol, params)\n",
|
| 222 |
+
" if cid != -1:\n",
|
| 223 |
+
" optimize_conformation(mol, confId=0)\n",
|
| 224 |
+
" return True, 0\n",
|
| 225 |
+
" params = AllChem.ETKDGv3()\n",
|
| 226 |
+
" params.useRandomCoords = True\n",
|
| 227 |
+
" params.randomSeed = 42\n",
|
| 228 |
+
" params.maxIterations = 5000\n",
|
| 229 |
+
" params.numThreads = 1\n",
|
| 230 |
+
" params.enforceChirality = False\n",
|
| 231 |
+
" cid = AllChem.EmbedMolecule(mol, params)\n",
|
| 232 |
+
" if cid != -1:\n",
|
| 233 |
+
" optimize_conformation(mol, confId=0)\n",
|
| 234 |
+
" return True, 0\n",
|
| 235 |
+
" return False, -1\n",
|
| 236 |
+
"\n",
|
| 237 |
+
"def compute_usr_robust(smi):\n",
|
| 238 |
+
" mol = Chem.MolFromSmiles(smi)\n",
|
| 239 |
+
" if mol is None:\n",
|
| 240 |
+
" return np.full(12, np.nan)\n",
|
| 241 |
+
" try:\n",
|
| 242 |
+
" Chem.SanitizeMol(mol)\n",
|
| 243 |
+
" except Exception:\n",
|
| 244 |
+
" try:\n",
|
| 245 |
+
" Chem.SanitizeMol(mol, sanitizeOps=Chem.SanitizeFlags.SANITIZE_ALL ^ Chem.SanitizeFlags.SANITIZE_KEKULIZE)\n",
|
| 246 |
+
" except Exception:\n",
|
| 247 |
+
" return np.full(12, np.nan)\n",
|
| 248 |
+
" try:\n",
|
| 249 |
+
" mol = Chem.AddHs(mol, addCoords=True)\n",
|
| 250 |
+
" except Exception:\n",
|
| 251 |
+
" return np.full(12, np.nan)\n",
|
| 252 |
+
" success, cid = generate_3d_conformation(mol)\n",
|
| 253 |
+
" if not success:\n",
|
| 254 |
+
" return np.full(12, np.nan)\n",
|
| 255 |
+
" try:\n",
|
| 256 |
+
" return np.asarray(rdMolDescriptors.GetUSR(mol, confId=cid), dtype=float)\n",
|
| 257 |
+
" except Exception:\n",
|
| 258 |
+
" return np.full(12, np.nan)\n",
|
| 259 |
+
"\n",
|
| 260 |
+
"def load_or_compute_usr(smiles, required_indices=None):\n",
|
| 261 |
+
" cache_dir = OUTPUT_DIR / 'usr_cache'\n",
|
| 262 |
+
" cache_dir.mkdir(parents=True, exist_ok=True)\n",
|
| 263 |
+
" cache_path = cache_dir / f'{DATASET_NAME}_usr_{stable_hash(smiles)}.npz'\n",
|
| 264 |
+
" if cache_path.exists():\n",
|
| 265 |
+
" payload = np.load(cache_path, allow_pickle=True)\n",
|
| 266 |
+
" if payload['smiles'].tolist() == smiles:\n",
|
| 267 |
+
" print(f'Loaded local USR cache: {cache_path}')\n",
|
| 268 |
+
" return payload['usr'].astype(float)\n",
|
| 269 |
+
" usr = np.full((len(smiles), 12), np.nan, dtype=float)\n",
|
| 270 |
+
" if required_indices is None:\n",
|
| 271 |
+
" required_indices = range(len(smiles))\n",
|
| 272 |
+
" required_indices = list(map(int, required_indices))\n",
|
| 273 |
+
" for step, idx in enumerate(required_indices, start=1):\n",
|
| 274 |
+
" smi = smiles[idx]\n",
|
| 275 |
+
" usr[idx] = compute_usr_robust(smi)\n",
|
| 276 |
+
" if step % 100 == 0:\n",
|
| 277 |
+
" print(f'USR conformers: {step}/{len(required_indices)}')\n",
|
| 278 |
+
" np.savez_compressed(cache_path, usr=usr, smiles=np.asarray(smiles, dtype=object))\n",
|
| 279 |
+
" print(f'Saved local USR cache: {cache_path}')\n",
|
| 280 |
+
" return usr\n"
|
| 281 |
+
]
|
| 282 |
+
},
|
| 283 |
+
{
|
| 284 |
+
"cell_type": "code",
|
| 285 |
+
"execution_count": null,
|
| 286 |
+
"metadata": {},
|
| 287 |
+
"outputs": [],
|
| 288 |
+
"source": [
|
| 289 |
+
"def build_common_pairs(common_indices, n_random=N_RANDOM, seed=SEED):\n",
|
| 290 |
+
" common_indices = np.asarray(sorted(set(map(int, common_indices))), dtype=np.int64)\n",
|
| 291 |
+
" if len(common_indices) < 2:\n",
|
| 292 |
+
" raise RuntimeError('Too few valid molecules to sample pairs.')\n",
|
| 293 |
+
" rng = np.random.default_rng(seed)\n",
|
| 294 |
+
" left = rng.choice(common_indices, size=n_random, replace=True)\n",
|
| 295 |
+
" right = rng.choice(common_indices, size=n_random, replace=True)\n",
|
| 296 |
+
" same = left == right\n",
|
| 297 |
+
" while np.any(same):\n",
|
| 298 |
+
" right[same] = rng.choice(common_indices, size=int(np.sum(same)), replace=True)\n",
|
| 299 |
+
" same = left == right\n",
|
| 300 |
+
" return np.column_stack([left, right]).astype(np.int64)\n",
|
| 301 |
+
"\n",
|
| 302 |
+
"def embedding_distances_for_pairs(embeddings, valid_indices, pairs):\n",
|
| 303 |
+
" valid_map = {int(original): row for row, original in enumerate(valid_indices)}\n",
|
| 304 |
+
" rows_i = np.asarray([valid_map[int(i)] for i in pairs[:, 0]], dtype=np.int64)\n",
|
| 305 |
+
" rows_j = np.asarray([valid_map[int(j)] for j in pairs[:, 1]], dtype=np.int64)\n",
|
| 306 |
+
" return np.linalg.norm(embeddings[rows_i] - embeddings[rows_j], axis=1).astype(float)\n",
|
| 307 |
+
"\n",
|
| 308 |
+
"def usr_distances_for_pairs(usr_matrix, pairs):\n",
|
| 309 |
+
" return np.linalg.norm(usr_matrix[pairs[:, 0]] - usr_matrix[pairs[:, 1]], axis=1).astype(float)\n",
|
| 310 |
+
"\n",
|
| 311 |
+
"def summarize_distances(embed_dist, conf_dist):\n",
|
| 312 |
+
" mask = np.isfinite(embed_dist) & np.isfinite(conf_dist)\n",
|
| 313 |
+
" embed = embed_dist[mask]\n",
|
| 314 |
+
" conf = conf_dist[mask]\n",
|
| 315 |
+
" spearman_r, spearman_p = spearmanr(embed, conf)\n",
|
| 316 |
+
" pearson_r, pearson_p = pearsonr(embed, conf)\n",
|
| 317 |
+
" return {\n",
|
| 318 |
+
" 'valid_points': int(len(embed)),\n",
|
| 319 |
+
" 'spearman_r': float(spearman_r),\n",
|
| 320 |
+
" 'spearman_p': float(spearman_p),\n",
|
| 321 |
+
" 'pearson_r': float(pearson_r),\n",
|
| 322 |
+
" 'pearson_p': float(pearson_p),\n",
|
| 323 |
+
" 'embedding_distance_mean': float(np.mean(embed)),\n",
|
| 324 |
+
" 'usr_conformation_distance_mean': float(np.mean(conf)),\n",
|
| 325 |
+
" }\n"
|
| 326 |
+
]
|
| 327 |
+
},
|
| 328 |
+
{
|
| 329 |
+
"cell_type": "code",
|
| 330 |
+
"execution_count": null,
|
| 331 |
+
"metadata": {},
|
| 332 |
+
"outputs": [],
|
| 333 |
+
"source": [
|
| 334 |
+
"cached = load_cached_payload(smiles)\n",
|
| 335 |
+
"fixed_subset = np.asarray(EXACT_HELDOUT_INDICES, dtype=np.int64)\n",
|
| 336 |
+
"if cached is not None:\n",
|
| 337 |
+
" embeddings = cached['embeddings']\n",
|
| 338 |
+
" valid_indices = cached['valid_indices']\n",
|
| 339 |
+
" usr_matrix = cached['usr']\n",
|
| 340 |
+
" cache_mode = 'cache'\n",
|
| 341 |
+
" print({'embedding_cache': cached['embedding_cache'], 'usr_cache': cached['usr_cache']})\n",
|
| 342 |
+
"else:\n",
|
| 343 |
+
" embeddings, valid_indices = load_or_encode_rmmol_embeddings(smiles)\n",
|
| 344 |
+
" usr_required = fixed_subset if len(fixed_subset) else None\n",
|
| 345 |
+
" usr_matrix = load_or_compute_usr(smiles, required_indices=usr_required)\n",
|
| 346 |
+
" cache_mode = 'computed'\n",
|
| 347 |
+
"\n",
|
| 348 |
+
"usr_valid = set(np.where(np.isfinite(usr_matrix).all(axis=1))[0].tolist())\n",
|
| 349 |
+
"rmmol_valid = set(map(int, valid_indices.tolist()))\n",
|
| 350 |
+
"if len(fixed_subset):\n",
|
| 351 |
+
" fixed_set = set(map(int, fixed_subset.tolist()))\n",
|
| 352 |
+
" missing_usr = sorted(fixed_set - usr_valid)\n",
|
| 353 |
+
" missing_rmmol = sorted(fixed_set - rmmol_valid)\n",
|
| 354 |
+
" if missing_usr or missing_rmmol:\n",
|
| 355 |
+
" raise RuntimeError({\n",
|
| 356 |
+
" 'missing_usr_first10': missing_usr[:10],\n",
|
| 357 |
+
" 'missing_rmmol_first10': missing_rmmol[:10],\n",
|
| 358 |
+
" })\n",
|
| 359 |
+
" common_indices = fixed_subset\n",
|
| 360 |
+
"else:\n",
|
| 361 |
+
" common_indices = np.asarray(sorted(usr_valid & rmmol_valid), dtype=np.int64)\n",
|
| 362 |
+
"pairs = build_common_pairs(common_indices)\n",
|
| 363 |
+
"embedding_distance = embedding_distances_for_pairs(embeddings, valid_indices, pairs)\n",
|
| 364 |
+
"conformation_distance = usr_distances_for_pairs(usr_matrix, pairs)\n",
|
| 365 |
+
"metrics = summarize_distances(embedding_distance, conformation_distance)\n",
|
| 366 |
+
"print({\n",
|
| 367 |
+
" 'cache_mode': cache_mode,\n",
|
| 368 |
+
" 'common_molecules': int(len(common_indices)),\n",
|
| 369 |
+
" 'pairs': int(len(pairs)),\n",
|
| 370 |
+
" **metrics,\n",
|
| 371 |
+
"})\n",
|
| 372 |
+
"\n",
|
| 373 |
+
"if len(fixed_subset) == 1067 and N_RANDOM == 10000 and SEED == 42:\n",
|
| 374 |
+
" assert len(common_indices) == 1067\n",
|
| 375 |
+
" assert abs(metrics['spearman_r'] - 0.8553455378850777) < 1e-9\n",
|
| 376 |
+
" assert abs(metrics['pearson_r'] - 0.9172573714535541) < 1e-9\n"
|
| 377 |
+
]
|
| 378 |
+
},
|
| 379 |
+
{
|
| 380 |
+
"cell_type": "code",
|
| 381 |
+
"execution_count": null,
|
| 382 |
+
"metadata": {},
|
| 383 |
+
"outputs": [],
|
| 384 |
+
"source": [
|
| 385 |
+
"def plot_activity_cliff_log_transform(layer2_dist_cliff, conf_dist_cliff, output_path='embed_vs_conf_log.png'):\n",
|
| 386 |
+
" mask = ~np.isnan(layer2_dist_cliff) & ~np.isnan(conf_dist_cliff)\n",
|
| 387 |
+
" embed_clean = layer2_dist_cliff[mask]\n",
|
| 388 |
+
" conf_clean = conf_dist_cliff[mask]\n",
|
| 389 |
+
" if len(embed_clean) < 10:\n",
|
| 390 |
+
" print('Warning: too few valid points to draw a meaningful plot.')\n",
|
| 391 |
+
" return None\n",
|
| 392 |
+
" r, p = spearmanr(embed_clean, conf_clean)\n",
|
| 393 |
+
" pear, pea = pearsonr(embed_clean, conf_clean)\n",
|
| 394 |
+
" embed_log = np.log1p(embed_clean)\n",
|
| 395 |
+
" conf_log = np.log1p(conf_clean)\n",
|
| 396 |
+
" scaler = MinMaxScaler()\n",
|
| 397 |
+
" embed_norm = scaler.fit_transform(embed_log.reshape(-1, 1)).flatten()\n",
|
| 398 |
+
" conf_norm = scaler.fit_transform(conf_log.reshape(-1, 1)).flatten()\n",
|
| 399 |
+
" available_fonts = {font.name for font in font_manager.fontManager.ttflist}\n",
|
| 400 |
+
" plt.rcParams.update({\n",
|
| 401 |
+
" 'font.family': 'Arial' if 'Arial' in available_fonts else 'DejaVu Sans',\n",
|
| 402 |
+
" 'axes.spines.top': False,\n",
|
| 403 |
+
" 'axes.spines.right': False,\n",
|
| 404 |
+
" 'axes.linewidth': 0.8,\n",
|
| 405 |
+
" 'font.size': 10,\n",
|
| 406 |
+
" 'axes.titlesize': 11,\n",
|
| 407 |
+
" 'axes.labelsize': 10,\n",
|
| 408 |
+
" 'xtick.labelsize': 8,\n",
|
| 409 |
+
" 'ytick.labelsize': 8,\n",
|
| 410 |
+
" 'legend.fontsize': 8,\n",
|
| 411 |
+
" 'figure.dpi': 300,\n",
|
| 412 |
+
" })\n",
|
| 413 |
+
" fig, ax = plt.subplots(figsize=(6, 5.5))\n",
|
| 414 |
+
" hb = ax.hexbin(embed_norm, conf_norm, gridsize=45, cmap='plasma', bins='log', mincnt=1, alpha=0.8)\n",
|
| 415 |
+
" cbar = plt.colorbar(hb, ax=ax, label='Log10(Count)')\n",
|
| 416 |
+
" cbar.ax.tick_params(labelsize=7)\n",
|
| 417 |
+
" ax.plot([0, 1], [0, 1], 'k--', alpha=0.4, linewidth=1, label='y=x')\n",
|
| 418 |
+
" z = np.polyfit(embed_norm, conf_norm, 1)\n",
|
| 419 |
+
" p_line = np.poly1d(z)\n",
|
| 420 |
+
" x_line = np.linspace(0, 1, 100)\n",
|
| 421 |
+
" ax.plot(x_line, p_line(x_line), 'r-', linewidth=2, label=f'Fit (slope={z[0]:.2f})')\n",
|
| 422 |
+
" ax.set_xlabel('Embedding Distance (log1p + normalized)', fontsize=10)\n",
|
| 423 |
+
" ax.set_ylabel('Conformational Distance (log1p + normalized)', fontsize=10)\n",
|
| 424 |
+
" ax.set_title(\n",
|
| 425 |
+
" f'RMMol lipid heldout IL_SMILES\\nSpearman rho = {r:.3f} (p={p:.2e}) Pearson rho = {pear:.3f} (p={pea:.2e})',\n",
|
| 426 |
+
" fontweight='bold',\n",
|
| 427 |
+
" fontsize=11,\n",
|
| 428 |
+
" )\n",
|
| 429 |
+
" ax.legend(loc='lower right', frameon=False, handlelength=1)\n",
|
| 430 |
+
" plt.tight_layout(pad=1.0)\n",
|
| 431 |
+
" fig.savefig(output_path, dpi=300, bbox_inches='tight')\n",
|
| 432 |
+
" return fig\n",
|
| 433 |
+
"\n",
|
| 434 |
+
"plot_path = OUTPUT_DIR / 'rmmol_lnpdb_heldout_il_smiles_embed_vs_conf_log.svg'\n",
|
| 435 |
+
"fig = plot_activity_cliff_log_transform(embedding_distance, conformation_distance, output_path=str(plot_path))\n",
|
| 436 |
+
"print(f'Figure written locally to: {plot_path}')\n"
|
| 437 |
+
]
|
| 438 |
+
}
|
| 439 |
+
],
|
| 440 |
+
"metadata": {
|
| 441 |
+
"kernelspec": {
|
| 442 |
+
"display_name": "Python 3",
|
| 443 |
+
"language": "python",
|
| 444 |
+
"name": "python3"
|
| 445 |
+
},
|
| 446 |
+
"language_info": {
|
| 447 |
+
"name": "python",
|
| 448 |
+
"pygments_lexer": "ipython3"
|
| 449 |
+
}
|
| 450 |
+
},
|
| 451 |
+
"nbformat": 4,
|
| 452 |
+
"nbformat_minor": 5
|
| 453 |
+
}
|