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.
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 theguessElement()
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, noparseInt
, only one call to.substring()
at most) It also adds to the logic of element identification by recognizing 2-letters standard elements names such asMg
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.