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.

2 comments:

  1. My first conference paper: http://www.ks.uiuc.edu/Publications/Papers/PDF/DALK97/DALK97.pdf "Using TCL for Molecular Visualization and Analysis."

    In VMD the code would be something like:

    mol new 1CRN
    set coords [[atomselect top all] get {x y z}]

    ReplyDelete
  2. Yeah, that's what you get when you write a few targeted commands. Nice! This is, BTW, what the Bioclipse Scripting Language is about too, defining a new scripting language with such shortcuts, while the CDK is just a library with no intention to do things with shortcuts, but create flexibility and traceability. (I would love to be able to quantify something like that :)

    ReplyDelete