コード例 #1
0
ファイル: Mmff.cs プロジェクト: roddickchen/NCDK
        /// <summary>
        /// Assign MMFF Symbolic atom types. The symbolic type can be accessed with
        /// <see cref="IAtomType.AtomTypeName"/>. An atom of unknown type is assigned the
        /// symbolic type <c>"UNK"</c>.
        /// All atoms, including hydrogens must be explicitly represented.
        /// </summary>
        /// <param name="mol">molecule</param>
        /// <returns>all atoms had a type assigned</returns>
        public virtual bool AssignAtomTypes(IAtomContainer mol)
        {
            // preconditions need explicit hydrogens
            foreach (var atom in mol.Atoms)
            {
                if (atom.ImplicitHydrogenCount == null || atom.ImplicitHydrogenCount > 0)
                {
                    throw new ArgumentException("Hydrogens must be explicit nodes, each must have a zero (non-null) impl H count.");
                }
            }

            // conversion to faster data structures
            var edgeMap = EdgeToBondMap.WithSpaceFor(mol);
            var adjList = GraphUtil.ToAdjList(mol, edgeMap);

            mol.SetProperty(MMFF_ADJLIST_CACHE, adjList);
            mol.SetProperty(MMFF_EDGEMAP_CACHE, edgeMap);

            var aromBonds = new HashSet <IBond>();
            var oldArom   = GetAromatics(mol);

            // note: for MMFF we need to remove current aromatic flags for type
            // assignment (they are restored after)
            foreach (var chemObj in oldArom)
            {
                chemObj.IsAromatic = false;
            }
            var atomTypes = mmffAtomTyper.SymbolicTypes(mol, adjList, edgeMap, aromBonds);

            bool hasUnkType = false;

            for (int i = 0; i < mol.Atoms.Count; i++)
            {
                if (atomTypes[i] == null)
                {
                    mol.Atoms[i].AtomTypeName = "UNK";
                    hasUnkType = true;
                }
                else
                {
                    mol.Atoms[i].AtomTypeName = atomTypes[i];
                }
            }

            // restore aromatic flags and mark the MMFF aromatic bonds
            foreach (var chemObj in oldArom)
            {
                chemObj.IsAromatic = true;
            }
            foreach (var bond in aromBonds)
            {
                bond.SetProperty(MMFF_AROM, true);
            }

            return(!hasUnkType);
        }
コード例 #2
0
        public void HydrogenCountMustBeDefined()
        {
            var container = CDK.Builder.NewAtomContainer();

            container.Atoms.Add(new Atom("C"));
            container.Atoms.Add(new Atom("H"));
            container.Atoms.Add(new Atom("H"));
            container.Atoms.Add(new Atom("H"));
            container.Atoms.Add(new Atom("H"));
            container.AddBond(container.Atoms[0], container.Atoms[1], BondOrder.Single);
            container.AddBond(container.Atoms[0], container.Atoms[2], BondOrder.Single);
            container.AddBond(container.Atoms[0], container.Atoms[3], BondOrder.Single);
            container.AddBond(container.Atoms[0], container.Atoms[4], BondOrder.Single);
            container.Atoms[0].ImplicitHydrogenCount = null;
            Instance.SymbolicTypes(container);
        }
コード例 #3
0
 public override string[] Assign(IAtomContainer container)
 {
     return(Instance.SymbolicTypes(container));
 }