From 90d75ec8dadd771fcf8ebc18c936b98fd04392ac Mon Sep 17 00:00:00 2001 From: Kazuya Ujihara Date: Sun, 14 Apr 2019 19:52:10 +0900 Subject: [PATCH] Add IAtomContainer.RemoveBond(bond). Fix AtomContainer.RemoveBond to remove stereoElement info. --- NCDK/Graphs/AllPairsShortestPaths.cs | 3 + NCDK/IAtomContainer.cs | 7 ++ NCDK/Isomorphisms/Matchers/QueryBond.cs | 11 +- NCDK/NCDKUtil.cs | 7 ++ NCDK/TT/AtomContainer.tt | 50 +++++++--- NCDK/TT/AtomContainer.tt.cs | 100 +++++++++++++------ NCDK/TT/AtomContainer2.tt | 11 +- NCDK/TT/AtomContainer2.tt.cs | 22 +++- NCDKTests/AbstractAtomContainerTest.cs | 22 ++++ NCDKTests/Stereo/StereoElementFactoryTest.cs | 60 ++++++++--- NCDKTests/TT/AtomContainer2Test.tt | 2 +- NCDKTests/TT/AtomContainer2Test.tt.cs | 4 +- 12 files changed, 230 insertions(+), 69 deletions(-) diff --git a/NCDK/Graphs/AllPairsShortestPaths.cs b/NCDK/Graphs/AllPairsShortestPaths.cs index 2337674c..173617c1 100644 --- a/NCDK/Graphs/AllPairsShortestPaths.cs +++ b/NCDK/Graphs/AllPairsShortestPaths.cs @@ -217,6 +217,9 @@ public void RemoveProperty(object description) { } public void Remove(IElectronContainer electronContainer) { } + public void RemoveBond(IBond bond) + { } + public IBond RemoveBond(IAtom atom0, IAtom atom1) { return null; diff --git a/NCDK/IAtomContainer.cs b/NCDK/IAtomContainer.cs index 02417789..67fc4d6d 100644 --- a/NCDK/IAtomContainer.cs +++ b/NCDK/IAtomContainer.cs @@ -262,6 +262,13 @@ public interface IAtomContainer /// The bond that connects the two atoms IBond RemoveBond(IAtom atom1, IAtom atom2); + /// + /// Removes the bond. + /// + /// The bond to remove. + /// + void RemoveBond(IBond bond); + /// /// , if the contains the given atom object. /// diff --git a/NCDK/Isomorphisms/Matchers/QueryBond.cs b/NCDK/Isomorphisms/Matchers/QueryBond.cs index a632ed34..a1d1f6f4 100644 --- a/NCDK/Isomorphisms/Matchers/QueryBond.cs +++ b/NCDK/Isomorphisms/Matchers/QueryBond.cs @@ -41,8 +41,8 @@ public class QueryBond /// /// /// // pi-bond in a ring - /// Expr e = new Expr(IS_IN_RING); - /// e.And(new Expr(ALIPHATIC_ORDER, 2)); + /// Expr e = new Expr(ExprType.IsInRing); + /// e.And(new Expr(ExprType.AliphaticOrder, 2)); /// new QueryBond(beg, end, e); /// /// @@ -60,7 +60,7 @@ public QueryBond(IAtom beg, IAtom end, Expr expr) /// /// /// - /// new QueryBond(beg, end, IS_IN_RING); + /// new QueryBond(beg, end, ExprType.IsInRing); /// /// /// the expression type @@ -71,18 +71,19 @@ public QueryBond(IAtom beg, IAtom end, ExprType type) while (Atoms.Count < 2) Atoms.Add(null); } + /// /// Constructs an query bond from an expression type and value. /// /// /// - /// new QueryBond(beg, end, ALIPHATIC_ORDER, 8); + /// new QueryBond(beg, end, ExprType.AliphaticOrder, 8); /// /// the expression type /// the expression value public QueryBond(IAtom beg, IAtom end, ExprType type, int val) : this(beg, end, BondOrder.Unset, BondStereo.None) - { + { this.Expression.SetPrimitive(type, val); while (Atoms.Count < 2) Atoms.Add(null); diff --git a/NCDK/NCDKUtil.cs b/NCDK/NCDKUtil.cs index 7fd91f7f..e714c367 100644 --- a/NCDK/NCDKUtil.cs +++ b/NCDK/NCDKUtil.cs @@ -112,5 +112,12 @@ public static IAtom Add(this IAtomContainer mol, ChemicalElement element) mol.Add(atom); return atom; } + + public static IAtom AddAtom(this IAtomContainer mol, string elementSymbol) + { + var atom = mol.Builder.NewAtom(elementSymbol); + mol.Add(atom); + return atom; + } } } diff --git a/NCDK/TT/AtomContainer.tt b/NCDK/TT/AtomContainer.tt index ca1cdb30..6409d39b 100644 --- a/NCDK/TT/AtomContainer.tt +++ b/NCDK/TT/AtomContainer.tt @@ -78,7 +78,7 @@ namespace <#= ns.NS #> /// /// Stereo elements contained by this object. /// - internal List> stereoElements; + internal List> stereo; /// public override IChemObjectBuilder Builder => builder; @@ -141,7 +141,7 @@ namespace <#= ns.NS #> List> oldStereo = null; List> newStereo = null; - foreach (var se in parent.stereoElements) + foreach (var se in parent.stereo) { if (se.Contains(oldAtom)) { @@ -161,9 +161,9 @@ namespace <#= ns.NS #> if (oldStereo != null) { foreach (var stereo in oldStereo) - parent.stereoElements.Remove(stereo); + parent.stereo.Remove(stereo); foreach (var stereo in newStereo) - parent.stereoElements.Add(stereo); + parent.stereo.Add(stereo); } <# if (!ns.IsSilent) { #> @@ -178,13 +178,13 @@ namespace <#= ns.NS #> ObservableChemObjectCollection bonds, ObservableChemObjectCollection lonePairs, ObservableChemObjectCollection singleElectrons, - List> stereoElements) + List> stereo) { this.atoms = atoms; this.bonds = bonds; this.lonePairs = lonePairs; this.singleElectrons = singleElectrons; - this.stereoElements = stereoElements; + this.stereo = stereo; } public AtomContainer( @@ -192,14 +192,14 @@ namespace <#= ns.NS #> IEnumerable bonds, IEnumerable lonePairs, IEnumerable singleElectrons, - IEnumerable> stereoElements) + IEnumerable> stereo) { Init( new ObservableChemObjectCollection_IAtom(this, atoms ?? Array.Empty()), CreateObservableChemObjectCollection(bonds ?? Array.Empty(), true), CreateObservableChemObjectCollection(lonePairs ?? Array.Empty(), true), CreateObservableChemObjectCollection(singleElectrons ?? Array.Empty(), true), - new List>(stereoElements ?? Array.Empty>()) + new List>(stereo ?? Array.Empty>()) ); } @@ -271,7 +271,7 @@ var thisListener = ns.IsSilent ? "null" : "this"; public virtual IList SingleElectrons => singleElectrons; /// - public virtual ICollection> StereoElements => stereoElements; + public virtual ICollection> StereoElements => stereo; /// /// Returns the bond that connects the two given atoms. @@ -414,7 +414,7 @@ var thisListener = ns.IsSilent ? "null" : "this"; foreach (var singleElectron in that.SingleElectrons.Where(singleElectron => !Contains(singleElectron))) SingleElectrons.Add(singleElectron); foreach (var se in that.StereoElements) - stereoElements.Add(se); + stereo.Add(se); <# if (!ns.IsSilent) { #> NotifyChanged(); <# } #> } @@ -498,9 +498,9 @@ var thisListener = ns.IsSilent ? "null" : "this"; singleElectrons.Remove(singleElectron); } { - var toRemove = stereoElements.Where(stereoElement => stereoElement.Contains(atom)).ToList(); + var toRemove = stereo.Where(stereoElement => stereoElement.Contains(atom)).ToList(); foreach (var stereoElement in toRemove) - stereoElements.Remove(stereoElement); + stereo.Remove(stereoElement); } Atoms.Remove(atom); @@ -521,7 +521,7 @@ var thisListener = ns.IsSilent ? "null" : "this"; foreach (var atom in atoms) atom.Listeners?.Remove(this); atoms.Clear(); - stereoElements.Clear(); + stereo.Clear(); <# if (!ns.IsSilent) { #> NotifyChanged(); <# } #> } @@ -549,9 +549,29 @@ var thisListener = ns.IsSilent ? "null" : "this"; public virtual IBond RemoveBond(IAtom atom1, IAtom atom2) { var bond = GetBond(atom1, atom2); + RemoveBond(bond); + return bond; + } + + public virtual void RemoveBond(IBond bond) + { if (bond != null) + { + var stereoToRemove = new List>(); + foreach (var stereoBond in stereo) + { + if (stereoBond.Focus == bond + || stereoBond.Carriers.Contains(bond)) + { + stereoToRemove.Add(stereoBond); + continue; + } + } + foreach (var remove in stereoToRemove) + stereo.Remove(remove); + Bonds.Remove(bond); - return bond; + } } /// @@ -586,7 +606,7 @@ var thisListener = ns.IsSilent ? "null" : "this"; clone.bonds = CreateObservableChemObjectCollection(bonds.Where(n => n != null).Select(n => (IBond)n.Clone(map)), true); clone.lonePairs = CreateObservableChemObjectCollection(lonePairs.Where(n => n != null).Select(n => (ILonePair)n.Clone(map)), true); clone.singleElectrons = CreateObservableChemObjectCollection(singleElectrons.Where(n => n != null).Select(n => (ISingleElectron)n.Clone(map)), true); - clone.stereoElements = new List>(stereoElements.Select(n => (IStereoElement)n.Clone(map))); + clone.stereo = new List>(stereo.Select(n => (IStereoElement)n.Clone(map))); // update sgroups var sgroups = this.GetCtabSgroups(); diff --git a/NCDK/TT/AtomContainer.tt.cs b/NCDK/TT/AtomContainer.tt.cs index 35008b80..289ab0df 100644 --- a/NCDK/TT/AtomContainer.tt.cs +++ b/NCDK/TT/AtomContainer.tt.cs @@ -76,7 +76,7 @@ public partial class AtomContainer /// /// Stereo elements contained by this object. /// - internal List> stereoElements; + internal List> stereo; /// public override IChemObjectBuilder Builder => builder; @@ -139,7 +139,7 @@ public override IAtom this[int index] List> oldStereo = null; List> newStereo = null; - foreach (var se in parent.stereoElements) + foreach (var se in parent.stereo) { if (se.Contains(oldAtom)) { @@ -159,9 +159,9 @@ public override IAtom this[int index] if (oldStereo != null) { foreach (var stereo in oldStereo) - parent.stereoElements.Remove(stereo); + parent.stereo.Remove(stereo); foreach (var stereo in newStereo) - parent.stereoElements.Add(stereo); + parent.stereo.Add(stereo); } @@ -176,13 +176,13 @@ private void Init( ObservableChemObjectCollection bonds, ObservableChemObjectCollection lonePairs, ObservableChemObjectCollection singleElectrons, - List> stereoElements) + List> stereo) { this.atoms = atoms; this.bonds = bonds; this.lonePairs = lonePairs; this.singleElectrons = singleElectrons; - this.stereoElements = stereoElements; + this.stereo = stereo; } public AtomContainer( @@ -190,14 +190,14 @@ public AtomContainer( IEnumerable bonds, IEnumerable lonePairs, IEnumerable singleElectrons, - IEnumerable> stereoElements) + IEnumerable> stereo) { Init( new ObservableChemObjectCollection_IAtom(this, atoms ?? Array.Empty()), CreateObservableChemObjectCollection(bonds ?? Array.Empty(), true), CreateObservableChemObjectCollection(lonePairs ?? Array.Empty(), true), CreateObservableChemObjectCollection(singleElectrons ?? Array.Empty(), true), - new List>(stereoElements ?? Array.Empty>()) + new List>(stereo ?? Array.Empty>()) ); } @@ -313,7 +313,7 @@ internal void SetIsSingleOrDoubleWithoutNotify(bool value) public virtual IList SingleElectrons => singleElectrons; /// - public virtual ICollection> StereoElements => stereoElements; + public virtual ICollection> StereoElements => stereo; /// /// Returns the bond that connects the two given atoms. @@ -456,7 +456,7 @@ public virtual void Add(IAtomContainer that) foreach (var singleElectron in that.SingleElectrons.Where(singleElectron => !Contains(singleElectron))) SingleElectrons.Add(singleElectron); foreach (var se in that.StereoElements) - stereoElements.Add(se); + stereo.Add(se); NotifyChanged(); } @@ -539,9 +539,9 @@ public virtual void RemoveAtom(IAtom atom) singleElectrons.Remove(singleElectron); } { - var toRemove = stereoElements.Where(stereoElement => stereoElement.Contains(atom)).ToList(); + var toRemove = stereo.Where(stereoElement => stereoElement.Contains(atom)).ToList(); foreach (var stereoElement in toRemove) - stereoElements.Remove(stereoElement); + stereo.Remove(stereoElement); } Atoms.Remove(atom); @@ -561,7 +561,7 @@ public virtual void RemoveAllElements() foreach (var atom in atoms) atom.Listeners?.Remove(this); atoms.Clear(); - stereoElements.Clear(); + stereo.Clear(); NotifyChanged(); } @@ -587,9 +587,29 @@ public virtual void RemoveAllElectronContainers() public virtual IBond RemoveBond(IAtom atom1, IAtom atom2) { var bond = GetBond(atom1, atom2); + RemoveBond(bond); + return bond; + } + + public virtual void RemoveBond(IBond bond) + { if (bond != null) + { + var stereoToRemove = new List>(); + foreach (var stereoBond in stereo) + { + if (stereoBond.Focus == bond + || stereoBond.Carriers.Contains(bond)) + { + stereoToRemove.Add(stereoBond); + continue; + } + } + foreach (var remove in stereoToRemove) + stereo.Remove(remove); + Bonds.Remove(bond); - return bond; + } } /// @@ -624,7 +644,7 @@ public override ICDKObject Clone(CDKObjectMap map) clone.bonds = CreateObservableChemObjectCollection(bonds.Where(n => n != null).Select(n => (IBond)n.Clone(map)), true); clone.lonePairs = CreateObservableChemObjectCollection(lonePairs.Where(n => n != null).Select(n => (ILonePair)n.Clone(map)), true); clone.singleElectrons = CreateObservableChemObjectCollection(singleElectrons.Where(n => n != null).Select(n => (ISingleElectron)n.Clone(map)), true); - clone.stereoElements = new List>(stereoElements.Select(n => (IStereoElement)n.Clone(map))); + clone.stereo = new List>(stereo.Select(n => (IStereoElement)n.Clone(map))); // update sgroups var sgroups = this.GetCtabSgroups(); @@ -716,7 +736,7 @@ public partial class AtomContainer /// /// Stereo elements contained by this object. /// - internal List> stereoElements; + internal List> stereo; /// public override IChemObjectBuilder Builder => builder; @@ -776,7 +796,7 @@ public override IAtom this[int index] List> oldStereo = null; List> newStereo = null; - foreach (var se in parent.stereoElements) + foreach (var se in parent.stereo) { if (se.Contains(oldAtom)) { @@ -796,9 +816,9 @@ public override IAtom this[int index] if (oldStereo != null) { foreach (var stereo in oldStereo) - parent.stereoElements.Remove(stereo); + parent.stereo.Remove(stereo); foreach (var stereo in newStereo) - parent.stereoElements.Add(stereo); + parent.stereo.Add(stereo); } @@ -811,13 +831,13 @@ private void Init( ObservableChemObjectCollection bonds, ObservableChemObjectCollection lonePairs, ObservableChemObjectCollection singleElectrons, - List> stereoElements) + List> stereo) { this.atoms = atoms; this.bonds = bonds; this.lonePairs = lonePairs; this.singleElectrons = singleElectrons; - this.stereoElements = stereoElements; + this.stereo = stereo; } public AtomContainer( @@ -825,14 +845,14 @@ public AtomContainer( IEnumerable bonds, IEnumerable lonePairs, IEnumerable singleElectrons, - IEnumerable> stereoElements) + IEnumerable> stereo) { Init( new ObservableChemObjectCollection_IAtom(this, atoms ?? Array.Empty()), CreateObservableChemObjectCollection(bonds ?? Array.Empty(), true), CreateObservableChemObjectCollection(lonePairs ?? Array.Empty(), true), CreateObservableChemObjectCollection(singleElectrons ?? Array.Empty(), true), - new List>(stereoElements ?? Array.Empty>()) + new List>(stereo ?? Array.Empty>()) ); } @@ -946,7 +966,7 @@ internal void SetIsSingleOrDoubleWithoutNotify(bool value) public virtual IList SingleElectrons => singleElectrons; /// - public virtual ICollection> StereoElements => stereoElements; + public virtual ICollection> StereoElements => stereo; /// /// Returns the bond that connects the two given atoms. @@ -1089,7 +1109,7 @@ public virtual void Add(IAtomContainer that) foreach (var singleElectron in that.SingleElectrons.Where(singleElectron => !Contains(singleElectron))) SingleElectrons.Add(singleElectron); foreach (var se in that.StereoElements) - stereoElements.Add(se); + stereo.Add(se); } @@ -1172,9 +1192,9 @@ public virtual void RemoveAtom(IAtom atom) singleElectrons.Remove(singleElectron); } { - var toRemove = stereoElements.Where(stereoElement => stereoElement.Contains(atom)).ToList(); + var toRemove = stereo.Where(stereoElement => stereoElement.Contains(atom)).ToList(); foreach (var stereoElement in toRemove) - stereoElements.Remove(stereoElement); + stereo.Remove(stereoElement); } Atoms.Remove(atom); @@ -1194,7 +1214,7 @@ public virtual void RemoveAllElements() foreach (var atom in atoms) atom.Listeners?.Remove(this); atoms.Clear(); - stereoElements.Clear(); + stereo.Clear(); } @@ -1220,9 +1240,29 @@ public virtual void RemoveAllElectronContainers() public virtual IBond RemoveBond(IAtom atom1, IAtom atom2) { var bond = GetBond(atom1, atom2); + RemoveBond(bond); + return bond; + } + + public virtual void RemoveBond(IBond bond) + { if (bond != null) + { + var stereoToRemove = new List>(); + foreach (var stereoBond in stereo) + { + if (stereoBond.Focus == bond + || stereoBond.Carriers.Contains(bond)) + { + stereoToRemove.Add(stereoBond); + continue; + } + } + foreach (var remove in stereoToRemove) + stereo.Remove(remove); + Bonds.Remove(bond); - return bond; + } } /// @@ -1257,7 +1297,7 @@ public override ICDKObject Clone(CDKObjectMap map) clone.bonds = CreateObservableChemObjectCollection(bonds.Where(n => n != null).Select(n => (IBond)n.Clone(map)), true); clone.lonePairs = CreateObservableChemObjectCollection(lonePairs.Where(n => n != null).Select(n => (ILonePair)n.Clone(map)), true); clone.singleElectrons = CreateObservableChemObjectCollection(singleElectrons.Where(n => n != null).Select(n => (ISingleElectron)n.Clone(map)), true); - clone.stereoElements = new List>(stereoElements.Select(n => (IStereoElement)n.Clone(map))); + clone.stereo = new List>(stereo.Select(n => (IStereoElement)n.Clone(map))); // update sgroups var sgroups = this.GetCtabSgroups(); diff --git a/NCDK/TT/AtomContainer2.tt b/NCDK/TT/AtomContainer2.tt index c511468f..1524229d 100644 --- a/NCDK/TT/AtomContainer2.tt +++ b/NCDK/TT/AtomContainer2.tt @@ -1146,6 +1146,15 @@ namespace <#= ns.NS #> public IBond RemoveBond(IAtom beg, IAtom end) { var bond = GetBond(beg, end); + if (bond != null) + { + RemoveBond(bond); + } + return bond; + } + + public void RemoveBond(IBond bond) + { if (bond != null) { var stereoToRemove = new List>(); @@ -1160,9 +1169,9 @@ namespace <#= ns.NS #> } foreach (var remove in stereoToRemove) stereo.Remove(remove); + Bonds.Remove(bond); } - return bond; } /// diff --git a/NCDK/TT/AtomContainer2.tt.cs b/NCDK/TT/AtomContainer2.tt.cs index 356329cd..d8ba6b46 100644 --- a/NCDK/TT/AtomContainer2.tt.cs +++ b/NCDK/TT/AtomContainer2.tt.cs @@ -1124,6 +1124,15 @@ public void Remove(IAtomContainer atomContainer) public IBond RemoveBond(IAtom beg, IAtom end) { var bond = GetBond(beg, end); + if (bond != null) + { + RemoveBond(bond); + } + return bond; + } + + public void RemoveBond(IBond bond) + { if (bond != null) { var stereoToRemove = new List>(); @@ -1138,9 +1147,9 @@ public IBond RemoveBond(IAtom beg, IAtom end) } foreach (var remove in stereoToRemove) stereo.Remove(remove); + Bonds.Remove(bond); } - return bond; } /// @@ -2480,6 +2489,15 @@ public void Remove(IAtomContainer atomContainer) public IBond RemoveBond(IAtom beg, IAtom end) { var bond = GetBond(beg, end); + if (bond != null) + { + RemoveBond(bond); + } + return bond; + } + + public void RemoveBond(IBond bond) + { if (bond != null) { var stereoToRemove = new List>(); @@ -2494,9 +2512,9 @@ public IBond RemoveBond(IAtom beg, IAtom end) } foreach (var remove in stereoToRemove) stereo.Remove(remove); + Bonds.Remove(bond); } - return bond; } /// diff --git a/NCDKTests/AbstractAtomContainerTest.cs b/NCDKTests/AbstractAtomContainerTest.cs index 64b0e917..4e0c7094 100644 --- a/NCDKTests/AbstractAtomContainerTest.cs +++ b/NCDKTests/AbstractAtomContainerTest.cs @@ -3105,5 +3105,27 @@ public void GetSelfBond() mol.Bonds.Add(b2); Assert.IsNull(mol.GetBond(a1, a1)); } + + [TestMethod()] + public void RemoveStereoBondFromBiphenyl() + { + var b1 = CDK.SmilesParser.ParseSmiles("c1ccccc1"); + var b2 = CDK.SmilesParser.ParseSmiles("c1ccccc1"); + var b = CDK.Builder.NewBond(b1.Atoms[0], b2.Atoms[0]); + var mol = CDK.Builder.NewAtomContainer(); + mol.Add(b1); + mol.Add(b2); + mol.Bonds.Add(b); + var focus = b; + var carriers = new List(); + carriers.AddRange(mol.GetConnectedAtoms(focus.Begin)); + carriers.AddRange(mol.GetConnectedAtoms(focus.End)); + carriers.Remove(focus.Begin); + carriers.Remove(focus.End); + mol.StereoElements.Add(new Atropisomeric(focus, carriers, StereoConfigurations.Left)); + Assert.IsTrue(mol.StereoElements.Any()); + mol.RemoveBond(b); + Assert.IsFalse(mol.StereoElements.Any()); + } } } diff --git a/NCDKTests/Stereo/StereoElementFactoryTest.cs b/NCDKTests/Stereo/StereoElementFactoryTest.cs index a3139474..adc70c81 100644 --- a/NCDKTests/Stereo/StereoElementFactoryTest.cs +++ b/NCDKTests/Stereo/StereoElementFactoryTest.cs @@ -207,10 +207,12 @@ public void E_hexa234triene() mol.AddBond(mol.Atoms[3], mol.Atoms[4], BondOrder.Single); mol.AddBond(mol.Atoms[0], mol.Atoms[5], BondOrder.Single); StereoElementFactory factory = StereoElementFactory.Using2DCoordinates(mol); - var dbs = new List(); - dbs.Add(mol.Bonds[0]); - dbs.Add(mol.Bonds[1]); - dbs.Add(mol.Bonds[2]); + var dbs = new List + { + mol.Bonds[0], + mol.Bonds[1], + mol.Bonds[2], + }; ExtendedCisTrans element = factory.CreateExtendedCisTrans(dbs, Stereocenters.Of(mol)); Assert.IsNotNull(element); Assert.AreEqual(StereoConfigurations.Opposite, element.Configure); @@ -221,7 +223,7 @@ public void E_hexa234triene() /// // @cdk.smiles C/C=C=C=C\C [TestMethod()] - public void z_hexa234triene() + public void Z_hexa234triene() { var mol = builder.NewAtomContainer(); mol.Atoms.Add(Atom("C", 1, 2.48d, 0.00d)); @@ -236,10 +238,12 @@ public void z_hexa234triene() mol.AddBond(mol.Atoms[3], mol.Atoms[4], BondOrder.Single); mol.AddBond(mol.Atoms[0], mol.Atoms[5], BondOrder.Single); StereoElementFactory factory = StereoElementFactory.Using2DCoordinates(mol); - var dbs = new List(); - dbs.Add(mol.Bonds[0]); - dbs.Add(mol.Bonds[1]); - dbs.Add(mol.Bonds[2]); + var dbs = new List + { + mol.Bonds[0], + mol.Bonds[1], + mol.Bonds[2], + }; ExtendedCisTrans element = factory.CreateExtendedCisTrans(dbs, Stereocenters.Of(mol)); Assert.IsNotNull(element); Assert.AreEqual(StereoConfigurations.Together, element.Configure); @@ -265,10 +269,12 @@ public void E_hexa234triene_3D() mol.AddBond(mol.Atoms[3], mol.Atoms[4], BondOrder.Single); mol.AddBond(mol.Atoms[0], mol.Atoms[5], BondOrder.Single); StereoElementFactory factory = StereoElementFactory.Using3DCoordinates(mol); - var dbs = new List(); - dbs.Add(mol.Bonds[0]); - dbs.Add(mol.Bonds[1]); - dbs.Add(mol.Bonds[2]); + var dbs = new List + { + mol.Bonds[0], + mol.Bonds[1], + mol.Bonds[2] + }; ExtendedCisTrans element = factory.CreateExtendedCisTrans(dbs, Stereocenters.Of(mol)); Assert.IsNotNull(element); Assert.AreEqual(StereoConfigurations.Opposite, element.Configure); @@ -1540,6 +1546,34 @@ public void Atropisomer3D() Assert.AreEqual(1, stereo.Count()); } + [TestMethod()] + public void SamePositionWithStereocenter() + { + IAtomContainer m = builder.NewAtomContainer(); + m.Atoms.Add(Atom("F", 0, -1, -1)); + m.Atoms.Add(Atom("Cl", 0, 1, -1)); + m.Atoms.Add(Atom("C", 0, 0, 0)); + m.Atoms.Add(Atom("Br", 0, 1, 1)); + m.Atoms.Add(Atom("H", 0, 0, 0)); + m.AddBond(m.Atoms[2], m.Atoms[0], BondOrder.Single); + m.AddBond(m.Atoms[2], m.Atoms[1], BondOrder.Single); + m.AddBond(m.Atoms[2], m.Atoms[3], BondOrder.Single); + m.AddBond(m.Atoms[2], m.Atoms[4], BondOrder.Single); + m.Bonds[2].Stereo = BondStereo.Down; + + var ses = StereoElementFactory.Using2DCoordinates(m).CreateAll(); + bool flag = false; + foreach (var se in ses) + { + if (se != null) + { + flag = true; + break; + } + } + Assert.IsTrue(flag); + } + static IAtom Atom(string symbol, int h, double x, double y) { IAtom a = builder.NewAtom(symbol); diff --git a/NCDKTests/TT/AtomContainer2Test.tt b/NCDKTests/TT/AtomContainer2Test.tt index e51ef82d..f95ece39 100644 --- a/NCDKTests/TT/AtomContainer2Test.tt +++ b/NCDKTests/TT/AtomContainer2Test.tt @@ -101,7 +101,7 @@ namespace <#= ns.NS #> Assert.AreEqual(mol.Atoms[0].GetBond(mol.Atoms[1]), mol.Bonds[0]); Assert.AreEqual(mol.Atoms[1].GetBond(mol.Atoms[2]), mol.Bonds[1]); Assert.IsNull(mol.Atoms[0].GetBond(mol.Atoms[2])); - } + } <# if (ns.IsSilent) { #> <#@ include file="TestAbstractAtomContainer.ttinclude" #> diff --git a/NCDKTests/TT/AtomContainer2Test.tt.cs b/NCDKTests/TT/AtomContainer2Test.tt.cs index 074667fb..396d39af 100644 --- a/NCDKTests/TT/AtomContainer2Test.tt.cs +++ b/NCDKTests/TT/AtomContainer2Test.tt.cs @@ -102,7 +102,7 @@ public void TestAtomGetBond() Assert.AreEqual(mol.Atoms[0].GetBond(mol.Atoms[1]), mol.Bonds[0]); Assert.AreEqual(mol.Atoms[1].GetBond(mol.Atoms[2]), mol.Bonds[1]); Assert.IsNull(mol.Atoms[0].GetBond(mol.Atoms[2])); - } + } } } @@ -181,7 +181,7 @@ public void TestAtomGetBond() Assert.AreEqual(mol.Atoms[0].GetBond(mol.Atoms[1]), mol.Bonds[0]); Assert.AreEqual(mol.Atoms[1].GetBond(mol.Atoms[2]), mol.Bonds[1]); Assert.IsNull(mol.Atoms[0].GetBond(mol.Atoms[2])); - } + } [TestMethod()]