Saturday, September 02, 2006

Calculating geometrical properties with the CDK

ケムインフォマティクスに虚空投げ runs a story on how to calculate geometrical properties of a 3D structure using CDK's ForceFieldTools. This class contains a few methods to calculate distances between atoms and angles between bonds.

This tools class is special as it uses vecmath GVector objects, which just contain atomic coordinates, likely suitable for extensive computation, as expected in CDK's force field implementation. However, for just calculating the distance and angles, there are simpler alternatives.

The distance between two atoms can be calculated with:

atom1 = molecule.getAtom(0);
atom2 = molecule.getAtom(1);
double dist = atom1.getPoint3d().distance(atom2.getPoint3d());

or, by constructing a vector for the bond first:

Vector3d bond1to2 = new Vector3d(atom2.getPoint3d());
double dist = bond1to2.length();

Using vectors to represent bond (with two atoms!), allows easily calculating angles too (assuming the bonds shard atom1):

double angle = bond1to2.angle(bond1to3);

Vecmath does not seem to contain a convenience method for calculating torsion angles :(

1 comment:

  1. JUMBO has a torsion angle routine in its euclid library if you want to lift one. However I think it would make sense to refactor euclid to use vecmath at some stage if we standardise on it...