Esempio n. 1
0
		/// <summary>  Description of the Method
		/// 
		/// </summary>
		/// <param name="smiles">                     Description of the Parameter
		/// </param>
		/// <returns>                             Description of the Return Value
		/// </returns>
		/// <exception cref="InvalidSmilesException"> Description of the Exception
		/// </exception>
		public virtual Reaction parseReactionSmiles(System.String smiles)
		{
			SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(smiles, ">");
			System.String reactantSmiles = tokenizer.NextToken();
			System.String agentSmiles = "";
			System.String productSmiles = tokenizer.NextToken();
			if (tokenizer.HasMoreTokens())
			{
				agentSmiles = productSmiles;
				productSmiles = tokenizer.NextToken();
			}
			
			Reaction reaction = new Reaction();
			
			// add reactants
			IMolecule reactantContainer = parseSmiles(reactantSmiles);
			ISetOfMolecules reactantSet = ConnectivityChecker.partitionIntoMolecules(reactantContainer);
			IMolecule[] reactants = reactantSet.Molecules;
			for (int i = 0; i < reactants.Length; i++)
			{
				reaction.addReactant(reactants[i]);
			}
			
			// add reactants
			if (agentSmiles.Length > 0)
			{
				IMolecule agentContainer = parseSmiles(agentSmiles);
				ISetOfMolecules agentSet = ConnectivityChecker.partitionIntoMolecules(agentContainer);
				IMolecule[] agents = agentSet.Molecules;
				for (int i = 0; i < agents.Length; i++)
				{
					reaction.addAgent(agents[i]);
				}
			}
			
			// add products
			IMolecule productContainer = parseSmiles(productSmiles);
			ISetOfMolecules productSet = ConnectivityChecker.partitionIntoMolecules(productContainer);
			IMolecule[] products = productSet.Molecules;
			for (int i = 0; i < products.Length; i++)
			{
				reaction.addProduct(products[i]);
			}
			
			return reaction;
		}
Esempio n. 2
0
 private int addArrayElementsTo(System.Collections.ArrayList toAddto, System.String array)
 {
     SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(array);
     int i = 0;
     while (tokenizer.HasMoreTokens())
     {
         toAddto.Add(tokenizer.NextToken());
         i++;
     }
     return i;
 }
