예제 #1
0
        /// <summary>  Generates the SMILES string for the atom
        /// 
        /// </summary>
        /// <param name="a">                       the atom to generate the SMILES for.
        /// </param>
        /// <param name="buffer">                  the string buffer that the atom is to be
        /// apended to.
        /// </param>
        /// <param name="container">               the AtomContainer to analyze.
        /// </param>
        /// <param name="chiral">                  is a chiral smiles wished?
        /// </param>
        /// <param name="parent">                  the atom we came from.
        /// </param>
        /// <param name="atomsInOrderOfSmiles">    a vector containing the atoms in the order
        /// they are in the smiles.
        /// </param>
        /// <param name="currentChain">            The chain we currently deal with.
        /// </param>
        /// <param name="doubleBondConfiguration"> Description of Parameter
        /// </param>
        private void parseAtom(IAtom a, System.Text.StringBuilder buffer, IAtomContainer container, bool chiral, bool[] doubleBondConfiguration, IAtom parent, System.Collections.ArrayList atomsInOrderOfSmiles, System.Collections.ArrayList currentChain)
        {
            System.String symbol = a.Symbol;
            bool stereo = BondTools.isStereo(container, a);
            bool brackets = symbol.Equals("B") || symbol.Equals("C") || symbol.Equals("N") || symbol.Equals("O") || symbol.Equals("P") || symbol.Equals("S") || symbol.Equals("F") || symbol.Equals("Br") || symbol.Equals("I") || symbol.Equals("Cl");
            brackets = !brackets;
            //System.out.println("in parseAtom()");
            //Deal with the start of a double bond configuration
            if (isStartOfDoubleBond(container, a, parent, doubleBondConfiguration))
            {
                buffer.Append('/');
            }

            if (a is IPseudoAtom)
            {
                buffer.Append("[*]");
            }
            else
            {
                System.String mass = generateMassString(a);
                brackets = brackets | !mass.Equals("");

                System.String charge = generateChargeString(a);
                brackets = brackets | !charge.Equals("");

                if (chiral && stereo)
                {
                    brackets = true;
                }
                if (brackets)
                {
                    buffer.Append('[');
                }
                buffer.Append(mass);
                if (a.getFlag(CDKConstants.ISAROMATIC))
                {
                    // Strictly speaking, this is wrong. Lower case is only used for sp2 atoms!
                    buffer.Append(a.Symbol.ToLower());
                }
                else if (a.Hybridization == CDKConstants.HYBRIDIZATION_SP2)
                {
                    buffer.Append(a.Symbol.ToLower());
                }
                else
                {
                    buffer.Append(symbol);
                }
                if (a.getProperty(RING_CONFIG) != null && a.getProperty(RING_CONFIG).Equals(UP))
                {
                    buffer.Append('/');
                }
                if (a.getProperty(RING_CONFIG) != null && a.getProperty(RING_CONFIG).Equals(DOWN))
                {
                    buffer.Append('\\');
                }
                if (chiral && stereo && (BondTools.isTrigonalBipyramidalOrOctahedral(container, a) != 0 || BondTools.isSquarePlanar(container, a) || BondTools.isTetrahedral(container, a, false) != 0))
                {
                    buffer.Append('@');
                }
                if (chiral && stereo && BondTools.isSquarePlanar(container, a))
                {
                    buffer.Append("SP1");
                }
                //chiral
                //hcount
                buffer.Append(charge);
                if (brackets)
                {
                    buffer.Append(']');
                }
            }
            //System.out.println("in parseAtom() after dealing with Pseudoatom or not");
            //Deal with the end of a double bond configuration
            if (isEndOfDoubleBond(container, a, parent, doubleBondConfiguration))
            {
                IAtom viewFrom = null;
                for (int i = 0; i < currentChain.Count; i++)
                {
                    if (currentChain[i] == parent)
                    {
                        int k = i - 1;
                        while (k > -1)
                        {
                            if (currentChain[k] is IAtom)
                            {
                                viewFrom = (IAtom)currentChain[k];
                                break;
                            }
                            k--;
                        }
                    }
                }
                if (viewFrom == null)
                {
                    for (int i = 0; i < atomsInOrderOfSmiles.Count; i++)
                    {
                        if (atomsInOrderOfSmiles[i] == parent)
                        {
                            viewFrom = (IAtom)atomsInOrderOfSmiles[i - 1];
                        }
                    }
                }
                bool afterThisAtom = false;
                IAtom viewTo = null;
                for (int i = 0; i < currentChain.Count; i++)
                {
                    if (afterThisAtom && currentChain[i] is IAtom)
                    {
                        viewTo = (IAtom)currentChain[i];
                        break;
                    }
                    if (afterThisAtom && currentChain[i] is System.Collections.ArrayList)
                    {
                        viewTo = (IAtom)((System.Collections.ArrayList)currentChain[i])[0];
                        break;
                    }
                    if (a == currentChain[i])
                    {
                        afterThisAtom = true;
                    }
                }
                try
                {
                    if (BondTools.isCisTrans(viewFrom, a, parent, viewTo, container))
                    {
                        buffer.Append('\\');
                    }
                    else
                    {
                        buffer.Append('/');
                    }
                }
                catch (CDKException ex)
                {
                    //If the user wants a double bond configuration, where there is none, we ignore this.
                }
            }
            System.Collections.ArrayList v = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            System.Collections.IEnumerator it = getRingOpenings(a, v).GetEnumerator();
            System.Collections.IEnumerator it2 = v.GetEnumerator();
            //System.out.println("in parseAtom() after checking for Ring openings");
            //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 (it.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'"
                System.Int32 integer = (System.Int32)it.Current;
                //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'"
                IBond b = container.getBond((IAtom)it2.Current, a);
                //UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
                int type = (int)b.Order;
                if (type == 2 && !b.getFlag(CDKConstants.ISAROMATIC))
                {
                    buffer.Append("=");
                }
                else if (type == 3 && !b.getFlag(CDKConstants.ISAROMATIC))
                {
                    buffer.Append("#");
                }
                buffer.Append(integer);
            }
            atomsInOrderOfSmiles.Add(a);
            //System.out.println("End of parseAtom()");
        }
