Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HETATM record type written out #2880

Merged
merged 19 commits into from
Aug 14, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions package/MDAnalysis/coordinates/PDB.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,11 @@ class PDBWriter(base.WriterBase):
"{chainID:1s}{resSeq:4d}{iCode:1s}"
" {pos[0]:8.3f}{pos[1]:8.3f}{pos[2]:8.3f}{occupancy:6.2f}"
"{tempFactor:6.2f} {segID:<4s}{element:>2s}\n"),
'HETATM': (
"HETATM{serial:5d} {name:<4s}{altLoc:<1s}{resName:<4s}"
"{chainID:1s}{resSeq:4d}{iCode:1s}"
" {pos[0]:8.3f}{pos[1]:8.3f}{pos[2]:8.3f}{occupancy:6.2f}"
"{tempFactor:6.2f} {segID:<4s}{element:>2s}\n"),
'REMARK': "REMARK {0}\n",
'COMPND': "COMPND {0}\n",
'HEADER': "HEADER {0}\n",
Expand Down Expand Up @@ -1029,6 +1034,7 @@ def get_attr(attrname, default):
tempfactors = get_attr('tempfactors', 0.0)
atomnames = get_attr('names', 'X')

no_record_type = False
IAlibay marked this conversation as resolved.
Show resolved Hide resolved
for i, atom in enumerate(atoms):
vals = {}
vals['serial'] = util.ltruncate_int(i + 1, 5) # check for overflow here?
Expand All @@ -1044,8 +1050,21 @@ def get_attr(attrname, default):
vals['segID'] = segids[i][:4]
vals['element'] = guess_atom_element(atomnames[i].strip())[:2]

# .. _ATOM: http://www.wwpdb.org/documentation/file-format-content/format32/sect9.html#ATOM
self.pdbfile.write(self.fmt['ATOM'].format(**vals))
if hasattr(atom, 'record_type'):
if atom.record_type == 'HETATM':
IAlibay marked this conversation as resolved.
Show resolved Hide resolved
# .. _HETATM: http://www.wwpdb.org/documentation/file-format-content/format32/sect9.html#HETATM
IAlibay marked this conversation as resolved.
Show resolved Hide resolved
self.pdbfile.write(self.fmt['HETATM'].format(**vals))
else:
# .. _ATOM: http://www.wwpdb.org/documentation/file-format-content/format32/sect9.html#ATOM
self.pdbfile.write(self.fmt['ATOM'].format(**vals))
else:
# .. _ATOM: http://www.wwpdb.org/documentation/file-format-content/format32/sect9.html#ATOM
no_record_type = True
self.pdbfile.write(self.fmt['ATOM'].format(**vals))

if no_record_type:
warnings.warn("PDBWriter: No record type found for an atom - HETATM may be written out as ATOM")

if multiframe:
self.ENDMDL()
self.frames_written += 1
Expand Down