diff --git a/prody/proteins/mmtffile.py b/prody/proteins/mmtffile.py index 0480e7045..a9e55e85b 100644 --- a/prody/proteins/mmtffile.py +++ b/prody/proteins/mmtffile.py @@ -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 """ @@ -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' @@ -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", @@ -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]) diff --git a/prody/proteins/pdbfile.py b/prody/proteins/pdbfile.py index 9fcbe8edf..15339afe3 100644 --- a/prody/proteins/pdbfile.py +++ b/prody/proteins/pdbfile.py @@ -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)) @@ -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 @@ -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], @@ -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], @@ -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],