예제 #2
0
        /// <summary> Creates amino acid AminoAcid objects.
        ///
        /// </summary>
        /// <returns> aminoAcids, a HashMap containing the amino acids as AminoAcids.
        /// </returns>
        public static AminoAcid[] createAAs()
        {
            if (aminoAcids != null)
            {
                return(aminoAcids);
            }

            // Create set of AtomContainers
            aminoAcids = new AminoAcid[20];

            IChemFile list = new ChemFile();
            //UPGRADE_ISSUE: Method 'java.lang.ClassLoader.getResourceAsStream' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassLoader'"
            //UPGRADE_ISSUE: Method 'java.lang.Class.getClassLoader' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangClassgetClassLoader'"
            CMLReader reader = new CMLReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("NuGenCDKSharp." + "list_aminoacids.cml"));//typeof(AminoAcids).getClassLoader().getResourceAsStream("data/templates/list_aminoacids.cml"));

            try
            {
                list = (IChemFile)reader.read(list);
                IAtomContainer[] containers = ChemFileManipulator.getAllAtomContainers(list);
                for (int i = 0; i < containers.Length; i++)
                {
                    //logger.debug("Adding AA: ", containers[i]);
                    // convert into an AminoAcid
                    AminoAcid aminoAcid = new AminoAcid();
                    IAtom[]   atoms     = containers[i].Atoms;
                    System.Collections.IEnumerator props = containers[i].Properties.Keys.GetEnumerator();
                    //UPGRADE_TODO: Method 'java.util.Enumeration.hasMoreElements' 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_javautilEnumerationhasMoreElements'"
                    while (props.MoveNext())
                    {
                        //UPGRADE_TODO: Method 'java.util.Enumeration.nextElement' 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_javautilEnumerationnextElement'"
                        System.Object next = props.Current;
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Class.getName' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        //logger.debug("Prop class: " + next.GetType().FullName);
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        //logger.debug("Prop: " + next.ToString());
                        if (next is DictRef)
                        {
                            DictRef dictRef = (DictRef)next;
                            // System.out.println("DictRef type: " + dictRef.getType());
                            if (dictRef.Type.Equals("pdb:residueName"))
                            {
                                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                                aminoAcid.setProperty(RESIDUE_NAME, containers[i].getProperty(dictRef).ToString().ToUpper());
                            }
                            else if (dictRef.Type.Equals("pdb:oneLetterCode"))
                            {
                                aminoAcid.setProperty(RESIDUE_NAME_SHORT, containers[i].getProperty(dictRef));
                            }
                            else if (dictRef.Type.Equals("pdb:id"))
                            {
                                aminoAcid.setProperty(ID, containers[i].getProperty(dictRef));
                                //logger.debug("Set AA ID to: ", containers[i].getProperty(dictRef));
                            }
                            else
                            {
                                //logger.error("Cannot deal with dictRef!");
                            }
                        }
                    }
                    for (int atomCount = 0; atomCount < atoms.Length; atomCount++)
                    {
                        IAtom         atom    = atoms[atomCount];
                        System.String dictRef = (System.String)atom.getProperty("org.openscience.cdk.dict");
                        if (dictRef != null && dictRef.Equals("pdb:nTerminus"))
                        {
                            aminoAcid.addNTerminus(atom);
                        }
                        else if (dictRef != null && dictRef.Equals("pdb:cTerminus"))
                        {
                            aminoAcid.addCTerminus(atom);
                        }
                        else
                        {
                            aminoAcid.addAtom(atom);
                        }
                    }
                    IBond[] bonds = containers[i].Bonds;
                    for (int bondCount = 0; bondCount < bonds.Length; bondCount++)
                    {
                        aminoAcid.addBond(bonds[bondCount]);
                    }
                    AminoAcidManipulator.removeAcidicOxygen(aminoAcid);
                    aminoAcid.setProperty(NO_ATOMS, "" + aminoAcid.AtomCount);
                    aminoAcid.setProperty(NO_BONDS, "" + aminoAcid.getBondCount());
                    if (i < aminoAcids.Length)
                    {
                        aminoAcids[i] = aminoAcid;
                    }
                    else
                    {
                        //logger.error("Could not store AminoAcid! Array too short!");
                    }
                }
            }
            catch (System.Exception exception)
            {
                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                //logger.error("Failed reading file: ", exception.Message);
                //logger.debug(exception);
            }

            return(aminoAcids);
        }