Skip to content

Commit

Permalink
PQRParser now reads icodes
Browse files Browse the repository at this point in the history
Fixes Issue #1317
  • Loading branch information
richardjgowers committed May 1, 2017
1 parent 5c6700b commit 657451b
Show file tree
Hide file tree
Showing 5 changed files with 5,493 additions and 8 deletions.
5 changes: 3 additions & 2 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ The rules for this file:

------------------------------------------------------------------------------

mm/dd/17 utkbansal, kain88-de, xiki-tempula, kaplajon, wouterboomsma

mm/dd/17 utkbansal, kain88-de, xiki-tempula, kaplajon, wouterboomsma,
richardjgowers

* 0.16.1

Expand All @@ -25,6 +25,7 @@ Enhancements
(apply to PDB, GRO) (Issue #1306)
* Improved print to screen format in waterdynamics module (using
ProgressMeter).
* PQRParser now treats insertion codes properly (Issue #1317)

Fixes
* In Universe.transfer_to_memory(): dt is now adjusted with step (Issue #1310)
Expand Down
23 changes: 19 additions & 4 deletions package/MDAnalysis/topology/PQRParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
Atomnames,
Atomtypes,
Charges,
ICodes,
Masses,
Radii,
Resids,
Expand All @@ -65,7 +66,7 @@
Segids,
)
from ..core.topology import Topology
from .base import TopologyReaderBase, squash_by
from .base import TopologyReaderBase, squash_by, change_squash


class PQRParser(TopologyReaderBase):
Expand Down Expand Up @@ -102,6 +103,7 @@ def parse(self):
resnames = []
chainIDs = []
resids = []
icodes = []
charges = []
radii = []

Expand All @@ -118,10 +120,20 @@ def parse(self):
(recordName, serial, name, resName,
resSeq, x, y, z, charge, radius) = fields
chainID = "SYSTEM"
try:
resid = int(resSeq)
except ValueError:
# has icode present
resid = int(resSeq[:-1])
icode = resSeq[-1]
else:
icode = ''

serials.append(serial)
names.append(name)
resnames.append(resName)
resids.append(resSeq)
resids.append(resid)
icodes.append(icode)
charges.append(charge)
radii.append(radius)
chainIDs.append(chainID)
Expand All @@ -140,16 +152,19 @@ def parse(self):
attrs.append(Radii(np.array(radii, dtype=np.float32)))

resids = np.array(resids, dtype=np.int32)
icodes = np.array(icodes, dtype=object)
resnames = np.array(resnames, dtype=object)
chainIDs = np.array(chainIDs, dtype=object)

residx, resids, (resnames, chainIDs) = squash_by(
resids, resnames, chainIDs)
residx, (resids, resnames, icodes, chainIDs) = change_squash(
(resids, resnames, icodes, chainIDs),
(resids, resnames, icodes, chainIDs))

n_residues = len(resids)
attrs.append(Resids(resids))
attrs.append(Resnums(resids.copy()))
attrs.append(Resnames(resnames))
attrs.append(ICodes(icodes))

segidx, chainIDs = squash_by(chainIDs)[:2]

Expand Down
Loading

0 comments on commit 657451b

Please sign in to comment.