Created
June 18, 2017 21:28
-
-
Save leelasd/7f8bcff22608c09c74a1d4cda1e2c562 to your computer and use it in GitHub Desktop.
Bio-Python Module for doing Chop stuff
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
# Using BioPython Doing All the Manipulations | |
## | |
import numpy as np | |
from Bio.PDB import * | |
from Bio.KDTree import KDTree | |
import pandas as pd | |
import warnings | |
from Bio import BiopythonWarning | |
warnings.simplefilter('ignore', BiopythonWarning) | |
def DeleteClashes(prot, memb): | |
''' | |
- Deleting The Overlapping residues between two models | |
- Meant for Protein and Membrane system but can be used | |
for membrane systems too | |
- Deletion happens in place | |
''' | |
prot_atoms = [at for at in prot.get_atoms()] | |
memb_atoms = [at for at in memb.get_atoms()] | |
prot_coos = np.array([at.coord for at in prot_atoms], np.float) | |
memb_coos = np.array([at.coord for at in memb_atoms], np.float) | |
clashes = [] | |
atom_kdtree = KDTree(3) | |
atom_kdtree.set_coords(memb_coos) | |
for p in range(len(prot_coos)): | |
atom_kdtree.search(prot_coos[p], 1.500) | |
res = list(atom_kdtree.get_indices()) | |
clashes = clashes + res | |
del_res = [memb_atoms[c].get_parent().get_id()[1] for c in clashes] | |
del_res = list(set(del_res)) | |
for p in range(len(del_res)): | |
for chain in memb[0]: | |
if chain.has_id(del_res[p]): | |
chain.detach_child((' ', del_res[p], ' ')) | |
return None | |
def Struct2DF(prot): | |
''' | |
- Creates a pandas dataframe from BIO.PDB object | |
''' | |
prot_atoms = [at for at in prot.get_atoms()] | |
prot_coos = np.array([at.coord for at in prot_atoms], np.float) | |
f3 = pd.DataFrame(prot_coos, columns=['X', 'Y', 'Z']) | |
f3['res_name'] = [at.get_parent().get_resname() for at in prot_atoms] | |
f3['res_id'] = [at.get_parent().get_id()[1] for at in prot_atoms] | |
f3['atom_name'] = [at.get_id() for at in prot_atoms] | |
return f3 | |
def Displace(prot, disp_vec): | |
''' | |
- Displace all atoms in model by values in DispVec | |
''' | |
for chain in prot[0]: | |
for res in chain: | |
for atom in res: | |
old = atom.coord | |
atom.set_coord(old - disp_vec) | |
return None |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment