ProtonAffinityHOSEDescriptor extends AbstractAtomicDescriptor { @Override public DescriptorValue calculate(IAtom atom, IAtomContainer container) { double value; try { int i = container.indexOf(atom); if (i < 0) throw new CDKException("atom was not a memeber of the provided container"); container = container.clone(); atom = container.getAtom(i); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(container); LonePairElectronChecker lpcheck = new LonePairElectronChecker(); lpcheck.saturate(container); } catch (CDKException | CloneNotSupportedException e) { return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult( Double.NaN), NAMES, null); } value = db.extractAffinity(container, atom); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(value), NAMES); } ProtonAffinityHOSEDescriptor(); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override DescriptorValue calculate(IAtom atom, IAtomContainer container); @Override String[] getParameterNames(); @Override Object getParameterType(String name);  }
@Test public void testAffinityDescriptor1() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(0, 1, IBond.Order.DOUBLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(1, 2, IBond.Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(2, 3, IBond.Order.DOUBLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(3, 4, IBond.Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(4, 5, IBond.Order.DOUBLE); mol.addBond(5, 0, IBond.Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "Cl")); mol.addBond(0, 6, IBond.Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); addExplicitHydrogens(mol); lpcheck.saturate(mol); double result = ((DoubleResult) descriptor.calculate(mol.getAtom(6), mol).getValue()).doubleValue(); double resultAccordingNIST = 753.1; Assert.assertEquals(resultAccordingNIST, result, 0.00001); }
@Test public void testAffinityDescriptor2() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(0, 1, IBond.Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "Cl")); mol.addBond(1, 2, IBond.Order.SINGLE); addExplicitHydrogens(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); lpcheck.saturate(mol); double result = ((DoubleResult) descriptor.calculate(mol.getAtom(2), mol).getValue()).doubleValue(); double resultAccordingNIST = 693.4; Assert.assertEquals(resultAccordingNIST, result, 0.00001); }