ProGAL examples

Reading a PDB-file and printing coordinates of atoms

ProGAL.proteins.PDBFile represents a PDB-file and all its contents. It even tries to manage some of the common mistakes made in PDB-file such as non-consecutive numbering etc. The following code loads a PDB-file from the filesystem (assuming the file exists) and prints the coordinates of all atoms.

PDBFile file = new PDBFile("../datasets/2CRO.pdb");
//Alternatively, download the file automatically from
//PDBFile file = new PDBFile(PDBWebReader.downloadPDBFile("2CRO"));

List<Point> coords = file.getAtomCoords();
for(int i=0;i<coords.size();i++){
   System.out.println( coords.get(i) );
JavaDoc links:

Retrieving coordinates of only specific types of atoms

AtomRecord is a static inner class of ProGAL.proteins.PDBFile that holds a lot of information about each atom. One way to use this information is shown in the second half of this example.

PDBFile file = new PDBFile(PDBWebReader.downloadPDBFile("2CRO"));
List<Point> allCoords = file.getAtomCoords();
List<Point> caCoords = file.getAtomCoords("CA");
List<Point> backboneCoords = file.getAtomCoords("N,CA,C,O");

//Retrieve coordinates of all cysteine side-chains
List<PDBFile.AtomRecord> atomRecords = file.getAtomRecords();
List<Point> cysSideChains = new ArrayList<Point>();
for(PDBFile.AtomRecord ar: atomRecords){
   if( ar.aaType.equalsIgnoreCase("CYS") && 
       ( ar.atomType.equalsIgnoreCase("CB") ||
         ar.atomType.equalsIgnoreCase("SG") ) ){

      cysSideChains.add( ar.coords );
JavaDoc links:

Display a stick-model of a protein

List<Point> points = new PDBFile(PDBWebReader.downloadPDBFile("2CRO")).getAtomCoords();
J3DScene scene = J3DScene.createJ3DSceneInFrame();
for(Point p1: points){
   for(Point p2: points){
      if(p1==p2) break;//Dont add bonds twice
      if(p1.distance(p2)<1.9){//Typical covalent bond distance
         //An LSS is a cylinder-like shape. 
         Shape bond = new LSS(p1,p2,0.2);

         //Paint only 5 sub-divisions to spare the memory
         scene.addShape( bond, java.awt.Color.GRAY, 5 );
JavaDoc links:

Build an alpha complex

This example builds an alpha complex of a protein and visualizes it.

List<Point> points = new PDBFile(PDBWebReader.downloadPDBFile("2CRO")).getAtomCoords();
AlphaComplex ac = new AlphaComplex(points, 2.8);
J3DScene scene = J3DScene.createJ3DSceneInFrame();
//Display triangles
for(CTriangle tri: ac.getTriangles()){
   scene.addShape(tri, java.awt.Color.BLUE);
JavaDoc links:

Display the alpha shape

This example builds an alpha filtration of a protein but visualizes only the alpha-shape.

PDBFile pdb = new PDBFile(PDBWebReader.downloadPDBFile("2CRO"));
List<Point> points = pdb.getAtomCoords();
AlphaFiltration af = new AlphaFiltration(points);
List<CTriangle> triangles = af.getAlphaShape(2.8);
J3DScene scene = J3DScene.createJ3DSceneInFrame();
for(CTriangle tri: triangles)
   scene.addShape(tri, java.awt.Color.BLUE);
JavaDoc links:

Display a set of points in 2D

Generates some random 2D points and displays them using J2DScene.

//Generate points
List<Point> points = new ArrayList<Point>();
for(int i=0;i<10;i++) 
   points.add(new Point(Math.random(), Math.random()));

//Display them
J2DScene scene = J2DScene.createJ2DSceneInFrame();
scene.addShape(new LineSegment(new Point(0,0), new Point(1,0)), Color.BLACK);
scene.addShape(new LineSegment(new Point(0,0), new Point(0,1)), Color.BLACK);
for(Point p: points){
   //A filled circle with radius 0.01 and border 0
   scene.addShape(new Circle(p, 0.01), Color.BLACK, 0, true);
JavaDoc links:

Animate a sphere

J3DScene scene = J3DScene.createJ3DSceneInFrame();

Sphere ball = new Sphere(new Point(0,0,0), 0.2);
scene.addShape(ball, java.awt.Color.BLUE);

double time = 0;
   ball.getCenter().set( new Point(Math.cos(time),0,0) );   
   time = time+0.05;

   try { Thread.sleep(30); } catch (InterruptedException e) { break; }
JavaDoc links: