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 ) ; // add reactants 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 ) ) ; } } // add agents 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 ; // add products 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 { // CXSMILES layer parseRxnCXSMILES ( title , reaction ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; throw new InvalidSmilesException ( "Error parsing CXSMILES:" + e . getMessage ( ) ) ; } return reaction ; }
Parse a reaction SMILES .