示例#1
0
  /**
   * Constructs an AtomContainer with a copy of the atoms and electronContainers of another
   * AtomContainer (A shallow copy, i.e., with the same objects as in the original AtomContainer).
   *
   * @param container An AtomContainer to copy the atoms and electronContainers from
   */
  public AtomContainer(IAtomContainer container) {
    this.atomCount = container.getAtomCount();
    this.bondCount = container.getBondCount();
    this.lonePairCount = container.getLonePairCount();
    this.singleElectronCount = container.getSingleElectronCount();
    this.atoms = new IAtom[this.atomCount];
    this.bonds = new IBond[this.bondCount];
    this.lonePairs = new ILonePair[this.lonePairCount];
    this.singleElectrons = new ISingleElectron[this.singleElectronCount];

    stereoElements = new HashSet<IStereoElement>(atomCount / 2);

    for (IStereoElement element : container.stereoElements()) {
      addStereoElement(element);
    }

    for (int f = 0; f < container.getAtomCount(); f++) {
      atoms[f] = container.getAtom(f);
      container.getAtom(f).addListener(this);
    }
    for (int f = 0; f < this.bondCount; f++) {
      bonds[f] = container.getBond(f);
      container.getBond(f).addListener(this);
    }
    for (int f = 0; f < this.lonePairCount; f++) {
      lonePairs[f] = container.getLonePair(f);
      container.getLonePair(f).addListener(this);
    }
    for (int f = 0; f < this.singleElectronCount; f++) {
      singleElectrons[f] = container.getSingleElectron(f);
      container.getSingleElectron(f).addListener(this);
    }
  }
示例#2
0
 /**
  * Returns the ring that is formed by the atoms in the given vector.
  *
  * @param vec The vector that contains the atoms of the ring
  * @param mol The molecule this ring is a substructure of
  * @return The ring formed by the given atoms
  */
 private IRing prepareRing(List vec, IAtomContainer mol) {
   // add the atoms in vec to the new ring
   int atomCount = vec.size();
   IRing ring = mol.getBuilder().newInstance(IRing.class, atomCount);
   IAtom[] atoms = new IAtom[atomCount];
   vec.toArray(atoms);
   ring.setAtoms(atoms);
   // add the bonds in mol to the new ring
   try {
     IBond b;
     for (int i = 0; i < atomCount - 1; i++) {
       b = mol.getBond(atoms[i], atoms[i + 1]);
       if (b != null) {
         ring.addBond(b);
       } else {
         logger.error("This should not happen.");
       }
     }
     b = mol.getBond(atoms[0], atoms[atomCount - 1]);
     if (b != null) {
       ring.addBond(b);
     } else {
       logger.error("This should not happen either.");
     }
   } catch (Exception exc) {
     logger.debug(exc);
   }
   logger.debug("found Ring  ", ring);
   return ring;
 }
示例#3
0
  /**
   * Adds all atoms and electronContainers of a given atomcontainer to this container.
   *
   * @param atomContainer The atomcontainer to be added
   */
  public void add(IAtomContainer atomContainer) {
    for (int f = 0; f < atomContainer.getAtomCount(); f++) {
      if (!contains(atomContainer.getAtom(f))) {
        addAtom(atomContainer.getAtom(f));
      }
    }
    for (int f = 0; f < atomContainer.getBondCount(); f++) {
      if (!contains(atomContainer.getBond(f))) {
        addBond(atomContainer.getBond(f));
      }
    }
    for (int f = 0; f < atomContainer.getLonePairCount(); f++) {
      if (!contains(atomContainer.getLonePair(f))) {
        addLonePair(atomContainer.getLonePair(f));
      }
    }
    for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) {
      if (!contains(atomContainer.getSingleElectron(f))) {
        addSingleElectron(atomContainer.getSingleElectron(f));
      }
    }

    for (IStereoElement se : atomContainer.stereoElements()) stereoElements.add(se);

    notifyChanged();
  }
  /**
   * 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));
  }
 public static void checkAverageBondLength(IAtomContainer ac) {
   double avlength = GeometryTools.getBondLengthAverage3D(ac);
   for (int i = 0; i < ac.getBondCount(); i++) {
     double distance =
         ac.getBond(i).getAtom(0).getPoint3d().distance(ac.getBond(i).getAtom(1).getPoint3d());
     Assert.assertTrue(
         "Unreasonable bond length (" + distance + ") for bond " + i,
         distance >= avlength / 2 && distance <= avlength * 2);
   }
 }
示例#6
0
  /** @cdk.inchi InChI=1/C4H5N/c1-2-4-5-3-1/h1-5H */
  @Test
  public void xtestPyrrole() throws Exception {
    IAtomContainer enol = new AtomContainer();

    // atom block
    IAtom atom1 = new Atom(Elements.CARBON);
    atom1.setHybridization(Hybridization.SP2);
    IAtom atom2 = new Atom(Elements.CARBON);
    atom2.setHybridization(Hybridization.SP2);
    IAtom atom3 = new Atom(Elements.CARBON);
    atom3.setHybridization(Hybridization.SP2);
    IAtom atom4 = new Atom(Elements.CARBON);
    atom4.setHybridization(Hybridization.SP2);
    IAtom atom5 = new Atom(Elements.NITROGEN);
    atom5.setHybridization(Hybridization.SP2);
    atom5.setImplicitHydrogenCount(1);

    // bond block
    IBond bond1 = new Bond(atom1, atom2);
    IBond bond2 = new Bond(atom2, atom3);
    IBond bond3 = new Bond(atom3, atom4);
    IBond bond4 = new Bond(atom4, atom5);
    IBond bond5 = new Bond(atom5, atom1);

    enol.addAtom(atom1);
    enol.addAtom(atom2);
    enol.addAtom(atom3);
    enol.addAtom(atom4);
    enol.addAtom(atom5);
    enol.addBond(bond1);
    enol.addBond(bond2);
    enol.addBond(bond3);
    enol.addBond(bond4);
    enol.addBond(bond5);

    // perceive atom types
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(enol);

    // now have the algorithm have a go at it
    enol = fbot.kekuliseAromaticRings(enol);
    Assert.assertNotNull(enol);
    // Assert.assertTrue(fbot.isOK(enol));

    // now check whether it did the right thing
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(0).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(1).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, enol.getBond(2).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(3).getOrder());
    ;
    Assert.assertEquals(CDKConstants.BONDORDER_SINGLE, enol.getBond(4).getOrder());
    ;
  }
