Skip to content

Commit

Permalink
Merge pull request #1808 from jamesmkrieger/pdb_fixes
Browse files Browse the repository at this point in the history
Several fixes related to fetching and writing pdb files
  • Loading branch information
jamesmkrieger authored Dec 22, 2023
2 parents a19b435 + 2366c2e commit 514bdda
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 6 deletions.
9 changes: 9 additions & 0 deletions prody/atomic/pointer.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ def _getSubset(self, label):
.intersection(set(self._getIndices()))), int)
subset.sort()
return subset

def getAnisous(self):
"""Returns a copy of anisotropic temperature factors from the active coordinate set."""

if self._ag._anisous is not None:
# Since this is not slicing, a view is not returned
return self._ag._anisous[self.getACSIndex(), self._indices]

_getAnisous = getAnisous

def _iterBonds(self):
"""Yield pairs of indices for bonded atoms that are within the pointer.
Expand Down
2 changes: 1 addition & 1 deletion prody/proteins/localpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def fetchPDB(*pdb, **kwargs):

folder = kwargs.get('folder', '.')
compressed = kwargs.get('compressed')
format_ = kwargs.get('format')
format_ = kwargs.get('format', 'pdb')

# check *folder* specified by the user, usually pwd ('.')
filedict = findPDBFiles(folder, compressed=compressed,
Expand Down
24 changes: 24 additions & 0 deletions prody/tests/datafiles/6zu5_sel_SE0_SF0_10-20.pdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
REMARK Selection 'name CA and seg...resnum 10 to 20'
ATOM 1 CA LYS Z 10 241.064 218.683 115.080 1.00 76.19 SE0 C
ATOM 2 CA ARG Z 11 241.395 216.353 112.126 1.00 78.29 SE0 C
ATOM 3 CA LEU Z 12 238.042 214.694 112.724 1.00 77.55 SE0 C
ATOM 4 CA ASN Z 13 236.407 218.088 113.221 1.00 75.95 SE0 C
ATOM 5 CA ALA Z 14 237.705 219.231 109.829 1.00 74.73 SE0 C
ATOM 6 CA PRO Z 15 235.172 219.530 106.991 1.00 73.66 SE0 C
ATOM 7 CA SER Z 16 234.780 216.288 105.093 1.00 75.83 SE0 C
ATOM 8 CA SER Z 17 234.971 218.169 101.797 1.00 76.09 SE0 C
ATOM 9 CA TRP Z 18 238.691 218.624 102.453 1.00 75.23 SE0 C
ATOM 10 CA GLN Z 19 239.073 214.811 102.251 1.00 80.09 SE0 C
ATOM 11 CA LEU Z 20 241.546 214.456 105.094 1.00 80.45 SE0 C
ATOM 12 CA LEU B 10 168.714 96.728 179.585 1.00 83.97 SF0 C
ATOM 13 CA LEU B 11 169.608 98.301 182.936 1.00 85.19 SF0 C
ATOM 14 CA LEU B 12 172.320 100.641 184.178 1.00 84.57 SF0 C
ATOM 15 CA PHE B 13 174.993 98.778 186.200 1.00 83.57 SF0 C
ATOM 16 CA ASP B 14 172.684 95.721 185.895 1.00 86.57 SF0 C
ATOM 17 CA LYS B 15 170.596 97.232 188.710 1.00 85.32 SF0 C
ATOM 18 CA TYR B 16 168.849 100.479 187.837 1.00 85.19 SF0 C
ATOM 19 CA SER B 17 166.316 100.980 185.057 1.00 87.78 SF0 C
ATOM 20 CA ARG B 18 166.755 104.070 182.910 1.00 88.01 SF0 C
ATOM 21 CA ASP B 19 163.206 103.794 181.561 1.00 90.86 SF0 C
ATOM 22 CA GLU B 20 161.410 104.550 184.827 1.00 90.52 SF0 C
END
10 changes: 10 additions & 0 deletions prody/tests/datafiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,16 @@
'atoms': 165175,
'segment_SX0_atoms': 1089,
},
'6zu5_sel': {
'pdb': '6zu5',
'file': '6zu5_sel_SE0_SF0_10-20.pdb',
'atoms': 22,
'segment_SF0_atoms': 11,
'chid_order': ['Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z',
'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B'],
'sorted_order': ['B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B',
'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z', 'Z']
},
'3hsy': {
'pdb': '3hsy',
'file': 'pdb3hsy.pdb',
Expand Down
24 changes: 19 additions & 5 deletions prody/tests/proteins/test_pdbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,13 @@ def setUp(self):
self.h36_ter = parsePDB(DATA_FILES['h36_ter']['path'])

self.altlocs = DATA_FILES['6flr']
self.altloc_full = parsePDB(self.altlocs['path'], altloc=None)
self.altloc_full = parsePDB(self.altlocs['path'], altloc=None,
secondary=False)
self.altloc_sel = DATA_FILES['6flr_sel']['path']

self.sort_sel = DATA_FILES['6zu5_sel']
self.sort_sel_ag = parsePDB(self.sort_sel['path'])

msg = 'user does not have write access to temp dir {0:s}'.format(TEMPDIR)

@dec.slow
Expand Down Expand Up @@ -447,11 +451,11 @@ def testWritingAltlocModels(self):
lines2 = fi.readlines()
fi.close()

self.assertEqual(lines1[4], lines2[4],
'writePDB failed to write correct ANISOU line 4 for 6flr selection with altloc None')
self.assertEqual(lines1[3], lines2[3],
'writePDB failed to write correct ANISOU line 3 for 6flr selection with altloc None')

self.assertEqual(lines1[8], lines2[8],
'writePDB failed to write correct ANISOU line 8 for 6flr selection with altloc None')
self.assertEqual(lines1[7], lines2[7],
'writePDB failed to write correct ANISOU line 7 for 6flr selection with altloc None')

def testWriteEnsembleToPDB(self):
"""Test that writePDB can handle ensembles."""
Expand All @@ -463,6 +467,16 @@ def testWriteEnsembleToPDB(self):
assert_equal(out.getCoords(), self.ag.getCoordsets(0),
'failed to write ensemble model 1 coordinates correctly')

@dec.slow
@unittest.skipUnless(os.access(TEMPDIR, os.W_OK), msg)
def testWritingAtomMap(self):
"""Test if output from writing a sorted AtomMap works and is as expected."""

sorted_sel = sortAtoms(self.sort_sel_ag, 'chain')
out = writePDB(self.tmp, sorted_sel)
new = parsePDB(out)
self.assertListEqual(list(new.getChids()), self.sort_sel['sorted_order'])

@dec.slow
def tearDown(self):
"""Remove test file."""
Expand Down

0 comments on commit 514bdda

Please sign in to comment.