{
  "filename": "plot_1.png",
  "iteration": 1,
  "description": "Visualization of RCL hinge region comparison between inhibitory serpins and HSP47, showing structural incompatibility with protease inhibition",
  "timestamp": "2026-07-06 12:42:11",
  "code": "\nimport matplotlib.pyplot as plt\nimport matplotlib.patches as mpatches\nimport numpy as np\n\n# Create a figure showing the hinge region comparison\nfig, axes = plt.subplots(2, 1, figsize=(14, 10), gridspec_kw={'height_ratios': [3, 2]})\n\n# === Panel A: Hinge region residue comparison ===\nax1 = axes[0]\n\nserpins = {\n    \"\u03b11-Antitrypsin\\n(SERPINA1)\\nInhibitory\": {\"P14\": \"T\", \"P13\": \"E\", \"P12\": \"A\", \"P11\": \"A\", \"P10\": \"G\", \"P9\": \"A\", \"type\": \"inhibitory\"},\n    \"Antithrombin-III\\n(SERPINC1)\\nInhibitory\": {\"P14\": \"S\", \"P13\": \"E\", \"P12\": \"A\", \"P11\": \"A\", \"P10\": \"A\", \"P9\": \"S\", \"type\": \"inhibitory\"},\n    \"PAI-1\\n(SERPINE1)\\nInhibitory\": {\"P14\": \"T\", \"P13\": \"V\", \"P12\": \"A\", \"P11\": \"S\", \"P10\": \"S\", \"P9\": \"S\", \"type\": \"inhibitory\"},\n    \"Mouse HSP47\\n(SERPINH1)\\nP19324\": {\"P14\": \"N\", \"P13\": \"P\", \"P12\": \"F\", \"P11\": \"D\", \"P10\": \"Q\", \"P9\": \"D\", \"type\": \"test\"},\n    \"Human HSP47\\n(SERPINH1)\\nP50454\": {\"P14\": \"N\", \"P13\": \"P\", \"P12\": \"F\", \"P11\": \"D\", \"P10\": \"Q\", \"P9\": \"D\", \"type\": \"test\"},\n}\n\npositions = [\"P14\", \"P13\", \"P12\", \"P11\", \"P10\", \"P9\"]\ny_labels = list(serpins.keys())\n\nfor i, (name, data) in enumerate(serpins.items()):\n    for j, pos in enumerate(positions):\n        res = data[pos]\n        is_small = res in \"AGST\"\n        \n        # Color coding\n        if data[\"type\"] == \"test\":\n            if is_small:\n                color = \"#4CAF50\"  # green\n            else:\n                color = \"#F44336\"  # red\n        elif data[\"type\"] == \"inhibitory\":\n            if is_small:\n                color = \"#4CAF50\"  # green\n            else:\n                color = \"#FFC107\"  # amber\n        else:\n            color = \"#9E9E9E\"\n        \n        rect = plt.Rectangle((j - 0.4, i - 0.4), 0.8, 0.8, \n                            facecolor=color, edgecolor='white', linewidth=2,\n                            alpha=0.8)\n        ax1.add_patch(rect)\n        \n        # Add residue letter\n        fontweight = 'bold'\n        fontcolor = 'white' if not is_small and data[\"type\"] == \"test\" else 'black'\n        ax1.text(j, i, res, ha='center', va='center', fontsize=16, \n                fontweight=fontweight, color=fontcolor)\n\nax1.set_xlim(-0.6, len(positions) - 0.4)\nax1.set_ylim(-0.6, len(y_labels) - 0.4)\nax1.set_xticks(range(len(positions)))\nax1.set_xticklabels(positions, fontsize=13, fontweight='bold')\nax1.set_yticks(range(len(y_labels)))\nax1.set_yticklabels(y_labels, fontsize=11)\nax1.set_title(\"RCL Hinge Region: Inhibitory Serpins vs HSP47\\n(Small residues A/G/S/T required for inhibitory mechanism)\", \n              fontsize=14, fontweight='bold', pad=15)\n\n# Legend\nlegend_elements = [\n    mpatches.Patch(facecolor='#4CAF50', alpha=0.8, label='Small residue (A/G/S/T) - compatible with inhibition'),\n    mpatches.Patch(facecolor='#F44336', alpha=0.8, label='Large/charged residue - INCOMPATIBLE with RCL insertion'),\n    mpatches.Patch(facecolor='#FFC107', alpha=0.8, label='Non-small in inhibitory serpin (tolerated)'),\n]\nax1.legend(handles=legend_elements, loc='upper right', fontsize=9, framealpha=0.9)\n\n# Add a dividing line between inhibitory and test serpins\nax1.axhline(y=2.5, color='black', linestyle='--', linewidth=1.5, alpha=0.5)\nax1.text(5.3, 3.5, 'HSP47\\n(non-inhibitory)', fontsize=10, fontstyle='italic', \n         ha='center', va='center', color='#F44336', fontweight='bold')\nax1.text(5.3, 1.0, 'Inhibitory\\nserpins', fontsize=10, fontstyle='italic', \n         ha='center', va='center', color='#4CAF50', fontweight='bold')\n\n# === Panel B: Small residue count bar chart ===\nax2 = axes[1]\n\nbar_names = [\"\u03b11-AT\\n(SERPINA1)\", \"AT-III\\n(SERPINC1)\", \"PAI-1\\n(SERPINE1)\", \n             \"Mouse HSP47\\n(SERPINH1)\", \"Human HSP47\\n(SERPINH1)\"]\nsmall_counts = [5, 5, 5, 0, 0]\ncolors = ['#4CAF50', '#4CAF50', '#4CAF50', '#F44336', '#F44336']\n\nbars = ax2.bar(range(len(bar_names)), small_counts, color=colors, edgecolor='white', \n               linewidth=2, alpha=0.85, width=0.6)\n\n# Add count labels\nfor bar, count in zip(bars, small_counts):\n    ax2.text(bar.get_x() + bar.get_width()/2., bar.get_height() + 0.1,\n            f'{count}/6', ha='center', va='bottom', fontweight='bold', fontsize=14)\n\nax2.set_xticks(range(len(bar_names)))\nax2.set_xticklabels(bar_names, fontsize=10)\nax2.set_ylabel(\"Small residues in hinge\\n(P14-P9)\", fontsize=12)\nax2.set_ylim(0, 7)\nax2.set_title(\"Hinge Region Small Residue Count\", fontsize=13, fontweight='bold')\nax2.axhline(y=3, color='gray', linestyle=':', linewidth=1, alpha=0.5)\nax2.text(4.5, 3.2, 'Threshold for\\ninhibitory activity', fontsize=9, \n         color='gray', ha='center', fontstyle='italic')\n\n# Add dividing line\nax2.axvline(x=2.5, color='black', linestyle='--', linewidth=1.5, alpha=0.3)\n\nplt.tight_layout()\nplt.savefig(\"hinge_region_comparison.png\", dpi=150, bbox_inches='tight')\nplt.show()\nprint(\"Figure saved: hinge_region_comparison.png\")\n",
  "plot_number": 1
}