示例#7
0
  void expandNode(Node node) {
    // System.out.println(node.toString(target));
    QuerySequenceElement el = sequence.get(node.sequenceElNum);

    if (el.center == null) // This node describers a bond that closes a ring
    {
      // Checking whether this bond is present in the target
      IAtom tAt0 = node.atoms[query.getAtomNumber(el.atoms[0])];
      IAtom tAt1 = node.atoms[query.getAtomNumber(el.atoms[1])];
      IBond tBo = target.getBond(tAt0, tAt1);
      if (tBo != null)
        if (el.bonds[0].matches(tBo)) {
          node.sequenceElNum++;
          // stack.push(node);
          if (node.sequenceElNum == sequence.size()) {
            // The node is not added in the stack if the end of the sequence is reached
            isomorphismFound = true;
            if (FlagStoreIsomorphismNode) isomorphismNodes.add(node);
          } else stack.push(node);
        }
    } else {
      targetAt.clear();
      IAtom tAt = node.atoms[el.centerNum];
      List<IAtom> conAt = target.getConnectedAtomsList(tAt);
      for (int i = 0; i < conAt.size(); i++) {
        if (!containsAtom(node.atoms, conAt.get(i))) targetAt.add(conAt.get(i));
      }

      if (el.atoms.length <= targetAt.size()) generateNodes(node);
    }
  }
示例#8
0
 /**
  * Helper method, used to help construct a configuration.
  *
  * @param bond
  * @param container
  * @return the array position of the bond in the container
  */
 private int getBondPosition(IBond bond, IAtomContainer container) {
   for (int i = 0; i < container.getBondCount(); i++) {
     if (bond.equals(container.getBond(i))) {
       return i;
     }
   }
   return -1;
 }
示例#9
0
  /**
   * (Z)-1,2-difluoroethene
   *
   * @cdk.inchi InChI=1/C2H2F2/c3-1-2-4/h1-2H/b2-1-
   */
  @Test
  public void z_1_2_difluoroethene() throws Exception {

    IAtomContainer ac = new AtomContainer();
    ac.addAtom(new Atom("F"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("F"));
    ac.addBond(0, 1, SINGLE);
    ac.addBond(1, 2, DOUBLE);
    ac.addBond(2, 3, SINGLE);

    ac.addStereoElement(
        new DoubleBondStereochemistry(
            ac.getBond(1), new IBond[] {ac.getBond(0), ac.getBond(2)}, TOGETHER));
    Graph g = convert(ac);
    assertThat(g.toSmiles(), is("F/C=C\\F"));
  }
示例#10
0
  /**
   * Returns bond map between sourceAtomCount and targetAtomCount molecules based on the atoms
   *
   * @param ac1 sourceAtomCount molecule
   * @param ac2 targetAtomCount molecule
   * @param mapping mappings between sourceAtomCount and targetAtomCount molecule atoms
   * @return bond map between sourceAtomCount and targetAtomCount molecules based on the atoms
   */
  private synchronized Map<IBond, IBond> makeBondMapOfAtomMap(
      IAtomContainer ac1, IAtomContainer ac2, AtomAtomMapping mapping) {

    Map<IBond, IBond> bondbondMappingMap = Collections.synchronizedMap(new HashMap<IBond, IBond>());

    for (Map.Entry<IAtom, IAtom> map1 : mapping.getMappingsByAtoms().entrySet()) {
      for (Map.Entry<IAtom, IAtom> map2 : mapping.getMappingsByAtoms().entrySet()) {
        if (map1.getKey() != map2.getKey()) {
          IBond bond1 = ac1.getBond(map1.getKey(), map2.getKey());
          IBond bond2 = ac2.getBond(map1.getValue(), map2.getValue());
          if (bond1 != null && bond2 != null && !bondbondMappingMap.containsKey(bond1)) {
            bondbondMappingMap.put(bond1, bond2);
          }
        }
      }
    }
    //        System.out.println("Mol Map size:" + bondbondMappingMap.size());
    return bondbondMappingMap;
  }
示例#11
0
  /** A unit test for JUnit */
  @Test
  public void testAlanin() throws Exception {
    HydrogenPlacer hydrogenPlacer = new HydrogenPlacer();
    IAtomContainer mol1 = new AtomContainer();
    SmilesGenerator sg = new SmilesGenerator();
    mol1.addAtom(new Atom("N", new Point2d(1, 0)));
    // 1
    mol1.addAtom(new Atom("C", new Point2d(1, 2)));
    // 2
    mol1.addAtom(new Atom("F", new Point2d(1, 2)));
    // 3
    mol1.addAtom(new Atom("C", new Point2d(0, 0)));
    // 4
    mol1.addAtom(new Atom("C", new Point2d(1, 4)));
    // 5
    mol1.addAtom(new Atom("O", new Point2d(1, 5)));
    // 6
    mol1.addAtom(new Atom("O", new Point2d(1, 6)));
    // 7
    mol1.addBond(0, 1, IBond.Order.SINGLE);
    // 1
    mol1.addBond(1, 2, IBond.Order.SINGLE, IBond.Stereo.UP);
    // 2
    mol1.addBond(1, 3, IBond.Order.SINGLE, IBond.Stereo.DOWN);
    // 3
    mol1.addBond(1, 4, IBond.Order.SINGLE);
    // 4
    mol1.addBond(4, 5, IBond.Order.SINGLE);
    // 5
    mol1.addBond(4, 6, IBond.Order.DOUBLE);
    // 6
    addExplicitHydrogens(mol1);
    hydrogenPlacer.placeHydrogens2D(mol1, 1.0);
    IsotopeFactory ifac = IsotopeFactory.getInstance(mol1.getBuilder());
    ifac.configureAtoms(mol1);

    String smiles1 = null;
    if (standAlone) {
      display(mol1);
    }
    smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);
    if (standAlone) {
      System.err.println("SMILES 1: " + smiles1);
    }
    Assert.assertNotNull(smiles1);
    Assert.assertEquals("[H]OC(=O)[C@](F)(N([H])[H])C([H])([H])[H]", smiles1);
    mol1.getBond(1).setStereo(IBond.Stereo.DOWN);
    mol1.getBond(2).setStereo(IBond.Stereo.UP);
    smiles1 = sg.createSMILES(mol1, true, new boolean[mol1.getBondCount()]);
    if (standAlone) {
      System.err.println("SMILES 1: " + smiles1);
    }
    Assert.assertNotNull(smiles1);
    Assert.assertEquals("[H]OC(=O)[C@](F)(C([H])([H])[H])N([H])[H]", smiles1);
  }
