gt:         int sizeT = reactionMatrix.getProductsAtomArray().size();
context: /*
   * Copyright (C) 2007-2020 Syed Asad Rahman <asad @ ebi.ac.uk>.
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the Free Software
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
   * MA 02110-1301  USA
   */
  package uk.ac.ebi.reactionblast.mechanism;
  
  import java.io.File;
  import java.io.IOException;
  import java.util.Collection;
  import static java.util.Collections.synchronizedMap;
  import java.util.List;
  import java.util.Map;
  import static java.util.logging.Level.SEVERE;
  import org.openscience.cdk.Bond;
  import static org.openscience.cdk.CDKConstants.ISAROMATIC;
  import static org.openscience.cdk.CDKConstants.ISINRING;
  import static org.openscience.cdk.CDKConstants.REACTIVE_CENTER;
  import org.openscience.cdk.exception.CDKException;
  import org.openscience.cdk.interfaces.IAtom;
  import org.openscience.cdk.interfaces.IAtomContainer;
  import org.openscience.cdk.interfaces.IBond;
  import static org.openscience.cdk.interfaces.IBond.Order.SINGLE;
  import org.openscience.cdk.interfaces.IReaction;
  import org.openscience.cdk.interfaces.IRingSet;
  import uk.ac.ebi.reactionblast.mechanism.helper.AtomAtomMappingContainer;
  import uk.ac.ebi.reactionblast.mechanism.helper.AtomStereoChangeInformation;
  import uk.ac.ebi.reactionblast.mechanism.helper.BondChange;
  import uk.ac.ebi.reactionblast.mechanism.interfaces.ECBLAST_BOND_CHANGE_FLAGS;
  import static uk.ac.ebi.reactionblast.mechanism.interfaces.ECBLAST_BOND_CHANGE_FLAGS.BOND_CLEAVED;
  import static uk.ac.ebi.reactionblast.mechanism.interfaces.ECBLAST_BOND_CHANGE_FLAGS.BOND_FORMED;
  import static uk.ac.ebi.reactionblast.mechanism.interfaces.ECBLAST_BOND_CHANGE_FLAGS.BOND_ORDER;
  import static uk.ac.ebi.reactionblast.mechanism.interfaces.ECBLAST_BOND_CHANGE_FLAGS.PSEUDO_BOND;
  import static uk.ac.ebi.reactionblast.mechanism.interfaces.ECBLAST_FLAGS.ATOM_STEREO_CHANGE_INFORMATION;
  import static uk.ac.ebi.reactionblast.mechanism.interfaces.ECBLAST_FLAGS.BOND_CHANGE_INFORMATION;
  import uk.ac.ebi.reactionblast.stereo.IStereoAndConformation;
  import static uk.ac.ebi.reactionblast.stereo.IStereoAndConformation.E;
  import static uk.ac.ebi.reactionblast.stereo.IStereoAndConformation.R;
  import static uk.ac.ebi.reactionblast.stereo.IStereoAndConformation.S;
  import static uk.ac.ebi.reactionblast.stereo.IStereoAndConformation.Z;
  import static java.lang.Math.abs;
  import static java.lang.System.getProperty;
  import org.openscience.cdk.PseudoAtom;
  import org.openscience.cdk.graph.CycleFinder;
  import org.openscience.cdk.graph.Cycles;
  import org.openscience.cdk.tools.ILoggingTool;
  import org.openscience.cdk.tools.LoggingToolFactory;
  
  /**
   * @contact Syed Asad Rahman, EMBL-EBI, Cambridge, UK.
   * @author Syed Asad Rahman <asad @ ebi.ac.uk>
   */
  public final class BondChangeAnnotator extends DUModel {
  
      static final String NEW_LINE = getProperty("line.separator");
      private static final long serialVersionUID = 988987678877861L;
      private static final ILoggingTool LOGGER
              = LoggingToolFactory.createLoggingTool(BondChangeAnnotator.class);
      private static final boolean DEBUG = false;
  
      /**
       *
       * @param reaction with Atom-Atom Mapping produced by Reactor class
       * @param withoutHydrogen
       * @param generate2D
       * @param generate3D
       * @throws Exception
       */
      protected BondChangeAnnotator(IReaction reaction,
              boolean withoutHydrogen,
              boolean generate2D,
              boolean generate3D) throws Exception {
          super(reaction, withoutHydrogen, generate2D, generate3D);
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized AtomAtomMappingContainer getMappingContainer() {
          return mapping;
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized BEMatrix getEductBEMatrix() {
          return reactantBE;
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized List<BondChange> getBondChangeList() {
          return bondChangeList;
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized Collection<IAtom> getReactionCenterSet() {
          return reactionCenterList;
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized List<AtomStereoChangeInformation> getStereoChangeList() {
          return stereoChangeList;
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized BEMatrix getProductBEMatrix() {
          return productBE;
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized Map<IAtom, IAtom> getMappingMap() {
          return synchronizedMap(mappingMap);
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized RMatrix getRMatrix() {
          return reactionMatrix;
      }
  
      /**
       *
       * @return
       */
      @Override
      public synchronized boolean hasRMatrix() {
          return reactionMatrix != null;
      }
  
      /**
       *
       */
      @Override
      public synchronized void printBMatrix() {
          printBEMatrix(reactantBE);
      }
  
      /**
       *
       * @return
       */
      @Override
      public List<AtomStereoChangeInformation> getConformationChangeList() {
          return conformationChangeList;
      }
  
      /**
       *
       * @param outputFile
       */
      @Override
      public synchronized void writeBMatrix(File outputFile) {
          try {
              writeBEMatrix(outputFile, reactantBE);
          } catch (IOException ex) {
              LOGGER.error(SEVERE, null, ex);
          }
      }
  
      /**
       *
       */
      @Override
      public synchronized void printEMatrix() {
          printBEMatrix(productBE);
      }
  
      /**
       *
       * @param outputFile
       */
      @Override
      public synchronized void writeEMatrix(File outputFile) {
          try {
              writeBEMatrix(outputFile, productBE);
          } catch (IOException ex) {
              LOGGER.error(SEVERE, null, ex);
          }
      }
  
      /**
       *
       */
      @Override
      public synchronized void printRMatrix() {
          printReactionMatrix(reactionMatrix);
      }
  
      /**
       *
       * @param outputFile
       */
      @Override
      public synchronized void writeRMatrix(File outputFile) {
          try {
              writeReactionMatrix(outputFile, reactionMatrix);
          } catch (IOException ex) {
              LOGGER.error(SEVERE, null, ex);
          }
      }
  
      /**
       * set bond change flag
       *
       * @throws Exception
       */
      protected synchronized void markBondChanges() throws Exception {
  
          BEMatrix substrateBEMatrix = reactantBE;
          BEMatrix productBEMatrix = productBE;
  
          if (DEBUG) {
              System.out.println("markBondChanges method START");
  //        System.out.println(reactantBE.toString());
  //        System.out.println(productBE.toString());
  //        System.out.println(reactionMatrix.toString
          }
  
          /*
           * Marking CDKConstants.ISINRING FLAGS
           */
          if (DEBUG) {
              System.out.println("Marking Rings");
          }
          for (IAtomContainer atomContainerQ : reactantSet.atomContainers()) {
              try {
                  /*
                   * set Flag(CDKConstants.ISINRING)
                   */
                  initializeMolecule(atomContainerQ);
              } catch (CDKException ex) {
                  LOGGER.error(SEVERE, null, ex);
              }
  //            IRingSet singleRingsQ = new SSSRFinder(atomContainerQ).findSSSR();
              //New Method
              CycleFinder cf = Cycles.mcb();
              Cycles cycles = cf.find(atomContainerQ); // ignore error - essential cycles do not check tractability
              IRingSet singleRingsQ = cycles.toRingSet();
              queryRingSet.add(singleRingsQ);
          }
  
          for (IAtomContainer atomContainerT : productSet.atomContainers()) {
              try {
                  /*
                   * set Flag(CDKConstants.ISINRING)
                   */
                  initializeMolecule(atomContainerT);
              } catch (CDKException ex) {
                  LOGGER.error(SEVERE, null, ex);
              }
  //            IRingSet singleRingsT = new SSSRFinder(atomContainerT).findSSSR();
              //New Method
              CycleFinder cf = Cycles.mcb();
              Cycles cycles = cf.find(atomContainerT); // ignore error - essential cycles do not check tractability
              IRingSet singleRingsT = cycles.toRingSet();
              targetRingSet.add(singleRingsT);
          }
          /*
           * Mining Stereo Atom Changes E/Z or R/S only
           */
  
          if (DEBUG) {
              System.out.println("Marking E/Z or R/S");
          }
          for (StereoChange sc : stereogenicCenters) {
              IAtom atomE = sc.getReactantAtom();
              IAtom atomP = sc.getProductAtom();
  
              IStereoAndConformation rsb = sc.getReactantAtomStereo();
              IStereoAndConformation psb = sc.getProductAtomStereo();
  
              if (atomE != null && atomP != null) {
                  if (atomE.getSymbol().equals("P") || atomP.getSymbol().equals("P")) {
                      LOGGER.warn(NEW_LINE + "WARNING: The stereo change " + atomE.getSymbol()
                              + " not supported");
                      continue;
                  }
                  atomE.setProperty(ATOM_STEREO_CHANGE_INFORMATION, rsb);
                  atomP.setProperty(ATOM_STEREO_CHANGE_INFORMATION, psb);
                  atomE.setFlag(REACTIVE_CENTER, true);
                  atomP.setFlag(REACTIVE_CENTER, true);
                  getReactionCenterSet().add(atomE);
                  getReactionCenterSet().add(atomP);
  
                  if ((sc.getReactantAtomStereo().equals(E)
                          || sc.getProductAtomStereo().equals(Z))
                          || (sc.getReactantAtomStereo().equals(Z)
                          || sc.getProductAtomStereo().equals(E))) {
                      getConformationChangeList().add(new AtomStereoChangeInformation(atomE, atomP, sc.getReactantAtomStereo(), sc.getProductAtomStereo()));
                  } else if ((sc.getReactantAtomStereo().equals(R)
                          || sc.getProductAtomStereo().equals(S))
                          || (sc.getReactantAtomStereo().equals(S)
                          || sc.getProductAtomStereo().equals(R))) {
                      getStereoChangeList().add(new AtomStereoChangeInformation(atomE, atomP, sc.getReactantAtomStereo(), sc.getProductAtomStereo()));
                  }
              }
          }
          /*
           * Mining bond cleaved formed, order change except stereo information
           *
           */
  
          if (DEBUG) {
              System.out.println("Marking Bond Changes");
          }
          int sizeQ = reactionMatrix.getReactantsAtomArray().size();
  