예제 #1
0
        public void Hydrate()
        {
            var tokens = new List <string>();

            AbbreviationLabel.Parse("•H2O", tokens);
            Assert.IsTrue(tokens.SequenceEqual(new string[] { "•", "H2", "O" }));
        }
예제 #2
0
        public void NonAbbreviationLabel()
        {
            var tokens = new List <string>();

            Assert.IsFalse(AbbreviationLabel.Parse("A Random Label - Don't Reverse", tokens));
            Assert.AreEqual(1, tokens.Count);
        }
예제 #3
0
        public void ReversingBracketsWithNumbers()
        {
            List <string> tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("B(OH)2", tokens));
            AbbreviationLabel.Reverse(tokens);
            Assert.AreEqual("(HO)2B", string.Join("", tokens));
        }
예제 #4
0
        public void ReversingBrackets()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("N(CH2CH2O)CH2", tokens));
            AbbreviationLabel.Reverse(tokens);
            Assert.AreEqual("H2C(OH2CH2C)N", string.Join("", tokens));
        }
예제 #5
0
        public void ParseBrackets()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("N(CH2CH2O)CH2", tokens));
            Assert.AreEqual(10, tokens.Count);
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(new[] { "N", "(", "C", "H2", "C", "H2", "O", ")", "C", "H2" }, tokens));
        }
예제 #6
0
        public void CO2Et()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("CO2Et", tokens));
            Assert.AreEqual(3, tokens.Count);
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(new[] { "C", "O2", "Et" }, tokens));
        }
예제 #7
0
        public void Triphenylmethyl()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("CPh3", tokens));
            Assert.AreEqual(2, tokens.Count);
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(new[] { "C", "Ph3" }, tokens));
        }
예제 #8
0
        public void Peglinker()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("CH2CH2OCH2CH2O", tokens));
            Assert.AreEqual(10, tokens.Count);
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(new[] { "C", "H2", "C", "H2", "O", "C", "H2", "C", "H2", "O" }, tokens));
        }
예제 #9
0
        public void Carboxylate()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("COO-", tokens));
            Assert.AreEqual(4, tokens.Count);
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(new[] { "C", "O", "O", "-" }, tokens));
        }
예제 #10
0
        public void ParseFeacac3()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("Fe(acac)3", tokens));
            Assert.AreEqual(5, tokens.Count);
            Assert.IsTrue(Compares.AreOrderLessDeepEqual(new[] { "Fe", "(", "acac", ")", "3" }, tokens));
        }
예제 #11
0
        public void ReversingFormatPOOHOEt()
        {
            List <string> tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("PO(OH)OEt", tokens));
            AbbreviationLabel.Reverse(tokens);
            AbbreviationLabel.Format(tokens);
            Assert.AreEqual("EtO(HO)OP", string.Join("", tokens));
        }
예제 #12
0
        public void FormatTBu()
        {
            var tokens = new[] { "tBu" };
            List <AbbreviationLabel.FormattedText> texts = AbbreviationLabel.Format(tokens);

            Assert.AreEqual(2, texts.Count);
            Assert.AreEqual("t", texts[0].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_ITALIC, texts[0].Style);
            Assert.AreEqual("Bu", texts[1].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, texts[1].Style);
        }
예제 #13
0
        public void Tertbutyls()
        {
            var tokens = new List <string>(1);

            foreach (var str in new[] { "tBu", "tertBu", "t-Bu", "t-Butyl", "tertButyl" })
            {
                tokens.Clear();
                Assert.IsTrue(AbbreviationLabel.Parse(str, tokens), str);
                Assert.AreEqual(1, tokens.Count);
            }
        }
예제 #14
0
        public void FormatFeacac3()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("Fe(acac)3", tokens));
            List <AbbreviationLabel.FormattedText> formatted = AbbreviationLabel.Format(tokens);

            Assert.AreEqual("Fe(acac)", formatted[0].Text);
            Assert.AreEqual(0, formatted[0].Style);
            Assert.AreEqual("3", formatted[1].Text);
            Assert.AreEqual(-1, formatted[1].Style);
        }
예제 #15
0
        public AtomSymbol GenerateAbbreviatedSymbol(string label, HydrogenPosition position)
        {
            var tokens = new List <string>();

            if (AbbreviationLabel.Parse(label, tokens))
            {
                return(GenerateAbbreviationSymbol(tokens, position));
            }
            else
            {
                return(new AtomSymbol(new TextOutline(label, font, emSize), Array.Empty <TextOutline>()));
            }
        }
예제 #16
0
        public void FormatOPO3()
        {
            var tokens = new[] { "O", "P", "O3", "-2" };
            var texts  = AbbreviationLabel.Format(tokens);

            Assert.AreEqual(3, texts.Count);
            Assert.AreEqual("OPO", texts[0].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, texts[0].Style);
            Assert.AreEqual("3", texts[1].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_SUBSCRIPT, texts[1].Style);
            Assert.AreEqual("2−", texts[2].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_SUPSCRIPT, texts[2].Style);
        }
예제 #17
0
        public void FormatOPO3H2()
        {
            var tokens = new[] { "O", "P", "O3", "H2" };
            List <AbbreviationLabel.FormattedText> texts = AbbreviationLabel.Format(tokens);

            Assert.AreEqual(4, texts.Count);
            Assert.AreEqual("OPO", texts[0].Text);
            Assert.AreEqual(0, texts[0].Style);
            Assert.AreEqual("3", texts[1].Text);
            Assert.AreEqual(-1, texts[1].Style);
            Assert.AreEqual("H", texts[2].Text);
            Assert.AreEqual(0, texts[2].Style);
            Assert.AreEqual("2", texts[3].Text);
            Assert.AreEqual(-1, texts[3].Style);
        }