Esempio n. 3
0
        public virtual void endElement(CMLStack xpath, System.String uri, System.String name, System.String raw)
        {
            ////logger.debug("EndElement: ", name);

            System.String cData = currentChars;

            if ("bond".Equals(name))
            {
                if (!stereoGiven)
                    bondStereo.Add("");
                if (bondStereo.Count > bondDictRefs.Count)
                    bondDictRefs.Add(null);
            }
            else if ("atom".Equals(name))
            {
                if (atomCounter > eltitles.Count)
                {
                    eltitles.Add(null);
                }
                if (atomCounter > hCounts.Count)
                {
                    /* while strictly undefined, assume zero 
                    implicit hydrogens when no number is given */
                    hCounts.Add("0");
                }
                if (atomCounter > atomDictRefs.Count)
                {
                    atomDictRefs.Add(null);
                }
                if (atomCounter > isotope.Count)
                {
                    isotope.Add(null);
                }
                if (atomCounter > spinMultiplicities.Count)
                {
                    spinMultiplicities.Add(null);
                }
                if (atomCounter > formalCharges.Count)
                {
                    /* while strictly undefined, assume zero 
                    implicit hydrogens when no number is given */
                    formalCharges.Add("0");
                }
                /* It may happen that not all atoms have
                associated 2D or 3D coordinates. accept that */
                if (atomCounter > x2.Count && x2.Count != 0)
                {
                    /* apparently, the previous atoms had atomic
                    coordinates, add 'null' for this atom */
                    x2.Add(null);
                    y2.Add(null);
                }
                if (atomCounter > x3.Count && x3.Count != 0)
                {
                    /* apparently, the previous atoms had atomic
                    coordinates, add 'null' for this atom */
                    x3.Add(null);
                    y3.Add(null);
                    z3.Add(null);
                }

                if (atomCounter > xfract.Count && xfract.Count != 0)
                {
                    /* apparently, the previous atoms had atomic
                    coordinates, add 'null' for this atom */
                    xfract.Add(null);
                    yfract.Add(null);
                    zfract.Add(null);
                }
            }
            else if ("molecule".Equals(name))
            {
                storeData();
                cdo.endObject("Molecule");
            }
            else if ("crystal".Equals(name))
            {
                if (crystalScalar > 0)
                {
                    // convert unit cell parameters to cartesians
                    Vector3d[] axes = CrystalGeometryTools.notionalToCartesian(unitcellparams[0], unitcellparams[1], unitcellparams[2], unitcellparams[3], unitcellparams[4], unitcellparams[5]);
                    aAxis = axes[0];
                    bAxis = axes[1];
                    cAxis = axes[2];
                    cartesianAxesSet = true;
                    cdo.startObject("a-axis");
                    cdo.setObjectProperty("a-axis", "x", aAxis.x.ToString());
                    cdo.setObjectProperty("a-axis", "y", aAxis.y.ToString());
                    cdo.setObjectProperty("a-axis", "z", aAxis.z.ToString());
                    cdo.endObject("a-axis");
                    cdo.startObject("b-axis");
                    cdo.setObjectProperty("b-axis", "x", bAxis.x.ToString());
                    cdo.setObjectProperty("b-axis", "y", bAxis.y.ToString());
                    cdo.setObjectProperty("b-axis", "z", bAxis.z.ToString());
                    cdo.endObject("b-axis");
                    cdo.startObject("c-axis");
                    cdo.setObjectProperty("c-axis", "x", cAxis.x.ToString());
                    cdo.setObjectProperty("c-axis", "y", cAxis.y.ToString());
                    cdo.setObjectProperty("c-axis", "z", cAxis.z.ToString());
                    cdo.endObject("c-axis");
                }
                else
                {
                    ////logger.error("Could not find crystal unit cell parameters");
                }
                cdo.endObject("Crystal");
            }
            else if ("list".Equals(name))
            {
                cdo.endObject("SetOfMolecules");
            }
            else if ("coordinate3".Equals(name))
            {
                if (BUILTIN.Equals("xyz3"))
                {
                    ////logger.debug("New coord3 xyz3 found: ", currentChars);

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(currentChars);
                        x3.Add(st.NextToken());
                        y3.Add(st.NextToken());
                        z3.Add(st.NextToken());
                        ////logger.debug("coord3 x3.length: ", x3.Count);
                        ////logger.debug("coord3 y3.length: ", y3.Count);
                        ////logger.debug("coord3 z3.length: ", z3.Count);
                    }
                    catch (System.Exception exception)
                    {
                        ////logger.error("CMLParsing error while setting coordinate3!");
                        ////logger.debug(exception);
                    }
                }
                else
                {
                    ////logger.warn("Unknown coordinate3 BUILTIN: " + BUILTIN);
                }
            }
            else if ("string".Equals(name))
            {
                if (BUILTIN.Equals("elementType"))
                {
                    ////logger.debug("Element: ", cData.Trim());
                    elsym.Add(cData);
                }
                else if (BUILTIN.Equals("atomRef"))
                {
                    curRef++;
                    ////logger.debug("Bond: ref #", curRef);

                    if (curRef == 1)
                    {
                        bondARef1.Add(cData.Trim());
                    }
                    else if (curRef == 2)
                    {
                        bondARef2.Add(cData.Trim());
                    }
                }
                else if (BUILTIN.Equals("order"))
                {
                    ////logger.debug("Bond: order ", cData.Trim());
                    order.Add(cData.Trim());
                }
                else if (BUILTIN.Equals("formalCharge"))
                {
                    // NOTE: this combination is in violation of the CML DTD!!!
                    ////logger.warn("formalCharge BUILTIN accepted but violating CML DTD");
                    ////logger.debug("Charge: ", cData.Trim());
                    System.String charge = cData.Trim();
                    if (charge.StartsWith("+") && charge.Length > 1)
                    {
                        charge = charge.Substring(1);
                    }
                    formalCharges.Add(charge);
                }
            }
            else if ("float".Equals(name))
            {
                if (BUILTIN.Equals("x3"))
                {
                    x3.Add(cData.Trim());
                }
                else if (BUILTIN.Equals("y3"))
                {
                    y3.Add(cData.Trim());
                }
                else if (BUILTIN.Equals("z3"))
                {
                    z3.Add(cData.Trim());
                }
                else if (BUILTIN.Equals("x2"))
                {
                    x2.Add(cData.Trim());
                }
                else if (BUILTIN.Equals("y2"))
                {
                    y2.Add(cData.Trim());
                }
                else if (BUILTIN.Equals("order"))
                {
                    // NOTE: this combination is in violation of the CML DTD!!!
                    order.Add(cData.Trim());
                }
                else if (BUILTIN.Equals("charge") || BUILTIN.Equals("partialCharge"))
                {
                    partialCharges.Add(cData.Trim());
                }
            }
            else if ("integer".Equals(name))
            {
                if (BUILTIN.Equals("formalCharge"))
                {
                    formalCharges.Add(cData.Trim());
                }
            }
            else if ("coordinate2".Equals(name))
            {
                if (BUILTIN.Equals("xy2"))
                {
                    ////logger.debug("New coord2 xy2 found.", cData);

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);
                        x2.Add(st.NextToken());
                        y2.Add(st.NextToken());
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 175, 1);
                    }
                }
            }
            else if ("stringArray".Equals(name))
            {
                if (BUILTIN.Equals("id") || BUILTIN.Equals("atomId") || BUILTIN.Equals("atomID"))
                {
                    // invalid according to CML1 DTD but found in OpenBabel 1.x output

                    try
                    {
                        bool countAtoms = (atomCounter == 0) ? true : false;
                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                        {
                            if (countAtoms)
                            {
                                atomCounter++;
                            }
                            System.String token = st.NextToken();
                            ////logger.debug("StringArray (Token): ", token);
                            elid.Add(token);
                        }
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 186, 1);
                    }
                }
                else if (BUILTIN.Equals("elementType"))
                {

                    try
                    {
                        bool countAtoms = (atomCounter == 0) ? true : false;
                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                        {
                            if (countAtoms)
                            {
                                atomCounter++;
                            }
                            elsym.Add(st.NextToken());
                        }
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 194, 1);
                    }
                }
                else if (BUILTIN.Equals("atomRefs"))
                {
                    curRef++;
                    ////logger.debug("New atomRefs found: ", curRef);

                    try
                    {
                        bool countBonds = (bondCounter == 0) ? true : false;
                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                        {
                            if (countBonds)
                            {
                                bondCounter++;
                            }
                            System.String token = st.NextToken();
                            ////logger.debug("Token: ", token);

                            if (curRef == 1)
                            {
                                bondARef1.Add(token);
                            }
                            else if (curRef == 2)
                            {
                                bondARef2.Add(token);
                            }
                        }
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 194, 1);
                    }
                }
                else if (BUILTIN.Equals("atomRef"))
                {
                    curRef++;
                    ////logger.debug("New atomRef found: ", curRef); // this is CML1 stuff, we get things like:
                    /*
                    <bondArray>
                    <stringArray builtin="atomRef">a2 a2 a2 a2 a3 a3 a4 a4 a5 a6 a7 a9</stringArray>
                    <stringArray builtin="atomRef">a9 a11 a12 a13 a5 a4 a6 a9 a7 a8 a8 a10</stringArray>
                    <stringArray builtin="order">1 1 1 1 2 1 2 1 1 1 2 2</stringArray>
                    </bondArray>
                    */

                    try
                    {
                        bool countBonds = (bondCounter == 0) ? true : false;
                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                        {
                            if (countBonds)
                            {
                                bondCounter++;
                            }
                            System.String token = st.NextToken();
                            ////logger.debug("Token: ", token);

                            if (curRef == 1)
                            {
                                bondARef1.Add(token);
                            }
                            else if (curRef == 2)
                            {
                                bondARef2.Add(token);
                            }
                        }
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 194, 1);
                    }
                }
                else if (BUILTIN.Equals("order"))
                {
                    ////logger.debug("New bond order found.");

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                        {

                            System.String token = st.NextToken();
                            ////logger.debug("Token: ", token);
                            order.Add(token);
                        }
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 194, 1);
                    }
                }
            }
            else if ("integerArray".Equals(name))
            {
                ////logger.debug("IntegerArray: builtin = ", BUILTIN);

                if (BUILTIN.Equals("formalCharge"))
                {

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                        {

                            System.String token = st.NextToken();
                            ////logger.debug("Charge added: ", token);
                            formalCharges.Add(token);
                        }
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 205, 1);
                    }
                }
            }
            else if ("scalar".Equals(name))
            {
                if (xpath.ToString().EndsWith("crystal/scalar/"))
                {
                    ////logger.debug("Going to set a crystal parameter: " + crystalScalar, " to ", cData);
                    try
                    {
                        unitcellparams[crystalScalar - 1] = System.Double.Parse(cData.Trim());
                    }
                    catch (System.FormatException exception)
                    {
                        ////logger.error("Content must a float: " + cData);
                    }
                }
                else
                {
                    if (xpath.ToString().EndsWith("bond/scalar/"))
                    {
                        if (DICTREF.Equals("mdl:stereo"))
                        {
                            bondStereo.Add(cData.Trim());
                            stereoGiven = true;
                        }
                    }
                    else
                    {
                        if (xpath.ToString().EndsWith("atom/scalar/"))
                        {
                            if (DICTREF.Equals("cdk:partialCharge"))
                            {
                                partialCharges.Add(cData.Trim());
                            }
                        }
                        else
                        {
                            if (xpath.ToString().EndsWith("molecule/scalar/"))
                            {
                                if (DICTREF.Equals("pdb:id"))
                                {
                                    cdo.setObjectProperty("Molecule", DICTREF, cData);
                                }
                            }
                            else
                            {
                                ////logger.warn("Ignoring scalar: " + xpath);
                            }
                        }
                    }
                }
            }
            else if ("floatArray".Equals(name))
            {
                if (BUILTIN.Equals("x3"))
                {

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                            x3.Add(st.NextToken());
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 205, 1);
                    }
                }
                else if (BUILTIN.Equals("y3"))
                {

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                            y3.Add(st.NextToken());
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 213, 1);
                    }
                }
                else if (BUILTIN.Equals("z3"))
                {

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                            z3.Add(st.NextToken());
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 221, 1);
                    }
                }
                else if (BUILTIN.Equals("x2"))
                {
                    ////logger.debug("New floatArray found.");

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                            x2.Add(st.NextToken());
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 205, 1);
                    }
                }
                else if (BUILTIN.Equals("y2"))
                {
                    ////logger.debug("New floatArray found.");

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                            y2.Add(st.NextToken());
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 454, 1);
                    }
                }
                else if (BUILTIN.Equals("partialCharge"))
                {
                    ////logger.debug("New floatArray with partial charges found.");

                    try
                    {

                        SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData);

                        while (st.HasMoreTokens())
                            partialCharges.Add(st.NextToken());
                    }
                    catch (System.Exception e)
                    {
                        //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                        notify("CMLParsing error: " + e, SYSTEMID, 462, 1);
                    }
                }
            }
            else if ("basic".Equals(name))
            {
                // assuming this is the child element of <identifier>
                this.inchi = cData;
            }
            else if ("name".Equals(name))
            {
                if (xpath.ToString().EndsWith("molecule/name/"))
                {
                    cdo.setObjectProperty("Molecule", DICTREF, cData);
                }
            }
            else
            {
                ////logger.warn("Skipping element: " + name);
            }

            currentChars = "";
            BUILTIN = "";
            elementTitle = "";
        }
