3dmol / 3Dmol.js

WebGL accelerated JavaScript molecular graphics library
https://3dmol.org/
Other
803 stars 194 forks source link

Extract partial charges from Mol2 files #39

Closed ghutchis closed 9 years ago

ghutchis commented 9 years ago

Most mol2 files include atomic partial charges. It would be awesome to use the potentials defined by the file rather than residue-based charges, e.g.:

  1 O          -3.9862   -0.0915   -0.4753 O.2     1  UNL11111   -0.4322
  2 C          -3.1086   -0.7606    0.0104 C.2     1  UNL11111    0.3255
  3 C          -1.9542   -0.0724    0.7328 C.3     1  UNL11111   -0.0217
  4 H          -2.0091   -0.2416    1.8344 H       1  UNL11111    0.1622
  5 O          -2.0231    1.3296    0.5822 O.3     1  UNL11111   -0.5655

The last column is always the partial charge. Open Babel's parser looks like this:

   sscanf(buffer," %*s %1024s %lf %lf %lf %1024s %d %1024s %lf",
           atmid, &x,&y,&z, temp_type, &resnum, resname, &pcharge);

This would imply that there's always(?) a token[8] entry with the floating-point partial charge.

dkoes commented 9 years ago

Okay, I've committed this fix. You can color by the partialCharge property like so:

m.setColorByProperty({}, 'charge', new $3Dmol.Gradient.RWB(-0.5,0.5)); //this sets the default color of each atom based on the charge
//you can specify a mapping for a surface (or you can just let it pick up the set atom colors, but this let's you keep the atom colors at their default)
glviewer.addSurface($3Dmol.SurfaceType.VDW, {map:{prop:'partialCharge',scheme:new $3Dmol.Gradient.RWB(-.5,.5)}, opacity:0.8});