def testRenameChain(self):
        pdb1 = self._importStructurePDB('5NI1')  # A, B, C
        _dictOperations = ProtAtomStrucOperate.operationsDictInv
        args = {
            'pdbFileToBeRefined': pdb1,
            'Operation': _dictOperations['reNameChain'],
            'inputStructureChain':
            '{"model": 0, "chain": "B", "residues": 146}',
            'chainName': 'AA'
        }

        protAtomStrucExtractChain = self.newProtocol(ProtAtomStrucOperate,
                                                     **args)
        self.launchProtocol(protAtomStrucExtractChain)
        aSH2 = AtomicStructHandler()
        outFileName = protAtomStrucExtractChain.outputPdb.getFileName()
        aSH2.read(outFileName)
        atomsNumT = len([atom.id for atom in aSH2.getStructure().get_atoms()])
        # check size
        self.assertEqual(4579, atomsNumT)
        # check chain names
        d1, d2 = aSH2.getModelsChains()
        chains = d1[0].keys()
        self.assertTrue('A' in chains)
        self.assertTrue('AA' in chains)
        self.assertTrue('C' in chains)
        self.assertTrue('D' in chains)
        self.assertFalse('B' in chains)
 def extractAllChainsStep(self, structFileName):
     import json
     outFileName = self._getExtraPath("atomStruct_extractChain_%s.cif")
     aStruct1 = AtomicStructHandler(structFileName)
     listOfChains, _ = aStruct1.getModelsChains()
     for model, chainDic in listOfChains.items():
         for chainID, lenResidues in chainDic.items():
             chainIdDict = json.loads(
                 '{"model": %d, "chain": "%s", "residues": %d}' %
                 (model, str(chainID), lenResidues))
             chainIDStr = chainIdDict['chain']
             aStruct1.extractChain(modelID=chainIdDict['model'],
                                   chainID=chainIDStr,
                                   start=-1,
                                   end=sys.maxsize,
                                   filename=outFileName % chainIDStr)
             self.createOutputStep(outFileName % chainIDStr,
                                   suffix=chainIDStr)