Molecule.clone doesn't seem to work!

User 07eebf78ca

20-12-2004 08:27:12

Hi,





I have a Molecule a. I call a.getDocument() and the returned value is non null. Then


I call Molecule b = (Molecule) a.clone(). After doing that, if I call b.clone(), the return value is null. That doesn't seem to be a clone! The Molecule a is actually obtained from MolImporter like this:


Code:
Molecule a = (Molecule) MolImported.importMol(somestring);



What should I do so that b.getDocument() return a non-null value? Please reply ASAP.





Thanks,


Sarav

ChemAxon 7c2d26e5cf

20-12-2004 13:11:12

Instead of mol.clone(), you should use the following code


Code:



        MDocument doc = mol.getDocument();


        Molecule m = doc != null? doc.cloneMainMolecule() : mol.cloneMolecule();





You can find the description of the above methods in the documentation


http://www.chemaxon.com/marvin/doc/api/chemaxon/struc/MoleculeGraph.html#getDocument()


http://www.chemaxon.com/marvin/doc/api/chemaxon/struc/MDocument.html#cloneMainMolecule()


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

User 20dc561d96

08-04-2005 00:40:37

I'm using an older version of JChem that doesn't support the Molecule.cloneMolecule() method. I need to make a copy of a Molecule instance that preserves all internal structures. Will the following code do this:





Code:



Molecule duplicateMolecule( Molecule mol ) {


    String strMol = mol.toFormat("mol");


    Molecule molCopy = new MolHandler( strMol ).getMolecule();


    return molCopy;


}





...





molecule2 = duplicateMolecule( molecule1 );





...











Or does this not guarantee that all internal data structures in molecule1 will be identical to molecule2? In particular, will molecule1.getAtomArray() and molecule2.getAtomArray() always return the same array of Atom objects in the same order?





Or do I need to upgrade to the latest version of JChem and use the Molecule.cloneMolecule() method?





Thanks,


Nolan

ChemAxon fb166edcbd

08-04-2005 11:03:54

You can use





Code:



Molecule molCopy = (Molecule) mol.clone();








instead of





Code:



Molecule molCopy = mol.cloneMolecule();