当前位置: 首页>>代码示例>>C#>>正文


C# IAtomContainer.addAtom方法代码示例

本文整理汇总了C#中IAtomContainer.addAtom方法的典型用法代码示例。如果您正苦于以下问题:C# IAtomContainer.addAtom方法的具体用法?C# IAtomContainer.addAtom怎么用?C# IAtomContainer.addAtom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IAtomContainer的用法示例。


在下文中一共展示了IAtomContainer.addAtom方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: processFormula

        /// <summary> Processes the content from the formula field of the INChI.
        /// Typical values look like C6H6, from INChI=1.12Beta/C6H6/c1-2-4-6-5-3-1/h1-6H.
        /// </summary>
        public virtual IAtomContainer processFormula(IAtomContainer parsedContent, System.String atomsEncoding)
        {
            //logger.debug("Parsing atom data: ", atomsEncoding);

            Regex pattern = new Regex("([A-Z][a-z]?)(\\d+)?(.*)");
            //Pattern pattern = Pattern.compile("([A-Z][a-z]?)(\\d+)?(.*)");
            System.String remainder = atomsEncoding;
            while (remainder.Length > 0)
            {
                //logger.debug("Remaining: ", remainder);
                Match matcher = pattern.Match(remainder);
                //Matcher matcher = pattern.matcher(remainder);
                //if (matcher.matches())
                if (matcher != null && matcher.Success)
                {
                    System.String symbol = matcher.Groups[1].Value;
                    //logger.debug("Atom symbol: ", symbol);
                    if (symbol.Equals("H"))
                    {
                        // don't add explicit hydrogens
                    }
                    else
                    {
                        System.String occurenceStr = matcher.Groups[2].Value;
                        int occurence = 1;
                        if (occurenceStr != null)
                        {
                            occurence = System.Int32.Parse(occurenceStr);
                        }
                        //logger.debug("  occurence: ", occurence);
                        for (int i = 1; i <= occurence; i++)
                        {
                            parsedContent.addAtom(parsedContent.Builder.newAtom(symbol));
                        }
                    }
                    remainder = matcher.Groups[3].Value;
                    if (remainder == null)
                        remainder = "";
                    //logger.debug("  Remaining: ", remainder);
                }
                else
                {
                    //logger.error("No match found!");
                    remainder = "";
                }
                //logger.debug("NO atoms: ", parsedContent.AtomCount);
            }
            return parsedContent;
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:52,代码来源:INChIContentProcessorTool.cs

示例2: readAtomBlock


//.........这里部分代码省略.........
                        //logger.error(error);
                        //logger.debug(exception);
                        throw new CDKException(error, exception);
                    }
                    // parse the element
                    System.String element = tokenizer.NextToken();
                    bool isElement = false;
                    try
                    {
                        isElement = IsotopeFactory.getInstance(atom.Builder).isElement(element);
                    }
                    catch (System.Exception exception)
                    {
                        throw new CDKException("Could not determine if element exists!", exception);
                    }
                    if (isPseudoAtom(element))
                    {
                        atom = readData.Builder.newPseudoAtom(atom);
                    }
                    else if (isElement)
                    {
                        atom.Symbol = element;
                    }
                    else
                    {
                        System.String error = "Cannot parse element of type: " + element;
                        //logger.error(error);
                        throw new CDKException("(Possible CDK bug) " + error);
                    }
                    // parse atom coordinates (in Angstrom)
                    try
                    {
                        System.String xString = tokenizer.NextToken();
                        System.String yString = tokenizer.NextToken();
                        System.String zString = tokenizer.NextToken();
                        double x = System.Double.Parse(xString);
                        double y = System.Double.Parse(yString);
                        double z = System.Double.Parse(zString);
                        atom.setPoint3d(new Point3d(x, y, z));
                        atom.setPoint2d(new Point2d(x, y)); // FIXME: dirty!
                    }
                    catch (System.Exception exception)
                    {
                        System.String error = "Error while parsing atom coordinates";
                        //logger.error(error);
                        //logger.debug(exception);
                        throw new CDKException(error, exception);
                    }
                    // atom-atom mapping
                    System.String mapping = tokenizer.NextToken();
                    if (!mapping.Equals("0"))
                    {
                        //logger.warn("Skipping atom-atom mapping: " + mapping);
                    } // else: default 0 is no mapping defined

                    // the rest are key value things
                    if (command.IndexOf("=") != -1)
                    {
                        System.Collections.Hashtable options = parseOptions(exhaustStringTokenizer(tokenizer));
                        System.Collections.IEnumerator keys = options.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 (keys.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.String key = (System.String)keys.Current;
                            System.String value_Renamed = (System.String)options[key];
                            try
                            {
                                if (key.Equals("CHG"))
                                {
                                    int charge = System.Int32.Parse(value_Renamed);
                                    if (charge != 0)
                                    {
                                        // zero is no charge specified
                                        atom.setFormalCharge(charge);
                                    }
                                }
                                else
                                {
                                    //logger.warn("Not parsing key: " + key);
                                }
                            }
                            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'"
                                System.String error = "Error while parsing key/value " + key + "=" + value_Renamed + ": " + exception.Message;
                                //logger.error(error);
                                //logger.debug(exception);
                                throw new CDKException(error, exception);
                            }
                        }
                    }

                    // store atom
                    readData.addAtom(atom);
                    //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("Added atom: " + atom);
                }
            }
        }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:101,代码来源:MDLV3000Reader.cs

