Skip to content

Commit

Permalink
Added missing files
Browse files Browse the repository at this point in the history
Signed-off-by: John May <john.wilkinsonmay@gmail.com>
  • Loading branch information
aclarkxyz authored and johnmay committed Feb 21, 2014
1 parent 125d674 commit 282457b
Show file tree
Hide file tree
Showing 2 changed files with 267 additions and 0 deletions.
@@ -0,0 +1,97 @@

/* $Revision$ $Author$ $Date$
*
* Copyright (c) 2014 Collaborative Drug Discovery, Inc. <alex@collaborativedrug.com>
*
* Implemented by Alex M. Clark, produced by Collaborative Drug Discovery, Inc.
* Made available to the CDK community under the terms of the GNU LGPL.
*
* http://collaborativedrug.com
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.openscience.cdk.qsar.descriptors.molecular;

import org.junit.Before;
import org.junit.Test;
import org.openscience.cdk.*;
import org.openscience.cdk.qsar.*;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.*;
import org.openscience.cdk.io.*;
import org.openscience.cdk.qsar.result.*;
import org.openscience.cdk.tools.*;
import org.openscience.cdk.annotations.*;

import java.util.*;
import java.util.zip.*;
import java.io.*;

/**
* Test for fractional PSA descriptor.
*
* @cdk.module test-qsarmolecular
*/

public class FractionalPSADescriptorTest extends MolecularDescriptorTest
{
private static ILoggingTool logger=LoggingToolFactory.createLoggingTool(FractionalPSADescriptorTest.class);

public FractionalPSADescriptorTest()
{
}

@Before
public void setUp() throws Exception
{
setDescriptor(FractionalPSADescriptor.class);
}

@Test
public void testDescriptors() throws Exception
{
String fnmol="data/cdd/pyridineacid.mol";
MDLReader mdl=new MDLReader(this.getClass().getClassLoader().getResourceAsStream(fnmol));
AtomContainer mol=new AtomContainer();
mdl.read(mol);
mdl.close();

FractionalPSADescriptor fpsa=new FractionalPSADescriptor();
DescriptorValue results=fpsa.calculate(mol);

// note: test currently assumes that just one descriptor is calculated
String[] names=results.getNames();
if (names.length!=1 || !names[0].equals("tpsaEfficiency")) throw new CDKException("Only expecting 'tpsaEfficiency'");
DoubleResult value=(DoubleResult)results.getValue();
double tpsaEfficiency=value.doubleValue();
final double ANSWER=0.4036,ANSWER_LO=ANSWER*0.999,ANSWER_HI=ANSWER*1.001; // (we can tolerate rounding errors)
if (tpsaEfficiency<ANSWER_LO || tpsaEfficiency>ANSWER_HI)
{
throw new CDKException("Got "+tpsaEfficiency+", expected "+ANSWER);
}
}

// included to shutdown the warning messages for not having tests for trivial methods
@Test
public void nop() throws Exception {}
}

@@ -0,0 +1,170 @@

/* $Revision$ $Author$ $Date$
*
* Copyright (c) 2014 Collaborative Drug Discovery, Inc. <alex@collaborativedrug.com>
*
* Implemented by Alex M. Clark, produced by Collaborative Drug Discovery, Inc.
* Made available to the CDK community under the terms of the GNU LGPL.
*
* http://collaborativedrug.com
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

package org.openscience.cdk.qsar.descriptors.molecular;

import org.junit.Before;
import org.junit.Test;
import org.openscience.cdk.*;
import org.openscience.cdk.qsar.*;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.*;
import org.openscience.cdk.io.MDLReader;
import org.openscience.cdk.io.MDLV2000Writer;
import org.openscience.cdk.qsar.result.*;
import org.openscience.cdk.tools.*;
import org.openscience.cdk.annotations.*;

import java.util.*;
import java.util.zip.*;
import java.io.*;

/**
* Test for small rings descriptor.
*
* @cdk.module test-qsarmolecular
*/

