private IDescriptorResult newDescriptorResultArray(String descriptorValue) { IDescriptorResult result = null; if ("xsd:double".equals(currentDescriptorDataType)) { result = new DoubleArrayResult(); StringTokenizer tokenizer = new StringTokenizer(descriptorValue); while (tokenizer.hasMoreElements()) { ((DoubleArrayResult) result).add(Double.parseDouble(tokenizer.nextToken())); } } else if ("xsd:integer".equals(currentDescriptorDataType)) { result = new IntegerArrayResult(); StringTokenizer tokenizer = new StringTokenizer(descriptorValue); while (tokenizer.hasMoreElements()) { ((IntegerArrayResult) result).add(Integer.parseInt(tokenizer.nextToken())); } } return result; } }
@Test public void testGet_int() { IntegerArrayResult result = new IntegerArrayResult(); Assert.assertNotNull(result); Assert.assertEquals("", result.toString()); result.add(5); Assert.assertEquals(5, result.get(0)); result.add(2); Assert.assertEquals(5, result.get(0)); Assert.assertEquals(2, result.get(1)); result.add(-1); Assert.assertEquals(5, result.get(0)); Assert.assertEquals(2, result.get(1)); Assert.assertEquals(-1, result.get(2)); }
static public Object toObject(IDescriptorResult result, int index) throws DescriptorException { if(result instanceof DoubleArrayResult){ double doubleValue = ((DoubleArrayResult)result).get(index); validateValue(doubleValue); return Double.valueOf(doubleValue); } else if(result instanceof IntegerArrayResult){ int intValue = ((IntegerArrayResult)result).get(index); return Integer.valueOf(intValue); } throw new DescriptorException(String.valueOf(result)); }
@Test public void testIntegerArrayResult() { IntegerArrayResult result = new IntegerArrayResult(); Assert.assertNotNull(result); Assert.assertEquals(0, result.length()); }
@Test public void testToString() { IntegerArrayResult result = new IntegerArrayResult(); Assert.assertNotNull(result); Assert.assertEquals("", result.toString()); result.add(5); Assert.assertEquals("5", result.toString()); result.add(2); Assert.assertEquals("5,2", result.toString()); result.add(-3); Assert.assertEquals("5,2,-3", result.toString()); }
/** * Returns a placeholder with the descriptor size and type. */ @Override public IDescriptorResult getDescriptorResultType() { return new IntegerArrayResult(NAMES.length); }
@Test public void testSize() { IntegerArrayResult result = new IntegerArrayResult(); Assert.assertNotNull(result); Assert.assertEquals(0, result.length()); result.add(5); Assert.assertEquals(1, result.length()); }
@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)); }
@Test public void IntegerArrayResult_int() { IntegerArrayResult result = new IntegerArrayResult(5); Assert.assertNotNull(result); Assert.assertEquals(5, result.length()); }
/** * Returns a placeholder with the descriptor size and type. */ @Override public IDescriptorResult getDescriptorResultType() { return new IntegerArrayResult(NAMES.length); }
@Test public void testAACount() throws Exception { IBioPolymer protein = ProteinBuilderTool.createProtein("ARNDCFQEGHIPLKMSTYVW", SilentChemObjectBuilder.getInstance()); IDescriptorResult result = descriptor.calculate(protein).getValue(); Assert.assertTrue(result instanceof IntegerArrayResult); IntegerArrayResult iaResult = (IntegerArrayResult) result; for (int i = 0; i < iaResult.length(); i++) { Assert.assertTrue(iaResult.get(i) >= 1); // all AAs are found at least once } Assert.assertEquals(20, iaResult.get(8)); // glycine is in all of them, so 20 times }
private IDescriptorResult newDescriptorResultArray(String descriptorValue) { IDescriptorResult result = null; if ("xsd:double".equals(currentDescriptorDataType)) { result = new DoubleArrayResult(); StringTokenizer tokenizer = new StringTokenizer(descriptorValue); while (tokenizer.hasMoreElements()) { ((DoubleArrayResult) result).add(Double.parseDouble(tokenizer.nextToken())); } } else if ("xsd:integer".equals(currentDescriptorDataType)) { result = new IntegerArrayResult(); StringTokenizer tokenizer = new StringTokenizer(descriptorValue); while (tokenizer.hasMoreElements()) { ((IntegerArrayResult) result).add(Integer.parseInt(tokenizer.nextToken())); } } return result; } }
@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)); }
/** * Returns the specific type of the DescriptorResult object. * * The return value from this method really indicates what type of result will * be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result * can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method * allows you to do the same thing, without actually calculating the descriptor. * * @return an object that implements the {@link org.openscience.cdk.qsar.result.IDescriptorResult} interface indicating * the actual type of values returned by the descriptor in the {@link org.openscience.cdk.qsar.DescriptorValue} object */ @Override public IDescriptorResult getDescriptorResultType() { return new IntegerArrayResult(20); }
@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"))); }
nRingBlocks = Math.max(nRingBlocks, ringBlock[n]); IntegerArrayResult result = new IntegerArrayResult(); result.add(nSmallRings); result.add(nAromRings); result.add(nRingBlocks); result.add(nAromBlocks); result.add(nRings3); result.add(nRings4); result.add(nRings5); result.add(nRings6); result.add(nRings7); result.add(nRings8); result.add(nRings9); return new DescriptorValue(getSpecification(), getParameterNames(), getParameters(), result, NAMES);
@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)); }
/** * Returns the specific type of the DescriptorResult object. * * The return value from this method really indicates what type of result will * be obtained from the {@link org.openscience.cdk.qsar.DescriptorValue} object. Note that the same result * can be achieved by interrogating the {@link org.openscience.cdk.qsar.DescriptorValue} object; this method * allows you to do the same thing, without actually calculating the descriptor. * * @return an object that implements the {@link org.openscience.cdk.qsar.result.IDescriptorResult} interface indicating * the actual type of values returned by the descriptor in the {@link org.openscience.cdk.qsar.DescriptorValue} object */ @Override public IDescriptorResult getDescriptorResultType() { return new IntegerArrayResult(20); }