示例#12
0
  protected void process(
      IAtomContainer target,
      List<Integer> unmapped_atoms_molB,
      int mappingSize,
      List<Integer> i_bond_setB,
      List<String> c_bond_setB,
      List<Integer> mapped_atoms,
      int counter) {

    int unmapped_numB = unmapped_atoms_molB.size();
    boolean bond_considered = false;
    boolean normal_bond = true;

    for (int atomIndex = 0; atomIndex < target.getBondCount(); atomIndex++) {

      Integer indexI = target.getAtomNumber(target.getBond(atomIndex).getAtom(0));
      Integer indexJ = target.getAtomNumber(target.getBond(atomIndex).getAtom(1));
      IBond bond = target.getBond(atomIndex);
      Integer order = (bond.getOrder().ordinal() + 1);

      for (int b = 0; b < unmapped_numB; b++) {
        if (unmapped_atoms_molB.get(b).equals(indexI)) {
          normal_bond =
              unMappedAtomsEqualsIndexI(
                  target, mappingSize, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
          bond_considered = true;
        } else if (unmapped_atoms_molB.get(b) == indexJ) {
          normal_bond =
              unMappedAtomsEqualsIndexJ(
                  target, mappingSize, atomIndex, counter, mapped_atoms, indexI, indexJ, order);
          bond_considered = true;
        }

        if (normal_bond && bond_considered) {
          markNormalBonds(atomIndex, i_bond_setB, c_bond_setB, indexI, indexJ, order);
          normal_bond = true;
          break;
        }
      }
      bond_considered = false;
    }
  }
示例#13
0
  /**
   * This is a mock test where we don't want aromatic bonds to have a configuration.
   * (Z)-1,2-difluoroethene is not aromatic but a 'real' example would be porphyrins.
   *
   * @cdk.inchi InChI=1/C2H2F2/c3-1-2-4/h1-2H/b2-1-
   */
  @Test
  public void z_1_2_difluoroethene_aromatic() throws Exception {

    IAtomContainer ac = new AtomContainer();
    ac.addAtom(new Atom("F"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("C"));
    ac.addAtom(new Atom("F"));
    ac.addBond(0, 1, SINGLE);
    ac.addBond(1, 2, DOUBLE);
    ac.addBond(2, 3, SINGLE);

    ac.getBond(1).setFlag(CDKConstants.ISAROMATIC, true);

    ac.addStereoElement(
        new DoubleBondStereochemistry(
            ac.getBond(1), new IBond[] {ac.getBond(0), ac.getBond(2)}, TOGETHER));
    Graph g = convert(ac);
    assertThat(g.toSmiles(), is("F[CH]:[CH]F"));
  }
  /**
   * Generate Compatibility Graph Nodes Bond Insensitive
   *
   * @return
   * @throws IOException
   */
  private int compatibilityGraph() throws IOException {
    int comp_graph_nodes_List_size = compGraphNodes.size();
    //        System.out.println("Source atom count " + source.getAtomCount());
    //        System.out.println("target atom count " + target.getAtomCount());
    //        System.out.println("Expected " + (source.getAtomCount() * target.getAtomCount())
    //                + " Found Compatibilty: " + ((compGraphNodes.size() / 3) * 2));
    //        System.out.println("compGraphNodes " + compGraphNodes);
    for (int a = 0; a < comp_graph_nodes_List_size; a += 3) {
      for (int b = a; b < comp_graph_nodes_List_size; b += 3) {
        if ((a != b)
            && (!Objects.equals(compGraphNodes.get(a), compGraphNodes.get(b)))
            && (!Objects.equals(compGraphNodes.get(a + 1), compGraphNodes.get(b + 1)))) {

          IBond reactantBond;
          IBond productBond;

          //                    System.out.println("a " + compGraphNodes.get(a) + " b " +
          // compGraphNodes.get(b));
          // exists a bond in molecule 2, so that molecule 1 pair is connected?
          reactantBond =
              source.getBond(
                  source.getAtom(compGraphNodes.get(a)), source.getAtom(compGraphNodes.get(b)));
          productBond =
              target.getBond(
                  target.getAtom(compGraphNodes.get(a + 1)),
                  target.getAtom(compGraphNodes.get(b + 1)));

          if (reactantBond != null && productBond != null) {
            addEdges(reactantBond, productBond, a, b);
          } else if (reactantBond == null && productBond == null) {
            dEdges.add((a / 3) + 1);
            dEdges.add((b / 3) + 1);
          }
        }
      }
    }
    cEdgesSize = cEdges.size();
    dEdgesSize = dEdges.size();
    return 0;
  }
  /**
   * compatibilityGraphCEdgeZero is used to build up of the edges of the compatibility graph BIS
   *
   * @return
   * @throws IOException
   */
  private int compatibilityGraphCEdgeZero() throws IOException {

    int compGraphNodesCZeroListSize = compGraphNodesCZero.size();

    for (int a = 0; a < compGraphNodesCZeroListSize; a += 4) {
      int index_a = compGraphNodesCZero.get(a);
      int index_aPlus1 = compGraphNodesCZero.get(a + 1);
      for (int b = a + 4; b < compGraphNodesCZeroListSize; b += 4) {
        int index_b = compGraphNodesCZero.get(b);
        int index_bPlus1 = compGraphNodesCZero.get(b + 1);

        // if element atomCont !=jIndex and atoms on the adjacent sides of the bonds are not equal
        if ((a != b) && (index_a != index_b) && (index_aPlus1 != index_bPlus1)) {

          IBond reactantBond;
          IBond productBond;

          reactantBond = source.getBond(source.getAtom(index_a), source.getAtom(index_b));
          productBond = target.getBond(target.getAtom(index_aPlus1), target.getAtom(index_bPlus1));

          if (reactantBond != null && productBond != null) {
            addZeroEdges(reactantBond, productBond, a, b);
          } else if (reactantBond == null
              && productBond == null
              && source.getAtomCount() < 50
              && target.getAtomCount() < 50) {
            // 50 unique condition to speed up the AAM
            dEdges.add((a / 4) + 1);
            dEdges.add((b / 4) + 1);
          }
        }
      }
    }

    // Size of C and D edges of the compatibility graph
    cEdgesSize = cEdges.size();
    dEdgesSize = dEdges.size();
    return 0;
  }
 private void processBondsBlock(int lineCount, IAtomContainer container) throws IOException {
   for (int i = 0; i < lineCount; i++) {
     String line = input.readLine();
     int atom1 = Integer.parseInt(line.substring(10, 13).trim()) - 1;
     int atom2 = Integer.parseInt(line.substring(16, 19).trim()) - 1;
     if (container.getBond(container.getAtom(atom1), container.getAtom(atom2)) == null) {
       IBond bond =
           container.getBuilder().newBond(container.getAtom(atom1), container.getAtom(atom2));
       int order = Integer.parseInt(line.substring(23).trim());
       bond.setOrder(BondManipulator.createBondOrder((double) order));
       container.addBond(bond);
     } // else: bond already present; CTX store the bonds twice
   }
 }
示例#17
0
 /**
  * Removes all atoms and electronContainers of a given atomcontainer from this container.
  *
  * @param atomContainer The atomcontainer to be removed
  */
 public void remove(IAtomContainer atomContainer) {
   for (int f = 0; f < atomContainer.getAtomCount(); f++) {
     removeAtom(atomContainer.getAtom(f));
   }
   for (int f = 0; f < atomContainer.getBondCount(); f++) {
     removeBond(atomContainer.getBond(f));
   }
   for (int f = 0; f < atomContainer.getLonePairCount(); f++) {
     removeLonePair(atomContainer.getLonePair(f));
   }
   for (int f = 0; f < atomContainer.getSingleElectronCount(); f++) {
     removeSingleElectron(atomContainer.getSingleElectron(f));
   }
 }
示例#18
0
 @Test
 public void testSplit() throws CDKException {
   IAtomContainer mol = smilesParser.parseSmiles("C1CC1C2CCC2");
   SpanningTree st = new SpanningTree(mol);
   IRingSet rings = st.getAllRings();
   IBond splitBond = null;
   for (int i = 0; i < mol.getBondCount(); i++) {
     if (rings.getRings(mol.getBond(i)).getAtomContainerCount() == 0) {
       splitBond = mol.getBond(i);
       break;
     }
   }
   List<IAtomContainer> frags = FragmentUtils.splitMolecule(mol, splitBond);
   SmilesGenerator sg = new SmilesGenerator();
   Set<String> uniqueFrags = new HashSet<String>();
   for (IAtomContainer frag : frags) {
     uniqueFrags.add(sg.createSMILES(frag));
   }
   Assert.assertEquals(2, uniqueFrags.size());
   // You can put the fragments back together with a ring closure and dot
   // [CH]12CC1.[CH]12CCC1
   Assert.assertThat(uniqueFrags, hasItems("[CH]1CC1", "[CH]1CCC1"));
 }
示例#19
0
  /** {@inheritDoc} */
  @Override
  @TestMethod("testIsStereoMisMatch")
  public synchronized boolean isStereoMisMatch() {
    boolean flag = false;
    IAtomContainer reactant = getQuery();
    IAtomContainer product = getTarget();
    int stereoMisMatchScore = 0;
    if (getMappingCount() > 0) {
      AtomAtomMapping firstAtomMCS = getMCSList().iterator().next();
      for (IAtom indexI : firstAtomMCS.getMappingsByAtoms().keySet()) {
        IAtom indexJ = firstAtomMCS.getMappingsByAtoms().get(indexI);
        for (IAtom indexIPlus : firstAtomMCS.getMappingsByAtoms().keySet()) {
          IAtom indexJPlus = firstAtomMCS.getMappingsByAtoms().get(indexIPlus);
          if (!indexI.equals(indexIPlus) && !indexJ.equals(indexJPlus)) {

            IAtom sourceAtom1 = indexI;
            IAtom sourceAtom2 = indexIPlus;

            IBond rBond = reactant.getBond(sourceAtom1, sourceAtom2);

            IAtom targetAtom1 = indexJ;
            IAtom targetAtom2 = indexJPlus;
            IBond pBond = product.getBond(targetAtom1, targetAtom2);

            if ((rBond != null && pBond != null) && (rBond.getStereo() != pBond.getStereo())) {
              stereoMisMatchScore++;
            }
          }
        }
      }
    }
    if (stereoMisMatchScore > 0) {
      flag = true;
    }
    return flag;
  }
示例#20
0
  public List<IBond> generateBondMapping(IAtomContainer container, List<IAtom> atomMapping) {
    if (query == null) return null;

    List<IBond> v = new ArrayList<IBond>();
    for (int i = 0; i < query.getBondCount(); i++) {
      IAtom qa0 = query.getBond(i).getAtom(0);
      IAtom qa1 = query.getBond(i).getAtom(1);
      IAtom a0 = atomMapping.get(query.getAtomNumber(qa0));
      IAtom a1 = atomMapping.get(query.getAtomNumber(qa1));

      v.add(container.getBond(a0, a1));
    }

    return (v);
  }
示例#21
0
 private synchronized IQuery build(IAtomContainer queryMolecule) {
   VFQueryBuilder result = new VFQueryBuilder();
   for (IAtom atom : queryMolecule.atoms()) {
     AtomMatcher matcher = createAtomMatcher(queryMolecule, atom);
     if (matcher != null) {
       result.addNode(matcher, atom);
     }
   }
   for (int i = 0; i < queryMolecule.getBondCount(); i++) {
     IBond bond = queryMolecule.getBond(i);
     IAtom atomI = bond.getAtom(0);
     IAtom atomJ = bond.getAtom(1);
     result.connect(
         result.getNode(atomI), result.getNode(atomJ), createBondMatcher(queryMolecule, bond));
   }
   return result;
 }
示例#22
0
  @Test(timeout = 1000)
  public void testPyrrole_Silent() throws Exception {
    String smiles = "c2ccc3n([H])c1ccccc1c3(c2)";
    SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC));
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(6, doubleBondCount);
  }
