Esempio n. 1
0
        public virtual void Or()
        {
            ICycleFinder   cf        = Cycles.Or(Cycles.AllSimpleFinder, Cycles.GetAllFinder(3));
            IAtomContainer fullerene = GetFullerene();

            CheckSize(cf.Find(fullerene, fullerene.Atoms.Count), 120);
        }
Esempio n. 2
0
 /// <summary>
 /// Internal method to wrap cycle computations which <i>should</i> be
 /// tractable. That is they currently won't throw the exception - if the
 /// method does throw an exception an internal error is triggered as a sanity
 /// check.
 /// </summary>
 /// <param name="finder">the cycle finding method</param>
 /// <param name="container">the molecule to find the cycles of</param>
 /// <param name="length">maximum size or cycle to find</param>
 /// <returns>the cycles of the molecule</returns>
 private static Cycles _invoke(ICycleFinder finder, IAtomContainer container, int length)
 {
     try
     {
         return(finder.Find(container, length));
     }
     catch (IntractableException e)
     {
         throw new IntractableException($"Cycle computation should not be intractable: {e.Message}");
     }
 }
Esempio n. 3
0
        /// <summary>
        /// ApplyAromaticity
        ///
        /// Mimics the CDKHuckelAromaticityDetector
        ///  Aromaticity aromaticity = new Aromaticity(ElectronDonation.cdk(),	Cycles.cdkAromaticSet());
        ///
        /// Mimics the DoubleBondAcceptingAromaticityDetector
        ///  Aromaticity aromaticity = new Aromaticity(ElectronDonation.cdkAllowingExocyclic(), Cycles.cdkAromaticSet());
        ///
        /// A good model for writing SMILES
        ///  Aromaticity aromaticity = new Aromaticity(ElectronDonation.daylight(), Cycles.all());
        ///
        /// A good model for writing MDL/Mol2
        ///  Aromaticity aromaticity = new Aromaticity(ElectronDonation.piBonds(), Cycles.all());
        ///
        /// </summary>
        /// <param name="mol"></param>
        /// <param name="electronDonation"></param>
        /// <param name="cycleFinder"></param>
        /// <returns></returns>

        public static bool ApplyAromaticity(
            IAtomContainer mol,
            ElectronDonation electronDonation,
            ICycleFinder cycleFinder)
        {
            Aromaticity aromaticity = new Aromaticity(electronDonation, cycleFinder);

            try
            {
                bool isAromatic = aromaticity.Apply(mol);
                return(isAromatic);
            }
            catch (Exception e)
            {
                string msg = e.Message;                 // cycle computation was intractable
                return(false);
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Filter any cycles produced by the <paramref name="primary"/> cycle finder and
 /// only allow those without a chord.
 /// </summary>
 /// <param name="primary">the primary cycle finder</param>
 internal Unchorded(ICycleFinder primary)
 {
     this.primary = primary;
 }
Esempio n. 5
0
 /// <summary>
 /// Create a fallback for two cycle finders.
 /// </summary>
 /// <param name="primary">the primary cycle finder</param>
 /// <param name="auxiliary">the auxiliary cycle finder</param>
 internal Fallback(ICycleFinder primary, ICycleFinder auxiliary)
 {
     this.primary   = primary;
     this.auxiliary = auxiliary;
 }
Esempio n. 6
0
 /// <summary>
 /// Internal method to wrap cycle computations which <i>should</i> be
 /// tractable. That is they currently won't throw the exception - if the
 /// method does throw an exception an internal error is triggered as a sanity
 /// check.
 /// </summary>
 /// <param name="finder">the cycle finding method</param>
 /// <param name="container">the molecule to find the cycles of</param>
 /// <returns>the cycles of the molecule</returns>
 private static Cycles _invoke(ICycleFinder finder, IAtomContainer container)
 {
     return(_invoke(finder, container, container.Atoms.Count));
 }
Esempio n. 7
0
 /// <summary>
 /// Derive a new cycle finder that only provides cycles without a chord.
 /// </summary>
 /// <param name="original">find the initial cycles before filtering</param>
 /// <returns>cycles or the original without chords</returns>
 public static ICycleFinder GetUnchorded(ICycleFinder original)
 {
     return(new Unchorded(original));
 }
Esempio n. 8
0
 /// <summary>
 /// Use an auxiliary cycle finder if the primary method was intractable.
 /// </summary>
 /// <example>
 /// <include file='IncludeExamples.xml' path='Comments/Codes[@id="NCDK.Graphs.Cycles_Example.cs+Or6"]/*' />
 /// It is possible to nest multiple levels.
 /// <include file='IncludeExamples.xml' path='Comments/Codes[@id="NCDK.Graphs.Cycles_Example.cs+OrARE"]/*' />
 /// </example>
 /// <param name="primary">primary cycle finding method</param>
 /// <param name="auxiliary">auxiliary cycle finding method if the primary failed</param>
 /// <returns>a new cycle finder</returns>
 public static ICycleFinder Or(ICycleFinder primary, ICycleFinder auxiliary)
 {
     return(new Fallback(primary, auxiliary));
 }
Esempio n. 9
0
 /// <summary>
 /// Create an aromaticity model using the specified electron donation
 /// <paramref name="model"/> which is tested on the <paramref name="cycles"/>. The <paramref name="model"/> defines
 /// how many π-electrons each atom may contribute to an aromatic system. The
 /// <paramref name="cycles"/> defines the <see cref="ICycleFinder"/> which is used to find
 /// cycles in a molecule. The total electron donation from each atom in each
 /// cycle is counted and checked. If the electron contribution is equal to
 /// "4n + 2" for a "n &gt;= 0" then the cycle is considered
 /// aromatic.
 /// </summary>
 /// <remarks>
 /// Changing the electron contribution model or which cycles
 /// are tested affects which atoms/bonds are found to be aromatic. There are
 /// several <see cref="ElectronDonation"/> models and <see cref="Cycles"/>
 /// available. A good choice for the cycles
 /// is to use <see cref="Cycles.AllSimpleFinder()"/> falling back to
 /// <see cref="Cycles.RelevantFinder"/> on failure. Finding all cycles is very
 /// fast but may produce an exponential number of cycles. It is therefore not
 /// feasible for complex fused systems and an exception is thrown.
 /// In such cases the aromaticity can either be skipped or a simpler
 /// polynomial cycle set <see cref="Cycles.RelevantFinder"/> used.
 /// </remarks>
 /// <example>
 /// <include file='IncludeExamples.xml' path='Comments/Codes[@id="NCDK.Aromaticities.Aromaticity_Example.cs+ctor"]/*' />
 /// </example>
 /// <param name="model"></param>
 /// <param name="cycles"></param>
 /// <seealso cref="ElectronDonation"/>
 /// <seealso cref="Cycles"/>
 public Aromaticity(ElectronDonation model, ICycleFinder cycles)
 {
     this.model  = model ?? throw new ArgumentNullException(nameof(model));
     this.cycles = cycles ?? throw new ArgumentNullException(nameof(cycles));
 }
Esempio n. 10
0
        public void Main()
        {
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region AllSimpleFinder
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // handle error - note it is common that finding all simple cycles in chemical graphs is intractable
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region MCB
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - MCB should never be intractable
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region Relevant
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - there may be an exponential number of cycles but this is not currently checked
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region Essential
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - essential cycles do not check tractability
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region TripletShort
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - triple short cycles do not check tractability
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region VertexShort
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - vertex short cycles do not check tractability
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region EdgeShort
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - edge short cycles do not check tractability
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region CDKAromaticSetFinder
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - edge short cycles do not check tractability
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region AllOrVertexShortFinder
                ICycleFinder cf = Cycles.AllSimpleFinder;
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = cf.Find(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // ignore error - edge short cycles do not check tractability
                    }
                }
                #endregion
            }

            {
                #region Or6
                // all cycles or all cycles size <= 6
                ICycleFinder cf = Cycles.Or(Cycles.AllSimpleFinder, Cycles.GetAllFinder(6));
                #endregion
            }
            {
                #region OrARE
                // all cycles or relevant or essential
                ICycleFinder cf = Cycles.Or(Cycles.AllSimpleFinder, Cycles.Or(Cycles.RelevantFinder, Cycles.EssentialFinder));
                #endregion
            }

            {
                IChemObjectSet <IAtomContainer> containers = null;
                #region FindAll
                foreach (var container in containers)
                {
                    try
                    {
                        Cycles   cycles = Cycles.FindAll(container);
                        IRingSet rings  = cycles.ToRingSet();
                    }
                    catch (IntractableException)
                    {
                        // handle error - note it is common that finding all simple cycles in chemical graphs is intractable
                    }
                }
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                IAtomContainer container = null;
                #region FindMCB
                Cycles   cycles = Cycles.FindMCB(container);
                IRingSet rings  = cycles.ToRingSet();
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                IAtomContainer container = null;
                #region FindSSSR
                Cycles   cycles = Cycles.FindSSSR(container);
                IRingSet rings  = cycles.ToRingSet();
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                IAtomContainer container = null;
                #region FindRelevant
                Cycles   cycles = Cycles.FindRelevant(container);
                IRingSet rings  = cycles.ToRingSet();
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                IAtomContainer container = null;
                #region FindEssential
                Cycles   cycles = Cycles.FindEssential(container);
                IRingSet rings  = cycles.ToRingSet();
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                IAtomContainer container = null;
                #region FindTripletShort
                Cycles   cycles = Cycles.FindTripletShort(container);
                IRingSet rings  = cycles.ToRingSet();
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                IAtomContainer container = null;
                #region FindVertexShort
                Cycles   cycles = Cycles.FindVertexShort(container);
                IRingSet rings  = cycles.ToRingSet();
                #endregion
            }
            {
                IChemObjectSet <IAtomContainer> containers = null;
                IAtomContainer container = null;
                #region FindEdgeShort
                Cycles   cycles = Cycles.FindEdgeShort(container);
                IRingSet rings  = cycles.ToRingSet();
                #endregion
            }
        }
