SmilesExport not working

User 248fb9fe9c

13-08-2004 17:12:30

Hi,


I'm trying to convert a MOL file into a Smiles string. I can read it fine using:


MolImport importer = new MolImport();


MolInputStream mis = new MolInputStream(new FileInputStream("mol.txt"));


importer.initMolImport(mis, null);


Molecule molecule = importer.createMol();





So far, so good. I can call methods like getBondLength on the Molecule object and they seem to work. But now I need to export it as Smiles.





I tried toFormat("smiles"), that returns a string containing a newline only. I tried the following:


SmilesExport exporter = new SmilesExporter();


exporter.open(null);


String smiles = (String) exporter.convert(molecule);


exporter.close();





But that also returns a string with just a newline in it.





What am I doing wrong?





I'm using JDK 1.4.2 on Solaris 8, a machine that has a display (so this is not a headless problem). All I have on my classpath is marvin.jar and the marvin directory (containing the unpacked compiled chemaxon.marvin classes including the modules). No exceptions are thrown by the program.





Your help is much appreciated. Thanks, and have a good weekend ;)

ChemAxon 7c2d26e5cf

13-08-2004 18:14:05

I think you chosen a too complicated way for conversion.


Why don't you use MolImporter?


http://www.chemaxon.com/marvin/doc/api/chemaxon/formats/MolImporter.html





Its using is very simple:


Code:



   MolImporter importer = new MolImporter(molfile);


   Molecule mol = importer.read();


   String result = mol.toFormat("smiles");





If you would like to use MolImport you should modify your code like this:


Code:



        MolImport importer = new MolImport();


        MolInputStream mis = new MolInputStream(new FileInputStream("mol.txt"));


        importer.initMolImport(mis, null);


        Molecule molecule = importer.createMol();


        importer.readMol(molecule);


        String result = molecule.toFormat("smiles");





MolImport.creatMol creates only an empty molecule. To read a molecule from the input stream, you should also use MolImporter.readMol.


http://www.chemaxon.com/marvin/doc/api/chemaxon/marvin/modules/MolImport.html#readMol(chemaxon.struc.Molecule)

User 248fb9fe9c

13-08-2004 19:09:48

Thanks for the rapid response. I would love to use MolImporter, but I can't find it (the compiled class or a jar containing it) in my download. Where is it located?

User 248fb9fe9c

13-08-2004 19:23:49

Hi,


OK, using your 2nd code snippet, I was able to get the import to work, as well as export to smiles and mol formats. Now I'm trying to export as JPEG without success. Here's my code, and if anyone could offer suggestions as to what I'm doing wrong, I would appreciate it ;)





MolImport mi = new MolImport();


MolInputStream mis = new MolInputStream(new FileInputStream("mol.txt"));


mi.initMolImport(mis, null);


Molecule molecule = mi.createMol();


mi.readMol(molecule);





// This works fine


System.out.println(molecule.toFormat("smiles"));


// This outputs null


byte[] jpeg = molecule.toBinFormat("jpeg");


if(jpeg == null) {


System.out.println("JPEG is null.");


} else {


// Write to a file...


}





? Thanks, and have a good weekend ;)

ChemAxon 7c2d26e5cf

13-08-2004 19:33:35

Quote:
Thanks for the rapid response. I would love to use MolImporter, but I can't find it (the compiled class or a jar containing it) in my download. Where is it located?
MolImporter is located in chemaxon.formats package. You can find it in lib/MarvinBeans.jar.

ChemAxon 7c2d26e5cf

13-08-2004 19:41:22

Please see the examples/converter/SimpleConverter.java example in the Marvin Beans package.


It demonstrates how you can convert a molecule to an image.


http://www.chemaxon.com/marvin/examples/converter/SimpleConverter.java.txt