Skip to content

Commit

Permalink
PQRParser now reads icodes (#1328)
Browse files Browse the repository at this point in the history
* PQRParser now reads icodes
* Fixes Issue #1317
* Updated PQR docs
  • Loading branch information
richardjgowers authored and orbeckst committed May 1, 2017
1 parent d5bc8f5 commit ac27e28
Show file tree
Hide file tree
Showing 6 changed files with 5,497 additions and 10 deletions.
6 changes: 3 additions & 3 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +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 @@ -26,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
25 changes: 21 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 All @@ -87,6 +88,8 @@ class PQRParser(TopologyReaderBase):
.. versionchanged:: 0.9.0
Read chainID from a PQR file and use it as segid (before we always used
'SYSTEM' as the new segid).
.. versionchanged:: 0.16.1
Now reads insertion codes and splits into new residues around these
"""
format = 'PQR'

Expand All @@ -102,6 +105,7 @@ def parse(self):
resnames = []
chainIDs = []
resids = []
icodes = []
charges = []
radii = []

Expand All @@ -118,10 +122,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 +154,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
3 changes: 2 additions & 1 deletion package/MDAnalysis/topology/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@
PQR [#a]_ pqr names, charges, PDB-like but whitespace-separated files with charge
types, and radius information;
radii, resids, :mod:`MDAnalysis.topology.PQRParser`
resnames, segids
resnames, icodes,
segids
PDBQT [#a]_ pdbqt names, types, file format used by AutoDock with atom types and
altLocs, charges, partial charges. Module:
Expand Down
Loading

0 comments on commit ac27e28

Please sign in to comment.