Example #1
0
        /// <summary> Returns the adjacency matrix for the given AtomContainer.
        ///
        /// </summary>
        /// <param name="container">The AtomContainer for which the matrix is calculated
        /// </param>
        /// <returns>           A adjacency matrix representating this AtomContainer
        /// </returns>
        public static int[][] getMatrix(IAtomContainer container)
        {
            IElectronContainer electronContainer = null;
            int indexAtom1;
            int indexAtom2;

            int[][] conMat = new int[container.AtomCount][];
            for (int i = 0; i < container.AtomCount; i++)
            {
                conMat[i] = new int[container.AtomCount];
            }
            for (int f = 0; f < container.ElectronContainerCount; f++)
            {
                electronContainer = container.getElectronContainerAt(f);
                if (electronContainer is IBond)
                {
                    IBond bond = (IBond)electronContainer;
                    indexAtom1 = container.getAtomNumber(bond.getAtomAt(0));
                    indexAtom2 = container.getAtomNumber(bond.getAtomAt(1));
                    conMat[indexAtom1][indexAtom2] = 1;
                    conMat[indexAtom2][indexAtom1] = 1;
                }
            }
            return(conMat);
        }
 /// <summary>  Makes an array containing the morgan numbers of the atoms of atomContainer.
 /// 
 /// </summary>
 /// <param name="atomContainer"> The atomContainer to analyse.
 /// </param>
 /// <returns>                The morgan numbers value.
 /// </returns>
 public static int[] getMorganNumbers(IAtomContainer atomContainer)
 {
     int[] morganMatrix;
     int[] tempMorganMatrix;
     int N = atomContainer.AtomCount;
     morganMatrix = new int[N];
     tempMorganMatrix = new int[N];
     IAtom[] atoms = null;
     for (int f = 0; f < N; f++)
     {
         morganMatrix[f] = atomContainer.getBondCount(f);
         tempMorganMatrix[f] = atomContainer.getBondCount(f);
     }
     for (int e = 0; e < N; e++)
     {
         for (int f = 0; f < N; f++)
         {
             morganMatrix[f] = 0;
             atoms = atomContainer.getConnectedAtoms(atomContainer.getAtomAt(f));
             for (int g = 0; g < atoms.Length; g++)
             {
                 morganMatrix[f] += tempMorganMatrix[atomContainer.getAtomNumber(atoms[g])];
             }
         }
         Array.Copy(morganMatrix, 0, tempMorganMatrix, 0, N);
     }
     return tempMorganMatrix;
 }
        /// <summary>  Makes an array containing the morgan numbers of the atoms of atomContainer.
        ///
        /// </summary>
        /// <param name="atomContainer"> The atomContainer to analyse.
        /// </param>
        /// <returns>                The morgan numbers value.
        /// </returns>
        public static int[] getMorganNumbers(IAtomContainer atomContainer)
        {
            int[] morganMatrix;
            int[] tempMorganMatrix;
            int   N = atomContainer.AtomCount;

            morganMatrix     = new int[N];
            tempMorganMatrix = new int[N];
            IAtom[] atoms = null;
            for (int f = 0; f < N; f++)
            {
                morganMatrix[f]     = atomContainer.getBondCount(f);
                tempMorganMatrix[f] = atomContainer.getBondCount(f);
            }
            for (int e = 0; e < N; e++)
            {
                for (int f = 0; f < N; f++)
                {
                    morganMatrix[f] = 0;
                    atoms           = atomContainer.getConnectedAtoms(atomContainer.getAtomAt(f));
                    for (int g = 0; g < atoms.Length; g++)
                    {
                        morganMatrix[f] += tempMorganMatrix[atomContainer.getAtomNumber(atoms[g])];
                    }
                }
                Array.Copy(morganMatrix, 0, tempMorganMatrix, 0, N);
            }
            return(tempMorganMatrix);
        }
Example #4
0
        /// <summary>
        /// Remove the following features from a molecule
        ///  - Atom non-standard mass
        ///  - Stereo chemistry
        ///  - explicit hydrogens
        /// </summary>
        /// <param name="src"></param>
        /// <returns>Modified mol</returns>

        public static IAtomContainer RemoveIsotopesStereoExplicitHydrogens(
            IAtomContainer src)
        {
            IAtom[] atoms = new IAtom[src.getAtomCount()];
            IBond[] bonds = new IBond[src.getBondCount()];

            IChemObjectBuilder builder = src.getBuilder();

            for (int i = 0; i < atoms.Length; i++)
            {
                IAtom atom  = src.getAtom(i);
                IAtom atom2 = (IAtom)builder.newInstance(typeof(IAtom), atom.getSymbol());
                SetImplicitHydrogenCount(atom2, GetImplicitHydrogenCount(atom));
                atom2.setPoint2d(atom.getPoint2d());
                atoms[i] = atom2;
            }

            for (int i = 0; i < bonds.Length; i++)
            {
                IBond bond = src.getBond(i);

                int   u     = src.getAtomNumber(bond.getAtom(0));
                int   v     = src.getAtomNumber(bond.getAtom(1));
                IBond bond2 = (IBond)builder.newInstance(typeof(IBond), atoms[u], atoms[v]);

                bond2.setIsAromatic(bond.isAromatic());
                bond2.setIsInRing(bond.isInRing());
                bond2.setOrder(bond.getOrder());

                bond2.setFlag(CDKConstants.ISAROMATIC, bond.getFlag(CDKConstants.ISAROMATIC));
                bond2.setFlag(CDKConstants.SINGLE_OR_DOUBLE, bond.getFlag(CDKConstants.SINGLE_OR_DOUBLE));

                bonds[i] = bond2;
            }

            IAtomContainer dest = (IAtomContainer)builder.newInstance(typeof(IAtomContainer));

            dest.setAtoms(atoms);
            dest.setBonds(bonds);

            AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(dest);
            dest = AtomContainerManipulator.suppressHydrogens(dest);
            GetHydrogenAdder().addImplicitHydrogens(dest);

            return(dest);
        }
Example #5
0
        public String toString(IAtomContainer ac)
        {
            String s = "Path of length " + Count + ": ";

            for (int f = 0; f < Count; f++)
            {
                s += ac.getAtomNumber((IAtom)this[f]) + " ";
            }
            return(s);
        }
 /// <summary> Returns the adjacency matrix for the given AtomContainer.
 /// 
 /// </summary>
 /// <param name="container">The AtomContainer for which the matrix is calculated
 /// </param>
 /// <returns>           A adjacency matrix representating this AtomContainer
 /// </returns>
 public static int[][] getMatrix(IAtomContainer container)
 {
     IElectronContainer electronContainer = null;
     int indexAtom1;
     int indexAtom2;
     int[][] conMat = new int[container.AtomCount][];
     for (int i = 0; i < container.AtomCount; i++)
     {
         conMat[i] = new int[container.AtomCount];
     }
     for (int f = 0; f < container.ElectronContainerCount; f++)
     {
         electronContainer = container.getElectronContainerAt(f);
         if (electronContainer is IBond)
         {
             IBond bond = (IBond)electronContainer;
             indexAtom1 = container.getAtomNumber(bond.getAtomAt(0));
             indexAtom2 = container.getAtomNumber(bond.getAtomAt(1));
             conMat[indexAtom1][indexAtom2] = 1;
             conMat[indexAtom2][indexAtom1] = 1;
         }
     }
     return conMat;
 }
