Chemistry::File::SMARTS - SMARTS chemical substructure pattern linear notation parser


    use Chemistry::File::SMARTS;

    # this string matches an oxygen next to an atom with three 
    # neighbors, one of which is a hydrogen, and a positive charge
    my $smarts = 'O[D3H+]'; 

    # parse a SMARTS string and compile it into a
    # Chemistry::Pattern object
    my $patt = Chemistry::Pattern->parse("$smarts", format => 'smarts');

    # find matches of the pattern in a Chemistry::Mol object $mol
    my $mol = Chemistry::Mol->read("myfile.mol");
    while ($patt->match($mol)) {
        print "pattern matches atoms: ", $patt->atom_map, "\n"

    # NOTE: if the SMARTS pattern relies on aromaticity or ring
    # properties, you have to make sure that the target 
    # molecule is "aromatized" first:
    my $smarts = 'c:a';
    my $patt = Chemistry::Pattern->parse("$smarts", format => 'smarts');
    use Chemistry::Ring 'aromatize_mol';
    aromatize_mol($mol);  # <--- AROMATIZE!!!
    while ($patt->match($mol)) {
        print "pattern matches atoms: ", $patt->atom_map, "\n"

    # Note that "atom mapping numbers" end up as $atom->name
    my $patt = Chemistry::Pattern->parse("[C:7][C:8]", format => 'smarts');
    print $patt->atoms(1)->name;    # prints 7


This module parse a SMARTS (SMiles ARbitrary Target Specification) string, generating a Chemistry::Pattern object. It is a file I/O driver for the PerlMol toolkit; it's not called directly but by means of the Chemistry::Pattern->parse class method.

For a detailed description of the SMARTS language, see Note that this module doesn't implement the full language, as detailed under CAVEATS.

This module is part of the PerlMol project,


The following features are not implemented yet:

chirality: @, @@
component-level gruouping

That is, the difference between these three cases:


The so-called parser is very lenient, so if you give it something that's not quite reasonable it will ignore it or interpret it in a strange way without warning.

As shown in the synopsis, you have to make sure that the molecule is "aromatized" if you want to apply to it a pattern that relies on aromaticity or ring properties.




Chemistry::Pattern, Chemistry::Mol, Chemistry::File, Chemistry::File::SMILES.

For more information about SMARTS, see the SMARTS Theory Manual at


Ivan Tubert-Brohman <>


Copyright (c) 2005 Ivan Tubert-Brohman. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.