Created
March 27, 2017 17:24
-
-
Save richardjgowers/b16b871259451e85af0bd2907d30de91 to your computer and use it in GitHub Desktop.
Multiply out a single PDB file using MDAnalysis (similar to editconf in Gromacs)
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": 1, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import MDAnalysis as mda\n", | |
"import numpy as np" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def box_iter(size):\n", | |
" Nx, Ny, Nz = size\n", | |
" for x in range(Nx):\n", | |
" for y in range(Ny):\n", | |
" for z in range(Nz):\n", | |
" yield x, y, z" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"name": "stderr", | |
"output_type": "stream", | |
"text": [ | |
"/home/richard/miniconda2/envs/mdadev/lib/python2.7/site-packages/MDAnalysis/topology/guessers.py:56: UserWarning: Failed to guess the mass for the following atom types: Z\n", | |
" \"\".format(', '.join(misses)))\n" | |
] | |
} | |
], | |
"source": [ | |
"u = mda.Universe('single.pdb')\n", | |
"# set dimensions to what I know a single unit cell to be\n", | |
"u.dimensions = [51.664 / 2.0] * 3 + [90] * 3" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"<AtomGroup with 424 atoms>" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"u.atoms" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([ 25.83200073, 25.83200073, 25.83200073, 90. ,\n", | |
" 90. , 90. ], dtype=float32)" | |
] | |
}, | |
"execution_count": 5, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"u.dimensions" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 9, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"def make_universe(size):\n", | |
" box = np.array([51.664 / 2.0] * 3)\n", | |
" \n", | |
" unis = []\n", | |
" for x, y, z in box_iter(size):\n", | |
" u = mda.Universe('single.pdb')\n", | |
" u.atoms.translate(box * (x, y, z))\n", | |
" \n", | |
" unis.append(u.atoms)\n", | |
" \n", | |
" new_u = mda.Merge(*unis)\n", | |
" new_u.dimensions = list(box * size) + [90.] * 3\n", | |
" \n", | |
" return new_u" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"u = make_universe((2, 2, 2))" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 11, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"array([ 51.66400146, 51.66400146, 51.66400146, 90. ,\n", | |
" 90. , 90. ], dtype=float32)" | |
] | |
}, | |
"execution_count": 11, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"u.dimensions" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 47, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"u.atoms.write('larger.pdb')" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"anaconda-cloud": {}, | |
"kernelspec": { | |
"display_name": "Python [conda env:mdadev]", | |
"language": "python", | |
"name": "conda-env-mdadev-py" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why have the merged universe vectors doubled instead of tripled? Along the x axis for example are you not tiling before and after the primary cell to have L (before) + L (primary unit cell) + L (after) total length--around 75 instead of 51?