problem with MolImporter

User 8201cee929

28-06-2007 13:23:29

Hi,


I'd like to load an sd file into Molecule objects using MolImporter (JChem 3.2.7) with the following code:





Code:
MolImporter oSDFileImporter = new MolImporter(sInputFile);


while(!oSDFileImporter.isEndReached()){


    Molecule  oMolecule = oSDFileImporter.read();


    System.out.println(oMolecule.toFormat("smiles")); //for test


}






When I run it I have a NullPointerException not on the read() function but on the print line. It seems that the isEndReached() doesn't find the end of the source file or I just missed something?


Thank you,


peter

ChemAxon a9ded07333

28-06-2007 13:27:57

Hi Peter,





Could you send the SD file?





Tamás

User 8201cee929

28-06-2007 14:17:20

Please find attached my sample file.


peter

ChemAxon a9ded07333

28-06-2007 16:05:22

Hi Peter,





There's no problem with your file, the error is in our system.


The isEndReached() method is misleading: it is not designed for checking the end of the file. You should check whether the molecule given back to you is null or not:





Code:



   MolImporter oSDFileImporter = new MolImporter(sInputFile);


   Molecule  oMolecule = oSDFileImporter.read();


   while(oMolecule != null){


       System.out.println(oMolecule.toFormat("smiles")); //for test


       oMolecule = oSDFileImporter.read();


   }








This way I could read your file.





Tamás

User 8201cee929

29-06-2007 07:01:51

Hi,


Thank you to clarify this point!


Now, I'm curious: what is the purpose of this function?


regards,


peter

ChemAxon a9ded07333

29-06-2007 10:34:24

It's used in estimating the number of records (see MolImporter.estimateNumRecords() in the API-doc: "If the end of file is already reached ...").


Probably should be a private method.





Tamás