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

Allow PDBWriter (and similar) to write record_types #1753

Closed
xiki-tempula opened this issue Jan 11, 2018 · 11 comments · Fixed by #2880
Closed

Allow PDBWriter (and similar) to write record_types #1753

xiki-tempula opened this issue Jan 11, 2018 · 11 comments · Fixed by #2880

Comments

@xiki-tempula
Copy link
Contributor

xiki-tempula commented Jan 11, 2018

(@richardjgowers edit:) Following #1762 we now read the record type (ATOM/HETATM) of each atom. Now we need to make the PDBWriter (and PQR/PDBQT) write these records when found, otherwise defaulting to a sensible value.

Original Issue:

I have a gro file which contains a ligand and I want to write it out as a pdb file. In the new pdb file can the ligand has a Record type of HETATOM instead of ATOM?

Like

import MDAnalysis as mda
u = mda.Universe(grofile)
u.atoms.recordtype = 'HETATOM'
u.atoms.write('ligand.pdb')
@kain88-de
Copy link
Member

Our PDB writer currently doesn't support writing HETATM records. I'm not sure we track this information in the topology either.

@xiki-tempula
Copy link
Contributor Author

xiki-tempula commented Jan 11, 2018

@kain88-de It seems not.
I have loaded a PDB file where the record type is HETATOM and write it into another pdb. It seems that the HETATOM information is lost.

import MDAnalysis as mda
u = mda.Universe('old.pdb')
u.atoms.write('new.pdb')

old pdb
HETATM 1 N LEU 1 32.310 13.778 14.372 1.00 0.00 SYST N 0
new.pdb
ATOM 1 N LEU 1 32.310 13.778 14.372 1.00 0.00 SYST N 0

@kain88-de
Copy link
Member

Well yeah for the writing it is lost. Like I said we do not write HETATM records at all. This doesn't mean the topology isn't keeping track of this information internally.

@xiki-tempula
Copy link
Contributor Author

@kain88-de Thank you for the help. I guess I will do some string manipulation at the end of my script to solve this problem.

@richardjgowers
Copy link
Member

richardjgowers commented Jan 11, 2018 via email

@kain88-de kain88-de reopened this Jan 11, 2018
@xiki-tempula xiki-tempula changed the title changing ATOM to HETATOM in writing PDB file. changing ATOM to HETATM in writing PDB file. Jan 17, 2018
@richardjgowers richardjgowers changed the title changing ATOM to HETATM in writing PDB file. Allow PDBWriter (and similar) to write record_types Jan 30, 2018
@mieczyslaw
Copy link
Contributor

I planned to create an issue ticket with the same request so I'm glad that someone else noticed this. I have also noticed that the ticket is already 2 years old.

I can confirm that HETATM is kept in selection, but I'm not sure what's the problem with writing it out?

The simple code to reproduce the issue is as follows (the one in the first message with u.atoms.recordtype = 'HETATOM' crashes because of Cannot set arbitrary attributes to a Group):

from MDAnalysis import Universe
reference = Universe("input.pdb", "input.pdb")
hetatms = reference.select_atoms("record_type HETATM")
hetatms.atoms.write("out.pdb")

@IAlibay
Copy link
Member

IAlibay commented Jul 30, 2020

@mieczyslaw the issue currently is just a case that the PDBWriter as-is doesn't have the correct if/else construct to switch between HETATMs and ATOMs when writing the record lines. It should be relatively simple (from the looks of it maybe ~ 3 lines + tests), unfortunately it's one of those things that get added on top of very long to-do list.

I've added a help wanted tag in case this might incite others to join in and work on this.

@mieczyslaw
Copy link
Contributor

@IAlibay I have just improved PDB.py code and will create a PR in a couple of minutes!

@mieczyslaw
Copy link
Contributor

mieczyslaw commented Jul 30, 2020

@IAlibay my first PR created; is this change desired also for PDBQT?

@IAlibay
Copy link
Member

IAlibay commented Jul 30, 2020

@mieczyslaw I think we'll eventually need to fix the PDBQT writer too (although I'm not super clear on where the standard is written out for PDBQT). That being said, the changes here are probably going to be more involved as I'm already seeing a ton of tests that are failing. My suggestion here would be to get #2880 closer to merging before starting on the PDBQT writer (just to avoid code backtracking in case we make decisions that should then be ported from PDB to PDBQT). Either way it's your choice though.

@mieczyslaw
Copy link
Contributor

@mieczyslaw I think we'll eventually need to fix the PDBQT writer too (although I'm not super clear on where the standard is written out for PDBQT). That being said, the changes here are probably going to be more involved as I'm already seeing a ton of tests that are failing. My suggestion here would be to get #2880 closer to merging before starting on the PDBQT writer (just to avoid code backtracking in case we make decisions that should then be ported from PDB to PDBQT). Either way it's your choice though.

Good suggestion, let's focus on #2880.

IAlibay pushed a commit that referenced this issue Aug 14, 2020
Fixes #1753 and #2906 

## Overview of work done in this PR
1) PDBWriter will now write out either `ATOM` or `HETATM` entries based on the contents of the atomgroup `record_types` attribute. If the `record_types` attribute is missing, writing will default to `ATOM` entries.
2) Updates the PDB documentation to refer to PDBv3.3 instead of PDBv3.2.
PicoCentauri pushed a commit to PicoCentauri/mdanalysis that referenced this issue Mar 30, 2021
Fixes MDAnalysis#1753 and MDAnalysis#2906 

## Overview of work done in this PR
1) PDBWriter will now write out either `ATOM` or `HETATM` entries based on the contents of the atomgroup `record_types` attribute. If the `record_types` attribute is missing, writing will default to `ATOM` entries.
2) Updates the PDB documentation to refer to PDBv3.3 instead of PDBv3.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants