示例#1
0
        public override ICDKObject Clone(CDKObjectMap map)
        {
            var clone = (SingleElectron)base.Clone(map);

            clone.atom = (IAtom)atom?.Clone(map);
            return(clone);
        }
        private static IAtomContainer PermuteA(int[] p, IAtomContainer atomContainer)
        {
            IAtomContainer permutedContainer = null;

            permutedContainer = atomContainer.Builder.NewAtomContainer();
            foreach (var pp in p)
            {
                IAtom atom = atomContainer.Atoms[pp];
                permutedContainer.Atoms.Add((IAtom)atom.Clone());
            }
            foreach (var bond in atomContainer.Bonds)
            {
                IBond clonedBond = (IBond)bond.Clone();
                clonedBond.SetAtoms(new IAtom[clonedBond.Atoms.Count]);
                int i = 0;
                foreach (var atom in bond.Atoms)
                {
                    int   index        = atomContainer.Atoms.IndexOf(atom);
                    IAtom permutedAtom = permutedContainer.Atoms[p[index]];
                    clonedBond.Atoms[i++] = permutedAtom;
                }
                permutedContainer.Bonds.Add(clonedBond);
            }
            return(permutedContainer);
        }
示例#3
0
        public override ICDKObject Clone(CDKObjectMap map)
        {
            var clone = (LonePair)base.Clone(map);

            clone.atom = (IAtom)atom?.Clone(map);
            return(clone);
        }
示例#4
0
        public virtual void TestCloneFractionalPoint3d()
        {
            IAtom atom = (IAtom)NewChemObject();

            atom.FractionalPoint3D = new Vector3(2, 3, 4);
            IAtom clone = (IAtom)atom.Clone();

            Assert.AreEqual(clone.FractionalPoint3D.Value.X, 2.0, 0.001);
        }
示例#5
0
        public virtual void TestClonePoint2d()
        {
            IAtom atom = (IAtom)NewChemObject();

            atom.Point2D = new Vector2(2, 3);
            IAtom clone = (IAtom)atom.Clone();

            Assert.AreEqual(clone.Point2D.Value.X, 2.0, 0.001);
        }
示例#6
0
        public virtual void TestCloneCharge()
        {
            IAtom atom = (IAtom)NewChemObject();

            atom.Charge = 1.0;
            IAtom clone = (IAtom)atom.Clone();

            // test cloning
            atom.Charge = 5.0;
            Assert.AreEqual(1.0, clone.Charge.Value, 0.001);
        }
示例#7
0
        public virtual void TestCloneStereoParity()
        {
            IAtom atom = (IAtom)NewChemObject();

            atom.StereoParity = 3;
            IAtom clone = (IAtom)atom.Clone();

            // test cloning
            atom.StereoParity = 4;
            Assert.AreEqual(3, clone.StereoParity);
        }
示例#8
0
        public virtual void TestCloneHydrogenCount()
        {
            IAtom atom = (IAtom)NewChemObject();

            atom.ImplicitHydrogenCount = 3;
            IAtom clone = (IAtom)atom.Clone();

            // test cloning
            atom.ImplicitHydrogenCount = 4;
            Assert.AreEqual(3, clone.ImplicitHydrogenCount.Value);
        }
示例#9
0
        public override void TestClone()
        {
            IAtom  atom  = (IAtom)NewChemObject();
            object clone = atom.Clone();

            Assert.IsTrue(clone is IAtom);

            // test that everything has been cloned properly
            string diff = AtomDiff.Diff(atom, (IAtom)clone);

            Assert.IsNotNull(diff);
            Assert.AreEqual(0, diff.Length);
        }
示例#10
0
        /// <summary> Clones this AtomParity object.
        ///
        /// </summary>
        /// <returns>  The cloned object
        /// </returns>
        public override System.Object Clone()
        {
            AtomParity clone = (AtomParity)base.Clone();

            // clone Atom's
            clone.centralAtom  = (IAtom)centralAtom.Clone();
            clone.neighbors    = new IAtom[4];
            clone.neighbors[0] = (IAtom)(neighbors[0].Clone());
            clone.neighbors[1] = (IAtom)(neighbors[1].Clone());
            clone.neighbors[2] = (IAtom)(neighbors[2].Clone());
            clone.neighbors[3] = (IAtom)(neighbors[3].Clone());
            return(clone);
        }
        public void TestMap_Map_Map()
        {
            IChemObjectBuilder builder = ChemObjectBuilder.Instance;

            IAtom c1 = builder.NewAtom("C");
            IAtom o2 = builder.NewAtom("O");
            IAtom n3 = builder.NewAtom("N");
            IAtom c4 = builder.NewAtom("C");
            IAtom h5 = builder.NewAtom("H");

            // new stereo element
            ITetrahedralChirality original = new TetrahedralChirality(c1, new IAtom[] { o2, n3, c4, h5 }, TetrahedralStereo.Clockwise);

            // clone the atoms and place in a map
            var   mapping = new CDKObjectMap();
            IAtom c1clone = (IAtom)c1.Clone();

            mapping.Set(c1, c1clone);
            IAtom o2clone = (IAtom)o2.Clone();

            mapping.Set(o2, o2clone);
            IAtom n3clone = (IAtom)n3.Clone();

            mapping.Set(n3, n3clone);
            IAtom c4clone = (IAtom)c4.Clone();

            mapping.Set(c4, c4clone);
            IAtom h5clone = (IAtom)h5.Clone();

            mapping.Set(h5, h5clone);

            // map the existing element a new element
            ITetrahedralChirality mapped = (ITetrahedralChirality)original.Clone(mapping);

            Assert.AreNotSame(original.ChiralAtom, mapped.ChiralAtom, "mapped chiral atom was the same as the original");
            Assert.AreSame(c1clone, mapped.ChiralAtom, "mapped chiral atom was not the clone");

            var originalLigands = original.Ligands;
            var mappedLigands   = mapped.Ligands;

            Assert.AreNotSame(originalLigands[0], mappedLigands[0], "first ligand was the same as the original");
            Assert.AreSame(o2clone, mappedLigands[0], "first mapped ligand was not the clone");
            Assert.AreNotSame(originalLigands[1], mappedLigands[1], "second ligand was the same as the original");
            Assert.AreSame(n3clone, mappedLigands[1], "second mapped ligand was not the clone");
            Assert.AreNotSame(originalLigands[2], mappedLigands[2], "third ligand was the same as the original");
            Assert.AreSame(c4clone, mappedLigands[2], "third mapped ligand was not the clone");
            Assert.AreNotSame(originalLigands[3], mappedLigands[3], "forth ligand was te same as the original");
            Assert.AreSame(h5clone, mappedLigands[3], "forth mapped ligand was not the clone");

            Assert.AreEqual(original.Stereo, mapped.Stereo, "stereo was not mapped");
        }
