Skip to content

IterateOverAllProteinsOfASystem

dstoeckel edited this page Mar 16, 2015 · 2 revisions

How can I iterate over all Proteins of a System?

Iterate over all Proteins in a System using BALL's MoleculeIterator:

C++

#include <BALL/FORMAT/PDBFile.h>
#include <BALL/KERNEL/system.h>
#include <BALL/KERNEL/protein.h>

...
using namespace BALL;
using namespace std;
...

// read the PDB-file into a BALL::System
PDBFile f("myProtein.pdb");
System S;
f >> S;	

for (MoleculeIterator m_it = S.beginMolecule(); +m_it; ++m_it)
{
   if (RTTI::isKindOf<Protein>(*(m_it)))
   {
      // cast to BALL::Protein
      Protein* protein = RTTI::castTo<Protein>(*(m_it));
   
      // get the protein's sequence
      cout << Peptides::GetSequence(*protein) << endl;
   }
}

Note that _+m_it _ equals m_it != S.endMolecule() !

Note also: Never try to add or remove Molecules 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)

for protein in proteins(S):
  # get the protein's sequence
  print Peptides.GetSequence(protein)

Clone this wiki locally