BioJava:CookBook:PDB:read

From BioJava

Jump to: navigation, search

How do I read a PDB file?

BioJava provides a flexible data model for managing protein structural data. The example below shows how to read a PDB file from your file system, obtain a Structure object and iterate over the Groups that are contained in the file. For more examples of how to access the Atoms please go to BioJava:CookBook:PDB:atoms. For more info on how the parser deals with SEQRES and ATOM records please see BioJava:CookBook:PDB:seqres


// also works for gzip compressed files
 String filename =  "path/to/pdbfile.ent" ;
 
 PDBFileReader pdbreader = new PDBFileReader();
 
 // the following parameters are optional: 
 
 //the parser can read the secondary structure
 // assignment from the PDB file header and add it to the amino acids
 pdbreader.setParseSecStruc(true);
 
 // align the SEQRES and ATOM records, default = true   
 // slows the parsing speed slightly down, so if speed matters turn it off.
 pdbreader.setAlignSeqRes(true);
  
 // parse the C-alpha atoms only, default = false
 pdbreader.setParseCAOnly(false);
 
 // download missing PDB files automatically from EBI ftp server, default = false
 pdbreader.setAutoFetch(false);
 
 try{
     Structure struc = pdbreader.getStructure(filename);
     
     System.out.println(struc);
 
     GroupIterator gi = new GroupIterator(struc);
 
     while (gi.hasNext()){
 
           Group g = (Group) gi.next();
          
           if ( g instanceof AminoAcid ){
               AminoAcid aa = (AminoAcid)g;
               Map sec = aa.getSecStruc();
               Chain  c = g.getParent();
               System.out.println(c.getName() + " " + g + " " + sec);
           }                
     }
 
 } catch (Exception e) {
     e.printStackTrace();
 }


To learn how to serialize a Structure object to a database see BioJava:CookBook:PDB:hibernate

Next: BioJava:CookBook:PDB:atoms - How to access atoms.

Personal tools