{
"metadata": {
"name": "",
"signature": "sha256:fb3d371186ab55835635c21c9e8ebca4e0cf6d8d505616413e6089ef688a45ef"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# New IPython support\n",
"\n",
"As of version 0.4 chemlab can display molecules interactively in the browser using the package chemview."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from chemlab.notebook import download_molecule, display_molecule\n",
"\n",
"arg = download_molecule(\"arginine\")\n",
"display_molecule(arg)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
""
],
"metadata": {},
"output_type": "display_data",
"text": [
""
]
}
],
"prompt_number": 13
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"# let's make an arginine box\n",
"from chemlab.core import System\n",
"from chemlab.notebook import display_system\n",
"\n",
"import numpy as np\n",
"\n",
"copies = []\n",
"for i in range(100):\n",
" tmp = arg.copy()\n",
" tmp.r_array += np.random.random(3) * 3.0\n",
" copies.append(tmp)\n",
"\n",
"system = System(copies)\n",
"\n",
"display_system(system)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
""
],
"metadata": {},
"output_type": "display_data",
"text": [
""
]
}
],
"prompt_number": 14
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Trajectory Support\n",
"\n",
"Thanks to the added interactivity, we can also play trajectory. Fast"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from chemlab.notebook import display_trajectory\n",
"\n",
"# Let's scramble those coordinates\n",
"frames = system.r_array + np.random.random((100, system.n_atoms, 3))\n",
"\n",
"display_trajectory(system, frames)"
],
"language": "python",
"metadata": {},
"outputs": [
{
"metadata": {},
"output_type": "pyout",
"prompt_number": 15,
"text": [
"(,\n",
" )"
]
},
{
"html": [
""
],
"metadata": {},
"output_type": "display_data",
"text": [
""
]
}
],
"prompt_number": 15
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can really leverage this feature by downloading and displaying data directly from the web"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"from chemlab.notebook import load_remote_system, load_remote_trajectory, load_trajectory, display_trajectory"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 16
},
{
"cell_type": "code",
"collapsed": true,
"input": [
"system = load_remote_system(\"https://github.com/chemlab/chemlab-testdata/raw/master/water.gro\")\n",
"system.guess_bonds()\n",
"t, frames = load_remote_trajectory(\"https://github.com/chemlab/chemlab-testdata/raw/master/trajout.xtc\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 17
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"tc, mv = display_trajectory(system, frames)\n",
"\n",
"# Change the speed\n",
"tc.fps = 10"
],
"language": "python",
"metadata": {},
"outputs": [
{
"html": [
""
],
"metadata": {},
"output_type": "display_data",
"text": [
""
]
}
],
"prompt_number": 18
}
],
"metadata": {}
}
]
}