Skip to content

Instantly share code, notes, and snippets.

@uppittu11
Last active July 10, 2020 18:46
Show Gist options
  • Save uppittu11/f2acb70e12bff6ae249775b7bd24e6f8 to your computer and use it in GitHub Desktop.
Save uppittu11/f2acb70e12bff6ae249775b7bd24e6f8 to your computer and use it in GitHub Desktop.
test_pr734.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "import mbuild as mb\nimport numpy as np\n\n# Set the number of compounds\nn = 10\n\n# Creates a list of waters of length n\ncompounds = [mb.lib.moieties.H2O() for _ in range(n)]",
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"text": "/Users/parashara/miniconda/envs/mosdef/lib/python3.7/site-packages/hoomd/meta.py:26: DeprecationWarning: Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated since Python 3.3,and in 3.9 it will stop working\n from collections import Mapping\n",
"name": "stderr"
},
{
"output_type": "display_data",
"data": {
"text/plain": "_ColormakerRegistry()",
"application/vnd.jupyter.widget-view+json": {
"version_major": 2,
"version_minor": 0,
"model_id": "b1d676c7161c4289af0bb93283ad0486"
}
},
"metadata": {}
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Case 1\n**This works**: fix_orientation is a tuple of length 3. "
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "n_compounds=[100]*n\nfix_orientation=tuple([True]*3)\n\nsystem = mb.fill_box(compounds,\n n_compounds=n_compounds,\n box=mb.Box(lengths=[100, 100, 100]),\n fix_orientation=fix_orientation)",
"execution_count": 2,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "**This doesn't work**: fix_orientation is a *list* of length 3. "
},
{
"metadata": {
"trusted": true,
"scrolled": true
},
"cell_type": "code",
"source": "n_compounds=[100]*n\nfix_orientation=[True]*3\n\nsystem = mb.fill_box(compounds,\n n_compounds=n_compounds,\n box=mb.Box(lengths=[100, 100, 100]),\n fix_orientation=fix_orientation)",
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"text": "/Users/parashara/devel/git/mbuild/mbuild/packing.py:135: UserWarning: fix_orientation can now be passed as a tuple or list with True/False values specified for each x,y,z axis individually. Using a single instance of True/False defaults to (True,True,True) and (Fale,False,False) respectively\n warnings.warn(\"fix_orientation can now be passed as a tuple or list with True/False \"\n",
"name": "stderr"
},
{
"output_type": "error",
"ename": "ValueError",
"evalue": "`compound`, `n_compounds`, and `fix_orientation` must be of equal length.",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-3-145ca54d5c0a>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mn_compounds\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mn_compounds\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mbox\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mBox\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlengths\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m100\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m fix_orientation=fix_orientation)\n\u001b[0m",
"\u001b[0;32m~/devel/git/mbuild/mbuild/packing.py\u001b[0m in \u001b[0;36mfill_box\u001b[0;34m(compound, n_compounds, box, density, overlap, seed, edge, compound_ratio, aspect_ratio, fix_orientation, temp_file, update_port_locations)\u001b[0m\n\u001b[1;32m 147\u001b[0m msg = (\"`compound`, `n_compounds`, and `fix_orientation` \"\n\u001b[1;32m 148\u001b[0m \"must be of equal length.\")\n\u001b[0;32m--> 149\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mValueError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 150\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 151\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mdensity\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mValueError\u001b[0m: `compound`, `n_compounds`, and `fix_orientation` must be of equal length."
]
}
]
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Case 2\n**This works**: fix_orientation is just a bool even though the docstring says `fix_orientation : tuple of booleans or list of tuples`"
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "n_compounds = [100]*n\nfix_orientation = True\n\nsystem = mb.fill_box(compounds,\n n_compounds=n_compounds,\n box=mb.Box(lengths=[100, 100, 100]),\n fix_orientation=fix_orientation)",
"execution_count": 4,
"outputs": []
},
{
"metadata": {},
"cell_type": "markdown",
"source": "# Case 3\n**This doesn't work**: Anything with numpy arrays "
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "n_compounds = [100]*n\nfix_orientation = np.full((n, 3), True)\n\nsystem = mb.fill_box(compounds,\n n_compounds=n_compounds,\n box=mb.Box(lengths=[100, 100, 100]),\n fix_orientation=fix_orientation)",
"execution_count": 5,
"outputs": [
{
"output_type": "error",
"ename": "ValueError",
"evalue": "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-5-353e1d353d04>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mn_compounds\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mn_compounds\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 6\u001b[0m \u001b[0mbox\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mmb\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mBox\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlengths\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m100\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m100\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 7\u001b[0;31m fix_orientation=fix_orientation)\n\u001b[0m",
"\u001b[0;32m~/devel/git/mbuild/mbuild/packing.py\u001b[0m in \u001b[0;36mfill_box\u001b[0;34m(compound, n_compounds, box, density, overlap, seed, edge, compound_ratio, aspect_ratio, fix_orientation, temp_file, update_port_locations)\u001b[0m\n\u001b[1;32m 207\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 208\u001b[0m \u001b[0mcomp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msave\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mcompound_xyz\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0moverwrite\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 209\u001b[0;31m \u001b[0mPACKMOL_CONSTRAIN\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0m_packmol_constrain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mrotate\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 210\u001b[0m input_text += PACKMOL_BOX.format(compound_xyz.name, m_compounds,\n\u001b[1;32m 211\u001b[0m \u001b[0mbox_mins\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mbox_mins\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/devel/git/mbuild/mbuild/packing.py\u001b[0m in \u001b[0;36m_packmol_constrain\u001b[0;34m(fix_orientation)\u001b[0m\n\u001b[1;32m 670\u001b[0m \"\"\"\n\u001b[1;32m 671\u001b[0m \u001b[0;31m# Handles instances that are not iterable; defaults to True/Fales for all axes\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 672\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mfix_orientation\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 673\u001b[0m \u001b[0mfix_orientation\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;32mTrue\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 674\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mfix_orientation\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;32mFalse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mValueError\u001b[0m: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
]
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"language_info": {
"name": "python",
"version": "3.7.6",
"mimetype": "text/x-python",
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"pygments_lexer": "ipython3",
"nbconvert_exporter": "python",
"file_extension": ".py"
},
"gist": {
"id": "f2acb70e12bff6ae249775b7bd24e6f8",
"data": {
"description": "test_pr734.ipynb",
"public": false
}
},
"_draft": {
"nbviewer_url": "https://gist.github.com/f2acb70e12bff6ae249775b7bd24e6f8"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment