/// <summary> Puts all the AtomContainers of this set together in one
        /// AtomCcntainer.
        ///
        /// </summary>
        /// <returns>  The AtomContainer with all the AtomContainers of this set
        ///
        /// </returns>
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(ISetOfAtomContainers set_Renamed)
        {
            IAtomContainer container = set_Renamed.Builder.newAtomContainer();

            IAtomContainer[] acs = set_Renamed.AtomContainers;
            for (int i = 0; i < acs.Length; i++)
            {
                container.add(acs[i]);
            }
            return(container);
        }
Exemplo n.º 2
0
        /// <summary> Puts all the Molecules of this container together in one
        /// AtomCcntainer.
        ///
        /// </summary>
        /// <returns>  The AtomContainer with all the Molecules of this container
        ///
        /// </returns>
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(IChemSequence sequence)
        {
            IAtomContainer container = sequence.Builder.newAtomContainer();

            for (int i = 0; i < sequence.ChemModelCount; i++)
            {
                IChemModel model = sequence.getChemModel(i);
                container.add(ChemModelManipulator.getAllInOneContainer(model));
            }
            return(container);
        }
Exemplo n.º 3
0
        /// <summary> Puts all the Molecules of this container together in one
        /// AtomCcntainer.
        ///
        /// </summary>
        /// <returns>  The AtomContainer with all the Molecules of this container
        ///
        /// </returns>
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(IChemFile file)
        {
            IAtomContainer container = file.Builder.newAtomContainer();

            for (int i = 0; i < file.ChemSequenceCount; i++)
            {
                IChemSequence sequence = file.getChemSequence(i);
                container.add(ChemSequenceManipulator.getAllInOneContainer(sequence));
            }
            return(container);
        }
Exemplo n.º 4
0
        /// <summary> Returns all the atoms and bonds from all the rings in the RingSet
        /// in one AtomContainer.
        ///
        /// </summary>
        /// <returns> an AtomContainer with all atoms and bonds from the RingSet
        ///
        /// </returns>
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(IRingSet ringSet)
        {
            // FIXME: make RingSet a subclass of IChemObject (see bug #) and clean up
            // the code in the next line
            IAtomContainer container = ringSet.Builder.newAtomContainer();

            for (int i = 0; i < ringSet.AtomContainerCount; i++)
            {
                container.add((IRing)ringSet.getAtomContainer(i));
            }
            return(container);
        }
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(ISetOfReactions set_Renamed)
        {
            IAtomContainer container = set_Renamed.Builder.newAtomContainer();

            IReaction[] reactions = set_Renamed.Reactions;
            for (int i = 0; i < reactions.Length; i++)
            {
                IReaction reaction = reactions[i];
                container.add(ReactionManipulator.getAllInOneContainer(reaction));
            }
            return(container);
        }
Exemplo n.º 6
0
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(IReaction reaction)
        {
            IAtomContainer container = reaction.Builder.newAtomContainer();

            if (reaction == null)
            {
                return(container);
            }
            IMolecule[] reactants = reaction.Reactants.Molecules;
            for (int i = 0; i < reactants.Length; i++)
            {
                IMolecule molecule = reactants[i];
                container.add(molecule);
            }
            IMolecule[] products = reaction.Products.Molecules;
            for (int i = 0; i < products.Length; i++)
            {
                IMolecule molecule = products[i];
                container.add(molecule);
            }
            return(container);
        }
Exemplo n.º 7
0
        /// <summary> Puts all the Molecules of this container together in one
        /// AtomContainer.
        ///
        /// </summary>
        /// <returns>  The AtomContainer with all the Molecules of this container
        ///
        /// </returns>
        /// <deprecated> This method has a serious performace impact. Try to use
        /// other methods.
        /// </deprecated>
        public static IAtomContainer getAllInOneContainer(IChemModel chemModel)
        {
            IAtomContainer container = chemModel.Builder.newAtomContainer();
            ICrystal       crystal   = chemModel.Crystal;

            if (crystal != null)
            {
                container.add(crystal);
            }
            ISetOfMolecules moleculeSet = chemModel.SetOfMolecules;

            if (moleculeSet != null)
            {
                container.add(SetOfMoleculesManipulator.getAllInOneContainer(moleculeSet));
            }
            ISetOfReactions reactionSet = chemModel.SetOfReactions;

            if (reactionSet != null)
            {
                container.add(SetOfReactionsManipulator.getAllInOneContainer(reactionSet));
            }
            return(container);
        }
