Ejemplo n.º 1
0
        public void Test_WithNInChI()
        {
            string mdlInput = // same as NC1=CC(N)=NC(O)=N1
                              "\n" + "  Mrv0541 02151109592D\n" + "\n" + "  9  9  0  0  0  0            999 V2000\n"
                              + "    2.1434   -0.4125    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "    1.4289   -0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "    0.7145   -0.4125    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "    0.0000   -0.0000    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "   -0.7145   -0.4125    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "    0.0000    0.8250    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "    0.7145    1.2375    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "    0.7145    2.0625    0.0000 O   0  0  0  0  0  0  0  0  0  0  0  0\n"
                              + "    1.4289    0.8250    0.0000 N   0  0  0  0  0  0  0  0  0  0  0  0\n" + "  1  2  1  0  0  0  0\n"
                              + "  2  3  2  0  0  0  0\n" + "  3  4  1  0  0  0  0\n" + "  4  5  1  0  0  0  0\n"
                              + "  4  6  2  0  0  0  0\n" + "  6  7  1  0  0  0  0\n" + "  7  8  1  0  0  0  0\n"
                              + "  7  9  2  0  0  0  0\n" + "  2  9  1  0  0  0  0\n" + "M  END\n";

            var reader   = new MDLV2000Reader(new StringReader(mdlInput));
            var molecule = reader.Read(builder.NewAtomContainer());

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
            var hAdder = CDK.HydrogenAdder;

            hAdder.AddImplicitHydrogens(molecule);

            var tautomers = tautomerGenerator.GetTautomers(molecule); // InChI will be calculated

            Assert.AreEqual(5, tautomers.Count);
        }