示例#12
0
 /// <inheritdoc/>
 public override ICDKObject Clone(CDKObjectMap map)
 {
     return(atom.Clone(map));
 }
示例#13
0
        /// <summary> Produces an AtomContainer without explicit Hs but with H count from one with Hs.
        /// The new molecule is a deep copy.
        ///
        /// </summary>
        /// <param name="atomContainer">The AtomContainer from which to remove the hydrogens
        /// </param>
        /// <returns>              The molecule without Hs.
        /// </returns>
        /// <cdk.keyword>          hydrogen, removal </cdk.keyword>
        public static IAtomContainer removeHydrogens(IAtomContainer atomContainer)
        {
            //UPGRADE_TODO: Class 'java.util.HashMap' was converted to 'System.Collections.Hashtable' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilHashMap'"
            System.Collections.IDictionary map    = new System.Collections.Hashtable(); // maps original atoms to clones.
            System.Collections.IList       remove = new System.Collections.ArrayList(); // lists removed Hs.

            // Clone atoms except those to be removed.
            IMolecule mol   = atomContainer.Builder.newMolecule();
            int       count = atomContainer.AtomCount;

            for (int i = 0; i < count; i++)
            {
                // Clone/remove this atom?
                IAtom atom = atomContainer.getAtomAt(i);
                if (!atom.Symbol.Equals("H"))
                {
                    IAtom clonedAtom = null;
                    try
                    {
                        clonedAtom = (IAtom)atom.Clone();
                    }
                    //UPGRADE_NOTE: Exception 'java.lang.CloneNotSupportedException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
                    catch (System.Exception e)
                    {
                        // TODO Auto-generated catch block
                        SupportClass.WriteStackTrace(e, Console.Error);
                    }
                    clonedAtom.setHydrogenCount(0);
                    mol.addAtom(clonedAtom);
                    map[atom] = clonedAtom;
                }
                else
                {
                    remove.Add(atom); // maintain list of removed H.
                }
            }

            // Clone bonds except those involving removed atoms.
            count = atomContainer.getBondCount();
            for (int i = 0; i < count; i++)
            {
                // Check bond.
                //UPGRADE_NOTE: Final was removed from the declaration of 'bond '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                IBond   bond        = atomContainer.getBondAt(i);
                IAtom[] atoms       = bond.getAtoms();
                bool    removedBond = false;
                //UPGRADE_NOTE: Final was removed from the declaration of 'length '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                int length = atoms.Length;
                for (int k = 0; k < length; k++)
                {
                    if (remove.Contains(atoms[k]))
                    {
                        removedBond = true;
                        break;
                    }
                }

                // Clone/remove this bond?
                if (!removedBond)
                // if (!remove.contains(atoms[0]) && !remove.contains(atoms[1]))
                {
                    IBond clone = null;
                    try
                    {
                        clone = (IBond)atomContainer.getBondAt(i).Clone();
                    }
                    //UPGRADE_NOTE: Exception 'java.lang.CloneNotSupportedException' was converted to 'System.Exception' which has different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1100'"
                    catch (System.Exception e)
                    {
                        // TODO Auto-generated catch block
                        SupportClass.WriteStackTrace(e, Console.Error);
                    }
                    clone.setAtoms(new IAtom[] { (IAtom)map[atoms[0]], (IAtom)map[atoms[1]] });
                    mol.addBond(clone);
                }
            }

            // Recompute hydrogen counts of neighbours of removed Hydrogens.
            //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
            for (System.Collections.IEnumerator i = remove.GetEnumerator(); i.MoveNext();)
            {
                // Process neighbours.
                //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                //UPGRADE_TODO: Method 'java.util.Iterator.hasNext' was converted to 'System.Collections.IEnumerator.MoveNext' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratorhasNext'"
                for (System.Collections.IEnumerator n = atomContainer.getConnectedAtomsVector((IAtom)i.Current).GetEnumerator(); n.MoveNext();)
                {
                    //UPGRADE_NOTE: Final was removed from the declaration of 'neighb '. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1003'"
                    //UPGRADE_TODO: Method 'java.util.Iterator.next' was converted to 'System.Collections.IEnumerator.Current' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilIteratornext'"
                    IAtom neighb = (IAtom)map[n.Current];
                    neighb.setHydrogenCount(neighb.getHydrogenCount() + 1);
                }
            }
            mol.Properties = atomContainer.Properties;
            mol.Flags      = atomContainer.Flags;

            return(mol);
        }