示例3: addExplicitHydrogensToSatisfyValency

		/// <summary> Method that saturates an atom in a molecule by adding explicit hydrogens.
		/// 
		/// </summary>
		/// <param name="atom">     Atom to saturate
		/// </param>
		/// <param name="container">AtomContainer containing the atom
		/// </param>
		/// <param name="count">    Number of hydrogens to add
		/// </param>
		/// <param name="totalContainer">In case you have a container containing multiple structures, this is the total container, whereas container is a partial structure
		/// 
		/// </param>
		/// <cdk.keyword>           hydrogen, adding </cdk.keyword>
		/// <cdk.keyword>           explicit hydrogen </cdk.keyword>
		public virtual IAtomContainer addExplicitHydrogensToSatisfyValency(IAtomContainer container, IAtom atom, int count, IAtomContainer totalContainer)
		{
			//boolean create2DCoordinates = GeometryTools.has2DCoordinates(container);
			
			IIsotope isotope = IsotopeFactory.getInstance(container.Builder).getMajorIsotope("H");
			atom.setHydrogenCount(0);
			IAtomContainer changedAtomsAndBonds = container.Builder.newAtomContainer();
			for (int i = 1; i <= count; i++)
			{
				IAtom hydrogen = container.Builder.newAtom("H");
				IsotopeFactory.getInstance(container.Builder).configure(hydrogen, isotope);
				totalContainer.addAtom(hydrogen);
				IBond newBond = container.Builder.newBond((IAtom) atom, hydrogen, 1.0);
				totalContainer.addBond(newBond);
				changedAtomsAndBonds.addAtom(hydrogen);
				changedAtomsAndBonds.addBond(newBond);
			}
			return changedAtomsAndBonds;
		}
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:33,代码来源:HydrogenAdder.cs

示例4: depthFirstTargetSearch

 /// <summary> Recursivly perfoms a depth first search in a molecular graphs contained in
 /// the AtomContainer molecule, starting at the root atom and returning when it
 /// hits the target atom.
 /// CAUTION: This recursive method sets the VISITED flag of each atom
 /// does not reset it after finishing the search. If you want to do the
 /// operation on the same collection of atoms more than once, you have
 /// to set all the VISITED flags to false before each operation
 /// by looping of the atoms and doing a
 /// "atom.setFlag((CDKConstants.VISITED, false));"
 /// 
 /// </summary>
 /// <param name="molecule">The
 /// AtomContainer to be searched
 /// </param>
 /// <param name="root">    The root atom
 /// to start the search at
 /// </param>
 /// <param name="target">  The target
 /// </param>
 /// <param name="path">    An
 /// AtomContainer to be filled with the path
 /// </param>
 /// <returns> true if the
 /// target atom was found during this function call
 /// </returns>
 public static bool depthFirstTargetSearch(IAtomContainer molecule, IAtom root, IAtom target, IAtomContainer path)
 {
     IBond[] bonds = molecule.getConnectedBonds(root);
     IAtom nextAtom;
     root.setFlag(CDKConstants.VISITED, true);
     for (int f = 0; f < bonds.Length; f++)
     {
         nextAtom = bonds[f].getConnectedAtom(root);
         if (!nextAtom.getFlag(CDKConstants.VISITED))
         {
             path.addAtom(nextAtom);
             path.addBond(bonds[f]);
             if (nextAtom == target)
             {
                 return true;
             }
             else
             {
                 if (!depthFirstTargetSearch(molecule, nextAtom, target, path))
                 {
                     // we did not find the target
                     path.removeAtom(nextAtom);
                     path.removeElectronContainer(bonds[f]);
                 }
                 else
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }
开发者ID:xuchuansheng,项目名称:GenXSource,代码行数:58,代码来源:PathTools.cs


注:本文中的IAtomContainer.addAtom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。