static void Test(string delocalised, string localised) { Graph g = Graph.FromSmiles(delocalised); Graph h = Localise.GenerateLocalise(g); Assert.AreEqual(localised, h.ToSmiles()); //fixed Beam }
public static Graph LocaliseInPlace(Graph delocalised) { // nothing to do, return fast if (delocalised.GetFlags(Graph.HAS_AROM) == 0) { return(delocalised); } BitArray aromatic = new BitArray(delocalised.Order); BitArray subset = BuildSet(delocalised, aromatic); if (HasOddCardinality(subset)) { throw new InvalidSmilesException("a valid kekulé structure could not be assigned"); } return(Localise.GenerateKekuleForm(delocalised, subset, aromatic, true)); }
[TestMethod()] public void SmallRingTest_linked() { Graph g = Graph.FromSmiles("C1CCC(CC1)=C1CCCCC1"); Assert.IsFalse(Localise.InSmallRing(g, g.CreateEdge(3, 6))); }
[TestMethod()] public void SmallRingTest_7() { Graph g = Graph.FromSmiles("C1CCCCCC1"); Assert.IsTrue(Localise.InSmallRing(g, g.CreateEdge(0, 1))); }
/// <summary> /// Localise delocalized (aromatic) bonds in this molecule producing the Kekulé form. /// </summary> /// <remarks> /// The original graph is not modified. /// <code> /// Graph furan = Graph.FromSmiles("o1cccc1"); /// </code> /// If the graph could not be converted to a kekulé representation then a /// checked exception is thrown. Graphs cannot be converted if their /// structures are erroneous and there is no valid way to assign the /// delocalised electrons. /// <para> /// Some reasons are shown below. /// <list type="bullet"> /// <item> /// <term>n1cncc1</term> /// <description>pyrole (incorrect) could be either C1C=NC=N1 or N1C=CN=C1</description> /// </item> /// <item> /// <term>[Hg+2][c-]1ccccc1</term> /// <description>Mercury(2+) ion benzenide (incorrect)</description> /// </item> /// <item> /// <term>[Hg+2].[c-]1ccccc1</term> /// <description>Mercury(2+) ion benzenide (correct)</description> /// </item> /// </list> /// </para> /// </remarks> /// <returns>kekulé representation</returns> /// <exception cref="InvalidSmilesException">molecule exploded on contact with reality</exception>" public Graph Kekule() { return(Localise.LocaliseInPlace(this)); }
/// <summary> /// Resonate bond assignments in conjugate rings such that two SMILES with /// the same Ordering have the same kekulé assignment. /// </summary> /// <returns>(self) - the graph is mutated</returns> public Graph Resonate() { return(Localise.Resonate(this)); }
/// <summary> /// Utility method to verify electrons can be assigned. /// </summary> /// <param name="g">graph to check</param> /// <returns>electrons could be assigned to delocalised structure</returns> public static bool Verify(Graph g) { return(g.GetFlags(Graph.HAS_AROM) == 0 || !ContainsOddCardinalitySubgraph(g, Localise.BuildSet(g, new BitArray(g.Order)))); }