示例#23
0
  @Test
  public void testLargeRingSystem() throws Exception {
    String smiles = "O=C1Oc6ccccc6(C(O)C1C5c2ccccc2CC(c3ccc(cc3)c4ccccc4)C5)";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    Assert.assertEquals(34, molecule.getAtomCount());

    // we should have 14 double bonds
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(13, doubleBondCount);
  }
示例#24
0
  /** @cdk.bug 3506770 */
  @Test
  public void testLargeBioclipseUseCase() throws Exception {
    String smiles =
        "COc1ccc2[C@@H]3[C@H](COc2c1)C(C)(C)OC4=C3C(=O)C(=O)C5=C4OC(C)(C)[C@@H]6COc7cc(OC)ccc7[C@H]56";
    SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance());
    IAtomContainer molecule = smilesParser.parseSmiles(smiles);

    molecule = fbot.kekuliseAromaticRings(molecule);
    Assert.assertNotNull(molecule);

    molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule);
    Assert.assertEquals(40, molecule.getAtomCount());

    // we should have 14 double bonds
    int doubleBondCount = 0;
    for (int i = 0; i < molecule.getBondCount(); i++) {
      IBond bond = molecule.getBond(i);
      if (bond.getOrder() == Order.DOUBLE) doubleBondCount++;
    }
    Assert.assertEquals(10, doubleBondCount);
  }
示例#25
0
  private List<List<Integer>> getAtomMappings(List bondMapping, IAtomContainer atomContainer) {
    List<List<Integer>> atomMapping = new ArrayList<List<Integer>>();

    // loop over each mapping
    for (Object aBondMapping : bondMapping) {
      List list = (List) aBondMapping;

      List<Integer> tmp = new ArrayList<Integer>();
      IAtom atom1 = null;
      IAtom atom2 = null;
      // loop over this mapping
      for (Object aList : list) {
        RMap map = (RMap) aList;
        int bondID = map.getId1();

        // get the atoms in this bond
        IBond bond = atomContainer.getBond(bondID);
        atom1 = bond.getAtom(0);
        atom2 = bond.getAtom(1);

        Integer idx1 = atomContainer.getAtomNumber(atom1);
        Integer idx2 = atomContainer.getAtomNumber(atom2);

        if (!tmp.contains(idx1)) tmp.add(idx1);
        if (!tmp.contains(idx2)) tmp.add(idx2);
      }
      if (tmp.size() > 0) atomMapping.add(tmp);

      // If there is only one bond, check if it matches both ways.
      if (list.size() == 1 && atom1.getAtomicNumber() == atom2.getAtomicNumber()) {
        List<Integer> tmp2 = new ArrayList<Integer>();
        tmp2.add(tmp.get(0));
        tmp2.add(tmp.get(1));
        atomMapping.add(tmp2);
      }
    }

    return atomMapping;
  }
示例#26
0
  /**
   * Generated coordinates for a given ring, which is fused to another ring. The rings share exactly
   * one bond.
   *
   * @param ring The ring to be placed
   * @param sharedAtoms The atoms of this ring, also members of another ring, which are already
   *     placed
   * @param sharedAtomsCenter The geometric center of these atoms
   * @param ringCenterVector A vector pointing the the center of the new ring
   * @param bondLength The standard bondlength
   */
  public void placeFusedRing(
      IRing ring,
      IAtomContainer sharedAtoms,
      Point2d sharedAtomsCenter,
      Vector2d ringCenterVector,
      double bondLength) {
    logger.debug("RingPlacer.placeFusedRing() start");
    Point2d ringCenter = new Point2d(sharedAtomsCenter);
    double radius = getNativeRingRadius(ring, bondLength);
    double newRingPerpendicular = Math.sqrt(Math.pow(radius, 2) - Math.pow(bondLength / 2, 2));
    ringCenterVector.normalize();
    logger.debug("placeFusedRing->: ringCenterVector.length()" + ringCenterVector.length());
    ringCenterVector.scale(newRingPerpendicular);
    ringCenter.add(ringCenterVector);

    IAtom bondAtom1 = sharedAtoms.getAtom(0);
    IAtom bondAtom2 = sharedAtoms.getAtom(1);

    Vector2d bondAtom1Vector = new Vector2d(bondAtom1.getPoint2d());
    Vector2d bondAtom2Vector = new Vector2d(bondAtom2.getPoint2d());
    Vector2d originRingCenterVector = new Vector2d(ringCenter);

    bondAtom1Vector.sub(originRingCenterVector);
    bondAtom2Vector.sub(originRingCenterVector);

    double occupiedAngle = bondAtom1Vector.angle(bondAtom2Vector);

    double remainingAngle = (2 * Math.PI) - occupiedAngle;
    double addAngle = remainingAngle / (ring.getRingSize() - 1);

    logger.debug("placeFusedRing->occupiedAngle: " + Math.toDegrees(occupiedAngle));
    logger.debug("placeFusedRing->remainingAngle: " + Math.toDegrees(remainingAngle));
    logger.debug("placeFusedRing->addAngle: " + Math.toDegrees(addAngle));

    IAtom startAtom;

    double centerX = ringCenter.x;
    double centerY = ringCenter.y;

    double xDiff = bondAtom1.getPoint2d().x - bondAtom2.getPoint2d().x;
    double yDiff = bondAtom1.getPoint2d().y - bondAtom2.getPoint2d().y;

    double startAngle;
    ;

    int direction = 1;
    // if bond is vertical
    if (xDiff == 0) {
      logger.debug("placeFusedRing->Bond is vertical");
      // starts with the lower Atom
      if (bondAtom1.getPoint2d().y > bondAtom2.getPoint2d().y) {
        startAtom = bondAtom1;
      } else {
        startAtom = bondAtom2;
      }

      // changes the drawing direction
      if (centerX < bondAtom1.getPoint2d().x) {
        direction = 1;
      } else {
        direction = -1;
      }
    }

    // if bond is not vertical
    else {
      // starts with the left Atom
      if (bondAtom1.getPoint2d().x > bondAtom2.getPoint2d().x) {
        startAtom = bondAtom1;
      } else {
        startAtom = bondAtom2;
      }

      // changes the drawing direction
      if (centerY - bondAtom1.getPoint2d().y
          > (centerX - bondAtom1.getPoint2d().x) * yDiff / xDiff) {
        direction = 1;
      } else {
        direction = -1;
      }
    }
    startAngle =
        GeometryTools.getAngle(
            startAtom.getPoint2d().x - ringCenter.x, startAtom.getPoint2d().y - ringCenter.y);

    IAtom currentAtom = startAtom;
    // determine first bond in Ring
    //        int k = 0;
    //        for (k = 0; k < ring.getElectronContainerCount(); k++) {
    //            if (ring.getElectronContainer(k) instanceof IBond) break;
    //        }
    IBond currentBond = sharedAtoms.getBond(0);
    Vector atomsToDraw = new Vector();
    for (int i = 0; i < ring.getBondCount() - 2; i++) {
      currentBond = ring.getNextBond(currentBond, currentAtom);
      currentAtom = currentBond.getConnectedAtom(currentAtom);
      atomsToDraw.addElement(currentAtom);
    }
    addAngle = addAngle * direction;
    try {
      logger.debug("placeFusedRing->startAngle: " + Math.toDegrees(startAngle));
      logger.debug("placeFusedRing->addAngle: " + Math.toDegrees(addAngle));
      logger.debug("placeFusedRing->startAtom is: " + (molecule.getAtomNumber(startAtom) + 1));
      logger.debug("AtomsToDraw: " + atomPlacer.listNumbers(molecule, atomsToDraw));
    } catch (Exception exc) {
      logger.debug("Caught an exception while logging in RingPlacer");
    }
    atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius);
  }
  private static IAtomContainer change(
      IAtomContainer ac,
      int x1,
      int y1,
      int x2,
      int y2,
      double b11,
      double b12,
      double b21,
      double b22) {
    IAtom ax1 = null, ax2 = null, ay1 = null, ay2 = null;
    IBond b1 = null, b2 = null, b3 = null, b4 = null;
    try {
      ax1 = ac.getAtom(x1);
      ax2 = ac.getAtom(x2);
      ay1 = ac.getAtom(y1);
      ay2 = ac.getAtom(y2);
    } catch (Exception exc) {
      logger.debug(exc);
    }
    b1 = ac.getBond(ax1, ay1);
    b2 = ac.getBond(ax1, ay2);
    b3 = ac.getBond(ax2, ay1);
    b4 = ac.getBond(ax2, ay2);
    if (b11 > 0) {
      if (b1 == null) {
        logger.debug("no bond " + x1 + "-" + y1 + ". Adding it with order " + b11);
        b1 = ac.getBuilder().newBond(ax1, ay1, BondManipulator.createBondOrder(b11));
        ac.addBond(b1);
      } else {
        b1.setOrder(BondManipulator.createBondOrder(b11));
        logger.debug("Setting bondorder for " + x1 + "-" + y1 + " to " + b11);
      }
    } else if (b1 != null) {
      ac.removeBond(b1);
      logger.debug("removing bond " + x1 + "-" + y1);
    }

    if (b12 > 0) {
      if (b2 == null) {
        logger.debug("no bond " + x1 + "-" + y2 + ". Adding it with order " + b12);
        b2 = ac.getBuilder().newBond(ax1, ay2, BondManipulator.createBondOrder(b12));
        ac.addBond(b2);
      } else {
        b2.setOrder(BondManipulator.createBondOrder(b12));
        logger.debug("Setting bondorder for " + x1 + "-" + y2 + " to " + b12);
      }
    } else if (b2 != null) {
      ac.removeBond(b2);
      logger.debug("removing bond " + x1 + "-" + y2);
    }

    if (b21 > 0) {
      if (b3 == null) {
        logger.debug("no bond " + x2 + "-" + y1 + ". Adding it with order " + b21);
        b3 = ac.getBuilder().newBond(ax2, ay1, BondManipulator.createBondOrder(b21));
        ac.addBond(b3);
      } else {
        b3.setOrder(BondManipulator.createBondOrder(b21));
        logger.debug("Setting bondorder for " + x2 + "-" + y1 + " to " + b21);
      }
    } else if (b3 != null) {
      ac.removeBond(b3);
      logger.debug("removing bond " + x2 + "-" + y1);
    }

    if (b22 > 0) {
      if (b4 == null) {
        logger.debug("no bond " + x2 + "-" + y2 + ". Adding it  with order " + b22);
        b4 = ac.getBuilder().newBond(ax2, ay2, BondManipulator.createBondOrder(b22));
        ac.addBond(b4);
      } else {
        b4.setOrder(BondManipulator.createBondOrder(b22));
        logger.debug("Setting bondorder for " + x2 + "-" + y2 + " to " + b22);
      }
    } else if (b4 != null) {
      ac.removeBond(b4);
      logger.debug("removing bond " + x2 + "-" + y2);
    }
    return ac;
  }
示例#28
0
  /** Recursive function to produce valid configurations for {@link #getAllConfigurations()}. */
  private void findConfigurationsRecursively(
      List<Integer> rGroupNumbers,
      List<List<Integer>> occurrences,
      List<Integer> occurIndexes,
      List<Integer[]> distributions,
      List<List<RGroup>> substitutes,
      int level,
      List<IAtomContainer> result)
      throws CDKException {

    if (level == rGroupNumbers.size()) {

      if (!checkIfThenConditionsMet(rGroupNumbers, distributions)) return;

      // Clone the root to get a scaffold to plug the substitutes into.
      IAtomContainer root = this.getRootStructure();
      IAtomContainer rootClone = null;
      try {
        rootClone = (IAtomContainer) root.clone();
      } catch (CloneNotSupportedException e) {
        // Abort with CDK exception
        throw new CDKException("clone() failed; could not perform R-group substitution.");
      }

      for (int rgpIdx = 0; rgpIdx < rGroupNumbers.size(); rgpIdx++) {

        int rNum = rGroupNumbers.get(rgpIdx);
        int pos = 0;

        List<RGroup> mapped = substitutes.get(rgpIdx);
        for (RGroup substitute : mapped) {
          IAtom rAtom = this.getRgroupQueryAtoms(rNum).get(pos);
          if (substitute != null) {

            IAtomContainer rgrpClone = null;
            try {
              rgrpClone = (IAtomContainer) (substitute.getGroup().clone());
            } catch (CloneNotSupportedException e) {
              throw new CDKException("clone() failed; could not perform R-group substitution.");
            }

            // root cloned, substitute cloned. These now need to be attached to each other..
            rootClone.add(rgrpClone);

            Map<Integer, IBond> rAttachmentPoints = this.getRootAttachmentPoints().get(rAtom);
            if (rAttachmentPoints != null) {
              // Loop over attachment points of the R# atom
              for (int apo = 0; apo < rAttachmentPoints.size(); apo++) {
                IBond bond = rAttachmentPoints.get(apo + 1);
                // Check how R# is attached to bond
                int whichAtomInBond = 0;
                if (bond.getAtom(1).equals(rAtom)) whichAtomInBond = 1;
                IAtom subsAt = null;
                if (apo == 0) subsAt = substitute.getFirstAttachmentPoint();
                else subsAt = substitute.getSecondAttachmentPoint();

                // Do substitution with the clones
                IBond cloneBond = rootClone.getBond(getBondPosition(bond, root));
                if (subsAt != null) {
                  IAtom subsCloneAtom =
                      rgrpClone.getAtom(getAtomPosition(subsAt, substitute.getGroup()));
                  cloneBond.setAtom(subsCloneAtom, whichAtomInBond);
                }
              }
            }

            // Optional: shift substitutes 2D for easier visual checking
            if (rAtom.getPoint2d() != null
                && substitute != null
                && substitute.getFirstAttachmentPoint() != null
                && substitute.getFirstAttachmentPoint().getPoint2d() != null) {
              Point2d pointR = rAtom.getPoint2d();
              Point2d pointC = substitute.getFirstAttachmentPoint().getPoint2d();
              double xDiff = pointC.x - pointR.x;
              double yDiff = pointC.y - pointR.y;
              for (IAtom subAt : rgrpClone.atoms()) {
                if (subAt.getPoint2d() != null) {
                  subAt.getPoint2d().x -= xDiff;
                  subAt.getPoint2d().y -= yDiff;
                }
              }
            }
          } else {
            // Distribution flag is 0, this means the R# group will not be substituted.
            // Any atom connected to this group should be given the defined RestH value.
            IAtom discarded = rootClone.getAtom(getAtomPosition(rAtom, root));
            for (IBond r0Bond : rootClone.bonds()) {
              if (r0Bond.contains(discarded)) {
                for (IAtom atInBond : r0Bond.atoms()) {
                  atInBond.setProperty(
                      CDKConstants.REST_H, this.getRGroupDefinitions().get(rNum).isRestH());
                }
              }
            }
          }

          pos++;
        }
      }

      // Remove R# remnants from the clone, bonds and atoms that may linger.
      boolean confHasRGroupBonds = true;
      while (confHasRGroupBonds) {
        for (IBond cloneBond : rootClone.bonds()) {
          boolean removeBond = false;
          if (cloneBond.getAtom(0) instanceof IPseudoAtom
              && isValidRgroupQueryLabel(((IPseudoAtom) cloneBond.getAtom(0)).getLabel()))
            removeBond = true;
          else if (cloneBond.getAtom(1) instanceof IPseudoAtom
              && isValidRgroupQueryLabel(((IPseudoAtom) cloneBond.getAtom(1)).getLabel()))
            removeBond = true;

          if (removeBond) {
            rootClone.removeBond(cloneBond);
            confHasRGroupBonds = true;
            break;
          }
          confHasRGroupBonds = false;
        }
      }
      boolean confHasRGroupAtoms = true;
      while (confHasRGroupAtoms) {
        for (IAtom cloneAt : rootClone.atoms()) {
          if (cloneAt instanceof IPseudoAtom)
            if (isValidRgroupQueryLabel(((IPseudoAtom) cloneAt).getLabel())) {
              rootClone.removeAtom(cloneAt);
              confHasRGroupAtoms = true;
              break;
            }
          confHasRGroupAtoms = false;
        }
      }
      // Add to result list
      result.add(rootClone);

    } else {
      for (int idx = 0; idx < occurrences.get(level).size(); idx++) {
        occurIndexes.set(level, idx);
        // With an occurrence picked 0..n for this level's R-group, now find
        // all possible distributions (positional alternatives).
        int occurrence = occurrences.get(level).get(idx);
        int positions = this.getRgroupQueryAtoms(rGroupNumbers.get(level)).size();
        Integer[] candidate = new Integer[positions];
        for (int j = 0; j < candidate.length; j++) {
          candidate[j] = 0;
        }
        List<Integer[]> rgrpDistributions = new ArrayList<Integer[]>();
        findDistributions(occurrence, candidate, rgrpDistributions, 0);

        for (Integer[] distribution : rgrpDistributions) {
          distributions.set(level, distribution);

          RGroup[] mapping = new RGroup[distribution.length];
          List<List<RGroup>> mappedSubstitutes = new ArrayList<List<RGroup>>();
          mapSubstitutes(
              this.getRGroupDefinitions().get(rGroupNumbers.get(level)),
              0,
              distribution,
              mapping,
              mappedSubstitutes);

          for (List<RGroup> mappings : mappedSubstitutes) {
            substitutes.set(level, mappings);
            findConfigurationsRecursively(
                rGroupNumbers,
                occurrences,
                occurIndexes,
                distributions,
                substitutes,
                level + 1,
                result);
          }
        }
      }
    }
  }
