Exemplo n.º 1
0
        public static void removeElectronContainer(IChemModel chemModel, IElectronContainer electrons)
        {
            ICrystal crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.contains(electrons))
                {
                    crystal.removeElectronContainer(electrons);
                }
                return;
            }
            ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;

            if (moleculeSet != null)
            {
                SetOfMoleculesManipulator.removeElectronContainer(moleculeSet, electrons);
            }
            ISetOfReactions reactionSet = chemModel.SetOfReactions;

            if (reactionSet != null)
            {
                SetOfReactionsManipulator.removeElectronContainer(reactionSet, electrons);
            }
        }
Exemplo n.º 2
0
        public static void RemoveElectronContainer(IReaction reaction, IElectronContainer electrons)
        {
            var reactants = reaction.Reactants;

            for (int i = 0; i < reactants.Count; i++)
            {
                IAtomContainer mol = reactants[i];
                if (mol.Contains(electrons))
                {
                    mol.Remove(electrons);
                }
            }
            var agents = reaction.Reactants;

            for (int i = 0; i < agents.Count; i++)
            {
                var mol = agents[i];
                if (mol.Contains(electrons))
                {
                    mol.Remove(electrons);
                }
            }
            var products = reaction.Products;

            for (int i = 0; i < products.Count; i++)
            {
                var mol = products[i];
                if (mol.Contains(electrons))
                {
                    mol.Remove(electrons);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary> Partitions the atoms in an AtomContainer into covalently connected components.
        ///
        /// </summary>
        /// <param name="atomContainer"> The AtomContainer to be partitioned into connected components, i.e. molecules
        /// </param>
        /// <returns>                 A SetOfMolecules.
        ///
        /// </returns>
        /// <cdk.dictref>    blue-obelisk:graphPartitioning </cdk.dictref>
        public static ISetOfMolecules partitionIntoMolecules(IAtomContainer atomContainer)
        {
            IAtomContainer     ac         = atomContainer.Builder.newAtomContainer();
            IAtom              atom       = null;
            IElectronContainer eContainer = null;
            IMolecule          molecule   = null;
            ISetOfMolecules    molecules  = atomContainer.Builder.newSetOfMolecules();

            System.Collections.ArrayList sphere = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            for (int f = 0; f < atomContainer.AtomCount; f++)
            {
                atom = atomContainer.getAtomAt(f);
                atom.setFlag(CDKConstants.VISITED, false);
                ac.addAtom(atom);
            }
            IElectronContainer[] eContainers = atomContainer.ElectronContainers;
            for (int f = 0; f < eContainers.Length; f++)
            {
                eContainer = eContainers[f];
                eContainer.setFlag(CDKConstants.VISITED, false);
                ac.addElectronContainer(eContainer);
            }
            while (ac.AtomCount > 0)
            {
                atom     = ac.getAtomAt(0);
                molecule = atomContainer.Builder.newMolecule();
                sphere.Clear();
                sphere.Add(atom);
                atom.setFlag(CDKConstants.VISITED, true);
                PathTools.breadthFirstSearch(ac, sphere, molecule);
                molecules.addMolecule(molecule);
                ac.remove(molecule);
            }
            return(molecules);
        }
Exemplo n.º 4
0
        public void TestMatchAgainstItself()
        {
            var    m_atom1 = new Mock <IElectronContainer>(); IElectronContainer atom1 = m_atom1.Object;
            string result = ElectronContainerDiff.Diff(atom1, atom1);

            AssertZeroLength(result);
        }
Exemplo n.º 5
0
        /// <summary> Returns the adjacency matrix for the given AtomContainer.
        ///
        /// </summary>
        /// <param name="container">The AtomContainer for which the matrix is calculated
        /// </param>
        /// <returns>           A adjacency matrix representating this AtomContainer
        /// </returns>
        public static int[][] getMatrix(IAtomContainer container)
        {
            IElectronContainer electronContainer = null;
            int indexAtom1;
            int indexAtom2;

            int[][] conMat = new int[container.AtomCount][];
            for (int i = 0; i < container.AtomCount; i++)
            {
                conMat[i] = new int[container.AtomCount];
            }
            for (int f = 0; f < container.ElectronContainerCount; f++)
            {
                electronContainer = container.getElectronContainerAt(f);
                if (electronContainer is IBond)
                {
                    IBond bond = (IBond)electronContainer;
                    indexAtom1 = container.getAtomNumber(bond.getAtomAt(0));
                    indexAtom2 = container.getAtomNumber(bond.getAtomAt(1));
                    conMat[indexAtom1][indexAtom2] = 1;
                    conMat[indexAtom2][indexAtom1] = 1;
                }
            }
            return(conMat);
        }
Exemplo n.º 6
0
        public virtual void TestSetElectronCount_Integer()
        {
            IElectronContainer ec = (IElectronContainer)NewChemObject();

            ec.ElectronCount = 3;
            Assert.AreEqual(3, ec.ElectronCount.Value);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Remove an ElectronContainer from all AtomContainers
        /// inside an IChemModel.
        /// </summary>
        /// <param name="chemModel">The IChemModel object.</param>
        /// <param name="electrons">The ElectronContainer to remove.</param>
        public static void RemoveElectronContainer(IChemModel chemModel, IElectronContainer electrons)
        {
            var crystal = chemModel.Crystal;

            if (crystal != null)
            {
                if (crystal.Contains(electrons))
                {
                    crystal.Remove(electrons);
                }
                return;
            }
            var moleculeSet = chemModel.MoleculeSet;

            if (moleculeSet != null)
            {
                MoleculeSetManipulator.RemoveElectronContainer(moleculeSet, electrons);
            }
            var reactionSet = chemModel.ReactionSet;

            if (reactionSet != null)
            {
                ReactionSetManipulator.RemoveElectronContainer(reactionSet, electrons);
            }
        }
Exemplo n.º 8
0
        public void TestNewElectronContainer()
        {
            IChemObjectBuilder builder   = RootObject.Builder;
            IElectronContainer container = builder.NewElectronContainer();

            Assert.IsNotNull(container);
        }
Exemplo n.º 9
0
 public static void RemoveElectronContainer(IReactionSet set, IElectronContainer electrons)
 {
     foreach (var reaction in set)
     {
         ReactionManipulator.RemoveElectronContainer(reaction, electrons);
     }
 }
        /// <summary>  Uses precomputed set of ALL rings and performs an aromaticity detection
        /// based on Hueckels 4n + 2 rule.
        ///
        /// </summary>
        /// <param name="ringSet">                set of ALL rings
        /// </param>
        /// <param name="removeAromaticityFlags"> Leaves ChemObjects that are already marked as
        /// aromatic as they are
        /// </param>
        /// <param name="atomContainer">          AtomContainer to be searched for rings
        /// </param>
        /// <returns>                         True, if molecules contains an
        /// aromatic feature
        /// </returns>
        public static bool detectAromaticity(IAtomContainer atomContainer, IRingSet ringSet, bool removeAromaticityFlags)
        {
            bool foundSomething = false;

            if (removeAromaticityFlags)
            {
                for (int f = 0; f < atomContainer.AtomCount; f++)
                {
                    atomContainer.getAtomAt(f).setFlag(CDKConstants.ISAROMATIC, false);
                }
                for (int f = 0; f < atomContainer.ElectronContainerCount; f++)
                {
                    IElectronContainer electronContainer = atomContainer.getElectronContainerAt(f);
                    if (electronContainer is IBond)
                    {
                        electronContainer.setFlag(CDKConstants.ISAROMATIC, false);
                    }
                }
                for (int f = 0; f < ringSet.AtomContainerCount; f++)
                {
                    ((IRing)ringSet.getAtomContainer(f)).setFlag(CDKConstants.ISAROMATIC, false);
                }
            }

            IRing ring = null;

            RingSetManipulator.sort(ringSet);
            for (int f = 0; f < ringSet.AtomContainerCount; f++)
            {
                ring = (IRing)ringSet.getAtomContainer(f);
                //logger.debug("Testing for aromaticity in ring no ", f);
                if (AromaticityCalculator.isAromatic(ring, atomContainer))
                {
                    ring.setFlag(CDKConstants.ISAROMATIC, true);

                    for (int g = 0; g < ring.AtomCount; g++)
                    {
                        ring.getAtomAt(g).setFlag(CDKConstants.ISAROMATIC, true);
                    }

                    for (int g = 0; g < ring.ElectronContainerCount; g++)
                    {
                        IElectronContainer electronContainer = ring.getElectronContainerAt(g);
                        if (electronContainer is IBond)
                        {
                            electronContainer.setFlag(CDKConstants.ISAROMATIC, true);
                        }
                    }

                    foundSomething = true;
                    //logger.debug("This ring is aromatic: ", f);
                }
                else
                {
                    //logger.debug("This ring is *not* aromatic: ", f);
                }
            }
            return(foundSomething);
        }
Exemplo n.º 11
0
 private void SerializeElectronContainerFields(INode rdfBond, IElectronContainer bond)
 {
     SerializeChemObjectFields(rdfBond, bond);
     if (bond.ElectronCount != null)
     {
         g.Assert(new Triple(rdfBond, P_HASELECTRONCOUNT, g.CreateLiteralNode(bond.ElectronCount.ToString())));
     }
 }
 public static void removeElectronContainer(ISetOfReactions set_Renamed, IElectronContainer electrons)
 {
     IReaction[] reactions = set_Renamed.Reactions;
     for (int i = 0; i < reactions.Length; i++)
     {
         IReaction reaction = reactions[i];
         ReactionManipulator.removeElectronContainer(reaction, electrons);
     }
 }
 public static void removeElectronContainer(ISetOfReactions set_Renamed, IElectronContainer electrons)
 {
     IReaction[] reactions = set_Renamed.Reactions;
     for (int i = 0; i < reactions.Length; i++)
     {
         IReaction reaction = reactions[i];
         ReactionManipulator.removeElectronContainer(reaction, electrons);
     }
 }
Exemplo n.º 14
0
        public override void TestSetElectronCount_Integer()
        {
            IElectronContainer ec = (IElectronContainer)NewChemObject();

            ec.ElectronCount = 3;
            Assert.AreEqual(2, ec.ElectronCount.Value);
            ec.ElectronCount = null;
            Assert.AreEqual(2, ec.ElectronCount.Value);
        }
Exemplo n.º 15
0
        private void DeserializeElectronContainerFields(INode rdfObject, IElectronContainer bond)
        {
            DeserializeChemObjectFields(rdfObject, bond);
            var count = g.GetTriplesWithSubjectPredicate(rdfObject, P_HASELECTRONCOUNT).Select(n => n.Object).FirstOrDefault();

            if (count != null)
            {
                bond.ElectronCount = int.Parse(count.ToString(), NumberFormatInfo.InvariantInfo);
            }
        }
Exemplo n.º 16
0
        public override void TestClone()
        {
            IElectronContainer ec = (IElectronContainer)NewChemObject();

            ec.ElectronCount = 2;
            object clone = ec.Clone();

            Assert.IsNotNull(clone);
            Assert.IsTrue(clone is IElectronContainer);
        }
Exemplo n.º 17
0
        public virtual void TestToString()
        {
            IElectronContainer at          = (IElectronContainer)NewChemObject();
            string             description = at.ToString();

            for (int i = 0; i < description.Length; i++)
            {
                Assert.IsTrue(description[i] != '\n');
                Assert.IsTrue(description[i] != '\r');
            }
        }
Exemplo n.º 18
0
        public void TestDifference()
        {
            var m_ec1 = new Mock <IElectronContainer>(); IElectronContainer ec1 = m_ec1.Object;
            var m_ec2 = new Mock <IElectronContainer>(); IElectronContainer ec2 = m_ec2.Object;

            m_ec1.SetupGet(n => n.ElectronCount).Returns(2);
            m_ec2.SetupGet(n => n.ElectronCount).Returns(3);

            IDifference difference = ElectronContainerDiff.Difference(ec1, ec2);

            Assert.IsNotNull(difference);
        }
Exemplo n.º 19
0
        public ValidationReport ValidateElectronContainer(IElectronContainer subject)
        {
            Trace.TraceInformation($"Validating {nameof(IElectronContainer)}");
            var report = new ValidationReport();

            // apply validators
            foreach (var test in validators.Values)
            {
                report.Add(test.ValidateElectronContainer(subject));
            }
            // traverse into super class
            report.Add(ValidateChemObject(subject));
            // traverse into hierarchy
            return(report);
        }
Exemplo n.º 20
0
        public void TestDiff()
        {
            var m_ec1 = new Mock <IElectronContainer>(); IElectronContainer ec1 = m_ec1.Object;
            var m_ec2 = new Mock <IElectronContainer>(); IElectronContainer ec2 = m_ec2.Object;

            m_ec1.SetupGet(n => n.ElectronCount).Returns(2);
            m_ec2.SetupGet(n => n.ElectronCount).Returns(3);

            string result = ElectronContainerDiff.Diff(ec1, ec2);

            Assert.IsNotNull(result);
            Assert.AreNotSame(0, result.Length);
            AssertContains(result, "ElectronContainerDiff");
            AssertContains(result, "eCount");
            AssertContains(result, "2/3");
        }
Exemplo n.º 21
0
        /// <summary> Returns the next bond in order, relative to a given bond and atom.
        /// Example: Let the ring be composed of 0-1, 1-2, 2-3 and 3-0. A request getNextBond(1-2, 2)
        /// will return Bond 2-3.
        ///
        /// </summary>
        /// <param name="bond"> A bond for which an atom from a consecutive bond is sought
        /// </param>
        /// <param name="atom"> A atom from the bond above to assign a search direction
        /// </param>
        /// <returns>  The next bond in the order given by the above assignment
        /// </returns>
        public virtual IBond getNextBond(IBond bond, IAtom atom)
        {
            Bond tempBond;

            for (int f = 0; f < ElectronContainerCount; f++)
            {
                IElectronContainer electronContainer = getElectronContainerAt(f);
                if (electronContainer is IBond)
                {
                    tempBond = (Bond)electronContainer;
                    if (tempBond.contains(atom) && bond != tempBond)
                    {
                        return(tempBond);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 22
0
 public static void removeElectronContainer(IReaction reaction, IElectronContainer electrons)
 {
     IMolecule[] reactants = reaction.Reactants.Molecules;
     for (int i = 0; i < reactants.Length; i++)
     {
         IMolecule mol = reactants[i];
         if (mol.contains(electrons))
         {
             mol.removeElectronContainer(electrons);
         }
     }
     IMolecule[] products = reaction.Products.Molecules;
     for (int i = 0; i < products.Length; i++)
     {
         IMolecule mol = products[i];
         if (mol.contains(electrons))
         {
             mol.removeElectronContainer(electrons);
         }
     }
 }
 public static void removeElectronContainer(ISetOfAtomContainers set_Renamed, IElectronContainer electrons)
 {
     IAtomContainer[] acs = set_Renamed.AtomContainers;
     for (int i = 0; i < acs.Length; i++)
     {
         IAtomContainer container = acs[i];
         if (container.contains(electrons))
         {
             container.removeElectronContainer(electrons);
             IMolecule[] molecules = ConnectivityChecker.partitionIntoMolecules(container).Molecules;
             if (molecules.Length > 1)
             {
                 set_Renamed.removeAtomContainer(container);
                 for (int k = 0; k < molecules.Length; k++)
                 {
                     set_Renamed.addAtomContainer(molecules[k]);
                 }
             }
             return;
         }
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// Compare two <see cref="IChemObject"/> classes and return the difference as an <see cref="IDifference"/>.
        ///
        /// <param name="first">the first of the two classes to compare</param>
        /// <param name="second">the second of the two classes to compare</param>
        /// <returns>an <see cref="IDifference"/> representation of the difference between the first and second <see cref="IChemObject"/>.</returns>
        /// </summary>
        public static IDifference Difference(IChemObject first, IChemObject second)
        {
            if (!(first is IElectronContainer && second is IElectronContainer))
            {
                return(null);
            }
            IElectronContainer firstEC   = (IElectronContainer)first;
            IElectronContainer secondEC  = (IElectronContainer)second;
            IDifferenceList    totalDiff = new ChemObjectDifference("ElectronContainerDiff");

            totalDiff.AddChild(IntegerDifference.Construct("eCount", firstEC.ElectronCount,
                                                           secondEC.ElectronCount));
            totalDiff.AddChild(ChemObjectDiff.Difference(first, second));
            if (totalDiff.ChildCount() > 0)
            {
                return(totalDiff);
            }
            else
            {
                return(null);
            }
        }
 public static void removeElectronContainer(ISetOfAtomContainers set_Renamed, IElectronContainer electrons)
 {
     IAtomContainer[] acs = set_Renamed.AtomContainers;
     for (int i = 0; i < acs.Length; i++)
     {
         IAtomContainer container = acs[i];
         if (container.contains(electrons))
         {
             container.removeElectronContainer(electrons);
             IMolecule[] molecules = ConnectivityChecker.partitionIntoMolecules(container).Molecules;
             if (molecules.Length > 1)
             {
                 set_Renamed.removeAtomContainer(container);
                 for (int k = 0; k < molecules.Length; k++)
                 {
                     set_Renamed.addAtomContainer(molecules[k]);
                 }
             }
             return;
         }
     }
 }
Exemplo n.º 26
0
 public void Remove(IElectronContainer electronContainer)
 {
 }
Exemplo n.º 27
0
 public bool Contains(IElectronContainer electronContainer)
 => false;
Exemplo n.º 28
0
 public void Add(IElectronContainer electronContainer)
 {
     throw new InvalidOperationException("not supported");
 }
Exemplo n.º 29
0
 public static void RemoveElectronContainer(IChemObjectSet <IAtomContainer> set, IElectronContainer electrons)
 {
     foreach (var atomContainer in set)
     {
         if (atomContainer.Contains(electrons))
         {
             atomContainer.Remove(electrons);
             var molecules = ConnectivityChecker.PartitionIntoMolecules(atomContainer);
             if (molecules.Count > 1)
             {
                 set.Remove(atomContainer);
                 for (int k = 0; k < molecules.Count; k++)
                 {
                     set.Add(molecules[k]);
                 }
             }
             return;
         }
     }
 }
Exemplo n.º 30
0
 public static void removeElectronContainer(IReaction reaction, IElectronContainer electrons)
 {
     IMolecule[] reactants = reaction.Reactants.Molecules;
     for (int i = 0; i < reactants.Length; i++)
     {
         IMolecule mol = reactants[i];
         if (mol.contains(electrons))
         {
             mol.removeElectronContainer(electrons);
         }
     }
     IMolecule[] products = reaction.Products.Molecules;
     for (int i = 0; i < products.Length; i++)
     {
         IMolecule mol = products[i];
         if (mol.contains(electrons))
         {
             mol.removeElectronContainer(electrons);
         }
     }
 }
Exemplo n.º 31
0
 public static void RemoveElectronContainer(IChemObjectSet <IAtomContainer> set, IElectronContainer electrons)
 {
     AtomContainerSetManipulator.RemoveElectronContainer(set, electrons);
 }
Exemplo n.º 32
0
        public virtual ValidationReport ValidateElectronContainer(IElectronContainer subject)
        {
            var report = new ValidationReport();

            return(report);
        }
Exemplo n.º 33
0
 public static void removeElectronContainer(ISetOfMolecules set_Renamed, IElectronContainer electrons)
 {
     SetOfAtomContainersManipulator.removeElectronContainer(set_Renamed, electrons);
 }