Skip to content

Commit

Permalink
Fixed Issue #1347 (#1348)
Browse files Browse the repository at this point in the history
PSFParser now considers segid and resname when splitting into residues
  • Loading branch information
richardjgowers authored and kain88-de committed May 14, 2017
1 parent 1f9a31f commit f189758
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Fixes
* Fixed incorrect handling of residue names with trailing numbers in
HydrogenBondAnalysis (issue #801)
* Fixed AnalysisBase class provides numerical start,stop,step values (PR #1340)
* Fixed PSFParser not creating multiple residues for identical resids in
different segments. (Issue #1347, PR #1348)

Changes
* Enable various pylint warnings to increase python 3 compatibility
Expand Down
7 changes: 4 additions & 3 deletions package/MDAnalysis/topology/PSFParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

from ..lib.util import openany
from . import guessers
from .base import TopologyReaderBase, squash_by
from .base import TopologyReaderBase, squash_by, change_squash
from ..core.topologyattrs import (
Atomids,
Atomnames,
Expand Down Expand Up @@ -311,8 +311,9 @@ def _parseatoms(self, lines, atoms_per, numlines):

# Residue
# resids, resnames
residx, new_resids, (new_resnames, perres_segids) = squash_by(
resids, resnames, segids)
residx, (new_resids, new_resnames, perres_segids) = change_squash(
(resids, resnames, segids),
(resids, resnames, segids))
# transform from atom:Rid to atom:Rix
residueids = Resids(new_resids)
residuenums = Resnums(new_resids.copy())
Expand Down
23 changes: 23 additions & 0 deletions testsuite/MDAnalysisTests/topology/test_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
PSF,
PSF_nosegid,
PSF_NAMD,
XYZ_psf, XYZ,
)


Expand Down Expand Up @@ -110,6 +111,28 @@ class TestNAMDPSFParser(ParserBase):
expected_n_segments = 1


class TestPSFParser2(ParserBase):
parser = mda.topology.PSFParser.PSFParser
filename = XYZ_psf
expected_attrs = ['ids', 'names', 'types', 'masses',
'charges',
'resids', 'resnames',
'segids',
'bonds', 'angles', 'dihedrals', 'impropers']
expected_n_atoms = 1284
expected_n_residues = 152
expected_n_segments = 4

def test_as_universe_resids(self):
u = mda.Universe(XYZ_psf, XYZ)

# each segment has [380, 381, 382, 383] as the first
# 4 residues
for seg in u.segments:
assert_equal(seg.residues.resids[:4],
[380, 381, 382, 383])


def test_psf_nosegid():
"""Issue #121"""
u = mda.Universe(PSF_nosegid)
Expand Down

0 comments on commit f189758

Please sign in to comment.