CarbonTypesDescriptor extends AbstractMolecularDescriptor implements IMolecularDescriptor { @Override public DescriptorValue calculate(IAtomContainer container) { int c1sp1 = 0; int c2sp1 = 0; int c1sp2 = 0; int c2sp2 = 0; int c3sp2 = 0; int c1sp3 = 0; int c2sp3 = 0; int c3sp3 = 0; int c4sp3 = 0; for (IAtom atom : container.atoms()) { if (atom.getAtomicNumber() != IElement.C) continue; List<IAtom> connectedAtoms = container.getConnectedAtomsList(atom); int cc = 0; for (IAtom connectedAtom : connectedAtoms) { if (connectedAtom.getAtomicNumber() == IElement.C) cc++; } IBond.Order maxBondOrder = getHighestBondOrder(container, atom); if (maxBondOrder == IBond.Order.TRIPLE && cc == 1) c1sp1++; else if (maxBondOrder == IBond.Order.TRIPLE && cc == 2) c2sp1++; else if (maxBondOrder == IBond.Order.DOUBLE && cc == 1) c1sp2++; else if (maxBondOrder == IBond.Order.DOUBLE && cc == 2) c2sp2++; else if (maxBondOrder == IBond.Order.DOUBLE && cc == 3) c3sp2++; else if (maxBondOrder == IBond.Order.SINGLE && cc == 1) c1sp3++; else if (maxBondOrder == IBond.Order.SINGLE && cc == 2) c2sp3++; else if (maxBondOrder == IBond.Order.SINGLE && cc == 3) c3sp3++; else if (maxBondOrder == IBond.Order.SINGLE && cc == 4) c4sp3++; } IntegerArrayResult retval = new IntegerArrayResult(9); retval.add(c1sp1); retval.add(c2sp1); retval.add(c1sp2); retval.add(c2sp2); retval.add(c3sp2); retval.add(c1sp3); retval.add(c2sp3); retval.add(c3sp3); retval.add(c4sp3); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), retval, getDescriptorNames()); } CarbonTypesDescriptor(); @Override DescriptorSpecification getSpecification(); @Override void setParameters(Object[] params); @Override Object[] getParameters(); @Override String[] getDescriptorNames(); @Override String[] getParameterNames(); @Override Object getParameterType(String name); @Override DescriptorValue calculate(IAtomContainer container); @Override IDescriptorResult getDescriptorResultType();  }
@Test public void testButane() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("CCCC"); IntegerArrayResult ret = (IntegerArrayResult) descriptor.calculate(mol).getValue(); Assert.assertEquals(0, ret.get(0)); Assert.assertEquals(0, ret.get(1)); Assert.assertEquals(0, ret.get(2)); Assert.assertEquals(0, ret.get(3)); Assert.assertEquals(0, ret.get(4)); Assert.assertEquals(2, ret.get(5)); Assert.assertEquals(2, ret.get(6)); Assert.assertEquals(0, ret.get(7)); Assert.assertEquals(0, ret.get(8)); }
@Test public void testComplex1() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("C(C)(C)C=C(C)C"); IntegerArrayResult ret = (IntegerArrayResult) descriptor.calculate(mol).getValue(); Assert.assertEquals(0, ret.get(0)); Assert.assertEquals(0, ret.get(1)); Assert.assertEquals(0, ret.get(2)); Assert.assertEquals(1, ret.get(3)); Assert.assertEquals(1, ret.get(4)); Assert.assertEquals(4, ret.get(5)); Assert.assertEquals(0, ret.get(6)); Assert.assertEquals(1, ret.get(7)); Assert.assertEquals(0, ret.get(8)); }
@Test public void testComplex2() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("C#CC(C)=C"); IntegerArrayResult ret = (IntegerArrayResult) descriptor.calculate(mol).getValue(); Assert.assertEquals(1, ret.get(0)); Assert.assertEquals(1, ret.get(1)); Assert.assertEquals(1, ret.get(2)); Assert.assertEquals(0, ret.get(3)); Assert.assertEquals(1, ret.get(4)); Assert.assertEquals(1, ret.get(5)); Assert.assertEquals(0, ret.get(6)); Assert.assertEquals(0, ret.get(7)); Assert.assertEquals(0, ret.get(8)); }