/// <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 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); } }
/// <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); } }