Beispiel #1
0
 /**
  * Selects an optimum edge for elimination in structures without N2 nodes.
  *
  * <p>This might be severely broken! Would have helped if there was an explanation of how this
  * algorithm worked.
  *
  * @param ring
  * @param molecule
  */
 private IBond checkEdges(IRing ring, IAtomContainer molecule) {
   IRing r1, r2;
   IRingSet ringSet = ring.getBuilder().newInstance(IRingSet.class);
   IBond bond;
   int minMaxSize = Integer.MAX_VALUE;
   int minMax = 0;
   logger.debug("Molecule: " + molecule);
   Iterator<IBond> bonds = ring.bonds().iterator();
   while (bonds.hasNext()) {
     bond = (IBond) bonds.next();
     molecule.removeElectronContainer(bond);
     r1 = getRing(bond.getAtom(0), molecule);
     r2 = getRing(bond.getAtom(1), molecule);
     logger.debug("checkEdges: " + bond);
     if (r1.getAtomCount() > r2.getAtomCount()) {
       ringSet.addAtomContainer(r1);
     } else {
       ringSet.addAtomContainer(r2);
     }
     molecule.addBond(bond);
   }
   for (int i = 0; i < ringSet.getAtomContainerCount(); i++) {
     if (((IRing) ringSet.getAtomContainer(i)).getBondCount() < minMaxSize) {
       minMaxSize = ((IRing) ringSet.getAtomContainer(i)).getBondCount();
       minMax = i;
     }
   }
   return (IBond) ring.getElectronContainer(minMax);
 }
Beispiel #2
0
 /**
  * Performs a breadthFirstSearch in an AtomContainer starting with a particular sphere, which
  * usually consists of one start atom, and searches for a pi system.
  *
  * @param container The AtomContainer to be searched
  * @param sphere A sphere of atoms to start the search with
  * @param path A ArrayList which stores the atoms belonging to the pi system
  * @throws org.openscience.cdk.exception.CDKException Description of the Exception
  */
 private void breadthFirstSearch(IAtomContainer container, List<IAtom> sphere, List<IAtom> path)
     throws CDKException {
   IAtom atom;
   IAtom nextAtom;
   List<IAtom> newSphere = new ArrayList<IAtom>();
   // logger.debug("Start of breadthFirstSearch");
   for (int i = 0; i < sphere.size(); i++) {
     atom = sphere.get(i);
     // logger.debug("BreadthFirstSearch around atom " + (atomNr + 1));
     List<IBond> bonds = container.getConnectedBondsList(atom);
     for (IBond bond : bonds) {
       nextAtom = bond.getConnectedAtom(atom);
       if ((!nextAtom.getFlag(CDKConstants.ISAROMATIC) && !nextAtom.getFlag(CDKConstants.ISINRING))
           & !nextAtom.getFlag(CDKConstants.VISITED)) {
         // logger.debug("BDS> AtomNr:"+container.getAtomNumber(nextAtom)+"
         // maxBondOrder:"+container.getMaximumBondOrder(nextAtom)+"
         // Aromatic:"+nextAtom.getFlag(CDKConstants.ISAROMATIC)+"
         // FormalCharge:"+nextAtom.getFormalCharge()+" Charge:"+nextAtom.getCharge()+"
         // Flag:"+nextAtom.getFlag(CDKConstants.VISITED));
         path.add(nextAtom);
         // logger.debug("BreadthFirstSearch is meeting new atom " + (nextAtomNr + 1));
         nextAtom.setFlag(CDKConstants.VISITED, true);
         if (container.getConnectedBondsCount(nextAtom) > 1) {
           newSphere.add(nextAtom);
         }
       } else {
         nextAtom.setFlag(CDKConstants.VISITED, true);
       }
     }
   }
   if (newSphere.size() > 0) {
     breadthFirstSearch(container, newSphere, path);
   }
 }
