Beispiel #1
0
        private static List <IAtomContainer> MakeCut(IBond cut, IAtomContainer mol, Dictionary <IAtom, int> idx, int[][] adjlist)
        {
            var beg = cut.Begin;
            var end = cut.End;

            var bvisit = new LinkedHashSet <IAtom>();
            var evisit = new LinkedHashSet <IAtom>();
            var queue  = new ArrayDeque <IAtom>();

            bvisit.Add(beg);
            evisit.Add(end);

            queue.Add(beg);
            bvisit.Add(end); // stop visits
            while (queue.Any())
            {
                var atom = queue.Poll();
                bvisit.Add(atom);
                foreach (var w in adjlist[idx[atom]])
                {
                    var nbr = mol.Atoms[w];
                    if (!bvisit.Contains(nbr))
                    {
                        queue.Add(nbr);
                    }
                }
            }
            bvisit.Remove(end);

            queue.Add(end);
            evisit.Add(beg); // stop visits
            while (queue.Any())
            {
                var atom = queue.Poll();
                evisit.Add(atom);
                foreach (var w in adjlist[idx[atom]])
                {
                    var nbr = mol.Atoms[w];
                    if (!evisit.Contains(nbr))
                    {
                        queue.Add(nbr);
                    }
                }
            }
            evisit.Remove(beg);

            var bldr  = mol.Builder;
            var bfrag = bldr.NewAtomContainer();
            var efrag = bldr.NewAtomContainer();

            int diff = bvisit.Count - evisit.Count;

            if (diff < -10)
            {
                evisit.Clear();
            }
            else if (diff > 10)
            {
                bvisit.Clear();
            }

            if (bvisit.Any())
            {
                bfrag.Atoms.Add(bldr.NewPseudoAtom());
                foreach (var atom in bvisit)
                {
                    bfrag.Atoms.Add(atom);
                }
                bfrag.AddBond(bfrag.Atoms[0], bfrag.Atoms[1], cut.Order);
                bfrag.Bonds[0].SetProperty(PropertyName_CutBond, cut);
            }

            if (evisit.Any())
            {
                efrag.Atoms.Add(bldr.NewPseudoAtom());
                foreach (var atom in evisit)
                {
                    efrag.Atoms.Add(atom);
                }
                efrag.AddBond(efrag.Atoms[0], efrag.Atoms[1], cut.Order);
                efrag.Bonds[0].SetProperty(PropertyName_CutBond, cut);
            }

            foreach (var bond in mol.Bonds)
            {
                var a1 = bond.Begin;
                var a2 = bond.End;
                if (bvisit.Contains(a1) && bvisit.Contains(a2))
                {
                    bfrag.Bonds.Add(bond);
                }
                else if (evisit.Contains(a1) && evisit.Contains(a2))
                {
                    efrag.Bonds.Add(bond);
                }
            }

            var res = new List <IAtomContainer>();

            if (!bfrag.IsEmpty())
            {
                res.Add(bfrag);
            }
            if (!efrag.IsEmpty())
            {
                res.Add(efrag);
            }
            return(res);
        }