Beispiel #1
0
  /**
   * Layout all rings in the given RingSet that are connected to a given Ring
   *
   * @param rs The RingSet to be searched for rings connected to Ring
   * @param ring The Ring for which all connected rings in RingSet are to be layed out.
   */
  void placeConnectedRings(IRingSet rs, IRing ring, int handleType, double bondLength) {
    IRingSet connectedRings = rs.getConnectedRings(ring);
    IRing connectedRing;
    IAtomContainer sharedAtoms;
    int sac;
    Point2d oldRingCenter, sharedAtomsCenter, tempPoint;
    Vector2d tempVector, oldRingCenterVector, newRingCenterVector;

    //		logger.debug(rs.reportRingList(molecule));
    for (IAtomContainer container : connectedRings.atomContainers()) {
      connectedRing = (IRing) container;
      if (!connectedRing.getFlag(CDKConstants.ISPLACED)) {
        //				logger.debug(ring.toString(molecule));
        //				logger.debug(connectedRing.toString(molecule));
        sharedAtoms = AtomContainerManipulator.getIntersection(ring, connectedRing);
        sac = sharedAtoms.getAtomCount();
        logger.debug("placeConnectedRings-> connectedRing: " + (ring.toString()));
        if ((sac == 2 && handleType == FUSED)
            || (sac == 1 && handleType == SPIRO)
            || (sac > 2 && handleType == BRIDGED)) {
          sharedAtomsCenter = GeometryTools.get2DCenter(sharedAtoms);
          oldRingCenter = GeometryTools.get2DCenter(ring);
          tempVector = (new Vector2d(sharedAtomsCenter));
          newRingCenterVector = new Vector2d(tempVector);
          newRingCenterVector.sub(new Vector2d(oldRingCenter));
          oldRingCenterVector = new Vector2d(newRingCenterVector);
          logger.debug(
              "placeConnectedRing -> tempVector: "
                  + tempVector
                  + ", tempVector.length: "
                  + tempVector.length());
          logger.debug("placeConnectedRing -> bondCenter: " + sharedAtomsCenter);
          logger.debug(
              "placeConnectedRing -> oldRingCenterVector.length(): "
                  + oldRingCenterVector.length());
          logger.debug(
              "placeConnectedRing -> newRingCenterVector.length(): "
                  + newRingCenterVector.length());
          tempPoint = new Point2d(sharedAtomsCenter);
          tempPoint.add(newRingCenterVector);
          placeRing(connectedRing, sharedAtoms, sharedAtomsCenter, newRingCenterVector, bondLength);
          connectedRing.setFlag(CDKConstants.ISPLACED, true);
          placeConnectedRings(rs, connectedRing, handleType, bondLength);
        }
      }
    }
  }
  /**
   * Fixes Aromaticity of the molecule i.e. need to find rings and aromaticity again since added H's
   *
   * @param mol
   */
  @TestMethod("testFixAromaticity")
  public static void configure(IAtomContainer mol) {
    // need to find rings and aromaticity again since added H's

    IRingSet ringSet = null;
    try {
      AllRingsFinder arf = new AllRingsFinder();
      ringSet = arf.findAllRings(mol);
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      // figure out which atoms are in aromatic rings:
      CDKHydrogenAdder cdk = CDKHydrogenAdder.getInstance(DefaultChemObjectBuilder.getInstance());
      cdk.addImplicitHydrogens(mol);
      ExtAtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);

      CDKHueckelAromaticityDetector.detectAromaticity(mol);
      // figure out which rings are aromatic:
      RingSetManipulator.markAromaticRings(ringSet);
      // figure out which simple (non cycles) rings are aromatic:

      // only atoms in 6 membered rings are aromatic
      // determine largest ring that each atom is a part of

      for (int i = 0; i < mol.getAtomCount(); i++) {
        mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, false);
        jloop:
        for (int j = 0; j < ringSet.getAtomContainerCount(); j++) {
          // logger.debug(i+"\t"+j);
          IRing ring = (IRing) ringSet.getAtomContainer(j);
          if (!ring.getFlag(CDKConstants.ISAROMATIC)) {
            continue jloop;
          }
          boolean haveatom = ring.contains(mol.getAtom(i));
          // logger.debug("haveatom="+haveatom);
          if (haveatom && ring.getAtomCount() == 6) {
            mol.getAtom(i).setFlag(CDKConstants.ISAROMATIC, true);
          }
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }