Skip to content

ComputeSecondaryStruture

dstoeckel edited this page Apr 28, 2015 · 2 revisions

How can I compute the secondary structure a molecule?

C++

This is a short example on how to compute the secondary structure of all proteins in a system. It also shows how to iterate over the secondary structures:

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

using namespace BALL;

int main(int argc, char* argv[])
{
  PDBFile f(argv[1]);

  System s;
  f >> s;

  //Compute the secondary structure
  SecondaryStructureProcessor sp;
  s.apply(sp);

  //Iterate over all proteins and print the secondary structure
  for(ProteinIterator pit = s.beginProtein(); +pit; ++pit)
  {
    std::cout << "Protein: " << pit->getName() << "\n";
    for(SecondaryStructureIterator sit = pit->beginSecondaryStructure(); +sit; ++sit) {
      std::cout << "\t";
      switch(sit->getType()) {
        case SecondaryStructure::HELIX:
          std::cout << "Helix:   ";
          break;
        case SecondaryStructure::COIL:
          std::cout << "Coil:    ";
          break;
        case SecondaryStructure::TURN:
          std::cout << "Turn:    ";
          break;
        case SecondaryStructure::STRAND:
          std::cout << "Strand:  ";
          break;
        case SecondaryStructure::UNKNOWN:
          std::cout << "Unknown: ";
          break;
      }

      for(ResidueIterator rit = sit->beginResidue(); +rit; ++rit) {
        std::cout << " " << rit->getID() << " " << rit->getName();
      }
      std::cout << "\n";
    }
    std::cout << "\n";
  }

  return 0;
}

Python

# get a system
s = getSystem(0)

# compute the secondary strucures
sp=SecondaryStructureProcessor()
s.apply(sp)

for res in residues(s):
  ss = res.getSecondaryStructure()
  print ss.countResidues()
  print ss.getType()

If the secondary structure is computed you can use following code to print the types:

s = getSystem(0)
smap = { 0:'H', 1:'C', 2:'S', 3:'T', 4:'?'}
for r in residues(s.getProtein(0).getChain(0)):
    print smap[r.getSecondaryStructure().getType()]

Please note, that for secondary structures compute by our DSSP implementation S=T!

Clone this wiki locally