Skip to content

Commit

Permalink
Fixes for Issue #936
Browse files Browse the repository at this point in the history
CONECT records to unknown entries (hopefully TER) are now ignored
  • Loading branch information
richardjgowers committed Aug 21, 2016
1 parent 8f803a4 commit 59916ed
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 2 deletions.
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ Fixes
defaults (#914)
* Fixed same interRDF can be run twice (Issue #924)
* Support for TPR files produced by Gromacs-2016 (Issue #932)
* Fixed parsing PDB files with CONECT records to TER entries (Issue #936)

Changes
* Added protected variable _frame_index to to keep track of frame iteration
number in AnalysisBase
Expand Down
10 changes: 8 additions & 2 deletions package/MDAnalysis/topology/PDBParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,14 @@ def _parsebonds(self, atoms):
for line in lines:
atom, atoms = _parse_conect(line.strip())
for a in atoms:
bond = tuple([mapping[atom], mapping[a]])
bonds.add(bond)
try:
bond = tuple([mapping[atom], mapping[a]])
except KeyError:
# Bonds to TER records have no mapping
# Ignore these as they are not real atoms
pass
else:
bonds.add(bond)

bonds = tuple(bonds)

Expand Down
12 changes: 12 additions & 0 deletions testsuite/MDAnalysisTests/data/CONECT2TER.pdb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
HEADER ISSUE936 Test File
REMARK Contains a CONECT record to a TER entry
MODEL 1
CRYST1 216.489 216.489 216.489 90.00 90.00 90.00 P 1 1
ATOM 1 CA ABC A 1 111.252 98.373 98.187
ATOM 2 CA ABC A 1 111.203 101.742 96.430
ATOM 3 CA ABC A 1 107.607 102.968 96.316
TER 4 ABC A 1
CONECT 1 2
CONECT 2 1 3
CONECT 3 2 4
ENDMDL
2 changes: 2 additions & 0 deletions testsuite/MDAnalysisTests/datafiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"PDB_multiframe",
"PDB_helix",
"PDB_conect",
"PDB_conect2TER", # Conect record to a TER entry (Issue 936)
"XPDB_small",
"PDB_full", # PDB 4E43 (full HEADER, TITLE, COMPND, REMARK, altloc)
"ALIGN", # Various way to align atom names in PDB files
Expand Down Expand Up @@ -172,6 +173,7 @@
PDB_multiframe = resource_filename(__name__, 'data/nmr_neopetrosiamide.pdb')
PDB_helix = resource_filename(__name__, 'data/A6PA6_alpha.pdb')
PDB_conect = resource_filename(__name__, 'data/conect_parsing.pdb')
PDB_conect2TER = resource_filename(__name__, 'data/CONECT2TER.pdb')

GRO = resource_filename(__name__, 'data/adk_oplsaa.gro')
GRO_velocity = resource_filename(__name__, 'data/sample_velocity_file.gro')
Expand Down
30 changes: 30 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_pdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- Mode: python; tab-width: 4; indent-tabs-mode:nil; coding:utf-8 -*-
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 fileencoding=utf-8
#
# MDAnalysis --- http://www.MDAnalysis.org
# Copyright (c) 2006-2015 Naveen Michaud-Agrawal, Elizabeth J. Denning, Oliver Beckstein
# and contributors (see AUTHORS for the full list)
#
# Released under the GNU Public Licence, v2 or any higher version
#
# Please cite your use of MDAnalysis in published work:
# N. Michaud-Agrawal, E. J. Denning, T. B. Woolf, and O. Beckstein.
# MDAnalysis: A Toolkit for the Analysis of Molecular Dynamics Simulations.
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#

from numpy.testing import assert_
from MDAnalysisTests.datafiles import (
PDB_conect2TER,
)

import MDAnalysis as mda
from MDAnalysis.topology.PDBParser import PDBParser


def test_conect2ter():
with PDBParser(PDB_conect2TER) as p:
struc = p.parse()

assert_('bonds' in struc)
assert_(len(struc['bonds']) == 4)

0 comments on commit 59916ed

Please sign in to comment.