Esempio n. 1
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);
    }
  }
  /**
   * This method calculates the ionization potential of an atom.
   *
   * @param atom The IAtom to ionize.
   * @param container Parameter is the IAtomContainer.
   * @return The ionization potential. Not possible the ionization.
   */
  @Override
  public DescriptorValue calculate(IAtom atom, IAtomContainer container) {
    double value = 0;
    // FIXME: for now I'll cache a few modified atomic properties, and restore them at the end of
    // this method
    String originalAtomtypeName = atom.getAtomTypeName();
    Integer originalNeighborCount = atom.getFormalNeighbourCount();
    Integer originalValency = atom.getValency();
    IAtomType.Hybridization originalHybrid = atom.getHybridization();
    Double originalBondOrderSum = atom.getBondOrderSum();
    Order originalMaxBondOrder = atom.getMaxBondOrder();

    if (!isCachedAtomContainer(container)) {
      try {
        AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(container);

        LonePairElectronChecker lpcheck = new LonePairElectronChecker();
        lpcheck.saturate(container);
      } catch (CDKException e) {
        return new DescriptorValue(
            getSpecification(),
            getParameterNames(),
            getParameters(),
            new DoubleResult(Double.NaN),
            getDescriptorNames(),
            e);
      }
    }

    try {
      value = IonizationPotentialTool.predictIP(container, atom);
    } catch (CDKException e) {
      return new DescriptorValue(
          getSpecification(),
          getParameterNames(),
          getParameters(),
          new DoubleResult(Double.NaN),
          getDescriptorNames(),
          e);
    }
    // restore original props
    atom.setAtomTypeName(originalAtomtypeName);
    atom.setFormalNeighbourCount(originalNeighborCount);
    atom.setValency(originalValency);
    atom.setHybridization(originalHybrid);
    atom.setMaxBondOrder(originalMaxBondOrder);
    atom.setBondOrderSum(originalBondOrderSum);

    return new DescriptorValue(
        getSpecification(),
        getParameterNames(),
        getParameters(),
        new DoubleResult(value),
        getDescriptorNames());
  }