Kekule.js icon indicating copy to clipboard operation
Kekule.js copied to clipboard

Measuring bond lengths and angles

Open schneiderfelipe opened this issue 3 years ago • 2 comments

Hi @partridgejiang! Is there a way to show bond lengths and/or angles by selecting atoms?

schneiderfelipe avatar Oct 15 '20 20:10 schneiderfelipe

Hi @schneiderfelipe, they can be calculated out from the atoms' coordinate with ease. For example, the length of a bond in a 2D molecule model can be calculated by the following code:

var atoms = bond.getConnectedChemNodes();
var coord1 = atoms[0].getAbsCoord2D();
var coord2 = atoms[1].getAbsCoord2D();
var bondLength = Kekule.CoordUtils.getDistance(coord1, coord2);

To get the bond angle of three neighboring atoms (atom1-atom2-atom3):

var coord1 = atoms1.getAbsCoord2D();
var coord2 = atoms2.getAbsCoord2D();
var coord3 = atoms3.getAbsCoord2D();
var vector1 = Kekule.CoordUtils.substract(coord1, coord2);
var vector2 = Kekule.CoordUtils.substract(coord3, coord2);
var angle = Kekule.GeometryUtils.getVectorIncludedAngle2(vector1, vector2);

partridgejiang avatar Oct 17 '20 04:10 partridgejiang

Thanks, @partridgejiang, that is really useful! I was wondering if I could make somehow it interactive.

schneiderfelipe avatar Oct 17 '20 15:10 schneiderfelipe