Beispiel #3
0
 /**
  * Sets the array of bonds of this AtomContainer.
  *
  * @param bonds The array of bonds to be assigned to this AtomContainer
  * @see #getBond
  */
 public void setBonds(IBond[] bonds) {
   this.bonds = bonds;
   for (IBond bond : bonds) {
     bond.addListener(this);
   }
   this.bondCount = bonds.length;
 }
  private static Map<SgroupBracket, IBond> bracketBondPairs(
      Collection<SgroupBracket> brackets, Collection<IBond> bonds) {
    Map<SgroupBracket, IBond> pairs = new HashMap<>();

    for (SgroupBracket bracket : brackets) {
      IBond crossingBond = null;
      for (IBond bond : bonds) {
        IAtom a1 = bond.getAtom(0);
        IAtom a2 = bond.getAtom(1);
        if (Line2D.linesIntersect(
            bracket.getFirstPoint().x, bracket.getFirstPoint().y,
            bracket.getSecondPoint().x, bracket.getSecondPoint().y,
            a1.getPoint2d().x, a1.getPoint2d().y,
            a2.getPoint2d().x, a2.getPoint2d().y)) {
          // more than one... not good
          if (crossingBond != null) return new HashMap<>();
          crossingBond = bond;
        }
      }
      if (crossingBond == null) return new HashMap<>();
      pairs.put(bracket, crossingBond);
    }

    return pairs;
  }
  /** Converts a Bond to a MSML Bond element */
  protected BondType convertBond(IBond bond, String parentID, ArrayList<String> hashes) {
    BondType bondElement = new BondType();
    String bondID = parentID + PREFIX_BOND + bond.hashCode();
    bondElement.setId(bondID);
    int atom1 = hashes.indexOf(Integer.toString(bond.getAtom(0).hashCode())) + 1;
    int atom2 = hashes.indexOf(Integer.toString(bond.getAtom(1).hashCode())) + 1;
    // bondElement.setCustomId("" + bond.getID());
    // atom name
    // bondElement.setTitle(bond.getID());
    /*
     * System.out.println(bond.getAtom(0).getSymbol()); System.out.println(bond.getAtom(1).getSymbol());
     */

    String a1 = "a" + atom1;
    String a2 = "a" + atom2;
    List<String> atomrefs = bondElement.getAtomRefs2();
    atomrefs.add(a1); // add first atom in bond
    atomrefs.add(a2); // add second atom in bond
    if (bond.getOrder() != null) {
      bondElement.setOrder(bond.getOrder().toString());
    }
    /*
     * if (bond.getStereo() != null){ bondElement.setStereo(bond.getStereo().toString()); //no stereo property as of
     * now }
     */

    return bondElement;
  }
  /**
   * Hide the atoms and bonds of a contracted abbreviation. If the abbreviations is attached we
   * remap the attachment symbol to display the name. If there are no attachments the symbol we be
   * added later ({@see #generateSgroups}).
   *
   * @param container molecule
   * @param sgroup abbreviation group display shortcut
   */
  private static void contractAbbreviation(
      IAtomContainer container, Map<IAtom, String> symbolRemap, Sgroup sgroup) {

    final Set<IBond> crossing = sgroup.getBonds();
    final Set<IAtom> atoms = sgroup.getAtoms();

    // only do 0,1 attachments for now
    if (crossing.size() > 1) return;

    for (IAtom atom : atoms) {
      StandardGenerator.hide(atom);
    }
    for (IBond bond : container.bonds()) {
      if (atoms.contains(bond.getAtom(0)) || atoms.contains(bond.getAtom(1)))
        StandardGenerator.hide(bond);
    }
    for (IBond bond : crossing) {
      StandardGenerator.unhide(bond);
      IAtom a1 = bond.getAtom(0);
      IAtom a2 = bond.getAtom(1);
      StandardGenerator.unhide(a1);
      if (atoms.contains(a1)) symbolRemap.put(a1, sgroup.getSubscript());
      StandardGenerator.unhide(a2);
      if (atoms.contains(a2)) symbolRemap.put(a2, sgroup.getSubscript());
    }
  }