Exemplo n.º 8
0
        /// <summary>  Fings the set of all rings in a molecule
        ///
        /// </summary>
        /// <param name="atomContainer">    the molecule to be searched for rings
        /// </param>
        /// <param name="useSSSR">          use the SSSRFinder & RingPartitioner as pre-filter
        /// </param>
        /// <returns>                   a RingSet containing the rings in molecule
        /// </returns>
        /// <exception cref="CDKException"> An exception thrown if something goes wrong or if the timeout limit is reached
        /// </exception>
        public virtual IRingSet findAllRings(IAtomContainer atomContainer, bool useSSSR)
        {
            if (startTime == 0)
            {
                startTime = (System.DateTime.Now.Ticks - 621355968000000000) / 10000;
            }
            System.Collections.ArrayList pathes = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            IRingSet       ringSet = atomContainer.Builder.newRingSet();
            IAtomContainer ac      = atomContainer.Builder.newAtomContainer();

            originalAc = atomContainer;
            ac.add(atomContainer);
            if (debug)
            {
                System.Console.Out.WriteLine("AtomCount before removal of aliphatic atoms: " + ac.AtomCount);
            }
            removeAliphatic(ac);
            if (debug)
            {
                System.Console.Out.WriteLine("AtomCount after removal of aliphatic atoms: " + ac.AtomCount);
            }
            if (useSSSR)
            {
                SSSRFinder sssrf = new SSSRFinder(atomContainer);
                IRingSet   sssr  = sssrf.findSSSR();
                System.Collections.ArrayList ringSets = RingPartitioner.partitionRings(sssr);

                for (int r = 0; r < ringSets.Count; r++)
                {
                    IAtomContainer tempAC = RingPartitioner.convertToAtomContainer((IRingSet)ringSets[r]);

                    doSearch(tempAC, pathes, ringSet);
                }
            }
            else
            {
                doSearch(ac, pathes, ringSet);
            }
            atomContainer.setProperty(CDKConstants.ALL_RINGS, ringSet);
            return(ringSet);
        }
Exemplo n.º 9
0
        /// <summary> Method that saturates a molecule by adding explicit hydrogens.
        /// In order to get coordinates for these Hydrogens, you need to
        /// remember the average bondlength of you molecule (coordinates for
        /// all atoms should be available) by using
        /// double bondLength = GeometryTools.getBondLengthAverage(atomContainer);
        /// and then use this method here and then use
        /// org.openscience.cdk.HydrogenPlacer(atomContainer, bondLength);
        ///
        /// </summary>
        /// <param name="molecule"> Molecule to saturate
        /// </param>
        /// <cdk.keyword>           hydrogen, adding </cdk.keyword>
        /// <cdk.keyword>           explicit hydrogen </cdk.keyword>
        public virtual IAtomContainer addExplicitHydrogensToSatisfyValency(IMolecule molecule)
        {
            //logger.debug("Start of addExplicitHydrogensToSatisfyValency");
            ISetOfMolecules moleculeSet = ConnectivityChecker.partitionIntoMolecules(molecule);

            IMolecule[]    molecules             = moleculeSet.Molecules;
            IAtomContainer changedAtomsAndBonds  = molecule.Builder.newAtomContainer();
            IAtomContainer intermediateContainer = null;

            for (int k = 0; k < molecules.Length; k++)
            {
                IMolecule molPart = molecules[k];
                IAtom[]   atoms   = molPart.Atoms;
                for (int i = 0; i < atoms.Length; i++)
                {
                    intermediateContainer = addHydrogensToSatisfyValency(molPart, atoms[i], molecule);
                    changedAtomsAndBonds.add(intermediateContainer);
                }
            }
            //logger.debug("End of addExplicitHydrogensToSatisfyValency");
            return(changedAtomsAndBonds);
        }
Exemplo n.º 10
0
        static bool JoinMmpFragments(
            IAtomContainer mol,
            string commonFragSmiles,
            int attachmentNo)
        {
            IAtomContainer cfMol = SmilesToAtomContainer(commonFragSmiles);

            //AtomContainerManipulator.removeHydrogens(cfMol);

            mol.add(cfMol);

            List <IAtom> atoms = GetAttachmentAtoms(mol, attachmentNo);

            if (atoms.Count != 2)
            {
                return(false);
            }

            Bond b = new Bond(atoms[0], atoms[1], IBond.Order.SINGLE);

            mol.addBond(b);

            return(true);
        }
