/// <summary> Partitions the atoms in an AtomContainer into covalently connected components.
        ///
        /// </summary>
        /// <param name="atomContainer"> The AtomContainer to be partitioned into connected components, i.e. molecules
        /// </param>
        /// <returns>                 A SetOfMolecules.
        ///
        /// </returns>
        /// <cdk.dictref>    blue-obelisk:graphPartitioning </cdk.dictref>
        public static ISetOfMolecules partitionIntoMolecules(IAtomContainer atomContainer)
        {
            IAtomContainer     ac         = atomContainer.Builder.newAtomContainer();
            IAtom              atom       = null;
            IElectronContainer eContainer = null;
            IMolecule          molecule   = null;
            ISetOfMolecules    molecules  = atomContainer.Builder.newSetOfMolecules();

            System.Collections.ArrayList sphere = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            for (int f = 0; f < atomContainer.AtomCount; f++)
            {
                atom = atomContainer.getAtomAt(f);
                atom.setFlag(CDKConstants.VISITED, false);
                ac.addAtom(atom);
            }
            IElectronContainer[] eContainers = atomContainer.ElectronContainers;
            for (int f = 0; f < eContainers.Length; f++)
            {
                eContainer = eContainers[f];
                eContainer.setFlag(CDKConstants.VISITED, false);
                ac.addElectronContainer(eContainer);
            }
            while (ac.AtomCount > 0)
            {
                atom     = ac.getAtomAt(0);
                molecule = atomContainer.Builder.newMolecule();
                sphere.Clear();
                sphere.Add(atom);
                atom.setFlag(CDKConstants.VISITED, true);
                PathTools.breadthFirstSearch(ac, sphere, molecule);
                molecules.addMolecule(molecule);
                ac.remove(molecule);
            }
            return(molecules);
        }
