BasicGroupCountDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer atomContainer) { if (tools.isEmpty()) { throw new IllegalStateException("descriptor is not initalised, invoke 'initalise' first"); } atomContainer = clone(atomContainer); for (IAtom atom : atomContainer.atoms()) { if (atom.getImplicitHydrogenCount() == null) atom.setImplicitHydrogenCount(0); } int count = 0; for (SmartsPattern ptrn : tools) { count += ptrn.matchAll(atomContainer).count(); } return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), new IntegerResult( count), getDescriptorNames()); } BasicGroupCountDescriptor(); @Override void initialise(IChemObjectBuilder builder); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override DescriptorValue calculate(IAtomContainer atomContainer); @Override IDescriptorResult getDescriptorResultType(); @Override String[] getParameterNames(); @Override Object getParameterType(String name);  }
@Test public void testAmine() throws Exception { SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("NC"); IntegerResult result = (IntegerResult) descriptor.calculate(mol).getValue(); Assert.assertEquals(1, result.intValue()); }
@Test(expected = IllegalStateException.class) public void uninitalisedError() { new BasicGroupCountDescriptor().calculate(new AtomContainer()); }
@Test public void test() throws Exception { IChemObjectBuilder builder = SilentChemObjectBuilder.getInstance(); IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom a1 = builder.newInstance(IAtom.class, "N"); mol.addAtom(a1); IAtom a2 = builder.newInstance(IAtom.class, "N"); mol.addAtom(a2); IAtom a3 = builder.newInstance(IAtom.class, "C"); mol.addAtom(a3); IAtom a4 = builder.newInstance(IAtom.class, "C"); mol.addAtom(a4); IAtom a5 = builder.newInstance(IAtom.class, "H"); mol.addAtom(a5); IAtom a6 = builder.newInstance(IAtom.class, "H"); mol.addAtom(a6); IAtom a7 = builder.newInstance(IAtom.class, "H"); mol.addAtom(a7); IAtom a8 = builder.newInstance(IAtom.class, "H"); mol.addAtom(a8); IBond b1 = builder.newInstance(IBond.class, a1, a3, IBond.Order.SINGLE); mol.addBond(b1); IBond b2 = builder.newInstance(IBond.class, a1, a4, IBond.Order.DOUBLE); mol.addBond(b2); IBond b3 = builder.newInstance(IBond.class, a2, a3, IBond.Order.DOUBLE); mol.addBond(b3); IBond b4 = builder.newInstance(IBond.class, a2, a8, IBond.Order.SINGLE); mol.addBond(b4); IBond b5 = builder.newInstance(IBond.class, a3, a5, IBond.Order.SINGLE); mol.addBond(b5); IBond b6 = builder.newInstance(IBond.class, a4, a6, IBond.Order.SINGLE); mol.addBond(b6); IBond b7 = builder.newInstance(IBond.class, a4, a7, IBond.Order.SINGLE); mol.addBond(b7); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); addImplicitHydrogens(mol); IntegerResult result = (IntegerResult) descriptor.calculate(mol).getValue(); Assert.assertEquals(2, result.intValue()); }