Last active
October 28, 2019 12:16
-
-
Save dominiquesydow/77412320e10f83ac75c072d2c5945729 to your computer and use it in GitHub Desktop.
NGLviewer: Attempt to add text labels to selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": {}, | |
"source": [ | |
"# NGL viewer - Add labels" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "216f1874f5ad4447a03e4697edf231d3", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"_ColormakerRegistry()" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "86873e6202c743d0a71993acfff274f9", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"NGLWidget()" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"import nglview as nv\n", | |
"\n", | |
"pdb_id = '2g2i'\n", | |
"chain = 'A'\n", | |
"res_id = 229\n", | |
"\n", | |
"viewer = nv.show_pdbid(pdb_id, default=False)\n", | |
"viewer.clear()\n", | |
"viewer.add_cartoon(selection=f':{chain}', assembly='AU')\n", | |
"viewer.center(selection=f'{res_id}')\n", | |
"\n", | |
"viewer" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"label_kwargs = dict(labelType='text', showBackground=True, backgroundColor='black')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"viewer.add_label(sele=f'@0', labelText=[f'First atom? ID 0'], **label_kwargs)\n", | |
"# Label shows up!" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"viewer.add_label(sele=f'@1', labelText=[f'Also first atom? ID 1'], **label_kwargs)\n", | |
"# Vertical mini-label without text shows up..." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"viewer.remove_label()\n", | |
"viewer.remove_label()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 7, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"viewer.add_label(sele=f'{res_id}:{chain}.CA', labelText=[f'Atom I am interested in'], **label_kwargs)\n", | |
"# Same vertical mini-label without text shows up..." | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "kinsim", | |
"language": "python", | |
"name": "kinsim" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.7" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment