|
| 1 | +First Steps |
| 2 | +=========== |
| 3 | + |
| 4 | +## First steps |
| 5 | + |
| 6 | +The simplest way to load a PDB file is by using the [StructureIO](http://www.biojava.org/docs/api/org/biojava3/structure/StructureIO.html) class. |
| 7 | + |
| 8 | +<pre> |
| 9 | + public static void main(String[] args){ |
| 10 | + |
| 11 | + try { |
| 12 | + Structure structure = StructureIO.getStructure("4HHB"); |
| 13 | + // and let's print out how many atoms are in this structure |
| 14 | + System.out.println(StructureTools.getNrAtoms(structure)); |
| 15 | + } catch (Exception e){ |
| 16 | + e.printStackTrace(); |
| 17 | + } |
| 18 | + } |
| 19 | +</pre> |
| 20 | + |
| 21 | +BioJava automatically downloads the PDB file for hemoglobin [4HHB](http://www.rcsb.org/pdb/explore.do?structureId=4HHB) and copies it into a temporary location. Then the PDB file parser loads the data into a [Structure](http://www.biojava.org/docs/api/org/biojava/bio/structure/Structure.html) object, that provides access to the content in the file. (If you call this a second time, BioJava will automatically re-use the local file.) |
| 22 | + |
| 23 | +<table> |
| 24 | + <tr> |
| 25 | + <td> |
| 26 | + <a href="http://www.rcsb.org/pdb/explore.do?structureId=4hhb"><img src="img/4hhb_bio_r_250.jpg"/></a> |
| 27 | + </td> |
| 28 | + <td> |
| 29 | + The crystal structure of human deoxyhaemoglobin PDB ID <a href="http://www.rcsb.org/pdb/explore.do?structureId=4hhb">4HHB</a> (image source: <a href="http://www.rcsb.org/pdb/explore.do?structureId=4hhb">RCSB</a>) |
| 30 | + </tr> |
| 31 | +</table> |
| 32 | + |
| 33 | + |
| 34 | + |
| 35 | +This demonstrates two things: |
| 36 | + |
| 37 | ++ BioJava can automatically download and install files locally (more on this in Chapter 4) |
| 38 | ++ BioJava by default writes those files into a temporary location (The system temp directory "java.io.tempdir"). |
| 39 | + |
| 40 | +If you already have a local PDB installation, you can configure where BioJava should read the files from by setting the PDB_DIR system property |
| 41 | + |
| 42 | +<pre> |
| 43 | + -DPDB_DIR=/wherever/you/want/ |
| 44 | +</pre> |
| 45 | + |
| 46 | +## A Quick 3D View |
| 47 | + |
| 48 | +If you have the *biojava-structure-gui* module installed, you can quickly visualise a [Structure](http://www.biojava.org/docs/api/org/biojava/bio/structure/Structure.html) via this: |
| 49 | + |
| 50 | +<pre> |
| 51 | + public static void main(String[] args){ |
| 52 | + |
| 53 | + try { |
| 54 | + |
| 55 | + Structure struc = StructureIO.getStructure("4hhb"); |
| 56 | + |
| 57 | + StructureAlignmentJmol jmolPanel = new StructureAlignmentJmol(); |
| 58 | + |
| 59 | + jmolPanel.setStructure(struc); |
| 60 | + |
| 61 | + // send some commands to Jmol |
| 62 | + jmolPanel.evalString("select * ; color chain;"); |
| 63 | + jmolPanel.evalString("select *; spacefill off; wireframe off; cartoon on; "); |
| 64 | + jmolPanel.evalString("select ligands; cartoon off; wireframe 0.3; spacefill 0.5; color cpk;"); |
| 65 | + |
| 66 | + } catch (Exception e){ |
| 67 | + e.printStackTrace(); |
| 68 | + } |
| 69 | + } |
| 70 | +</pre> |
| 71 | + |
| 72 | +This will result in the following view: |
| 73 | + |
| 74 | +<table> |
| 75 | + <tr> |
| 76 | + <td> |
| 77 | + <img src="img/4hhb_jmol.png"/> |
| 78 | + </td> |
| 79 | + <td> |
| 80 | + The <a href="http://www.biojava.org/docs/api/org/biojava/bio/structure/align/gui/jmol/StructureAlignmentJmol.html">StructureAlignmentJmol</a> class provides a wrapper for the <a href="http://jmol.sourceforge.net/">Jmol</a> viewer and provides a bridge to BioJava, so Structure objects can be sent to Jmol for visualisation. |
| 81 | + </td> |
| 82 | + </tr> |
| 83 | +</table> |
0 commit comments