Example #7
0
 public static bool replaceAtomByAtom(IAtomContainer container, IAtom atom, IAtom newAtom)
 {
     if (!container.contains(atom))
     {
         // it should complain
         return(false);
     }
     else
     {
         container.setAtomAt(container.getAtomNumber(atom), newAtom);
         IElectronContainer[] electronContainers = container.ElectronContainers;
         for (int i = 0; i < electronContainers.Length; i++)
         {
             if (electronContainers[i] is IBond)
             {
                 IBond bond = (IBond)electronContainers[i];
                 if (bond.contains(atom))
                 {
                     for (int j = 0; j < bond.AtomCount; j++)
                     {
                         if (atom.Equals(bond.getAtomAt(j)))
                         {
                             bond.setAtomAt(newAtom, j);
                         }
                     }
                 }
             }
             else if (electronContainers[i] is ILonePair)
             {
                 ILonePair lonePair = (ILonePair)electronContainers[i];
                 if (atom.Equals(lonePair.Atom))
                 {
                     lonePair.Atom = newAtom;
                 }
             }
         }
         return(true);
     }
 }
 public static bool replaceAtomByAtom(IAtomContainer container, IAtom atom, IAtom newAtom)
 {
     if (!container.contains(atom))
     {
         // it should complain
         return false;
     }
     else
     {
         container.setAtomAt(container.getAtomNumber(atom), newAtom);
         IElectronContainer[] electronContainers = container.ElectronContainers;
         for (int i = 0; i < electronContainers.Length; i++)
         {
             if (electronContainers[i] is IBond)
             {
                 IBond bond = (IBond)electronContainers[i];
                 if (bond.contains(atom))
                 {
                     for (int j = 0; j < bond.AtomCount; j++)
                     {
                         if (atom.Equals(bond.getAtomAt(j)))
                         {
                             bond.setAtomAt(newAtom, j);
                         }
                     }
                 }
             }
             else if (electronContainers[i] is ILonePair)
             {
                 ILonePair lonePair = (ILonePair)electronContainers[i];
                 if (atom.Equals(lonePair.Atom))
                 {
                     lonePair.Atom = newAtom;
                 }
             }
         }
         return true;
     }
 }
Example #9
0
 /// <summary>  Returns a Map with the AtomNumbers, the first number corresponds to the first (or the largest
 /// AtomContainer) atomContainer. 
 /// 
 /// Only for similar and aligned molecules with coordinates!
 /// 
 /// </summary>
 /// <param name="firstAtomContainer">               the (largest) first aligned AtomContainer which is the reference
 /// </param>
 /// <param name="secondAtomContainer">              the second aligned AtomContainer
 /// </param>
 /// <returns>                   				a Map of the mapped atoms
 /// </returns>
 /// <exception cref="CDKException"> Description of the Exception
 /// </exception>
 public static System.Collections.IDictionary mapAtomsOfAlignedStructures(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer, System.Collections.IDictionary mappedAtoms)
 {
     //System.out.println("**** GT MAP ATOMS ****");
     //Map atoms onto each other
     if (firstAtomContainer.AtomCount < 1 & secondAtomContainer.AtomCount < 1)
     {
         return mappedAtoms;
     }
     RMap map;
     IAtom atom1;
     IAtom atom2;
     int countMappedAtoms = 0;
     System.Collections.IList list;
     try
     {
         list = UniversalIsomorphismTester.getSubgraphAtomsMap(firstAtomContainer, secondAtomContainer);
         //System.out.println("ListSize:"+list.size());
         for (int i = 0; i < list.Count; i++)
         {
             map = (RMap)list[i];
             atom1 = firstAtomContainer.getAtomAt(map.Id1);
             atom2 = secondAtomContainer.getAtomAt(map.Id2);
             if (checkAtomMapping(firstAtomContainer, secondAtomContainer, firstAtomContainer.getAtomNumber(atom1), secondAtomContainer.getAtomNumber(atom2)))
             {
                 mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(atom1)] = (System.Int32)secondAtomContainer.getAtomNumber(atom2);
                 countMappedAtoms++;
                 //System.out.println("#:"+countMappedAtoms+" Atom:"+firstAtomContainer.getAtomNumber(atom1)+" is mapped to Atom:"+secondAtomContainer.getAtomNumber(atom2));
             }
             else
             {
                 System.Console.Out.WriteLine("Error: Atoms are not similar !!");
             }
         }
     }
     catch (CDKException e)
     {
         // TODO Auto-generated catch block
         System.Console.Out.WriteLine("Error in UniversalIsomorphismTester due to:");
         SupportClass.WriteStackTrace(e, Console.Error);
     }
     return mappedAtoms;
 }
Example #10
0
        /// <summary>  Removes an atom from the AtomContainer under certain conditions.
        /// See {@cdk.cite HAN96} for details
        ///
        ///
        /// </summary>
        /// <param name="atom">             The atom to be removed
        /// </param>
        /// <param name="ac">               The AtomContainer to work on
        /// </param>
        /// <param name="pathes">           The pathes to manipulate
        /// </param>
        /// <param name="rings">            The ringset to be extended
        /// </param>
        /// <exception cref="CDKException"> Thrown if something goes wrong or if the timeout is exceeded
        /// </exception>
        private void remove(IAtom atom, IAtomContainer ac, System.Collections.ArrayList pathes, IRingSet rings)
        {
            Path path1            = null;
            Path path2            = null;
            Path union            = null;
            int  intersectionSize = 0;

            newPathes.Clear();
            removePathes.Clear();
            potentialRings.Clear();
            if (debug)
            {
                System.Console.Out.WriteLine("*** Removing atom " + originalAc.getAtomNumber(atom) + " ***");
            }

            for (int i = 0; i < pathes.Count; i++)
            {
                path1 = (Path)pathes[i];
                if (path1[0] == atom || path1[path1.Count - 1] == atom)
                {
                    for (int j = i + 1; j < pathes.Count; j++)
                    {
                        //System.out.print(".");
                        path2 = (Path)pathes[j];
                        if (path2[0] == atom || path2[path2.Count - 1] == atom)
                        {
                            intersectionSize = path1.getIntersectionSize(path2);
                            if (intersectionSize < 3)
                            {
                                //if (debug) System.out.println("Joining " + path1.toString(originalAc) + " and " + path2.toString(originalAc));
                                union = Path.join(path1, path2, atom);
                                if (intersectionSize == 1)
                                {
                                    newPathes.Add(union);
                                }
                                else
                                {
                                    potentialRings.Add(union);
                                }
                                //if (debug) System.out.println("Intersection Size: " + intersectionSize);
                                //if (debug) System.out.println("Union: " + union.toString(originalAc));

                                /*
                                 *  Now we know that path1 and
                                 *  path2 share the Atom atom.
                                 */
                                removePathes.Add(path1);
                                removePathes.Add(path2);
                            }
                        }
                        checkTimeout();
                    }
                }
            }
            for (int f = 0; f < removePathes.Count; f++)
            {
                pathes.Remove(removePathes[f]);
            }
            for (int f = 0; f < newPathes.Count; f++)
            {
                pathes.Add(newPathes[f]);
            }
            detectRings(potentialRings, rings, originalAc);
            ac.removeAtomAndConnectedElectronContainers(atom);
            if (debug)
            {
                System.Console.Out.WriteLine("\n" + pathes.Count + " pathes and " + ac.AtomCount + " atoms left.");
            }
        }
