Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AddHs creates H atom with nan coordinates on edge case 2D structure #3854

Closed
ricrogz opened this issue Feb 24, 2021 · 0 comments · Fixed by #3855
Closed

AddHs creates H atom with nan coordinates on edge case 2D structure #3854

ricrogz opened this issue Feb 24, 2021 · 0 comments · Fixed by #3855
Labels
Milestone

Comments

@ricrogz
Copy link
Contributor

ricrogz commented Feb 24, 2021

This illustrates the problem:

In [1]: from rdkit import Chem 
   ...: mol = Chem.MolFromMolBlock(""" 
   ...:      RDKit          2D 
   ...:  
   ...:   7  8  0  0  1  0  0  0  0  0999 V2000 
   ...:     5.0014    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0 
   ...:     4.1764    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0 
   ...:     3.3514    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0 
   ...:     2.9389    1.1271    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0 
   ...:     3.3514    1.8412    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0 
   ...:     4.1764    1.8412    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0 
   ...:     4.5889    1.1271    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0 
   ...:   2  1  1  1 
   ...:   7  1  1  1 
   ...:   2  3  1  0 
   ...:   2  7  1  0 
   ...:   3  4  1  0 
   ...:   4  5  1  0 
   ...:   5  6  1  0 
   ...:   7  6  1  0 
   ...: M  END 
   ...: """) 
   ...: res = Chem.AddHs(mol, explicitOnly=False, addCoords=True, onlyOnAtoms=[1, 6]) 
   ...: print(Chem.MolToMolBlock(res))                                                                                                                                              

     RDKit          2D

  9 10  0  0  1  0  0  0  0  0999 V2000
    5.0014    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.1764    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.3514    0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    2.9389    1.1271    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    3.3514    1.8412    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.1764    1.8412    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    4.5889    1.1271    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
       nan       nan       nan H   0  0  0  0  0  0  0  0  0  0  0  0
    3.7229    0.6270    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
  2  1  1  0
  7  1  1  0
  2  3  1  0
  2  7  1  0
  3  4  1  0
  4  5  1  0
  5  6  1  0
  7  6  1  0
  2  8  1  1
  7  9  1  6
M  END

This is apparently happening because atoms 0, 1 and 6 are perfectly aligned:
image

If coordinates are regenerated, so that they are no longer perectly aligned, all is fine:

In [2]: params = Chem.rdCoordGen.CoordGenParams() 
   ...: Chem.rdCoordGen.AddCoords(mol, params) 
   ...: print(Chem.MolToMolBlock(mol))                                                                                                                                              

     RDKit          2D

  7  8  0  0  1  0  0  0  0  0999 V2000
   -1.4846   -0.0011    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.6190    0.4995    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.2466    1.0003    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.1130    0.5009    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.1138   -0.4991    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.2482   -0.9997    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.6182   -0.5005    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
  2  1  1  1
  7  1  1  1
  2  3  1  0
  2  7  1  0
  3  4  1  0
  4  5  1  0
  5  6  1  0
  7  6  1  0
M  END


In [3]: res = Chem.AddHs(mol, explicitOnly=False, addCoords=True, onlyOnAtoms=[1, 6]) 
   ...: print(Chem.MolToMolBlock(res))                                                                                                                                              

     RDKit          2D

  9 10  0  0  1  0  0  0  0  0999 V2000
   -1.4846   -0.0011    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.6190    0.4995    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.2466    1.0003    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.1130    0.5009    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    1.1138   -0.4991    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
    0.2482   -0.9997    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -0.6182   -0.5005    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0
   -1.1197    1.3651    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
   -0.1189    0.3659    0.0000 H   0  0  0  0  0  0  0  0  0  0  0  0
  2  1  1  0
  7  1  1  0
  2  3  1  0
  2  7  1  0
  3  4  1  0
  4  5  1  0
  5  6  1  0
  7  6  1  0
  2  8  1  6
  7  9  1  6
M  END
@ricrogz ricrogz added the bug label Feb 24, 2021
@greglandrum greglandrum added this to the 2020_09_5 milestone Feb 25, 2021
greglandrum added a commit that referenced this issue Mar 1, 2021
* add fix

* add test

* fix the referenced issue

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
greglandrum added a commit that referenced this issue Mar 1, 2021
* add fix

* add test

* fix the referenced issue

Co-authored-by: Greg Landrum <greg.landrum@gmail.com>
greglandrum added a commit to greglandrum/rdkit that referenced this issue Mar 9, 2021
greglandrum added a commit that referenced this issue Mar 10, 2021
* backup

* Fixes #3879
also simplifies the code to place Hs

* switch to bisecting the angle

* reapply the fix for #3854
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants