Skip to content

IterateOverAllChainsInASystem

jleclaire edited this page Apr 25, 2017 · 4 revisions

How can I iterate over all chains in a System?

Iterate over all Chains in a System using BALL's ChainIterator:

C++

#include <BALL/KERNEL/chainIterator.h>
...
BALL::System S;
...
BALL::ChainIterator ch_it = S.beginChain();
for (; +ch_it; ++ch_it)
{
   std::cout << ch_it->countResidues() << std::endl;
}

Note, that +ch_it equals ch_it != S.endChain() !

Note also: Never try to add or remove atoms or chains from the System while iterating over it! Your program will crash!

python

import sys
from BALL import *


# read the PDB-file into a BALL::System
f = PDBFile(sys.argv[1])
S = System()
f.read(S)

print "Number of chains :" , len(chains(S))

for chain in chains(S):
  print "Number of residues: ", chain.countResidues()
Clone this wiki locally