HybridizationRatioDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer container) { try { IAtomContainer clone = (IAtomContainer) container.clone(); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(clone); int nsp2 = 0; int nsp3 = 0; for (IAtom atom : clone.atoms()) { if (atom.getAtomicNumber() != IElement.C) continue; if (atom.getHybridization() == Hybridization.SP2) nsp2++; else if (atom.getHybridization() == Hybridization.SP3) nsp3++; } double ratio = nsp3 / (double) (nsp2 + nsp3); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new DoubleResult(ratio), getDescriptorNames()); } catch (CloneNotSupportedException e) { return getDummyDescriptorValue(e); } catch (CDKException e) { return getDummyDescriptorValue(e); } } HybridizationRatioDescriptor(); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override DescriptorValue calculate(IAtomContainer container); @Override IDescriptorResult getDescriptorResultType(); @Override String[] getParameterNames(); @Override Object getParameterType(String name);  }
@Test public void testHybRatioDescriptor1() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("CCC"); Assert.assertEquals(1.0, ((DoubleResult) descriptor.calculate(mol).getValue()).doubleValue(), 0.1); }
@Test public void testHybRatioDescriptor2() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("c1ccccc1"); Assert.assertEquals(0.0, ((DoubleResult) descriptor.calculate(mol).getValue()).doubleValue(), 0.1); }
@Test public void testHybRatioDescriptor3() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("[H]C#N"); Assert.assertEquals(Double.NaN, ((DoubleResult) descriptor.calculate(mol).getValue()).doubleValue(), 0.1); }