Example #11
0
        /// <summary>  Returns a Map with the AtomNumbers, the first number corresponds to the first (or the largest
        /// AtomContainer) atomcontainer. It is recommend to sort the atomContainer due to their number of atoms before
        /// calling this function.
        /// 
        /// The molecules needs to be aligned before! (coordinates are needed)
        /// 
        /// </summary>
        /// <param name="firstAtomContainer">               the (largest) first aligned AtomContainer which is the reference
        /// </param>
        /// <param name="secondAtomContainer">              the second aligned AtomContainer
        /// </param>
        /// <param name="searchRadius">              		the radius of space search from each atom
        /// </param>
        /// <returns>                   				a Map of the mapped atoms
        /// </returns>
        /// <exception cref="CDKException"> Description of the Exception
        /// </exception>
        public static System.Collections.IDictionary mapAtomsOfAlignedStructures(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer, double searchRadius, System.Collections.IDictionary mappedAtoms)
        {
            //to return the mapping setProperty("MappedAtom",AtomNumber)
            //System.out.println("**** MAP ATOMS ****");
            getLargestAtomContainer(firstAtomContainer, secondAtomContainer);
            double[][] distanceMatrix = new double[firstAtomContainer.AtomCount][];
            for (int i = 0; i < firstAtomContainer.AtomCount; i++)
            {
                distanceMatrix[i] = new double[secondAtomContainer.AtomCount];
            }
            for (int i = 0; i < firstAtomContainer.AtomCount; i++)
            {
                Point3d firstAtomPoint = firstAtomContainer.getAtomAt(i).getPoint3d();
                //System.out.println("Closest atoms of "+firstAtomContainer.getAtoms()[i].getSymbol()+" :");
                for (int j = 0; j < secondAtomContainer.AtomCount; j++)
                {
                    distanceMatrix[i][j] = firstAtomPoint.distance(secondAtomContainer.getAtomAt(j).getPoint3d());
                    //System.out.println("Distance "+i+" "+j+":"+distanceMatrix[i][j]);
                }
                //System.out.println(" Atoms from the secondAtomContainer");
            }

            //System.out.println();
            //System.out.print("\t");
            //for (int j=0;j<secondAtomContainer.getAtomCount();j++){
            //System.out.print(j+" "+secondAtomContainer.getAtomAt(j).getSymbol()+"\t");
            //}
            double tmp = 0;
            for (int i = 0; i < firstAtomContainer.AtomCount; i++)
            {
                //System.out.print(i+" "+firstAtomContainer.getAtomAt(i).getSymbol()+"\t");
                for (int j = 0; j < secondAtomContainer.AtomCount; j++)
                {
                    tmp = System.Math.Floor(distanceMatrix[i][j] * 10);
                    //System.out.println(tmp/10+"\t");
                }
            }

            double minimumDistance = searchRadius;
            int countMappedAtoms = 0;
            for (int i = 0; i < firstAtomContainer.AtomCount; i++)
            {
                minimumDistance = searchRadius;
                for (int j = 0; j < secondAtomContainer.AtomCount; j++)
                {
                    if (distanceMatrix[i][j] < searchRadius && distanceMatrix[i][j] < minimumDistance)
                    {
                        //System.out.println("Distance OK "+i+" "+j+":"+distanceMatrix[i][j]+" AtomCheck:"+checkAtomMapping(firstAtomContainer,secondAtomContainer, i, j));
                        //check atom properties
                        if (checkAtomMapping(firstAtomContainer, secondAtomContainer, i, j))
                        {
                            minimumDistance = distanceMatrix[i][j];
                            mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(firstAtomContainer.getAtomAt(i))] = (System.Int32)secondAtomContainer.getAtomNumber(secondAtomContainer.getAtomAt(j));
                            //firstAtomContainer.getAtomAt(i).setProperty("MappedAtom",new Integer(secondAtomContainer.getAtomNumber(secondAtomContainer.getAtomAt(j))));
                            countMappedAtoms++;
                            //System.out.println("#:"+countMappedAtoms+" Atom:"+i+" is mapped to Atom"+j);
                            //System.out.println(firstAtomContainer.getConnectedAtoms(firstAtomContainer.getAtomAt(i)).length);
                        }
                    }
                }
            }
            return mappedAtoms;
        }
 /// <summary>  Says if an atom is the start of a double bond configuration
 /// 
 /// </summary>
 /// <param name="a">                       The atom which is the start of configuration
 /// </param>
 /// <param name="container">               The atomContainer the atom is in
 /// </param>
 /// <param name="parent">                  The atom we came from
 /// </param>
 /// <param name="doubleBondConfiguration"> The array indicating where double bond
 /// configurations are specified (this method ensures that there is
 /// actually the possibility of a double bond configuration)
 /// </param>
 /// <returns>                          false=is not start of configuration, true=is
 /// </returns>
 private bool isStartOfDoubleBond(IAtomContainer container, IAtom a, IAtom parent, bool[] doubleBondConfiguration)
 {
     int lengthAtom = container.getConnectedAtoms(a).Length + a.getHydrogenCount();
     if (lengthAtom != 3 && (lengthAtom != 2 && (System.Object)a.Symbol != (System.Object)("N")))
     {
         return (false);
     }
     IAtom[] atoms = container.getConnectedAtoms(a);
     IAtom one = null;
     IAtom two = null;
     bool doubleBond = false;
     IAtom nextAtom = null;
     for (int i = 0; i < atoms.Length; i++)
     {
         if (atoms[i] != parent && container.getBond(atoms[i], a).Order == CDKConstants.BONDORDER_DOUBLE && isEndOfDoubleBond(container, atoms[i], a, doubleBondConfiguration))
         {
             doubleBond = true;
             nextAtom = atoms[i];
         }
         if (atoms[i] != nextAtom && one == null)
         {
             one = atoms[i];
         }
         else if (atoms[i] != nextAtom && one != null)
         {
             two = atoms[i];
         }
     }
     System.String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container);
     if (one != null && ((!a.Symbol.Equals("N") && two != null && !morgannumbers[container.getAtomNumber(one)].Equals(morgannumbers[container.getAtomNumber(two)]) && doubleBond && doubleBondConfiguration[container.getBondNumber(a, nextAtom)]) || (doubleBond && a.Symbol.Equals("N") && System.Math.Abs(BondTools.giveAngleBothMethods(nextAtom, a, parent, true)) > System.Math.PI / 10)))
     {
         return (true);
     }
     else
     {
         return (false);
     }
 }
