Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Biopython question
#1
Dear forum members,

I am trying to write a script to calculate distances between atoms in two separate collections (collection_AA_atoms & collection_DNA_atoms) using biopython but am not getting any values. The program runs but doesn't print any values. Where might be the problem? The code:

from Bio.PDB import PDBParser

# create parser
parser = PDBParser()

# read structure from file
structure = parser.get_structure('HS_1az0_B', 'HS_1az0_B.pdb')

model = structure[0]
chain = model['B']
collection_AA_atoms = ['N' 'O' 'CB' 'CG' 'ND2' 'CD1' 'SD']
collection_DNA_atoms = ['CA' 'C8' 'N7' 'N4']

for residue1 in chain:
    for residue2 in chain:
            for i in collection_AA_atoms:
               	for x in collection_DNA_atoms:
        			if residue1 != residue2:
            			# compute distance between CA atoms
            				try:
                				distance = residue1[i] - residue2[x]
            				except KeyError:
              			## no CA atom, e.g. for H_NAG
                				continue
            				if distance < 3.9:
               					print(residue1, residue2, distance)
       					 # stop after
I will look forward to all replies. If you need more details - please let me know and I'll provide.

Sincerely,
Aurimas
Reply
#2
I don't know anything about Biopython, but from a pure Python stand point, I can see two potential reasons for no output. They depend on what chain is, or perhaps what list(chain) is.

First, if chain is only one item, the conditional on line 18 will always be False, so there would be no output. Second, if there are no CA atoms anywhere in chain, everything will be a KeyError (line 22), and there will be no output. So I would inspect chain, and make sure it contains values that would cause output.

Note that the first two for loops could be done as one using itertools.permutations.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020