Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

to_smiles raises KeyError for N/S-containing adsorbates with vdW bonds

Aperta Adatta ai principianti
#3,014 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
1-3 ore
Idoneità per principianti
88/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python
Ambito
backend

Direzione di ricerca

Inizia con lo snippet di riproduzione dell'issue: solleva KeyError: 0.0 in to_ob_mol in rmgpy/molecule/converter.py, dove il dizionario orders mappa gli ordini di legame di RMG a quelli di OpenBabel e manca di una voce per l'ordine 0 (vdW). Confronta con il modo in cui il percorso RDKit in rmgpy/molecule/converter.py mappa i legami vdW a UNSPECIFIED, e decidi se aggiungere una voce 0 o se saltare i legami di ordine zero in to_ob_mol. Si considera completato quando molec.to_smiles() restituisce una SMILES per la lista di adiacenza data, più un test di regressione accanto ai test translator/converter esistenti (ad es. sotto rmgpy/molecule/tests/).

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Bug Description

As I understand it, when getting the smiles for an RMG molecule, either an RDKit or OpenBabel molecule equivalent is created (to_smiles in rmgpy/molecule/translator.py), and the smiles string is determined by these packages. OpenBabel is used instead of the default RDKit when the species contains N or S atoms. When the molecule is an adsorbate with a vdw bond, there is an RMG bond order of 0, which gives a key error when you try to make the smiles for these molecules (to_ob_mol in rmgpy/molecule/converter.py). This has manifested in the labeling of species in the RMG run. I have found that, if bonds of order 0 are ignored, the RMG runs with these species do not seem to have errors related to it as far as I can tell. However, it may be a concern to skip this if the OpenBabel molecule is used for anything else, since that object will not know about the vdw bond. I noticed that the RDKit handling uses an UNSPECIFIED bond type for vdw since it also does not specifically handle these, and OpenBabel has a bond order of zero which seems to be intended for the same type of unspecified bond. Adding an entry of 0: 0 into the orders dictionary of to_ob_mol also seems to get rid of the error and seems to be close to the RDKit handling of this, so it may be an appropriate change to make.

How To Reproduce

The following code can be run, which produces an error in the current version of RMG. If you implement a change skipping adding bonds to the OpenBabel molecule or adding a zero order bond, you will not have an error.

from rmgpy.molecule import Molecule

adj = '''1 O u0 p2 c0 {3,D} {7,vdW}
2 O u0 p2 c0 {3,S} {8,S}
3 C u0 p0 c0 {1,D} {2,S} {4,S}
4 N u0 p1 c0 {3,S} {5,S} {6,S}
5 H u0 p0 c0 {4,S}
6 H u0 p0 c0 {4,S}
7 X u0 p0 c0 {1,vdW}
8 X u0 p0 c0 {2,S}'''

molec = Molecule().from_adjacency_list(adj)

molec.to_smiles()

The error looks like this:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~/RMG-Py/rmgpy/molecule/translator.py:277, in rmgpy.molecule.translator.to_smiles()

KeyError: 'CH2NO2X2'

During handling of the above exception, another exception occurred:

KeyError                                  Traceback (most recent call last)
Cell In[1], line 14
      3 adj = '''1 O u0 p2 c0 {3,D} {7,vdW}
      4 2 O u0 p2 c0 {3,S} {8,S}
      5 3 C u0 p0 c0 {1,D} {2,S} {4,S}
   (...)      9 7 X u0 p0 c0 {1,vdW}
     10 8 X u0 p0 c0 {2,S}'''
     12 molec = Molecule().from_adjacency_list(adj)
---> 14 molec.to_smiles()

File ~/RMG-Py/rmgpy/molecule/molecule.py:2094, in rmgpy.molecule.molecule.Molecule.to_smiles()
File ~/RMG-Py/rmgpy/molecule/molecule.py:2108, in rmgpy.molecule.molecule.Molecule.to_smiles()
File ~/RMG-Py/rmgpy/molecule/translator.py:256, in rmgpy.molecule.translator.to_smiles()
File ~/RMG-Py/rmgpy/molecule/translator.py:282, in rmgpy.molecule.translator.to_smiles()
File ~/RMG-Py/rmgpy/molecule/translator.py:562, in rmgpy.molecule.translator._write()
File ~/RMG-Py/rmgpy/molecule/translator.py:455, in rmgpy.molecule.translator._openbabel_translator()
File ~/RMG-Py/rmgpy/molecule/converter.py:249, in rmgpy.molecule.converter.to_ob_mol()
File ~/RMG-Py/rmgpy/molecule/converter.py:283, in rmgpy.molecule.converter.to_ob_mol()

KeyError: 0.0
Expected Behavior

I am not sure how this case is meant to be handled, since it seems to be a particular case (vdw bonding) within another particular case (N, S in a molecule).

Additional Context

I am not familiar with all of the uses for to_smiles and how/if the OpenBabel molecule representation is relied upon for other uses that would require the vdw bond, so I am not sure if the proposed solution would be the correct way of handling this.

Lingua principale
Python
Stelle
535
Fork
262
Merge medio
3g 19h
PR unite (30g)
2

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ReactionMechanismGenerator/RMG-Py

Tutte le issue di ReactionMechanismGenerator/RMG-Py

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.