Skip to content

Commit

Permalink
pair evol
Browse files Browse the repository at this point in the history
  • Loading branch information
nifets committed Apr 13, 2023
1 parent 6729152 commit 6ecf3d8
Show file tree
Hide file tree
Showing 15 changed files with 622 additions and 7,728 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.archive
archive
TorusEvol.code-workspace
images
output
424 changes: 320 additions & 104 deletions Manifest.toml

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
ExponentialAction = "e24c0720-ea99-47e8-929e-571b494574d3"
FastaIO = "a0c94c4b-ebed-5953-b5fc-82fe598ac79f"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Formatting = "59287772-0a20-5a39-b81b-1366585eb4c0"
HypothesisTests = "09f84164-cd44-5f33-b23f-e6b0d136a0d5"
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
Expand All @@ -28,10 +30,14 @@ OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PDMats = "90014a1f-27ba-587c-ab20-58faa44d9150"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
RandomMatrices = "2576dda1-a324-5b11-aa66-c48ed7e3c618"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
Rotations = "6038ab10-8711-5258-84ad-4b1120ba62dc"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"
SubstitutionModels = "8365b1bb-bd83-58ee-a267-f2965fc81c73"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
UpdateJulia = "770da0de-323d-4d28-9202-0e205c1e0aff"
WebIO = "0f1e0344-ec1d-5b48-a673-e5cf874b6c29"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
137 changes: 45 additions & 92 deletions ProteinViewer.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,125 +2,83 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5c7b2f8e3a274d1c89c6ce833bbaac71",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"<Chain id=A>\n"
]
},
{
"ename": "ValueError",
"evalue": "I/O operation on closed file",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn [1], line 11\u001b[0m\n\u001b[0;32m 8\u001b[0m chain \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(structure\u001b[39m.\u001b[39mget_chains())[\u001b[39m0\u001b[39m]\n\u001b[0;32m 9\u001b[0m \u001b[39mprint\u001b[39m(chain)\n\u001b[1;32m---> 11\u001b[0m nv\u001b[39m.\u001b[39;49mshow_biopython(structure)\n",
"File \u001b[1;32mc:\\Users\\stefa\\Dropbox\\Jotun Hein - Part C Projects\\Manolache\\Code\\Evolutionary Toroidal Difussions\\TorusEvol\\.venv\\lib\\site-packages\\nglview\\show.py:452\u001b[0m, in \u001b[0;36mshow_biopython\u001b[1;34m(entity, **kwargs)\u001b[0m\n\u001b[0;32m 437\u001b[0m \u001b[39m'''Show NGL widget with Biopython structural entity.\u001b[39;00m\n\u001b[0;32m 438\u001b[0m \n\u001b[0;32m 439\u001b[0m \u001b[39mTakes a Structure, Model, Chain, Residue or Atom\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 449\u001b[0m \u001b[39m... w\u001b[39;00m\n\u001b[0;32m 450\u001b[0m \u001b[39m'''\u001b[39;00m\n\u001b[0;32m 451\u001b[0m entity \u001b[39m=\u001b[39m BiopythonStructure(entity)\n\u001b[1;32m--> 452\u001b[0m \u001b[39mreturn\u001b[39;00m NGLWidget(entity, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n",
"File \u001b[1;32mc:\\Users\\stefa\\Dropbox\\Jotun Hein - Part C Projects\\Manolache\\Code\\Evolutionary Toroidal Difussions\\TorusEvol\\.venv\\lib\\site-packages\\nglview\\widget.py:245\u001b[0m, in \u001b[0;36mNGLWidget.__init__\u001b[1;34m(self, structure, representations, parameters, **kwargs)\u001b[0m\n\u001b[0;32m 243\u001b[0m \u001b[39melse\u001b[39;00m:\n\u001b[0;32m 244\u001b[0m \u001b[39mif\u001b[39;00m structure \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m--> 245\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39madd_structure(structure, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m 247\u001b[0m \u001b[39mif\u001b[39;00m representations:\n\u001b[0;32m 248\u001b[0m \u001b[39m# If initial representations are provided,\u001b[39;00m\n\u001b[0;32m 249\u001b[0m \u001b[39m# we need to set defaultRepresentation to False\u001b[39;00m\n\u001b[0;32m 250\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mrepresentations \u001b[39m=\u001b[39m representations\n",
"File \u001b[1;32mc:\\Users\\stefa\\Dropbox\\Jotun Hein - Part C Projects\\Manolache\\Code\\Evolutionary Toroidal Difussions\\TorusEvol\\.venv\\lib\\site-packages\\nglview\\widget.py:1113\u001b[0m, in \u001b[0;36mNGLWidget.add_structure\u001b[1;34m(self, structure, **kwargs)\u001b[0m\n\u001b[0;32m 1111\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(structure, Structure):\n\u001b[0;32m 1112\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00mstructure\u001b[39m}\u001b[39;00m\u001b[39m is not an instance of Structure\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[1;32m-> 1113\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_load_data(structure, \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs)\n\u001b[0;32m 1114\u001b[0m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39m_ngl_component_ids\u001b[39m.\u001b[39mappend(structure\u001b[39m.\u001b[39mid)\n\u001b[0;32m 1115\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mn_components \u001b[39m>\u001b[39m \u001b[39m1\u001b[39m:\n",
"File \u001b[1;32mc:\\Users\\stefa\\Dropbox\\Jotun Hein - Part C Projects\\Manolache\\Code\\Evolutionary Toroidal Difussions\\TorusEvol\\.venv\\lib\\site-packages\\nglview\\widget.py:1231\u001b[0m, in \u001b[0;36mNGLWidget._load_data\u001b[1;34m(self, obj, **kwargs)\u001b[0m\n\u001b[0;32m 1229\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m is_url:\n\u001b[0;32m 1230\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mhasattr\u001b[39m(obj, \u001b[39m'\u001b[39m\u001b[39mget_structure_string\u001b[39m\u001b[39m'\u001b[39m):\n\u001b[1;32m-> 1231\u001b[0m blob \u001b[39m=\u001b[39m obj\u001b[39m.\u001b[39;49mget_structure_string()\n\u001b[0;32m 1232\u001b[0m kwargs2[\u001b[39m'\u001b[39m\u001b[39mext\u001b[39m\u001b[39m'\u001b[39m] \u001b[39m=\u001b[39m obj\u001b[39m.\u001b[39mext\n\u001b[0;32m 1233\u001b[0m passing_buffer \u001b[39m=\u001b[39m \u001b[39mTrue\u001b[39;00m\n",
"File \u001b[1;32mc:\\Users\\stefa\\Dropbox\\Jotun Hein - Part C Projects\\Manolache\\Code\\Evolutionary Toroidal Difussions\\TorusEvol\\.venv\\lib\\site-packages\\nglview\\adaptor.py:200\u001b[0m, in \u001b[0;36mBiopythonStructure.get_structure_string\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 198\u001b[0m io_str \u001b[39m=\u001b[39m StringIO()\n\u001b[0;32m 199\u001b[0m io_pdb\u001b[39m.\u001b[39msave(io_str)\n\u001b[1;32m--> 200\u001b[0m \u001b[39mreturn\u001b[39;00m io_str\u001b[39m.\u001b[39;49mgetvalue()\n",
"\u001b[1;31mValueError\u001b[0m: I/O operation on closed file"
]
}
],
"outputs": [],
"source": [
"import nglview as nv\n",
"from Bio.PDB import PDBParser\n",
"import time\n",
"import threading\n",
"import os\n",
"from IPython.display import display, clear_output\n",
"\n",
"parser = PDBParser()\n",
"def save_image(name):\n",
" img = view[name].render_image()\n",
" while not img.value:\n",
" time.sleep(0.1)\n",
" # insert your code here to do something with img.value\n",
" # You don’t need to save to disk and read the value again\n",
" with open(\"./images/evol/\"+os.path.splitext(name)[0] + \".png\", \"wb\") as f:\n",
" f.write(img.value)\n",
"\n",
"with open(\"data/m1A3N.pdb\") as handle:\n",
" record = next(SeqIO.parse(handle, \"fasta\"))\n",
" human_a = record.seq\n",
" print(human_a)\n",
"structure = parser.get_structure(\"m1A3N\", \"m1A3N.pdb\")\n",
"files = os.listdir(\"./output/evol\")\n",
"view = dict()\n",
"thread = dict()\n",
"n = len(files)\n",
"ranges=[slice(5*i, 5*(i+1)) for i in range(int(n/5))]\n",
"\n",
"chain = list(structure.get_chains())[0]\n",
"print(chain)\n",
"\n",
"nv.show_biopython(structure)\n",
"\n"
"for name in files[ranges[60]]:\n",
" print(name)\n",
" view[name] = nv.show_file(\"output/evol/\"+name)\n",
" thread[name] = threading.Thread(target=save_image, args=(name, ), daemon=False)\n",
" thread[name].start()\n",
" display(view[name])"
]
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import nglview as nv\n",
"\n",
"import imageio\n",
"import os\n",
"images = []\n",
"\n",
"w = nv.show_structure_file(\"output/n1A3N.pdb\")\n",
"w.clear()\n",
"w.add_representation(\"backbone\")\n",
"\n",
"for i in range(10):\n",
" if i % 2 == 0:\n",
" w = nv.show_structure_file(\"output/n1A3N.pdb\")\n",
" else:\n",
" w = nv.show_structure_file(\"output/m1A3N.pdb\")\n",
" w.clear()\n",
" w.add_representation(\"backbone\")\n",
" w"
"files = os.listdir(\"./images/evol\")\n",
"for name in files:\n",
" images.append(imageio.imread(\"./images/evol/\"+name))\n",
"imageio.mimsave('./images/evolution.gif', images)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "abbeed12461a445698b89c1caa5e72ec",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"A Jupyter Widget"
"<PDBReader ./output/struc.pdb with 101 frames of 563 atoms>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "display_data"
"output_type": "execute_result"
}
],
"source": [
"u = nv.show_structure_file(\"output/n1A3N.pdb\")\n",
"u"
"import MDAnalysis\n",
"from MDAnalysis.coordinates.PDB import PDBReader\n",
"\n",
"traj = PDBReader(\"./output/struc.pdb\")\n",
"traj\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.9.6 ('.venv': venv)",
"display_name": ".venv",
"language": "python",
"name": "python3"
},
Expand All @@ -134,14 +92,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)]"
"version": "3.9.6"
},
"orig_nbformat": 4,
"vscode": {
"interpreter": {
"hash": "9f23c5b2d7923a9bf6ddcca76ea127105863b859cb6fc4879d608de940540fb9"
}
}
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
Expand Down
Loading

0 comments on commit 6ecf3d8

Please sign in to comment.