コード例 #1
0
        public virtual void TestContains_IAtomContainer()
        {
            IRingSet ringset = (IRingSet)NewChemObject();

            IAtom ring1Atom1  = ringset.Builder.NewAtom("C"); // rather artificial molecule
            IAtom ring1Atom2  = ringset.Builder.NewAtom("C");
            IAtom sharedAtom1 = ringset.Builder.NewAtom("C");
            IAtom sharedAtom2 = ringset.Builder.NewAtom("C");
            IAtom ring2Atom1  = ringset.Builder.NewAtom("C");
            IAtom ring2Atom2  = ringset.Builder.NewAtom("C");
            IBond ring1Bond1  = ringset.Builder.NewBond(ring1Atom1, ring1Atom2);
            IBond ring1Bond2  = ringset.Builder.NewBond(sharedAtom1, ring1Atom1);
            IBond ring1Bond3  = ringset.Builder.NewBond(sharedAtom2, ring1Atom2);
            IBond sharedBond  = ringset.Builder.NewBond(sharedAtom1, sharedAtom2);
            IBond ring2Bond1  = ringset.Builder.NewBond(ring2Atom1, ring2Atom2);
            IBond ring2Bond2  = ringset.Builder.NewBond(sharedAtom1, ring2Atom1);
            IBond ring2Bond3  = ringset.Builder.NewBond(sharedAtom2, ring2Atom2);

            IRing ring1 = ringset.Builder.NewRing();

            ring1.Atoms.Add(ring1Atom1);
            ring1.Atoms.Add(ring1Atom2);
            ring1.Atoms.Add(sharedAtom1);
            ring1.Atoms.Add(sharedAtom2);
            ring1.Bonds.Add(ring1Bond1);
            ring1.Bonds.Add(ring1Bond2);
            ring1.Bonds.Add(ring1Bond3);
            ring1.Bonds.Add(sharedBond);
            IRing ring2 = ringset.Builder.NewRing();

            ring2.Atoms.Add(ring2Atom1);
            ring2.Atoms.Add(ring2Atom2);
            ring2.Atoms.Add(sharedAtom1);
            ring2.Atoms.Add(sharedAtom2);
            ring2.Bonds.Add(ring2Bond1);
            ring2.Bonds.Add(ring2Bond2);
            ring2.Bonds.Add(ring2Bond3);
            ring2.Bonds.Add(sharedBond);

            ringset.Add(ring1);
            ringset.Add(ring2);

            Assert.IsTrue(ringset.Contains(ring1));
            Assert.IsTrue(ringset.Contains(ring2));
        }
コード例 #2
0
ファイル: RingPartitioner.cs プロジェクト: ch-hristov/NCDK
        /// <summary>
        /// Perform a walk in the given RingSet, starting at a given Ring and
        /// recursively searching for other Rings connected to this ring. By doing
        /// this it finds all rings in the RingSet connected to the start ring,
        /// putting them in newRs, and removing them from rs.
        /// </summary>
        /// <param name="rs">The RingSet to be searched</param>
        /// <param name="ring">The ring to start with</param>
        /// <param name="newRs">The RingSet containing all Rings connected to ring</param>
        /// <returns>newRs The RingSet containing all Rings connected to ring</returns>
        private static IRingSet WalkRingSystem(IRingSet rs, IRing ring, IRingSet newRs)
        {
            IRing tempRing;
            var   tempRings = rs.GetConnectedRings(ring);

            rs.Remove(ring);
            foreach (var container in tempRings)
            {
                tempRing = (IRing)container;
                if (!newRs.Contains(tempRing))
                {
                    newRs.Add(tempRing);
                    newRs.Add(WalkRingSystem(rs, tempRing, newRs));
                }
            }
            return(newRs);
        }
コード例 #3
0
ファイル: RingSet.tt.cs プロジェクト: roddickchen/NCDK
        /// <summary>
        /// Returns all the rings in the RingSet that share one or more atoms with a given ring.
        /// </summary>
        /// <param name="ring">A ring with which all return rings must share one or more atoms</param>
        /// <returns>All the rings that share one or more atoms with a given ring.</returns>
        public IEnumerable <IRing> GetConnectedRings(IRing ring)
        {
            IRingSet connectedRings = ring.Builder.NewRingSet();

            foreach (var atom in ring.Atoms)
            {
                foreach (var tempRing in this)
                {
                    if (tempRing != ring &&
                        !connectedRings.Contains(tempRing) &&
                        tempRing.Contains(atom))
                    {
                        connectedRings.Add(tempRing);
                    }
                }
            }
            return(connectedRings);
        }
