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

BasicValidator.ValidIsotopeExistence problem #10

Closed ghost closed 6 years ago

ghost commented 6 years ago

BasicValidator.ValidIsotopeExistence smiles with no isotope information e.g. "CC" throws error "Isotope with this mass number is not known for this element." NCDK (and also cdk) code is

                if (isotope.MassNumber != 0)

should be

                if (isotope.MassNumber != null)

test code, call

        validate("CC");
        validate("[13C]C");
        validate("[30C]C");

        private static void validate(string s) {    
            var builder = ChemObjectBuilder.Instance;
            ModelBuilder3D builder3D = ModelBuilder3D.GetInstance(builder);
            IAtomContainer m = builder3D.Generate3DCoordinates(molecule: smilesToMol(s), clone: false);
            var engine  = new ValidatorEngine();
            engine.Add(new BasicValidator());
            engine.Add(new CDKValidator());
            engine.Add(new Geometry3DValidator());
            var report = engine.ValidateMolecule(m);

            for(int i=0;i<report.Errors.Count;i++){
                Console.WriteLine("Valdation errors are: " +report.Errors[i].Error);
            }
        }
    private static IAtomContainer smilesToMol(string s)
    {
        var builder = ChemObjectBuilder.Instance;
        var m = new SmilesParser(builder).ParseSmiles(s);
        m = MoleculeSanityCheck.CheckAndCleanMolecule(m);

        AtomContainerManipulator.ConvertImplicitToExplicitHydrogens(m);
        AtomContainerManipulator.PercieveAtomTypesAndConfigureUnsetProperties(m);
        return m;
    }