personal issue with image making

ChemAxon 587f88acea

31-08-2004 14:25:54

hello,





I'd like to make files like jpeg or png from a Molecule.


I used toBinFormat(...) and I write the byte[] I get in a file thanks to the java.io.RandomAccessFile and its method write(byte[] b, int off, int len) and write(byte[] b); and here is my problem : the picture I get only contains the first atom of my smiles expression that I used to make the Molecule (I tryed with other smiles).





Code:



File ftmp = File.createTempFile("mol",".png","./");


RandomAccessFile raf = new RandomAccessFile(ftmp,"rw");


MolHandler mh = new MolHandler("N1C=CC=C1");


Molecule molec = mh.getMolecule();


raf.write(molec.toBinFormat("png:w250,h250,b32,#ededed,wireframe"));


raf.close();








I join the picture I got.





I think that I missed something but I don't manage to find what... :(





thanks and bye.

ChemAxon 7c2d26e5cf

31-08-2004 14:45:55

You should clean the molecule before the image export. MolHandler does not generate molecule coordinates automatically at SMILES import.


If you miss it, each atom will be in the same coordinates.





Thus, you should modify your code like this:


Code:



File ftmp = File.createTempFile("mol",".png","./");


RandomAccessFile raf = new RandomAccessFile(ftmp,"rw");


MolHandler mh = new MolHandler("N1C=CC=C1");


Molecule molec = mh.getMolecule();





// calculate coordinates if it is necessary


if(molec.getDim() < 2) {


    molec.clean(2,"O1");


}





raf.write(molec.toBinFormat("png:w250,h250,b32,#ededed,wireframe"));


raf.close();


ChemAxon 587f88acea

31-08-2004 14:57:26

that's a splendid and quick response you gave me !!!





I should look at the API more seriously. ;)


Sorry to have disturb you for that and thank you again.





bye

ChemAxon 7c2d26e5cf

23-09-2004 16:30:23

We have simplified the issue. Image export generates atom coordinates if the molecule's dimension is zero (no atom coordinates).


The cleaning of the molecule before image export will be unnecessary from Marvin 3.5.