Exemplo n.º 11
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 IReaction readReaction(IChemObjectBuilder builder)
        {
            IReaction reaction = builder.newReaction();

            try
            {
                input.ReadLine(); // first line should be $RXN
                input.ReadLine(); // second line
                input.ReadLine(); // third line
                input.ReadLine(); // fourth line
            }
            catch (System.IO.IOException exception)
            {
                //logger.debug(exception);
                throw new CDKException("Error while reading header of RXN file", exception);
            }

            int reactantCount = 0;
            int productCount  = 0;

            try
            {
                System.String countsLine = input.ReadLine();

                /* this line contains the number of reactants
                 * and products */
                SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(countsLine);
                reactantCount = System.Int32.Parse(tokenizer.NextToken());
                //logger.info("Expecting " + reactantCount + " reactants in file");
                productCount = System.Int32.Parse(tokenizer.NextToken());
                //logger.info("Expecting " + productCount + " products in file");
            }
            catch (System.Exception exception)
            {
                //logger.debug(exception);
                throw new CDKException("Error while counts line of RXN file", exception);
            }

            // now read the reactants
            try
            {
                for (int i = 1; i <= reactantCount; i++)
                {
                    System.Text.StringBuilder molFile = new System.Text.StringBuilder();
                    input.ReadLine(); // announceMDLFileLine
                    System.String molFileLine = "";
                    do
                    {
                        molFileLine = input.ReadLine();
                        molFile.Append(molFileLine);
                        molFile.Append("\n");
                    }while (!molFileLine.Equals("M  END"));

                    // read MDL molfile content
                    MDLReader reader   = new MDLReader(new StreamReader(molFile.ToString()));
                    IMolecule reactant = (IMolecule)reader.read(builder.newMolecule());

                    // add reactant
                    reaction.addReactant(reactant);
                }
            }
            catch (CDKException exception)
            {
                // rethrow exception from MDLReader
                throw exception;
            }
            catch (System.Exception exception)
            {
                //logger.debug(exception);
                throw new CDKException("Error while reading reactant", exception);
            }

            // now read the products
            try
            {
                for (int i = 1; i <= productCount; i++)
                {
                    System.Text.StringBuilder molFile = new System.Text.StringBuilder();
                    input.ReadLine(); // String announceMDLFileLine =
                    System.String molFileLine = "";
                    do
                    {
                        molFileLine = input.ReadLine();
                        molFile.Append(molFileLine);
                        molFile.Append("\n");
                    }while (!molFileLine.Equals("M  END"));

                    // read MDL molfile content
                    MDLReader reader  = new MDLReader(new StreamReader(molFile.ToString()));
                    IMolecule product = (IMolecule)reader.read(builder.newMolecule());

                    // add reactant
                    reaction.addProduct(product);
                }
            }
            catch (CDKException exception)
            {
                // rethrow exception from MDLReader
                throw exception;
            }
            catch (System.Exception exception)
            {
                //logger.debug(exception);
                throw new CDKException("Error while reading products", exception);
            }

            // now try to map things, if wanted
            //logger.info("Reading atom-atom mapping from file");
            // distribute all atoms over two AtomContainer's
            IAtomContainer reactingSide = builder.newAtomContainer();

            IMolecule[] molecules = reaction.Reactants.Molecules;
            for (int i = 0; i < molecules.Length; i++)
            {
                reactingSide.add(molecules[i]);
            }
            IAtomContainer producedSide = builder.newAtomContainer();

            molecules = reaction.Products.Molecules;
            for (int i = 0; i < molecules.Length; i++)
            {
                producedSide.add(molecules[i]);
            }

            // map the atoms
            int mappingCount = 0;

            IAtom[] reactantAtoms = reactingSide.Atoms;
            IAtom[] producedAtoms = producedSide.Atoms;
            for (int i = 0; i < reactantAtoms.Length; i++)
            {
                for (int j = 0; j < producedAtoms.Length; j++)
                {
                    if (reactantAtoms[i].ID != null && reactantAtoms[i].ID.Equals(producedAtoms[j].ID))
                    {
                        reaction.addMapping(builder.newMapping(reactantAtoms[i], producedAtoms[j]));
                        mappingCount++;
                        break;
                    }
                }
            }
            //logger.info("Mapped atom pairs: " + mappingCount);

            return(reaction);
        }