Example #2
0
        /// <summary> Procedure required by the CDOInterface. This function is only
        /// supposed to be called by the JCFL library
        /// </summary>
        public virtual void setObjectProperty(System.String objectType, System.String propertyType, System.String propertyValue)
        {
            //logger.debug("objectType: " + objectType);
            //logger.debug("propType: " + propertyType);
            //logger.debug("property: " + propertyValue);

            if (objectType == null)
            {
                //logger.error("Cannot add property for null object");
                return;
            }
            if (propertyType == null)
            {
                //logger.error("Cannot add property for null property type");
                return;
            }
            if (propertyValue == null)
            {
                //logger.warn("Will not add null property");
                return;
            }

            if (objectType.Equals("Molecule"))
            {
                if (propertyType.Equals("id"))
                {
                    currentMolecule.ID = propertyValue;
                }
                else if (propertyType.Equals("inchi"))
                {
                    currentMolecule.setProperty("iupac.nist.chemical.identifier", propertyValue);
                }
                else if (propertyType.Equals("pdb:residueName"))
                {
                    currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue);
                }
                else if (propertyType.Equals("pdb:oneLetterCode"))
                {
                    currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue);
                }
                else if (propertyType.Equals("pdb:id"))
                {
                    currentMolecule.setProperty(new DictRef(propertyType, propertyValue), propertyValue);
                }
                else
                {
                    //logger.warn("Not adding molecule property!");
                }
            }
            else if (objectType.Equals("PseudoAtom"))
            {
                if (propertyType.Equals("label"))
                {
                    if (!(currentAtom is IPseudoAtom))
                    {
                        currentAtom = currentChemFile.Builder.newPseudoAtom(currentAtom);
                    }
                    ((IPseudoAtom)currentAtom).Label = propertyValue;
                }
            }
            else if (objectType.Equals("Atom"))
            {
                if (propertyType.Equals("type"))
                {
                    if (propertyValue.Equals("R") && !(currentAtom is IPseudoAtom))
                    {
                        currentAtom = currentChemFile.Builder.newPseudoAtom(currentAtom);
                    }
                    currentAtom.Symbol = propertyValue;
                }
                else if (propertyType.Equals("x2"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.X2d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("y2"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.Y2d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("x3"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.X3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("y3"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.Y3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("z3"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.Z3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("xFract"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.FractX3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("yFract"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.FractY3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("zFract"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.FractZ3d = System.Double.Parse(propertyValue);
                }
                else if (propertyType.Equals("formalCharge"))
                {
                    currentAtom.setFormalCharge(System.Int32.Parse(propertyValue));
                }
                else if (propertyType.Equals("charge") || propertyType.Equals("partialCharge"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.setCharge(System.Double.Parse(propertyValue));
                }
                else if (propertyType.Equals("hydrogenCount"))
                {
                    currentAtom.setHydrogenCount(System.Int32.Parse(propertyValue));
                }
                else if (propertyType.Equals("dictRef"))
                {
                    currentAtom.setProperty("org.openscience.cdk.dict", propertyValue);
                }
                else if (propertyType.Equals("atomicNumber"))
                {
                    currentAtom.AtomicNumber = System.Int32.Parse(propertyValue);
                }
                else if (propertyType.Equals("massNumber"))
                {
                    //UPGRADE_TODO: The differences in the format  of parameters for constructor 'java.lang.Double.Double'  may cause compilation errors.  "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1092'"
                    currentAtom.MassNumber = (int)(System.Double.Parse(propertyValue));
                }
                else if (propertyType.Equals("spinMultiplicity"))
                {
                    int unpairedElectrons = System.Int32.Parse(propertyValue) - 1;
                    for (int i = 0; i < unpairedElectrons; i++)
                    {
                        currentMolecule.addElectronContainer(currentChemFile.Builder.newSingleElectron(currentAtom));
                    }
                }
                else if (propertyType.Equals("id"))
                {
                    //logger.debug("id: ", propertyValue);
                    currentAtom.ID = propertyValue;
                    atomEnumeration[propertyValue] = (System.Int32)numberOfAtoms;
                }
            }
            else if (objectType.Equals("Bond"))
            {
                if (propertyType.Equals("atom1"))
                {
                    bond_a1 = System.Int32.Parse(propertyValue);
                }
                else if (propertyType.Equals("atom2"))
                {
                    bond_a2 = System.Int32.Parse(propertyValue);
                }
                else if (propertyType.Equals("id"))
                {
                    //logger.debug("id: " + propertyValue);
                    bond_id = propertyValue;
                }
                else if (propertyType.Equals("order"))
                {
                    try
                    {
                        bond_order = System.Double.Parse(propertyValue);
                    }
                    catch (System.Exception e)
                    {
                        //logger.error("Cannot convert to double: " + propertyValue);
                        bond_order = 1.0;
                    }
                }
                else if (propertyType.Equals("stereo"))
                {
                    if (propertyValue.Equals("H"))
                    {
                        bond_stereo = CDKConstants.STEREO_BOND_DOWN;
                    }
                    else if (propertyValue.Equals("W"))
                    {
                        bond_stereo = CDKConstants.STEREO_BOND_UP;
                    }
                }
            }
            else if (objectType.Equals("Reaction"))
            {
                if (propertyType.Equals("id"))
                {
                    currentReaction.ID = propertyValue;
                }
            }
            else if (objectType.Equals("SetOfReactions"))
            {
                if (propertyType.Equals("id"))
                {
                    currentSetOfReactions.ID = propertyValue;
                }
            }
            else if (objectType.Equals("Reactant"))
            {
                if (propertyType.Equals("id"))
                {
                    currentMolecule.ID = propertyValue;
                }
            }
            else if (objectType.Equals("Product"))
            {
                if (propertyType.Equals("id"))
                {
                    currentMolecule.ID = propertyValue;
                }
            }
            else if (objectType.Equals("Crystal"))
            {
                // set these variables
                if (currentMolecule is ICrystal)
                {
                    ICrystal current = (ICrystal)currentMolecule;
                    if (propertyType.Equals("spacegroup"))
                    {
                        //logger.debug("Setting crystal spacegroup to: " + propertyValue);
                        current.SpaceGroup = propertyValue;
                    }
                    else if (propertyType.Equals("z"))
                    {
                        try
                        {
                            //logger.debug("Setting z to: " + propertyValue);
                            current.Z = System.Int32.Parse(propertyValue);
                        }
                        catch (System.FormatException exception)
                        {
                            //logger.error("Error in format of Z value");
                        }
                    }
                }
                else
                {
                    //logger.warn("Cannot add crystal cell parameters to a non " + "Crystal class!");
                }
            }
            else if (objectType.Equals("a-axis") || objectType.Equals("b-axis") || objectType.Equals("c-axis"))
            {
                // set these variables
                if (currentMolecule is ICrystal)
                {
                    //logger.debug("Setting axis (" + objectType + "): " + propertyValue);
                    if (propertyType.Equals("x"))
                    {
                        crystal_axis_x = System.Double.Parse(propertyValue);
                    }
                    else if (propertyType.Equals("y"))
                    {
                        crystal_axis_y = System.Double.Parse(propertyValue);
                    }
                    else if (propertyType.Equals("z"))
                    {
                        crystal_axis_z = System.Double.Parse(propertyValue);
                    }
                }
                else
                {
                    //logger.warn("Cannot add crystal cell parameters to a non " + "Crystal class!");
                }
            }
            //logger.debug("Object property set...");
        }