Ejemplo n.º 1
0
        public void TestExampleStructure2InchiAlanine()
        {
            // START SNIPPET: structure2inchi-alanine
            // Example input - 0D D-Alanine
            NInchiInput input = new NInchiInput();
            //
            // Generate atoms
            NInchiAtom a1 = input.Add(new NInchiAtom(0.0, 0.0, 0.0, "C"));
            NInchiAtom a2 = input.Add(new NInchiAtom(0.0, 0.0, 0.0, "C"));
            NInchiAtom a3 = input.Add(new NInchiAtom(0.0, 0.0, 0.0, "N"));
            NInchiAtom a4 = input.Add(new NInchiAtom(0.0, 0.0, 0.0, "C"));
            NInchiAtom a5 = input.Add(new NInchiAtom(0.0, 0.0, 0.0, "O"));
            NInchiAtom a6 = input.Add(new NInchiAtom(0.0, 0.0, 0.0, "O"));
            NInchiAtom a7 = input.Add(new NInchiAtom(0.0, 0.0, 0.0, "H"));

            a3.ImplicitH = 2;
            a4.ImplicitH = 3;
            a5.ImplicitH = 1;
            //
            // Add bonds
            input.Add(new NInchiBond(a1, a2, INCHI_BOND_TYPE.Single));
            input.Add(new NInchiBond(a1, a3, INCHI_BOND_TYPE.Single));
            input.Add(new NInchiBond(a1, a4, INCHI_BOND_TYPE.Single));
            input.Add(new NInchiBond(a2, a5, INCHI_BOND_TYPE.Single));
            input.Add(new NInchiBond(a2, a6, INCHI_BOND_TYPE.Double));
            input.Add(new NInchiBond(a1, a7, INCHI_BOND_TYPE.Single));
            //
            // Add stereo parities
            input.Stereos.Add(NInchiStereo0D
                              .CreateNewTetrahedralStereo0D(a1, a3, a4, a7, a2, INCHI_PARITY.Even));
            //
            NInchiOutput output = NInchiWrapper.GetInchi(input);
            // END SNIPPET: structure2inchi-alanine
        }
Ejemplo n.º 2
0
        /// <summary>
        /// <para>Converts an InChI into an InChI for validation purposes (the same as the -InChI2InChI option).</para>
        /// <para>This method may also be used to filter out specific layers. For instance, /Snon would remove the
        /// stereochemical layer; Omitting /FixedH and/or /RecMet would remove Fixed-H or Reconnected layers.
        /// In order to keep all InChI layers use options string "/FixedH /RecMet"; option /InChI2InChI is not needed.</para>
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static NInchiOutput GetInchiFromInchi(NInchiInputInchi input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input), "Null input");
            }

            var native_input = new Inchi_InputINCHI();

            var szInChI   = Marshal.StringToHGlobalAnsi(input.Inchi);
            var szOptions = Marshal.StringToHGlobalAnsi(input.Options);

            try
            {
                native_input.szInChI   = szInChI;
                native_input.szOptions = szOptions;

                var native_output = new Inchi_Output();

                var ret = GetINCHIfromINCHI(ref native_input, out native_output);

                NInchiOutput oo = ToInchiOutput(ret, native_output);
                FreeStdINCHI(ref native_output);
                return(oo);
            }
            finally
            {
                Marshal.FreeHGlobal(szOptions);
                Marshal.FreeHGlobal(szInChI);
            }
        }
Ejemplo n.º 3
0
 public void TestInchi2InchiHydrogen()
 {
     // START SNIPPET: inchi2inchi-hydrogen
     // Input InChI with fixed-hydrogen layer
     string inchiIn = "InChI=1/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/"
                      + "t2-/m0/s1/f/h5H";
     //
     NInchiOutput output = NInchiWrapper.GetInchiFromInchi(
         new NInchiInputInchi(inchiIn));
     string inchiOut = output.InChI;
     // Output InChI:
     //   InChI=1/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)/t2-/m0/s1
     // END SNIPPET: inchi2inchi-hydrogen
 }
Ejemplo n.º 4
0
 public void TestInchi2InchiCompress()
 {
     // START SNIPPET: inchi2inchi-compress
     string inchi = "InChI=1/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)";
     //
     // Compress InChI
     NInchiOutput cout = NInchiWrapper.GetInchiFromInchi(
         new NInchiInputInchi(inchi, "-compress"));
     string compressedInchi = cout.InChI;
     // compressedInchi = InChI=1/C3H7NO2/cABBCC/hB1D2A3,1EF
     //
     // Uncompress InChI
     NInchiOutput ucout = NInchiWrapper.GetInchiFromInchi(
         new NInchiInputInchi(compressedInchi));
     string uncompressedInchi = ucout.InChI;
     // uncompressedInchi = InChI=1/C3H7NO2/c1-2(4)3(5)6/h2H,4H2,1H3,(H,5,6)
     // END SNIPPET: inchi2inchi-compress
 }
