k-ujihara / NCDK

The Chemistry Development Kit ported to .NET
https://kazuyaujihara.github.io/NCDK/
GNU Lesser General Public License v2.1
35 stars 11 forks source link

error using StructureDiagramGenerator for 2D coodinates generation #24

Closed greatlse closed 3 years ago

greatlse commented 4 years ago

Hi kazuyaujihara,

I found an error when I tried to use StructureDiagramGenerator to get the 2d coodinates for a structure. The version NCDK is 1.5.6.0.

Please find the code below.

   public static void testNCDK(Boolean newSmiles)
    {
        var smi = "CCOC(=O)[C@]12CCC[C@]3([C@H]1CCC[C@H]3c1ccccc1)C2(F)F";
        var mol= Chem.MolFromSmiles(smi);

        // using SmilesGenerator to change the smiles string without any structure changes
        if (newSmiles)
        {
            SmilesGenerator smigen = new SmilesGenerator(SmiFlavors.UniversalSmiles);
            smi = smigen.Create(mol);
            Console.WriteLine(smi);
            mol = Chem.MolFromSmiles(smi);

        }

        StructureDiagramGenerator sdg = new StructureDiagramGenerator();
        ConnectivityChecker.PartitionIntoMolecules(mol);
        sdg.Molecule = mol;
        sdg.GenerateCoordinates();
        IAtomContainer layedOutMol = sdg.Molecule;
        String molblock = Chem.MolToMolBlock(layedOutMol);

        Console.WriteLine(molblock);
        Console.ReadLine();
    }

the error information is "“System.IndexOutOfRangeException”类型的未经处理的异常在 NCDK.dll 中发生 索引超出了数组界限。" Any suggestion is welcomed. Thanks very much. Best

greatlse commented 4 years ago

forget to notice you. there is no error when I use CDK to treat the same smiles string "CCOC(=O)[C@]12CCC[C@]3([C@H]1CCC[C@H]3c1ccccc1)C2(F)F".

k-ujihara commented 3 years ago

Fixed by https://github.com/kazuyaujihara/NCDK/commit/a88ec8da9a552ed0511efd8aed465e6ec851d3c1.