Beispiel #7
0
  /**
   * Place ring with user provided angles.
   *
   * @param ring the ring to place.
   * @param ringCenter center coordinates of the ring.
   * @param bondLength given bond length.
   * @param startAngles a map with start angles when drawing the ring.
   */
  public void placeRing(
      IRing ring, Point2d ringCenter, double bondLength, Map<Integer, Double> startAngles) {
    double radius = this.getNativeRingRadius(ring, bondLength);
    double addAngle = 2 * Math.PI / ring.getRingSize();

    IAtom startAtom = ring.getFirstAtom();
    Point2d p = new Point2d(ringCenter.x + radius, ringCenter.y);
    startAtom.setPoint2d(p);
    double startAngle = Math.PI * 0.5;

    /* Different ring sizes get different start angles to have
     * visually correct placement */
    int ringSize = ring.getRingSize();
    if (startAngles.get(ringSize) != null) startAngle = startAngles.get(ringSize);

    List<IBond> bonds = ring.getConnectedBondsList(startAtom);
    /*
     * Store all atoms to draw in consecutive order relative to the
     * chosen bond.
     */
    Vector<IAtom> atomsToDraw = new Vector<IAtom>();
    IAtom currentAtom = startAtom;
    IBond currentBond = (IBond) bonds.get(0);
    for (int i = 0; i < ring.getBondCount(); i++) {
      currentBond = ring.getNextBond(currentBond, currentAtom);
      currentAtom = currentBond.getConnectedAtom(currentAtom);
      atomsToDraw.addElement(currentAtom);
    }
    atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius);
  }
  /**
   * Fill the {@literal coordinates} and {@literal elevation} from the given offset index. If there
   * is only one connection then the second entry (from the offset) will use the coordinates of
   * <i>a</i>. The permutation parity is also built and returned.
   *
   * @param container atom container
   * @param a the central atom
   * @param connected bonds connected to the central atom
   * @param coordinates the coordinates array to fill
   * @param elevations the elevations of the connected atoms
   * @param offset current location in the offset array
   * @return the permutation parity
   */
  private static PermutationParity fill2DCoordinates(
      IAtomContainer container,
      IAtom a,
      List<IBond> connected,
      Point2d[] coordinates,
      int[] elevations,
      int offset) {

    int i = 0;
    coordinates[offset + 1] = a.getPoint2d();
    elevations[offset + 1] = 0;
    int[] indices = new int[2];

    for (IBond bond : connected) {
      if (!isDoubleBond(bond)) {
        IAtom other = bond.getConnectedAtom(a);
        coordinates[i + offset] = other.getPoint2d();
        elevations[i + offset] = elevation(bond, a);
        indices[i] = container.getAtomNumber(other);
        i++;
      }
    }

    if (i == 1) {
      return PermutationParity.IDENTITY;
    } else {
      return new BasicPermutationParity(indices);
    }
  }
 /**
  * Procedure required by the CDOInterface. This function is only supposed to be called by the JCFL
  * library
  */
 public void endObject(String objectType) {
   logger.debug("END: " + objectType);
   if (objectType.equals("Molecule")) {
     eventReader.fireFrameRead();
     clearData();
   } else if (objectType.equals("Atom")) {
     currentMolecule.addAtom(currentAtom);
   } else if (objectType.equals("Bond")) {
     logger.debug("Bond(" + bond_id + "): " + bond_a1 + ", " + bond_a2 + ", " + bond_order);
     if (bond_a1 > currentMolecule.getAtomCount() || bond_a2 > currentMolecule.getAtomCount()) {
       logger.error(
           "Cannot add bond between at least one non-existant atom: "
               + bond_a1
               + " and "
               + bond_a2);
     } else {
       IAtom a1 = currentMolecule.getAtom(bond_a1);
       IAtom a2 = currentMolecule.getAtom(bond_a2);
       IBond b = builder.newBond(a1, a2, bond_order);
       if (bond_id != null) b.setID(bond_id);
       if (bond_stereo != -99) {
         b.setStereo(bond_stereo);
       }
       currentMolecule.addBond(b);
     }
   }
 }
 /**
  * Check if all atoms in the bond list have 3D coordinates. There is some redundant checking but
  * the list will typically be short.
  *
  * @param bonds the bonds to check
  * @return whether all atoms have 2D coordinates
  */
 private static boolean has3DCoordinates(List<IBond> bonds) {
   for (IBond bond : bonds) {
     if (bond.getAtom(0).getPoint3d() == null || bond.getAtom(1).getPoint3d() == null)
       return false;
   }
   return true;
 }
  /**
   * Initiate process. It is needed to call the addExplicitHydrogensToSatisfyValency from the class
   * tools.HydrogenAdder.
   *
   * @param reactants reactants of the reaction
   * @param agents agents of the reaction (Must be in this case null)
   * @exception CDKException Description of the Exception
   */
  @TestMethod("testInitiate_IMoleculeSet_IMoleculeSet")
  public IReactionSet initiate(IMoleculeSet reactants, IMoleculeSet agents) throws CDKException {

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

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

    IReactionSet setOfReactions =
        DefaultChemObjectBuilder.getInstance().newInstance(IReactionSet.class);
    IMolecule reactant = reactants.getMolecule(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<IBond> bondis = reactant.bonds().iterator();
    while (bondis.hasNext()) {
      IBond bondi = bondis.next();
      IAtom atom1 = bondi.getAtom(0);
      IAtom atom2 = bondi.getAtom(1);
      if (bondi.getFlag(CDKConstants.REACTIVE_CENTER)
          && bondi.getOrder() != IBond.Order.SINGLE
          && atom1.getFlag(CDKConstants.REACTIVE_CENTER)
          && atom2.getFlag(CDKConstants.REACTIVE_CENTER)
          && (atom1.getFormalCharge() == CDKConstants.UNSET ? 0 : atom1.getFormalCharge()) == 0
          && (atom2.getFormalCharge() == CDKConstants.UNSET ? 0 : atom2.getFormalCharge()) == 0
          && reactant.getConnectedSingleElectronsCount(atom1) == 0
          && reactant.getConnectedSingleElectronsCount(atom2) == 0) {

        /**/
        for (int j = 0; j < 2; j++) {

          ArrayList<IAtom> atomList = new ArrayList<IAtom>();
          if (j == 0) {
            atomList.add(atom1);
            atomList.add(atom2);
          } else {
            atomList.add(atom2);
            atomList.add(atom1);
          }
          ArrayList<IBond> bondList = new ArrayList<IBond>();
          bondList.add(bondi);

          IMoleculeSet moleculeSet = reactant.getBuilder().newInstance(IMoleculeSet.class);
          moleculeSet.addMolecule(reactant);
          IReaction reaction = mechanism.initiate(moleculeSet, atomList, bondList);
          if (reaction == null) continue;
          else setOfReactions.addReaction(reaction);
        }
      }
    }
    return setOfReactions;
  }
Beispiel #12
0
 @Test
 public void testAnyOrder() {
   AnyOrderQueryBond matcher = new AnyOrderQueryBond(mock(IChemObjectBuilder.class));
   IBond testBond = new Bond();
   for (IBond.Order order : IBond.Order.values()) {
     testBond.setOrder(order);
     Assert.assertTrue(matcher.matches(testBond));
   }
 }
Beispiel #13
0
 @Override
 public int seed(IAtomContainer molecule, IAtom atom, BitSet mask) {
   double sum = 0;
   for (IBond bond : molecule.getConnectedBondsList(atom)) {
     if (mask.get(molecule.getAtomNumber(bond.getConnectedAtom(atom))))
       sum += order(bond.getOrder());
   }
   return ((Double) sum).hashCode();
 }
Beispiel #14
0
 private int getAttachedMultipleBondCount(IAtom atom, IAtomContainer atomContainer) {
   int count = 0;
   for (IBond bond : atomContainer.getConnectedBondsList(atom)) {
     if (bond.getOrder() == IBond.Order.SINGLE) {
       continue;
     }
     ++count;
   }
   return count;
 }
Beispiel #15
0
 /**
  * Eliminates one bond of this atom from the molecule
  *
  * @param atom The atom one bond is eliminated of
  * @param molecule The molecule that contains the atom
  */
 private void breakBond(IAtom atom, IAtomContainer molecule) {
   Iterator<IBond> bonds = molecule.bonds().iterator();
   while (bonds.hasNext()) {
     IBond bond = (IBond) bonds.next();
     if (bond.contains(atom)) {
       molecule.removeElectronContainer(bond);
       break;
     }
   }
 }
Beispiel #16
0
 /**
  * Removes the bond at the given position from the AtomContainer.
  *
  * @param position The position of the bond to be removed.
  */
 public IBond removeBond(int position) {
   IBond bond = bonds[position];
   bond.removeListener(this);
   for (int i = position; i < bondCount - 1; i++) {
     bonds[i] = bonds[i + 1];
   }
   bonds[bondCount - 1] = null;
   bondCount--;
   notifyChanged();
   return bond;
 }
  @Test
  public void testBondStereo() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'><bondStereo dictRef='cml:H'/></bond></bondArray></molecule>";
    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(2, mol.getAtomCount());
    Assert.assertEquals(1, mol.getBondCount());
    IBond bond = mol.getBond(0);
    Assert.assertEquals(IBond.Stereo.DOWN, bond.getStereo());
  }