예제 #18
0
        public void FormatRubpy3Cl2()
        {
            var tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("Ru(bpy)3Cl2", tokens));
            var formatted = AbbreviationLabel.Format(tokens);

            AbbreviationLabel.Reduce(formatted, 0, formatted.Count);
            Assert.AreEqual("Ru(bpy)", formatted[0].Text);
            Assert.AreEqual(0, formatted[0].Style);
            Assert.AreEqual("3", formatted[1].Text);
            Assert.AreEqual(-1, formatted[1].Style);
            Assert.AreEqual("Cl", formatted[2].Text);
            Assert.AreEqual(0, formatted[2].Style);
            Assert.AreEqual("2", formatted[3].Text);
            Assert.AreEqual(-1, formatted[3].Style);
        }
예제 #19
0
        public void NEt3DotHCl()
        {
            List <string> tokens = new List <string>();

            Assert.IsTrue(AbbreviationLabel.Parse("NEt3·HCl", tokens));
            Assert.AreEqual(5, tokens.Count);
            Assert.AreEqual("N", tokens[0]);
            Assert.AreEqual("Et3", tokens[1]);
            Assert.AreEqual("·", tokens[2]);
            Assert.AreEqual("H", tokens[3]);
            Assert.AreEqual("Cl", tokens[4]);
            List <AbbreviationLabel.FormattedText> formatted = AbbreviationLabel.Format(tokens);

            AbbreviationLabel.Reduce(formatted, 0, formatted.Count);
            Assert.AreEqual(3, formatted.Count);
            Assert.AreEqual("NEt", formatted[0].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, formatted[0].Style);
            Assert.AreEqual("3", formatted[1].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_SUBSCRIPT, formatted[1].Style);
            Assert.AreEqual("·HCl", formatted[2].Text);
            Assert.AreEqual(AbbreviationLabel.STYLE_NORMAL, formatted[2].Style);
        }
예제 #20
0
 public void NonAsciiLabel()
 {
     // phenyl
     Assert.IsFalse(AbbreviationLabel.Parse("苯基", new List <string>()));
 }
예제 #21
0
 public void ParseNumberOnly()
 {
     Assert.IsFalse(AbbreviationLabel.Parse("1", new List <string>()));
 }
예제 #22
0
 public void ParseChargeOnly()
 {
     Assert.IsFalse(AbbreviationLabel.Parse("+", new List <string>()));
 }
예제 #23
0
 public void Het()
 {
     // 'Het' not 'He'lium and 't'erts
     Assert.IsFalse(AbbreviationLabel.Parse("Het", new List <string>()));
 }
예제 #24
0
        /// <summary>
        /// Generate a formatted abbreviation AtomSymbol for the given Hydrogen position.
        /// </summary>
        /// <param name="tokens">the parsed tokens</param>
        /// <param name="position">hydrogen position - determines if we reverse the label</param>
        /// <returns>the generated symbol</returns>
        public AtomSymbol GenerateAbbreviationSymbol(List <string> tokens, HydrogenPosition position)
        {
            if (position == HydrogenPosition.Left)
            {
                AbbreviationLabel.Reverse(tokens);
            }

            var tmpRefPoint = new TextOutline("H", font, emSize);
            var fTexts      = AbbreviationLabel.Format(tokens);

            var italicFont = new Typeface(font.FontFamily, FontStyles.Italic, font.Weight, font.Stretch);

            var outlines = new List <TextOutline>(fTexts.Count);

            foreach (var fText in fTexts)
            {
                var outline = fText.Style == AbbreviationLabel.STYLE_ITALIC
                            ? new TextOutline(fText.Text, italicFont, emSize)
                            : new TextOutline(fText.Text, font, emSize);

                // resize and position scripts
                if (fText.Style == AbbreviationLabel.STYLE_SUBSCRIPT)
                {
                    outline = outline.Resize(scriptSize, scriptSize);
                    outline = PositionSubscript(tmpRefPoint, outline);
                }
                else if (fText.Style == AbbreviationLabel.STYLE_SUPSCRIPT)
                {
                    outline = outline.Resize(scriptSize, scriptSize);
                    outline = PositionSuperscript(tmpRefPoint, outline);
                }

                outlines.Add(outline);
            }

            // position the outlines relative to each other
            for (int i = 1; i < outlines.Count; i++)
            {
                var ref_ = outlines[i - 1];
                var curr = outlines[i];
                // charge aligns to symbol not a subscript part
                if (fTexts[i].Style == AbbreviationLabel.STYLE_SUPSCRIPT &&
                    fTexts[i - 1].Style == AbbreviationLabel.STYLE_SUBSCRIPT && i > 1)
                {
                    ref_ = outlines[i - 2];
                }
                outlines[i] = PositionAfter(ref_, curr);
            }

            // find symbol where we want to attach the bond
            // this becomes the primary outline
            int index;

            if (position == HydrogenPosition.Left)
            {
                for (index = outlines.Count - 1; index >= 0; index--)
                {
                    if ((fTexts[index].Style & 0x1) == 0)
                    {
                        break;
                    }
                }
            }
            else
            {
                for (index = 0; index < outlines.Count; index++)
                {
                    if ((fTexts[index].Style & 0x1) == 0)
                    {
                        break;
                    }
                }
            }
            var primary = outlines[index];

            outlines.RemoveAt(index);

            return(new AtomSymbol(primary, outlines));
        }