Chemis...nSMILES(3pm)

πŸ’– NAME πŸ’–

Chemistry::OpenSMILES β€” bestie, this is your OpenSMILES format reader and writer, like a whole two-way translator for chemical structure strings and she is serving.


✨ SYNOPSIS ✨

use Chemistry::OpenSMILES::Parser;

my $parser = Chemistry::OpenSMILES::Parser->new;
my @moieties = $parser->parse( 'C#C.c1ccccc1' );

$\ = "\n";
for my $moiety (@moieties) {
    #  $moiety is a Graph::Undirected object
    print scalar $moiety->vertices;
    print scalar $moiety->edges;
}

use Chemistry::OpenSMILES::Writer qw(write_SMILES);

print write_SMILES( \@moieties );

okay so that's literally the whole vibe: make a parser, throw a SMILES string at it, get back a list of Graph::Undirected objects, peek at how many vertices and edges each one has, then hand the whole list to write_SMILES and get a string back. no cap, iconic. πŸ§ͺ✨


🌸 DESCRIPTION 🌸

Chemistry::OpenSMILES has your back for SMILES chemical identifiers that play by the OpenSMILES v1.0 specification rules β€” here's where the rules live: <http://opensmiles.org/opensmiles.html> 🫢

  • Chemistry::OpenSMILES::Parser reads in SMILES strings and hands them back parsed into arrays of Graph::Undirected objects. Every single atom is represented by a hash. (yes. a hash. she's giving structure.)
  • Chemistry::OpenSMILES::Writer does the inverse β€” the glow-up in reverse. For all the SMILES writing conventions and options, go check out its own description, iykyk. πŸ’…

πŸ¦‹ Molecular graph πŸ¦‹

Disconnected parts of a compound? They get to be their own separate Graph::Undirected objects β€” no forcing them to sit together, we respect boundaries here. Atoms become vertices, and bonds become edges. that's the whole anatomy, periodt.

⭐ Atoms

Atoms (aka the vertices of a molecular graph) are represented as hash references:

{
    "symbol"    => "C",
    "isotope"   => 13,
    "chirality" => "@@",
    "hcount"    => 3,
    "charge"    => 1,
    "class"     => 0,
    "number"    => 0,
}

Okay so listen: except for "symbol", "class" and "number", every key in that hash is optional. You do not have to fill it all in, bestie, it's giving low-maintenance. And per the OpenSMILES specification, the default values for "hcount" and "class" are 0.

For chiral atoms πŸŒ€, the order of their neighbours in the input is preserved in an array that gets added as the value for the "chirality_neighbours" key of the atom hash. The order of the atoms in there follows OpenSMILES convention β€” so don't go rearranging them, the chirality is literally depending on it. πŸ™ˆ

πŸŽ€ Bonds

Bonds β€” the edges of a molecular graph β€” rely completely on Graph::Undirected's internal representation. Like, fully trusting her, no extra sauce. 🫢

Bond orders other than single (-, which is also the default, cute) are represented as values of the edge attribute "bond". Those values correspond to the symbols used in the OpenSMILES specification. ⚑


πŸ‘‘ AUTHORS πŸ‘‘

Andrius Merkys, <merkys@cpan.org> β€” thank you for your service, king. 🫑


and that's the whole page! shipped with πŸ“ perl v5.40.1, dated 2026-06-19, and the manual name you're reading is Chemistry::OpenSMILES(3pm) β€” go forth and parse some molecules, bestie πŸ’œπŸŒˆβœ¨

πŸ“¦ where this page comes from