How can I generate a 3D diagram using JChem API?

User 9d2c03e26a

17-06-2010 09:51:30

2D diagrams can be generated like this:


Molecule mol = new MolHandler(smiles).getMolecule();
byte[] content = mol.toBinFormat(format);


How about 3D? I don't see any document related to that.


Can anyone give me some hints? thanks


ChemAxon a3d59b832c

17-06-2010 11:47:16

Hi,


I moved this topic to the Marvin section of the forum, my colleagues will answer soon.


 


Best regards,


Szabolcs

ChemAxon efa1591b5a

17-06-2010 12:19:23

Hi,


well, the same, just make sure your structure is in 3D. The easiest way to generate the 3D conformation of your molecule is to call


	mol.clean(3,null);

before rendering it to an image. With this you can get images similar to what you see in MView or MSketch. 


Or do you mean sg fancy like in MarvinSpace?


 


Regards,


Miklos

User 9d2c03e26a

18-06-2010 04:26:53

Hi Miklos:


What I am looking for is to programatically generated a 3D diagram with a given SMILES string


No user interaction is involved within the process, and the result should be an image just like what we see in MarvinSpace


So it is some function like this: byte[ ] 3dContent = generate3D(String smiles)


I hope I am making myself clear this time.

ChemAxon efa1591b5a

18-06-2010 12:55:01

Hi,


Thank you for the clear explanation.


The image generation is the same step regardless of the depiction of molecule (2D or 3D):


byte[] content = mol.toBinFormat(format);

In case if you call 


mol.clean(2,null);

before the toBinFormat() (image generation) method then you get the 2D diagram of your molecule (regardless of its original input format, Smiles or anything else). In contrast to this, if you call


mol.clean(3,null);

before the image generation, then you get the 3D diagram.


So your code would look like this:


Molecule mol = new MolHandler(smiles).getMolecule();
mol.clean(3,null);
byte[] content = mol.toBinFormat(format); 

Just one related questions: is your molecule source a file, as in the above pseudo code, or you just used this MolHandler thing for the sake of illustration, but in practice your structures do not directly come from a file? In case they come form a smiles file, and apart from the 3D structure generation you do not perform any other transformation, just get the 3D diagram, then you may also consider the use of the molconverter program. It is capable of generating 3D structure and render structure diagrams in common image files (as jpeg, png etc.).


Regards


Miklos



User 9d2c03e26a

19-06-2010 02:25:48

Hi Miklos:


Thank you for the solution, it works well.


The molecule source refers to a whole column in an excel sheet which is generated by ChemDraw in smiles format, I use apache POI to read it.


Regarding the molconverter program, it is not helpful to me since we are doing all the things programmatically.


But I do have question with the following two lines:


Molecule mol = MolImporter.importMol(smiles, "smiles");
Molecule mol = new MolHandler(smiles).getMolecule();

I was told by one of your colleagues (via email) that they result the same molecule in case of smiles, but I would like to know the difference, or which one has the better performance.


Another question is still about 3D diagram generation, I use the format:


png:w500,h350,maxscale28,transbg,#ffffffff

To generate imges; in 2D the diagram is indeed transparent, but in 3D it always has a black background.


The document here does not mention too much about this.


Is it always black in order to have a 3D visual effect?

ChemAxon 42004978e8

23-06-2010 13:21:34

Hi,


Regarding the MolHandler and the MolImporter question:


The two possibilities use the same core for reading the molecule, there shouldn't be any difference in the speed. However MolHandler offers some other functionality beside importing molecules. With these the molecule can be manipulated, see http://www.chemaxon.com/jchem/doc/dev/java/api/chemaxon/util/MolHandler.html .


Bye,


Robert


 

ChemAxon 7c2d26e5cf

24-06-2010 20:45:51

About 3d background:


I have created the following code to test conversion. It works.


    MolImporter importer = new MolImporter(args[0]);
    Molecule mol = importer.read();
    if(mol.getDim() == 0) {
        mol.clean(3, null);
    }
    String format = args[1];
    byte[] data=mol.toBinFormat(format+":w500,h350,maxscale28,transbg");
    if(data == null) {
        System.err.println("Cannot export molecule in \""
                + format + "\" format.");
        System.exit(1);
    }
    String outfile = "output."+format;
    OutputStream out = new FileOutputStream(outfile);
    out.write(data);
    out.close();



Giving the background color (#ffffffff) is insufficent, since the transbg parameter determine the transparency of the image.