Skip to content

Instantly share code, notes, and snippets.

@jbarnoud
Created April 11, 2018 19:33
Show Gist options
  • Select an option

  • Save jbarnoud/6cdca889ef040d5836f705127d5087c7 to your computer and use it in GitHub Desktop.

Select an option

Save jbarnoud/6cdca889ef040d5836f705127d5087c7 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:04:03.528893Z",
"start_time": "2018-04-11T11:04:02.919186Z"
}
},
"outputs": [],
"source": [
"import networkx as nx\n",
"import vermouth\n",
"import vermouth.forcefield\n",
"import collections"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:30:47.224132Z",
"start_time": "2018-04-11T19:30:46.956029Z"
}
},
"outputs": [],
"source": [
"molecule = vermouth.molecule.Molecule()\n",
"molecule.add_nodes_from((\n",
" (0, {'resid': 1, 'resname': 'GLU', 'atomname': 'N', 'chain': 'A'}),\n",
" (1, {'resid': 1, 'resname': 'GLU', 'atomname': 'CA', 'chain': 'A'}),\n",
" (2, {'resid': 1, 'resname': 'GLU', 'atomname': 'C', 'chain': 'A'}),\n",
" (3, {'resid': 1, 'resname': 'GLU', 'atomname': 'O', 'chain': 'A'}),\n",
" (4, {'resid': 1, 'resname': 'GLU', 'atomname': 'CB', 'chain': 'A'}),\n",
" (5, {'resid': 1, 'resname': 'GLU', 'atomname': 'HB1', 'chain': 'A'}),\n",
" (6, {'resid': 1, 'resname': 'GLU', 'atomname': 'HB2', 'chain': 'A'}),\n",
" (7, {'resid': 1, 'resname': 'GLU', 'atomname': 'CG', 'chain': 'A'}),\n",
" (8, {'resid': 1, 'resname': 'GLU', 'atomname': 'HG1', 'chain': 'A'}),\n",
" (9, {'resid': 1, 'resname': 'GLU', 'atomname': 'HG2', 'chain': 'A'}),\n",
" (10, {'resid': 1, 'resname': 'GLU', 'atomname': 'CD', 'chain': 'A'}),\n",
" (11, {'resid': 1, 'resname': 'GLU', 'atomname': 'OE2', 'chain': 'A'}),\n",
" (12, {'resid': 1, 'resname': 'GLU', 'atomname': 'OE1', 'chain': 'A'}),\n",
" (13, {'resid': 1, 'resname': 'GLU', 'atomname': 'HE1', 'chain': 'A'}),\n",
" (14, {'resid': 1, 'resname': 'GLU', 'atomname': 'H', 'chain': 'A'}),\n",
" (15, {'resid': 1, 'resname': 'GLU', 'atomname': 'HA', 'chain': 'A'}),\n",
" (16, {'resid': 1, 'resname': 'GLU', 'atomname': 'HN', 'chain': 'A'}),\n",
"))\n",
"molecule.add_edges_from([\n",
" [0, 1], [1, 2], [2, 3], [1, 4], [4, 5], [4, 6], [4, 7], [7, 8],\n",
" [7, 9], [7, 10], [10, 11], [10, 12], [12, 13], [14, 0], [15, 1], [16, 0],\n",
"])\n",
"system = vermouth.System()\n",
"system.molecules = [molecule]\n",
"system.force_field = vermouth.forcefield.FORCE_FIELDS['universal']"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:30:50.818510Z",
"start_time": "2018-04-11T19:30:50.801704Z"
}
},
"outputs": [],
"source": [
"name_count_before = collections.Counter(\n",
" node['atomname']\n",
" for molecule in system.molecules\n",
" for node in molecule.nodes.values()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:30:51.556554Z",
"start_time": "2018-04-11T19:30:51.509980Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Counter({'C': 1,\n",
" 'CA': 1,\n",
" 'CB': 1,\n",
" 'CD': 1,\n",
" 'CG': 1,\n",
" 'H': 1,\n",
" 'HA': 1,\n",
" 'HB1': 1,\n",
" 'HB2': 1,\n",
" 'HE1': 1,\n",
" 'HG1': 1,\n",
" 'HG2': 1,\n",
" 'HN': 1,\n",
" 'N': 1,\n",
" 'O': 1,\n",
" 'OE1': 1,\n",
" 'OE2': 1})"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"name_count_before"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:30:53.509486Z",
"start_time": "2018-04-11T19:30:53.490797Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"17"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(name_count_before.values())"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:30:54.455205Z",
"start_time": "2018-04-11T19:30:54.400514Z"
}
},
"outputs": [],
"source": [
"vermouth.RepairGraph().run_system(system)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:30:55.633548Z",
"start_time": "2018-04-11T19:30:55.621396Z"
}
},
"outputs": [],
"source": [
"name_count_after = collections.Counter(\n",
" node['atomname']\n",
" for molecule in system.molecules\n",
" for node in molecule.nodes.values()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:30:56.525912Z",
"start_time": "2018-04-11T19:30:56.519591Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Counter({'C': 1,\n",
" 'CA': 1,\n",
" 'CB': 1,\n",
" 'CD': 1,\n",
" 'CG': 1,\n",
" 'HA': 1,\n",
" 'HB1': 1,\n",
" 'HB2': 1,\n",
" 'HE1': 1,\n",
" 'HG1': 1,\n",
" 'HG2': 1,\n",
" 'HN': 2,\n",
" 'N': 1,\n",
" 'O': 1,\n",
" 'OE1': 1,\n",
" 'OE2': 1})"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"name_count_after"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:31:00.075602Z",
"start_time": "2018-04-11T19:31:00.065174Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"17"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(name_count_after.values())"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:31:00.730949Z",
"start_time": "2018-04-11T19:31:00.719348Z"
}
},
"outputs": [],
"source": [
"name_count_block = collections.Counter(\n",
" vermouth.forcefield.FORCE_FIELDS['universal'].blocks['GLU'].nodes.keys()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:31:01.303426Z",
"start_time": "2018-04-11T19:31:01.293086Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Counter({'C': 1,\n",
" 'CA': 1,\n",
" 'CB': 1,\n",
" 'CD': 1,\n",
" 'CG': 1,\n",
" 'HA': 1,\n",
" 'HB1': 1,\n",
" 'HB2': 1,\n",
" 'HG1': 1,\n",
" 'HG2': 1,\n",
" 'HN': 1,\n",
" 'N': 1,\n",
" 'O': 1,\n",
" 'OE1': 1,\n",
" 'OE2': 1})"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"name_count_block"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:31:03.188035Z",
"start_time": "2018-04-11T19:31:03.175735Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"15"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(name_count_block.values())"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T19:31:05.371365Z",
"start_time": "2018-04-11T19:31:05.352133Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"[<vermouth.molecule.Molecule at 0x7fb2ccf10940>]"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system.molecules"
]
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.4"
},
"toc": {
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"toc_cell": false,
"toc_position": {},
"toc_section_display": "block",
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment