Logo Search packages:      
Sourcecode: cdk version File versions  Download package

IReaction org::openscience::cdk::smiles::SmilesParser::parseReactionSmiles ( String  smiles ) throws InvalidSmilesException [inline]

Parse a reaction SMILES.

Parameters:
smilesThe SMILES string to parse
Returns:
An instance of org.openscience.cdk.interfaces.IReaction
See also:
parseSmiles(String)
Exceptions:
InvalidSmilesExceptionif the string cannot be parsed

Definition at line 125 of file SmilesParser.java.

References org::openscience::cdk::interfaces::IReaction::addAgent(), org::openscience::cdk::interfaces::IReaction::addProduct(), org::openscience::cdk::interfaces::IReaction::addReactant(), org::openscience::cdk::interfaces::IAtomContainerSet::getAtomContainerCount(), org::openscience::cdk::interfaces::IMoleculeSet::getMolecule(), org::openscience::cdk::interfaces::IChemObjectBuilder::newReaction(), and org::openscience::cdk::graph::ConnectivityChecker::partitionIntoMolecules().

      {
            StringTokenizer tokenizer = new StringTokenizer(smiles, ">");
            String reactantSmiles = tokenizer.nextToken();
            String agentSmiles = "";
            String productSmiles = tokenizer.nextToken();
            if (tokenizer.hasMoreTokens())
            {
                  agentSmiles = productSmiles;
                  productSmiles = tokenizer.nextToken();
            }

            IReaction reaction = builder.newReaction();

            // add reactants
            IMolecule reactantContainer = parseSmiles(reactantSmiles);
            IMoleculeSet reactantSet = ConnectivityChecker.partitionIntoMolecules(reactantContainer);
            for (int i = 0; i < reactantSet.getAtomContainerCount(); i++)
            {
                  reaction.addReactant(reactantSet.getMolecule(i));
            }

            // add reactants
            if (agentSmiles.length() > 0)
            {
                  IMolecule agentContainer = parseSmiles(agentSmiles);
                  IMoleculeSet agentSet = ConnectivityChecker.partitionIntoMolecules(agentContainer);
                  for (int i = 0; i < agentSet.getAtomContainerCount(); i++)
                  {
                        reaction.addAgent(agentSet.getMolecule(i));
                  }
            }

            // add products
            IMolecule productContainer = parseSmiles(productSmiles);
            IMoleculeSet productSet = ConnectivityChecker.partitionIntoMolecules(productContainer);
            for (int i = 0; i < productSet.getAtomContainerCount(); i++)
            {
                  reaction.addProduct(productSet.getMolecule(i));
            }

            return reaction;
      }

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index