Пример #1
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;
  }
Пример #2
0
  @Test
  public void testAtomicNumber() throws Exception {
    String cmlString =
        "<molecule><atomArray><atom id='a1' elementType=\"C\"><scalar dataType=\"xsd:integer\" dictRef=\"cdk:atomicNumber\">6</scalar></atom></atomArray></molecule>";

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

    Assert.assertEquals(1, mol.getAtomCount());
    IAtom atom = mol.getAtom(0);
    Assert.assertEquals("C", atom.getSymbol());
    Assert.assertEquals(6, atom.getAtomicNumber().intValue());
  }
Пример #3
0
  /**
   * Applies the MDL valence model to atoms using the explicit valence (bond order sum) and charge
   * to determine the correct number of implicit hydrogens. The model is not applied if the explicit
   * valence is less than 0 - this is the case when a query bond was read for an atom.
   *
   * @param atom the atom to apply the model to
   * @param explicitValence the explicit valence (bond order sum)
   */
  private void applyMDLValenceModel(IAtom atom, int explicitValence) {

    if (explicitValence < 0) return;

    if (atom.getValency() != null) {
      atom.setImplicitHydrogenCount(atom.getValency() - explicitValence);
    } else {
      Integer element = atom.getAtomicNumber();
      if (element == null) return;

      Integer charge = atom.getFormalCharge();
      if (charge == null) charge = 0;

      int implicitValence = MDLValence.implicitValence(element, charge, explicitValence);
      atom.setValency(implicitValence);
      atom.setImplicitHydrogenCount(implicitValence - explicitValence);
    }
  }