Пример #1
0
        public void TestGetOptions()
        {
            NInchiInput input = new NInchiInput();

            input.Options = NInchiWrapper.FlagChar + "compress";
            Assert.AreEqual(NInchiWrapper.FlagChar + "compress", input.Options);
        }
Пример #2
0
        public static NInchiInputData GetInputFromAuxInfo(string auxInfo)
        {
            if (auxInfo == null)
            {
                throw new ArgumentNullException(nameof(auxInfo), "Null AuxInfo");
            }

            var native_output = new InchiInpData();
            var iiii          = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(Inchi_Input)));

            try
            {
                native_output.pInp = iiii;

                int ret;
                ret = Get_inchi_Input_FromAuxInfo(auxInfo, 0, 0, out native_output);

                NInchiInput  oos = new NInchiInput();
                Inchi_Input *pii = (Inchi_Input *)native_output.pInp.ToPointer();
                {
                    CreateAtoms(oos, pii->num_atoms, pii->atom);
                    CreateBonds(oos, pii->num_atoms, pii->atom);
                    CreateStereos(oos, pii->num_stereo0D, pii->stereo0D);
                }

                var oo = new NInchiInputData(ret, oos, native_output.bChiral, new string(native_output.szErrMsg));
                return(oo);
            }
            finally
            {
                Free_inchi_Input((Inchi_Input *)iiii.ToPointer());
            }
        }
Пример #3
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
        }
Пример #4
0
 public void TestAuxinfo2Input()
 {
     // START SNIPPET: auxinfo2input
     NInchiInputData data = NInchiWrapper.GetInputFromAuxInfo("AuxInfo=1/1/N:4,1,2,3,5,6/"
                                                              + "E:(5,6)/it:im/rA:6CCNCOO/rB:s1;N1;s1;s2;d2;/rC:264,968,0;295,985,0;233,986,0;"
                                                              + "264,932,0;326,967,0;295,1021,0;");
     InChIReturnCode ret   = data.ReturnStatus;
     NInchiInput     input = data.Input;
     // END SNIPPET: auxinfo2input
 }
Пример #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
        }
Пример #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);
                }
            }
        }
Пример #7
0
        static Set_inchi_Input_ InitInchiInput(NInchiInput input)
        {
            var natoms  = input.Atoms.Count;
            var nstereo = input.Stereos.Count;
            var nbonds  = input.Bonds.Count;

            if (natoms > MAX_ATOMS)
            {
                throw new ArgumentException("Too many atoms");
            }

            var atoms = new Inchi_Atom[natoms];
            {
                for (int i = 0; i < natoms; i++)
                {
                    var atom = input.Atoms[i];

                    Inchi_Atom iatom = new Inchi_Atom();
                    {
                        var elname = Encoding.ASCII.GetBytes(atom.ElementType);
                        for (int n = 0; n < elname.Length; n++)
                        {
                            iatom.elname[n] = (sbyte)elname[n];
                        }
                        iatom.elname[elname.Length] = 0;
                    }

                    iatom.X = atom.X;
                    iatom.Y = atom.Y;
                    iatom.Z = atom.Z;

                    iatom.charge  = (SByte)atom.Charge;
                    iatom.radical = (SByte)atom.Radical;

                    iatom.num_iso_H[0] = (SByte)atom.ImplicitH;
                    iatom.num_iso_H[1] = (SByte)atom.ImplicitProtium;
                    iatom.num_iso_H[2] = (SByte)atom.ImplicitDeuterium;
                    iatom.num_iso_H[3] = (SByte)atom.ImplicitTritium;

                    iatom.isotopic_mass = (Int16)atom.IsotopicMass;

                    iatom.num_bonds = 0;

                    atoms[i] = iatom;
                }
            }

            {
                for (int i = 0; i < nbonds; i++)
                {
                    var bond       = input.Bonds[i];
                    var atomO      = bond.OriginAtom;
                    var atomT      = bond.TargetAtom;
                    var bondType   = bond.BondType;
                    var bondStereo = bond.BondStereo;

                    var iaO = input.Atoms.IndexOf(atomO);
                    var iaT = input.Atoms.IndexOf(atomT);

                    var iatom    = atoms[iaO];
                    int numbonds = atoms[iaO].num_bonds;
                    if (numbonds == MAXVAL)
                    {
                        throw new ArgumentException("Too many bonds from one atom; maximum: " + MAXVAL);
                    }
                    iatom.neighbor[numbonds]    = (Int16)iaT;
                    iatom.bond_type[numbonds]   = (SByte)bondType;
                    iatom.bond_stereo[numbonds] = (SByte)bondStereo;
                    iatom.num_bonds++;
                    atoms[iaO] = iatom;
                }
            }

            var stereos = new Inchi_Stereo0D[nstereo];
            {
                for (var i = 0; i < input.Stereos.Count; i++)
                {
                    var stereo = input.Stereos[i];

                    var istereo = stereos[i];

                    var cat  = stereo.CentralAtom;
                    var nat0 = stereo.Neighbors[0];
                    var nat1 = stereo.Neighbors[1];
                    var nat2 = stereo.Neighbors[2];
                    var nat3 = stereo.Neighbors[3];

                    istereo.central_atom = (Int16)input.Atoms.IndexOf(cat);
                    istereo.neighbor[0]  = (Int16)input.Atoms.IndexOf(nat0);
                    istereo.neighbor[1]  = (Int16)input.Atoms.IndexOf(nat1);
                    istereo.neighbor[2]  = (Int16)input.Atoms.IndexOf(nat2);
                    istereo.neighbor[3]  = (Int16)input.Atoms.IndexOf(nat3);
                    istereo.type         = (SByte)stereo.StereoType;
                    istereo.parity       = (SByte)stereo.Parity;

                    stereos[i] = istereo;
                }
            }

            var pre = new Set_inchi_Input_
            {
                atoms   = atoms,
                stereos = stereos
            };

            return(pre);
        }