Exemplo n.º 1
0
        private static void AddExtendedCisTransConfig(ExtendedCisTrans ect, GraphBuilder gb,
                                                      Dictionary <IAtom, int> indices,
                                                      IAtomContainer container)
        {
            var ends     = ExtendedCisTrans.FindTerminalAtoms(container, ect.Focus);
            var carriers = ect.Carriers;

            if (ends != null)
            {
                Configuration.ConfigurationDoubleBond config;
                switch (ect.Configure)
                {
                case StereoConfigurations.Together:
                    config = Configuration.ConfigurationDoubleBond.Together;
                    break;

                case StereoConfigurations.Opposite:
                    config = Configuration.ConfigurationDoubleBond.Opposite;
                    break;

                default:
                    config = Configuration.ConfigurationDoubleBond.Unspecified;
                    break;
                }
                gb.CreateExtendedGeometric(indices[ends[0]], indices[ends[1]])
                .Configure(indices[carriers[0].GetOther(ends[0])],
                           indices[carriers[1].GetOther(ends[1])],
                           config);
            }
        }
        /// <summary>
        /// Adjust the configuration of the cumulated double bonds to be
        /// either Cis or Trans.
        /// </summary>
        /// <param name="elem">the stereo element to adjust</param>
        private void Adjust(ExtendedCisTrans elem)
        {
            var middle = elem.Focus;
            var ends   = ExtendedCisTrans.FindTerminalAtoms(container, middle);
            var bonds  = elem.Carriers;
            var left   = ends[0];
            var right  = ends[1];
            var p      = Parity(elem.Configure);
            var q      = Parity(GetAtoms(left, bonds[0].GetOther(left), right))
                         * Parity(GetAtoms(right, bonds[1].GetOther(right), left));

            // configuration is unspecified? then we add an unspecified bond.
            // note: IDoubleBondStereochemistry doesn't indicate this yet
            if (p == 0)
            {
                foreach (var bond in container.GetConnectedBonds(left))
                {
                    bond.Stereo = BondStereo.None;
                }
                foreach (var bond in container.GetConnectedBonds(right))
                {
                    bond.Stereo = BondStereo.None;
                }
                bonds[0].Stereo = BondStereo.UpOrDown;
                return;
            }
            // configuration is already correct
            if (p == q)
            {
                return;
            }
            Arrays.Fill(visited, false);
            visited[atomToIndex[left]] = true;
            if (ringSearch.Cyclic(atomToIndex[middle.Begin], atomToIndex[middle.End]))
            {
                return;
            }
            foreach (var w in graph[atomToIndex[right]])
            {
                if (!visited[w])
                {
                    Reflect(w, middle);
                }
            }
        }