public void DecodeCoordinates()
 {
     Vector2[] points = IdentityTemplateLibrary.DecodeCoordinates("12.5, 5.5, 4, 2");
     Assert.AreEqual(2, points.Length);
     Assert.AreEqual(12.5, points[0].X, 0.01);
     Assert.AreEqual(5.5, points[0].Y, 0.01);
     Assert.AreEqual(4, points[1].X, 0.01);
     Assert.AreEqual(2, points[1].Y, 0.01);
 }
Exemple #2
0
        /// <summary>
        /// Convert to an identity template library.
        /// </summary>
        /// <returns>identity template library</returns>
        internal IdentityTemplateLibrary ToIdentityTemplateLibrary()
        {
            var lib = IdentityTemplateLibrary.Empty();

            foreach (var mol in templates)
            {
                lib.Add(AtomContainerManipulator.Anonymise(mol));
            }
            return(lib);
        }
        public void EncodeEntry()
        {
            var smiles = "CO";

            Vector2[] points  = new Vector2[] { new Vector2(12.5f, 5.5f), new Vector2(4f, 2f) };
            string    encoded = IdentityTemplateLibrary.EncodeEntry(new KeyValuePair <string, Vector2[]>(smiles, points));
            var       entry   = IdentityTemplateLibrary.DecodeEntry(encoded);

            Assert.AreEqual("CO |(12.5,5.5,;4,2,)|", encoded);
        }
Exemple #4
0
 /// <summary>
 /// Add one template library to another.
 /// </summary>
 /// <param name="library">another template library</param>
 /// <returns>this library with the other one added in (allows chaining)</returns>
 public IdentityTemplateLibrary Add(IdentityTemplateLibrary library)
 {
     foreach (var e in library.templateMap)
     {
         foreach (var v in e.Value)
         {
             this.templateMap.Add(e.Key, v);
         }
     }
     return(this);
 }
        public void Store()
        {
            IdentityTemplateLibrary lib = IdentityTemplateLibrary.Empty();

            lib.Add(IdentityTemplateLibrary.DecodeEntry("[C][C][O] 0, 1, 2, 3, 4, 5"));
            lib.Add(IdentityTemplateLibrary.DecodeEntry("[C][C] 0, 1, 2, 3"));
            using (var baos = new MemoryStream())
            {
                lib.Store(baos);
                Assert.AreEqual(
                    "[C][C][O] |(0,1,;2,3,;4,5,)|\n[C][C] |(0,1,;2,3,)|\n",
                    Encoding.UTF8.GetString(baos.ToArray()));
            }
        }
        public void AssignEthanolNoEntry()
        {
            IAtomContainer container = new AtomContainer();

            container.Atoms.Add(new Atom("O"));
            container.Atoms.Add(new Atom("C"));
            container.Atoms.Add(new Atom("C"));
            container.Atoms[0].ImplicitHydrogenCount = 0;
            container.Atoms[1].ImplicitHydrogenCount = 0;
            container.Atoms[2].ImplicitHydrogenCount = 0;
            container.AddBond(container.Atoms[0], container.Atoms[1], BondOrder.Single);
            container.AddBond(container.Atoms[1], container.Atoms[2], BondOrder.Single);

            Assert.IsFalse(IdentityTemplateLibrary.Empty().AssignLayout(container));
        }
Exemple #7
0
 /// <summary>
 /// Load a template library from an input stream.
 /// </summary>
 /// <returns>loaded template library</returns>
 /// <exception cref="IOException">low level IO error</exception>
 public static IdentityTemplateLibrary Load(Stream ins)
 {
     using (var br = new StreamReader(ins))
     {
         string line    = null;
         var    library = new IdentityTemplateLibrary();
         while ((line = br.ReadLine()) != null)
         {
             // skip comments
             if (line[0] == '#')
             {
                 continue;
             }
             library.Add(DecodeEntry(line));
         }
         return(library);
     }
 }
        public void AssignEthanol()
        {
            IAtomContainer container = new AtomContainer();

            container.Atoms.Add(new Atom("O"));
            container.Atoms.Add(new Atom("C"));
            container.Atoms.Add(new Atom("C"));
            container.Atoms[0].ImplicitHydrogenCount = 0;
            container.Atoms[1].ImplicitHydrogenCount = 0;
            container.Atoms[2].ImplicitHydrogenCount = 0;
            container.AddBond(container.Atoms[0], container.Atoms[1], BondOrder.Single);
            container.AddBond(container.Atoms[1], container.Atoms[2], BondOrder.Single);

            IdentityTemplateLibrary lib = IdentityTemplateLibrary.Empty();

            lib.Add(IdentityTemplateLibrary.DecodeEntry("OCC 4, 5, 2, 3, 0, 1"));
            Assert.IsTrue(lib.AssignLayout(container));
            Assert.AreEqual(4, container.Atoms[0].Point2D.Value.X, 0.01);
            Assert.AreEqual(5, container.Atoms[0].Point2D.Value.Y, 0.01);
            Assert.AreEqual(2, container.Atoms[1].Point2D.Value.X, 0.01);
            Assert.AreEqual(3, container.Atoms[1].Point2D.Value.Y, 0.01);
            Assert.AreEqual(0, container.Atoms[2].Point2D.Value.X, 0.01);
            Assert.AreEqual(1, container.Atoms[2].Point2D.Value.Y, 0.01);
        }