Example #13
0
        /// <summary> Returns a list of atoms in the shortest path between two atoms.
        /// 
        /// This method uses the Djikstra algorithm to find all the atoms in the shortest
        /// path between the two specified atoms. The start and end atoms are also included
        /// in the path returned
        /// 
        /// </summary>
        /// <param name="atomContainer">The molecule to search in
        /// </param>
        /// <param name="start">The starting atom
        /// </param>
        /// <param name="end">The ending atom
        /// </param>
        /// <returns> A <code>List</code> containing the atoms in the shortest path between <code>start</code> and
        /// <code>end</code> inclusive
        /// </returns>
        public static System.Collections.IList getShortestPath(IAtomContainer atomContainer, IAtom start, IAtom end)
        {
            int natom = atomContainer.AtomCount;
            int endNumber = atomContainer.getAtomNumber(end);
            int startNumber = atomContainer.getAtomNumber(start);
            int[] d = new int[natom];
            int[] previous = new int[natom];
            for (int i = 0; i < natom; i++)
            {
                d[i] = 99999999;
                previous[i] = -1;
            }
            d[atomContainer.getAtomNumber(start)] = 0;

            System.Collections.ArrayList S = new System.Collections.ArrayList();
            System.Collections.ArrayList Q = new System.Collections.ArrayList();
            for (int i = 0; i < natom; i++)
                Q.Add((System.Int32)i);

            while (true)
            {
                if (Q.Count == 0)
                    break;

                // extract min
                int u = 999999;
                int index = 0;
                for (int i = 0; i < Q.Count; i++)
                {
                    int tmp = ((System.Int32)Q[i]);
                    if (d[tmp] < u)
                    {
                        u = d[tmp];
                        index = i;
                    }
                }
                Q.RemoveAt(index);
                S.Add(atomContainer.getAtomAt(u));
                if (u == endNumber)
                    break;

                // relaxation
                IAtom[] connected = atomContainer.getConnectedAtoms(atomContainer.getAtomAt(u));
                for (int i = 0; i < connected.Length; i++)
                {
                    int anum = atomContainer.getAtomNumber(connected[i]);
                    if (d[anum] > d[u] + 1)
                    {
                        // all edges have equals weights
                        d[anum] = d[u] + 1;
                        previous[anum] = u;
                    }
                }
            }

            System.Collections.ArrayList tmp2 = new System.Collections.ArrayList();
            int u2 = endNumber;
            while (true)
            {
                tmp2.Insert(0, atomContainer.getAtomAt(u2));
                u2 = previous[u2];
                if (u2 == startNumber)
                {
                    tmp2.Insert(0, atomContainer.getAtomAt(u2));
                    break;
                }
            }
            return tmp2;
        }
Example #14
0
        /// <summary> Returns a list of atoms in the shortest path between two atoms.
        ///
        /// This method uses the Djikstra algorithm to find all the atoms in the shortest
        /// path between the two specified atoms. The start and end atoms are also included
        /// in the path returned
        ///
        /// </summary>
        /// <param name="atomContainer">The molecule to search in
        /// </param>
        /// <param name="start">The starting atom
        /// </param>
        /// <param name="end">The ending atom
        /// </param>
        /// <returns> A <code>List</code> containing the atoms in the shortest path between <code>start</code> and
        /// <code>end</code> inclusive
        /// </returns>
        public static System.Collections.IList getShortestPath(IAtomContainer atomContainer, IAtom start, IAtom end)
        {
            int natom       = atomContainer.AtomCount;
            int endNumber   = atomContainer.getAtomNumber(end);
            int startNumber = atomContainer.getAtomNumber(start);

            int[] d        = new int[natom];
            int[] previous = new int[natom];
            for (int i = 0; i < natom; i++)
            {
                d[i]        = 99999999;
                previous[i] = -1;
            }
            d[atomContainer.getAtomNumber(start)] = 0;

            System.Collections.ArrayList S = new System.Collections.ArrayList();
            System.Collections.ArrayList Q = new System.Collections.ArrayList();
            for (int i = 0; i < natom; i++)
            {
                Q.Add((System.Int32)i);
            }

            while (true)
            {
                if (Q.Count == 0)
                {
                    break;
                }

                // extract min
                int u     = 999999;
                int index = 0;
                for (int i = 0; i < Q.Count; i++)
                {
                    int tmp = ((System.Int32)Q[i]);
                    if (d[tmp] < u)
                    {
                        u     = d[tmp];
                        index = i;
                    }
                }
                Q.RemoveAt(index);
                S.Add(atomContainer.getAtomAt(u));
                if (u == endNumber)
                {
                    break;
                }

                // relaxation
                IAtom[] connected = atomContainer.getConnectedAtoms(atomContainer.getAtomAt(u));
                for (int i = 0; i < connected.Length; i++)
                {
                    int anum = atomContainer.getAtomNumber(connected[i]);
                    if (d[anum] > d[u] + 1)
                    {
                        // all edges have equals weights
                        d[anum]        = d[u] + 1;
                        previous[anum] = u;
                    }
                }
            }

            System.Collections.ArrayList tmp2 = new System.Collections.ArrayList();
            int u2 = endNumber;

            while (true)
            {
                tmp2.Insert(0, atomContainer.getAtomAt(u2));
                u2 = previous[u2];
                if (u2 == startNumber)
                {
                    tmp2.Insert(0, atomContainer.getAtomAt(u2));
                    break;
                }
            }
            return(tmp2);
        }
 /// <summary>  Says if an atom is the end of a double bond configuration
 /// 
 /// </summary>
 /// <param name="atom">                    The atom which is the end of configuration
 /// </param>
 /// <param name="container">               The atomContainer the atom is in
 /// </param>
 /// <param name="parent">                  The atom we came from
 /// </param>
 /// <param name="doubleBondConfiguration"> The array indicating where double bond
 /// configurations are specified (this method ensures that there is
 /// actually the possibility of a double bond configuration)
 /// </param>
 /// <returns>                          false=is not end of configuration, true=is
 /// </returns>
 private bool isEndOfDoubleBond(IAtomContainer container, IAtom atom, IAtom parent, bool[] doubleBondConfiguration)
 {
     if (container.getBondNumber(atom, parent) == -1 || doubleBondConfiguration.Length <= container.getBondNumber(atom, parent) || !doubleBondConfiguration[container.getBondNumber(atom, parent)])
     {
         return false;
     }
     int lengthAtom = container.getConnectedAtoms(atom).Length + atom.getHydrogenCount();
     int lengthParent = container.getConnectedAtoms(parent).Length + parent.getHydrogenCount();
     if (container.getBond(atom, parent) != null)
     {
         if (container.getBond(atom, parent).Order == CDKConstants.BONDORDER_DOUBLE && (lengthAtom == 3 || (lengthAtom == 2 && atom.Symbol.Equals("N"))) && (lengthParent == 3 || (lengthParent == 2 && parent.Symbol.Equals("N"))))
         {
             IAtom[] atoms = container.getConnectedAtoms(atom);
             IAtom one = null;
             IAtom two = null;
             for (int i = 0; i < atoms.Length; i++)
             {
                 if (atoms[i] != parent && one == null)
                 {
                     one = atoms[i];
                 }
                 else if (atoms[i] != parent && one != null)
                 {
                     two = atoms[i];
                 }
             }
             System.String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container);
             if ((one != null && two == null && atom.Symbol.Equals("N") && System.Math.Abs(BondTools.giveAngleBothMethods(parent, atom, one, true)) > System.Math.PI / 10) || (!atom.Symbol.Equals("N") && one != null && two != null && !morgannumbers[container.getAtomNumber(one)].Equals(morgannumbers[container.getAtomNumber(two)])))
             {
                 return (true);
             }
             else
             {
                 return (false);
             }
         }
     }
     return (false);
 }
