Exemple #1
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IAtomType && second is IAtomType))
            {
                return(null);
            }
            var firstElem  = (IAtomType)first;
            var secondElem = (IAtomType)second;
            var totalDiff  = new ChemObjectDifference("AtomTypeDiff");

            totalDiff.AddChild(StringDifference.Construct("N", firstElem.AtomTypeName, secondElem.AtomTypeName));
            totalDiff.AddChild(BondOrderDifference.Construct("MBO", firstElem.MaxBondOrder,
                                                             secondElem.MaxBondOrder));
            totalDiff
            .AddChild(DoubleDifference.Construct("BOS", firstElem.BondOrderSum, secondElem.BondOrderSum));
            totalDiff
            .AddChild(IntegerDifference.Construct("FC", firstElem.FormalCharge, secondElem.FormalCharge));
            totalDiff.AddChild(AtomTypeHybridizationDifference.Construct("H", firstElem.Hybridization,
                                                                         secondElem.Hybridization));
            totalDiff.AddChild(IntegerDifference.Construct("NC", firstElem.FormalNeighbourCount,
                                                           secondElem.FormalNeighbourCount));
            totalDiff.AddChild(DoubleDifference.Construct("CR", firstElem.CovalentRadius,
                                                          secondElem.CovalentRadius));
            totalDiff.AddChild(IntegerDifference.Construct("V", firstElem.Valency, secondElem.Valency));
            totalDiff.AddChild(IsotopeDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Exemple #2
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IBond && second is IBond))
            {
                return(null);
            }
            IBond           firstB    = (IBond)first;
            IBond           secondB   = (IBond)second;
            IDifferenceList totalDiff = new ChemObjectDifference("BondDiff");

            totalDiff.AddChild(BondOrderDifference.Construct("order", firstB.Order, secondB.Order));
            totalDiff.AddChild(IntegerDifference.Construct("atomCount", firstB.Atoms.Count, secondB.Atoms.Count));
            if (firstB.Atoms.Count == secondB.Atoms.Count)
            {
                totalDiff.AddChild(AtomDiff.Difference(firstB.Begin, secondB.Begin));
                totalDiff.AddChild(AtomDiff.Difference(firstB.End, secondB.End));
                for (int i = 2; i < firstB.Atoms.Count; i++)
                {
                    totalDiff.AddChild(AtomDiff.Difference(firstB.Atoms[i], secondB.Atoms[i]));
                }
            }
            totalDiff.AddChild(ElectronContainerDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Exemple #3
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IAtom && second is IAtom))
            {
                return(null);
            }
            IAtom firstElem  = (IAtom)first;
            IAtom secondElem = (IAtom)second;
            ChemObjectDifference totalDiff = new ChemObjectDifference("AtomDiff");

            totalDiff.AddChild(IntegerDifference.Construct("H", firstElem.ImplicitHydrogenCount,
                                                           secondElem.ImplicitHydrogenCount));
            totalDiff
            .AddChild(IntegerDifference.Construct("SP", (int)firstElem.StereoParity, (int)secondElem.StereoParity));
            totalDiff.AddChild(Point2DDifference.Construct("2D", firstElem.Point2D, secondElem.Point2D));
            totalDiff.AddChild(Point3DDifference.Construct("3D", firstElem.Point3D, secondElem.Point3D));
            totalDiff.AddChild(Point3DDifference.Construct("F3D", firstElem.FractionalPoint3D,
                                                           secondElem.FractionalPoint3D));
            totalDiff.AddChild(DoubleDifference.Construct("C", firstElem.Charge, secondElem.Charge));
            totalDiff.AddChild(AtomTypeDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IAtomContainer && second is IAtomContainer))
            {
                return(null);
            }
            var firstAC   = (IAtomContainer)first;
            var secondAC  = (IAtomContainer)second;
            var totalDiff = new ChemObjectDifference("AtomContainerDiff");

            totalDiff.AddChild(IntegerDifference.Construct("atomCount", firstAC.Atoms.Count, secondAC.Atoms.Count));
            if (firstAC.Atoms.Count == secondAC.Atoms.Count)
            {
                for (int i = 0; i < firstAC.Atoms.Count; i++)
                {
                    totalDiff.AddChild(AtomDiff.Difference(firstAC.Atoms[i], secondAC.Atoms[i]));
                }
            }
            totalDiff.AddChild(IntegerDifference.Construct("electronContainerCount", firstAC.GetElectronContainers().Count(),
                                                           secondAC.GetElectronContainers().Count()));
            if (firstAC.GetElectronContainers().Count() == secondAC.GetElectronContainers().Count())
            {
                for (int i = 0; i < firstAC.GetElectronContainers().Count(); i++)
                {
                    if (firstAC.GetElectronContainers().ElementAt(i) is IBond &&
                        secondAC.GetElectronContainers().ElementAt(i) is IBond)
                    {
                        totalDiff.AddChild(BondDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                               secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else if (firstAC.GetElectronContainers().ElementAt(i) is ILonePair &&
                             secondAC.GetElectronContainers().ElementAt(i) is ILonePair)
                    {
                        totalDiff.AddChild(LonePairDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                   secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else if (firstAC.GetElectronContainers().ElementAt(i) is ISingleElectron &&
                             secondAC.GetElectronContainers().ElementAt(i) is ISingleElectron)
                    {
                        totalDiff.AddChild(SingleElectronDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                         secondAC.GetElectronContainers().ElementAt(i)));
                    }
                    else
                    {
                        totalDiff.AddChild(ElectronContainerDiff.Difference(firstAC.GetElectronContainers().ElementAt(i),
                                                                            secondAC.GetElectronContainers().ElementAt(i)));
                    }
                }
            }
            totalDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Exemple #5
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is ILonePair && second is ILonePair))
            {
                return(null);
            }
            var firstB    = (ILonePair)first;
            var secondB   = (ILonePair)second;
            var totalDiff = new ChemObjectDifference("LonePairDiff");

            totalDiff.AddChild(AtomDiff.Difference(firstB.Atom, secondB.Atom));
            totalDiff.AddChild(ElectronContainerDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is ISingleElectron && second is ISingleElectron))
            {
                return(null);
            }
            ISingleElectron firstB    = (ISingleElectron)first;
            ISingleElectron secondB   = (ISingleElectron)second;
            IDifferenceList totalDiff = new ChemObjectDifference("SingleElectronDiff");

            totalDiff.AddChild(AtomDiff.Difference(firstB.Atom, secondB.Atom));
            totalDiff.AddChild(ElectronContainerDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Exemple #7
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IElectronContainer && second is IElectronContainer))
            {
                return(null);
            }
            var firstEC   = (IElectronContainer)first;
            var secondEC  = (IElectronContainer)second;
            var totalDiff = new ChemObjectDifference("ElectronContainerDiff");

            totalDiff.AddChild(IntegerDifference.Construct("eCount", firstEC.ElectronCount,
                                                           secondEC.ElectronCount));
            totalDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Exemple #8
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IChemObject && second is IChemObject))
            {
                return(null);
            }
            var firstElem  = (IChemObject)first;
            var secondElem = (IChemObject)second;
            var coDiff     = new ChemObjectDifference("ChemObjectDiff");

            // Compare flags
            bool[] firstFlags  = new[] { firstElem.IsVisited };
            bool[] secondFlags = new[] { secondElem.IsVisited };
            coDiff.AddChild(BooleanArrayDifference.Construct("flag", firstFlags, secondFlags));
            if (coDiff.ChildCount() > 0)
            {
                return(coDiff);
            }
            else
            {
                return(null);
            }
        }
