Skip to content

Instantly share code, notes, and snippets.

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

  • Save jbarnoud/20f20ee4b3e2d6afe92b6d5925a7f52c to your computer and use it in GitHub Desktop.

Select an option

Save jbarnoud/20f20ee4b3e2d6afe92b6d5925a7f52c to your computer and use it in GitHub Desktop.
Demonstration of a RepairGraph issue
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:28:33.646002Z",
"start_time": "2018-04-11T11:28:32.770834Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Using redistributed KDTree\n"
]
}
],
"source": [
"import networkx as nx\n",
"import martinize2\n",
"import martinize2.forcefield\n",
"import collections"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:28:52.581835Z",
"start_time": "2018-04-11T11:28:52.533163Z"
}
},
"outputs": [],
"source": [
"molecule = martinize2.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",
"system = martinize2.System()\n",
"system.molecules = [molecule]\n",
"system.force_field = martinize2.forcefield.FORCE_FIELDS['universal']"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:28:56.892534Z",
"start_time": "2018-04-11T11:28:56.881647Z"
}
},
"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": 4,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:28:57.741969Z",
"start_time": "2018-04-11T11:28:57.727303Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Counter({'N': 1,\n",
" 'CA': 1,\n",
" 'C': 1,\n",
" 'O': 1,\n",
" 'CB': 1,\n",
" 'HB1': 1,\n",
" 'HB2': 1,\n",
" 'CG': 1,\n",
" 'HG1': 1,\n",
" 'HG2': 1,\n",
" 'CD': 1,\n",
" 'OE2': 1,\n",
" 'OE1': 1,\n",
" 'HE1': 1,\n",
" 'H': 1,\n",
" 'HA': 1,\n",
" 'HN': 1})"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"name_count_before"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:28:59.722354Z",
"start_time": "2018-04-11T11:28:59.710564Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"17"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(name_count_before.values())"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:06.318762Z",
"start_time": "2018-04-11T11:29:05.592325Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Doing MCS matching for residue GLU1\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:HN\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:CA\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:HB1\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:HB2\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:CG\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:OE1\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:OE2\n",
"{'N': 0, 'C': 2, 'CB': 4, 'HG1': 8, 'HG2': 9, 'CD': 10, 'HA': 15}\n",
"Missing atom GLU1:O\n"
]
}
],
"source": [
"martinize2.RepairGraph().run_system(system)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:14.816305Z",
"start_time": "2018-04-11T11:29:14.810185Z"
}
},
"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": 9,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:17.037531Z",
"start_time": "2018-04-11T11:29:17.031088Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Counter({'N': 1,\n",
" 'CA': 2,\n",
" 'C': 1,\n",
" 'O': 2,\n",
" 'CB': 1,\n",
" 'HB1': 2,\n",
" 'HB2': 2,\n",
" 'CG': 2,\n",
" 'HG1': 1,\n",
" 'HG2': 1,\n",
" 'CD': 1,\n",
" 'OE2': 2,\n",
" 'OE1': 2,\n",
" 'HE1': 1,\n",
" 'H': 1,\n",
" 'HA': 1,\n",
" 'HN': 2})"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"name_count_after"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:18.777363Z",
"start_time": "2018-04-11T11:29:18.770732Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(name_count_after.values())"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:30.385291Z",
"start_time": "2018-04-11T11:29:30.370776Z"
}
},
"outputs": [],
"source": [
"name_count_block = collections.Counter(\n",
" martinize2.forcefield.FORCE_FIELDS['universal'].blocks['GLU'].nodes.keys()\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:31.594095Z",
"start_time": "2018-04-11T11:29:31.579554Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"Counter({'N': 1,\n",
" 'HN': 1,\n",
" 'CA': 1,\n",
" 'HA': 1,\n",
" 'CB': 1,\n",
" 'HB1': 1,\n",
" 'HB2': 1,\n",
" 'CG': 1,\n",
" 'HG1': 1,\n",
" 'HG2': 1,\n",
" 'CD': 1,\n",
" 'OE1': 1,\n",
" 'OE2': 1,\n",
" 'C': 1,\n",
" 'O': 1})"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"name_count_block"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:33.542096Z",
"start_time": "2018-04-11T11:29:33.524953Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"15"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(name_count_block.values())"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"ExecuteTime": {
"end_time": "2018-04-11T11:29:34.832519Z",
"start_time": "2018-04-11T11:29:34.824189Z"
}
},
"outputs": [
{
"data": {
"text/plain": [
"[<martinize2.molecule.Molecule at 0x7f9d94e213c8>]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"system.molecules"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"hide_input": false,
"kernelspec": {
"display_name": "Python 3 (oldm2)",
"language": "python",
"name": "oldm2"
},
"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.5"
},
"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
}
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment