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 On 21 September 2015 at 10:20, Schmid Emanuel (ID SIS) < 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 > https://lists.sourceforge.net/lists/listinfo/cdk-user > >
------------------------------------------------------------------------------
_______________________________________________ Cdk-user mailing list Cdk-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cdk-user