SmilesParser { public IReaction parseReactionSmiles(String smiles) throws InvalidSmilesException { if (!smiles.contains(">")) throw new InvalidSmilesException("Not a reaction SMILES: " + smiles); final int first = smiles.indexOf('>'); final int second = smiles.indexOf('>', first + 1); if (second < 0) throw new InvalidSmilesException("Invalid reaction SMILES:" + smiles); final String reactants = smiles.substring(0, first); final String agents = smiles.substring(first + 1, second); final String products = smiles.substring(second + 1, smiles.length()); IReaction reaction = builder.newInstance(IReaction.class); if (!reactants.isEmpty()) { IAtomContainer reactantContainer = parseSmiles(reactants, true); IAtomContainerSet reactantSet = ConnectivityChecker.partitionIntoMolecules(reactantContainer); for (int i = 0; i < reactantSet.getAtomContainerCount(); i++) { reaction.addReactant(reactantSet.getAtomContainer(i)); } } if (!agents.isEmpty()) { IAtomContainer agentContainer = parseSmiles(agents, true); IAtomContainerSet agentSet = ConnectivityChecker.partitionIntoMolecules(agentContainer); for (int i = 0; i < agentSet.getAtomContainerCount(); i++) { reaction.addAgent(agentSet.getAtomContainer(i)); } } String title = null; if (!products.isEmpty()) { IAtomContainer productContainer = parseSmiles(products, true); IAtomContainerSet productSet = ConnectivityChecker.partitionIntoMolecules(productContainer); for (int i = 0; i < productSet.getAtomContainerCount(); i++) { reaction.addProduct(productSet.getAtomContainer(i)); } reaction.setProperty(CDKConstants.TITLE, title = productContainer.getProperty(CDKConstants.TITLE)); } try { parseRxnCXSMILES(title, reaction); } catch (Exception e) { e.printStackTrace(); throw new InvalidSmilesException("Error parsing CXSMILES:" + e.getMessage()); } return reaction; } SmilesParser(final IChemObjectBuilder builder); void setStrict(boolean strict); IReaction parseReactionSmiles(String smiles); IAtomContainer parseSmiles(String smiles); @Deprecated void setPreservingAromaticity(boolean preservingAromaticity); @Deprecated boolean isPreservingAromaticity(); void kekulise(boolean kekulise);  }
@Test public void noReactants() throws Exception { IReaction reaction = sp.parseReactionSmiles(">>C"); Assert.assertEquals(0, reaction.getReactantCount()); Assert.assertEquals(1, reaction.getProductCount()); }
@Test public void noProducts() throws Exception { IReaction reaction = sp.parseReactionSmiles("C>>"); Assert.assertEquals(1, reaction.getReactantCount()); Assert.assertEquals(0, reaction.getProductCount()); }
@Test public void noReaction() throws Exception { IReaction reaction = sp.parseReactionSmiles(">>"); Assert.assertEquals(0, reaction.getReactantCount()); Assert.assertEquals(0, reaction.getProductCount()); }
@Test public void onlyAgents() throws Exception { IReaction reaction = sp.parseReactionSmiles(">C>"); Assert.assertEquals(0, reaction.getReactantCount()); Assert.assertEquals(1, reaction.getAgents().getAtomContainerCount()); Assert.assertEquals(0, reaction.getProductCount()); }