Your code works properly, thank you very much for the fast answer! A look in the SMARTSQueryTool#matches method shows the problem: The molecule have to be initialized before searching. SMARTSQueryTool does this implicit.
Kai Quoting Rajarshi Guha <[email protected]>: > You should be using the SMARTSQueryTool > > SMARTSQueryTool sqt = new SMARTSQueryTool("[a]") > if (sqt.matches(mol)) { > // do stuff > } > > Do you still get this error with the above code? > > On Wed, Jul 28, 2010 at 12:20 PM, <[email protected]> wrote: >> Hi, >> >> I'm trying to search a substructure in a molecule by a given SMART >> pattern. So I searched for a java library which supports SMART >> patterns. CDK looks like a very professional framework, although I >> wish I could find a smaller library which just support SMART and not >> hundred features more ^^ >> >> Nevertheless, I include the cdk jar file and try following code: >> >> Mol2Reader mr = new Mol2Reader(new FileReader(new File(filename))); >> final IMolecule molecule = (IMolecule)mr.read(new Molecule()); >> final QueryAtomContainer query = SMARTSParser.parse("[#8]"); >> final boolean b = UniversalIsomorphismTester.isSubgraph(molecule, query); >> System.out.println(b); // true >> >> It works. Next I changed the pattern into "[#8D2]". Now following >> error message occurs: >> >> Exception in thread "main" java.lang.NullPointerException >> at >> org.openscience.cdk.isomorphism.matchers.smarts.ExplicitConnectionAtom.matches(ExplicitConnectionAtom.java:60) >> at >> org.openscience.cdk.isomorphism.matchers.smarts.LogicalOperatorAtom.matches(LogicalOperatorAtom.java:82) >> at >> org.openscience.cdk.isomorphism.UniversalIsomorphismTester.isSubgraph(UniversalIsomorphismTester.java:337) >> at TestMol2.main(TestMol2.java:33) >> >> I looked in the source code and find following: >> atom.getProperty(CDKConstants.TOTAL_CONNECTIONS) >> >> This property isn't defined in my atoms. In fact, there are no >> properties defined in my atoms. So how can I load atoms which full >> property sets so that substructure search works properly? >> >> I thank you very much in advance, >> Kai >> >> >> >> >> ------------------------------------------------------------------------------ >> The Palm PDK Hot Apps Program offers developers who use the >> Plug-In Development Kit to bring their C/C++ apps to Palm for a share >> of $1 Million in cash or HP Products. Visit us here for more details: >> http://p.sf.net/sfu/dev2dev-palm >> _______________________________________________ >> Cdk-user mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/cdk-user >> > > > > -- > Rajarshi Guha > NIH Chemical Genomics Center > ------------------------------------------------------------------------------ The Palm PDK Hot Apps Program offers developers who use the Plug-In Development Kit to bring their C/C++ apps to Palm for a share of $1 Million in cash or HP Products. Visit us here for more details: http://p.sf.net/sfu/dev2dev-palm _______________________________________________ Cdk-user mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cdk-user

