Exemple #1
0
        private static IRingSet toRingSet(IAtomContainer ac, System.Collections.ICollection cycles)
        {
            IRingSet ringSet = ac.Builder.newRingSet();

            System.Collections.IEnumerator cycleIterator = cycles.GetEnumerator();

            while (cycleIterator.MoveNext())
            {
                SimpleCycle cycle = (SimpleCycle)cycleIterator.Current;

                IRing ring = ac.Builder.newRing();

                System.Collections.IList vertices = cycle.vertexList();

                IAtom[] atoms = new IAtom[vertices.Count];
                atoms[0] = (IAtom)vertices[0];
                for (int i = 1; i < vertices.Count; i++)
                {
                    atoms[i] = (IAtom)vertices[i];
                    ring.addElectronContainer(ac.getBond(atoms[i - 1], atoms[i]));
                }
                ring.addElectronContainer(ac.getBond(atoms[vertices.Count - 1], atoms[0]));
                ring.Atoms = atoms;

                ringSet.addAtomContainer(ring);
            }

            return(ringSet);
        }
Exemple #2
0
        public virtual int[] weightVector()
        {
            SimpleCycleBasis basis = simpleBasis();

            System.Collections.IList cycles = basis.cycles();

            int[] result = new int[cycles.Count];
            for (int i = 0; i < cycles.Count; i++)
            {
                SimpleCycle cycle = (SimpleCycle)cycles[i];
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                result[i] = (int)cycle.weight();
            }
            System.Array.Sort(result);

            return(result);
        }
Exemple #3
0
        /// <remarks>Like <see cref="TryExecute(RecipeExecutorState, out RecipeExecutorState)"/>
        /// but with a boolean parameter for throwing.</remarks>
        private bool InternalExecute(RecipeExecutorState state, out RecipeExecutorState stateAfter, bool shouldThrow)
        {
            var oldPathTuples       = state.Boundary.GetRange(Index, Count);
            var oldPathArrows       = oldPathTuples.Select(x => x.Arrow);
            var oldPathOrientations = oldPathTuples.Select(x => x.Orientation);

            if (!oldPathOrientations.AllAreEqual())
            {
                if (shouldThrow)
                {
                    throw new PotentialRecipeExecutionException("The path in the boundary has arrows of different orientation.");
                }

                stateAfter = null;
                return(false);
            }
            var oldPathOrientation = oldPathTuples.First().Orientation;

            if (oldPathOrientation == BoundaryArrowOrientation.Left)
            {
                oldPathArrows = oldPathArrows.Reverse();
            }
            var oldPath = new Path <int>(oldPathArrows);

            var newPathLength = CycleLength - Count;
            var newPath       = Utility.MakePath(oldPath.EndingPoint, oldPath.StartingPoint, newPathLength, state.NextVertex);

            if (newPathLength == 1)
            {
                var newArrow = newPath.Arrows.Single();
                // Bad cancellation
                if (state.PotentiallyProblematicArrows.Contains(newArrow))
                {
                    if (shouldThrow)
                    {
                        throw new PotentialRecipeExecutionException("The arrow of the singleton new path is already present in the potential.");
                    }

                    stateAfter = null;
                    return(false);
                }

                // 2-cycle (which is bad)
                if (state.PotentiallyProblematicArrows.Contains(new Arrow <int>(newArrow.Target, newArrow.Source)))
                {
                    if (shouldThrow)
                    {
                        throw new PotentialRecipeExecutionException("The anti-parallel of the arrow of the singleton new path is present in the potential.");
                    }

                    stateAfter = null;
                    return(false);
                }
            }

            var newPathOrientation = oldPathOrientation.Reverse();
            IEnumerable <Arrow <int> > newPathArrows = newPath.Arrows;

            if (newPathOrientation == BoundaryArrowOrientation.Left)
            {
                newPathArrows = newPathArrows.Reverse();
            }
            var newPathTuples = newPathArrows.Select(a => (a, newPathOrientation));

            var newCycle    = new SimpleCycle <int>(oldPath.AppendPath(newPath));
            int coefficient = newPathOrientation == BoundaryArrowOrientation.Right ? +1 : -1;

            var newBoundary = new CircularList <(Arrow <int>, BoundaryArrowOrientation)>(state.Boundary);

            newBoundary.ReplaceRange(Index, Count, newPathTuples);

            var newPotentiallyProblematicArrows = new HashSet <Arrow <int> >(state.PotentiallyProblematicArrows);

            if (Count == 1)
            {
                newPotentiallyProblematicArrows.Add(oldPath.Arrows.Single());
            }

            stateAfter = new RecipeExecutorState
            {
                Potential  = state.Potential.AddCycle(newCycle, coefficient),
                NextVertex = state.NextVertex + (newPath.LengthInVertices - 2),
                Boundary   = newBoundary,
                PotentiallyProblematicArrows = newPotentiallyProblematicArrows
            };

            return(true);
        }