Skip to content

Instantly share code, notes, and snippets.

@dominiquesydow
Created August 3, 2020 13:14
Show Gist options
  • Save dominiquesydow/51d58dc3ab8f9d477e98095ce2410517 to your computer and use it in GitHub Desktop.
Save dominiquesydow/51d58dc3ab8f9d477e98095ce2410517 to your computer and use it in GitHub Desktop.
Example: Structural alignment with biopython
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# `biopython`\n",
"## Structural alignment using Quaternion Characteristic Polynomial (QCP)\n",
"\n",
"https://biopython.org/docs/dev/api/Bio.PDB.QCPSuperimposer.html"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"\n",
"from Bio.PDB import QCPSuperimposer"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# Example coordinates\n",
"reference_coords = np.array([[0, 0, 0], [1, 1, 1]])\n",
"coords = np.array([[1, 0, 0], [3, 1, 1]])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Get untransformed coordinate sets:\n",
"Reference coordinates\n",
"[[0 0 0]\n",
" [1 1 1]]\n",
"\n",
"Mobile coordinates\n",
"[[1 0 0]\n",
" [3 1 1]]\n",
"\n",
"Get tranformed coordinate set\n",
"[[-0.5 0. 0. ]\n",
" [ 1.5 1. 1. ]]\n",
"\n",
"Rotation matrix\n",
"[[1. 0. 0.]\n",
" [0. 1. 0.]\n",
" [0. 0. 1.]]\n",
"\n",
"Translation\n",
"[-1.5 0. 0. ]\n",
"\n",
"RMS\n",
"0.3587194598822338\n",
"\n"
]
}
],
"source": [
"# Initialize class\n",
"superimposer = QCPSuperimposer.QCPSuperimposer()\n",
"\n",
"# Set the coordinates to be superimposed\n",
"superimposer.set(reference_coords, coords)\n",
"\n",
"# Superimpose the coordinate sets\n",
"superimposer.run()\n",
"\n",
"print(f'Get untransformed coordinate sets:')\n",
"print(f'Reference coordinates\\n{reference_coords}\\n')\n",
"print(f'Mobile coordinates\\n{coords}\\n')\n",
"print(f'Get tranformed coordinate set\\n{superimposer.get_transformed()}\\n')\n",
"print(f'Rotation matrix\\n{superimposer.get_rotran()[0]}\\n')\n",
"print(f'Translation\\n{superimposer.get_rotran()[1]}\\n')\n",
"print(f'RMS\\n{superimposer.get_rms()}\\n')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "kissim",
"language": "python",
"name": "kissim"
},
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment