Skip to main content

PyOPSIN

This is a Python wrapper for the OPSIN (Open Parser for Systematic IUPAC Nomenclature) package, which allows you to generate SMILES and CML form the standardized IUPAC names for organic molecules. The original OPSIN package was written in Java, but this wrapper allows you to use OPSIN functionality directly from Python.

Installation

PyOPSIN requires Java 8+. The first time you create a PyOpsin() instance, it downloads the latest OPSIN CLI JAR (opsin-cli-*-jar-with-dependencies.jar) from the official OPSIN GitHub releases.

pip install pyopsin

From a source checkout:

pip install -e .

The JAR is cached under ~/.cache/pyopsin/ on Unix and %LOCALAPPDATA%\pyopsin on Windows. Override the cache directory with the PYOPSIN_JAR_DIR environment variable. You can also pass a local JAR with PyOpsin(path="/path/to/opsin-cli.jar").

Usage

Here's an example of how to use the PyOPSIN to generate SMILES string using the IUPAC name for a molecule:

from pyopsin import PyOpsin

# create an PyOpsin object
opsin = PyOpsin()

# generate the SMILES string from an IUPAC name for a molecule
name = "2,4,6-trinitrotoluene"
smiles = opsin.to_smiles(name)

# print the SMILES string
print(smiles)

This should output the following SMILES string:

["[N+](=O)([O-])C1=C(C)C(=CC(=C1)[N+](=O)[O-])[N+](=O)[O-]"]

Here is another example of how to invoke parallel processing to process a list of IUPAC names:

names = ["2,4,6-trinitrotoluene", "cycloheptene"]
smiles = opsin.to_smiles(names, num_workers=2)
print(smiles)

This should output the following SMILES strings:

["[N+](=O)([O-])C1=C(C)C(=CC(=C1)[N+](=O)[O-])[N+](=O)[O-]", "C1=CCCCCC1"]

With the default capture_message=False, to_smiles returns a list of SMILES strings. Pass capture_message=True to include the OPSIN parse status and message for each name. Each result is a dictionary with these keys:

  • chemical_name: the input IUPAC name
  • smiles: the SMILES string, or None when parsing fails
  • message: the OPSIN message
  • status: the OPSIN status name, such as SUCCESS, WARNING, or FAILURE
opsin = PyOpsin(capture_message=True)

names = ["dichlorobenze", "dichlorobenzene"]
results = opsin.to_smiles(names)
print(results)

This should output:

[
    {
        "chemical_name": "dichlorobenze",
        "smiles": None,
        "message": "dichlorobenze is unparsable due to the following being uninterpretable: benze The following was not parseable: e",
        "status": "FAILURE",
    },
    {
        "chemical_name": "dichlorobenzene",
        "smiles": "ClC1=C(C=CC=C1)Cl",
        "message": "APPEARS_AMBIGUOUS: Connection of chloro to benzen",
        "status": "WARNING",
    },
]

to_smiles_single returns the same dictionary for one name.

Tests

python -m unittest test.py

TestPyOpsinClean checks SMILES conversion for valid names. TestPyOpsinAmbiguous checks capture_message=True for an unparsable name (FAILURE) and an ambiguous name (WARNING).

Acknowledgments

The OPSIN Python wrapper is built on top of the OPSIN package, which was developed by the Centre for Molecular Informatics at the University of Cambridge. We would like to thank the developers of OPSIN for creating such a powerful and useful tool.

Metadata

Release files for pyopsin 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyopsin 1.1.0
File Size Uploaded
pyopsin-1.1.0.tar.gz 12.2 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyopsin 1.1.0
File Interpreter ABI Platform
pyopsin-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 24.3 MB

Release files / pyopsin-1.1.0.tar.gz

Download URL pyopsin-1.1.0.tar.gz
Size 12.2 MB
Tags Source
SHA-256 checksum
How to use checksums
5cb8ea4b00d895946ffe68f5e791feda61f3a41fdb30726aa1b85f026c217ff1
BLAKE2b-256 checksum
How to use checksums
e61d80063bce48293feb4e70d03a69c8df9419017fdfead407f874d13e8a62f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release files / pyopsin-1.1.0-py3-none-any.whl

Download URL pyopsin-1.1.0-py3-none-any.whl
Size 12.2 MB
Tags Python 3
SHA-256 checksum
How to use checksums
005f00cbecd2b9b9fc6918da8827f8b5e82f3e3fb2515c7451da17a5307cc477
BLAKE2b-256 checksum
How to use checksums
b00e08460910e0f17196f836d77a041de0fb15d7d35b6fe2258de28d78fc04c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.14

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page