def test_bitorder(self): result = run_fps("--maccs166", 7, support.fullpath("maccs.smi")) # The fingerprints are constructed to test the first few bytes. self.assertEquals(result[0][:6], support.set_bit(2)) self.assertEquals(result[1][:6], support.set_bit(3)) self.assertEquals(result[2][:6], support.set_bit(4)) self.assertEquals(result[3][:6], support.set_bit(5)) self.assertEquals(result[4][:6], support.set_bit(9)) self.assertEquals(result[5][:6], support.set_bit(10)) self.assertEquals(result[6][:6], support.set_bit(16))
def test_bitorder(self): result = runner.run_fps("--MACCS", 7, support.fullpath("maccs.smi")) # The fingerprints are constructed to test the first few bytes. self.assertEquals(result[0][:6], support.set_bit(2)) self.assertEquals(result[1][:6], support.set_bit(3)) self.assertEquals(result[2][:6], support.set_bit(4)) self.assertEquals(result[3][:6], support.set_bit(5)) self.assertEquals(result[4][:6], support.set_bit(9)) ## This appears to be a bug in the OpenBabel MACCS definition if VERSION in ("2.2.3", "2.3.0"): # This is WRONG, since OB has an off-by-one error in the ring sizes self.assertEquals(result[5][:6], "000020") else: # which is fixed in the SVN version self.assertEquals(result[5][:6], support.set_bit(10)) self.assertEquals(result[6][:6], support.set_bit(16))
import unittest2 from cStringIO import StringIO as SIO import support # Make sure the module correctly implements __all__ before = after = None before = set(globals()) from chemfp.sdf_reader import * after = set(globals()) assert len(after - before) == 4, ("wrong import * count", after-before) # Needed for access to the experimental FileLocation from chemfp import sdf_reader TRYPTOPHAN_SDF = support.fullpath("tryptophan.sdf") PUBCHEM_SDF = support.fullpath("pubchem.sdf") PUBCHEM_SDF_GZ = support.fullpath("pubchem.sdf.gz") STRANGE_SDF = support.fullpath("strange.sdf") expected_identifiers = ["9425004", "9425009", "9425012", "9425015", "9425018", "9425021", "9425030", "9425031", "9425032", "9425033", "9425034", "9425035", "9425036", "9425037", "9425040", "9425041", "9425042", "9425045", "9425046"] expected_linenos = [1, 191, 401, 592, 817, 1027, 1236, 1457, 1678, 1872, 2086, 2288, 2493, 2700, 2894, 3103, 3305, 3507, 3722] assert len(expected_identifiers) == len(expected_linenos) expected_locs = [dict(title=title, lineno=lineno) for (title, lineno) in zip(expected_identifiers, expected_linenos)]
# Test the symmetric code import unittest2 from cStringIO import StringIO import array import chemfp from chemfp import search, bitops from support import fullpath, PUBCHEM_SDF, PUBCHEM_SDF_GZ fps = chemfp.load_fingerprints(fullpath("queries.fps")) zeros = chemfp.load_fingerprints(StringIO("""\ 0000\tA 0000\tB 0001\tC 0002\tD FFFE\tE FFFF\tF """)) def slow_counts(counts, fps, threshold, query_start, query_end, target_start, target_end): N = len(fps) query_end = min(N, query_end) target_end = min(N, target_end) for row in range(query_start, query_end): row_fp = fps[row][1]
has_oechem = False skip_oechem = True if not support.can_skip("oe"): skip_oechem = False from openeye import oechem if has_oechem: from chemfp.commandline import oe2fps import chemfp.openeye OEGRAPHSIM_API_VERSION = chemfp.openeye.OEGRAPHSIM_API_VERSION chemfp.openeye._USE_SELECT = False # Grrr. Needed to automate testing. real_stdout = sys.stdout real_stderr = sys.stderr PUBCHEM_SDF = support.fullpath("pubchem.sdf") PUBCHEM_SDF_GZ = support.fullpath("pubchem.sdf.gz") PUBCHEM_ANOTHER_EXT = support.fullpath("pubchem.should_be_sdf_but_is_not") oeerrs = oechem.oeosstream() oechem.OEThrow.SetOutputStream(oeerrs) def convert_v1_atom_names_to_v2(s): return (s.replace("Aromaticity", "Arom") .replace("AtomicNumber", "AtmNum") .replace("EqAromatic", "EqArom") .replace("EqHalogen", "EqHalo") .replace("FormalCharge", "FCharge") .replace("HvyDegree", "HvyDeg") .replace("Hybridization", "Hyb")
import sys import unittest2 from cStringIO import StringIO as SIO from chemfp.commandline import sdf2fps import support real_stdin = sys.stdin real_stdout = sys.stdout real_stderr = sys.stderr DECODER_SDF = support.fullpath("decoder.sdf") def run(s): args = s.split() try: sys.stdin = open(DECODER_SDF) sys.stdout = stdout = SIO() sdf2fps.main(args) finally: sys.stdout = real_stdout sys.stdin = real_stdin result = stdout.getvalue().splitlines() if result: assert result[0] == "#FPS1" return result def run_failure(s): sys.stderr = stderr = SIO() try:
# Tests for the different alignment methods in bitops from __future__ import absolute_import, with_statement import unittest2 from cStringIO import StringIO from support import fullpath import chemfp import chemfp.bitops import _chemfp set_alignment_method = chemfp.bitops.set_alignment_method get_alignment_method = chemfp.bitops.get_alignment_method CHEBI_TARGETS = fullpath("chebi_rdmaccs.fps") CHEBI_QUERIES = fullpath("chebi_queries.fps.gz") targets = chemfp.load_fingerprints(CHEBI_TARGETS, alignment=8) targets_64 = chemfp.load_fingerprints(CHEBI_TARGETS, alignment=64) available_methods = chemfp.bitops.get_methods() alignment_methods = chemfp.bitops.get_alignment_methods() all_methods = dict.fromkeys("LUT8-1 LUT8-4 LUT16-4 Lauradoux POPCNT Gillies ssse3".split()) class TestMethods(unittest2.TestCase): def test_no_duplicates(self): methods = chemfp.bitops.get_methods() self.assertEquals(len(methods), len(set(methods)))
except ImportError: has_rdkit = False skip_rdkit = True if not support.can_skip("rdkit"): skip_rdkit = False import rdkit if has_rdkit: from chemfp.commandline import rdkit2fps runner = support.Runner(rdkit2fps.main) else: runner = None MACCS_SMI = support.fullpath("maccs.smi") TRP = open(support.fullpath("tryptophan.sdf")).read() class TestMACCS(unittest2.TestCase): def test_bitorder(self): result = runner.run_fps("--maccs166", 7, MACCS_SMI) # The fingerprints are constructed to test the first few bytes. self.assertEquals(result[0][:6], support.set_bit(2)) self.assertEquals(result[1][:6], support.set_bit(3)) self.assertEquals(result[2][:6], support.set_bit(4)) self.assertEquals(result[3][:6], support.set_bit(5)) self.assertEquals(result[4][:6], support.set_bit(9)) self.assertEquals(result[5][:6], support.set_bit(10)) self.assertEquals(result[6][:6], support.set_bit(16)) def test_type(self): for line in runner.run("--maccs166", MACCS_SMI):
try: from openeye.oechem import OEGraphMol, OEParseSmiles, OEChemIsLicensed if not OEChemIsLicensed(): raise ImportError skip_oechem = False except ImportError: skip_oechem = support.can_skip("oe") if not skip_oechem: from chemfp import openeye_patterns from chemfp.openeye import OEGRAPHSIM_API_VERSION import test_patterns from chemfp import types MACCS_SMI = support.fullpath("maccs.smi") def parse_smiles(smiles): mol = OEGraphMol() OEParseSmiles(mol, smiles) return mol def _count(it): return sum(1 for item in it) class ReferenceMixin(object): def test_reference_data_set(self): largest = min(self.reference_limit,
try: from openeye.oechem import OEGraphMol, OEParseSmiles, OEChemIsLicensed if not OEChemIsLicensed(): raise ImportError skip_oechem = False except ImportError: skip_oechem = support.can_skip("oe") if not skip_oechem: from chemfp import openeye_patterns from chemfp.openeye import OEGRAPHSIM_API_VERSION import test_patterns from chemfp import types MACCS_SMI = support.fullpath("maccs.smi") def parse_smiles(smiles): mol = OEGraphMol() OEParseSmiles(mol, smiles) return mol def _count(it): return sum(1 for item in it) class ReferenceMixin(object): def test_reference_data_set(self): largest = min(self.reference_limit, max(v for (k,v) in self.reference_cases)) matcher = self.reference_class(largest)
class CountRunner(support.Runner): def verify_result(self, result): assert result[0] == "#Count/1", result[0] runner = SimsearchRunner(simsearch.main) run = runner.run run_split = runner.run_split run_exit = runner.run_exit count_runner = CountRunner(simsearch.main) count_run_split = count_runner.run_split count_run_exit = count_runner.run_exit SIMPLE_FPS = support.fullpath("simple.fps") SIMPLE_FPS_GZ = support.fullpath("simple.fps.gz") def run_split_stdin(input, cmdline, expect_length=None, source=SIMPLE_FPS): old_stdin = sys.stdin sys.stdin = StringIO(input) try: return run_split(cmdline, expect_length, source) finally: sys.stdin = old_stdin def gzip_compress(s): f = StringIO() g = gzip.GzipFile(fileobj=f, mode="w")
# Test the symmetric code import unittest2 from cStringIO import StringIO import array import chemfp from chemfp import search, bitops from support import fullpath, PUBCHEM_SDF, PUBCHEM_SDF_GZ fps = chemfp.load_fingerprints(fullpath("queries.fps")) zeros = chemfp.load_fingerprints( StringIO("""\ 0000\tA 0000\tB 0001\tC 0002\tD FFFE\tE FFFF\tF """)) def slow_counts(counts, fps, threshold, query_start, query_end, target_start, target_end): N = len(fps) query_end = min(N, query_end) target_end = min(N, target_end) for row in range(query_start, query_end):
# Tests for the different alignment methods in bitops from __future__ import absolute_import, with_statement import unittest2 from cStringIO import StringIO from support import fullpath import chemfp import chemfp.bitops import _chemfp set_alignment_method = chemfp.bitops.set_alignment_method get_alignment_method = chemfp.bitops.get_alignment_method CHEBI_TARGETS = fullpath("chebi_rdmaccs.fps") CHEBI_QUERIES = fullpath("chebi_queries.fps.gz") targets = chemfp.load_fingerprints(CHEBI_TARGETS, alignment=8) targets_64 = chemfp.load_fingerprints(CHEBI_TARGETS, alignment=64) available_methods = chemfp.bitops.get_methods() alignment_methods = chemfp.bitops.get_alignment_methods() all_methods = dict.fromkeys( "LUT8-1 LUT8-4 LUT16-4 Lauradoux POPCNT Gillies ssse3".split()) class TestMethods(unittest2.TestCase): def test_no_duplicates(self): methods = chemfp.bitops.get_methods()