示例#29
0
  /**
   * Choose any possible quadruple of the set of atoms in ac and establish all of the possible
   * bonding schemes according to Faulon's equations.
   */
  public static List sample(IAtomContainer ac) {
    logger.debug("RandomGenerator->mutate() Start");
    List structures = new ArrayList();

    int nrOfAtoms = ac.getAtomCount();
    double a11 = 0, a12 = 0, a22 = 0, a21 = 0;
    double b11 = 0, lowerborder = 0, upperborder = 0;
    double b12 = 0;
    double b21 = 0;
    double b22 = 0;
    double[] cmax = new double[4];
    double[] cmin = new double[4];
    IAtomContainer newAc = null;

    IAtom ax1 = null, ax2 = null, ay1 = null, ay2 = null;
    IBond b1 = null, b2 = null, b3 = null, b4 = null;
    // int[] choices = new int[3];
    /* We need at least two non-zero bonds in order to be successful */
    int nonZeroBondsCounter = 0;
    for (int x1 = 0; x1 < nrOfAtoms; x1++) {
      for (int x2 = x1 + 1; x2 < nrOfAtoms; x2++) {
        for (int y1 = x2 + 1; y1 < nrOfAtoms; y1++) {
          for (int y2 = y1 + 1; y2 < nrOfAtoms; y2++) {
            nonZeroBondsCounter = 0;
            ax1 = ac.getAtom(x1);
            ay1 = ac.getAtom(y1);
            ax2 = ac.getAtom(x2);
            ay2 = ac.getAtom(y2);

            /* Get four bonds for these four atoms */

            b1 = ac.getBond(ax1, ay1);
            if (b1 != null) {
              a11 = BondManipulator.destroyBondOrder(b1.getOrder());
              nonZeroBondsCounter++;
            } else {
              a11 = 0;
            }

            b2 = ac.getBond(ax1, ay2);
            if (b2 != null) {
              a12 = BondManipulator.destroyBondOrder(b2.getOrder());
              nonZeroBondsCounter++;
            } else {
              a12 = 0;
            }

            b3 = ac.getBond(ax2, ay1);
            if (b3 != null) {
              a21 = BondManipulator.destroyBondOrder(b3.getOrder());
              nonZeroBondsCounter++;
            } else {
              a21 = 0;
            }

            b4 = ac.getBond(ax2, ay2);
            if (b4 != null) {
              a22 = BondManipulator.destroyBondOrder(b4.getOrder());
              nonZeroBondsCounter++;
            } else {
              a22 = 0;
            }
            if (nonZeroBondsCounter > 1) {
              /* Compute the range for b11 (see Faulons formulae for details) */

              cmax[0] = 0;
              cmax[1] = a11 - a22;
              cmax[2] = a11 + a12 - 3;
              cmax[3] = a11 + a21 - 3;
              cmin[0] = 3;
              cmin[1] = a11 + a12;
              cmin[2] = a11 + a21;
              cmin[3] = a11 - a22 + 3;
              lowerborder = MathTools.max(cmax);
              upperborder = MathTools.min(cmin);
              for (b11 = lowerborder; b11 <= upperborder; b11++) {
                if (b11 != a11) {

                  b12 = a11 + a12 - b11;
                  b21 = a11 + a21 - b11;
                  b22 = a22 - a11 + b11;
                  logger.debug("Trying atom combination : " + x1 + ":" + x2 + ":" + y1 + ":" + y2);
                  try {
                    newAc = (IAtomContainer) ac.clone();
                    change(newAc, x1, y1, x2, y2, b11, b12, b21, b22);
                    if (ConnectivityChecker.isConnected(newAc)) {
                      structures.add(newAc);
                    } else {
                      logger.debug("not connected");
                    }
                  } catch (CloneNotSupportedException e) {
                    logger.error("Cloning exception: " + e.getMessage());
                    logger.debug(e);
                  }
                }
              }
            }
          }
        }
      }
    }
    return structures;
  }
  /**
   * 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;
  }