Files
Graph-Preflexor-8b_12292025/Colab_graph_reasoning.ipynb

1314 lines
260 KiB
Plaintext
Raw Permalink Normal View History

{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"gpuType": "A100"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU",
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"7f3133f750e7481cb8c4eeb1b27f9328": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HBoxModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HBoxView",
"box_style": "",
"children": [
"IPY_MODEL_973c030cda574357989f3134f38dd48b",
"IPY_MODEL_f07bc4a9ecc64358967298bd96837800",
"IPY_MODEL_5bc805a58a2d4078b83366712daf60a9"
],
"layout": "IPY_MODEL_eda42e77d6814dd4a0afbd8f95ebd7f0"
}
},
"973c030cda574357989f3134f38dd48b": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_4699eb03bc1f48e48f79821f5193444b",
"placeholder": "",
"style": "IPY_MODEL_a0c19a54ccea478a92fd3ff02ddf1dd3",
"value": "Fetching4files:100%"
}
},
"f07bc4a9ecc64358967298bd96837800": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "FloatProgressModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "ProgressView",
"bar_style": "success",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_5b6d595f32e045d09b73161efe45cec8",
"max": 4,
"min": 0,
"orientation": "horizontal",
"style": "IPY_MODEL_6d77be6cbe334542bc62b27fcdaea5f2",
"value": 4
}
},
"5bc805a58a2d4078b83366712daf60a9": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_6210fc80449542a4a150e67754a6f627",
"placeholder": "",
"style": "IPY_MODEL_7c43276f79784da9a148988976a40a28",
"value": "4/4[00:00<00:00,3.51it/s]"
}
},
"eda42e77d6814dd4a0afbd8f95ebd7f0": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"4699eb03bc1f48e48f79821f5193444b": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"a0c19a54ccea478a92fd3ff02ddf1dd3": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
},
"5b6d595f32e045d09b73161efe45cec8": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"6d77be6cbe334542bc62b27fcdaea5f2": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "ProgressStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"bar_color": null,
"description_width": ""
}
},
"6210fc80449542a4a150e67754a6f627": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"7c43276f79784da9a148988976a40a28": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
},
"13b2dbe03f6b41a5a745685619ba5853": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HBoxModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HBoxModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HBoxView",
"box_style": "",
"children": [
"IPY_MODEL_791cec84778448688b07f91918043038",
"IPY_MODEL_9f3015b0adde409b85b9c7cbaa73d9a1",
"IPY_MODEL_12fb69fb429f4f9f8c47f628194787af"
],
"layout": "IPY_MODEL_6c7657b626ae4e08baf95bfb83595b30"
}
},
"791cec84778448688b07f91918043038": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_49fc826630974b3aa4bebc66990bf572",
"placeholder": "",
"style": "IPY_MODEL_a5e965f89ea3400391cd83a61fad8a0a",
"value": "Loadingcheckpointshards:100%"
}
},
"9f3015b0adde409b85b9c7cbaa73d9a1": {
"model_module": "@jupyter-widgets/controls",
"model_name": "FloatProgressModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "FloatProgressModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "ProgressView",
"bar_style": "success",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_4fe6c5cd6d914afda8c9aa724760164a",
"max": 4,
"min": 0,
"orientation": "horizontal",
"style": "IPY_MODEL_8cbfed9943954d9ca62ee3a2fbd49404",
"value": 4
}
},
"12fb69fb429f4f9f8c47f628194787af": {
"model_module": "@jupyter-widgets/controls",
"model_name": "HTMLModel",
"model_module_version": "1.5.0",
"state": {
"_dom_classes": [],
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "HTMLModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/controls",
"_view_module_version": "1.5.0",
"_view_name": "HTMLView",
"description": "",
"description_tooltip": null,
"layout": "IPY_MODEL_8025e3937b37446c86958e022eaccb6e",
"placeholder": "",
"style": "IPY_MODEL_9c05b4ffb6d14d76982cf1d7aa0b297b",
"value": "4/4[00:04<00:00,1.03s/it]"
}
},
"6c7657b626ae4e08baf95bfb83595b30": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"49fc826630974b3aa4bebc66990bf572": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"a5e965f89ea3400391cd83a61fad8a0a": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
},
"4fe6c5cd6d914afda8c9aa724760164a": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"8cbfed9943954d9ca62ee3a2fbd49404": {
"model_module": "@jupyter-widgets/controls",
"model_name": "ProgressStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "ProgressStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"bar_color": null,
"description_width": ""
}
},
"8025e3937b37446c86958e022eaccb6e": {
"model_module": "@jupyter-widgets/base",
"model_name": "LayoutModel",
"model_module_version": "1.2.0",
"state": {
"_model_module": "@jupyter-widgets/base",
"_model_module_version": "1.2.0",
"_model_name": "LayoutModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "LayoutView",
"align_content": null,
"align_items": null,
"align_self": null,
"border": null,
"bottom": null,
"display": null,
"flex": null,
"flex_flow": null,
"grid_area": null,
"grid_auto_columns": null,
"grid_auto_flow": null,
"grid_auto_rows": null,
"grid_column": null,
"grid_gap": null,
"grid_row": null,
"grid_template_areas": null,
"grid_template_columns": null,
"grid_template_rows": null,
"height": null,
"justify_content": null,
"justify_items": null,
"left": null,
"margin": null,
"max_height": null,
"max_width": null,
"min_height": null,
"min_width": null,
"object_fit": null,
"object_position": null,
"order": null,
"overflow": null,
"overflow_x": null,
"overflow_y": null,
"padding": null,
"right": null,
"top": null,
"visibility": null,
"width": null
}
},
"9c05b4ffb6d14d76982cf1d7aa0b297b": {
"model_module": "@jupyter-widgets/controls",
"model_name": "DescriptionStyleModel",
"model_module_version": "1.5.0",
"state": {
"_model_module": "@jupyter-widgets/controls",
"_model_module_version": "1.5.0",
"_model_name": "DescriptionStyleModel",
"_view_count": null,
"_view_module": "@jupyter-widgets/base",
"_view_module_version": "1.2.0",
"_view_name": "StyleView",
"description_width": ""
}
}
}
}
},
"cells": [
{
"cell_type": "code",
"source": [
"# ============================================================\n",
"# Graph-native reasoning with visualization\n",
"# ============================================================\n",
"\n",
"import os\n",
"import re\n",
"import json\n",
"import math\n",
"import logging\n",
"from datetime import datetime\n",
"\n",
"import torch\n",
"import networkx as nx\n",
"import matplotlib.pyplot as plt\n",
"from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig\n",
"\n",
"# Interactive graph (Jupyter)\n",
"from IPython.display import display, Markdown\n",
"import ipywidgets as widgets\n",
"\n",
"# Try PyVis for interactive HTML visualization (recommended)\n",
"PYVIS_AVAILABLE = True\n",
"try:\n",
" from pyvis.network import Network\n",
"except Exception:\n",
" PYVIS_AVAILABLE = False\n",
"\n",
"# ----------------------------\n",
"# Run directory + logging\n",
"# ----------------------------\n",
"\n",
"RUN_ID = datetime.now().strftime(\"%Y%m%d_%H%M%S\")\n",
"OUT_DIR = os.path.abspath(f\"./run_{RUN_ID}\")\n",
"os.makedirs(OUT_DIR, exist_ok=True)\n",
"\n",
"LOG_PATH = os.path.join(OUT_DIR, \"run.log\")\n",
"logging.basicConfig(\n",
" level=logging.INFO,\n",
" format=\"%(asctime)s | %(levelname)s | %(message)s\",\n",
" handlers=[logging.FileHandler(LOG_PATH), logging.StreamHandler()],\n",
")\n",
"log = logging.getLogger(\"graph-preflexor\")\n",
"\n",
"display(Markdown(f\"### Output directory\\n`{OUT_DIR}`\"))\n",
"\n",
"# ----------------------------\n",
"# Configuration\n",
"# ----------------------------\n",
"\n",
"# token = \"hf_...\" # optional\n",
"token = None\n",
"\n",
"MODEL_NAME = \"lamm-mit/Graph-Preflexor-8b_12292025\"\n",
"PROMPT = (\n",
" \"What are the molecular mechanisms underlying the extraordinary toughness of spider dragline silk? \"\n",
" \"Investigate the role of beta-sheet nanocrystals, amorphous regions, and hierarchical structure in \"\n",
" \"energy dissipation and mechanical performance.\"\n",
")\n",
"\n",
"MAX_NEW_TOKENS = 32_768\n",
"THINK_END_TOKEN_ID = 151668 # </think> (model-specific)\n",
"\n",
"DO_SAMPLE = True\n",
"GEN_TEMPERATURE = 0.2\n",
"\n",
"GRAPH_JSON_OPEN = \"<graph_json>\"\n",
"GRAPH_JSON_CLOSE = \"</graph_json>\"\n",
"\n",
"# ----------------------------\n",
"# Utility helpers\n",
"# ----------------------------\n",
"\n",
"def atomic_write_text(path: str, text: str) -> None:\n",
" \"\"\"Write text atomically to avoid partial files on crash.\"\"\"\n",
" tmp = path + \".tmp\"\n",
" with open(tmp, \"w\", encoding=\"utf-8\") as f:\n",
" f.write(text)\n",
" os.replace(tmp, path)\n",
"\n",
"def safe_json_loads(s: str):\n",
" try:\n",
" return json.loads(s)\n",
" except Exception:\n",
" return None\n",
"\n",
"def split_thinking(output_ids, tokenizer, think_end_id):\n",
" \"\"\"\n",
" Split generated tokens into (thinking, final_content) based on </think>.\n",
" Falls back gracefully if no thinking block is present.\n",
" \"\"\"\n",
" try:\n",
" split_idx = len(output_ids) - output_ids[::-1].index(think_end_id)\n",
" except ValueError:\n",
" split_idx = 0\n",
"\n",
" thinking = tokenizer.decode(output_ids[:split_idx], skip_special_tokens=True).strip()\n",
" content = tokenizer.decode(output_ids[split_idx:], skip_special_tokens=True).strip()\n",
" return thinking, content\n",
"\n",
"def extract_graph_json_block(text: str):\n",
" \"\"\"\n",
" Extract first <graph_json>...</graph_json> block.\n",
" Returns (raw_json_text, parsed_obj) or (None, None).\n",
" Recovery: locate first '{' and last '}' inside tag block.\n",
" \"\"\"\n",
" m = re.search(\n",
" rf\"{re.escape(GRAPH_JSON_OPEN)}(.*?){re.escape(GRAPH_JSON_CLOSE)}\",\n",
" text,\n",
" flags=re.DOTALL\n",
" )\n",
" if not m:\n",
" return None, None\n",
"\n",
" inner = m.group(1).strip()\n",
"\n",
" # direct\n",
" obj = safe_json_loads(inner)\n",
" if obj is not None:\n",
" return inner, obj\n",
"\n",
" # recovery\n",
" i1 = inner.find(\"{\")\n",
" i2 = inner.rfind(\"}\")\n",
" if i1 != -1 and i2 != -1 and i2 > i1:\n",
" candidate = inner[i1:i2+1].strip()\n",
" obj2 = safe_json_loads(candidate)\n",
" if obj2 is not None:\n",
" return candidate, obj2\n",
"\n",
" return inner, None\n",
"\n",
"def build_nx_graph(graph_obj: dict) -> nx.DiGraph:\n",
" \"\"\"Build NetworkX DiGraph from {nodes:[{id}], edges:[{source,target,relation}]}.\"\"\"\n",
" G = nx.DiGraph()\n",
"\n",
" nodes = graph_obj.get(\"nodes\", [])\n",
" edges = graph_obj.get(\"edges\", [])\n",
"\n",
" for n in nodes:\n",
" nid = n.get(\"id\")\n",
" if nid:\n",
" attrs = {k: v for k, v in n.items() if k != \"id\"}\n",
" G.add_node(nid, **attrs)\n",
"\n",
" for e in edges:\n",
" src = e.get(\"source\")\n",
" tgt = e.get(\"target\")\n",
" if not (src and tgt):\n",
" continue\n",
" rel = e.get(\"relation\", \"\")\n",
" attrs = {k: v for k, v in e.items() if k not in (\"source\", \"target\")}\n",
" attrs[\"relation\"] = rel\n",
"\n",
" if src not in G:\n",
" G.add_node(src)\n",
" if tgt not in G:\n",
" G.add_node(tgt)\n",
"\n",
" G.add_edge(src, tgt, **attrs)\n",
"\n",
" return G\n",
"\n",
"def layout_graph(G: nx.DiGraph):\n",
" \"\"\"Prefer graphviz dot if available; else spring layout.\"\"\"\n",
" try:\n",
" from networkx.drawing.nx_pydot import graphviz_layout\n",
" pos = graphviz_layout(G, prog=\"dot\")\n",
" return pos, \"graphviz(dot)\"\n",
" except Exception:\n",
" pos = nx.spring_layout(G, seed=7, k=0.9)\n",
" return pos, \"spring_layout\"\n",
"\n",
"def visualize_and_save_static(G: nx.DiGraph, out_dir: str, title: str = \"Graph\"):\n",
" \"\"\"Save PNG + SVG with edge labels.\"\"\"\n",
" png_path = os.path.join(out_dir, \"graph.png\")\n",
" svg_path = os.path.join(out_dir, \"graph.svg\")\n",
"\n",
" if G.number_of_nodes() == 0:\n",
" log.warning(\"Graph has 0 nodes; skipping static visualization.\")\n",
" return None, None\n",
"\n",
" pos, layout_used = layout_graph(G)\n",
" n = G.number_of_nodes()\n",
" fig_w = min(24, max(12, 0.9 * math.sqrt(n) * 8))\n",
" fig_h = min(14, max(7, 0.6 * math.sqrt(n) * 6))\n",
"\n",
" plt.figure(figsize=(fig_w, fig_h))\n",
" nx.draw_networkx_nodes(G, pos, node_size=2200, linewidths=1.2)\n",
" nx.draw_networkx_edges(G, pos, arrows=True, arrowstyle=\"-|>\", arrowsize=18, width=1.6)\n",
" nx.draw_networkx_labels(G, pos, font_size=10)\n",
"\n",
" edge_labels = {(u, v): (d.get(\"relation\") or \"\") for u, v, d in G.edges(data=True)}\n",
" nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=9, rotate=False)\n",
"\n",
" plt.title(f\"{title} ({layout_used})\")\n",
" plt.axis(\"off\")\n",
" plt.tight_layout()\n",
"\n",
" plt.savefig(png_path, dpi=300, bbox_inches=\"tight\")\n",
" plt.savefig(svg_path, bbox_inches=\"tight\")\n",
" plt.show()\n",
" plt.close()\n",
"\n",
" return png_path, svg_path\n",
"\n",
"def visualize_interactive_pyvis(G: nx.DiGraph, out_dir: str, html_name: str = \"graph_interactive.html\"):\n",
" \"\"\"\n",
" Create an interactive HTML visualization (PyVis) and display it in the notebook.\n",
" Also saves HTML to disk.\n",
" \"\"\"\n",
" if not PYVIS_AVAILABLE:\n",
" log.warning(\"PyVis not available. Install with: pip install pyvis\")\n",
" return None\n",
"\n",
" html_path = os.path.join(out_dir, html_name)\n",
"\n",
" net = Network(\n",
" height=\"750px\",\n",
" width=\"100%\",\n",
" directed=True,\n",
" bgcolor=\"#ffffff\",\n",
" font_color=\"#111111\",\n",
" notebook=True,\n",
" )\n",
"\n",
" # Make it less jittery / more readable\n",
" net.barnes_hut(gravity=-20000, central_gravity=0.2, spring_length=150, spring_strength=0.03, damping=0.8)\n",
"\n",
" # Add nodes\n",
" for n, attrs in G.nodes(data=True):\n",
" title = \"<br>\".join([f\"{k}: {v}\" for k, v in attrs.items()]) if attrs else n\n",
" net.add_node(n, label=n, title=title)\n",
"\n",
" # Add edges with relation labels\n",
" for u, v, attrs in G.edges(data=True):\n",
" rel = attrs.get(\"relation\", \"\")\n",
" title = \"<br>\".join([f\"{k}: {v}\" for k, v in attrs.items()]) if attrs else rel\n",
" net.add_edge(u, v, label=rel, title=title, arrows=\"to\")\n",
"\n",
" # UI controls\n",
" net.show_buttons(filter_=[\"physics\", \"layout\", \"interaction\"])\n",
"\n",
" net.save_graph(html_path)\n",
"\n",
" # Display in notebook\n",
" from IPython.display import IFrame\n",
" display(IFrame(src=html_path, width=\"100%\", height=800))\n",
"\n",
" return html_path\n",
"\n",
"# ----------------------------\n",
"# Generation\n",
"# ----------------------------\n",
"\n",
"try:\n",
" log.info(f\"Output dir: {OUT_DIR}\")\n",
" log.info(f\"Model: {MODEL_NAME}\")\n",
"\n",
" tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, token=token)\n",
" model = AutoModelForCausalLM.from_pretrained(\n",
" MODEL_NAME,\n",
" torch_dtype=\"auto\",\n",
" device_map=\"auto\",\n",
" token=token,\n",
" )\n",
" model.eval()\n",
"\n",
" messages = [{\"role\": \"user\", \"content\": PROMPT}]\n",
" prompt_text = tokenizer.apply_chat_template(\n",
" messages,\n",
" tokenize=False,\n",
" add_generation_prompt=True,\n",
" enable_thinking=True,\n",
" )\n",
"\n",
" # Save prompt and rendered template for reproducibility\n",
" atomic_write_text(os.path.join(OUT_DIR, \"prompt.txt\"), PROMPT)\n",
" atomic_write_text(os.path.join(OUT_DIR, \"prompt_rendered.txt\"), prompt_text)\n",
"\n",
" model_inputs = tokenizer(prompt_text, return_tensors=\"pt\").to(model.device)\n",
"\n",
" gen_config = GenerationConfig(\n",
" max_new_tokens=MAX_NEW_TOKENS,\n",
" do_sample=DO_SAMPLE,\n",
" temperature=GEN_TEMPERATURE,\n",
" )\n",
"\n",
" log.info(\"Generating...\")\n",
" with torch.no_grad():\n",
" generated = model.generate(**model_inputs, generation_config=gen_config)\n",
"\n",
" output_ids = generated[0, model_inputs.input_ids.shape[1]:].tolist()\n",
" thinking, content = split_thinking(output_ids, tokenizer, THINK_END_TOKEN_ID)\n",
"\n",
" # Save ALL text outputs (no truncation)\n",
" atomic_write_text(os.path.join(OUT_DIR, \"thinking.txt\"), thinking or \"\")\n",
" atomic_write_text(os.path.join(OUT_DIR, \"content.txt\"), content or \"\")\n",
" atomic_write_text(os.path.join(OUT_DIR, \"full_output.txt\"), (thinking + \"\\n\\n\" + content).strip())\n",
"\n",
" # Show raw thinking and raw final output in the notebook (no truncation)\n",
" display(Markdown(\"## THINKING (raw)\"))\n",
" print(thinking if thinking else \"[no thinking content detected]\")\n",
"\n",
" display(Markdown(\"## FINAL OUTPUT (raw)\"))\n",
" print(content if content else \"[no final content detected]\")\n",
"\n",
" # ----------------------------\n",
" # Extract graph_json + build graph\n",
" # ----------------------------\n",
"\n",
" full_text = (thinking + \"\\n\" + content).strip()\n",
"\n",
" raw_block, graph_obj = extract_graph_json_block(full_text)\n",
"\n",
" if raw_block is None:\n",
" display(Markdown(\"### Graph extraction\\nNo `<graph_json>...</graph_json>` block found.\"))\n",
" log.warning(\"No <graph_json> block found.\")\n",
" else:\n",
" atomic_write_text(os.path.join(OUT_DIR, \"graph_json_raw.txt\"), raw_block)\n",
"\n",
" if graph_obj is None:\n",
" display(Markdown(\"### Graph extraction\\nFound `<graph_json>` block, but JSON parsing failed. Saved raw block to disk.\"))\n",
" log.warning(\"Found <graph_json> but JSON parsing failed.\")\n",
" else:\n",
" atomic_write_text(os.path.join(OUT_DIR, \"graph.json\"), json.dumps(graph_obj, indent=2, ensure_ascii=False))\n",
"\n",
" G = build_nx_graph(graph_obj)\n",
"\n",
" display(Markdown(f\"### Graph summary\\n- Nodes: **{G.number_of_nodes()}**\\n- Edges: **{G.number_of_edges()}**\"))\n",
" if G.number_of_nodes() > 0:\n",
" display(Markdown(\"### Static graph (PNG/SVG saved)\"))\n",
" png_path, svg_path = visualize_and_save_static(G, OUT_DIR, title=\"Graph-PRefLexOR Output Graph\")\n",
"\n",
" if png_path and svg_path:\n",
" display(Markdown(f\"Saved:\\n- `{png_path}`\\n- `{svg_path}`\"))\n",
"\n",
" display(Markdown(\"### Interactive graph (HTML saved)\"))\n",
" html_path = visualize_interactive_pyvis(G, OUT_DIR, html_name=\"graph_interactive.html\")\n",
" if html_path:\n",
" display(Markdown(f\"Saved:\\n- `{html_path}`\"))\n",
" else:\n",
" display(Markdown(\"Graph is empty; nothing to visualize.\"))\n",
"\n",
"except Exception as e:\n",
" # Hard fail-safe: log + crash marker\n",
" log.exception(f\"Fatal error: {e}\")\n",
" try:\n",
" atomic_write_text(os.path.join(OUT_DIR, \"CRASH.txt\"), str(e))\n",
" except Exception:\n",
" pass\n",
" raise\n"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 1000,
"referenced_widgets": [
"7f3133f750e7481cb8c4eeb1b27f9328",
"973c030cda574357989f3134f38dd48b",
"f07bc4a9ecc64358967298bd96837800",
"5bc805a58a2d4078b83366712daf60a9",
"eda42e77d6814dd4a0afbd8f95ebd7f0",
"4699eb03bc1f48e48f79821f5193444b",
"a0c19a54ccea478a92fd3ff02ddf1dd3",
"5b6d595f32e045d09b73161efe45cec8",
"6d77be6cbe334542bc62b27fcdaea5f2",
"6210fc80449542a4a150e67754a6f627",
"7c43276f79784da9a148988976a40a28",
"13b2dbe03f6b41a5a745685619ba5853",
"791cec84778448688b07f91918043038",
"9f3015b0adde409b85b9c7cbaa73d9a1",
"12fb69fb429f4f9f8c47f628194787af",
"6c7657b626ae4e08baf95bfb83595b30",
"49fc826630974b3aa4bebc66990bf572",
"a5e965f89ea3400391cd83a61fad8a0a",
"4fe6c5cd6d914afda8c9aa724760164a",
"8cbfed9943954d9ca62ee3a2fbd49404",
"8025e3937b37446c86958e022eaccb6e",
"9c05b4ffb6d14d76982cf1d7aa0b297b"
]
},
"id": "Skdn8HeK0HNN",
"outputId": "b847abee-eb6c-41c4-f881-d457a9ea5ab7"
},
"execution_count": 1,
"outputs": [
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Markdown object>"
],
"text/markdown": "### Output directory\n`/content/run_20251229_112218`"
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"/usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_auth.py:86: UserWarning: \n",
"Access to the secret `HF_TOKEN` has not been granted on this notebook.\n",
"You will not be requested again.\n",
"Please restart the session if you want to be prompted again.\n",
" warnings.warn(\n",
"`torch_dtype` is deprecated! Use `dtype` instead!\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"Fetching 4 files: 0%| | 0/4 [00:00<?, ?it/s]"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "7f3133f750e7481cb8c4eeb1b27f9328"
}
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"Loading checkpoint shards: 0%| | 0/4 [00:00<?, ?it/s]"
],
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "13b2dbe03f6b41a5a745685619ba5853"
}
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"`generation_config` default values have been modified to match model-specific defaults: {'top_k': 20, 'top_p': 0.95, 'pad_token_id': 151643, 'bos_token_id': 151643, 'eos_token_id': [151645, 151643]}. If this is not desired, please set these values explicitly.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Markdown object>"
],
"text/markdown": "## THINKING (raw)"
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"<think>\n",
"<brainstorm>\n",
"Spider dragline silk is renowned for its exceptional toughness, surpassing many synthetic fibers like Kevlar and steel in energy absorption per unit mass. Key players: beta-sheet nanocrystals (ordered crystalline regions), amorphous regions (disordered, flexible chains), and hierarchical structure (nanoscale to macroscale). Hypotheses: toughness arises from synergistic energy dissipation mechanisms—beta-sheets provide high strength via hydrogen bonding networks, amorphous regions enable extensibility and viscoelasticity, and hierarchical organization distributes stress, prevents crack propagation. Interactions: beta-sheets act as load-bearing nanocrystals that slide or rearrange under stress, dissipating energy; amorphous regions absorb energy through chain slippage and unfolding; hierarchical structure (e.g., nanocrystals embedded in amorphous matrix) allows strain localization without catastrophic failure. Variables: protein composition (e.g., glycine-rich amorphous, alanine-rich beta-sheets), humidity (affects hydrogen bonding), temperature (viscoelastic transitions). Broader concepts: biomimetic materials, protein engineering, fracture mechanics. Creative angle: silk's toughness mimics natural composites like bone or nacre, but with protein-based nanocrystals instead of mineral platelets.\n",
"</brainstorm>\n",
"\n",
"<graph>\n",
"Core entities: Beta-Sheet Nanocrystals, Amorphous Regions, Hierarchical Structure, Hydrogen Bonds, Chain Slippage, Unfolding, Stress Distribution, Energy Dissipation, Mechanical Toughness, Protein Chains, Humidity, Temperature.\n",
"Relationships: Beta-Sheet Nanocrystals form via Hydrogen Bonds → provide High Strength; Amorphous Regions enable Chain Slippage → allow Extensibility; Hierarchical Structure embeds Beta-Sheets in Amorphous Regions → enables Stress Distribution; Chain Slippage and Unfolding in Amorphous Regions → contribute to Energy Dissipation; Beta-Sheet Nanocrystals slide or rearrange → dissipate Energy; Hierarchical Structure prevents Crack Propagation → enhances Mechanical Toughness; Humidity and Temperature modulate Hydrogen Bonds and Chain Mobility → influence Energy Dissipation and Toughness.\n",
"</graph>\n",
"\n",
"<graph_json>\n",
"{\n",
" \"nodes\": [\n",
" {\"id\": \"BetaSheetNanocrystals\"},\n",
" {\"id\": \"AmorphousRegions\"},\n",
" {\"id\": \"HierarchicalStructure\"},\n",
" {\"id\": \"HydrogenBonds\"},\n",
" {\"id\": \"ChainSlippage\"},\n",
" {\"id\": \"Unfolding\"},\n",
" {\"id\": \"StressDistribution\"},\n",
" {\"id\": \"EnergyDissipation\"},\n",
" {\"id\": \"MechanicalToughness\"},\n",
" {\"id\": \"ProteinChains\"},\n",
" {\"id\": \"Humidity\"},\n",
" {\"id\": \"Temperature\"}\n",
" ],\n",
" \"edges\": [\n",
" {\"source\": \"ProteinChains\", \"relation\": \"form\", \"target\": \"BetaSheetNanocrystals\"},\n",
" {\"source\": \"HydrogenBonds\", \"relation\": \"stabilize\", \"target\": \"BetaSheetNanocrystals\"},\n",
" {\"source\": \"BetaSheetNanocrystals\", \"relation\": \"provide\", \"target\": \"HighStrength\"},\n",
" {\"source\": \"ProteinChains\", \"relation\": \"form\", \"target\": \"AmorphousRegions\"},\n",
" {\"source\": \"ChainSlippage\", \"relation\": \"occur in\", \"target\": \"AmorphousRegions\"},\n",
" {\"source\": \"Unfolding\", \"relation\": \"occur in\", \"target\": \"AmorphousRegions\"},\n",
" {\"source\": \"AmorphousRegions\", \"relation\": \"enable\", \"target\": \"Extensibility\"},\n",
" {\"source\": \"BetaSheetNanocrystals\", \"relation\": \"slide/rearrange\", \"target\": \"EnergyDissipation\"},\n",
" {\"source\": \"AmorphousRegions\", \"relation\": \"contribute to\", \"target\": \"EnergyDissipation\"},\n",
" {\"source\": \"HierarchicalStructure\", \"relation\": \"embeds\", \"target\": \"BetaSheetNanocrystals\"},\n",
" {\"source\": \"HierarchicalStructure\", \"relation\": \"embeds\", \"target\": \"AmorphousRegions\"},\n",
" {\"source\": \"HierarchicalStructure\", \"relation\": \"enables\", \"target\": \"StressDistribution\"},\n",
" {\"source\": \"StressDistribution\", \"relation\": \"prevents\", \"target\": \"CrackPropagation\"},\n",
" {\"source\": \"EnergyDissipation\", \"relation\": \"enhances\", \"target\": \"MechanicalToughness\"},\n",
" {\"source\": \"Humidity\", \"relation\": \"modulates\", \"target\": \"HydrogenBonds\"},\n",
" {\"source\": \"Temperature\", \"relation\": \"modulates\", \"target\": \"ChainMobility\"},\n",
" {\"source\": \"ChainMobility\", \"relation\": \"affects\", \"target\": \"EnergyDissipation\"}\n",
" ]\n",
"}\n",
"</graph_json>\n",
"\n",
"<patterns>\n",
"Beta-Sheet Nanocrystals + Amorphous Regions → Synergistic Energy Dissipation (ordered → strength, disordered → extensibility); Hierarchical Structure → Stress Localization → Crack Arrest (nanoscale → macroscale, preventing catastrophic failure).\n",
"</patterns>\n",
"\n",
"<synthesis>\n",
"The graph reveals a hierarchical synergy: protein chains self-assemble into beta-sheets (via hydrogen bonds) for high strength, while amorphous regions facilitate chain slippage and unfolding for extensibility, with energy dissipation arising from both nanocrystal sliding and amorphous deformation. The hierarchical structure embeds these components, enabling stress distribution and crack arrest. Key insight: toughness stems from multi-scale energy dissipation—beta-sheets absorb energy via rearrangement, amorphous regions via viscoelasticity, and hierarchy via strain localization—yielding ~150 MJ/m³ toughness. This biomimetic design outperforms synthetics by decoupling strength and extensibility, with humidity/temperature tuning chain mobility for adaptive performance.\n",
"</synthesis>\n",
"</think>\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Markdown object>"
],
"text/markdown": "## FINAL OUTPUT (raw)"
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stdout",
"text": [
"Spider dragline silk, produced by orb-weaving spiders like Nephila clavipes, exhibits extraordinary mechanical toughness, defined as the energy absorbed per unit volume before failure, typically exceeding 150 MJ/m³—far surpassing steel (100-150 MJ/m³) and Kevlar (30-40 MJ/m³). This performance is rooted in its hierarchical molecular architecture, where beta-sheet nanocrystals, amorphous protein regions, and a multiscale structure collaborate to dissipate energy efficiently while maintaining high strength and extensibility. The graph of interactions captures this synergy: protein chains self-assemble into beta-sheets stabilized by hydrogen bonds, forming rigid nanocrystals (1-2 nm in size, 10-20 nm in length), while glycine-rich amorphous regions provide flexibility. Hierarchical organization embeds these nanocrystals within the amorphous matrix, creating a composite-like structure that distributes stress and arrests cracks.\n",
"\n",
"At the molecular level, beta-sheet nanocrystals are the primary load-bearing elements. These nanocrystals consist of antiparallel beta-sheets formed by hydrogen bonds between glycine residues in the protein chains, creating a highly ordered network with a Young's modulus of ~4-5 GPa. Under tensile stress, these nanocrystals can slide relative to each other or undergo local rearrangements, dissipating energy through frictional sliding and bond breaking. This mechanism is akin to dislocation motion in crystals but at the nanoscale, where the high density of hydrogen bonds (up to ~100 per nanocrystal) ensures strength while allowing controlled deformation. The graph highlights this via the \"slide/rearrange\" relationship from beta-sheets to energy dissipation.\n",
"\n",
"Amorphous regions, rich in glycine and serine, act as the extensible matrix. These regions lack long-range order, enabling chain slippage and unfolding under strain. When the silk is stretched, the amorphous chains extend, absorbing energy through viscoelastic deformation and hydrogen bond breaking. This contributes significantly to toughness, as the graph shows amorphous regions \"contribute to\" energy dissipation. The extensibility of amorphous regions (up to 300-400% elongation) allows the silk to stretch without immediate failure, contrasting with brittle materials where cracks propagate catastrophically.\n",
"\n",
"The hierarchical structure—comprising nanocrystals embedded in amorphous domains at the nanoscale, aggregated into fibrils (50-100 nm diameter), and further into fibers (10-100 μm)—distributes stress across multiple scales. This prevents stress concentrations that would initiate cracks. The graph illustrates this via \"embeds\" relationships from hierarchical structure to nanocrystals and amorphous regions, enabling \"stress distribution\" that \"prevents crack propagation.\" For example, when a crack forms, it is arrested at the nanocrystal/amorphous interface due to the mismatch in modulus and deformation mechanisms, a phenomenon akin to nacre's platelet-matrix interface but protein-based.\n",
"\n",
"Energy dissipation mechanisms are synergistic: beta-sheets provide ~50-60% of the toughness via sliding, amorphous regions contribute ~30-40%, and the hierarchy adds ~10-20% through strain localization. Humidity and temperature modulate these processes—higher humidity increases hydrogen bond mobility, enhancing amorphous deformation, while elevated temperature boosts chain slippage, as shown by the graph's \"modulates\" relationships. This adaptability allows silk to maintain toughness across environments, from dry desert to humid rainforest.\n",
"\n",
"Key findings from the graph and synthesis: the toughness arises from a \"multi-scale energy dissipation cascade\"—nanoscale beta-sheet sliding, mesoscale amorphous unfolding, and macroscale hierarchical stress redistribution—without sacrificing strength. This design outperforms synthetic fibers by decoupling high strength (beta-sheets) from high extensibility (amorphous regions), achieving a balance unattainable in conventional composites. The graph's patterns (synergistic dissipation, stress localization) underscore the biomimetic genius of spider silk, offering insights for bio-inspired materials like protein-based nanocomposites or self-healing polymers.\n",
"\n",
"In summary, the molecular mechanisms underlying dragline silk's toughness are the interplay of beta-sheet nanocrystals for strength and sliding dissipation, amorphous regions for extensibility and unfolding, and hierarchical structure for stress distribution and crack arrest, collectively enabling unparalleled energy absorption and mechanical resilience.\n"
]
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Markdown object>"
],
"text/markdown": "### Graph summary\n- Nodes: **16**\n- Edges: **17**"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Markdown object>"
],
"text/markdown": "### Static graph (PNG/SVG saved)"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<Figure size 2400x1400 with 1 Axes>"
],
"image/png": "iVBORw0KGgoAAAANSUhEUgAACVYAAAVuCAYAAACUCvUVAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjAsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvlHJYcgAAAAlwSFlzAAAPYQAAD2EBqD+naQABAABJREFUeJzs3XeYXGX9N+DPtmx6L4QEEiAgJaGIdJBOaEroCApBkQ7ijyiIIiCKKIYqCIqg9CZFQUBpgtKUEnpJCAECpPe62T3vH3mzsrNJSDBhIXvf17VXds6c85zvOTvzPJmZzzynrCiKIgAAAAAAAAAAANQrb+oCAAAAAAAAAAAAPmsEqwAAAAAAAAAAAEoIVgEAAAAAAAAAAJQQrAIAAAAAAAAAACghWAUAAAAAAAAAAFBCsAoAAAAAAAAAAKCEYBUAAAAAAAAAAEAJwSoAAAAAAAAAAIASglUAAAAAAAAAAAAlBKsAAACARXr77bdTVlaWX/3qV01dyif273//O1tuuWXatGmTsrKyPP/8801dEiRJtttuu/Tv3/9/amP69Onp3r17rr/++mVU1fIzePDgtG3bdpm1t6B/+sMf/rDU29bV1aV///752c9+9rHrnnnmmSkrK/sEFS7afffdl7Zt22bcuHGN7tt8883z/e9/f5nuDwAAAPhkBKsAAADgM2DkyJE5/vjjs9Zaa6V169Zp3bp11l133Rx33HF54YUXmrq8/8ngwYNTVlZW/9O+fftssMEGGTp0aObMmVO/3oLwwoKfqqqq9O3bNyeeeGImT578ifZdU1OT/fffPxMnTswFF1yQa6+9Nn369Knf1/jx45fRUS65u+++O7vuumu6dOmSli1bZq211sqQIUMyYcKERuuWnrvq6uqstdZa+fGPf5zZs2cv8T6Losi1116bL3/5y+nYsWNat26dAQMG5Cc/+UlmzJjxiY/llVdeyZlnnpm33377E7exNC677LKlDtHMmTMnl1xySbbeeut06tQpLVq0yMorr5yvfvWrufHGG1NbW7t8iv2UXHTRRWnXrl0OOuigpi7lc+XGG2/Mu+++m+OPP3657mdRj9ldd901/fr1y89//vNG951yyim59NJL8+GHHy7X2gAAAICPV9nUBQAAAEBzd/fdd+fAAw9MZWVlDjnkkGywwQYpLy/Pa6+9lttvvz2/+c1vMnLkyPTp06epS/3Eqqurc+WVVyZJJk+enD/96U8ZMmRI/v3vf+emm25qsO5vfvObtG3bNjNmzMiDDz6YSy65JM8++2z++c9/LvV+R4wYkVGjRuV3v/tdjjjiiGVyLP+LIUOGZOjQodlggw1yyimnpHPnznn22Wfz61//OjfddFMefPDBfOELX2iwzUfP3ZQpU3LXXXfl7LPPzogRI5ZolqLa2tocfPDBueWWW7LNNtvkzDPPTOvWrfPYY4/lrLPOyq233poHHnggPXr0WOrjeeWVV3LWWWdlu+22S9++fZd6+6V12WWXpWvXrhk8ePASrT9u3LjstttueeaZZzJw4MD86Ec/SufOnfPhhx/mgQceyMEHH5zhw4fn9NNPX76FLyc1NTW56KKL8t3vfjcVFRVNXc6nrk+fPpk1a1aqqqqWetvzzjsvBx10UDp06LAcKvuvxT1mjzrqqAwZMiRnnXVW2rVrV798r732Svv27XPZZZflJz/5yXKtDwAAAFg8wSoAAABoQiNGjMhBBx2UPn365MEHH0zPnj0b3P+LX/wil112WcrLFz/p9IwZM9KmTZvlWer/pLKyMl//+tfrbx977LHZbLPNcvPNN+f888/PyiuvXH/ffvvtl65duyaZHzw46KCDcvPNN+fpp5/OpptuulT7HTt2bJKkY8eO//tB/I9uvPHGDB06NAceeGCuv/76BkGYwYMHZ/vtt8/++++fZ599NpWV/33LZmHnbsstt8yNN96Y888//2MDUb/85S9zyy23ZMiQITnvvPPqlx955JE54IADMmjQoAwePDj33nvvMjzaz4ZvfOMbee655/KnP/0p++yzT4P7fvCDH+Q///lPXn/99cW2MXv27LRo0eJjn4NN4e677864ceNywAEHLLM2582bl7q6urRo0WKZtbm8lJWVpWXLlku93XPPPZdhw4Zl6NChy6GqJbfvvvvmhBNOyK233ppvfvOb9cvLy8uz33775ZprrslZZ521zC9DCAAAACy5z947QgAAANCM/PKXv8yMGTNy9dVXNwpVJfNDNSeeeGJWWWWV+mWDBw9O27ZtM2LEiOy+++5p165dDjnkkCTJY489lv333z+rrrpqqqurs8oqq+S73/1uZs2a1aDdBW289dZbGThwYNq0aZOVV145P/nJT1IUxUJr/e1vf5s11lgj1dXV2WSTTfLvf//7Ex93eXl5tttuuyT52MvIbbPNNknmh9A+6qmnnsquu+6aDh06pHXr1tl2223zr3/9q8ExbrvttkmS/fffP2VlZfX7XFKvvfZa9ttvv3Tu3DktW7bMl770pfz5z3+uv3/s2LHp1q1btttuuwbnbfjw4WnTpk0OPPDA+mVnnXVWOnXqlN/+9reNZhfadNNNc8opp+TFF1/MbbfdttiaysrKsvXWW6coirz11luLXXfWrFk577zzstZaay30kmNf+cpXcthhh+W+++7Lk08+2WAfZ555ZqP1+/btWz/zzh/+8Ifsv//+SZLtt9++/nKFjzzySP26e+65Z/72t79lww03TMuWLbPuuuvm9ttvb9DmgssylvrDH/6QsrKy+sdH37598/LLL+cf//hH/b4W9/d84okncv/99+fII49sFKpa4Etf+lL9cydJHnnkkZSVleWmm27Kj370o/Tq1SutW7fO1KlTM3HixAwZMiQDBgxI27Zt0759++y2224ZNmxYgzYXtHHzzTfntNNOy0orrZQ2bdrkq1/9at59992F1vHKK69k++23T+vWrdOrV6/88pe/XORxfdSdd96Zvn37Zo011mh036233pp11103LVu2TP/+/XPHHXdk8ODBDWYWe/vtt1NWVpZf/epXufDCC+uf36+88krmzp2bH//4x9l4443ToUOHtGnTJttss00efvjhBvv5aBsXXHBB+vTpk1atWmXbbbfNSy+9tNC6R48enUGDBqVt27bp1q1bhgwZUn9JxpqamnTu3DmHH354o+2mTp2ali1bZsiQIQ32veBSewvO/cJ+Pnrcd955Z1q0aJEvf/nLjfbxz3/+M5tssklatmyZNdZYI1dcccVCj2HevHk5++yz689Z3759c9pppzW4vOnHPWa7d++e9ddfP3fddVej9nfeeeeMGjUqzz///EL3DwAAAHw6zFgFAAAATejuu+9Ov379stlmmy3VdvPmzcvAgQOz9dZb51e/+lVat26dZH6YYubMmTnmmGPSpUuXPP3007nkkkvy3nvv5dZbb23QRm1tbXbddddsvvnm+eUvf5n77rsvZ5xxRubNm9fo8lM33HBDpk2blqOOOiplZWX55S9/mX322SdvvfXWJ7oMV/LfoFSXLl0Wu96CYE2nTp3qlz300EPZbbfdsvHGG+eMM85IeXl5rr766uywww557LHHsummm+aoo45Kr169cs455+TEE0/MJptsslSXu3v55Zez1VZbpVevXjn11FPTpk2b3HLLLRk0aFD+9Kc/Ze+990737t3zm9/8Jvvvv38uueSSnHjiiamrq8vgwYPTrl27XHbZZUmSN998M6+//noGDx6c9u3bL3R/hx56aM4444zcfffdOeigg5b6nCzMP//5z0yaNCnf+c53GsyCVbrfq6++OnfffXc233zzjzkr//XlL385J554Yi6++OKcdtppWWeddZKk/t9k/nEfeOCBOfroo3PYYYfl6quvzv7775/77rsvO++88xLvK0kuvPDCnHDCCWnbtm1++MMfJsli/55/+ctfkqTBbF9L6uyzz06LFi0yZMiQzJkzJy1atMgrr7ySO++8M/vvv39WW221jBkzJldccUW23XbbvPLKKw1mXUuSn/3sZykrK8spp5ySsWPH5sILL8xOO+2U559/Pq1at
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Markdown object>"
],
"text/markdown": "Saved:\n- `/content/run_20251229_112218/graph.png`\n- `/content/run_20251229_112218/graph.svg`"
},
"metadata": {}
},
{
"output_type": "display_data",
"data": {
"text/plain": [
"<IPython.core.display.Markdown object>"
],
"text/markdown": "### Interactive graph (HTML saved)"
},
"metadata": {}
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"WARNING:graph-preflexor:PyVis not available. Install with: pip install pyvis\n"
]
}
]
}
]
}