From 574177fab79a3e756403f1a843d179a4278a68f0 Mon Sep 17 00:00:00 2001 From: James Krieger Date: Mon, 6 Nov 2023 17:10:25 +0100 Subject: [PATCH] better fix --- prody/proteins/pdbfile.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/prody/proteins/pdbfile.py b/prody/proteins/pdbfile.py index 5fbd270f9..9fcbe8edf 100644 --- a/prody/proteins/pdbfile.py +++ b/prody/proteins/pdbfile.py @@ -1242,12 +1242,7 @@ def writePDBStream(stream, atoms, csets=None, **kwargs): Default is **False**, which means using hexadecimal instead. NB: ChimeraX seems to prefer hybrid36 and may have problems with hexadecimal. :type hybrid36: bool - """ - keepACSI = False - if hasattr(atoms, 'getACSIndex'): - initialACSI = atoms.getACSIndex() - keepACSI = True - + """ renumber = kwargs.get('renumber', True) remark = str(atoms) @@ -1266,8 +1261,10 @@ def writePDBStream(stream, atoms, csets=None, **kwargs): if coordsets is None: raise ValueError('atoms does not have any coordinate sets') + had_atoms = False try: acsi = atoms.getACSIndex() + had_atoms = True except AttributeError: try: atoms = atoms.getAtoms() @@ -1442,7 +1439,8 @@ def writePDBStream(stream, atoms, csets=None, **kwargs): num_ter_lines = 0 for m, coords in enumerate(coordsets): - atoms.setACSIndex(m) + if had_atoms: + atoms.setACSIndex(m) anisous = atoms._getAnisous() if anisous is not None: anisous = np.array(anisous * 10000, dtype=int) @@ -1618,8 +1616,8 @@ def writePDBStream(stream, atoms, csets=None, **kwargs): write('END ' + " "*74 + '\n') - if keepACSI: - atoms.setACSIndex(initialACSI) + if had_atoms: + atoms.setACSIndex(acsi) writePDBStream.__doc__ += _writePDBdoc