Exemple #9
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        /// </summary>
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IIsotope && second is IIsotope))
            {
                return(null);
            }
            var firstElem  = (IIsotope)first;
            var secondElem = (IIsotope)second;
            var totalDiff  = new ChemObjectDifference("IsotopeDiff");

            totalDiff.AddChild(IntegerDifference.Construct("MN", firstElem.MassNumber, secondElem.MassNumber));
            totalDiff.AddChild(DoubleDifference.Construct("EM", firstElem.ExactMass, secondElem.ExactMass));
            totalDiff.AddChild(DoubleDifference.Construct("AB", firstElem.Abundance, secondElem.Abundance));
            totalDiff.AddChild(ElementDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
Exemple #10
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        ///
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        /// </summary>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IElement && second is IElement))
            {
                return(null);
            }
            var firstElem  = (IElement)first;
            var secondElem = (IElement)second;
            var coDiff     = new ChemObjectDifference("ElementDiff");

            coDiff.AddChild(StringDifference.Construct("S", firstElem.Symbol, secondElem.Symbol));
            coDiff.AddChild(StringDifference.Construct("ID", firstElem.Id, secondElem.Id));
            coDiff.AddChild(IntegerDifference.Construct("AN", firstElem.AtomicNumber, secondElem.AtomicNumber));
            coDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (coDiff.ChildCount() > 0)
            {
                return(coDiff);
            }
            else
            {
                return(null);
            }
        }