如何使用Python实现SYBYL线表示法(SNL)到SMILES的转换?
Great question! You’re right that RDKit doesn’t have native support for parsing SYBYL Line Notation (SNL) directly. But there’s a reliable workaround using OpenBabel—a robust cheminformatics tool that handles a massive range of chemical format conversions, including SNL to SMILES.
Here’s how to make it work:
Using OpenBabel’s Python Binding (Pybel)
First, install OpenBabel and its Python wrapper:
pip install openbabel
(Note: On some systems, you may need to install the core OpenBabel library first via your package manager—like sudo apt install openbabel on Debian/Ubuntu.)
Then use this code snippet to convert your N-methylpyrrolidone example:
import pybel # Your SYBYL Line Notation string snl = 'N[1](CH2CH2CH2C@1=O)CH3' # Parse the SNL as a SYBYL-format molecule mol = pybel.readstring("sybyl", snl) # Convert to SMILES and clean up extra whitespace smiles = mol.write("smi").strip() print(smiles) # Output: CN1CCCC1=O
Alternative: Command-Line OpenBabel
If you prefer avoiding Python bindings, you can use OpenBabel directly from the terminal:
echo "N[1](CH2CH2CH2C@1=O)CH3" | obabel -i sybyl -o smi
This will print the matching SMILES string right away.
Why This Works
OpenBabel has built-in support for parsing SYBYL’s line notation (the sybyl input flag covers SNL). Once it converts the SNL to its internal molecular representation, switching to SMILES is a trivial step.
内容的提问来源于stack exchange,提问作者B.Gees

