KierHallSmartsDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer container) { if (container == null || container.getAtomCount() == 0) { return getDummyDescriptorValue(new CDKException("Container was null or else had no atoms")); } IAtomContainer atomContainer; try { atomContainer = (IAtomContainer) container.clone(); for (IAtom atom : atomContainer.atoms()) { if (atom.getImplicitHydrogenCount() == null) atom.setImplicitHydrogenCount(0); } atomContainer = AtomContainerManipulator.removeHydrogens(atomContainer); } catch (CloneNotSupportedException e) { return getDummyDescriptorValue(new CDKException("Error during clone")); } int[] counts = new int[SMARTS.length]; SmartsPattern.prepare(atomContainer); for (int i = 0; i < SMARTS.length; i++) { counts[i] = SMARTS[i].matchAll(atomContainer).countUnique(); } IntegerArrayResult result = new IntegerArrayResult(); for (Integer i : counts) result.add(i); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), result, getDescriptorNames()); } KierHallSmartsDescriptor(); @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 test1() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("CCO"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); DescriptorValue value = descriptor.calculate(mol); IntegerArrayResult result = (IntegerArrayResult) value.getValue(); Assert.assertEquals(79, result.length()); Assert.assertEquals(1, result.get(getIndex("khs.sOH"))); }
@Test public void test2() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("c1c(CN)cc(CCNC)cc1C(CO)CC(=O)CCOCCCO"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); DescriptorValue value = descriptor.calculate(mol); IntegerArrayResult result = (IntegerArrayResult) value.getValue(); Assert.assertEquals(79, result.length()); Assert.assertEquals(2, result.get(getIndex("khs.sOH"))); Assert.assertEquals(1, result.get(getIndex("khs.dO"))); Assert.assertEquals(1, result.get(getIndex("khs.ssO"))); Assert.assertEquals(1, result.get(getIndex("khs.sNH2"))); Assert.assertEquals(1, result.get(getIndex("khs.ssNH"))); }
@Test public void test3() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("C#CC(C)(C)C(C)(C)C#C"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); DescriptorValue value = descriptor.calculate(mol); IntegerArrayResult result = (IntegerArrayResult) value.getValue(); Assert.assertEquals(79, result.length()); Assert.assertEquals(2, result.get(getIndex("khs.tsC"))); Assert.assertEquals(2, result.get(getIndex("khs.ssssC"))); }