Pages

Monday, January 31, 2011

Extracting 3D coordinates from PDB files with Groovy CDK

BioStar featured a question today about how to extract 3D coordinates from PDB files. Now, a simple script may actually do, and BioJava was mentioned too. Of course, it can also be done with the CDK. For example using this Groovy code:

import org.openscience.cdk.interfaces.*;
import org.openscience.cdk.io.*;
import org.openscience.cdk.tools.manipulator.*;
import org.openscience.cdk.io.IChemObjectReader.Mode;
import org.openscience.cdk.*;
import java.io.File;
import java.util.zip.GZIPInputStream;

reader = new PDBReader(
  new GZIPInputStream(
    new URL(
      "http://www.pdb.org/pdb/files/1CRN.pdb.gz"
    ).openStream()
  )
);
crambin = reader.read(new ChemFile());
for (container in 
     ChemFileManipulator.getAllAtomContainers(
       crambin
     )) {
  for (atom in container.atoms()) {
    println atom.point3d;
  }
}

Wondering what the Bioclipse Scripting Language version would look like... and, it can likely be done with Jmol script too.