Hi John

Thanks a lot for the suggestion. This approach indeed looks very promising to 
me!

Instead of the ValidatorEngine, the following method let me reliably detect 
faulty molecules in both cases:

    private static boolean validate(IAtomContainer molecule) throws 
CDKException {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
        for (int i=0; i < molecule.getAtomCount(); i++) {
            if (null == molecule.getAtom(i).getValency()) {
                System.err.println("Valence Error on "+molecule.getAtom(i));
                return false;
            }
        }
        return true;
    }

    public static void main(String[] args) throws CDKException {
        SmilesParser sp  = new 
SmilesParser(SilentChemObjectBuilder.getInstance());
        System.out.println("[O-2] is valid: 
"+validate(sp.parseSmiles("[O-2]")));
        System.out.println("[O-3] is valid: 
"+validate(sp.parseSmiles("[O-3]")));
        System.out.println("[CH2]=O is valid: 
"+validate(sp.parseSmiles("[CH2]=O")));
        System.out.println("[CH3]=O is valid: 
"+validate(sp.parseSmiles("[CH3]=O")));
    }


Just what I wanted!

Many thanks and greetings,
Emanuel

From: John M [mailto:john.wilkinson...@gmail.com]
Sent: Monday, September 21, 2015 8:25 PM
To: cdkuser
Subject: Re: [Cdk-user] Molecule Validation

Hi,

One approach would be to try and assign atom types and check for null.. or it 
might even throw an exception.

AtomContainerManipulator.perceiveAndConfigureAtomTypes(mol); // or something 
similar

The atom types are finite opposed to empirical rules so might be too strict 
depending on your use case.

Regards,
John W May
john.wilkinson...@gmail.com<mailto:john.wilkinson...@gmail.com>

On 21 September 2015 at 10:20, Schmid Emanuel (ID SIS) 
<emanuel.sch...@id.ethz.ch<mailto:emanuel.sch...@id.ethz.ch>> wrote:
Hi

Is there a way to detect implausibility of molecules in general but in 
particular about valence errors:

E.g. the SMILES string "[CH4]=O" can of course be parsed to a formally correct 
molecule, but it obviously has a valence error on the C atom.
First, I thought the org.openscience.cdk.validate.ValidatorEngine is the 
instrument of choice, but either I'm using it wrongly or it is not in the least 
concerned about such a molecule.
But after all, for "[O-3]" it works as expected, I'm getting a Warning "Atom O 
has charge -3" from the BasicValidator.

I'm running this kind of code:

import org.openscience.cdk.exception.InvalidSmilesException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.validate.BasicValidator;
import org.openscience.cdk.validate.ValidationReport;
import org.openscience.cdk.validate.ValidationTest;
import org.openscience.cdk.validate.ValidatorEngine;

public class Snippet {

    private static boolean validate(IAtomContainer molecule) {
        ValidatorEngine validatorEngine = new ValidatorEngine();
        validatorEngine.addValidator(new BasicValidator());
        ValidationReport report = validatorEngine.validateMolecule(molecule);
        for (ValidationTest error : report.getErrors()){
            System.err.println(error.getDetails());
        }
        for (ValidationTest cdkerror : report.getCDKErrors()){
            System.err.println(cdkerror.getDetails());
        }
        for (ValidationTest warning : report.getWarnings()){
            System.err.println(warning.getDetails());
        }
        return report.getCount() == report.getOKCount();
    }
    public static void main(String[] args) throws InvalidSmilesException {
        SmilesParser sp  = new 
SmilesParser(SilentChemObjectBuilder.getInstance());
        System.out.println("[O-3] is valid: 
"+validate(sp.parseSmiles("[O-3]")));
        System.out.println("[CH4]=O is valid: 
"+validate(sp.parseSmiles("[CH4]=O")));
    }
}

and I'm getting this kind of output:

Atom O has charge -3
[O-3] is valid: false
[CH4]=O is valid: true


Can you give me guidance?

Many thanks and greetings,
Emanuel

------------------------------------------------------------------------------

_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net<mailto:Cdk-user@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/cdk-user

------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to