File: test_PDB.py

package info (click to toggle)
python-biopython 1.45-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 18,192 kB
  • ctags: 12,310
  • sloc: python: 83,505; xml: 13,834; ansic: 7,015; cpp: 1,855; sql: 1,144; makefile: 179
file content (70 lines) | stat: -rw-r--r-- 2,144 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Copyright (C) 2002, Thomas Hamelryck (thamelry@vub.ac.be)
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.  

import sys
# Redirect stderr so user does not see warnings

class TheVoid:
    # Class to hide stderr output
    def write(self, string):
        pass

def run_test():
	from Bio.PDB import PDBParser, PPBuilder, CaPPBuilder


	# first make a PDB parser object
	p=PDBParser(PERMISSIVE=1) 

	# get the structure, call it "example"
	structure=p.get_structure("example", "PDB/a_structure.pdb")

	# now loop over content and print some info
	for model in structure.get_list():
		model_id=model.get_id()
		print "Model %i contains %i chains." % (model_id, len(model))
		for chain in model.get_list():
			chain_id=chain.get_id()
			print "\tChain '%s' contains %i residues." % (chain_id, len(chain))
			for residue in chain.get_list():
				residue_id=residue.get_id()
				hetfield, resseq, icode=residue_id
				print "\t\tResidue ('%s', %i, '%s') contains %i atoms." % (hetfield, resseq, icode, len(residue))
				# check if there is disorder due to a point mutation --- this is rare
				if residue.is_disordered()==2:
					print "\t\t\tThere is a point mutation present in the crystal at this position."
					s="\t\t\tResidues at this position are "
					for resname in residue.disordered_get_id_list():
						s=s+resname+" "
					print s[:-1]+"."
				# count the number of disordered atoms
				if residue.is_disordered()==1:
					disordered_count=0
					for atom in residue.get_list():
						if atom.is_disordered():
							disordered_count=disordered_count+1
					if disordered_count>0:
						print "\t\t\tThe residue contains %i disordered atoms." % disordered_count


	print "Polypeptides using C-N"
	ppb=PPBuilder()
	for pp in ppb.build_peptides(structure[1]):
		print pp

	print "Polypeptides using CA-CA"
	ppb=CaPPBuilder()
	for pp in ppb.build_peptides(structure[1]):
		print pp

					

old_stderr = sys.stderr
# Hide stderr output for user
sys.stderr=TheVoid()
try:
	run_test()
finally:
	sys.stderr = old_stderr