Skip to content

A Go cheminformatics toolkit based on the Indigo library, providing high-performance molecule and reaction processing via CGO bindings.

Notifications You must be signed in to change notification settings

cx-luo/go-indigo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

93 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

go-indigo

Go License

A Go cheminformatics toolkit based on the Indigo library, providing high-performance molecule and reaction processing via CGO bindings.

English | ็ฎ€ไฝ“ไธญๆ–‡

โœจ Features

  • ๐Ÿงช Molecule Processing: Complete molecule loading, editing, and saving
  • โš—๏ธ Reaction Processing: Chemical reaction loading, analysis, and AAM (Atom-to-Atom Mapping)
  • ๐ŸŽจ Structure Rendering: Render molecules and reactions as images (PNG, SVG, PDF)
  • ๐Ÿ”ฌ InChI Support: InChI and InChIKey generation and parsing
  • ๐Ÿ“Š Molecular Properties: Calculate molecular weight, TPSA, molecular formula, etc.
  • ๐Ÿ—๏ธ Molecule Building: Build molecular structures from scratch
  • ๐Ÿ”„ Format Conversion: Convert between SMILES, MOL, SDF formats

๐Ÿ“ฆ Installation

Prerequisites

  1. Go 1.20+
  2. Indigo Library: Precompiled libraries included
    • Windows (x86_64, i386)
    • Linux (x86_64, aarch64)
    • macOS (x86_64, arm64)

Installation Steps

# Clone the repository
git clone https://github.com/cx-luo/go-indigo.git
cd go-indigo

# Set environment variables (Windows example)
set CGO_ENABLED=1
set CGO_CFLAGS=-I%CD%/3rd
set CGO_LDFLAGS=-L%CD%/3rd/windows-x86_64

# Set environment variables (Linux example)
export CGO_ENABLED=1
export CGO_CFLAGS="-I$(pwd)/3rd"
export CGO_LDFLAGS="-L$(pwd)/3rd/linux-x86_64"
export LD_LIBRARY_PATH=$(pwd)/3rd/linux-x86_64:$LD_LIBRARY_PATH

# Run tests to verify installation
go test ./test/molecule/...

๐Ÿš€ Quick Start

Load and Render a Molecule

package main

import (
    "github.com/cx-luo/go-indigo/molecule"
    "github.com/cx-luo/go-indigo/render"
)

func main() {
    // Load molecule from SMILES
    mol, err := molecule.LoadMoleculeFromString("c1ccccc1")
    if err != nil {
        panic(err)
    }
    defer mol.Close()

    // Initialize renderer
    renderer := &render.Renderer{}
    defer renderer.DisposeRenderer()

    // Set render options
    opts := &render.RenderOptions{
        OutputFormat: "png",
        ImageWidth:   800,
        ImageHeight:  600,
    }
    renderer.Options = opts
    renderer.Apply()

    // Render to PNG
    renderer.RenderToFile(mol.Handle, "benzene.png")
}

Calculate Molecular Properties

package main

import (
    "fmt"
    "github.com/cx-luo/go-indigo/molecule"
)

func main() {
    // Load ethanol
    mol, _ := molecule.LoadMoleculeFromString("CCO")
    defer mol.Close()

    // Calculate properties
    mw, _ := mol.MolecularWeight()
    fmt.Printf("Molecular Weight: %.2f\n", mw)

    formula, _ := mol.GrossFormula()
    fmt.Printf("Formula: %s\n", formula)

    tpsa, _ := mol.TPSA(false)
    fmt.Printf("TPSA: %.2f\n", tpsa)

    // Convert to SMILES
    smiles, _ := mol.ToSmiles()
    fmt.Printf("SMILES: %s\n", smiles)
}

InChI Generation

package main

import (
    "fmt"
    "github.com/cx-luo/go-indigo/molecule"
)

func main() {
    // Load molecule
    mol, _ := molecule.LoadMoleculeFromString("CC(=O)O")
    defer mol.Close()

    // Initialize InChI
    molecule.InitInChI()
    defer molecule.DisposeInChI()

    // Generate InChI
    inchi, _ := mol.ToInChI()
    fmt.Println("InChI:", inchi)

    // Generate InChIKey
    key, _ := mol.ToInChIKey()
    fmt.Println("InChIKey:", key)
}

Chemical Reaction Processing

package main

import (
    "fmt"
    "github.com/cx-luo/go-indigo/reaction"
)

func main() {
    // Load reaction
    rxn, _ := reaction.LoadReactionFromString("CCO>>CC=O")
    defer rxn.Close()

    // Get reaction information
    nReactants, _ := rxn.CountReactants()
    nProducts, _ := rxn.CountProducts()
    fmt.Printf("Reactants: %d, Products: %d\n", nReactants, nProducts)

    // Automatic atom mapping
    rxn.Automap("discard")

    // Save as RXN file
    rxn.SaveToFile("reaction.rxn")
}

๐Ÿ“š Documentation

Core Documentation

Topic Documentation

๐Ÿ“‚ Project Structure

