Skip to content

Instantly share code, notes, and snippets.

@sczizzo
Created March 15, 2013 21:54
Show Gist options
  • Save sczizzo/5173372 to your computer and use it in GitHub Desktop.
Save sczizzo/5173372 to your computer and use it in GitHub Desktop.
Examine the relationship between the sidechain separation and protonation
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
from marshal import dump, load
from random import sample
from glob import glob
from pdb import *
import sys
def run_experiment(residues, interests, ss_code=None, mind=0.0, maxd=100.0):
results = []
for interest in interests:
left, right = [], []
res_name, a1n, a2n, a3n, a4n = interest
matching_residues = filter(lambda r: r['resName'] == res_name, residues)
for residue in matching_residues:
if ss_code != None and residue['ssCode'] != ss_code: continue
distance = residue_distance(residue, a3n, a4n)
if distance == None:
# print("Error on %s (%.2f): " % (res_name, residue['resNum']), find_atoms('HD2', residue))
continue
if len(find_atoms('HD2', residue)) > 0:
left.append(distance)
else: right.append(distance)
results.append([res_name, left, right])
return results
def analyze_result(name, data, mind=0.0, maxd=1000.0, nbins=50):
print("Average: %.2f Angstrom" % average(data))
print("Median: %.2f Angstrom" % median(data))
rdata = filter(lambda x: mind < x < maxd, data)
figure(figsize=[11, 8.5])
hist(rdata, histtype='bar', bins=nbins, label=name)
legend()
grid()
savefig(name + '.png', dpi=300)
interests = [
['ASP', 'CB', 'CG', 'OD1', 'OD2'],
# ['GLU', 'CG', 'CD', 'OE1', 'OE2'],
# ['ASN', 'CB', 'CG', 'OD1', 'ND2'],
# ['GLN', 'CG', 'CD', 'OE1', 'NE2'],
# ['VAL', 'CA', 'CB', 'CG1', 'CG2']
]
try:
__IPYTHON__
is_ipy = True
except: is_ipy = False
all_residues = []
for pdb_fname in glob('nrpdb_hd2/*'):
all_residues += extract_models(pdb_fname)[0]['residues']
r = run_experiment(all_residues, interests)[0]
print("Protonated: %d, Non-protonated: %d" % (len(r[1]), len(r[2])))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment