Exemplo n.º 1
0
        void Main()
        {
            IAtomContainer mol = null;

            #region
            ModelBuilder3D mb3d     = ModelBuilder3D.GetInstance();
            IAtomContainer molecule = mb3d.Generate3DCoordinates(mol, false);
            #endregion
        }
Exemplo n.º 2
0
        public void TestAlkanes()
        {
            string smiles1           = "CCCCCCCCCCCCCCCCCC";
            string smiles2           = "CCCCCC(CCCC)CCCC";
            var    parser            = CDK.SmilesParser;
            var    nonBranchedAlkane = parser.ParseSmiles(smiles1);
            var    branchedAlkane    = parser.ParseSmiles(smiles2);

            ModelBuilder3D.GetInstance().Generate3DCoordinates(nonBranchedAlkane,
                                                               false);
            ModelBuilder3D.GetInstance().Generate3DCoordinates(branchedAlkane, false);
        }
Exemplo n.º 3
0
        public void HydrogenAsFirstAtomInEthane()
        {
            SmilesParser smipar = CDK.SmilesParser;
            var          ethane = smipar.ParseSmiles("[H]C([H])([H])C([H])([H])[H]");

            AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(ethane);
            ModelBuilder3D mb3d = ModelBuilder3D.GetInstance();

            mb3d.Generate3DCoordinates(ethane, false);
            foreach (var atom in ethane.Atoms)
            {
                Assert.IsNotNull(atom.Point3D);
            }
        }
Exemplo n.º 4
0
        public void TestModelBuilder3D_bug_1241421()
        {
            var mb3d     = ModelBuilder3D.GetInstance();
            var filename = "NCDK.Data.MDL.bug1241421.mol";
            var ins      = ResourceLoader.GetAsStream(filename);
            var reader   = new MDLV2000Reader(ins);
            var chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            var            containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();
            IAtomContainer ac             = new Silent.AtomContainer(containersList[0]);

            ac = mb3d.Generate3DCoordinates(ac, false);
            CheckAverageBondLength(ac);
        }
Exemplo n.º 5
0
        public void TestModelBuilder3D_C1CCCCCCC1CC()
        {
            ModelBuilder3D mb3d  = ModelBuilder3D.GetInstance();
            string         smile = "C1CCCCCCC1CC";
            var            sp    = CDK.SmilesParser;
            var            mol   = sp.ParseSmiles(smile);

            AddExplicitHydrogens(mol);
            mol = mb3d.Generate3DCoordinates(mol, false);
            for (int i = 0; i < mol.Atoms.Count; i++)
            {
                Assert.IsNotNull(mol.Atoms[i].Point3D);
            }
            CheckAverageBondLength(mol);
        }
Exemplo n.º 6
0
        public void TestModelBuilder3D_Konstanz()
        {
            ModelBuilder3D mb3d  = ModelBuilder3D.GetInstance();
            string         smile = "C12(-[H])-C3(-C(-[H])(-[H])-C(-C4(-C5(-C(-Cl)(-Cl)-C(-C-3-4-[H])(-Cl)-C(-Cl)(-[H])-C-5(-Cl)-[H])-Cl)-[H])(-[H])-C-2(-O-1)-[H])-[H]";
            var            sp    = CDK.SmilesParser;
            var            mol   = sp.ParseSmiles(smile);

            AddExplicitHydrogens(mol);
            mol = mb3d.Generate3DCoordinates(mol, false);
            for (int i = 0; i < mol.Atoms.Count; i++)
            {
                Assert.IsNotNull(mol.Atoms[i].Point3D);
            }
            CheckAverageBondLength(mol);
        }
Exemplo n.º 7
0
        public void TestModelBuilder3D_232()
        {
            ModelBuilder3D mb3d     = ModelBuilder3D.GetInstance();
            var            filename = "NCDK.Data.MDL.allmol232.mol";
            var            ins      = ResourceLoader.GetAsStream(filename);
            var            reader   = new MDLV2000Reader(ins);
            var            chemFile = reader.Read(builder.NewChemFile());

            reader.Close();
            var            containersList = ChemFileManipulator.GetAllAtomContainers(chemFile).ToReadOnlyList();
            IAtomContainer ac             = new Silent.AtomContainer(containersList[0]);

            AddExplicitHydrogens(ac);
            ac = mb3d.Generate3DCoordinates(ac, false);
            Assert.IsNotNull(ac.Atoms[0].Point3D);
            CheckAverageBondLength(ac);
        }
