Exemplo n.º 1
0
  /**
   * calculates the kier shape indices for an atom container
   *
   * @param container AtomContainer
   * @return kier1, kier2 and kier3 are returned as arrayList of doubles
   * @throws CDKException Possible Exceptions
   */
  @Override
  public DescriptorValue calculate(IAtomContainer container) {
    IAtomContainer atomContainer;
    try {
      atomContainer = (IAtomContainer) container.clone();
    } catch (CloneNotSupportedException e) {
      DoubleArrayResult kierValues = new DoubleArrayResult(3);
      kierValues.add(Double.NaN);
      kierValues.add(Double.NaN);
      kierValues.add(Double.NaN);
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          kierValues,
          getDescriptorNames());
    }
    atomContainer = AtomContainerManipulator.removeHydrogens(atomContainer);

    // org.openscience.cdk.interfaces.IAtom[] atoms = atomContainer.getAtoms();
    java.util.List firstAtomNeighboors;
    java.util.List secondAtomNeighboors;
    java.util.List thirdAtomNeighboors;
    DoubleArrayResult kierValues = new DoubleArrayResult(3);
    double bond1;
    double bond2;
    double bond3;
    double kier1;
    double kier2;
    double kier3;
    double atomsCount = atomContainer.getAtomCount();
    ArrayList<Double> singlePaths = new ArrayList<Double>();
    ArrayList<String> doublePaths = new ArrayList<String>();
    ArrayList<String> triplePaths = new ArrayList<String>();
    double[] sorterFirst = new double[2];
    double[] sorterSecond = new double[3];
    String tmpbond2;
    String tmpbond3;

    for (int a1 = 0; a1 < atomsCount; a1++) {
      bond1 = 0;
      firstAtomNeighboors = atomContainer.getConnectedAtomsList(atomContainer.getAtom(a1));
      for (int a2 = 0; a2 < firstAtomNeighboors.size(); a2++) {
        bond1 =
            atomContainer.getBondNumber(
                atomContainer.getAtom(a1), (IAtom) firstAtomNeighboors.get(a2));
        if (!singlePaths.contains(new Double(bond1))) {
          singlePaths.add(bond1);
          java.util.Collections.sort(singlePaths);
        }
        secondAtomNeighboors =
            atomContainer.getConnectedAtomsList((IAtom) firstAtomNeighboors.get(a2));
        for (int a3 = 0; a3 < secondAtomNeighboors.size(); a3++) {
          bond2 =
              atomContainer.getBondNumber(
                  (IAtom) firstAtomNeighboors.get(a2), (IAtom) secondAtomNeighboors.get(a3));
          if (!singlePaths.contains(new Double(bond2))) {
            singlePaths.add(bond2);
          }
          sorterFirst[0] = bond1;
          sorterFirst[1] = bond2;
          java.util.Arrays.sort(sorterFirst);

          tmpbond2 = sorterFirst[0] + "+" + sorterFirst[1];

          if (!doublePaths.contains(tmpbond2) && (bond1 != bond2)) {
            doublePaths.add(tmpbond2);
          }
          thirdAtomNeighboors =
              atomContainer.getConnectedAtomsList((IAtom) secondAtomNeighboors.get(a3));
          for (int a4 = 0; a4 < thirdAtomNeighboors.size(); a4++) {
            bond3 =
                atomContainer.getBondNumber(
                    (IAtom) secondAtomNeighboors.get(a3), (IAtom) thirdAtomNeighboors.get(a4));
            if (!singlePaths.contains(new Double(bond3))) {
              singlePaths.add(bond3);
            }
            sorterSecond[0] = bond1;
            sorterSecond[1] = bond2;
            sorterSecond[2] = bond3;
            java.util.Arrays.sort(sorterSecond);

            tmpbond3 = sorterSecond[0] + "+" + sorterSecond[1] + "+" + sorterSecond[2];
            if (!triplePaths.contains(tmpbond3)) {
              if ((bond1 != bond2) && (bond1 != bond3) && (bond2 != bond3)) {
                triplePaths.add(tmpbond3);
              }
            }
          }
        }
      }
    }

    if (atomsCount == 1) {
      kier1 = 0;
      kier2 = 0;
      kier3 = 0;
    } else {
      kier1 =
          (((atomsCount) * ((atomsCount - 1) * (atomsCount - 1)))
              / (singlePaths.size() * singlePaths.size()));
      if (atomsCount == 2) {
        kier2 = 0;
        kier3 = 0;
      } else {
        if (doublePaths.size() == 0) kier2 = Double.NaN;
        else
          kier2 =
              (((atomsCount - 1) * ((atomsCount - 2) * (atomsCount - 2)))
                  / (doublePaths.size() * doublePaths.size()));
        if (atomsCount == 3) {
          kier3 = 0;
        } else {
          if (atomsCount % 2 != 0) {
            if (triplePaths.size() == 0) kier3 = Double.NaN;
            else
              kier3 =
                  (((atomsCount - 1) * ((atomsCount - 3) * (atomsCount - 3)))
                      / (triplePaths.size() * triplePaths.size()));
          } else {
            if (triplePaths.size() == 0) kier3 = Double.NaN;
            else
              kier3 =
                  (((atomsCount - 3) * ((atomsCount - 2) * (atomsCount - 2)))
                      / (triplePaths.size() * triplePaths.size()));
          }
        }
      }
    }

    kierValues.add(kier1);
    kierValues.add(kier2);
    kierValues.add(kier3);
    return new DescriptorValue(
        getSpecification(), getParameterNames(), getParameters(), kierValues, getDescriptorNames());
  }
  /**
   * 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;
  }
Exemplo n.º 3
0
 /**
  * This makes sourceAtom map1 of matching atoms out of sourceAtom map1 of matching bonds as
  * produced by the get(Subgraph|Ismorphism)Map methods.
  *
  * @param rMapList The list produced by the getMap method.
  * @param graph1 first molecule. Must not be an IQueryAtomContainer.
  * @param graph2 second molecule. May be an IQueryAtomContainer.
  * @return The mapping found projected on graph1. This is sourceAtom List of CDKRMap objects
  *     containing Ids of matching atoms.
  */
 private synchronized List<List<CDKRMap>> makeAtomsMapOfBondsMap(
     List<CDKRMap> rMapList, IAtomContainer graph1, IAtomContainer graph2) {
   if (rMapList == null) {
     return (null);
   }
   List<List<CDKRMap>> result;
   if (rMapList.size() == 1) {
     result = makeAtomsMapOfBondsMapSingleBond(rMapList, graph1, graph2);
   } else {
     List<CDKRMap> resultLocal = new ArrayList<CDKRMap>();
     for (CDKRMap rMapList2 : rMapList) {
       IBond qBond = graph1.getBond(rMapList2.getId1());
       IBond tBond = graph2.getBond(rMapList2.getId2());
       IAtom[] qAtoms = BondManipulator.getAtomArray(qBond);
       IAtom[] tAtoms = BondManipulator.getAtomArray(tBond);
       for (int j = 0; j < 2; j++) {
         List<IBond> bondsConnectedToAtom1j = graph1.getConnectedBondsList(qAtoms[j]);
         for (IBond bondsConnectedToAtom1j1 : bondsConnectedToAtom1j) {
           if (bondsConnectedToAtom1j1 != qBond) {
             IBond testBond = bondsConnectedToAtom1j1;
             for (CDKRMap rMapList1 : rMapList) {
               IBond testBond2;
               if ((rMapList1).getId1() == graph1.getBondNumber(testBond)) {
                 testBond2 = graph2.getBond((rMapList1).getId2());
                 for (int n = 0; n < 2; n++) {
                   List<IBond> bondsToTest = graph2.getConnectedBondsList(tAtoms[n]);
                   if (bondsToTest.contains(testBond2)) {
                     CDKRMap map1;
                     if (j == n) {
                       map1 =
                           new CDKRMap(
                               graph1.getAtomNumber(qAtoms[0]), graph2.getAtomNumber(tAtoms[0]));
                     } else {
                       map1 =
                           new CDKRMap(
                               graph1.getAtomNumber(qAtoms[1]), graph2.getAtomNumber(tAtoms[0]));
                     }
                     if (!resultLocal.contains(map1)) {
                       resultLocal.add(map1);
                     }
                     CDKRMap map2;
                     if (j == n) {
                       map2 =
                           new CDKRMap(
                               graph1.getAtomNumber(qAtoms[1]), graph2.getAtomNumber(tAtoms[1]));
                     } else {
                       map2 =
                           new CDKRMap(
                               graph1.getAtomNumber(qAtoms[0]), graph2.getAtomNumber(tAtoms[1]));
                     }
                     if (!resultLocal.contains(map2)) {
                       resultLocal.add(map2);
                     }
                   }
                 }
               }
             }
           }
         }
       }
     }
     result = new ArrayList<>();
     result.add(resultLocal);
   }
   return result;
 }