Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

MOL2: UNITY_ATOM_ATTR section prevents correct formal charge assignment

Abierto
#9,634 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python

Línea de trabajo

Look at the Mol2 parser in the RDKit source code, likely in Code/GraphMol/FileParsers/Mol2Parser.cpp or similar. The bug is in how the UNITY_ATOM_ATTR section is handled. Start by reproducing the issue with the provided test files. Then trace the code path that reads formal charges and see why the presence of that section interferes. The fix should ensure formal charge assignment is independent of unrelated atom attributes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug

Describe the bug
Presence of the @<TRIPOS>UNITY_ATOM_ATTR in a .mol2 file affects the formal charges assigned by RDKit, even when this section contains no formal-charge information. In the attached example, the section contains only MMFF94 partial charges. Nevertheless, its presence prevents RDKit from assigning the expected +1 formal charge to a four-coordinate nitrogen. This subsequently causes an AtomValenceException during sanitization.

To Reproduce
test.mol2.txt
test_truncated.mol2.txt

Download attached .txt files (they're .mol2 files, but GitHub does not support this format as attachement). Both files represent the same molecule. The difference is that test.mol2.txt contains an additional @<TRIPOS>UNITY_ATOM_ATTR section with MMFF94 partial charges.

The following script:

from rdkit import Chem

with open("test_truncated.mol2.txt") as f:
    txt = f.read()

mol = Chem.MolFromMol2Block(
    txt,
    sanitize=False,
)
print(mol.GetAtomWithIdx(0).GetFormalCharge()) # 1 
Chem.SanitizeMol(mol) # ok 
print(mol)

with open("test.mol2.txt") as f:
    txt = f.read()

mol = Chem.MolFromMol2Block(
    txt,
    sanitize=False,
)
print(mol.GetAtomWithIdx(0).GetFormalCharge()) # 0 
Chem.SanitizeMol(mol) # AtomValenceException: Explicit valence for atom # 0 N, 4, is greater than permitted
print(mol)

outputs:

1
<rdkit.Chem.rdchem.Mol object at 0x7fdfdcd05930>
0
[09:37:28] Explicit valence for atom # 0 N, 4, is greater than permitted
Traceback (most recent call last):
  File "/home/mtrojanowski/bdocker/scripts/skrypcik.py", line 22, in <module>
    Chem.SanitizeMol(mol) # AtomValenceException: Explicit valence for atom # 0 N, 4, is greater than permitted
    ^^^^^^^^^^^^^^^^^^^^^
rdkit.Chem.rdchem.AtomValenceException: Explicit valence for atom # 0 N, 4, is greater than permitted

Therefore, the presence of an @<TRIPOS>UNITY_ATOM_ATTR section containing unrelated atom attributes causes atom #0 N to have formal charge 0 instead of +1, which then causes an AtomValenceException during sanitization.

Expected behavior
The @<TRIPOS>UNITY_ATOM_ATT section that does not specify formal charges should not affect RDKit's determination of formal charges for the molecule.

Configuration (please complete the following information):

  • RDKit version: 2025.9.6
  • OS: Ubuntu 24.04
  • Python version: 3.11.0
  • Are you using conda? No
  • If you are not using conda: how did you install the RDKit? pip (via uv)
Lenguaje dominante
HTML
Estrellas
3.6k
Forks
1.1k
Merge medio
3 d 8 h
PR fusionados (30 d)
44

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de rdkit/rdkit

Todos los issues de rdkit/rdkit

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.