diff --git a/prody/proteins/pdbfile.py b/prody/proteins/pdbfile.py index 6dd8280f7..f76ae619a 100644 --- a/prody/proteins/pdbfile.py +++ b/prody/proteins/pdbfile.py @@ -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: @@ -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) @@ -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: @@ -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(), @@ -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 @@ -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] @@ -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]