Repository: ihmwg/python-ihm

Issue:
Missing auth_seq_id from _atom_site
I am using python-ihm to generate mmcif files based on pdbs generated by docking.

However I noticed that `_atom_site.auth_seq_id` is missing from the dump atoms function: https://github.com/ihmwg/python-ihm/blob/fb9199d655bef19b66674dc6334ea24ecd68259b/ihm/dumper.py#L1461

Then the generated PDBs are displayed with their seq_id residue numbering instead of the desired user-inputted numbering.

I patched it by adding `auth_seq_id` to the loop on `ihm/dumper.py#L1464` and also to the writing section `ihm/dumper.py#L1481` and now I am getting the correct numbering on the .cif file.

 Is this actually missing? If so I can do a pull request with my changes, else please let me know if I am not using it correctly.

Discussion:

Patch:
diff --git a/ihm/dumper.py b/ihm/dumper.py
index 4511db3..c9189a1 100644
--- a/ihm/dumper.py
+++ b/ihm/dumper.py
@@ -1464,7 +1464,7 @@ class _ModelDumper(Dumper):
         with writer.loop("_atom_site",
                          ["group_PDB", "id", "type_symbol",
                           "label_atom_id", "label_alt_id", "label_comp_id",
-                          "label_seq_id",
+                          "label_seq_id", "auth_seq_id",
                           "label_asym_id", "Cartn_x",
                           "Cartn_y", "Cartn_z", "occupancy", "label_entity_id",
                           "auth_asym_id",
@@ -1477,6 +1477,10 @@ class _ModelDumper(Dumper):
                     seq_id = 1 if atom.seq_id is None else atom.seq_id
                     comp = atom.asym_unit.entity.sequence[seq_id - 1]
                     seen_types[atom.type_symbol] = None
+                    if isinstance(atom.asym_unit.auth_seq_id_map, dict):
+                        auth_id = atom.asym_unit.auth_seq_id_map[atom.seq_id]
+                    else:
+                        auth_id = atom.seq_id
                     lp.write(id=next(ordinal),
                              type_symbol=atom.type_symbol,
                              group_PDB='HETATM' if atom.het else 'ATOM',
@@ -1485,6 +1489,7 @@ class _ModelDumper(Dumper):
                              label_asym_id=atom.asym_unit._id,
                              label_entity_id=atom.asym_unit.entity._id,
                              label_seq_id=atom.seq_id,
+                             auth_seq_id=auth_id,
                              auth_asym_id=atom.asym_unit._id,
                              Cartn_x=atom.x, Cartn_y=atom.y, Cartn_z=atom.z,
                              B_iso_or_equiv=atom.biso,


Test patch:
diff --git a/test/test_dumper.py b/test/test_dumper.py
index c27f6a5..a7df191 100644
--- a/test/test_dumper.py
+++ b/test/test_dumper.py
@@ -2139,6 +2139,7 @@ _atom_site.label_atom_id
 _atom_site.label_alt_id
 _atom_site.label_comp_id
 _atom_site.label_seq_id
+_atom_site.auth_seq_id
 _atom_site.label_asym_id
 _atom_site.Cartn_x
 _atom_site.Cartn_y
@@ -2149,9 +2150,9 @@ _atom_site.auth_asym_id
 _atom_site.B_iso_or_equiv
 _atom_site.pdbx_PDB_model_num
 _atom_site.ihm_model_id
-ATOM 1 C C . ALA 1 X 1.000 2.000 3.000 . 9 X . 1 1
-HETATM 2 C CA . ALA 1 X 10.000 20.000 30.000 . 9 X . 1 1
-ATOM 3 N N . CYS 2 X 4.000 5.000 6.000 0.200 9 X 42.000 1 1
+ATOM 1 C C . ALA 1 1 X 1.000 2.000 3.000 . 9 X . 1 1
+HETATM 2 C CA . ALA 1 1 X 10.000 20.000 30.000 . 9 X . 1 1
+ATOM 3 N N . CYS 2 2 X 4.000 5.000 6.000 0.200 9 X 42.000 1 1
 #
 #
 loop_
diff --git a/test/test_examples.py b/test/test_examples.py
index 5c72a38..38270e0 100644
--- a/test/test_examples.py
+++ b/test/test_examples.py
@@ -39,7 +39,7 @@ class Tests(unittest.TestCase):
             # can read it
             with open(os.path.join(tmpdir, 'output.cif')) as fh:
                 contents = fh.readlines()
-            self.assertEqual(len(contents), 313)
+            self.assertEqual(len(contents), 314)
             with open(os.path.join(tmpdir, 'output.cif')) as fh:
                 s, = ihm.reader.read(fh)