using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using ChemAxon.NET.IKVM.Chemistry;
using ChemAxon.NET.API;
using ChemAxon.NET.IKVM.RGroupDecomposition;

namespace ChemAxon.NET.UnitTest.API.Examples.Chemistry.RGroup
{    
    public class RGroupExample
    {        
        public void RGroup_Example()
        {
            var targets = new List<IJChemMolecule>();
            targets.Add(MainFactory.Chemistry.CreateMolecule("benzene"));
            targets.Add(MainFactory.Chemistry.CreateMolecule("methylpropane"));
            targets.Add(MainFactory.Chemistry.CreateMolecule("hexane"));

            IEnumerable<IJChemMolecule[]> rGroupResult = DoRGroupDecomp(targets);

            Console.WriteLine("R-group result:");

            foreach (IJChemMolecule[] rGroupRow in rGroupResult)
            {
                foreach (IJChemMolecule molecule in rGroupRow)
                    Console.Write(string.Format("\t{0}", molecule.Formula));
                
                Console.WriteLine();
            }
        }

        public IEnumerable<IJChemMolecule[]> DoRGroupDecomp(IEnumerable<IJChemMolecule> targets)
        {
            IRGroupDecomposition rGroup = MainFactory.Chemistry.CreateRGroupDecomposition(targets);
            rGroup.Options.IncludeHeader = true;
            rGroup.Options.IncludeNonMatchingTarget = false;

            IJChemMolecule query = MainFactory.Chemistry.CreateMolecule("methane");
            IEnumerable<IJChemMolecule[]> rGroupResult = rGroup.Decompose(query);
            return rGroupResult;
        }
    }
}