Skip to content

Commit

Permalink
Merge pull request #1793 from dkoes/master
Browse files Browse the repository at this point in the history
More robust handling of altloc
  • Loading branch information
jamesmkrieger authored Nov 15, 2023
2 parents 92435c1 + 41d3d8a commit c55c8a2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
19 changes: 11 additions & 8 deletions prody/proteins/mmtffile.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
:arg altloc: if a location indicator is passed, such as ``'A'`` or ``'B'``,
only indicated alternate locations will be parsed as the single
coordinate set of the AtomGroup, if *altloc* is set **True** all
coordinate set of the AtomGroup. If *altloc* is ``'all'`` then all
alternate locations will be parsed and each will be appended as a
distinct coordinate set, default is ``"A"``
distinct coordinate set, default is ``"A"``. In the rare instance
where all atoms have a location indicator specified and this does not
match altloc, the first location indicator in the file is used.
:type altloc: str
"""

Expand Down Expand Up @@ -143,7 +145,7 @@ def _parseMMTF(mmtf_struc, **kwargs):
chain = kwargs.get('chain')
header = kwargs.get('header', False)
get_bonds = kwargs.get('bonds',False)
altloc_sel = kwargs.get('altloc', 'A')
altloc_sel = kwargs.get('altloc', None)

assert isinstance(header, bool), 'header must be a boolean'

Expand Down Expand Up @@ -221,7 +223,7 @@ def _bio_transform(dec):
ret[t['name']] = L
return ret

def set_info(atomgroup, mmtf_data,get_bonds=False,altloc_sel='A'):
def set_info(atomgroup, mmtf_data,get_bonds=False,altloc_sel=None):

mmtfHETATMtypes = set([
"D-SACCHARIDE",
Expand Down Expand Up @@ -322,10 +324,11 @@ def set_info(atomgroup, mmtf_data,get_bonds=False,altloc_sel='A'):
mask = np.full(asize, True, dtype=bool)
if altloc_sel != 'all':
#mask out any unwanted alternative locations
mask = (altlocs == '') | (altlocs == altloc_sel)

if np.all(mask == False):
mask = (altlocs == '') | (altlocs == altlocs[0])
default_altloc = altloc_sel if altloc_sel != None else 'A'
mask = (altlocs == '') | (altlocs == default_altloc)
if np.all(mask == False) and altloc_sel == None and len(altlocs):
#nothing selected, use first altloc; 6uwi
mask = altlocs == altlocs[0]

atomgroup.setCoords(coords[:,mask])
atomgroup.setNames(atom_names[mask])
Expand Down
14 changes: 7 additions & 7 deletions prody/proteins/pdbfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,9 +1400,9 @@ def writePDBStream(stream, atoms, csets=None, **kwargs):
L = helix_resnums[-1] - helix_resnums[0] + 1

stream.write(HELIXLINE.format(serNum=i, helixID=helix_secids[0],
initResName=helix_resnames[0][:3], initChainID=helix_chainids[0],
initResName=helix_resnames[0][:3], initChainID=helix_chainids[0][:1],
initSeqNum=helix_resnums[0], initICode=helix_icodes[0],
endResName=helix_resnames[-1][:3], endChainID=helix_chainids[-1],
endResName=helix_resnames[-1][:3], endChainID=helix_chainids[-1][:1],
endSeqNum=helix_resnums[-1], endICode=helix_icodes[-1],
helixClass=helix_secclasses[0], length=L))

Expand All @@ -1426,9 +1426,9 @@ def writePDBStream(stream, atoms, csets=None, **kwargs):
strand_icodes = icodes[torf_strand]

stream.write(SHEETLINE.format(strand=i, sheetID=sheet_id, numStrands=numStrands,
initResName=strand_resnames[0][:3], initChainID=strand_chainids[0],
initResName=strand_resnames[0][:3], initChainID=strand_chainids[0][:1],
initSeqNum=strand_resnums[0], initICode=strand_icodes[0],
endResName=strand_resnames[-1][:3], endChainID=strand_chainids[-1],
endResName=strand_resnames[-1][:3], endChainID=strand_chainids[-1][:1],
endSeqNum=strand_resnums[-1], endICode=strand_icodes[-1],
sense=strand_secclasses[0]))
pass
Expand Down Expand Up @@ -1571,7 +1571,7 @@ def writePDBStream(stream, atoms, csets=None, **kwargs):

write(anisouline % ("ANISOU", serial,
atomnames[i], altlocs[i],
resname, chainids[i], resnum,
resname, chainids[i][:1], resnum,
icodes[i],
anisou[0], anisou[1], anisou[2],
anisou[3], anisou[4], anisou[5],
Expand All @@ -1586,7 +1586,7 @@ def writePDBStream(stream, atoms, csets=None, **kwargs):

false_pdbline = pdbline % ("TER ", serial,
"", "",
resname, chainids[i], resnum,
resname, chainids[i][:1], resnum,
icodes[i],
xyz[0], xyz[1], xyz[2],
occupancies[i], bfactors[i],
Expand All @@ -1602,7 +1602,7 @@ def writePDBStream(stream, atoms, csets=None, **kwargs):

false_pdbline = pdbline % ("TER ", serial,
"", "",
resname, chainids[i], resnum,
resname, chainids[i][:1], resnum,
icodes[i],
xyz[0], xyz[1], xyz[2],
occupancies[i], bfactors[i],
Expand Down

0 comments on commit c55c8a2

Please sign in to comment.