Example #1
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();
  }
Example #2
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);
    }
  }
Example #3
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));
   }
 }
  /**
   * A unit test for JUnit with C=CCCl # C=CC[Cl+*]
   *
   * @cdk.inchi InChI=1/C3H7Cl/c1-2-3-4/h2-3H2,1H3
   */
  @Test
  public void testCompareIonized() throws Exception {

    IAtomContainer molA = builder.newInstance(IAtomContainer.class);
    molA.addAtom(builder.newInstance(IAtom.class, "C"));
    molA.addAtom(builder.newInstance(IAtom.class, "C"));
    molA.addBond(0, 1, IBond.Order.SINGLE);
    molA.addAtom(builder.newInstance(IAtom.class, "C"));
    molA.addBond(1, 2, IBond.Order.SINGLE);
    molA.addAtom(builder.newInstance(IAtom.class, "Cl"));
    molA.addBond(2, 3, IBond.Order.SINGLE);

    addExplicitHydrogens(molA);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molA);
    lpcheck.saturate(molA);

    double resultA =
        ((DoubleResult) descriptor.calculate(molA.getAtom(3), molA).getValue()).doubleValue();

    IAtomContainer molB = builder.newInstance(IAtomContainer.class);
    molB.addAtom(builder.newInstance(IAtom.class, "C"));
    molB.addAtom(builder.newInstance(IAtom.class, "C"));
    molB.addBond(0, 1, IBond.Order.SINGLE);
    molB.addAtom(builder.newInstance(IAtom.class, "C"));
    molB.addBond(1, 2, IBond.Order.SINGLE);
    molB.addAtom(builder.newInstance(IAtom.class, "Cl"));
    molB.getAtom(3).setFormalCharge(1);
    molB.addSingleElectron(3);
    molB.addLonePair(3);
    molB.addLonePair(3);
    molB.addBond(2, 3, IBond.Order.SINGLE);

    addExplicitHydrogens(molB);
    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molB);
    lpcheck.saturate(molB);

    Assert.assertEquals(1, molB.getAtom(3).getFormalCharge(), 0.00001);
    Assert.assertEquals(1, molB.getSingleElectronCount(), 0.00001);
    Assert.assertEquals(2, molB.getLonePairCount(), 0.00001);

    double resultB =
        ((DoubleResult) descriptor.calculate(molB.getAtom(3), molB).getValue()).doubleValue();

    Assert.assertNotSame(resultA, resultB);
  }
  /**
   * Get all paths of lengths 0 to the specified length.
   *
   * <p>This method will find all paths upto length N starting from each atom in the molecule and
   * return the unique set of such paths.
   *
   * @param container The molecule to search
   * @return A map of path strings, keyed on themselves
   */
  private Integer[] findPaths(IAtomContainer container) {

    ShortestPathWalker walker = new ShortestPathWalker(container);
    // convert paths to hashes
    List<Integer> paths = new ArrayList<Integer>();
    int patternIndex = 0;

    for (String s : walker.paths()) {
      int toHashCode = s.hashCode();
      paths.add(patternIndex, toHashCode);
      patternIndex++;
    }

    /*
     * Add ring information
     */
    IRingSet sssr = Cycles.essential(container).toRingSet();
    RingSetManipulator.sort(sssr);
    for (Iterator<IAtomContainer> it = sssr.atomContainers().iterator(); it.hasNext(); ) {
      IAtomContainer ring = it.next();
      int toHashCode = String.valueOf(ring.getAtomCount()).hashCode();
      paths.add(patternIndex, toHashCode);
      patternIndex++;
    }
    /*
     * Check for the charges
     */
    List<String> l = new ArrayList<String>();
    for (Iterator<IAtom> it = container.atoms().iterator(); it.hasNext(); ) {
      IAtom atom = it.next();
      int charge = atom.getFormalCharge() == null ? 0 : atom.getFormalCharge();
      if (charge != 0) {
        l.add(atom.getSymbol().concat(String.valueOf(charge)));
      }
    }
    Collections.sort(l);
    int toHashCode = l.hashCode();
    paths.add(patternIndex, toHashCode);
    patternIndex++;

    l = new ArrayList<String>();
    /*
     * atom stereo parity
     */
    for (Iterator<IAtom> it = container.atoms().iterator(); it.hasNext(); ) {
      IAtom atom = it.next();
      int st = atom.getStereoParity() == null ? 0 : atom.getStereoParity();
      if (st != 0) {
        l.add(atom.getSymbol().concat(String.valueOf(st)));
      }
    }
    Collections.sort(l);
    toHashCode = l.hashCode();
    paths.add(patternIndex, toHashCode);
    patternIndex++;

    if (container.getSingleElectronCount() > 0) {
      StringBuilder radicalInformation = new StringBuilder();
      radicalInformation.append("RAD: ").append(String.valueOf(container.getSingleElectronCount()));
      paths.add(patternIndex, radicalInformation.toString().hashCode());
      patternIndex++;
    }
    if (container.getLonePairCount() > 0) {
      StringBuilder lpInformation = new StringBuilder();
      lpInformation.append("LP: ").append(String.valueOf(container.getLonePairCount()));
      paths.add(patternIndex, lpInformation.toString().hashCode());
      patternIndex++;
    }
    return paths.toArray(new Integer[paths.size()]);
  }