/**
   * Get the expected set of molecules.
   *
   * @return The IAtomContainerSet
   */
  private IAtomContainerSet getExpectedProducts() {
    IAtomContainerSet setOfProducts = builder.newInstance(IAtomContainerSet.class);

    IAtomContainer molecule = builder.newInstance(IAtomContainer.class);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.getAtom(0).setFormalCharge(1);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(0, 1, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(1, 2, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(2, 3, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(3, 4, IBond.Order.SINGLE);
    molecule.addAtom(builder.newInstance(IAtom.class, "C"));
    molecule.addBond(4, 5, IBond.Order.SINGLE);
    try {
      addExplicitHydrogens(molecule);
    } catch (Exception e) {
      e.printStackTrace();
    }

    molecule.getAtom(0).setFormalCharge(0);
    molecule.addSingleElectron(new SingleElectron(molecule.getAtom(0)));

    try {
      AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);
      makeSureAtomTypesAreRecognized(molecule);
    } catch (CDKException e) {
      e.printStackTrace();
    }
    setOfProducts.addAtomContainer(molecule);
    return setOfProducts;
  }
  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testCDKConstants_REACTIVE_CENTER() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);

    /* manually put the reactive center */
    molecule.getAtom(3).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(0).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getAtom(6).setFlag(CDKConstants.REACTIVE_CENTER, true);
    molecule.getBond(5).setFlag(CDKConstants.REACTIVE_CENTER, true);

    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.TRUE);
    paramList.add(param);
    type.setParameterList(paramList);

    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);

    IAtomContainer reactant = setOfReactions.getReaction(0).getReactants().getAtomContainer(0);
    Assert.assertTrue(molecule.getAtom(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(6).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(0).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getAtom(3).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(molecule.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
    Assert.assertTrue(reactant.getBond(5).getFlag(CDKConstants.REACTIVE_CENTER));
  }
  /**
   * Get the container which the bond is found on resonance from a IMolecule. It is based on looking
   * if the order of the bond changes. Return null is any is found.
   *
   * @param molecule The IMolecule to analyze
   * @param bond The IBond
   * @return The container with the bond
   */
  @TestMethod("testGetContainer_IMolecule_IBond")
  public IAtomContainer getContainer(IMolecule molecule, IBond bond) {
    IAtomContainerSet setOfCont = getContainers(molecule);
    if (setOfCont == null) return null;

    for (IAtomContainer container : setOfCont.atomContainers()) {
      if (container.contains(bond)) return container;
    }

    return null;
  }
예제 #4
0
 private IChemModel readChemModel(IChemModel chemModel) throws CDKException {
   IAtomContainerSet setOfMolecules = chemModel.getMoleculeSet();
   if (setOfMolecules == null) {
     setOfMolecules = chemModel.getBuilder().newInstance(IAtomContainerSet.class);
   }
   IAtomContainer m = readAtomContainer(chemModel.getBuilder().newInstance(IAtomContainer.class));
   if (m != null && m instanceof IAtomContainer) {
     setOfMolecules.addAtomContainer((IAtomContainer) m);
   }
   chemModel.setMoleculeSet(setOfMolecules);
   return chemModel;
 }
	private static void removeDuplicateAtomContainers(final IChemModel chemModel) {
		// we remove molecules which are in AtomContainerSet as well as in a
		// reaction
		final IReactionSet reactionSet = chemModel.getReactionSet();
		final IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
		if (reactionSet != null && moleculeSet != null) {
			final List<IAtomContainer> aclist = ReactionSetManipulator
					.getAllAtomContainers(reactionSet);
			for (int i = moleculeSet.getAtomContainerCount() - 1; i >= 0; i--) {
				for (int k = 0; k < aclist.size(); k++) {
					final String label = moleculeSet.getAtomContainer(i)
							.getID();
					if (aclist.get(k).getID().equals(label)) {
						chemModel.getMoleculeSet().removeAtomContainer(i);
						break;
					}
				}
			}
		}
	}
	private static void replaceReferencesWithClones(final IChemModel chemModel)
			throws CDKException {
		// we make references in products/reactants clones, since same compounds
		// in different reactions need separate layout (different positions etc)
		if (chemModel.getReactionSet() != null) {
			for (final IReaction reaction : chemModel.getReactionSet()
					.reactions()) {
				int i = 0;
				final IAtomContainerSet products = reaction.getProducts();
				for (final IAtomContainer product : products.atomContainers()) {
					try {
						products.replaceAtomContainer(i, product.clone());
					} catch (final CloneNotSupportedException e) {
					}
					i++;
				}
				i = 0;
				final IAtomContainerSet reactants = reaction.getReactants();
				for (final IAtomContainer reactant : reactants.atomContainers()) {
					try {
						reactants.replaceAtomContainer(i, reactant.clone());
					} catch (final CloneNotSupportedException e) {
					}
					i++;
				}
			}
		}
	}
예제 #7
0
  /**
   * Generates a shortest path based BitSet fingerprint for the given AtomContainer.
   *
   * @param ac The AtomContainer for which a fingerprint is generated
   * @exception CDKException if there error in aromaticity perception or other CDK functions
   * @return A {@link BitSet} representing the fingerprint
   */
  @Override
  public IBitFingerprint getBitFingerprint(IAtomContainer ac) throws CDKException {

    IAtomContainer atomContainer = null;
    try {
      atomContainer = (IAtomContainer) ac.clone();
    } catch (CloneNotSupportedException ex) {
      logger.error("Failed to clone the molecule:", ex);
    }
    Aromaticity.cdkLegacy().apply(atomContainer);
    BitSet bitSet = new BitSet(fingerprintLength);
    if (!ConnectivityChecker.isConnected(atomContainer)) {
      IAtomContainerSet partitionedMolecules =
          ConnectivityChecker.partitionIntoMolecules(atomContainer);
      for (IAtomContainer container : partitionedMolecules.atomContainers()) {
        addUniquePath(container, bitSet);
      }
    } else {
      addUniquePath(atomContainer, bitSet);
    }
    return new BitSetFingerprint(bitSet);
  }
  /**
   * A unit test suite for JUnit.
   *
   * @return The test suite
   */
  @Test
  public void testMapping() throws Exception {
    IReactionProcess type = new RadicalSiteHrBetaReaction();

    IAtomContainerSet setOfReactants = getExampleReactants();
    IAtomContainer molecule = setOfReactants.getAtomContainer(0);

    /* automatic search of the center active */
    List<IParameterReact> paramList = new ArrayList<IParameterReact>();
    IParameterReact param = new SetReactionCenter();
    param.setParameter(Boolean.FALSE);
    paramList.add(param);
    type.setParameterList(paramList);

    /* initiate */
    IReactionSet setOfReactions = type.initiate(setOfReactants, null);

    IAtomContainer product = setOfReactions.getReaction(0).getProducts().getAtomContainer(0);

    Assert.assertEquals(19, setOfReactions.getReaction(0).getMappingCount());
    IAtom mappedProductA1 =
        (IAtom)
            ReactionManipulator.getMappedChemObject(
                setOfReactions.getReaction(0), molecule.getAtom(0));
    Assert.assertEquals(mappedProductA1, product.getAtom(0));
    IAtom mappedProductA2 =
        (IAtom)
            ReactionManipulator.getMappedChemObject(
                setOfReactions.getReaction(0), molecule.getAtom(6));
    Assert.assertEquals(mappedProductA2, product.getAtom(6));
    IAtom mappedProductA3 =
        (IAtom)
            ReactionManipulator.getMappedChemObject(
                setOfReactions.getReaction(0), molecule.getAtom(3));
    Assert.assertEquals(mappedProductA3, product.getAtom(3));
  }
	private static void removeEmptyAtomContainers(final IChemModel chemModel) {
		final IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
		if (moleculeSet != null && moleculeSet.getAtomContainerCount() == 0) {
			chemModel.setMoleculeSet(null);
		}
	}
	/**
	 * Returns an IChemModel, using the reader provided (picked).
	 * 
	 * @param cor
	 * @param panel
	 * @return
	 * @throws CDKException
	 */
	public static IChemModel getChemModelFromReader(
			final ISimpleChemObjectReader cor,
			final AbstractJChemPaintPanel panel) throws CDKException {
		panel.get2DHub().setRGroupHandler(null);
		String error = null;
		ChemModel chemModel = null;
		IChemFile chemFile = null;
		if (cor.accepts(IChemFile.class) && chemModel == null) {
			// try to read a ChemFile
			try {
				chemFile = (IChemFile) cor.read((IChemObject) new ChemFile());
				if (chemFile == null) {
					error = "The object chemFile was empty unexpectedly!";
				}
			} catch (final Exception exception) {
				error = "Error while reading file: " + exception.getMessage();
				exception.printStackTrace();
			}
		}
		if (error != null) {
			throw new CDKException(error);
		}
		if (chemModel == null && chemFile != null) {
			chemModel = (ChemModel) chemFile.getChemSequence(0).getChemModel(0);
		}
		if (cor.accepts(ChemModel.class) && chemModel == null) {
			// try to read a ChemModel
			try {

				chemModel = (ChemModel) cor.read((IChemObject) new ChemModel());
				if (chemModel == null) {
					error = "The object chemModel was empty unexpectedly!";
				}
			} catch (final Exception exception) {
				error = "Error while reading file: " + exception.getMessage();
				exception.printStackTrace();
			}
		}

		// Smiles reading
		if (cor.accepts(AtomContainerSet.class) && chemModel == null) {
			// try to read a AtomContainer set
			try {
				final IAtomContainerSet som = cor.read(new AtomContainerSet());
				chemModel = new ChemModel();
				chemModel.setMoleculeSet(som);
				if (chemModel == null) {
					error = "The object chemModel was empty unexpectedly!";
				}
			} catch (final Exception exception) {
				error = "Error while reading file: " + exception.getMessage();
				exception.printStackTrace();
			}
		}

		// MDLV3000 reading
		if (cor.accepts(AtomContainer.class) && chemModel == null) {
			// try to read a AtomContainer
			final IAtomContainer mol = cor.read(new AtomContainer());
			if (mol != null) {
				try {
					final IAtomContainerSet newSet = new AtomContainerSet();
					newSet.addAtomContainer(mol);
					chemModel = new ChemModel();
					chemModel.setMoleculeSet(newSet);
					if (chemModel == null) {
						error = "The object chemModel was empty unexpectedly!";
					}
				} catch (final Exception exception) {
					error = "Error while reading file: "
							+ exception.getMessage();
					exception.printStackTrace();
				}
			}
		}

		// RGroupQuery reading
		if (cor.accepts(RGroupQuery.class) && chemModel == null) {
			final IRGroupQuery rgroupQuery = cor.read(new RGroupQuery());
			if (rgroupQuery != null) {
				try {
					chemModel = new ChemModel();
					final RGroupHandler rgHandler = new RGroupHandler(
							rgroupQuery);
					panel.get2DHub().setRGroupHandler(rgHandler);
					chemModel.setMoleculeSet(rgHandler
							.getMoleculeSet(chemModel));
					rgHandler.layoutRgroup();

				} catch (final Exception exception) {
					error = "Error while reading file: "
							+ exception.getMessage();
					exception.printStackTrace();
				}
			}
		}

		if (error != null) {
			throw new CDKException(error);
		}

		if (chemModel == null && chemFile != null) {
			chemModel = (ChemModel) chemFile.getChemSequence(0).getChemModel(0);
		}

		// SmilesParser sets valencies, switch off by default.
		if (cor instanceof SMILESReader) {
			final IAtomContainer allinone = JChemPaintPanel
					.getAllAtomContainersInOne(chemModel);
			for (int k = 0; k < allinone.getAtomCount(); k++) {
				allinone.getAtom(k).setValency(null);
			}
		}
		return chemModel;
	}
	/**
	 * Inserts a molecule into the current set, usually from Combobox or Insert
	 * field, with possible shifting of the existing set.
	 * 
	 * @param chemPaintPanel
	 * @param molecule
	 * @param generateCoordinates
	 * @param shiftPanel
	 * @throws CDKException
	 */
	public static void generateModel(
			final AbstractJChemPaintPanel chemPaintPanel,
			IAtomContainer molecule, final boolean generateCoordinates,
			final boolean shiftPasted) throws CDKException {
		if (molecule == null) {
			return;
		}

		final IChemModel chemModel = chemPaintPanel.getChemModel();
		IAtomContainerSet moleculeSet = chemModel.getMoleculeSet();
		if (moleculeSet == null) {
			moleculeSet = new AtomContainerSet();
		}

		// On copy & paste on top of an existing drawn structure, prevent the
		// pasted section to be drawn exactly on top or to far away from the
		// original by shifting it to a fixed position next to it.

		if (shiftPasted) {
			double maxXCurr = Double.NEGATIVE_INFINITY;
			double minXPaste = Double.POSITIVE_INFINITY;

			for (final IAtomContainer atc : moleculeSet.atomContainers()) {
				// Detect the right border of the current structure..
				for (final IAtom atom : atc.atoms()) {
					if (atom.getPoint2d().x > maxXCurr) {
						maxXCurr = atom.getPoint2d().x;
					}
				}
				// Detect the left border of the pasted structure..
				for (final IAtom atom : molecule.atoms()) {
					if (atom.getPoint2d().x < minXPaste) {
						minXPaste = atom.getPoint2d().x;
					}
				}
			}

			if (maxXCurr != Double.NEGATIVE_INFINITY
					&& minXPaste != Double.POSITIVE_INFINITY) {
				// Shift the pasted structure to be nicely next to the existing
				// one.
				final int MARGIN = 1;
				final double SHIFT = maxXCurr - minXPaste;
				for (final IAtom atom : molecule.atoms()) {
					atom.setPoint2d(new Point2d(atom.getPoint2d().x + MARGIN
							+ SHIFT, atom.getPoint2d().y));
				}
			}
		}

		if (generateCoordinates) {
			// now generate 2D coordinates
			final StructureDiagramGenerator sdg = new StructureDiagramGenerator();
			sdg.setTemplateHandler(new TemplateHandler(moleculeSet.getBuilder()));
			try {
				sdg.setMolecule(molecule);
				sdg.generateCoordinates(new Vector2d(0, 1));
				molecule = sdg.getMolecule();
			} catch (final Exception exc) {
				JOptionPane.showMessageDialog(chemPaintPanel,
						GT._("Structure could not be generated"));
				throw new CDKException("Cannot depict structure");
			}
		}

		if (moleculeSet.getAtomContainer(0).getAtomCount() == 0) {
			moleculeSet.getAtomContainer(0).add(molecule);
		} else {
			moleculeSet.addAtomContainer(molecule);
		}

		final IUndoRedoFactory undoRedoFactory = chemPaintPanel.get2DHub()
				.getUndoRedoFactory();
		final UndoRedoHandler undoRedoHandler = chemPaintPanel.get2DHub()
				.getUndoRedoHandler();

		if (undoRedoFactory != null) {
			final IUndoRedoable undoredo = undoRedoFactory
					.getAddAtomsAndBondsEdit(chemPaintPanel.get2DHub()
							.getIChemModel(), molecule, null, "Paste",
							chemPaintPanel.get2DHub());
			undoRedoHandler.postEdit(undoredo);
		}

		chemPaintPanel.getChemModel().setMoleculeSet(moleculeSet);
		chemPaintPanel.updateUndoRedoControls();
		chemPaintPanel.get2DHub().updateView();
	}
예제 #12
0
 private List<IAtomContainer> toList(IAtomContainerSet set) {
   return FluentIterable.from(set.atomContainers()).toList();
 }
예제 #13
0
  /**
   * Read a ChemFile from a file in MDL SDF format.
   *
   * @return The ChemFile that was read from the MDL file.
   */
  private IChemFile readChemFile(IChemFile chemFile) throws CDKException {
    IChemSequence chemSequence = chemFile.getBuilder().newInstance(IChemSequence.class);

    IChemModel chemModel = chemFile.getBuilder().newInstance(IChemModel.class);
    IAtomContainerSet setOfMolecules = chemFile.getBuilder().newInstance(IAtomContainerSet.class);
    IAtomContainer m = readAtomContainer(chemFile.getBuilder().newInstance(IAtomContainer.class));
    if (m != null && m instanceof IAtomContainer) {
      setOfMolecules.addAtomContainer((IAtomContainer) m);
    }
    chemModel.setMoleculeSet(setOfMolecules);
    chemSequence.addChemModel(chemModel);

    setOfMolecules = chemFile.getBuilder().newInstance(IAtomContainerSet.class);
    chemModel = chemFile.getBuilder().newInstance(IChemModel.class);
    String str;
    try {
      String line;
      while ((line = input.readLine()) != null) {
        logger.debug("line: ", line);
        // apparently, this is a SDF file, continue with
        // reading mol files
        str = new String(line);
        if (str.equals("$$$$")) {
          m = readAtomContainer(chemFile.getBuilder().newInstance(IAtomContainer.class));

          if (m != null && m instanceof IAtomContainer) {
            setOfMolecules.addAtomContainer((IAtomContainer) m);

            chemModel.setMoleculeSet(setOfMolecules);
            chemSequence.addChemModel(chemModel);

            setOfMolecules = chemFile.getBuilder().newInstance(IAtomContainerSet.class);
            chemModel = chemFile.getBuilder().newInstance(IChemModel.class);
          }
        } else {
          // here the stuff between 'M  END' and '$$$$'
          if (m != null) {
            // ok, the first lines should start with '>'
            String fieldName = null;
            if (str.startsWith("> ")) {
              // ok, should extract the field name
              str.substring(2); // String content =
              int index = str.indexOf("<");
              if (index != -1) {
                int index2 = str.substring(index).indexOf(">");
                if (index2 != -1) {
                  fieldName = str.substring(index + 1, index + index2);
                }
              }
            }
            if (line == null) {
              throw new CDKException("Expecting data line here, but found null!");
            }
            StringBuilder data = new StringBuilder();
            int dataLineCount = 0;
            boolean lineIsContinued = false;
            while ((line = input.readLine()) != null) {

              if (line.equals(" ") && dataLineCount == 0) {
                // apparently a file can have a field whose value is a single space. Moronic
                // we check for it *before* trimming it. ideally we should check for any length
                // of whitespace

                // In adition some SD files have the blank line after the value line contain
                // a space, rather than being a true blank line. So we only store a blank value
                // line if it's the first line after the key line
                data.append(line);
                lineIsContinued = false;
                dataLineCount++;
                if (!lineIsContinued && dataLineCount > 1)
                  data.append(System.getProperty("line.separator"));
                continue;
              }

              line = line.trim();
              if (line.length() == 0) break;

              if (line.equals("$$$$")) {
                logger.error("Expecting data line here, but found end of molecule: ", line);
                break;
              }
              logger.debug("data line: ", line);
              lineIsContinued = false; // reset property
              dataLineCount++;

              // preserve newlines, unless the line is exactly 80 chars;
              // in that case it is assumed to continue on the next line.
              // See MDL documentation.
              if (!lineIsContinued && dataLineCount > 1)
                data.append(System.getProperty("line.separator"));

              // add the data line
              data.append(line);

              // check if the line will be continued on the next line
              if (line.length() == 80) lineIsContinued = true;
            }

            if (fieldName != null) {
              logger.info("fieldName, data: ", fieldName, ", ", data);
              m.setProperty(fieldName, data.toString());
            }
          }
        }
      }
    } catch (CDKException cdkexc) {
      throw cdkexc;
    } catch (Exception exception) {
      String error = "Error while parsing SDF";
      logger.error(error);
      logger.debug(exception);
      throw new CDKException(error, exception);
    }
    try {
      input.close();
    } catch (Exception exc) {
      String error = "Error while closing file: " + exc.getMessage();
      logger.error(error);
      throw new CDKException(error, exc);
    }

    chemFile.addChemSequence(chemSequence);
    return chemFile;
  }
예제 #14
0
  @TestMethod(value = "testCalculate_IAtomContainer")
  public DescriptorValue calculate(
      IAtom atom, IAtomContainer atomContainer, IRingSet precalculatedringset) {
    IAtomContainer varAtomContainer;
    try {
      varAtomContainer = (IAtomContainer) atomContainer.clone();
    } catch (CloneNotSupportedException e) {
      return getDummyDescriptorValue(e);
    }

    int atomPosition = atomContainer.getAtomNumber(atom);
    IAtom clonedAtom = varAtomContainer.getAtom(atomPosition);

    DoubleArrayResult rdfProtonCalculatedValues = new DoubleArrayResult(gsr_desc_length);
    if (!atom.getSymbol().equals("H")) {
      return getDummyDescriptorValue(new CDKException("Invalid atom specified"));
    }

    ///////////////////////// FIRST SECTION OF MAIN METHOD: DEFINITION OF MAIN VARIABLES
    ///////////////////////// AND AROMATICITY AND PI-SYSTEM AND RINGS DETECTION

    Molecule mol = new Molecule(varAtomContainer);
    if (varAtomContainer != acold) {
      acold = varAtomContainer;
      // DETECTION OF pi SYSTEMS
      varAtomContainerSet = ConjugatedPiSystemsDetector.detect(mol);
      if (precalculatedringset == null)
        try {
          varRingSet = (new AllRingsFinder()).findAllRings(varAtomContainer);
        } catch (CDKException e) {
          return getDummyDescriptorValue(e);
        }
      else varRingSet = precalculatedringset;
      try {
        GasteigerMarsiliPartialCharges peoe = new GasteigerMarsiliPartialCharges();
        peoe.assignGasteigerMarsiliSigmaPartialCharges(mol, true);
      } catch (Exception ex1) {
        return getDummyDescriptorValue(ex1);
      }
    }
    if (checkAromaticity) {
      try {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(varAtomContainer);
        CDKHueckelAromaticityDetector.detectAromaticity(varAtomContainer);
      } catch (CDKException e) {
        return getDummyDescriptorValue(e);
      }
    }
    IRingSet rsAtom;
    Ring ring;
    IRingSet ringsWithThisBond;
    // SET ISINRING FLAGS FOR BONDS
    Iterator<IBond> bondsInContainer = varAtomContainer.bonds().iterator();
    while (bondsInContainer.hasNext()) {
      IBond bond = bondsInContainer.next();
      ringsWithThisBond = varRingSet.getRings(bond);
      if (ringsWithThisBond.getAtomContainerCount() > 0) {
        bond.setFlag(CDKConstants.ISINRING, true);
      }
    }

    // SET ISINRING FLAGS FOR ATOMS
    IRingSet ringsWithThisAtom;

    for (int w = 0; w < varAtomContainer.getAtomCount(); w++) {
      ringsWithThisAtom = varRingSet.getRings(varAtomContainer.getAtom(w));
      if (ringsWithThisAtom.getAtomContainerCount() > 0) {
        varAtomContainer.getAtom(w).setFlag(CDKConstants.ISINRING, true);
      }
    }

    IAtomContainer detected = varAtomContainerSet.getAtomContainer(0);

    // neighboors[0] is the atom joined to the target proton:
    List<IAtom> neighboors = mol.getConnectedAtomsList(clonedAtom);
    IAtom neighbour0 = neighboors.get(0);

    // 2', 3', 4', 5', 6', and 7' atoms up to the target are detected:
    List<IAtom> atomsInSecondSphere = mol.getConnectedAtomsList(neighbour0);
    List<IAtom> atomsInThirdSphere;
    List<IAtom> atomsInFourthSphere;
    List<IAtom> atomsInFifthSphere;
    List<IAtom> atomsInSixthSphere;
    List<IAtom> atomsInSeventhSphere;

    // SOME LISTS ARE CREATED FOR STORING OF INTERESTING ATOMS AND BONDS DURING DETECTION
    ArrayList<Integer> singles = new ArrayList<Integer>(); // list of any bond not rotatable
    ArrayList<Integer> doubles = new ArrayList<Integer>(); // list with only double bonds
    ArrayList<Integer> atoms = new ArrayList<Integer>(); // list with all the atoms in spheres
    // atoms.add( Integer.valueOf( mol.getAtomNumber(neighboors[0]) ) );
    ArrayList<Integer> bondsInCycloex =
        new ArrayList<Integer>(); // list for bonds in cycloexane-like rings

    // 2', 3', 4', 5', 6', and 7' bonds up to the target are detected:
    IBond secondBond; // (remember that first bond is proton bond)
    IBond thirdBond; //
    IBond fourthBond; //
    IBond fifthBond; //
    IBond sixthBond; //
    IBond seventhBond; //

    // definition of some variables used in the main FOR loop for detection of interesting atoms and
    // bonds:
    boolean theBondIsInA6MemberedRing; // this is like a flag for bonds which are in cycloexane-like
    // rings (rings with more than 4 at.)
    IBond.Order bondOrder;
    int bondNumber;
    int sphere;

    // THIS MAIN FOR LOOP DETECT RIGID BONDS IN 7 SPHERES:
    for (IAtom curAtomSecond : atomsInSecondSphere) {
      secondBond = mol.getBond(neighbour0, curAtomSecond);
      if (mol.getAtomNumber(curAtomSecond) != atomPosition
          && getIfBondIsNotRotatable(mol, secondBond, detected)) {
        sphere = 2;
        bondOrder = secondBond.getOrder();
        bondNumber = mol.getBondNumber(secondBond);
        theBondIsInA6MemberedRing = false;
        checkAndStore(
            bondNumber,
            bondOrder,
            singles,
            doubles,
            bondsInCycloex,
            mol.getAtomNumber(curAtomSecond),
            atoms,
            sphere,
            theBondIsInA6MemberedRing);
        atomsInThirdSphere = mol.getConnectedAtomsList(curAtomSecond);
        if (atomsInThirdSphere.size() > 0) {
          for (IAtom curAtomThird : atomsInThirdSphere) {
            thirdBond = mol.getBond(curAtomThird, curAtomSecond);
            // IF THE ATOMS IS IN THE THIRD SPHERE AND IN A CYCLOEXANE-LIKE RING, IT IS STORED IN
            // THE PROPER LIST:
            if (mol.getAtomNumber(curAtomThird) != atomPosition
                && getIfBondIsNotRotatable(mol, thirdBond, detected)) {
              sphere = 3;
              bondOrder = thirdBond.getOrder();
              bondNumber = mol.getBondNumber(thirdBond);
              theBondIsInA6MemberedRing = false;

              // if the bond is in a cyclohexane-like ring (a ring with 5 or more atoms, not
              // aromatic)
              // the boolean "theBondIsInA6MemberedRing" is set to true
              if (!thirdBond.getFlag(CDKConstants.ISAROMATIC)) {
                if (!curAtomThird.equals(neighbour0)) {
                  rsAtom = varRingSet.getRings(thirdBond);
                  for (int f = 0; f < rsAtom.getAtomContainerCount(); f++) {
                    ring = (Ring) rsAtom.getAtomContainer(f);
                    if (ring.getRingSize() > 4 && ring.contains(thirdBond)) {
                      theBondIsInA6MemberedRing = true;
                    }
                  }
                }
              }
              checkAndStore(
                  bondNumber,
                  bondOrder,
                  singles,
                  doubles,
                  bondsInCycloex,
                  mol.getAtomNumber(curAtomThird),
                  atoms,
                  sphere,
                  theBondIsInA6MemberedRing);
              theBondIsInA6MemberedRing = false;
              atomsInFourthSphere = mol.getConnectedAtomsList(curAtomThird);
              if (atomsInFourthSphere.size() > 0) {
                for (IAtom curAtomFourth : atomsInFourthSphere) {
                  fourthBond = mol.getBond(curAtomThird, curAtomFourth);
                  if (mol.getAtomNumber(curAtomFourth) != atomPosition
                      && getIfBondIsNotRotatable(mol, fourthBond, detected)) {
                    sphere = 4;
                    bondOrder = fourthBond.getOrder();
                    bondNumber = mol.getBondNumber(fourthBond);
                    theBondIsInA6MemberedRing = false;
                    checkAndStore(
                        bondNumber,
                        bondOrder,
                        singles,
                        doubles,
                        bondsInCycloex,
                        mol.getAtomNumber(curAtomFourth),
                        atoms,
                        sphere,
                        theBondIsInA6MemberedRing);
                    atomsInFifthSphere = mol.getConnectedAtomsList(curAtomFourth);
                    if (atomsInFifthSphere.size() > 0) {
                      for (IAtom curAtomFifth : atomsInFifthSphere) {
                        fifthBond = mol.getBond(curAtomFifth, curAtomFourth);
                        if (mol.getAtomNumber(curAtomFifth) != atomPosition
                            && getIfBondIsNotRotatable(mol, fifthBond, detected)) {
                          sphere = 5;
                          bondOrder = fifthBond.getOrder();
                          bondNumber = mol.getBondNumber(fifthBond);
                          theBondIsInA6MemberedRing = false;
                          checkAndStore(
                              bondNumber,
                              bondOrder,
                              singles,
                              doubles,
                              bondsInCycloex,
                              mol.getAtomNumber(curAtomFifth),
                              atoms,
                              sphere,
                              theBondIsInA6MemberedRing);
                          atomsInSixthSphere = mol.getConnectedAtomsList(curAtomFifth);
                          if (atomsInSixthSphere.size() > 0) {
                            for (IAtom curAtomSixth : atomsInSixthSphere) {
                              sixthBond = mol.getBond(curAtomFifth, curAtomSixth);
                              if (mol.getAtomNumber(curAtomSixth) != atomPosition
                                  && getIfBondIsNotRotatable(mol, sixthBond, detected)) {
                                sphere = 6;
                                bondOrder = sixthBond.getOrder();
                                bondNumber = mol.getBondNumber(sixthBond);
                                theBondIsInA6MemberedRing = false;
                                checkAndStore(
                                    bondNumber,
                                    bondOrder,
                                    singles,
                                    doubles,
                                    bondsInCycloex,
                                    mol.getAtomNumber(curAtomSixth),
                                    atoms,
                                    sphere,
                                    theBondIsInA6MemberedRing);
                                atomsInSeventhSphere = mol.getConnectedAtomsList(curAtomSixth);
                                if (atomsInSeventhSphere.size() > 0) {
                                  for (IAtom curAtomSeventh : atomsInSeventhSphere) {
                                    seventhBond = mol.getBond(curAtomSeventh, curAtomSixth);
                                    if (mol.getAtomNumber(curAtomSeventh) != atomPosition
                                        && getIfBondIsNotRotatable(mol, seventhBond, detected)) {
                                      sphere = 7;
                                      bondOrder = seventhBond.getOrder();
                                      bondNumber = mol.getBondNumber(seventhBond);
                                      theBondIsInA6MemberedRing = false;
                                      checkAndStore(
                                          bondNumber,
                                          bondOrder,
                                          singles,
                                          doubles,
                                          bondsInCycloex,
                                          mol.getAtomNumber(curAtomSeventh),
                                          atoms,
                                          sphere,
                                          theBondIsInA6MemberedRing);
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    // Variables
    double[] values; // for storage of results of other methods
    double distance;
    double sum;
    double smooth = -20;
    double partial;
    int position;
    double limitInf;
    double limitSup;
    double step;

    //////////////////////// THE FOUTH DESCRIPTOR IS gS(r), WHICH TAKES INTO ACCOUNT SINGLE BONDS IN
    // RIGID SYSTEMS

    Vector3d a_a = new Vector3d();
    Vector3d a_b = new Vector3d();
    Vector3d b_a = new Vector3d();
    Vector3d b_b = new Vector3d();
    Point3d middlePoint = new Point3d();
    double angle = 0;

    if (singles.size() > 0) {
      double dist0;
      double dist1;
      IAtom singleBondAtom0;
      IAtom singleBondAtom1;
      distance = 0;
      position = 0;
      IBond theSingleBond = null;
      limitInf = 0;
      limitSup = Math.PI / 2;
      step = (limitSup - limitInf) / 7;
      smooth = -1.15;
      int counter = 0;
      for (double ghs = 0; ghs < limitSup; ghs = ghs + step) {
        sum = 0;
        for (int sing = 0; sing < singles.size(); sing++) {
          angle = 0;
          partial = 0;
          Integer thisSingleBond = singles.get(sing);
          position = thisSingleBond;
          theSingleBond = mol.getBond(position);
          middlePoint = theSingleBond.get3DCenter();
          singleBondAtom0 = theSingleBond.getAtom(0);
          singleBondAtom1 = theSingleBond.getAtom(1);
          dist0 = calculateDistanceBetweenTwoAtoms(singleBondAtom0, atom);
          dist1 = calculateDistanceBetweenTwoAtoms(singleBondAtom1, atom);

          a_a.set(middlePoint.x, middlePoint.y, middlePoint.z);
          if (dist1 > dist0)
            a_b.set(
                singleBondAtom0.getPoint3d().x,
                singleBondAtom0.getPoint3d().y,
                singleBondAtom0.getPoint3d().z);
          else
            a_b.set(
                singleBondAtom1.getPoint3d().x,
                singleBondAtom1.getPoint3d().y,
                singleBondAtom1.getPoint3d().z);
          b_a.set(middlePoint.x, middlePoint.y, middlePoint.z);
          b_b.set(atom.getPoint3d().x, atom.getPoint3d().y, atom.getPoint3d().z);

          values = calculateDistanceBetweenAtomAndBond(atom, theSingleBond);

          angle = calculateAngleBetweenTwoLines(a_a, a_b, b_a, b_b);
          // System.out.println("ANGLe: "+angle+ " "+ mol.getAtomNumber(atomsInSingleBond[0]) +" "
          // +mol.getAtomNumber(atomsInSingleBond[1]));

          partial =
              (1 / (Math.pow(values[0], 2))) * Math.exp(smooth * (Math.pow((ghs - angle), 2)));
          sum += partial;
        }
        // gSr_function.add(new Double(sum));
        rdfProtonCalculatedValues.add(sum);
        logger.debug("RDF gSr prob.: " + sum + " at distance " + ghs);
        counter++;
      }
    } else {
      return getDummyDescriptorValue(new CDKException("Some error occurred. Please report"));
    }
    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        rdfProtonCalculatedValues,
        getDescriptorNames());
  }
  /**
   * Search if the setOfAtomContainer contains the atomContainer
   *
   * @param set ISetOfAtomContainer object where to search
   * @param atomContainer IAtomContainer to search
   * @return True, if the atomContainer is contained
   */
  private boolean existAC(IAtomContainerSet set, IAtomContainer atomContainer) {

    IAtomContainer acClone = null;
    try {
      acClone = (IMolecule) atomContainer.clone();
      if (!lookingSymmetry) {
        /*remove all aromatic flags*/
        for (IAtom atom : acClone.atoms()) atom.setFlag(CDKConstants.ISAROMATIC, false);
        for (IBond bond : acClone.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false);
      }
    } catch (CloneNotSupportedException e1) {
      e1.printStackTrace();
    }

    for (int i = 0; i < acClone.getAtomCount(); i++)
      //			if(acClone.getAtom(i).getID() == null)
      acClone.getAtom(i).setID("" + acClone.getAtomNumber(acClone.getAtom(i)));

    if (lookingSymmetry) {
      try {
        CDKHueckelAromaticityDetector.detectAromaticity(acClone);
      } catch (CDKException e) {
        e.printStackTrace();
      }
    } else {
      if (!lookingSymmetry) {
        /*remove all aromatic flags*/
        for (IAtom atom : acClone.atoms()) atom.setFlag(CDKConstants.ISAROMATIC, false);
        for (IBond bond : acClone.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false);
      }
    }
    for (int i = 0; i < set.getAtomContainerCount(); i++) {
      IAtomContainer ss = set.getAtomContainer(i);
      for (int j = 0; j < ss.getAtomCount(); j++)
        //				if(ss.getAtom(j).getID() == null)
        ss.getAtom(j).setID("" + ss.getAtomNumber(ss.getAtom(j)));

      try {

        if (!lookingSymmetry) {
          QueryAtomContainer qAC =
              QueryAtomContainerCreator.createSymbolChargeIDQueryContainer(acClone);
          if (UniversalIsomorphismTester.isIsomorph(ss, qAC)) {
            QueryAtomContainer qAC2 =
                QueryAtomContainerCreator.createSymbolAndBondOrderQueryContainer(acClone);
            if (UniversalIsomorphismTester.isIsomorph(ss, qAC2)) return true;
          }
        } else {
          QueryAtomContainer qAC =
              QueryAtomContainerCreator.createSymbolAndChargeQueryContainer(acClone);
          CDKHueckelAromaticityDetector.detectAromaticity(ss);
          if (UniversalIsomorphismTester.isIsomorph(ss, qAC)) return true;
        }

      } catch (CDKException e1) {
        System.err.println(e1);
        logger.error(e1.getMessage());
        logger.debug(e1);
      }
    }
    return false;
  }
  /**
   * Get the container which is found resonance from a IMolecule. It is based on looking if the
   * order of the bond changes.
   *
   * @param molecule The IMolecule to analyze
   * @return The different containers
   */
  @TestMethod("testGetContainers_IMolecule")
  public IAtomContainerSet getContainers(IMolecule molecule) {
    IAtomContainerSet setOfCont = molecule.getBuilder().newAtomContainerSet();
    IMoleculeSet setOfMol = getStructures(molecule);

    if (setOfMol.getMoleculeCount() == 0) return setOfCont;

    /*extraction of all bonds which has been produced a changes of order*/
    List<IBond> bondList = new ArrayList<IBond>();
    for (int i = 1; i < setOfMol.getMoleculeCount(); i++) {
      IMolecule mol = setOfMol.getMolecule(i);
      for (int j = 0; j < mol.getBondCount(); j++) {
        IBond bond = molecule.getBond(j);
        if (!mol.getBond(j).getOrder().equals(bond.getOrder())) {
          if (!bondList.contains(bond)) bondList.add(bond);
        }
      }
    }

    if (bondList.size() == 0) return null;

    int[] flagBelonging = new int[bondList.size()];
    for (int i = 0; i < flagBelonging.length; i++) flagBelonging[i] = 0;
    int[] position = new int[bondList.size()];
    int maxGroup = 1;

    /*Analysis if the bond are linked together*/
    List<IBond> newBondList = new ArrayList<IBond>();
    newBondList.add(bondList.get(0));

    int pos = 0;
    for (int i = 0; i < newBondList.size(); i++) {

      if (i == 0) flagBelonging[i] = maxGroup;
      else {
        if (flagBelonging[position[i]] == 0) {
          maxGroup++;
          flagBelonging[position[i]] = maxGroup;
        }
      }

      IBond bondA = newBondList.get(i);
      for (int ato = 0; ato < 2; ato++) {
        IAtom atomA1 = bondA.getAtom(ato);
        List<IBond> bondA1s = molecule.getConnectedBondsList(atomA1);
        for (int j = 0; j < bondA1s.size(); j++) {
          IBond bondB = bondA1s.get(j);
          if (!newBondList.contains(bondB))
            for (int k = 0; k < bondList.size(); k++)
              if (bondList.get(k).equals(bondB))
                if (flagBelonging[k] == 0) {
                  flagBelonging[k] = maxGroup;
                  pos++;
                  newBondList.add(bondB);
                  position[pos] = k;
                }
        }
      }
      // if it is final size and not all are added
      if (newBondList.size() - 1 == i)
        for (int k = 0; k < bondList.size(); k++)
          if (!newBondList.contains(bondList.get(k))) {
            newBondList.add(bondList.get(k));
            position[i + 1] = k;
            break;
          }
    }
    /*creating containers according groups*/
    for (int i = 0; i < maxGroup; i++) {
      IAtomContainer container = molecule.getBuilder().newAtomContainer();
      for (int j = 0; j < bondList.size(); j++) {
        if (flagBelonging[j] != i + 1) continue;
        IBond bond = bondList.get(j);
        IAtom atomA1 = bond.getAtom(0);
        IAtom atomA2 = bond.getAtom(1);
        if (!container.contains(atomA1)) container.addAtom(atomA1);
        if (!container.contains(atomA2)) container.addAtom(atomA2);
        container.addBond(bond);
      }
      setOfCont.addAtomContainer(container);
    }
    return setOfCont;
  }
  /**
   * Initiate process. It is needed to call the addExplicitHydrogensToSatisfyValency from the class
   * tools.HydrogenAdder.
   *
   * @exception CDKException Description of the Exception
   * @param reactants reactants of the reaction.
   * @param agents agents of the reaction (Must be in this case null).
   */
  @TestMethod("testInitiate_IAtomContainerSet_IAtomContainerSet")
  public IReactionSet initiate(IAtomContainerSet reactants, IAtomContainerSet agents)
      throws CDKException {

    logger.debug("initiate reaction: RearrangementRadicalReaction");

    if (reactants.getAtomContainerCount() != 1) {
      throw new CDKException("RearrangementRadicalReaction only expects one reactant");
    }
    if (agents != null) {
      throw new CDKException("RearrangementRadicalReaction don't expects agents");
    }

    IReactionSet setOfReactions =
        DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
    IAtomContainer reactant = reactants.getAtomContainer(0);

    /* if the parameter hasActiveCenter is not fixed yet, set the active centers*/
    IParameterReact ipr = super.getParameterClass(SetReactionCenter.class);
    if (ipr != null && !ipr.isSetParameter()) setActiveCenters(reactant);

    Iterator<IAtom> atoms = reactants.getAtomContainer(0).atoms().iterator();
    while (atoms.hasNext()) {
      IAtom atomi = atoms.next();
      if (atomi.getFlag(CDKConstants.REACTIVE_CENTER)
          && reactant.getConnectedSingleElectronsCount(atomi) == 1) {

        Iterator<IBond> bondis = reactant.getConnectedBondsList(atomi).iterator();

        while (bondis.hasNext()) {
          IBond bondi = bondis.next();

          if (bondi.getFlag(CDKConstants.REACTIVE_CENTER)
              && bondi.getOrder() == IBond.Order.SINGLE) {

            IAtom atomj = bondi.getConnectedAtom(atomi);
            if (atomi.getFlag(CDKConstants.REACTIVE_CENTER)
                && (atomj.getFormalCharge() == CDKConstants.UNSET ? 0 : atomj.getFormalCharge())
                    == 0
                && reactant.getConnectedSingleElectronsCount(atomj) == 0) {

              Iterator<IBond> bondjs = reactant.getConnectedBondsList(atomj).iterator();
              while (bondjs.hasNext()) {
                IBond bondj = bondjs.next();

                if (bondj.equals(bondi)) continue;

                if (bondj.getFlag(CDKConstants.REACTIVE_CENTER)
                    && bondj.getOrder() == IBond.Order.DOUBLE) {

                  IAtom atomk = bondj.getConnectedAtom(atomj);
                  if (atomk.getFlag(CDKConstants.REACTIVE_CENTER)
                      && (atomk.getFormalCharge() == CDKConstants.UNSET
                              ? 0
                              : atomk.getFormalCharge())
                          == 0
                      && reactant.getConnectedSingleElectronsCount(atomk) == 0) {

                    ArrayList<IAtom> atomList = new ArrayList<IAtom>();
                    atomList.add(atomi);
                    atomList.add(atomj);
                    atomList.add(atomk);
                    ArrayList<IBond> bondList = new ArrayList<IBond>();
                    bondList.add(bondi);
                    bondList.add(bondj);

                    IAtomContainerSet moleculeSet =
                        reactant.getBuilder().newInstance(IAtomContainerSet.class);
                    moleculeSet.addAtomContainer(reactant);
                    IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
                    if (reaction == null) continue;
                    else setOfReactions.addReaction(reaction);
                  }
                }
              }
            }
          }
        }
      }
    }
    return setOfReactions;
  }
예제 #18
0
  /**
   * Initiates the process for the given mechanism. The atoms to apply are mapped between reactants
   * and products.
   *
   * @param atomContainerSet
   * @param atomList The list of atoms taking part in the mechanism. Only allowed two atoms. The
   *     first atom is the atom which contains the ISingleElectron and the second third is the atom
   *     which will be removed the first atom
   * @param bondList The list of bonds taking part in the mechanism. Only allowed one bond. It is
   *     the bond which is moved
   * @return The Reaction mechanism
   */
  @TestMethod(value = "testInitiate_IAtomContainerSet_ArrayList_ArrayList")
  public IReaction initiate(
      IAtomContainerSet atomContainerSet, ArrayList<IAtom> atomList, ArrayList<IBond> bondList)
      throws CDKException {
    CDKAtomTypeMatcher atMatcher = CDKAtomTypeMatcher.getInstance(atomContainerSet.getBuilder());
    if (atomContainerSet.getAtomContainerCount() != 1) {
      throw new CDKException("RadicalSiteIonizationMechanism only expects one IMolecule");
    }
    if (atomList.size() != 3) {
      throw new CDKException("RadicalSiteIonizationMechanism expects three atoms in the ArrayList");
    }
    if (bondList.size() != 2) {
      throw new CDKException(
          "RadicalSiteIonizationMechanism only expect one bond in the ArrayList");
    }
    IAtomContainer molecule = atomContainerSet.getAtomContainer(0);
    IAtomContainer reactantCloned;
    try {
      reactantCloned = (IAtomContainer) molecule.clone();
    } catch (CloneNotSupportedException e) {
      throw new CDKException("Could not clone IMolecule!", e);
    }
    IAtom atom1 = atomList.get(0); // Atom containing the ISingleElectron
    IAtom atom1C = reactantCloned.getAtom(molecule.getAtomNumber(atom1));
    IAtom atom2 = atomList.get(1); // Atom
    IAtom atom2C = reactantCloned.getAtom(molecule.getAtomNumber(atom2));
    IAtom atom3 = atomList.get(2); // Atom to be saved
    IAtom atom3C = reactantCloned.getAtom(molecule.getAtomNumber(atom3));
    IBond bond1 = bondList.get(0); // Bond to increase the order
    int posBond1 = molecule.getBondNumber(bond1);
    IBond bond2 = bondList.get(1); // Bond to remove
    int posBond2 = molecule.getBondNumber(bond2);

    BondManipulator.increaseBondOrder(reactantCloned.getBond(posBond1));
    reactantCloned.removeBond(reactantCloned.getBond(posBond2));

    List<ISingleElectron> selectron = reactantCloned.getConnectedSingleElectronsList(atom1C);
    reactantCloned.removeSingleElectron(selectron.get(selectron.size() - 1));
    atom1C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    IAtomType type = atMatcher.findMatchingAtomType(reactantCloned, atom1C);
    if (type == null) return null;

    atom2C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom2C);
    if (type == null) return null;

    reactantCloned.addSingleElectron(new SingleElectron(atom3C));
    atom3C.setHybridization(null);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(reactantCloned);
    type = atMatcher.findMatchingAtomType(reactantCloned, atom3C);
    if (type == null) return null;

    IReaction reaction = DefaultChemObjectBuilder.getInstance().newInstance(IReaction.class);
    reaction.addReactant(molecule);

    /* mapping */
    for (IAtom atom : molecule.atoms()) {
      IMapping mapping =
          DefaultChemObjectBuilder.getInstance()
              .newInstance(
                  IMapping.class, atom, reactantCloned.getAtom(molecule.getAtomNumber(atom)));
      reaction.addMapping(mapping);
    }

    IAtomContainerSet moleculeSetP = ConnectivityChecker.partitionIntoMolecules(reactantCloned);
    for (int z = 0; z < moleculeSetP.getAtomContainerCount(); z++)
      reaction.addProduct((IAtomContainer) moleculeSetP.getAtomContainer(z));

    return reaction;
  }