nglviewer / ngl

WebGL protein viewer
http://nglviewer.org/ngl/
MIT License
657 stars 168 forks source link

SDF writer issues with selections #985

Open ppillot opened 1 year ago

ppillot commented 1 year ago

I've tried to export as an SDF file, a ligand extracted via a selection and noticed issues in relation with the bonds block of the SDF file.

code example:

const sview = component.structure.getView(new Selection('LIG'));
const w = new SDFWriter(sview)
console.log(w.getBlob())

The atom block looks correct, but the bond block contains every bond from the structure, with atom ids being the original indices, not the ones for each atom line number in the atom block.

Reading through the code, it appears that

  1. StructureView.eachBond does not take into account the current selection.
  2. The SDF writer directly outputs the atom indices from the bond proxy (i.e. the indices in the global bond store), not taking into account the position of the corresponding atom in the atom block.
  3. The limitation to 999 atoms is not enforced, leading to issues with column alignment in the bond block:
Screenshot 2023-05-09 at 08 39 53