コード例 #4
0
        /// <summary>
        ///  Method assigns atom types to atoms (calculates sssr and aromaticity)
        /// </summary>
        /// <returns>sssrf set</returns>
        /// <exception cref="CDKException"> Problems detecting aromaticity or making hose codes.</exception>
        public IRingSet AssignAtomTyps(IAtomContainer molecule)
        {
            IAtom             atom     = null;
            string            hoseCode = "";
            HOSECodeGenerator hcg      = new HOSECodeGenerator();
            int      NumberOfRingAtoms = 0;
            IRingSet ringSetMolecule   = Cycles.FindSSSR(molecule).ToRingSet();
            bool     isInHeteroRing    = false;

            try
            {
                AtomContainerManipulator.PercieveAtomTypesAndConfigureAtoms(molecule);
                Aromaticity.CDKLegacy.Apply(molecule);
            }
            catch (Exception cdk1)
            {
                throw new CDKException("AROMATICITYError: Cannot determine aromaticity due to: " + cdk1.Message, cdk1);
            }

            for (int i = 0; i < molecule.Atoms.Count; i++)
            {
                atom = molecule.Atoms[i];
                if (ringSetMolecule.Contains(atom))
                {
                    NumberOfRingAtoms = NumberOfRingAtoms + 1;
                    atom.IsInRing     = true;
                    atom.IsAliphatic  = false;
                    var ringSetA = ringSetMolecule.GetRings(atom).ToList();
                    RingSetManipulator.Sort(ringSetA);
                    IRing sring = (IRing)ringSetA[ringSetA.Count - 1];
                    atom.SetProperty("RING_SIZE", sring.RingSize);
                    foreach (var ring in ringSetA)
                    {
                        if (IsHeteroRingSystem(ring))
                        {
                            break;
                        }
                    }
                }
                else
                {
                    atom.IsAliphatic = true;
                    atom.IsInRing    = false;
                    isInHeteroRing   = false;
                }
                atom.SetProperty("MAX_BOND_ORDER", molecule.GetMaximumBondOrder(atom).Numeric());

                try
                {
                    hoseCode = hcg.GetHOSECode(molecule, atom, 3);
                    //Debug.WriteLine("HOSECODE GENERATION: ATOM "+i+" HoseCode: "+hoseCode+" ");
                }
                catch (CDKException ex1)
                {
                    Console.Out.WriteLine("Could not build HOSECode from atom " + i + " due to " + ex1.ToString());
                    throw new CDKException("Could not build HOSECode from atom " + i + " due to " + ex1.ToString(), ex1);
                }
                try
                {
                    ConfigureAtom(atom, hoseCode, isInHeteroRing);
                }
                catch (CDKException ex2)
                {
                    Console.Out.WriteLine("Could not final configure atom " + i + " due to " + ex2.ToString());
                    throw new CDKException("Could not final configure atom due to problems with force field", ex2);
                }
            }

            //        IBond[] bond = molecule.Bonds;
            string bondType;

            foreach (var bond in molecule.Bonds)
            {
                //Debug.WriteLine("bond[" + i + "] properties : " + molecule.Bonds[i].GetProperties());
                bondType = "0";
                if (bond.Order == BondOrder.Single)
                {
                    if ((bond.Begin.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) &&
                        ((bond.End.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) ||
                         (bond.End.AtomTypeName.Equals("C=", StringComparison.Ordinal))))
                    {
                        bondType = "1";
                    }

                    if ((bond.Begin.AtomTypeName.Equals("C=", StringComparison.Ordinal)) &&
                        ((bond.End.AtomTypeName.Equals("Csp2", StringComparison.Ordinal)) ||
                         (bond.End.AtomTypeName.Equals("C=", StringComparison.Ordinal))))
                    {
                        bondType = "1";
                    }

                    if ((bond.Begin.AtomTypeName.Equals("Csp", StringComparison.Ordinal)) &&
                        (bond.End.AtomTypeName.Equals("Csp", StringComparison.Ordinal)))
                    {
                        bondType = "1";
                    }
                }
                //            molecule.Bonds[i].SetProperty("MMFF94 bond type", bondType);
                bond.SetProperty("MMFF94 bond type", bondType);
                //Debug.WriteLine("bond[" + i + "] properties : " + molecule.Bonds[i].GetProperties());
            }

            return(ringSetMolecule);
        }