#!/usr/bin/perl
#======================================================================
# FILE:		smarts2smiles.pl
# AUTHOR:	Craig A. James
# DESCRIPTION:
#	Rough attempt to convert SMARTS into valid SMILES for display
#	purposes.  Doesn't attempt to deal with bond expressions.
#	
# Copyright (c) 2009, Craig A. James
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation version 3 of the License.
#======================================================================

use strict;

while (<DATA>) {
    chomp;
    my ($smiles, $remainder);
    while (m/([^]]*)(\[[^]]*\])/g) {
	$smiles .= $1;
	my $atom = $2;
	$remainder = $';
	if ($atom =~ m/\[[A-Za-z][a-z]?\@?\@?(H[0-9]*)?([-+][0-9]?)?\]/) {
	    $smiles .= $atom;
	} else {
	    $smiles .= "*";
	}
    }
    $smiles .= $remainder;
    print "$smiles\n";
}

__DATA__
c1[n]cccc1[CH1+2][C@@H1+2]([cR])(Br)[N,O,P]
c1[n]cc[cH]c1
c1[c,n]c[#6]cc1
