Пример #1
0
        /// <summary>
        /// Produces a HOSE code for Atom <paramref name="root"/> in the <see cref="IAtomContainer"/> <paramref name="ac"/>. The HOSE
        /// code is produced for the number of spheres given by <paramref name="noOfSpheres"/>.
        /// </summary>
        /// <remarks>
        /// <note type="important">
        /// If you want aromaticity to be included in the code, you need
        /// to apply <see cref="Aromaticities.Aromaticity.Apply(IAtomContainer)"/> to <paramref name="ac"/> prior to
        /// using <see cref="GetHOSECode(IAtomContainer, IAtom, int, bool)"/>. This method only gives proper results if the molecule is
        /// fully saturated (if not, the order of the HOSE code might depend on atoms in higher spheres).
        /// This method is known to fail for protons sometimes.
        /// </note>
        /// <note type="important">
        /// Your molecule must contain implicit or explicit hydrogens
        /// for this method to work properly.
        /// </note>
        /// </remarks>
        /// <param name="ac">The IAtomContainer with the molecular skeleton in which the root atom resides</param>
        /// <param name="root">The root atom for which to produce the HOSE code</param>
        /// <param name="noOfSpheres">The number of spheres to look at</param>
        /// <param name="ringsize">The size of the Ring(s) it is in is included in center atom code</param>
        /// <returns>The HOSECode value</returns>
        /// <exception cref="CDKException">Thrown if something is wrong</exception>
        public string GetHOSECode(IAtomContainer ac, IAtom root, int noOfSpheres, bool ringsize)
        {
            var canLabler = new CanonicalLabeler();

            canLabler.CanonLabel(ac);
            centerCode         = "";
            this.atomContainer = ac;
            maxSphere          = noOfSpheres;
            spheres            = new List <TreeNode> [noOfSpheres + 1];
            for (int i = 0; i < ac.Atoms.Count; i++)
            {
                ac.Atoms[i].IsVisited = false;
            }
            root.IsVisited = true;
            rootNode       = new TreeNode(this, root.Symbol, null, root, (double)0, atomContainer.GetConnectedBonds(root).Count(), 0);

            // All we need to observe is how the ranking of substituents in the
            // subsequent spheres of the root nodes influences the ranking of the
            // first sphere, since the order of a node in a sphere depends on the
            // order the preceding node in its branch
            HOSECode = new StringBuilder();
            CreateCenterCode(root, ac, ringsize);
            BreadthFirstSearch(root, true);
            CreateCode();
            FillUpSphereDelimiters();
            Debug.WriteLine($"HOSECodeGenerator -> HOSECode: {HOSECode}");
            return(HOSECode.ToString());
        }
Пример #2
0
        public int[] GetCanonicalPermutation(IAtomContainer container)
        {
            CanonicalLabeler labeler = new CanonicalLabeler();

            labeler.CanonLabel(container);
            int n = container.Atoms.Count;

            int[] perm = new int[n];
            for (int i = 0; i < n; i++)
            {
                IAtom a = container.Atoms[i];
                int   x = (int)a.GetProperty <long>(InvPair.CanonicalLabelPropertyKey);
                perm[i] = x - 1;
            }
            return(perm);
        }