Beispiel #18
0
 private double medianBondLength(Collection<IBond> bonds) {
   if (bonds.isEmpty()) return 1.5;
   int nBonds = 0;
   double[] lengths = new double[bonds.size()];
   for (IBond bond : bonds) {
     Point2d p1 = bond.getAtom(0).getPoint2d();
     Point2d p2 = bond.getAtom(1).getPoint2d();
     // watch out for overlaid atoms (occur in multiple group Sgroups)
     if (!p1.equals(p2)) lengths[nBonds++] = p1.distance(p2);
   }
   Arrays.sort(lengths, 0, nBonds);
   return lengths[nBonds / 2];
 }
  @Test
  public void testBondAromatic2() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray><bond atomRefs='a1 a2' order='2'><bondType dictRef='cdk:aromaticBond'/></bond></bondArray></molecule>";
    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(2, mol.getAtomCount());
    Assert.assertEquals(1, mol.getBondCount());
    org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);
    Assert.assertEquals(CDKConstants.BONDORDER_DOUBLE, bond.getOrder());
    Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC));
  }
Beispiel #20
0
 @SuppressWarnings("unchecked")
 @Test
 public void aromaticBond() throws Exception {
   IAtom u = mock(IAtom.class);
   IAtom v = mock(IAtom.class);
   IBond b = new Bond(u, v);
   b.setFlag(CDKConstants.ISAROMATIC, true);
   Map<IAtom, Integer> mock = mock(Map.class);
   when(mock.get(u)).thenReturn(0);
   when(mock.get(v)).thenReturn(1);
   CDKToBeam c2g = new CDKToBeam();
   assertThat(c2g.toBeamEdge(b, mock), is(uk.ac.ebi.beam.Bond.AROMATIC.edge(0, 1)));
 }
  @Test
  public void testBondId() throws Exception {
    String cmlString =
        "<molecule id='m1'><atomArray><atom id='a1'/><atom id='a2'/></atomArray><bondArray><bond id='b1' atomRefs2='a1 a2'/></bondArray></molecule>";

    IChemFile chemFile = parseCMLString(cmlString);
    IMolecule mol = checkForSingleMoleculeFile(chemFile);

    Assert.assertEquals(2, mol.getAtomCount());
    Assert.assertEquals(1, mol.getBondCount());
    org.openscience.cdk.interfaces.IBond bond = mol.getBond(0);
    Assert.assertEquals("b1", bond.getID());
  }
 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
   }
 }
