nglviewer / ngl

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

Fix parm7 parsing: guessElement for CL1 returns carbon #959

Closed papillot closed 1 year ago

papillot commented 1 year ago

A bug was visible after loading a parm7 (Amber topology file) file where a ligand contains a chlorine with an atom name like CL1. When parsing parm7 files, NGL infers the element from the atom name using the guessElement() utility function. In this function there was a limitation to atom name processing where digits were stripped from the left only, and up to 2 digits. This PR contains a change to find the first group of letters in the atom name with minimal processing (no regexp, no parseInt, only one call to .substring() at most) It also adds to the logic of element identification by recognizing 2-letters standard elements names such as Mg It was impractical to share the parm7 file where the bug was detected but a series of tests has been added to assess the guessElement function specs.