Skip to content

Commit

Permalink
Merge pull request prody#1747 from jamesmkrieger/long_resname
Browse files Browse the repository at this point in the history
parsePDB long resname and long chid options
  • Loading branch information
jamesmkrieger authored Oct 4, 2023
2 parents 5e3bae4 + d7ebc4e commit e7064a4
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions prody/proteins/pdbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,9 @@ def parsePDBStream(stream, **kwargs):
auto_bonds = SETTINGS.get('auto_bonds')
get_bonds = kwargs.get('bonds', auto_bonds)

long_resname = kwargs.get('long_resname')
long_chid = kwargs.get('long_chid')

if model is not None:
if isinstance(model, Integral):
if model < 0:
Expand Down Expand Up @@ -324,7 +327,8 @@ def parsePDBStream(stream, **kwargs):
if header or biomol or secondary:
hd, split = getHeaderDict(lines)
bonds = [] if get_bonds else None
_parsePDBLines(ag, lines, split, model, chain, subset, altloc, bonds=bonds)
_parsePDBLines(ag, lines, split, model, chain, subset, altloc, bonds=bonds,
long_resname=long_resname, long_chid=long_chid)
if bonds:
try:
ag.setBonds(bonds)
Expand Down Expand Up @@ -383,6 +387,8 @@ def parsePQR(filename, **kwargs):
title = kwargs.get('title', kwargs.get('name'))
chain = kwargs.get('chain')
subset = kwargs.get('subset')
long_resname = kwargs.get('long_resname')
long_chid = kwargs.get('long_chid')
if not os.path.isfile(filename):
raise IOError('No such file: {0}'.format(repr(filename)))
if title is None:
Expand Down Expand Up @@ -420,7 +426,8 @@ def parsePQR(filename, **kwargs):
pqr.close()
LOGGER.timeit()
ag = _parsePDBLines(ag, lines, split=0, model=1, chain=chain,
subset=subset, altloc_torf=False, format='pqr')
subset=subset, altloc_torf=False, format='pqr',
long_resname=long_resname, long_chid=long_chid)
if ag.numAtoms() > 0:
LOGGER.report('{0} atoms and {1} coordinate sets were '
'parsed in %.2fs.'.format(ag.numAtoms(),
Expand All @@ -432,7 +439,8 @@ def parsePQR(filename, **kwargs):
parsePQR.__doc__ += _parsePQRdoc

def _parsePDBLines(atomgroup, lines, split, model, chain, subset,
altloc_torf, format='PDB', bonds=None):
altloc_torf, format='PDB', bonds=None,
long_resname=False, long_chid=False):
"""Returns an AtomGroup. See also :func:`.parsePDBStream()`.
:arg lines: PDB/PQR lines
Expand Down Expand Up @@ -546,7 +554,11 @@ def _parsePDBLines(atomgroup, lines, split, model, chain, subset,
if startswith == 'ATOM' or startswith == 'HETATM':
if isPDB:
atomname = line[12:16].strip()
resname = line[17:20].strip()

if long_resname:
resname = line[17:21].strip()
else:
resname = line[17:20].strip()
else:
atomname= fields[2]
resname = fields[3]
Expand All @@ -557,12 +569,15 @@ def _parsePDBLines(atomgroup, lines, split, model, chain, subset,
continue

if isPDB:
chid = line[20:22].strip()
if len(chid) > 1 and not warned_long_chid:
LOGGER.warn('Parsed 2-character chid {0} continuous with resnum {1} from {2}. Please check if this was intended.'.format(
chid, line[17:20], line[17:22]
))
warned_long_chid = True
if long_chid:
chid = line[20:22].strip()
if len(chid) > 1 and not warned_long_chid:
LOGGER.warn('Parsed 2-character chid {0} continuous with resnum {1} from {2}. Please check if this was intended.'.format(
chid, line[17:20], line[17:22]
))
warned_long_chid = True
else:
chid = line[21].strip()
else:
chid = fields[4]

Expand Down

0 comments on commit e7064a4

Please sign in to comment.