Beispiel #23
0
  /**
   * Internal - makes a map of the highlights for reaction mapping.
   *
   * @param reactants reaction reactants
   * @param products reaction products
   * @return the highlight map
   */
  private Map<IChemObject, Color> makeHighlightAtomMap(
      List<IAtomContainer> reactants, List<IAtomContainer> products) {
    Map<IChemObject, Color> colorMap = new HashMap<>();
    Map<Integer, Color> mapToColor = new HashMap<>();
    int colorIdx = -1;
    for (IAtomContainer mol : reactants) {
      int prevPalletIdx = colorIdx;
      for (IAtom atom : mol.atoms()) {
        int mapidx = accessAtomMap(atom);
        if (mapidx > 0) {
          if (prevPalletIdx == colorIdx) {
            colorIdx++; // select next color
            if (colorIdx >= atomMapColors.length)
              throw new IllegalArgumentException(
                  "Not enough colors to highlight atom mapping, please provide mode");
          }
          Color color = atomMapColors[colorIdx];
          colorMap.put(atom, color);
          mapToColor.put(mapidx, color);
        }
      }
      if (colorIdx > prevPalletIdx) {
        for (IBond bond : mol.bonds()) {
          IAtom a1 = bond.getAtom(0);
          IAtom a2 = bond.getAtom(1);
          Color c1 = colorMap.get(a1);
          Color c2 = colorMap.get(a2);
          if (c1 != null && c1 == c2) colorMap.put(bond, c1);
        }
      }
    }

    for (IAtomContainer mol : products) {
      for (IAtom atom : mol.atoms()) {
        int mapidx = accessAtomMap(atom);
        if (mapidx > 0) {
          colorMap.put(atom, mapToColor.get(mapidx));
        }
      }
      for (IBond bond : mol.bonds()) {
        IAtom a1 = bond.getAtom(0);
        IAtom a2 = bond.getAtom(1);
        Color c1 = colorMap.get(a1);
        Color c2 = colorMap.get(a2);
        if (c1 != null && c1 == c2) colorMap.put(bond, c1);
      }
    }

    return colorMap;
  }