Ejemplo n.º 2
0
        public void TestMultipleDataFields()
        {
            var       filename     = "NCDK.Data.MDL.bug1587283.mol";
            var       ins          = ResourceLoader.GetAsStream(filename);
            var       reader       = new MDLV2000Reader(ins);
            IChemFile fileContents = (IChemFile)reader.Read(builder.NewChemFile());

            reader.Close();
            Assert.AreEqual(1, fileContents.Count);
            IChemSequence sequence = fileContents[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(1, sequence.Count);
            var model = sequence[0];

            Assert.IsNotNull(model);
            var som = model.MoleculeSet;

            Assert.IsNotNull(som);
            Assert.AreEqual(1, som.Count);
            IAtomContainer m = som[0];

            Assert.IsNotNull(m);
            Assert.AreEqual("B02", m.GetProperty <string>("id_no"));
            Assert.AreEqual("2-2", m.GetProperty <string>("eductkey"));
            Assert.AreEqual("1", m.GetProperty <string>("Step"));
            Assert.AreEqual("2", m.GetProperty <string>("Pos"));
            Assert.AreEqual("B02", m.GetProperty <string>("Tag"));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Convert a Molfile into a CDK AtomContainer (e.g. Molecule)
        /// </summary>
        /// <param name="molfile"></param>
        /// <returns></returns>

        public static IAtomContainer MolfileToAtomContainer(string molfile)
        {
            // Do basic read step

            if (Lex.Contains(molfile, "V2000"))
            {
                DefaultChemObjectReader cor;

                StringReader sr = new StringReader(molfile);
                cor            = new MDLV2000Reader(sr);
                cor.ReaderMode = ChemObjectReaderMode.Relaxed;

                IAtomContainer mol = (IAtomContainer)cor.Read(new AtomContainer());
                cor.Close();

                ConfigureAtomContainer(mol);
                return(mol);
            }


            else if (Lex.Contains(molfile, "V3000"))
            {
                return(MolfileV3000ToAtomContainer(molfile));
            }

            else
            {
                throw new Exception("Unrecognized molfile format");
            }
        }
Ejemplo n.º 4
0
        public void TestGetConfidenceLimit()
        {
            var result = new double[]
            {
                28.5, 25.7, 28.5, 34.9, 28.5, 25.7, 25.4, 28.5, 28.5, 14.8, 13.3, 23.0, 34.9, 25.7, 25.7,
                28.5, 25.7, 25.7, 13.3, 14.4, 14.4, 8.9, 14.8, 14.8, 13.3, 13.3, 13.3, 14.4, 14.4, 13.3, 14.4, 14.4,
                8.9, 14.8, 14.8, 13.3, 13.3, 13.3, 14.4, 14.4, 13.3,
            };
            IAtomContainer molecule = null;
            var            filename = "NCDK.Data.MDL.BremserPredictionTest.mol";
            var            ins      = ResourceLoader.GetAsStream(filename);
            var            reader   = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);

            molecule = reader.Read(builder.NewAtomContainer());
            double prediction;
            var    bp  = new BremserOneSphereHOSECodePredictor();
            var    hcg = new HOSECodeGenerator();
            string s   = null;

            RemoveHydrogens(molecule);
            for (int f = 0; f < molecule.Atoms.Count; f++)
            {
                s          = hcg.GetHOSECode(molecule, molecule.Atoms[f], 1);
                prediction = bp.GetConfidenceLimit(HOSECodeGenerator.MakeBremserCompliant(s));
                Assert.AreEqual(result[f], prediction, 0.001);
            }
        }
Ejemplo n.º 5
0
        public void TestSulfurCompound_ImplicitHydrogens()
        {
            var filename       = "NCDK.Data.MDL.sulfurCompound.mol";
            var ins            = ResourceLoader.GetAsStream(filename);
            var reader         = new MDLV2000Reader(ins);
            var chemFile       = reader.Read(builder.NewChemFile());
            var containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();

            Assert.AreEqual(1, containersList.Count);

            var atomContainer_0 = (IAtomContainer)containersList[0];

            Assert.AreEqual(10, atomContainer_0.Atoms.Count);
            var sulfur = atomContainer_0.Atoms[1];

            FindAndConfigureAtomTypesForAllAtoms(atomContainer_0);
            adder.AddImplicitHydrogens(atomContainer_0);
            Assert.AreEqual("S", sulfur.Symbol);
            Assert.IsNotNull(sulfur.ImplicitHydrogenCount);
            Assert.AreEqual(0, sulfur.ImplicitHydrogenCount.Value);
            Assert.AreEqual(3, atomContainer_0.GetConnectedBonds(sulfur).Count());
            Assert.AreEqual(10, atomContainer_0.Atoms.Count);
            Assert.IsNotNull(sulfur.ImplicitHydrogenCount);
            Assert.AreEqual(0, sulfur.ImplicitHydrogenCount.Value);
            Assert.AreEqual(3, atomContainer_0.GetConnectedBonds(sulfur).Count());
        }
Ejemplo n.º 6
0
        public void TestSDFFile6()
        {
            var filename     = "NCDK.Data.MDL.test6.sdf"; // a multi molecule SDF file
            var ins          = ResourceLoader.GetAsStream(filename);
            var reader       = new MDLV2000Reader(ins);
            var fileContents = reader.Read(builder.NewChemFile());

            reader.Close();
            Assert.AreEqual(1, fileContents.Count);
            var sequence = fileContents[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(3, sequence.Count);
            for (int i = 0; i < sequence.Count; i++)
            {
                Assert.IsNotNull(sequence[i]);
            }

            var model = sequence[0];

            Assert.IsNotNull(model);
            var som = model.MoleculeSet;

            Assert.IsNotNull(som);
            Assert.AreEqual(1, som.Count);
            IAtomContainer m = som[0];

            Assert.IsNotNull(m);
            Assert.AreEqual("ola11", m.GetProperty <string>("STRUCTURE ID"));
        }
Ejemplo n.º 7
0
 public SpanningTreeTest()
 {
     if (azulene == null)
     {
         // load azulene
         var            filename        = "NCDK.Data.MDL.azulene.mol";
         var            ins             = ResourceLoader.GetAsStream(filename);
         var            reader          = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
         var            chemFile        = reader.Read(builder.NewChemFile());
         var            seq             = chemFile[0];
         var            model           = seq[0];
         IAtomContainer azuleneMolecule = model.MoleculeSet[0];
         Assert.AreEqual(10, azuleneMolecule.Atoms.Count);
         Assert.AreEqual(11, azuleneMolecule.Bonds.Count);
         azulene = new SpanningTree(azuleneMolecule);
     }
     if (ethane == null)
     {
         // create ethane
         IAtomContainer ethaneMolecule = builder.NewAtomContainer();
         ethaneMolecule.Atoms.Add(builder.NewAtom("C"));
         ethaneMolecule.Atoms.Add(builder.NewAtom("C"));
         ethaneMolecule.AddBond(ethaneMolecule.Atoms[0], ethaneMolecule.Atoms[1], BondOrder.Single);
         ethane = new SpanningTree(ethaneMolecule);
     }
 }
Ejemplo n.º 8
0
        public void TestFindHeavyAtomsInChain_IAtomContainer_IAtomContainer()
        {
            var filename = "NCDK.Data.MDL.allmol232.mol";
            var ins      = ResourceLoader.GetAsStream(filename);
            // TODO: shk3-cleanuptests: best to use the STRICT IO mode here
            var reader   = new MDLV2000Reader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            var containersList = ChemFileManipulator.GetAllAtomContainers(chemFile);
            var ac             = new Silent.AtomContainer(containersList.First());

            AddExplicitHydrogens(ac);
            var chain = ac.Builder.NewAtomContainer();

            for (int i = 16; i < 25; i++)
            {
                chain.Atoms.Add(ac.Atoms[i]);
            }
            chain.Atoms.Add(ac.Atoms[29]);
            chain.Atoms.Add(ac.Atoms[30]);
            int[] result = new AtomPlacer3D().FindHeavyAtomsInChain(ac, chain);
            Assert.AreEqual(16, result[0]);
            Assert.AreEqual(11, result[1]);
        }
        public void TestDescriptors()
        {
            string         fnmol = "NCDK.Data.CDD.pyridineacid.mol";
            IAtomContainer mol;

            using (var mdl = new MDLV2000Reader(ResourceLoader.GetAsStream(fnmol)))
            {
                mol = mdl.Read(CDK.Builder.NewAtomContainer());
            }

            var fpsa    = CreateDescriptor();
            var results = fpsa.Calculate(mol);

            // note: test currently assumes that just one Descriptor is calculated
            var names = results.Keys.ToReadOnlyList();

            if (names.Count != 1 || !names[0].Equals("tpsaEfficiency"))
            {
                throw new CDKException("Only expecting 'tpsaEfficiency'");
            }
            var    tpsaEfficiency = results.Value;
            double ANSWER = 0.4036, ANSWER_LO = ANSWER * 0.999, ANSWER_HI = ANSWER * 1.001; // (we can tolerate rounding errors)

            if (tpsaEfficiency < ANSWER_LO || tpsaEfficiency > ANSWER_HI)
            {
                throw new CDKException($"Got {tpsaEfficiency}, expected {ANSWER}");
            }
        }
Ejemplo n.º 10
0
 private void ProcessMol(IAtomContainer mol, List <IAtomContainer> components, StringBuilder sb)
 {
     using (var reader = new MDLV2000Reader(new StringReader(sb.ToString()), this.ReaderMode))
     {
         components.Add(reader.Read(mol));
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Convert a Molfile into a CDK AtomContainer (e.g. Molecule)
        /// </summary>
        /// <param name="molfile"></param>
        /// <returns></returns>

        public static IAtomContainer MolfileToAtomContainer(string molfile)
        {
            // Do basic read step

            if (Lex.Contains(molfile, "V2000"))
            {
                cdk.io.DefaultChemObjectReader cor;

                java.io.StringReader sr = new java.io.StringReader(molfile);
                cor = new MDLV2000Reader(sr);
                cor.setReaderMode(IChemObjectReader.Mode.RELAXED);

                IAtomContainer mol = (IAtomContainer)cor.read(new AtomContainer());
                cor.close();

                ConfigureAtomContainer(mol);
                return(mol);
            }


            else if (Lex.Contains(molfile, "V3000"))
            {
                return(MolfileV3000ToAtomContainer(molfile));
            }

            else
            {
                throw new Exception("Unrecognized molfile format");
            }
        }
        public void TestBug853254()
        {
            var            builder        = CDK.Builder;
            var            filename       = "NCDK.Data.MDL.bug853254-2.mol";
            var            ins            = ResourceLoader.GetAsStream(filename);
            var            reader         = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            IAtomContainer superstructure = (IAtomContainer)reader.Read(builder.NewAtomContainer());

            filename = "NCDK.Data.MDL.bug853254-1.mol";
            ins      = ResourceLoader.GetAsStream(filename);
            reader   = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            IAtomContainer substructure = (IAtomContainer)reader.Read(builder.NewAtomContainer());

            // these molecules are different resonance forms of the same molecule
            // make sure aromaticity is detected. although some fingerprinters do this
            // one should not expected all implementations to do so.
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(superstructure);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(substructure);
            Aromaticity.CDKLegacy.Apply(superstructure);
            Aromaticity.CDKLegacy.Apply(substructure);

            IFingerprinter fingerprinter = GetBitFingerprinter();
            BitArray       superBS       = fingerprinter.GetBitFingerprint(superstructure).AsBitSet();
            BitArray       subBS         = fingerprinter.GetBitFingerprint(substructure).AsBitSet();
            bool           isSubset      = FingerprinterTool.IsSubset(superBS, subBS);

            Assert.IsTrue(isSubset);
        }
        public void TestBug931608()
        {
            var            builder    = CDK.Builder;
            var            filename   = "NCDK.Data.MDL.bug931608-1.mol";
            var            ins        = ResourceLoader.GetAsStream(filename);
            var            reader     = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            IAtomContainer structure1 = (IAtomContainer)reader.Read(builder.NewAtomContainer());

            filename = "NCDK.Data.MDL.bug931608-2.mol";
            ins      = ResourceLoader.GetAsStream(filename);
            reader   = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            IAtomContainer structure2 = (IAtomContainer)reader.Read(builder.NewAtomContainer());

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(structure1);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(structure2);

            IFingerprinter fingerprinter = GetBitFingerprinter();
            BitArray       bs1           = fingerprinter.GetBitFingerprint(structure1).AsBitSet();
            BitArray       bs2           = fingerprinter.GetBitFingerprint(structure2).AsBitSet();

            // now we do the bool XOR on the two bitsets, leading
            // to a bitset that has all the bits set to "true" which differ
            // between the two original bitsets
            bs1.Xor(bs2);
            // cardinality gives us the number of "true" bits in the
            // result of the XOR operation.
            int cardinality = BitArrays.Cardinality(bs1);

            Assert.AreEqual(0, cardinality);
        }
        public void TestPseudoAtoms()
        {
            var filename = "NCDK.Data.MDL.pseudoatoms.sdf";

            var ins    = ResourceLoader.GetAsStream(filename);
            var reader = new MDLV2000Reader(ins);
            var mol    = builder.NewAtomContainer();

            mol = reader.Read(mol);
            Assert.IsNotNull(mol);

            // check that there are some pseudo-atoms
            bool hasPseudo = false;

            foreach (var atom in mol.Atoms)
            {
                if (atom is IPseudoAtom)
                {
                    hasPseudo = true;
                }
            }
            Assert.IsTrue(hasPseudo, "The molecule should have one or more pseudo atoms");

            EquivalentClassPartitioner partitioner = new EquivalentClassPartitioner(mol);

            Assert.IsNotNull(partitioner);

            int[] classes = partitioner.GetTopoEquivClassbyHuXu(mol);
        }
Ejemplo n.º 15
0
        public void TestMapAtomsOfAlignedStructures()
        {
            string filenameMolOne = "NCDK.Data.MDL.murckoTest6_3d_2.mol";
            string filenameMolTwo = "NCDK.Data.MDL.murckoTest6_3d.mol";
            //string filenameMolTwo = "NCDK.Data.MDL.murckoTest6_3d_2.mol";
            var            ins = ResourceLoader.GetAsStream(filenameMolOne);
            IAtomContainer molOne;
            IAtomContainer molTwo;
            var            mappedAtoms = new Dictionary <int, int>();
            var            reader      = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);

            molOne = reader.Read(builder.NewAtomContainer());

            ins    = ResourceLoader.GetAsStream(filenameMolTwo);
            reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            molTwo = reader.Read(builder.NewAtomContainer());

            AtomMappingTools.MapAtomsOfAlignedStructures(molOne, molTwo, mappedAtoms);
            //Debug.WriteLine("mappedAtoms:"+mappedAtoms.ToString());
            //Debug.WriteLine("***** ANGLE VARIATIONS *****");
            double AngleRMSD = GeometryUtil.GetAngleRMSD(molOne, molTwo, mappedAtoms);

            //Debug.WriteLine("The Angle RMSD between the first and the second structure is :"+AngleRMSD);
            //Debug.WriteLine("***** ALL ATOMS RMSD *****");
            Assert.AreEqual(0.2, AngleRMSD, 0.1);
            double AllRMSD = GeometryUtil.GetAllAtomRMSD(molOne, molTwo, mappedAtoms, true);

            //Debug.WriteLine("The RMSD between the first and the second structure is :"+AllRMSD);
            Assert.AreEqual(0.242, AllRMSD, 0.001);
            //Debug.WriteLine("***** BOND LENGTH RMSD *****");
            double BondLengthRMSD = GeometryUtil.GetBondLengthRMSD(molOne, molTwo, mappedAtoms, true);

            //Debug.WriteLine("The Bond length RMSD between the first and the second structure is :"+BondLengthRMSD);
            Assert.AreEqual(0.2, BondLengthRMSD, 0.1);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Method will return an appropriate reader for the provided format. Each reader is stored
        /// in a map, if no reader is available for the specified format a new reader is created. The
        /// <see cref="IChemObjectReader.ErrorHandler"/> and
        /// <see cref="IChemObjectReader.ReaderMode"/> are set.
        /// </summary>
        /// <param name="format">The format to obtain a reader for</param>
        /// <returns>instance of a reader appropriate for the provided format</returns>
        private ISimpleChemObjectReader GetReader(IChemFormat format, TextReader input)
        {
            ISimpleChemObjectReader reader;

            switch (format)
            {
            case MDLV2000Format _:
                reader = new MDLV2000Reader(input);
                break;

            case MDLV3000Format _:
                reader = new MDLV3000Reader(input);
                break;

            case MDLFormat _:
                reader = new MDLReader(input);
                break;

            default:
                throw new ArgumentException($"Unexpected format: {format}");
            }
            reader.ErrorHandler = this.ErrorHandler;
            reader.ReaderMode   = this.ReaderMode;
            if (currentFormat is MDLV2000Format)
            {
                reader.AddSettings(IOSettings.Settings);
            }

            return(reader);
        }
Ejemplo n.º 17
0
        public void Test2Dvs3D()
        {
            var sp  = CDK.SmilesParser;
            var mol = sp.ParseSmiles("O1C2C34C(C(C1O)CCCc1cc(cc(c1)C(F)(F)F)C(F)(F)F)CCC(C3CCC(O2)(OO4)C)C");

            AddExplicitHydrogens(mol);
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol);
            Aromaticity.CDKLegacy.Apply(mol);

            double value2D = CreateDescriptor().Calculate(mol).Value;

            var       filename = "NCDK.Data.MDL.cpsa-uncharged.sdf";
            IChemFile content;

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(filename)))
            {
                content = reader.Read(CDK.Builder.NewChemFile());
            }
            var cList = ChemFileManipulator.GetAllAtomContainers(content).ToReadOnlyList();

            mol = cList[0];
            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(mol);
            Aromaticity.CDKLegacy.Apply(mol);

            var value3D = CreateDescriptor().Calculate(mol).Value;

            Assert.AreEqual(value2D, value3D, 0.001);
        }
        public void TestGetSubgraphMapIAtomContainerIAtomContainer()
        {
            var molfile               = "NCDK.Data.MDL.decalin.mol";
            var queryfile             = "NCDK.Data.MDL.decalin.mol";
            var mol                   = builder.NewAtomContainer();
            var temp                  = builder.NewAtomContainer();
            QueryAtomContainer query1 = null;
            QueryAtomContainer query2 = null;

            var ins    = ResourceLoader.GetAsStream(molfile);
            var reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);

            reader.Read(mol);
            ins    = ResourceLoader.GetAsStream(queryfile);
            reader = new MDLV2000Reader(ins, ChemObjectReaderMode.Strict);
            reader.Read(temp);
            query1 = QueryAtomContainerCreator.CreateBasicQueryContainer(temp);

            var sp            = CDK.SmilesParser;
            var atomContainer = sp.ParseSmiles("C1CCCCC1");

            query2 = QueryAtomContainerCreator.CreateBasicQueryContainer(atomContainer);

            var list = uiTester.GetSubgraphMap(mol, query1);

            Assert.AreEqual(11, list.Count);

            list = uiTester.GetSubgraphMap(mol, query2);
            Assert.AreEqual(6, list.Count);
        }
        public void TestSFBug999330()
        {
            var file1 = "NCDK.Data.MDL.5SD.mol";
            var file2 = "NCDK.Data.MDL.ADN.mol";

            var mol1 = builder.NewAtomContainer();

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(file1), ChemObjectReaderMode.Strict))
            {
                reader.Read(mol1);
            }

            var mol2 = builder.NewAtomContainer();

            using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream(file2), ChemObjectReaderMode.Strict))
            {
                reader.Read(mol2);
            }

            var permutor = new AtomContainerAtomPermutor(mol2);

            permutor.MoveNext();
            mol2 = builder.NewAtomContainer(permutor.Current);

            var list1 = uiTester.GetOverlaps(mol1, mol2);
            var list2 = uiTester.GetOverlaps(mol2, mol1);

            Assert.AreEqual(1, list1.Count);
            Assert.AreEqual(1, list2.Count);
            Assert.AreEqual(list1[0].Atoms.Count, list2[0].Atoms.Count);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Method will return an appropriate reader for the provided format. Each reader is stored
        /// in a map, if no reader is available for the specified format a new reader is created. The
        /// <see cref="IChemObjectReader.ErrorHandler"/> and
        /// <see cref="IChemObjectReader.ReaderMode"/> are set.
        /// </summary>
        /// <param name="format">The format to obtain a reader for</param>
        /// <returns>instance of a reader appropriate for the provided format</returns>
        private ISimpleChemObjectReader GetReader(IChemFormat format, TextReader input)
        {
            ISimpleChemObjectReader reader;

            if (format is MDLV2000Format)
            {
                reader = new MDLV2000Reader(input);
            }
            else if (format is MDLV3000Format)
            {
                reader = new MDLV3000Reader(input);
            }
            else if (format is MDLFormat)
            {
                reader = new MDLReader(input);
            }
            else
            {
                throw new ArgumentException("Unexpected format: " + format);
            }
            reader.ErrorHandler = this.ErrorHandler;
            reader.ReaderMode   = this.ReaderMode;
            if (currentFormat is MDLV2000Format)
            {
                reader.AddSettings(IOSettings.Settings);
            }

            return(reader);
        }