Esempio n. 4
0
        public override void characterData(CMLStack xpath, char[] ch, int start, int length)
        {

            System.String s = new System.String(ch, start, length).Trim();

            if (isELSYM)
            {
                elsym.Add(s);
            }
            else if (isBond)
            {
                //logger.debug("CD (bond): " + s);

                if (connect_root.Length > 0)
                {

                    SupportClass.Tokenizer st = new SupportClass.Tokenizer(s);

                    while (st.HasMoreTokens())
                    {

                        System.String atom = (System.String)st.NextToken();

                        if (!atom.Equals("0"))
                        {
                            //logger.debug("new bond: " + connect_root + "-" + atom);
                            cdo.startObject("Bond");

                            int atom1 = System.Int32.Parse(connect_root) - 1;
                            int atom2 = System.Int32.Parse(atom) - 1;
                            cdo.setObjectProperty("Bond", "atom1", ((System.Int32)atom1).ToString());
                            cdo.setObjectProperty("Bond", "atom2", ((System.Int32)atom2).ToString());
                            cdo.setObjectProperty("Bond", "order", "1");
                            cdo.endObject("Bond");
                        }
                    }
                }
            }
            else
            {
                base.characterData(xpath, ch, start, length);
            }
        }
Esempio n. 5
0
        /// <summary> Read a Reaction from a file in MDL RXN format
        /// 
        /// </summary>
        /// <returns>  The Reaction that was read from the MDL file.
        /// </returns>
        private IMolecule readMolecule(IMolecule molecule)
        {
            AtomTypeFactory atFactory = null;
            try
            {
                atFactory = AtomTypeFactory.getInstance("mol2_atomtypes.xml", molecule.Builder);
            }
            catch (System.Exception exception)
            {
                System.String error = "Could not instantiate an AtomTypeFactory";
                //logger.error(error);
                //logger.debug(exception);
                throw new CDKException(error, exception);
            }
            try
            {
                System.String line = input.ReadLine();
                int atomCount = 0;
                int bondCount = 0;
                while (line != null)
                {
                    if (line.StartsWith("@<TRIPOS>MOLECULE"))
                    {
                        //logger.info("Reading molecule block");
                        // second line has atom/bond counts?
                        input.ReadLine(); // disregard the name line
                        System.String counts = input.ReadLine();
                        SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(counts);
                        try
                        {
                            atomCount = System.Int32.Parse(tokenizer.NextToken());
                        }
                        catch (System.FormatException nfExc)
                        {
                            System.String error = "Error while reading atom count from MOLECULE block";
                            //logger.error(error);
                            //logger.debug(nfExc);
                            throw new CDKException(error, nfExc);
                        }
                        if (tokenizer.HasMoreTokens())
                        {
                            try
                            {
                                bondCount = System.Int32.Parse(tokenizer.NextToken());
                            }
                            catch (System.FormatException nfExc)
                            {
                                System.String error = "Error while reading atom and bond counts";
                                //logger.error(error);
                                //logger.debug(nfExc);
                                throw new CDKException(error, nfExc);
                            }
                        }
                        else
                        {
                            bondCount = 0;
                        }
                        //logger.info("Reading #atoms: ", atomCount);
                        //logger.info("Reading #bonds: ", bondCount);

                        //logger.warn("Not reading molecule qualifiers");
                    }
                    else if (line.StartsWith("@<TRIPOS>ATOM"))
                    {
                        //logger.info("Reading atom block");
                        for (int i = 0; i < atomCount; i++)
                        {
                            line = input.ReadLine().Trim();
                            SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line);
                            tokenizer.NextToken(); // disregard the id token
                            System.String nameStr = tokenizer.NextToken();
                            System.String xStr = tokenizer.NextToken();
                            System.String yStr = tokenizer.NextToken();
                            System.String zStr = tokenizer.NextToken();
                            System.String atomTypeStr = tokenizer.NextToken();
                            IAtomType atomType = atFactory.getAtomType(atomTypeStr);
                            if (atomType == null)
                            {
                                atomType = atFactory.getAtomType("X");
                                //logger.error("Could not find specified atom type: ", atomTypeStr);
                            }
                            IAtom atom = molecule.Builder.newAtom("X");
                            atom.ID = nameStr;
                            atom.AtomTypeName = atomTypeStr;
                            atFactory.configure(atom);
                            try
                            {
                                double x = System.Double.Parse(xStr);
                                double y = System.Double.Parse(yStr);
                                double z = System.Double.Parse(zStr);
                                atom.setPoint3d(new Point3d(x, y, z));
                            }
                            catch (System.FormatException nfExc)
                            {
                                System.String error = "Error while reading atom coordinates";
                                //logger.error(error);
                                //logger.debug(nfExc);
                                throw new CDKException(error, nfExc);
                            }
                            molecule.addAtom(atom);
                        }
                    }
                    else if (line.StartsWith("@<TRIPOS>BOND"))
                    {
                        //logger.info("Reading bond block");
                        for (int i = 0; i < bondCount; i++)
                        {
                            line = input.ReadLine();
                            SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line);
                            tokenizer.NextToken(); // disregard the id token
                            System.String atom1Str = tokenizer.NextToken();
                            System.String atom2Str = tokenizer.NextToken();
                            System.String orderStr = tokenizer.NextToken();
                            try
                            {
                                int atom1 = System.Int32.Parse(atom1Str);
                                int atom2 = System.Int32.Parse(atom2Str);
                                double order = 0;
                                if ("1".Equals(orderStr))
                                {
                                    order = CDKConstants.BONDORDER_AROMATIC;
                                }
                                else if ("2".Equals(orderStr))
                                {
                                    order = CDKConstants.BONDORDER_DOUBLE;
                                }
                                else if ("3".Equals(orderStr))
                                {
                                    order = CDKConstants.BONDORDER_TRIPLE;
                                }
                                else if ("am".Equals(orderStr))
                                {
                                    order = CDKConstants.BONDORDER_SINGLE;
                                }
                                else if ("ar".Equals(orderStr))
                                {
                                    order = CDKConstants.BONDORDER_AROMATIC;
                                }
                                else if ("du".Equals(orderStr))
                                {
                                    order = CDKConstants.BONDORDER_SINGLE;
                                }
                                else if ("un".Equals(orderStr))
                                {
                                    order = CDKConstants.BONDORDER_SINGLE;
                                }
                                else if ("nc".Equals(orderStr))
                                {
                                    // not connected
                                    order = 0;
                                }
                                if (order != 0)
                                {
                                    molecule.addBond(atom1 - 1, atom2 - 1, order);
                                }
                            }
                            catch (System.FormatException nfExc)
                            {
                                System.String error = "Error while reading bond information";
                                //logger.error(error);
                                //logger.debug(nfExc);
                                throw new CDKException(error, nfExc);
                            }
                        }
                    }
                    line = input.ReadLine();
                }
            }
            catch (System.IO.IOException exception)
            {
                System.String error = "Error while reading general structure";
                //logger.error(error);
                //logger.debug(exception);
                throw new CDKException(error, exception);
            }
            return molecule;
        }