Beispiel #24
0
  /**
   * Generated coordinates for a given ring, which is connected to a spiro ring. The rings share
   * exactly one atom.
   *
   * @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 placeSpiroRing(
      IRing ring,
      IAtomContainer sharedAtoms,
      Point2d sharedAtomsCenter,
      Vector2d ringCenterVector,
      double bondLength) {

    logger.debug("placeSpiroRing");
    double radius = getNativeRingRadius(ring, bondLength);
    Point2d ringCenter = new Point2d(sharedAtomsCenter);
    ringCenterVector.normalize();
    ringCenterVector.scale(radius);
    ringCenter.add(ringCenterVector);
    double addAngle = 2 * Math.PI / ring.getRingSize();

    IAtom startAtom = sharedAtoms.getAtom(0);

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

    // int direction = 1;

    IAtom currentAtom = startAtom;
    double startAngle =
        GeometryTools.getAngle(
            startAtom.getPoint2d().x - ringCenter.x, startAtom.getPoint2d().y - ringCenter.y);
    /*
     * Get one bond connected to the spiro bridge atom.
     * It doesn't matter in which direction we draw.
     */
    java.util.List bonds = ring.getConnectedBondsList(startAtom);

    IBond currentBond = (IBond) bonds.get(0);

    Vector atomsToDraw = new Vector();
    /*
     * Store all atoms to draw in consequtive order relative to the
     * chosen bond.
     */
    for (int i = 0; i < ring.getBondCount(); i++) {
      currentBond = ring.getNextBond(currentBond, currentAtom);
      currentAtom = currentBond.getConnectedAtom(currentAtom);
      atomsToDraw.addElement(currentAtom);
    }
    logger.debug("currentAtom  " + currentAtom);
    logger.debug("startAtom  " + startAtom);

    atomPlacer.populatePolygonCorners(atomsToDraw, ringCenter, startAngle, addAngle, radius);
  }
 private boolean getIfACarbonIsDoubleBondedToAnOxygen(Molecule mol, IAtom carbonAtom) {
   boolean isDoubleBondedToOxygen = false;
   List<IAtom> neighToCarbon = mol.getConnectedAtomsList(carbonAtom);
   IBond tmpBond;
   int counter = 0;
   for (int nei = 0; nei < neighToCarbon.size(); nei++) {
     IAtom neighbour = neighToCarbon.get(nei);
     if (neighbour.getSymbol().equals("O")) {
       tmpBond = mol.getBond(neighbour, carbonAtom);
       if (tmpBond.getOrder() == IBond.Order.DOUBLE) counter += 1;
     }
   }
   if (counter > 0) isDoubleBondedToOxygen = true;
   return isDoubleBondedToOxygen;
 }
 private boolean getIfBondIsNotRotatable(Molecule mol, IBond bond, IAtomContainer detected) {
   boolean isBondNotRotatable = false;
   int counter = 0;
   IAtom atom0 = bond.getAtom(0);
   IAtom atom1 = bond.getAtom(1);
   if (detected != null) {
     if (detected.contains(bond)) counter += 1;
   }
   if (atom0.getFlag(CDKConstants.ISINRING)) {
     if (atom1.getFlag(CDKConstants.ISINRING)) {
       counter += 1;
     } else {
       if (atom1.getSymbol().equals("H")) counter += 1;
       else counter += 0;
     }
   }
   if (atom0.getSymbol().equals("N") && atom1.getSymbol().equals("C")) {
     if (getIfACarbonIsDoubleBondedToAnOxygen(mol, atom1)) counter += 1;
   }
   if (atom0.getSymbol().equals("C") && atom1.getSymbol().equals("N")) {
     if (getIfACarbonIsDoubleBondedToAnOxygen(mol, atom0)) counter += 1;
   }
   if (counter > 0) isBondNotRotatable = true;
   return isBondNotRotatable;
 }
 // given a double bond
 // this method returns a bond bonded to this double bond
 private int getNearestBondtoAGivenAtom(Molecule mol, IAtom atom, IBond bond) {
   int nearestBond = 0;
   double[] values;
   double distance = 0;
   IAtom atom0 = bond.getAtom(0);
   List<IBond> bondsAtLeft = mol.getConnectedBondsList(atom0);
   int partial;
   for (int i = 0; i < bondsAtLeft.size(); i++) {
     IBond curBond = bondsAtLeft.get(i);
     values = calculateDistanceBetweenAtomAndBond(atom, curBond);
     partial = mol.getBondNumber(curBond);
     if (i == 0) {
       nearestBond = mol.getBondNumber(curBond);
       distance = values[0];
     } else {
       if (values[0] < distance) {
         nearestBond = partial;
       }
       /* XXX commented this out, because is has no effect
        *
        else {
           nearestBond = nearestBond;
       }*/
     }
   }
   return nearestBond;
 }
