Skip to main content

Python bindings for COSMolKit

Project description

COSMolKit

COSMolKit is a Rust-backed Python package for cheminformatics and molecular graph workflows. The Python package currently exposes a strict, tested subset of the Rust core while the chemistry implementation is expanded against RDKit parity tests.

The public Python API is intentionally non-inplace by default: ordinary operations return a new Molecule value instead of mutating the input object implicitly. The intended optimization strategy for this API shape is Rust-side copy-on-write storage, not ambiguous Python-layer mutation semantics.

Installation

pip install cosmolkit

Currently Available API

The current binding surface is useful for:

  • SMILES parsing with Molecule.from_smiles()
  • optional RDKit bridge with Molecule.from_rdkit() when rdkit is installed
  • atom and bond graph inspection with RDKit-like feature names
  • hydrogen add/remove transforms
  • Kekulization
  • tetrahedral stereo inspection
  • 2D coordinate generation and coordinate access
  • SMILES export
  • distance-geometry bounds matrix export
  • SDF read/write and SDF string export
  • explicit edit context with Molecule.edit()

Quick Start

from cosmolkit import Molecule

mol = Molecule.from_smiles("CCO")

print(mol)
print("atoms:", len(mol))

for atom in mol.atoms():
    print(atom.idx(), atom.atomic_num(), atom.total_valence())

for bond in mol.bonds():
    print(bond.begin_atom_idx(), bond.end_atom_idx(), bond.bond_type())

Hydrogen Transforms and Kekulization

from cosmolkit import Molecule

mol = Molecule.from_smiles("c1ccccc1O")
mol_h = mol.add_hydrogens()
mol_no_h = mol_h.remove_hydrogens()
kek = mol.kekulize()

print(len(mol.atoms()), len(mol_h.atoms()), len(mol_no_h.atoms()))
print(kek.to_smiles())

Tetrahedral Stereo and Chiral Tags

COSMolKit exposes an ordered tetrahedral stereo representation derived from the internal chiral tags. Each record is (center_atom_index, ordered_ligands). Implicit hydrogen is represented as None.

from cosmolkit import Molecule

mol = Molecule.from_smiles("F[C@H](Cl)Br")

print(mol.find_chiral_centers(include_unassigned=False))

for center, ligands in mol.tetrahedral_stereo():
    print("center:", center)
    print("ordered ligands:", ligands)

2D Coordinates and SDF I/O

from cosmolkit import Molecule

mol = Molecule.from_smiles("CCO").compute_2d_coords()

print("num conformers:", mol.num_conformers())
print("first position:", mol.conformer_positions()[0])

sdf_text = mol.to_sdf_string(format="v2000")
print("SDF length:", len(sdf_text))

mol.write_sdf("ethanol.sdf", format="v2000")
loaded = Molecule.read_sdf("ethanol.sdf")
print(loaded)

SMILES Export and DG Bounds

from cosmolkit import Molecule

mol = Molecule.from_smiles("F[C@H](Cl)Br")

print("isomeric:", mol.to_smiles())
print("non-isomeric:", mol.to_smiles(False))

bounds = mol.dg_bounds_matrix()
print("matrix size:", len(bounds), "x", len(bounds[0]))
print("d(0,1):", bounds[0][1])

Explicit Editing

from cosmolkit import Molecule

mol = Molecule.from_smiles("CCO")

editor = mol.edit()
cl = editor.add_atom("Cl")
editor.add_bond(0, cl, order="single")
editor.set_atom_charge(cl, -1)
mol2 = editor.commit()

print(mol2.to_smiles())

RDKit Bridge

Molecule.from_rdkit() is available when rdkit is installed in the active Python environment. The bridge copies basic graph information from an RDKit molecule into COSMolKit and then uses COSMolKit logic for downstream derived features.

from rdkit import Chem
from cosmolkit import Molecule

rd_mol = Chem.MolFromSmiles("CCO")
mol = Molecule.from_rdkit(rd_mol)

print(mol.to_smiles())

Not Implemented Yet

The following API directions are planned but not currently available:

  • sanitization pipeline methods such as sanitize()
  • explicit ring/aromaticity perception methods
  • substructure search
  • fingerprint generation
  • 3D embedding and force-field optimization
  • alignment APIs

Development Status

COSMolKit is not a full RDKit replacement today. The Python package is being built through strict parity testing against RDKit behavior where compatibility is the goal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cosmolkit-0.0.8.tar.gz (147.3 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

cosmolkit-0.0.8-cp39-abi3-win_amd64.whl (561.4 kB view details)

Uploaded CPython 3.9+Windows x86-64

cosmolkit-0.0.8-cp39-abi3-manylinux_2_34_x86_64.whl (678.6 kB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

cosmolkit-0.0.8-cp39-abi3-macosx_11_0_arm64.whl (577.6 kB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

File details

Details for the file cosmolkit-0.0.8.tar.gz.

File metadata

  • Download URL: cosmolkit-0.0.8.tar.gz
  • Upload date:
  • Size: 147.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cosmolkit-0.0.8.tar.gz
Algorithm Hash digest
SHA256 2f97545992a3ab84a7b4749d9552c8e61e5dd7d5c709ca6965b2056b61a9294d
MD5 d99060076427f174b8f7a9bb5906878e
BLAKE2b-256 676dc8ed7dae031700829f835931399bd3ed5900709bf8929d6b4fb2f723e84f

See more details on using hashes here.

File details

Details for the file cosmolkit-0.0.8-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: cosmolkit-0.0.8-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 561.4 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for cosmolkit-0.0.8-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 20dd699bb9ba43756d9874441d50160c6125581a0d6574371868ee78ee29520d
MD5 eac661c89023e1432c1947a865eb8613
BLAKE2b-256 8b6f8ed1635efbc190dcbdc4702446e2a1dcd6669aa17b619cba064352c99b83

See more details on using hashes here.

File details

Details for the file cosmolkit-0.0.8-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for cosmolkit-0.0.8-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 95cea0ba27d653db9b68fa2fc42c271d59683f0ef57ef573b728056bfc9be8a2
MD5 b728ec13b52b1c64fe4455eadfd73a1e
BLAKE2b-256 fe3f8db62838a109d60a328bbc47d7fe25d36b429293ca8160d4556b6b7e2b9c

See more details on using hashes here.

File details

Details for the file cosmolkit-0.0.8-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for cosmolkit-0.0.8-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e8391ed9f953d6affe12037922309331653eb46882e613d8461f10434bb6470b
MD5 b21db368b9b0576a4707f095b9abe18c
BLAKE2b-256 25054f198b7d0c289785b5956c0c5421a9dbbcea48d48a1aea3edc0c30e5b74e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page