Exemplo n.º 8
0
        public void TestModelBuilder3D_CF()
        {
            ModelBuilder3D mb3d     = ModelBuilder3D.GetInstance();
            Vector3        c_coord  = new Vector3(1.392, 0.0, 0.0);
            Vector3        f_coord  = new Vector3(0.0, 0.0, 0.0);
            Vector3        h1_coord = new Vector3(1.7439615035767404, 1.0558845107302222, 0.0);
            Vector3        h2_coord = new Vector3(1.7439615035767404, -0.5279422553651107, 0.914422809754875);
            Vector3        h3_coord = new Vector3(1.7439615035767402, -0.5279422553651113, -0.9144228097548747);

            var sp  = CDK.SmilesParser;
            var mol = sp.ParseSmiles("CF");

            AddExplicitHydrogens(mol);
            //mb3d.SetTemplateHandler();
            mol = mb3d.Generate3DCoordinates(mol, false);
            AssertAreEqual(c_coord, mol.Atoms[0].Point3D, 0.0001);
            AssertAreEqual(f_coord, mol.Atoms[1].Point3D, 0.0001);
            AssertAreEqual(h1_coord, mol.Atoms[2].Point3D, 0.0001);
            AssertAreEqual(h2_coord, mol.Atoms[3].Point3D, 0.0001);
            AssertAreEqual(h3_coord, mol.Atoms[4].Point3D, 0.0001);
            CheckAverageBondLength(mol);
        }
Exemplo n.º 9
0
        public void TestModelBuilder3D_keepChemObjectIDs()
        {
            ModelBuilder3D mb3d = ModelBuilder3D.GetInstance();

            IAtomContainer     methanol = new Silent.AtomContainer();
            IChemObjectBuilder builder  = methanol.Builder;

            IAtom carbon1 = builder.NewAtom("C");

            carbon1.Id = "carbon1";
            methanol.Atoms.Add(carbon1);
            for (int i = 0; i < 3; i++)
            {
                IAtom hydrogen = builder.NewAtom("H");
                methanol.Atoms.Add(hydrogen);
                methanol.Bonds.Add(builder.NewBond(carbon1, hydrogen, BondOrder.Single));
            }
            IAtom oxygen1 = builder.NewAtom("O");

            oxygen1.Id = "oxygen1";
            methanol.Atoms.Add(oxygen1);
            methanol.Bonds.Add(builder.NewBond(carbon1, oxygen1, BondOrder.Single));
            {
                IAtom hydrogen = builder.NewAtom("H");
                methanol.Atoms.Add(hydrogen);
                methanol.Bonds.Add(builder.NewBond(hydrogen, oxygen1, BondOrder.Single));
            }

            Assert.AreEqual(6, methanol.Atoms.Count);
            Assert.AreEqual(5, methanol.Bonds.Count);

            mb3d.Generate3DCoordinates(methanol, false);

            CheckAverageBondLength(methanol);
            Assert.AreEqual("carbon1", carbon1.Id);
            Assert.AreEqual("oxygen1", oxygen1.Id);
        }
Exemplo n.º 10
0
        public void TestModel3D_bug_1610997()
        {
            //bool notCalculatedResults = false;
            var inputList = new List <IAtomContainer>();

            ////////////////////////////////////////////////////////////////////////////////////////////
            //generate the input molecules. This are molecules without x, y, z coordinates

            string[] smiles = new string[] { "CC", "OCC", "O(C)CCC", "c1ccccc1", "C(=C)=C", "OCC=CCc1ccccc1(C=C)",
                                             "O(CC=C)CCN", "CCCCCCCCCCCCCCC", "OCC=CCO", "NCCCCN" };
            var sp = CDK.SmilesParser;

            IAtomContainer[] atomContainer = new IAtomContainer[smiles.Length];
            for (int i = 0; i < smiles.Length; i++)
            {
                atomContainer[i] = sp.ParseSmiles(smiles[i]);

                inputList.Add(atomContainer[i]);
            }
            ///////////////////////////////////////////////////////////////////////////////////////////
            // Generate 2D coordinates for the input molecules with the Structure Diagram Generator

            StructureDiagramGenerator str;
            List <IAtomContainer>     resultList = new List <IAtomContainer>();

            foreach (var molecule in inputList)
            {
                str = new StructureDiagramGenerator()
                {
                    Molecule = molecule
                };
                str.GenerateCoordinates();
                resultList.Add(str.Molecule);
            }
            inputList = resultList;

            /////////////////////////////////////////////////////////////////////////////////////////////
            // Delete x and y coordinates

            foreach (var molecule in inputList)
            {
                foreach (var atom in molecule.Atoms)
                {
                    atom.Point2D = null;
                }
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////
            // Test for the method Model3DBuildersWithMM2ForceField
            var builder = CDK.Builder;

            ModelBuilder3D mb3d = ModelBuilder3D.GetInstance();

            for (var i = 0; i < inputList.Count; i++)
            {
                var input = inputList[i];
                {
                    // shallow copy
                    IAtomContainer mol = builder.NewAtomContainer(input);
                    try
                    {
                        mol = mb3d.Generate3DCoordinates(mol, false);
                        foreach (var a in mol.Atoms)
                        {
                            Assert.IsNotNull(a.Point3D, $"{smiles[0]} has unplaced atom");
                        }
                        CheckAverageBondLength(mol);
                    }
                    catch (Exception e)
                    {
                        if (e is CDKException || e is IOException)
                        {
                            Assert.Fail($"3D coordinated could not be generator for {smiles[i]}: {e.StackTrace}");
                        }
                        else
                        {
                            throw;
                        }
                    }
                }
            }
        }