Beispiel #28
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;
 }
 /**
  * set the active center for this molecule. The active center will be those which correspond with
  * A-B. If the bond is simple, it will be broken forming two fragments
  *
  * <pre>
  * A: Atom
  * #/=/-: bond
  * B: Atom
  *  </pre>
  *
  * @param reactant The molecule to set the activity
  * @throws CDKException
  */
 private void setActiveCenters(IMolecule reactant) throws CDKException {
   Iterator<IBond> bonds = reactant.bonds().iterator();
   while (bonds.hasNext()) {
     IBond bond = bonds.next();
     IAtom atom1 = bond.getAtom(0);
     IAtom atom2 = bond.getAtom(1);
     if (bond.getOrder() != IBond.Order.SINGLE
         && (atom1.getFormalCharge() == CDKConstants.UNSET ? 0 : atom1.getFormalCharge()) == 0
         && (atom2.getFormalCharge() == CDKConstants.UNSET ? 0 : atom2.getFormalCharge()) == 0
         && reactant.getConnectedSingleElectronsCount(atom1) == 0
         && reactant.getConnectedSingleElectronsCount(atom2) == 0) {
       atom1.setFlag(CDKConstants.REACTIVE_CENTER, true);
       atom2.setFlag(CDKConstants.REACTIVE_CENTER, true);
       bond.setFlag(CDKConstants.REACTIVE_CENTER, true);
     }
   }
 }
Beispiel #30
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;
 }