Example #16
0
 /// <summary>  This makes a map of matching atoms out of a map of matching bonds as produced by the get(Subgraph|Ismorphism)Map methods.
 ///
 /// </summary>
 /// <param name="l">  The list produced by the getMap method.
 /// </param>
 /// <param name="g1"> The first atom container.
 /// </param>
 /// <param name="g2"> The second one (first and second as in getMap)
 /// </param>
 /// <returns>     The mapping found projected on g1. This is a List of RMap objects containing Ids of matching atoms.
 /// </returns>
 public static System.Collections.IList makeAtomsMapOfBondsMap(System.Collections.IList l, IAtomContainer g1, IAtomContainer g2)
 {
     if (l == null)
     {
         return(l);
     }
     IBond[] bonds1 = g1.Bonds;
     IBond[] bonds2 = g2.Bonds;
     System.Collections.IList result = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
     for (int i = 0; i < l.Count; i++)
     {
         IBond   bond1 = bonds1[((RMap)l[i]).Id1];
         IBond   bond2 = bonds2[((RMap)l[i]).Id2];
         IAtom[] atom1 = bond1.getAtoms();
         IAtom[] atom2 = bond2.getAtoms();
         for (int j = 0; j < 2; j++)
         {
             IBond[] bondsConnectedToAtom1j = g1.getConnectedBonds(atom1[j]);
             for (int k = 0; k < bondsConnectedToAtom1j.Length; k++)
             {
                 if (bondsConnectedToAtom1j[k] != bond1)
                 {
                     IBond testBond = bondsConnectedToAtom1j[k];
                     for (int m = 0; m < l.Count; m++)
                     {
                         IBond testBond2;
                         if (((RMap)l[m]).Id1 == g1.getBondNumber(testBond))
                         {
                             testBond2 = bonds2[((RMap)l[m]).Id2];
                             for (int n = 0; n < 2; n++)
                             {
                                 System.Collections.IList bondsToTest = g2.getConnectedBondsVector(atom2[n]);
                                 if (bondsToTest.Contains(testBond2))
                                 {
                                     RMap map;
                                     if (j == n)
                                     {
                                         map = new RMap(g1.getAtomNumber(atom1[0]), g2.getAtomNumber(atom2[0]));
                                     }
                                     else
                                     {
                                         map = new RMap(g1.getAtomNumber(atom1[1]), g2.getAtomNumber(atom2[0]));
                                     }
                                     if (!result.Contains(map))
                                     {
                                         result.Add(map);
                                     }
                                     RMap map2;
                                     if (j == n)
                                     {
                                         map2 = new RMap(g1.getAtomNumber(atom1[1]), g2.getAtomNumber(atom2[1]));
                                     }
                                     else
                                     {
                                         map2 = new RMap(g1.getAtomNumber(atom1[0]), g2.getAtomNumber(atom2[1]));
                                     }
                                     if (!result.Contains(map2))
                                     {
                                         result.Add(map2);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return(result);
 }
 /// <summary>  This makes a map of matching atoms out of a map of matching bonds as produced by the get(Subgraph|Ismorphism)Map methods.
 /// 
 /// </summary>
 /// <param name="l">  The list produced by the getMap method.
 /// </param>
 /// <param name="g1"> The first atom container.
 /// </param>
 /// <param name="g2"> The second one (first and second as in getMap)
 /// </param>
 /// <returns>     The mapping found projected on g1. This is a List of RMap objects containing Ids of matching atoms.
 /// </returns>
 public static System.Collections.IList makeAtomsMapOfBondsMap(System.Collections.IList l, IAtomContainer g1, IAtomContainer g2)
 {
     if (l == null)
         return (l);
     IBond[] bonds1 = g1.Bonds;
     IBond[] bonds2 = g2.Bonds;
     System.Collections.IList result = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
     for (int i = 0; i < l.Count; i++)
     {
         IBond bond1 = bonds1[((RMap)l[i]).Id1];
         IBond bond2 = bonds2[((RMap)l[i]).Id2];
         IAtom[] atom1 = bond1.getAtoms();
         IAtom[] atom2 = bond2.getAtoms();
         for (int j = 0; j < 2; j++)
         {
             IBond[] bondsConnectedToAtom1j = g1.getConnectedBonds(atom1[j]);
             for (int k = 0; k < bondsConnectedToAtom1j.Length; k++)
             {
                 if (bondsConnectedToAtom1j[k] != bond1)
                 {
                     IBond testBond = bondsConnectedToAtom1j[k];
                     for (int m = 0; m < l.Count; m++)
                     {
                         IBond testBond2;
                         if (((RMap)l[m]).Id1 == g1.getBondNumber(testBond))
                         {
                             testBond2 = bonds2[((RMap)l[m]).Id2];
                             for (int n = 0; n < 2; n++)
                             {
                                 System.Collections.IList bondsToTest = g2.getConnectedBondsVector(atom2[n]);
                                 if (bondsToTest.Contains(testBond2))
                                 {
                                     RMap map;
                                     if (j == n)
                                     {
                                         map = new RMap(g1.getAtomNumber(atom1[0]), g2.getAtomNumber(atom2[0]));
                                     }
                                     else
                                     {
                                         map = new RMap(g1.getAtomNumber(atom1[1]), g2.getAtomNumber(atom2[0]));
                                     }
                                     if (!result.Contains(map))
                                     {
                                         result.Add(map);
                                     }
                                     RMap map2;
                                     if (j == n)
                                     {
                                         map2 = new RMap(g1.getAtomNumber(atom1[1]), g2.getAtomNumber(atom2[1]));
                                     }
                                     else
                                     {
                                         map2 = new RMap(g1.getAtomNumber(atom1[0]), g2.getAtomNumber(atom2[1]));
                                     }
                                     if (!result.Contains(map2))
                                     {
                                         result.Add(map2);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return (result);
 }
Example #18
0
 /// <summary>  Says if an atom as a center of any valid stereo configuration or not
 /// 
 /// </summary>
 /// <param name="a">         The atom which is the center
 /// </param>
 /// <param name="container"> The atomContainer the atom is in
 /// </param>
 /// <returns>            true=is a stereo atom, false=is not
 /// </returns>
 public static bool isStereo(IAtomContainer container, IAtom a)
 {
     IAtom[] atoms = container.getConnectedAtoms(a);
     if (atoms.Length < 4 || atoms.Length > 6)
     {
         return (false);
     }
     IBond[] bonds = container.getConnectedBonds(a);
     int stereo = 0;
     for (int i = 0; i < bonds.Length; i++)
     {
         if (bonds[i].Stereo != 0)
         {
             stereo++;
         }
     }
     if (stereo == 0)
     {
         return false;
     }
     int differentAtoms = 0;
     for (int i = 0; i < atoms.Length; i++)
     {
         bool isDifferent = true;
         for (int k = 0; k < i; k++)
         {
             if (atoms[i].Symbol.Equals(atoms[k].Symbol))
             {
                 isDifferent = false;
                 break;
             }
         }
         if (isDifferent)
         {
             differentAtoms++;
         }
     }
     if (differentAtoms != atoms.Length)
     {
         int[] morgannumbers = MorganNumbersTools.getMorganNumbers(container);
         System.Collections.ArrayList differentSymbols = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
         for (int i = 0; i < atoms.Length; i++)
         {
             if (!differentSymbols.Contains(atoms[i].Symbol))
             {
                 differentSymbols.Add(atoms[i].Symbol);
             }
         }
         int[] onlyRelevantIfTwo = new int[2];
         if (differentSymbols.Count == 2)
         {
             for (int i = 0; i < atoms.Length; i++)
             {
                 if (differentSymbols.IndexOf(atoms[i].Symbol) == 0)
                 {
                     onlyRelevantIfTwo[0]++;
                 }
                 else
                 {
                     onlyRelevantIfTwo[1]++;
                 }
             }
         }
         bool[] symbolsWithDifferentMorganNumbers = new bool[differentSymbols.Count];
         System.Collections.ArrayList[] symbolsMorganNumbers = new System.Collections.ArrayList[differentSymbols.Count];
         for (int i = 0; i < symbolsWithDifferentMorganNumbers.Length; i++)
         {
             symbolsWithDifferentMorganNumbers[i] = true;
             symbolsMorganNumbers[i] = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
         }
         for (int k = 0; k < atoms.Length; k++)
         {
             int elementNumber = differentSymbols.IndexOf(atoms[k].Symbol);
             if (symbolsMorganNumbers[elementNumber].Contains((System.Int32)morgannumbers[container.getAtomNumber(atoms[k])]))
             {
                 symbolsWithDifferentMorganNumbers[elementNumber] = false;
             }
             else
             {
                 symbolsMorganNumbers[elementNumber].Add((System.Int32)morgannumbers[container.getAtomNumber(atoms[k])]);
             }
         }
         int numberOfSymbolsWithDifferentMorganNumbers = 0;
         for (int i = 0; i < symbolsWithDifferentMorganNumbers.Length; i++)
         {
             if (symbolsWithDifferentMorganNumbers[i] == true)
             {
                 numberOfSymbolsWithDifferentMorganNumbers++;
             }
         }
         if (numberOfSymbolsWithDifferentMorganNumbers != differentSymbols.Count)
         {
             if ((atoms.Length == 5 || atoms.Length == 6) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1)))
             {
                 return (true);
             }
             if (isSquarePlanar(container, a) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1)))
             {
                 return (true);
             }
             return false;
         }
     }
     return (true);
 }
Example #19
0
 /// <summary>  Return the RMSD of bonds length between the 2 aligned molecules.
 /// 
 /// </summary>
 /// <param name="firstAtomContainer">               the (largest) first aligned AtomContainer which is the reference
 /// </param>
 /// <param name="secondAtomContainer">              the second aligned AtomContainer
 /// </param>
 /// <param name="mappedAtoms">            			Map: a Map of the mapped atoms
 /// </param>
 /// <param name="Coords3d">           			    boolean: true if moecules has 3D coords, false if molecules has 2D coords
 /// </param>
 /// <returns>                   				double: all the RMSD of bonds length
 /// </returns>
 /// <exception cref="CDK">*
 /// 
 /// </exception>
 public static double getBondLengthRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer, System.Collections.IDictionary mappedAtoms, bool Coords3d)
 {
     //System.out.println("**** GT getBondLengthRMSD ****");
     //UPGRADE_TODO: Method 'java.util.Map.keySet' was converted to 'CSGraphT.SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilMapkeySet'"
     System.Collections.IEnumerator firstAtoms = new CSGraphT.SupportClass.HashSetSupport(mappedAtoms.Keys).GetEnumerator();
     IAtom centerAtomFirstMolecule = null;
     IAtom centerAtomSecondMolecule = null;
     IAtom[] connectedAtoms = null;
     double sum = 0;
     double n = 0;
     double distance1 = 0;
     double distance2 = 0;
     setVisitedFlagsToFalse(firstAtomContainer);
     setVisitedFlagsToFalse(secondAtomContainer);
     //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'"
     while (firstAtoms.MoveNext())
     {
         //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'"
         centerAtomFirstMolecule = firstAtomContainer.getAtomAt(((System.Int32)firstAtoms.Current));
         centerAtomFirstMolecule.setFlag(CDKConstants.VISITED, true);
         centerAtomSecondMolecule = secondAtomContainer.getAtomAt(((System.Int32)mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(centerAtomFirstMolecule)]));
         connectedAtoms = firstAtomContainer.getConnectedAtoms(centerAtomFirstMolecule);
         for (int i = 0; i < connectedAtoms.Length; i++)
         {
             //this step is built to know if the program has already calculate a bond length (so as not to have duplicate values)
             if (!connectedAtoms[i].getFlag(CDKConstants.VISITED))
             {
                 if (Coords3d)
                 {
                     distance1 = ((Point3d)centerAtomFirstMolecule.getPoint3d()).distance(connectedAtoms[i].getPoint3d());
                     distance2 = ((Point3d)centerAtomSecondMolecule.getPoint3d()).distance(secondAtomContainer.getAtomAt(((System.Int32)mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(connectedAtoms[i])])).getPoint3d());
                     sum = sum + System.Math.Pow((distance1 - distance2), 2);
                     n++;
                 }
                 else
                 {
                     distance1 = ((Point2d)centerAtomFirstMolecule.getPoint2d()).distance(connectedAtoms[i].getPoint2d());
                     distance2 = ((Point2d)centerAtomSecondMolecule.getPoint2d()).distance(secondAtomContainer.getAtomAt(((System.Int32)mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(connectedAtoms[i])])).getPoint2d());
                     sum = sum + System.Math.Pow((distance1 - distance2), 2);
                     n++;
                 }
             }
         }
     }
     setVisitedFlagsToFalse(firstAtomContainer);
     setVisitedFlagsToFalse(secondAtomContainer);
     return System.Math.Sqrt(sum / n);
 }
Example #20
0
        /// <summary>  Says if an atom is the end of a double bond configuration
        ///
        /// </summary>
        /// <param name="atom">                    The atom which is the end of configuration
        /// </param>
        /// <param name="container">               The atomContainer the atom is in
        /// </param>
        /// <param name="parent">                  The atom we came from
        /// </param>
        /// <param name="doubleBondConfiguration"> The array indicating where double bond
        /// configurations are specified (this method ensures that there is
        /// actually the possibility of a double bond configuration)
        /// </param>
        /// <returns>                          false=is not end of configuration, true=is
        /// </returns>
        private static bool isEndOfDoubleBond(IAtomContainer container, IAtom atom, IAtom parent, bool[] doubleBondConfiguration)
        {
            if (container.getBondNumber(atom, parent) == -1 || doubleBondConfiguration.Length <= container.getBondNumber(atom, parent) || !doubleBondConfiguration[container.getBondNumber(atom, parent)])
            {
                return(false);
            }
            int lengthAtom   = container.getConnectedAtoms(atom).Length + atom.getHydrogenCount();
            int lengthParent = container.getConnectedAtoms(parent).Length + parent.getHydrogenCount();

            if (container.getBond(atom, parent) != null)
            {
                if (container.getBond(atom, parent).Order == CDKConstants.BONDORDER_DOUBLE && (lengthAtom == 3 || (lengthAtom == 2 && atom.Symbol.Equals("N"))) && (lengthParent == 3 || (lengthParent == 2 && parent.Symbol.Equals("N"))))
                {
                    IAtom[] atoms = container.getConnectedAtoms(atom);
                    IAtom   one   = null;
                    IAtom   two   = null;
                    for (int i = 0; i < atoms.Length; i++)
                    {
                        if (atoms[i] != parent && one == null)
                        {
                            one = atoms[i];
                        }
                        else if (atoms[i] != parent && one != null)
                        {
                            two = atoms[i];
                        }
                    }
                    System.String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container);
                    if ((one != null && two == null && atom.Symbol.Equals("N") && System.Math.Abs(giveAngleBothMethods(parent, atom, one, true)) > System.Math.PI / 10) || (!atom.Symbol.Equals("N") && one != null && two != null && !morgannumbers[container.getAtomNumber(one)].Equals(morgannumbers[container.getAtomNumber(two)])))
                    {
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
Example #21
0
        /// <summary>  Says if an atom as a center of any valid stereo configuration or not
        ///
        /// </summary>
        /// <param name="a">         The atom which is the center
        /// </param>
        /// <param name="container"> The atomContainer the atom is in
        /// </param>
        /// <returns>            true=is a stereo atom, false=is not
        /// </returns>
        public static bool isStereo(IAtomContainer container, IAtom a)
        {
            IAtom[] atoms = container.getConnectedAtoms(a);
            if (atoms.Length < 4 || atoms.Length > 6)
            {
                return(false);
            }
            IBond[] bonds  = container.getConnectedBonds(a);
            int     stereo = 0;

            for (int i = 0; i < bonds.Length; i++)
            {
                if (bonds[i].Stereo != 0)
                {
                    stereo++;
                }
            }
            if (stereo == 0)
            {
                return(false);
            }
            int differentAtoms = 0;

            for (int i = 0; i < atoms.Length; i++)
            {
                bool isDifferent = true;
                for (int k = 0; k < i; k++)
                {
                    if (atoms[i].Symbol.Equals(atoms[k].Symbol))
                    {
                        isDifferent = false;
                        break;
                    }
                }
                if (isDifferent)
                {
                    differentAtoms++;
                }
            }
            if (differentAtoms != atoms.Length)
            {
                int[] morgannumbers = MorganNumbersTools.getMorganNumbers(container);
                System.Collections.ArrayList differentSymbols = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                for (int i = 0; i < atoms.Length; i++)
                {
                    if (!differentSymbols.Contains(atoms[i].Symbol))
                    {
                        differentSymbols.Add(atoms[i].Symbol);
                    }
                }
                int[] onlyRelevantIfTwo = new int[2];
                if (differentSymbols.Count == 2)
                {
                    for (int i = 0; i < atoms.Length; i++)
                    {
                        if (differentSymbols.IndexOf(atoms[i].Symbol) == 0)
                        {
                            onlyRelevantIfTwo[0]++;
                        }
                        else
                        {
                            onlyRelevantIfTwo[1]++;
                        }
                    }
                }
                bool[] symbolsWithDifferentMorganNumbers            = new bool[differentSymbols.Count];
                System.Collections.ArrayList[] symbolsMorganNumbers = new System.Collections.ArrayList[differentSymbols.Count];
                for (int i = 0; i < symbolsWithDifferentMorganNumbers.Length; i++)
                {
                    symbolsWithDifferentMorganNumbers[i] = true;
                    symbolsMorganNumbers[i] = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
                }
                for (int k = 0; k < atoms.Length; k++)
                {
                    int elementNumber = differentSymbols.IndexOf(atoms[k].Symbol);
                    if (symbolsMorganNumbers[elementNumber].Contains((System.Int32)morgannumbers[container.getAtomNumber(atoms[k])]))
                    {
                        symbolsWithDifferentMorganNumbers[elementNumber] = false;
                    }
                    else
                    {
                        symbolsMorganNumbers[elementNumber].Add((System.Int32)morgannumbers[container.getAtomNumber(atoms[k])]);
                    }
                }
                int numberOfSymbolsWithDifferentMorganNumbers = 0;
                for (int i = 0; i < symbolsWithDifferentMorganNumbers.Length; i++)
                {
                    if (symbolsWithDifferentMorganNumbers[i] == true)
                    {
                        numberOfSymbolsWithDifferentMorganNumbers++;
                    }
                }
                if (numberOfSymbolsWithDifferentMorganNumbers != differentSymbols.Count)
                {
                    if ((atoms.Length == 5 || atoms.Length == 6) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1)))
                    {
                        return(true);
                    }
                    if (isSquarePlanar(container, a) && (numberOfSymbolsWithDifferentMorganNumbers + differentAtoms > 2 || (differentAtoms == 2 && onlyRelevantIfTwo[0] > 1 && onlyRelevantIfTwo[1] > 1)))
                    {
                        return(true);
                    }
                    return(false);
                }
            }
            return(true);
        }
Example #22
0
        /// <summary>  Says if an atom is the start of a double bond configuration
        ///
        /// </summary>
        /// <param name="a">                       The atom which is the start of configuration
        /// </param>
        /// <param name="container">               The atomContainer the atom is in
        /// </param>
        /// <param name="parent">                  The atom we came from
        /// </param>
        /// <param name="doubleBondConfiguration"> The array indicating where double bond
        /// configurations are specified (this method ensures that there is
        /// actually the possibility of a double bond configuration)
        /// </param>
        /// <returns>                          false=is not start of configuration, true=is
        /// </returns>
        private static bool isStartOfDoubleBond(IAtomContainer container, IAtom a, IAtom parent, bool[] doubleBondConfiguration)
        {
            int lengthAtom = container.getConnectedAtoms(a).Length + a.getHydrogenCount();

            if (lengthAtom != 3 && (lengthAtom != 2 && (System.Object)a.Symbol != (System.Object)("N")))
            {
                return(false);
            }
            IAtom[] atoms      = container.getConnectedAtoms(a);
            IAtom   one        = null;
            IAtom   two        = null;
            bool    doubleBond = false;
            IAtom   nextAtom   = null;

            for (int i = 0; i < atoms.Length; i++)
            {
                if (atoms[i] != parent && container.getBond(atoms[i], a).Order == CDKConstants.BONDORDER_DOUBLE && isEndOfDoubleBond(container, atoms[i], a, doubleBondConfiguration))
                {
                    doubleBond = true;
                    nextAtom   = atoms[i];
                }
                if (atoms[i] != nextAtom && one == null)
                {
                    one = atoms[i];
                }
                else if (atoms[i] != nextAtom && one != null)
                {
                    two = atoms[i];
                }
            }
            System.String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container);
            if (one != null && ((!a.Symbol.Equals("N") && two != null && !morgannumbers[container.getAtomNumber(one)].Equals(morgannumbers[container.getAtomNumber(two)]) && doubleBond && doubleBondConfiguration[container.getBondNumber(a, nextAtom)]) || (doubleBond && a.Symbol.Equals("N") && System.Math.Abs(giveAngleBothMethods(nextAtom, a, parent, true)) > System.Math.PI / 10)))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Example #23
0
 /// <summary>  Return the variation of each angle value between the 2 aligned molecules.
 /// 
 /// </summary>
 /// <param name="firstAtomContainer">               the (largest) first aligned AtomContainer which is the reference
 /// </param>
 /// <param name="secondAtomContainer">              the second aligned AtomContainer
 /// </param>
 /// <param name="mappedAtoms">            			Map: a Map of the mapped atoms
 /// </param>
 /// <returns>                   				double: the value of the RMSD 
 /// </returns>
 /// <exception cref="CDK">*
 /// 
 /// </exception>
 public static double getAngleRMSD(IAtomContainer firstAtomContainer, IAtomContainer secondAtomContainer, System.Collections.IDictionary mappedAtoms)
 {
     //System.out.println("**** GT getAngleRMSD ****");
     //UPGRADE_TODO: Method 'java.util.Map.keySet' was converted to 'CSGraphT.SupportClass.HashSetSupport' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javautilMapkeySet'"
     System.Collections.IEnumerator firstAtoms = new CSGraphT.SupportClass.HashSetSupport(mappedAtoms.Keys).GetEnumerator();
     //System.out.println("mappedAtoms:"+mappedAtoms.toString());
     IAtom firstAtomfirstAC = null;
     IAtom centerAtomfirstAC = null;
     IAtom firstAtomsecondAC = null;
     IAtom secondAtomsecondAC = null;
     IAtom centerAtomsecondAC = null;
     double angleFirstMolecule = 0;
     double angleSecondMolecule = 0;
     double sum = 0;
     double n = 0;
     //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'"
     while (firstAtoms.MoveNext())
     {
         //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'"
         int firstAtomNumber = ((System.Int32)firstAtoms.Current);
         centerAtomfirstAC = firstAtomContainer.getAtomAt(firstAtomNumber);
         IAtom[] connectedAtoms = firstAtomContainer.getConnectedAtoms(centerAtomfirstAC);
         if (connectedAtoms.Length > 1)
         {
             //System.out.println("If "+centerAtomfirstAC.getSymbol()+" is the center atom :");
             for (int i = 0; i < connectedAtoms.Length - 1; i++)
             {
                 firstAtomfirstAC = connectedAtoms[i];
                 for (int j = i + 1; j < connectedAtoms.Length; j++)
                 {
                     angleFirstMolecule = getAngle(centerAtomfirstAC, firstAtomfirstAC, connectedAtoms[j]);
                     centerAtomsecondAC = secondAtomContainer.getAtomAt(((System.Int32)mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(centerAtomfirstAC)]));
                     firstAtomsecondAC = secondAtomContainer.getAtomAt(((System.Int32)mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(firstAtomfirstAC)]));
                     secondAtomsecondAC = secondAtomContainer.getAtomAt(((System.Int32)mappedAtoms[(System.Int32)firstAtomContainer.getAtomNumber(connectedAtoms[j])]));
                     angleSecondMolecule = getAngle(centerAtomsecondAC, firstAtomsecondAC, secondAtomsecondAC);
                     sum = sum + System.Math.Pow(angleFirstMolecule - angleSecondMolecule, 2);
                     n++;
                     //System.out.println("Error for the "+firstAtomfirstAC.getSymbol().toLowerCase()+"-"+centerAtomfirstAC.getSymbol()+"-"+connectedAtoms[j].getSymbol().toLowerCase()+" Angle :"+deltaAngle+" degrees");
                 }
             }
         } //if
     }
     return System.Math.Sqrt(sum / n);
 }
Example #24
0
        public String toString(IAtomContainer ac)
	    {
		    String s = "Path of length " + Count + ": ";
            for (int f = 0; f < Count; f++)
		    {
			    s += ac.getAtomNumber((IAtom)this[f]) + " ";
		    }
		    return s;
	    }