npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

smiles-js

v2.2.0

Published

A JavaScript library for building molecules using composable fragments

Readme

SMILES-JS

A modern JavaScript library for programmatic molecular construction and SMILES manipulation

CI Tests Coverage npm License

Build complex molecules programmatically with an intuitive, composable API. Parse, manipulate, and generate SMILES notation with full round-trip fidelity.


Features

  • Parse complex SMILES - Handles real-world pharmaceutical molecules (60-80+ characters)
  • Programmatic construction - Build molecules using composable Ring, Linear, and Molecule constructors
  • Polymer construction - Build repeating units with .repeat() and fused acene systems with .fusedRepeat()
  • Mirror symmetry - Create palindromic chains and ABA block patterns with .mirror()
  • Round-trip fidelity - Parse SMILES -> AST -> SMILES with structure preservation
  • Code generation - Auto-generate JavaScript construction code from SMILES strings
  • Pharmaceutical validated - Tested with Atorvastatin, Sildenafil, Ritonavir, and 30+ other drugs

Testimony

Testimony

Claude link


Installation

npm install smiles-js

Embedding

<script type="module">
  import { Fragment, Ring, FusedRing, Linear } from 'https://unpkg.com/smiles-js@latest/src/index.js';
  import { benzene, methyl, ethyl, hydroxyl, carboxyl, phenyl, cyclohexane } from 'https://unpkg.com/smiles-js@latest/src/common.js';

  window.SMILES = { Fragment, Ring, FusedRing, Linear, benzene, methyl, ethyl, hydroxyl, carboxyl, phenyl, cyclohexane };
  // Your code
</script>

Quick Start

Parse SMILES

import { parse } from 'smiles-js';

// Parse any SMILES string
const aspirin = parse('CC(=O)Oc1ccccc1C(=O)O');
console.log(aspirin.smiles);  // CC(=O)Oc1ccccc1C(=O)O

// Parse complex drugs
const atorvastatin = parse('CC(C)c1c(C(=O)Nc2ccccc2)c(c3ccccc3)c(c4ccc(F)cc4)n1CCC(O)CC(O)CC(=O)O');
console.log(atorvastatin.smiles);  // Perfect round-trip!

Build Molecules Programmatically

import { Ring, Linear, Molecule } from 'smiles-js';

// Create benzene ring
const benzene = Ring({ atoms: 'c', size: 6 });
console.log(benzene.smiles);  // c1ccccc1

// Add methyl group to make toluene
const methyl = Linear(['C']);
const toluene = benzene.attach(1, methyl);
console.log(toluene.smiles);  // c1(C)ccccc1

// Create pyridine via substitution
const pyridine = benzene.substitute(5, 'n');
console.log(pyridine.smiles);  // c1cccnc1

Build Polymers

import { Ring, Linear } from 'smiles-js';

// Polyethylene trimer: repeat ethylene unit 3 times
const ethylene = Linear(['C', 'C']);
const PE = ethylene.repeat(3, 1, 2);
console.log(PE.smiles);  // CCCCCC

// Polystyrene dimer: repeat styrene unit with phenyl branch
const styrene = Linear(['C', 'C']).attach(2, Ring({ atoms: 'c', size: 6 }));
const PS = styrene.repeat(2, 1, 2);
console.log(PS.smiles);  // CC(c1ccccc1)CC(c2ccccc2)

// Acene series via fused repeat
const benzene = Ring({ atoms: 'c', size: 6 });
const naphthalene = benzene.fusedRepeat(2, 4);  // 2 fused rings
const anthracene = benzene.fusedRepeat(3, 4);   // 3 fused rings

Mirror Symmetry

import { Ring, Linear, Molecule } from 'smiles-js';

// Diethyl ether: mirror C-C-O around oxygen
const ether = Linear(['C', 'C', 'O']).mirror();
console.log(ether.smiles);  // CCOCC

// ABA triblock copolymer
const A = Linear(['C', 'C']);
const B = Ring({ atoms: 'c', size: 6 });
const ABA = Molecule([A, B]).mirror();
console.log(ABA.smiles);  // CCc1ccccc1CC

Generate Construction Code

import { parse } from 'smiles-js';

const molecule = parse('CCCc1ccccc1');
console.log(molecule.toCode());

Output:

const molecule1 = Linear(['C', 'C', 'C']);
const molecule2 = Ring({ atoms: 'c', size: 6 });
const molecule3 = Molecule([molecule1, molecule2]);

Round-Trip Validation

import { isValidRoundTrip, normalize } from 'smiles-js';

// Quick boolean check
if (isValidRoundTrip('c1ccccc1')) {
  console.log('Perfect round-trip!');
}

// Automatic normalization
const normalized = normalize('COc1ccc2nc(S(=O)Cc3ncc(C)c(OC)c3C)[nH]c2c1');

Full API Reference

See API.md for complete documentation including:

  • All constructors and their options
  • Ring, Linear, Molecule, and FusedRing manipulation methods
  • Functional API imports
  • Parsing & serialization utilities
  • AST inspection
  • Clone utilities
  • RDKit integration

Documentation


Contributing

Contributions welcome! Please see our contributing guidelines.

# Install dependencies
npm install

# Run tests
npm test

# Run linter
npm run lint

License

MIT License - see LICENSE file for details


Acknowledgments

  • Tested with molecules from PubChem
  • Inspired by SMILES notation from Daylight Chemical Information Systems
  • Built with modern JavaScript and comprehensive testing

Support