Ejemplo n.º 21
0
        public void SkipDefaultProps()
        {
            var sw = new StringWriter();

            using (var mdlr = new MDLV2000Reader(ResourceLoader.GetAsStream("NCDK.Data.MDL.tetrahedral-parity-withImplH.mol")))
                using (var mdlw = new MDLV2000Writer(sw))
                {
                    mdlw.IOSettings[MDLV2000Writer.OptWriteDefaultProperties].Setting = "false";
                    mdlw.Write(mdlr.Read(builder.NewAtomContainer()));
                    var output = sw.ToString();
                    Assert.IsTrue(output.Contains(
                                      "\n"
                                      + "  5  4  0  0  1  0  0  0  0  0999 V2000\n"
                                      + "    0.0000    0.0000    0.0000 C   0  0  1  0  0  0\n"
                                      + "    0.0000    0.0000    0.0000 C   0  0\n"
                                      + "    0.0000    0.0000    0.0000 C   0  0\n"
                                      + "    0.0000    0.0000    0.0000 O   0  0\n"
                                      + "    0.0000    0.0000    0.0000 C   0  0\n"
                                      + "  1  2  1  0\n"
                                      + "  2  3  1  0\n"
                                      + "  1  4  1  0\n"
                                      + "  1  5  1  0\n"
                                      + "M  END"));
                }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// The object at given record No.
        /// </summary>
        /// <param name="record">Zero-based record number</param>
        /// <returns></returns>
        public override IAtomContainer this[int record]
        {
            get
            {
                string buffer;
                Debug.WriteLine($"Current record {record}");

                if ((record < 0) || (record >= numberOfRecords))
                {
                    throw new CDKException($"No such record {record}");
                }

                lock (lockRaFile)
                {
                    raFile.Seek(index[record][0], SeekOrigin.Begin);
                    int length = (int)index[record][1];
                    raFile.Read(b, 0, length);
                    buffer = Encoding.UTF8.GetString(b, 0, length);
                    using (var reader = new MDLV2000Reader(new StringReader(buffer)))
                    {
                        foreach (var listener in Listeners)
                        {
                            reader.Listeners.Add(listener);
                        }

                        var cf = reader.Read(Builder.NewChemFile());
                        return(ToAtomContainer(cf));
                    }
                }
            }
        }
Ejemplo n.º 23
0
        public void TestDataFromSDFReading()
        {
            var filename     = "NCDK.Data.MDL.test.sdf"; // a multi molecule SDF file
            var ins          = ResourceLoader.GetAsStream(filename);
            var reader       = new MDLV2000Reader(ins);
            var fileContents = reader.Read(builder.NewChemFile());

            reader.Close();
            Assert.AreEqual(1, fileContents.Count);
            var sequence = fileContents[0];

            Assert.IsNotNull(sequence);
            Assert.AreEqual(9, sequence.Count);
            var model = sequence[0];

            Assert.IsNotNull(model);

            var som = model.MoleculeSet;

            Assert.IsNotNull(som);
            Assert.AreEqual(1, som.Count);
            IAtomContainer m = som[0];

            Assert.IsNotNull(m);
            Assert.AreEqual("1", m.GetProperty <string>("E_NSC"));
            Assert.AreEqual("553-97-9", m.GetProperty <string>("E_CAS"));
        }
Ejemplo n.º 24
0
        public void TestAccepts()
        {
            var reader = new MDLV2000Reader(new StringReader(""));

            Assert.IsTrue(reader.Accepts(typeof(IChemFile)));
            Assert.IsTrue(reader.Accepts(typeof(IChemModel)));
            Assert.IsTrue(reader.Accepts(typeof(Silent.AtomContainer)));
        }
Ejemplo n.º 25
0
 public void Bug1295()
 {
     using (var reader = new MDLV2000Reader(ResourceLoader.GetAsStream("NCDK.Data.MDL.bug1295.mol")))
     {
         var container = reader.Read(builder.NewAtomContainer());
         var generator = factory.GetInChIGenerator(container);
         Assert.AreEqual("InChI=1S/C7H15NO/c1-4-7(3)6-8-9-5-2/h6-7H,4-5H2,1-3H3", generator.InChI);
     }
 }
Ejemplo n.º 26
0
        public void ReadMDLCoordinates_no_decimal_relaxed()
        {
            var reader = new MDLV2000Reader(new StringReader(""))
            {
                ReaderMode = ChemObjectReaderMode.Relaxed
            };

            Assert.IsTrue(Math.Abs(reader.ReadMDLCoordinate("   -2.0012   708089 ", 10) - 708089) < 0.1);
        }
Ejemplo n.º 27
0
        public void ReadMDLCoordinates_wrong_decimal_position_strict()
        {
            var reader = new MDLV2000Reader(new StringReader(""))
            {
                ReaderMode = ChemObjectReaderMode.Strict
            };

            Assert.IsTrue(Math.Abs(reader.ReadMDLCoordinate("   -2.0012   7.8089 ", 10) - 7.8089) < 0.1);
        }
Ejemplo n.º 28
0
        public void ReadOldJmolCoordsFailOnStrictRead()
        {
            var reader = new MDLV2000Reader(new StringReader(""))
            {
                ReaderMode = ChemObjectReaderMode.Strict
            };

            reader.ReadMDLCoordinate("  -2.00120    7.8089", 0);
        }
Ejemplo n.º 29
0
        public void ReadOldJmolCoords()
        {
            var reader = new MDLV2000Reader(new StringReader(""))
            {
                ReaderMode = ChemObjectReaderMode.Relaxed
            };

            Assert.IsTrue(Math.Abs(reader.ReadMDLCoordinate("  -2.00120    7.8089", 0) - (-2.00120)) < 0.1);
        }
Ejemplo n.º 30
0
 public void Chembl367774()
 {
     using (MDLV2000Reader mdlr = new MDLV2000Reader(GetType().Assembly.GetManifestResourceStream(GetType(), "CHEMBL367774.mol")))
     {
         IAtomContainer  container = mdlr.Read(builder.NewAtomContainer());
         SmilesGenerator smigen    = new SmilesGenerator(SmiFlavors.CxSmiles);
         Assert.AreEqual("OC(=O)C1=CC(F)=CC=2NC(=NC12)C3=CC=C(C=C3F)C4=CC=CC=C4", smigen.Create(container));
     }
 }
Ejemplo n.º 31
0
		public IEnumerable<IAtomContainer> Parse(string sdfString)
		{
			var reader = new MDLV2000Reader(new StringReader(sdfString));
			var chemFile = (ChemFile)reader.read(new ChemFile());
			return ChemFileManipulator.getAllAtomContainers(chemFile).ToWindowsEnumerable<IAtomContainer>();
		}