public class SmallRingDescriptorTest extends MolecularDescriptorTest
{
private static ILoggingTool logger=LoggingToolFactory.createLoggingTool(SmallRingDescriptorTest.class);

public SmallRingDescriptorTest()
{
}

@Before
public void setUp() throws Exception
{
setDescriptor(SmallRingDescriptor.class);
}

@Test
public void testDescriptors() throws Exception
{
logger.info("CircularFingerprinter test: loading source materials");

String fnzip="data/cdd/aromring_validation.zip";
logger.info("Loading source content: "+fnzip);
InputStream in=this.getClass().getClassLoader().getResourceAsStream(fnzip);
validate(in);
in.close();

logger.info("CircularFingerprinter test: completed without any problems");
}

// included to shutdown the warning messages for not having tests for trivial methods
@Test
public void nop() throws Exception {}

// run through the cases
private void validate(InputStream in) throws Exception
{
ZipInputStream zip=new ZipInputStream(in);

// stream the contents form the zipfile: these are all short
HashMap<String,byte[]> content=new HashMap<String,byte[]>();
while (true)
{
ZipEntry ze=zip.getNextEntry();
if (ze==null) break;
String fn=ze.getName();
ByteArrayOutputStream buff=new ByteArrayOutputStream();
while (true)
{
int b=zip.read();
if (b<0) break;
buff.write(b);
}
content.put(fn,buff.toByteArray());
}

zip.close();

for (int idx=1;;idx++)
{
String basefn=String.valueOf(idx);
while (basefn.length()<6) basefn="0"+basefn;
byte[] molBytes=content.get(basefn+".mol");
if (molBytes==null) break;

AtomContainer mol=new AtomContainer();
MDLReader mdl=new MDLReader(new ByteArrayInputStream(molBytes));
mdl.read(mol);
mdl.close();

ByteArrayInputStream rin=new ByteArrayInputStream(content.get(basefn+".rings"));
BufferedReader rdr=new BufferedReader(new InputStreamReader(rin));
String[] bits=rdr.readLine().split(" ");
rdr.close();
int wantSmallRings=Integer.parseInt(bits[0]);
int wantRingBlocks=Integer.parseInt(bits[1]);
int wantAromRings=Integer.parseInt(bits[2]);
int wantAromBlocks=Integer.parseInt(bits[3]);

logger.info("FN="+basefn+" MOL="+mol.getAtomCount()+","+mol.getBondCount()+
" nSmallRings="+wantSmallRings+" nRingBlocks="+wantRingBlocks+
" nAromRings="+wantAromRings+" nAromBlocks="+wantAromBlocks);

SmallRingDescriptor descr=new SmallRingDescriptor();
DescriptorValue results=descr.calculate(mol);
String[] names=results.getNames();
IntegerArrayResult values=(IntegerArrayResult)results.getValue();

int gotSmallRings=0,gotRingBlocks=0,gotAromRings=0,gotAromBlocks=0;
for (int n=0;n<names.length;n++)
{
if (names[n].equals("nSmallRings")) gotSmallRings=values.get(n);
else if (names[n].equals("nRingBlocks")) gotRingBlocks=values.get(n);
else if (names[n].equals("nAromRings")) gotAromRings=values.get(n);
else if (names[n].equals("nAromBlocks")) gotAromBlocks=values.get(n);
}

String error=null;
if (gotSmallRings!=wantSmallRings) error="Got "+gotSmallRings+" small rings, expected "+wantSmallRings;
else if (gotRingBlocks!=wantRingBlocks) error="Got "+gotRingBlocks+" ring blocks, expected "+wantRingBlocks;
else if (gotAromRings!=wantAromRings) error="Got "+gotAromRings+" aromatic rings, expected "+wantAromRings;
else if (gotAromBlocks!=wantAromBlocks) error="Got "+gotAromBlocks+" aromatic blocks, expected "+wantAromBlocks;

if (error!=null)
{
StringWriter str=new StringWriter();
MDLV2000Writer wtr=new MDLV2000Writer(str);
wtr.write(mol);
wtr.close();
error+="\nMolecule:\n"+str.toString();
throw new CDKException(error);
}
}
}

}

0 comments on commit 282457b

Please sign in to comment.