Last active
September 5, 2023 17:10
-
-
Save chrisjonesBSU/cd2b5b8d4fda72b20e497a022195c95c to your computer and use it in GitHub Desktop.
Removing particles in gmso
This file contains 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": "code", | |
"execution_count": 18, | |
"id": "09150dc0-25fd-4173-87f4-4a07044a279f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import gmso\n", | |
"from gmso.external import from_mbuild, to_mbuild\n", | |
"import mbuild as mb" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"id": "f4f82e58-9b67-47b0-ab41-a47cce54bbbb", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"_alkane = mb.load(\"CC\", smiles=True)\n", | |
"alkane = from_mbuild(_alkane)\n", | |
"alkane.identify_connections()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"id": "4f50cfdb-3bfe-4e35-bb8c-f802b5999548", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"8\n", | |
"36\n" | |
] | |
} | |
], | |
"source": [ | |
"print(alkane.n_sites)\n", | |
"print(alkane.n_connections)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"id": "98a44ccf-4f3d-49a2-98f3-a4566ad79d29", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"site_connections = alkane.get_connections_by_site(site=alkane.sites[-1])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 12, | |
"id": "2ed25304-731c-4446-93e6-7e9d7f5364e8", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"{'bonds': [<Bond Bond,\n", | |
" connection_members: (<Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6801252304>],\n", | |
" 'angles': [<Angle Angle,\n", | |
" connection_members: (<Atom C,\n", | |
" position: [-0.07590747 0.00182889 0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6814633744>, <Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814649936>,\n", | |
" <Angle Angle,\n", | |
" connection_members: (<Atom H,\n", | |
" position: [ 0.10994617 -0.09535855 -0.05134287] nm,\n", | |
" label: None,\n", | |
" id: 6814635280>, <Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814650256>,\n", | |
" <Angle Angle,\n", | |
" connection_members: (<Atom H,\n", | |
" position: [ 0.11407807 0.08535636 -0.0593128 ] nm,\n", | |
" label: None,\n", | |
" id: 6814635792>, <Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814649104>],\n", | |
" 'dihedrals': [<Dihedral Dihedral,\n", | |
" connection_members: (<Atom H,\n", | |
" position: [-0.11407801 -0.08535597 0.05931338] nm,\n", | |
" label: None,\n", | |
" id: 6801801168>, <Atom C,\n", | |
" position: [-0.07590747 0.00182889 0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6814633744>, <Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6801886672>,\n", | |
" <Dihedral Dihedral,\n", | |
" connection_members: (<Atom H,\n", | |
" position: [-0.10994615 0.09535899 0.05134223] nm,\n", | |
" label: None,\n", | |
" id: 6814634192>, <Atom C,\n", | |
" position: [-0.07590747 0.00182889 0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6814633744>, <Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814650960>,\n", | |
" <Dihedral Dihedral,\n", | |
" connection_members: (<Atom H,\n", | |
" position: [-0.11654095 -0.00179734 -0.10115584] nm,\n", | |
" label: None,\n", | |
" id: 6814634320>, <Atom C,\n", | |
" position: [-0.07590747 0.00182889 0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6814633744>, <Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814649744>],\n", | |
" 'impropers': [<Improper Improper,\n", | |
" connection_members: (<Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom C,\n", | |
" position: [-0.07590747 0.00182889 0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6814633744>, <Atom H,\n", | |
" position: [ 0.10994617 -0.09535855 -0.05134287] nm,\n", | |
" label: None,\n", | |
" id: 6814635280>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814651280>,\n", | |
" <Improper Improper,\n", | |
" connection_members: (<Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom C,\n", | |
" position: [-0.07590747 0.00182889 0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6814633744>, <Atom H,\n", | |
" position: [ 0.11407807 0.08535636 -0.0593128 ] nm,\n", | |
" label: None,\n", | |
" id: 6814635792>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814651344>,\n", | |
" <Improper Improper,\n", | |
" connection_members: (<Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>, <Atom H,\n", | |
" position: [ 0.10994617 -0.09535855 -0.05134287] nm,\n", | |
" label: None,\n", | |
" id: 6814635280>, <Atom H,\n", | |
" position: [ 0.11407807 0.08535636 -0.0593128 ] nm,\n", | |
" label: None,\n", | |
" id: 6814635792>, <Atom H,\n", | |
" position: [0.11654089 0.00179655 0.10115589] nm,\n", | |
" label: None,\n", | |
" id: 6814636304>),\n", | |
" potential: None,\n", | |
" id: 6814651408>]}" | |
] | |
}, | |
"execution_count": 12, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"site_connections" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 13, | |
"id": "d6bf5a34-643a-4018-9384-056bed9b1860", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"# Get list of hydrogen sites, remove their connections and then remove the particle\n", | |
"hydrogen_sites = [site for site in alkane.sites if site.element.atomic_number == 1]\n", | |
"\n", | |
"for h in hydrogen_sites:\n", | |
" site_conn_dict = alkane.get_connections_by_site(h)\n", | |
" for conn_type in site_conn_dict:\n", | |
" for conn in site_conn_dict[conn_type]:\n", | |
" alkane.remove_connection(conn)\n", | |
" alkane.remove_site(h)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 14, | |
"id": "c6032b27-adbb-46a1-be97-213e050e6970", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"2\n", | |
"1\n" | |
] | |
} | |
], | |
"source": [ | |
"print(alkane.n_sites)\n", | |
"print(alkane.n_connections)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 15, | |
"id": "181da5e9-742c-4cbe-be29-6bc5e947c573", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"IndexedSet([<Bond Bond,\n", | |
" connection_members: (<Atom C,\n", | |
" position: [-0.07590747 0.00182889 0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6814633744>, <Atom C,\n", | |
" position: [ 0.07590746 -0.00182894 -0.00211742] nm,\n", | |
" label: None,\n", | |
" id: 6801883984>),\n", | |
" potential: None,\n", | |
" id: 6814635216>])" | |
] | |
}, | |
"execution_count": 15, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"alkane.connections" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 16, | |
"id": "a3030725-dc82-42a1-a8ad-9a8610445613", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"alkane_ua = to_mbuild(alkane)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 17, | |
"id": "ce76fd9a-1432-40ad-9b84-f2fab7a8072c", | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/3dmoljs_load.v0": "<div id=\"3dmolviewer_1693933652754884\" style=\"position: relative; width: 640px; height: 480px\">\n <p id=\"3dmolwarning_1693933652754884\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension: <br>\n <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n </div>\n<script>\n\nvar loadScriptAsync = function(uri){\n return new Promise((resolve, reject) => {\n //this is to ignore the existence of requirejs amd\n var savedexports, savedmodule;\n if (typeof exports !== 'undefined') savedexports = exports;\n else exports = {}\n if (typeof module !== 'undefined') savedmodule = module;\n else module = {}\n\n var tag = document.createElement('script');\n tag.src = uri;\n tag.async = true;\n tag.onload = () => {\n exports = savedexports;\n module = savedmodule;\n resolve();\n };\n var firstScriptTag = document.getElementsByTagName('script')[0];\n firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n});\n};\n\nif(typeof $3Dmolpromise === 'undefined') {\n$3Dmolpromise = null;\n $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.1/3Dmol-min.js');\n}\n\nvar viewer_1693933652754884 = null;\nvar warn = document.getElementById(\"3dmolwarning_1693933652754884\");\nif(warn) {\n warn.parentNode.removeChild(warn);\n}\n$3Dmolpromise.then(function() {\nviewer_1693933652754884 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_1693933652754884\"),{backgroundColor:\"white\"});\nviewer_1693933652754884.zoomTo();\n\tviewer_1693933652754884.addModel(\"@<TRIPOS>MOLECULE\\nCompound\\n2 1 1 0 1\\nSMALL\\nNO_CHARGES\\n@<TRIPOS>CRYSIN\\n 6.5182 6.0000 6.0000 90.0000 90.0000 90.0000 1 1\\n@<TRIPOS>ATOM\\n 1 C -0.7591 0.0183 0.0212 C 1 Compound\\n 2 C 0.7591 -0.0183 -0.0212 C 1 Compound\\n@<TRIPOS>BOND\\n 1 1 2 1\\n@<TRIPOS>SUBSTRUCTURE\\n 1 Compound 1 RESIDUE 0 **** ROOT 0\\n\",\"mol2\");\n\tviewer_1693933652754884.setStyle({\"stick\": {\"radius\": 0.2, \"color\": \"grey\"}, \"sphere\": {\"scale\": 0.3, \"colorscheme\": {}}});\n\tviewer_1693933652754884.zoomTo();\nviewer_1693933652754884.render();\n});\n</script>", | |
"text/html": [ | |
"<div id=\"3dmolviewer_1693933652754884\" style=\"position: relative; width: 640px; height: 480px\">\n", | |
" <p id=\"3dmolwarning_1693933652754884\" style=\"background-color:#ffcccc;color:black\">You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension: <br>\n", | |
" <tt>jupyter labextension install jupyterlab_3dmol</tt></p>\n", | |
" </div>\n", | |
"<script>\n", | |
"\n", | |
"var loadScriptAsync = function(uri){\n", | |
" return new Promise((resolve, reject) => {\n", | |
" //this is to ignore the existence of requirejs amd\n", | |
" var savedexports, savedmodule;\n", | |
" if (typeof exports !== 'undefined') savedexports = exports;\n", | |
" else exports = {}\n", | |
" if (typeof module !== 'undefined') savedmodule = module;\n", | |
" else module = {}\n", | |
"\n", | |
" var tag = document.createElement('script');\n", | |
" tag.src = uri;\n", | |
" tag.async = true;\n", | |
" tag.onload = () => {\n", | |
" exports = savedexports;\n", | |
" module = savedmodule;\n", | |
" resolve();\n", | |
" };\n", | |
" var firstScriptTag = document.getElementsByTagName('script')[0];\n", | |
" firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);\n", | |
"});\n", | |
"};\n", | |
"\n", | |
"if(typeof $3Dmolpromise === 'undefined') {\n", | |
"$3Dmolpromise = null;\n", | |
" $3Dmolpromise = loadScriptAsync('https://cdnjs.cloudflare.com/ajax/libs/3Dmol/2.0.1/3Dmol-min.js');\n", | |
"}\n", | |
"\n", | |
"var viewer_1693933652754884 = null;\n", | |
"var warn = document.getElementById(\"3dmolwarning_1693933652754884\");\n", | |
"if(warn) {\n", | |
" warn.parentNode.removeChild(warn);\n", | |
"}\n", | |
"$3Dmolpromise.then(function() {\n", | |
"viewer_1693933652754884 = $3Dmol.createViewer(document.getElementById(\"3dmolviewer_1693933652754884\"),{backgroundColor:\"white\"});\n", | |
"viewer_1693933652754884.zoomTo();\n", | |
"\tviewer_1693933652754884.addModel(\"@<TRIPOS>MOLECULE\\nCompound\\n2 1 1 0 1\\nSMALL\\nNO_CHARGES\\n@<TRIPOS>CRYSIN\\n 6.5182 6.0000 6.0000 90.0000 90.0000 90.0000 1 1\\n@<TRIPOS>ATOM\\n 1 C -0.7591 0.0183 0.0212 C 1 Compound\\n 2 C 0.7591 -0.0183 -0.0212 C 1 Compound\\n@<TRIPOS>BOND\\n 1 1 2 1\\n@<TRIPOS>SUBSTRUCTURE\\n 1 Compound 1 RESIDUE 0 **** ROOT 0\\n\",\"mol2\");\n", | |
"\tviewer_1693933652754884.setStyle({\"stick\": {\"radius\": 0.2, \"color\": \"grey\"}, \"sphere\": {\"scale\": 0.3, \"colorscheme\": {}}});\n", | |
"\tviewer_1693933652754884.zoomTo();\n", | |
"viewer_1693933652754884.render();\n", | |
"});\n", | |
"</script>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"<py3Dmol.view at 0x196398790>" | |
] | |
}, | |
"execution_count": 17, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"alkane_ua.visualize()" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 3 (ipykernel)", | |
"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.11.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment