Пример #1
0
        void Main()
        {
            IAtomContainer m = TestMoleculeFactory.MakeBenzene();

            // converter is thread-safe and can be used by multiple threads
            CDKToBeam c2g = new CDKToBeam();

            Beam.Graph g = c2g.ToBeamGraph(m);

            // get the SMILES notation from the Beam graph
            string smi = g.ToSmiles();
        }
Пример #2
0
        public void QuadrupleBond()
        {
            var mock_u = new Mock <IAtom>(); var u = mock_u.Object;
            var mock_v = new Mock <IAtom>(); var v = mock_v.Object;
            var b = new Bond(u, v, BondOrder.Quadruple);
            var o = new Dictionary <IAtom, int>()
            {
                [u] = 0,
                [v] = 1,
            };
            var c2g = new CDKToBeam();

            Assert.AreEqual(Beam.Bond.Quadruple.CreateEdge(0, 1), c2g.ToBeamEdge(b, o));
        }
Пример #3
0
        public void AromaticBond()
        {
            var mock_u = new Mock <IAtom>(); var u = mock_u.Object;
            var mock_v = new Mock <IAtom>(); var v = mock_v.Object;
            var b = new Bond(u, v)
            {
                IsAromatic = true
            };
            var o = new Dictionary <IAtom, int>()
            {
                [u] = 0,
                [v] = 1,
            };

            mock_u.SetupGet(n => n.IsAromatic).Returns(true);
            mock_v.SetupGet(n => n.IsAromatic).Returns(true);
            var c2g = new CDKToBeam();

            Assert.AreEqual(Beam.Bond.Aromatic.CreateEdge(0, 1), c2g.ToBeamEdge(b, o));
        }
Пример #4
0
        /// <summary>
        /// Creates a SMILES string of the flavour specified as a parameter
        /// and write the output order to the provided array.
        /// </summary>
        /// <remarks>
        /// The output order allows one to arrange auxiliary atom data in the
        /// order that a SMILES string will be read. A simple example is seen below
        /// where 2D coordinates are stored with a SMILES string. This method
        /// forms the basis of CXSMILES.
        /// </remarks>
        /// <example>
        /// <include file='IncludeExamples.xml' path='Comments/Codes[@id="NCDK.Smiles.SmilesGenerator_Example.cs+Create_IAtomContainer_int_int"]/*' />
        /// </example>
        /// <param name="molecule">the molecule to write</param>
        /// <param name="order">array to store the output order of atoms</param>
        /// <returns>the SMILES string</returns>
        /// <exception cref="CDKException">a valid SMILES could not be created</exception>
        public static string Create(IAtomContainer molecule, SmiFlavors flavour, int[] order)
        {
            try
            {
                if (order.Length != molecule.Atoms.Count)
                {
                    throw new ArgumentException("the array for storing output order should be the same length as the number of atoms");
                }

                var g = CDKToBeam.ToBeamGraph(molecule, flavour);

                // apply the canonical labelling
                if (SmiFlavorTool.IsSet(flavour, SmiFlavors.Canonical))
                {
                    // determine the output order
                    var labels = Labels(flavour, molecule);

                    g = g.Permute(labels);

                    if ((flavour & SmiFlavors.AtomAtomMapRenumber) == SmiFlavors.AtomAtomMapRenumber)
                    {
                        g = Functions.RenumberAtomMaps(g);
                    }

                    if (!SmiFlavorTool.IsSet(flavour, SmiFlavors.UseAromaticSymbols))
                    {
                        g = g.Resonate();
                    }

                    if (SmiFlavorTool.IsSet(flavour, SmiFlavors.StereoCisTrans))
                    {
                        // FIXME: required to ensure canonical double bond labelling
                        g.Sort(new Graph.VisitHighOrderFirst());

                        // canonical double-bond stereo, output be C/C=C/C or C\C=C\C
                        // and we need to normalise to one
                        g = Functions.NormaliseDirectionalLabels(g);

                        // visit double bonds first, prefer C1=CC=C1 to C=1C=CC1
                        // visit hydrogens first
                        g.Sort(new Graph.VisitHighOrderFirst()).Sort(new Graph.VisitHydrogenFirst());
                    }

                    var smiles = g.ToSmiles(order);

                    // the SMILES has been generated on a reordered molecule, transform
                    // the ordering
                    var canorder = new int[order.Length];
                    for (int i = 0; i < labels.Length; i++)
                    {
                        canorder[i] = order[labels[i]];
                    }
                    System.Array.Copy(canorder, 0, order, 0, order.Length);

                    if (SmiFlavorTool.IsSet(flavour, SmiFlavors.CxSmilesWithCoords))
                    {
                        smiles += CxSmilesGenerator.Generate(GetCxSmilesState(flavour, molecule), flavour, null, order);
                    }

                    return(smiles);
                }
                else
                {
                    string smiles = g.ToSmiles(order);

                    if (SmiFlavorTool.IsSet(flavour, SmiFlavors.CxSmilesWithCoords))
                    {
                        smiles += CxSmilesGenerator.Generate(GetCxSmilesState(flavour, molecule), flavour, null, order);
                    }

                    return(smiles);
                }
            }
            catch (IOException e)
            {
                throw new CDKException(e.Message);
            }
        }