1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#!/usr/bin/perl
use strict;
use warnings;
use ChemOnomatopist;
use ChemOnomatopist::MolecularGraph;
use Chemistry::OpenSMILES::Parser;
use List::Util qw( uniq );
use Scalar::Util qw( blessed );
local $, = "\t";
local $\ = "\n";
while( my $SMILES = <> ) {
chomp $SMILES;
eval {
my $parser = Chemistry::OpenSMILES::Parser->new;
my @graphs = map { ChemOnomatopist::MolecularGraph->new( $_ ) }
$parser->parse( $SMILES );
die "separate molecular entities are not handled yet\n" if @graphs > 1;
my $graph = shift @graphs;
ChemOnomatopist::find_groups( $graph );
my @groups = sort { $a cmp $b }
uniq
map { blessed $_ }
grep { blessed $_ }
( $graph->groups, $graph->vertices );
print $SMILES, join ' ', @groups;
};
if( $@ ) {
$@ =~ s/\n$//;
print $SMILES, $@;
}
}
|