Search code examples
rdkit

Why i can't get 3D mol structure in RDkit?


I have edited the molecule as I wanted. Now I have to export it. But mol blocks always look 2D. So my molecules become 2D. I want to get a 3D structure. Does anyone know the solution? (look at the image for the screenshot)

enter image description here


Solution

  • No issues with the code as below (version 2021.03.3):

    m_smiles = 'c1ccccc1'
    mol = Chem.MolFromSmiles(m_smiles)
    mol = Chem.AddHs(mol)
    
    AllChem.EmbedMolecule(mol, randomSeed=0xf00d)
    print(Chem.MolToMolBlock(mol))
    
    ...
    
    
         RDKit          3D
    
     12 12  0  0  0  0  0  0  0  0999 V2000
       -0.2995   -1.3510    0.0141 C   0  0  0  0  0  0  0  0  0  0  0  0
       -1.3055   -0.4032    0.0428 C   0  0  0  0  0  0  0  0  0  0  0  0
       -1.0307    0.9497    0.0294 C   0  0  0  0  0  0  0  0  0  0  0  0
        0.3037    1.3426   -0.0142 C   0  0  0  0  0  0  0  0  0  0  0  0
        1.2985    0.3934   -0.0425 C   0  0  0  0  0  0  0  0  0  0  0  0
        1.0206   -0.9630   -0.0291 C   0  0  0  0  0  0  0  0  0  0  0  0
       -0.5031   -2.4015    0.0241 H   0  0  0  0  0  0  0  0  0  0  0  0
       -2.3381   -0.7237    0.0766 H   0  0  0  0  0  0  0  0  0  0  0  0
       -1.8299    1.6790    0.0523 H   0  0  0  0  0  0  0  0  0  0  0  0
        0.5056    2.4116   -0.0242 H   0  0  0  0  0  0  0  0  0  0  0  0
        2.3290    0.7220   -0.0763 H   0  0  0  0  0  0  0  0  0  0  0  0
        1.8494   -1.6559   -0.0530 H   0  0  0  0  0  0  0  0  0  0  0  0
      1  2  2  0
      2  3  1  0
      3  4  2  0
      4  5  1  0
      5  6  2  0
      6  1  1  0
      1  7  1  0
      2  8  1  0
      3  9  1  0
      4 10  1  0
      5 11  1  0
      6 12  1  0
    M  END
    
    
    

    Some things to check:

    Check if the embed function returns a non-zero exit status, it is possible that the function failed to embed your molecule

    result = AllChem.EmbedMolecule(mol, randomSeed=0xf00d)
    assert result != 0
    

    Check if the conformer is marked as 3D

    result = AllChem.EmbedMolecule(mol, randomSeed=0xf00d)
    c = mol.GetConformer()
    print(c.Is3D())
    ...
    True
    

    Print the coordinates of the conformer

    result = AllChem.EmbedMolecule(mol, randomSeed=0xf00d)
    c = mol.GetConformer()
    print(c.GetPositions())
    ...
    [[-0.29949394 -1.35098866  0.01410225]
     [-1.30551208 -0.40318505  0.04275071]
     [-1.03072469  0.949724    0.02942649]
     [ 0.30371624  1.34255959 -0.01420523]
     [ 1.29846541  0.39342702 -0.04249222]
     [ 1.02064112 -0.96295912 -0.02906111]
     [-0.50308026 -2.40153594  0.0241313 ]
     [-2.33811252 -0.72370675  0.07656442]
     [-1.82994742  1.67895926  0.0522682 ]
     [ 0.50563305  2.41164485 -0.02424598]
     [ 2.32904788  0.72199377 -0.07627234]
     [ 1.8493672  -1.65593298 -0.05296649]]