OECopyMolΒΆ

void OECopyMol(OEMolBase &dst, const OEMolBase &src,
               OEAtomBase **atommap=0, OEBondBase **bondmap=0)

Create a copy of the molecule src into the molecule dst. The mapping of the atoms and bonds between the two copies of the molecule can be retrieved by passing in arrays to the atommap and bondmap arguments. The size of the atommap array should be large enough to store src.GetMaxAtomIdx() atoms. The size of the bondmap array should be large enough to store src.GetMaxBondIdx() atoms. The new atom or bond in dst will be stored at the src atom or bond’s OEAtomBase.GetIdx location in the array.

The following code demonstrates how to access the atom associations output by the OECopyMol function.

using System;
using System.Collections.Generic;
using OpenEye.OEChem;

public class CopyMol 
{
    public static void Main(string[] argv) 
    {
        OEGraphMol src = new OEGraphMol(); 

        OEChem.OESmilesToMol(src, "c1ccccc1");

        // make holes in the molecule index space and juggle things around
        OEChem.OEAddExplicitHydrogens(src);
        OEChem.OESuppressHydrogens(src);
        OEChem.OEAddExplicitHydrogens(src);
        OEChem.OECanonicalOrderAtoms(src);

        OEAtomBasePtrArray atommap = new OEAtomBasePtrArray(src.GetMaxAtomIdx());
        
        OEGraphMol dst = new OEGraphMol();
        OEChem.OECopyMol(dst, src, atommap);

        foreach (OEAtomBase srcatom in src.GetAtoms()) 
        {
            OEAtomBase dstatom = atommap.GetItem((int)srcatom.GetIdx());
            Console.Write(srcatom.GetIdx() + " -> " + dstatom.GetIdx());
        }
    }
}