PDB to mmCIF #400
Replies: 11 comments 6 replies
|
BTW to goal if this project is to generate files for wwPDB deposition. |
|
Hi Genieve! |
|
All refinement programs can generate also mmCIF file nowadays, so ideally the beamline developers would update their pipeline. |
|
And in Python its: import gemmi
def convert_pdb_to_mmcif(input_pdb, output_cif):
# 1. Read the PDB file
# The read_structure function automatically detects the format
st = gemmi.read_structure(input_pdb)
# 2. Setup the mmCIF document
# make_mmcif_document() converts the internal structure object
# into a CIF document object
doc = st.make_mmcif_document()
# 3. Write the file
doc.write_file(output_cif)
print(f"Successfully converted {input_pdb} to {output_cif}")
# Usage
convert_pdb_to_mmcif("example.pdb", "example.cif") |
|
Thanks so much for the rapidly provided insight :-) To capture here: Here is the small script I used the strip TER records from the PDB file. Someone in the team at the synchrotron is looking into updating to code so PDB files are no longer used. Thanks again!! BTW The message: |
|
Dear Genevieve,
remember that the TER record might not only come after ATOM|HETATM but
also ANISOU: the documentation [1] isn't explicit about this, but
since ANISOU is always related to a ATOM/HETATM record it needs to be
taken as part of such a record.
Cheers
Clemens
[1] http://www.wwpdb.org/documentation/file-format-content/format33/sect9.html#ANISOU
…On Thu, Jan 22, 2026 at 03:49:41PM -0800, Genevieve Evans wrote:
Thanks so much for the rapidly provided insight :-)
To capture here:
The PDB file from this pipeline was generated by REFMAC 5.8.0267
The TER records need to first be removed (wrong placement).
Then added in the right place using script above.
Here is the small script I used the strip TER records from code.
I think it likely there is a way to strip TER records in Gemmi too.
```
import argparse
def remove_ter(input_file, output_file):
"""Reads a file, removes lines containing 'TER', and writes the result to a new file.
Args:
input_file (str): Path to the input file.
output_file (str): Path to the output file.
"""
with open(input_file, 'r') as infile, open(output_file, 'w') as outfile:
for line in infile:
if 'TER' not in line:
outfile.write(line)
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Remove lines containing TER from a file.')
parser.add_argument('input_file', help='The input file.')
parser.add_argument('output_file', help='The output file.')
args = parser.parse_args()
remove_ter(args.input_file, args.output_file)
print(f'Processed {args.input_file} and saved the output to {args.output_file}')
```
Someone in the team is looking into updating to code so PDB files are no longer used.
However, we need legacy compatibility.
Thanks again!!
--
Reply to this email directly or view it on GitHub:
#400 (comment)
You are receiving this because you are subscribed to this thread.
Message ID: ***@***.***>
--
*--------------------------------------------------------------
* Clemens Vonrhein, Ph.D. vonrhein AT GlobalPhasing DOT com
* Global Phasing Ltd., 9 Journey Campus, Castle Park
* Cambridge CB3 0AX, UK www.globalphasing.com
*--------------------------------------------------------------
|
|
BTW if may help if the beamline pipelines use the latest CCP4 and call the command |
|
One of the developers I am working with said I could share the finalized Python function we will be using: This deals with the ANISOU record complication nicely :-) Thanks for the insight Clemens! |
|
Dear all,
Not sure I'm reading that code correctly, but it seems as if it
assumes that there could not be an ANISOU card after a HETATM one?
That's not quite right: even SEQRES records can end with a HETATM
record (MSE for example) that has an ANISOU record attached to it ...
See "Details" in
http://www.wwpdb.org/documentation/file-format-content/format33/sect9.html#TER
Cheers
Clemens
…On Fri, Jan 23, 2026 at 02:26:29AM -0800, Genevieve Evans wrote:
One of the developers I am working with said I could share the finalized Python function we will be using:
```
def read_refmac_structure(pdb):
# this next big adds a missing TER line that is needed for correct conversion to MMCIF
lines = []
with open(pdb, 'r') as infile:
previous_line_was_atom_or_anisou = False
for line in infile:
is_atom_or_anisou = line.startswith('ATOM') or line.startswith('ANISOU')
is_hetatm = line.startswith('HETATM')
if is_hetatm and previous_line_was_atom_or_anisou:
lines.append('TER\n')
if not line.startswith('TER'):
lines.append(line)
previous_line_was_atom_or_anisou = is_atom_or_anisou
# now convert to MMCIF
struc = gemmi.read_pdb_string(''.join(lines))
doc = struc.make_mmcif_document()
scrape_pdb_stats.run(str(pdb), doc)
return doc
```
This deals with the ANISOU record complication nicely :-)
Thanks for the insight Clemens!
--
Reply to this email directly or view it on GitHub:
#400 (comment)
You are receiving this because you commented.
Message ID: ***@***.***>
--
*--------------------------------------------------------------
* Clemens Vonrhein, Ph.D. vonrhein AT GlobalPhasing DOT com
* Global Phasing Ltd., 9 Journey Campus, Castle Park
* Cambridge CB3 0AX, UK www.globalphasing.com
*--------------------------------------------------------------
|
|
Is there an option in Gemmi to add I have looked through the documentation but did not spot it. |
|
@wojdyr I don't see an |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi Marcin,
I've been working (among other things) on a project as consultant with beamline scientists and developers who have a pipeline where due to legacy code they can only produce PDB files.
I made a small script that fixes missing TER records to the PDB file.
I can see that we can use Gemmi to generate the correct mmCIF.
I could test this using your webtools available here:
https://project-gemmi.github.io/wasm/convert/pdb2cif.html
I forked from the following repo (and have now deleted):
https://github.com/project-gemmi/wasm
I thought maybe I could figure out what the backend for the webtools were
--> if it was Python anyway...
However, as you know the back-end is C++ not Python.
I am sure there is correct set of steps with the Python Gemmi library
that one could use to do the same thing as the webtool PDB2CIF.
Unfortunately I have not figured it out yet.
Any chance you or one of your colleagues could help?
All reactions