Ejemplo n.º 5
0
        public void TestExampleStructure2InchiDiChloroethene()
        {
            // START SNIPPET: structure2inchi-dichloroethene
            // Example input - 2D E-1,2-dichloroethene
            NInchiInput input = new NInchiInput();
            //
            // Generate atoms
            NInchiAtom a1 = input.Add(new NInchiAtom(2.866, -0.250, 0.000, "C"));
            NInchiAtom a2 = input.Add(new NInchiAtom(3.732, 0.250, 0.000, "C"));
            NInchiAtom a3 = input.Add(new NInchiAtom(2.000, 2.500, 0.000, "Cl"));
            NInchiAtom a4 = input.Add(new NInchiAtom(4.598, -0.250, 0.000, "Cl"));

            a1.ImplicitH = 1;
            a2.ImplicitH = 1;
            //
            // Add bond
            input.Add(new NInchiBond(a1, a2, INCHI_BOND_TYPE.Double));
            input.Add(new NInchiBond(a1, a3, INCHI_BOND_TYPE.Single));
            input.Add(new NInchiBond(a2, a4, INCHI_BOND_TYPE.Single));
            NInchiOutput output = NInchiWrapper.GetInchi(input);
            //END SNIPPET: structure2inchi - dichloroethene
        }
Ejemplo n.º 6
0
        /// <summary>
        /// <para>Calculates the Standard InChI string for a chemical structure.</para>
        /// <para>The only valid structure perception options are NEWPSOFF/DoNotAddH/SNon. In any other structural
        /// perception options are specified then the calculation will fail.</para>
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static NInchiOutput GetStdInchi(NInchiInput input)
        {
            if (input == null)
            {
                throw new ArgumentNullException(nameof(input), "Null input");
            }

            var prep = InitInchiInput(input);

            fixed(Inchi_Atom *atoms = prep.atoms)
            fixed(Inchi_Stereo0D * stereos = prep.stereos)
            {
                Inchi_Input  native_input  = new Inchi_Input();
                Inchi_Output native_output = new Inchi_Output();

                native_input.atom         = new IntPtr(atoms);
                native_input.num_atoms    = (Int16)input.Atoms.Count;
                native_input.stereo0D     = new IntPtr(stereos);
                native_input.num_stereo0D = (Int16)input.Stereos.Count;

                var szOptions = Marshal.StringToHGlobalAnsi(input.Options);

                try
                {
                    native_input.szOptions = szOptions;

                    var          ret = GetStdINCHI(ref native_input, out native_output);
                    NInchiOutput oo  = ToInchiOutput(ret, native_output);
                    FreeStdINCHI(ref native_output);

                    return(oo);
                }
                finally
                {
                    Marshal.FreeHGlobal(szOptions);
                }
            }
        }
Ejemplo n.º 7
0
        public void TestGetLog()
        {
            NInchiOutput output = new NInchiOutput(InChIReturnCode.Unknown, null, null, null, "Test log");

            Assert.AreEqual("Test log", output.Log);
        }
Ejemplo n.º 8
0
        public void TestGetMessage()
        {
            NInchiOutput output = new NInchiOutput(InChIReturnCode.Unknown, null, null, "Test message", null);

            Assert.AreEqual("Test message", output.Message);
        }
Ejemplo n.º 9
0
        public void TestGetAuxInfo()
        {
            NInchiOutput output = new NInchiOutput(InChIReturnCode.Unknown, null, "AuxInfo=1/0/N:1,2,6,3,5,4/E:(1,2,3,4,5,6)/rA:6nCCCCCC/rB:d1;s2;d3;s4;s1d5;/rC:-.7145,.4125,0;-.7145,-.4125,0;0,-.825,0;.7145,-.4125,0;.7145,.4125,0;0,.825,0;", null, null);

            Assert.AreEqual("AuxInfo=1/0/N:1,2,6,3,5,4/E:(1,2,3,4,5,6)/rA:6nCCCCCC/rB:d1;s2;d3;s4;s1d5;/rC:-.7145,.4125,0;-.7145,-.4125,0;0,-.825,0;.7145,-.4125,0;.7145,.4125,0;0,.825,0;", output.AuxInfo);
        }
Ejemplo n.º 10
0
        public void TestGetInchi()
        {
            NInchiOutput output = new NInchiOutput(InChIReturnCode.Unknown, "Inchi=1/C6H6/c1-2-4-6-5-3-1/h1-6H", null, null, null);

            Assert.AreEqual("Inchi=1/C6H6/c1-2-4-6-5-3-1/h1-6H", output.InChI);
        }
Ejemplo n.º 11
0
        public void TestGetReturnStatus()
        {
            NInchiOutput output = new NInchiOutput(InChIReturnCode.Ok, null, null, null, null);

            Assert.AreEqual(InChIReturnCode.Ok, output.ReturnStatus);
        }