Esempio n. 6
0
 private void addDictRefedAnnotation(IChemObject object_Renamed, System.String type, System.String values)
 {
     SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(values, ",");
     while (tokenizer.HasMoreTokens())
     {
         System.String token = tokenizer.NextToken();
         object_Renamed.setProperty(new DictRef("macie:" + type, token), token);
         //logger.debug("Added dict ref ", token, " to ", object_Renamed.GetType().FullName);
     }
 }
Esempio n. 7
0
 private void processAnnotation(System.String field, System.String value_Renamed, Reaction reaction)
 {
     //logger.debug("Annote: ", field, "=", value_Renamed);
     if (field.Equals("RxnAtts") || field.Equals("RxnType"))
     {
         // reaction attributes
         System.String dictionary = "macie";
         if (value_Renamed.Equals("Acid") || value_Renamed.Equals("Base"))
         {
             dictionary = "chemical";
         }
         addDictRefedAnnotation(reaction, "Attributes", value_Renamed);
     }
     else if (field.Equals("ResiduesPresent") || field.Equals("GroupTransferred") || field.Equals("BondFormed") || field.Equals("ReactiveCentres") || field.Equals("BondCleaved") || field.Equals("BondFormed") || field.Equals("Products") || field.Equals("ResiduesPresent"))
     {
         reaction.setProperty(new DictRef("macie:" + field, value_Renamed), value_Renamed);
     }
     else if (field.Equals("Reversible"))
     {
         if (value_Renamed.ToUpper().Equals("yes".ToUpper()))
         {
             reaction.Direction = IReaction_Fields.BIDIRECTIONAL;
             addDictRefedAnnotation(reaction, "ReactionType", "ReversibleReaction");
         }
     }
     else if (field.Equals("OverallReactionType"))
     {
         SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(value_Renamed, ",");
         int i = 0;
         while (tokenizer.HasMoreTokens())
         {
             System.String token = tokenizer.NextToken();
             i++;
             reaction.setProperty(DictionaryDatabase.DICTREFPROPERTYNAME + ":field:overallReactionType:" + i, "macie:" + token.ToLower());
         }
     }
     else
     {
         Match residueLocatorMatcher = residueLocator.Match(field);
         if (residueLocatorMatcher.Success)
         {
             //logger.debug("Found residueLocator: ", field);
             IAtom[] atoms = ReactionManipulator.getAllInOneContainer(reaction).Atoms;
             bool found = false;
             //logger.debug("Searching for given residueLocator through #atom: ", atoms.Length);
             //logger.debug("Taken from reaction ", reaction.ID);
             for (int i = 0; (i < atoms.Length && !found); i++)
             {
                 if (atoms[i] is PseudoAtom)
                 {
                     // that is what we are looking for
                     PseudoAtom atom = (PseudoAtom)atoms[i];
                     if (atom.Label.Equals(field))
                     {
                         // we have a hit, now mark Atom with dict refs
                         addDictRefedAnnotation(atom, "ResidueRole", value_Renamed);
                         found = true;
                     }
                 }
             }
             if (!found)
             {
                 //logger.error("MACiE annotation mentions a residue that does not exist: " + field);
             }
         }
         else
         {
             //logger.error("Did not parse annotation: ", field);
         }
     }
 }
        /// <summary>  Reads a set of vibrations into ChemFrame.
        /// 
        /// </summary>
        /// <param name="model">           Description of the Parameter
        /// </param>
        /// <exception cref="IOException"> if an I/O error occurs
        /// </exception>
        //	private void readFrequencies(IChemModel model) throws IOException
        //	{
        /*
        *  FIXME: this is yet to be ported
        *  String line;
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  while ((line != null) && line.startsWith(" Frequencies --")) {
        *  Vector currentVibs = new Vector();
        *  StringReader vibValRead = new StringReader(line.substring(15));
        *  StreamTokenizer token = new StreamTokenizer(vibValRead);
        *  while (token.nextToken() != StreamTokenizer.TT_EOF) {
        *  Vibration vib = new Vibration(Double.toString(token.nval));
        *  currentVibs.addElement(vib);
        *  }
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  for (int i = 0; i < frame.getAtomCount(); ++i) {
        *  line = input.readLine();
        *  StringReader vectorRead = new StringReader(line);
        *  token = new StreamTokenizer(vectorRead);
        *  token.nextToken();
        *  / ignore first token
        *  token.nextToken();
        *  / ignore second token
        *  for (int j = 0; j < currentVibs.size(); ++j) {
        *  double[] v = new double[3];
        *  if (token.nextToken() == StreamTokenizer.TT_NUMBER) {
        *  v[0] = token.nval;
        *  } else {
        *  throw new IOException("Error reading frequency");
        *  }
        *  if (token.nextToken() == StreamTokenizer.TT_NUMBER) {
        *  v[1] = token.nval;
        *  } else {
        *  throw new IOException("Error reading frequency");
        *  }
        *  if (token.nextToken() == StreamTokenizer.TT_NUMBER) {
        *  v[2] = token.nval;
        *  } else {
        *  throw new IOException("Error reading frequency");
        *  }
        *  ((Vibration) currentVibs.elementAt(j)).addAtomVector(v);
        *  }
        *  }
        *  for (int i = 0; i < currentVibs.size(); ++i) {
        *  frame.addVibration((Vibration) currentVibs.elementAt(i));
        *  }
        *  line = input.readLine();
        *  line = input.readLine();
        *  line = input.readLine();
        *  }
        */
        //	}


        /// <summary> Reads NMR nuclear shieldings.
        /// 
        /// </summary>
        /// <param name="model">    Description of the Parameter
        /// </param>
        /// <param name="labelLine">Description of the Parameter
        /// </param>
        /// <throws>  CDKException Description of the Exception </throws>
        private void readNMRData(IChemModel model, System.String labelLine)
        {
            IAtomContainer ac = ChemModelManipulator.getAllInOneContainer(model);
            // Determine label for properties
            System.String label;
            if (labelLine.IndexOf("Diamagnetic") >= 0)
            {
                label = "Diamagnetic Magnetic shielding (Isotropic)";
            }
            else if (labelLine.IndexOf("Paramagnetic") >= 0)
            {
                label = "Paramagnetic Magnetic shielding (Isotropic)";
            }
            else
            {
                label = "Magnetic shielding (Isotropic)";
            }
            int atomIndex = 0;
            for (int i = 0; i < atomCount; ++i)
            {
                try
                {
                    System.String line = input.ReadLine().Trim();
                    while (line.IndexOf("Isotropic") < 0)
                    {
                        if (line == null)
                        {
                            return;
                        }
                        line = input.ReadLine().Trim();
                    }
                    SupportClass.Tokenizer st1 = new SupportClass.Tokenizer(line);

                    // Find Isotropic label
                    while (st1.HasMoreTokens())
                    {
                        if (st1.NextToken().Equals("Isotropic"))
                        {
                            break;
                        }
                    }

                    // Find Isotropic value
                    while (st1.HasMoreTokens())
                    {
                        if (st1.NextToken().Equals("="))
                            break;
                    }
                    double shielding = System.Double.Parse(st1.NextToken());
                    //logger.info("Type of shielding: " + label);
                    ac.getAtomAt(atomIndex).setProperty(CDKConstants.ISOTROPIC_SHIELDING, (System.Object)shielding);
                    ++atomIndex;
                }
                catch (System.Exception exc)
                {
                    //logger.debug("failed to read line from gaussian98 file where I expected one.");
                }
            }
        }