Esempio n. 11
0
        public static void Main(string[] args)
        {
            {
                var molecules = new Silent.AtomContainerSet();
                #region
                ElectronDonation model       = ElectronDonation.DaylightModel;
                ICycleFinder     cycles      = Cycles.Or(Cycles.AllSimpleFinder, Cycles.GetAllFinder(6));
                Aromaticity      aromaticity = new Aromaticity(model, cycles);

                // apply our configured model to each molecule
                foreach (IAtomContainer molecule in molecules)
                {
                    aromaticity.Apply(molecule);
                }
                #endregion
            }
            {
                #region ctor
                // mimics the CDKHuckelAromaticityDetector
                Aromaticity aromaticity_cdk = new Aromaticity(ElectronDonation.CDKModel, Cycles.CDKAromaticSetFinder);
                // mimics the DoubleBondAcceptingAromaticityDetector
                Aromaticity aromaticity_exo = new Aromaticity(ElectronDonation.CDKAllowingExocyclicModel, Cycles.CDKAromaticSetFinder);
                // a good model for writing SMILES
                Aromaticity aromaticity_smi = new Aromaticity(ElectronDonation.DaylightModel, Cycles.AllSimpleFinder);
                // a good model for writing MDL/Mol2
                Aromaticity aromaticity_mdl = new Aromaticity(ElectronDonation.PiBondsModel, Cycles.AllSimpleFinder);
                #endregion
            }
            {
                #region FindBonds
                Aromaticity    aromaticity = new Aromaticity(ElectronDonation.CDKModel, Cycles.AllSimpleFinder);
                IAtomContainer container   = TestMoleculeFactory.MakeAnthracene();
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(container);
                try
                {
                    var bonds          = aromaticity.FindBonds(container);
                    int nAromaticBonds = bonds.Count();
                }
                catch (CDKException)
                {
                    // cycle computation was intractable
                }
                #endregion
            }
            {
                #region Apply
                Aromaticity    aromaticity = new Aromaticity(ElectronDonation.CDKModel, Cycles.AllSimpleFinder);
                IAtomContainer container   = TestMoleculeFactory.MakeAnthracene();
                try
                {
                    if (aromaticity.Apply(container))
                    {
                        //
                    }
                }
                catch (CDKException)
                {
                    // cycle computation was intractable
                }
                #endregion
            }
            {
                #region CDKLegacy_CDKAromaticSetFinder
                new Aromaticity(ElectronDonation.CDKModel, Cycles.CDKAromaticSetFinder);
                #endregion
            }
            {
                #region CDKLegacy_AllFinder_RelevantFinder
                new Aromaticity(ElectronDonation.CDKModel, Cycles.Or(Cycles.AllSimpleFinder, Cycles.RelevantFinder));
                #endregion
            }
        }