From 9e42eac70df58b463d81ef4b3f606d954992668e Mon Sep 17 00:00:00 2001
From: Marco Biasini <marco.biasini@unibas.ch>
Date: Wed, 19 Jun 2013 13:20:06 +0200
Subject: [PATCH] remember PDBize residue number

this is a follow up to 76b079d7a, in which part of the problem, but not
the complete one was fixed.
---
 modules/io/tests/test_io_mmcif.py | 13 +++++++++++++
 modules/mol/alg/src/pdbize.cc     |  7 +++----
 modules/mol/alg/src/pdbize.hh     |  4 +++-
 3 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/modules/io/tests/test_io_mmcif.py b/modules/io/tests/test_io_mmcif.py
index a11811f59..d5dcf651c 100644
--- a/modules/io/tests/test_io_mmcif.py
+++ b/modules/io/tests/test_io_mmcif.py
@@ -136,6 +136,19 @@ class TestMMCifInfo(unittest.TestCase):
     self.assertEquals(tr_ol[0][0], 0)
     self.assertEquals(tr_ol[0][1], 1)
 
+  def test_mmcifinfo_biounit_pdbize_with_multiple_transforms(self):
+    ent, seqres, info = io.LoadMMCIF("testfiles/mmcif/multiple_transforms.cif.gz",
+                                     seqres=True,
+                                     info=True)
+    pdb_ent = info.GetBioUnits()[0].PDBize(ent)
+    pdb_seqres_ent = info.GetBioUnits()[0].PDBize(ent, seqres)
+    chains = pdb_ent.chains
+    self.assertEquals([c.name for c in chains], 
+                      ['A', '_', '-', 'B', 'C', 'D'])
+    ligand_chain = chains[1]
+    ligand_residues = ligand_chain.residues
+    self.assertEquals([r.number for r in ligand_residues],
+                      [mol.ResNum(1), mol.ResNum(2), mol.ResNum(3), mol.ResNum(4)])
   def test_mmcifinfo_biounit_pdbize(self):
     ent, seqres, info = io.LoadMMCIF("testfiles/mmcif/3T6C.cif.gz",
                                      seqres=True,
diff --git a/modules/mol/alg/src/pdbize.cc b/modules/mol/alg/src/pdbize.cc
index 4b6fd0d57..9e3638358 100644
--- a/modules/mol/alg/src/pdbize.cc
+++ b/modules/mol/alg/src/pdbize.cc
@@ -70,7 +70,6 @@ void PDBize::Add(EntityView asu, const geom::Mat4List& transforms,
 {
   XCSEditor edi = ent_.EditXCS(BUFFERED_EDIT);
 
-  int last_rnum = 0;
   for (geom::Mat4List::const_iterator i = transforms.begin(), 
        e = transforms.end(); i != e; ++i) {
     for (ChainViewList::const_iterator j = asu.GetChainList().begin(),
@@ -125,14 +124,14 @@ void PDBize::Add(EntityView asu, const geom::Mat4List& transforms,
       // deal with ligands...
       if (!ligand_chain_) {
         ligand_chain_ = edi.InsertChain(LIGAND_CHAIN_NAME);
-        last_rnum = 0;
+        last_rnum_ = 0;
       }
       char ins_code = chain.GetResidueCount()>1 ? 'A' : '\0';
      
       for (ResidueViewList::const_iterator k = chain.GetResidueList().begin(),
            e3 = chain.GetResidueList().end(); k != e3; ++k) {
         ResidueHandle new_res = edi.AppendResidue(ligand_chain_, k->GetName(),
-                                                  ResNum(last_rnum+1, ins_code));
+                                                  ResNum(last_rnum_+1, ins_code));
         transfer_residue_properties(*k, new_res);
         new_res.SetStringProp("type", StringFromChainType(chain.GetType()));
         new_res.SetStringProp("description", chain.GetDescription());
@@ -144,7 +143,7 @@ void PDBize::Add(EntityView asu, const geom::Mat4List& transforms,
         ins_code += 1;
         needs_adjustment_ |= copy_atoms(*k, new_res, edi, *i);
       }
-      last_rnum+=1;
+      last_rnum_+=1;
     }
   }
 }
diff --git a/modules/mol/alg/src/pdbize.hh b/modules/mol/alg/src/pdbize.hh
index 00534a4cf..f3afec693 100644
--- a/modules/mol/alg/src/pdbize.hh
+++ b/modules/mol/alg/src/pdbize.hh
@@ -36,7 +36,8 @@ class DLLEXPORT_OST_MOL_ALG PDBize {
 public:
   explicit PDBize(int min_polymer_size=10):
     min_polymer_size_(min_polymer_size), ent_(mol::CreateEntity()),
-    curr_chain_name_(POLYPEPTIDE_CHAIN_NAMES), needs_adjustment_(false)
+    curr_chain_name_(POLYPEPTIDE_CHAIN_NAMES), needs_adjustment_(false),
+    last_rnum_(0)
   {}
 
   void Add(mol::EntityView asu, const geom::Mat4List& transforms,
@@ -50,6 +51,7 @@ private:
   ChainHandle                           water_chain_;
   const char*                           curr_chain_name_;
   bool                                  needs_adjustment_;
+  int                                   last_rnum_;
   std::map<ResidueHandle,ResidueHandle> dst_to_src_map_;
 };
 
-- 
GitLab