RgMolecule

User 870ab5b546

23-01-2008 16:34:44

Hi,





The documentation for the RgMolecule class is sparse. How does one create a new RgMolecule from a Molecule that contains R groups?





-- Bob

ChemAxon a3d59b832c

23-01-2008 16:46:46

I moved the question to the "Structure editing, viewing and file formats" forum, which also deals with molecular representation questions. My colleagues will answer your question soon.

ChemAxon e500b51457

24-01-2008 20:24:19

Hi,





Could you describe me the problem with an example, please?





Thanks,


Erika.

ChemAxon 42004978e8

25-01-2008 08:25:04

Hello,





If the Molecule object is read from an .mrv (or other file) that describes an RgMolecule then you can cast the Molecule to an RgMolecule.





e.g. (assuming smol is a molecule object as described above)





Code:
 if (smol instanceof RgMolecule) {


            RgMolecule rgSmol = (RgMolecule) smol;


....






However if you cast a "normal" Molecule to an RgMolecule than you will get an exception.





Please let us know, if this doesn't work!


Robert

User 870ab5b546

25-01-2008 14:02:43

(1) What exception will be thrown? We will want to catch it.





(2) Just to be clear: A "normal" Molecule in this context is one that has no R groups. Any Molecule that has at least one R group can be cast to an RgMolecule.

ChemAxon 42004978e8

25-01-2008 14:20:03

Hi Bob,





To (I): A ClassCastException is thrown.





To (II): I meant "normal" just as you wrote.





Best Regards,


Robert

ChemAxon 7c2d26e5cf

27-01-2008 13:58:34

MolImporter.read() can return with Molecule, RxnMolecule or RgMolecule object or null (if no more input).





If the molecule source describe a single molecule (not a reaction) and it does not include any R-group, the output will be a Molecule object.


RxnMolecule is created when the molecule source defines a reactions without query features.


In any other cases, RgMolecule is created.





So the following code is correct and it can not drop ClassCastException.


Code:
String filename;


...


MolImporter importer = new MolImporter(filename);


Molecule mol = importer.read();


if(mol instanceof RgMolecule) {


    RgMolecule rgmol = (RgMolecule) mol;


}






If you would not like to take care with casting, you can force MolImporter to give always RgMolecule. Use MolImporter.read(Molecule) and give an existing RgMolecule object to use this one instead of a new one by reading.


Code:
String filename;


...


MolImporter importer = new MolImporter(filename);


RgMolecule rgmol = new RgMolecule();


importer.read(rgmol);

User 870ab5b546

27-01-2008 15:12:34

And if I force MolImporter to give an RgMolecule, will an exception be thrown if the imported RgMolecule contains no R groups? Or will I just get an RgMolecule with zero R groups?

ChemAxon 7c2d26e5cf

27-01-2008 16:15:43

Quote:
And if I force MolImporter to give an RgMolecule, will an exception be thrown if the imported RgMolecule contains no R groups? Or will I just get an RgMolecule with zero R groups?
No, it does not cause any problem. Of course, in this case, RgMolecule.getRgroupCount returns with 0.