go-indigo/
โ”œโ”€โ”€ 3rd/                        # Indigo precompiled libraries
โ”‚   โ”œโ”€โ”€ windows-x86_64/         # Windows 64-bit
โ”‚   โ”œโ”€โ”€ windows-i386/           # Windows 32-bit
โ”‚   โ”œโ”€โ”€ linux-x86_64/           # Linux 64-bit
โ”‚   โ”œโ”€โ”€ linux-aarch64/          # Linux ARM64
โ”‚   โ”œโ”€โ”€ darwin-x86_64/          # macOS Intel
โ”‚   โ””โ”€โ”€ darwin-aarch64/         # macOS Apple Silicon
โ”œโ”€โ”€ core/                       # Core functionality
โ”‚   โ”œโ”€โ”€ indigo.go               # Indigo core functionality
โ”‚   โ”œโ”€โ”€ indigo_helper.go        # Indigo helper functionality
โ”‚   โ”œโ”€โ”€ indigo_inchi.go         # Indigo InChI functionality
โ”‚   โ”œโ”€โ”€ indigo_molecule.go      # Indigo molecule functionality
โ”‚   โ””โ”€โ”€ indigo_reaction.go      # Indigo reaction functionality
โ”œโ”€โ”€ molecule/                   # Molecule processing package
โ”‚   โ”œโ”€โ”€ README.md               # Molecule processing documentation
โ”‚   โ”œโ”€โ”€ molecule.go             # Core molecule structure
โ”‚   โ”œโ”€โ”€ molecule_atom.go        # Atom operations
โ”‚   โ”œโ”€โ”€ molecule_builder.go     # Molecule building
โ”‚   โ”œโ”€โ”€ molecule_match.go       # Molecule matching
โ”‚   โ”œโ”€โ”€ molecule_properties.go  # Property calculations
โ”‚   โ””โ”€โ”€ molecule_saver.go       # Molecule saving
โ”œโ”€โ”€ reaction/                   # Reaction processing package
โ”‚   โ”œโ”€โ”€ README.md               # Reaction processing documentation
โ”‚   โ”œโ”€โ”€ reaction.go             # Core reaction structure
โ”‚   โ”œโ”€โ”€ reaction_automap.go     # Automatic atom mapping
โ”‚   โ”œโ”€โ”€ reaction_helpers.go     # Reaction helper functions
โ”‚   โ”œโ”€โ”€ reaction_iterator.go    # Reaction iterator
โ”‚   โ”œโ”€โ”€ reaction_loader.go      # Reaction loading
โ”‚   โ””โ”€โ”€ reaction_saver.go       # Reaction saving
โ”œโ”€โ”€ render/                     # Rendering package
โ”‚   โ”œโ”€โ”€ README.md               # Rendering documentation
โ”‚   โ””โ”€โ”€ render.go               # Rendering functionality
โ”œโ”€โ”€ test/                       # Test files
โ”‚   โ”œโ”€โ”€ molecule/               # Molecule tests
โ”‚   โ”œโ”€โ”€ reaction/               # Reaction tests
โ”‚   โ””โ”€โ”€ render/                 # Rendering tests
โ”œโ”€โ”€ examples/                   # Example code
โ”‚   โ”œโ”€โ”€ molecule/               # Molecule examples
โ”‚   โ”œโ”€โ”€ reaction/               # Reaction examples
โ”‚   โ””โ”€โ”€ render/                 # Rendering examples
โ”œโ”€โ”€ docs/                       # Documentation
โ””โ”€โ”€ README.md                   # This file

๐Ÿ”ง Supported Features

Molecule Operations

  • โœ… Load from SMILES, MOL, SDF
  • โœ… Save as MOL, SMILES, JSON
  • โœ… Calculate properties (MW, TPSA, formula, etc.)
  • โœ… Add, delete, modify atoms and bonds
  • โœ… Aromatization and dearomatization
  • โœ… Fold and unfold hydrogens
  • โœ… 2D layout and cleanup
  • โœ… Normalization and standardization

Reaction Operations

  • โœ… Load from Reaction SMILES, RXN files
  • โœ… Save as RXN files
  • โœ… Add reactants, products, catalysts
  • โœ… Automatic atom-to-atom mapping (AAM)
  • โœ… Reaction center detection
  • โœ… Iterate reaction components

Rendering Features

  • โœ… PNG, SVG, PDF output
  • โœ… Custom image size and style
  • โœ… Grid rendering (multiple molecules)
  • โœ… Reference atom alignment
  • โœ… Stereochemistry display
  • โœ… Atom/bond label display

InChI Support

  • โœ… Standard InChI generation
  • โœ… InChIKey generation
  • โœ… Load molecule from InChI
  • โœ… Warning and log information
  • โœ… Auxiliary information output

๐Ÿงช Testing

# Run all tests
go test ./test/...

# Run specific package tests
go test ./test/molecule/...
go test ./test/reaction/...
go test ./test/render/...

# Verbose output
go test -v ./test/...

# Specific test
go test ./test/molecule/ -run TestLoadMoleculeFromString

๐Ÿ“Š Performance

  • Based on C++ Indigo library for excellent performance
  • Minimized CGO call overhead
  • Automatic memory management (using runtime.SetFinalizer)
  • Supports large-scale molecule processing

๐Ÿค Contributing

Contributions are welcome! Feel free to submit Pull Requests or create Issues.

Development Setup

  1. Fork this repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

๐Ÿ“„ License

This project is licensed under Apache License 2.0. See LICENSE file for details.

Third-Party Licenses

  • Indigo Toolkit: Apache License 2.0
  • Copyright ยฉ 2009-Present EPAM Systems

๐Ÿ™ Acknowledgments

  • EPAM Indigo - Excellent cheminformatics toolkit
  • All contributors and users

๐Ÿ“ฎ Contact

๐Ÿ”— Links


โญ If this project helps you, please give it a Star!

About

A Go cheminformatics toolkit based on the Indigo library, providing high-performance molecule and reaction processing via CGO bindings.

Topics

Resources

Contributing

Stars

Watchers

Forks

Packages

No packages published