Skip to content

Commit

Permalink
Merge pull request #132 from rigdenlab/changes
Browse files Browse the repository at this point in the history
Fixed issues with CCP4 tests
  • Loading branch information
hlasimpk committed Aug 26, 2020
2 parents bdde11c + 5ddd8b7 commit edc8000
Show file tree
Hide file tree
Showing 18 changed files with 19,085 additions and 29 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@
Changelog
=========

0.2.1
-----

Changed
~~~~~~~
- Fixed issues with simbad-database code
- Changed how the tests are called to allow automatic testing in ccp4

0.2.0
-----

Expand Down
24 changes: 16 additions & 8 deletions simbad/db/tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
import simbad
import simbad.db

SIMBAD_ROOT = os.environ['SIMBAD_ROOT']
try:
ROOT_DIR = SHARE_DIR = os.environ['SIMBAD_ROOT']
EXAMPLE_DIR = os.path.join(ROOT_DIR, "test_data")
except KeyError:
from simbad.command_line import CCP4RootDirectory
ROOT_DIR = str(CCP4RootDirectory())
SHARE_DIR = os.path.join(ROOT_DIR, "share", "simbad")
EXAMPLE_DIR = os.path.join(ROOT_DIR, "examples")


class Test(unittest.TestCase):
"""Unit test"""

def test_from_dat(self):
"""Test case for simbad.db._from_dat"""
input_dat = os.path.join(SIMBAD_ROOT, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
input_dat = os.path.join(SHARE_DIR, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
with open(input_dat, "r") as f_in:
output_str = simbad.db._from_dat(f_in)

Expand All @@ -27,7 +34,8 @@ def test_from_dat(self):

def test_to_dat(self):
"""Test case for simbad.db._to_dat"""
input_pdb = os.path.join(SIMBAD_ROOT, "test_data", "toxd.pdb")
input_pdb = os.path.join(EXAMPLE_DIR, "toxd", "toxd.pdb")

output_dat = os.path.join(os.getcwd(), "test.dat")
with open(input_pdb, "r") as f_in, open(output_dat, "wb") as f_out:
f_out.write(simbad.db._to_dat(f_in))
Expand Down Expand Up @@ -60,15 +68,15 @@ def test_str_to_dat(self):

def test_find_simbad_dat_files(self):
"""Test case for simbad.db.find_simbad_dat_files"""
test_dat_db = os.path.join(SIMBAD_ROOT, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122")
test_dat_db = os.path.join(SHARE_DIR, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122")
data = os.path.basename(simbad.db.find_simbad_dat_files(test_dat_db)[0])
reference_data = "2fbb.dat"

self.assertEqual(data, reference_data)

def test_convert_pdb_to_dat(self):
"""Test case for simbad.db.convert_pdb_to_dat"""
input_pdb = os.path.join(SIMBAD_ROOT, "test_data", "toxd.pdb")
input_pdb = os.path.join(EXAMPLE_DIR, "toxd", "toxd.pdb")
output_dat = os.path.join(os.getcwd(), "test.dat")
simbad.db.convert_pdb_to_dat(input_pdb, output_dat)

Expand All @@ -79,7 +87,7 @@ def test_convert_pdb_to_dat(self):

def test_convert_dat_to_pdb(self):
"""Test case for simbad.db.convert_dat_to_pdb"""
input_dat = os.path.join(SIMBAD_ROOT, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
input_dat = os.path.join(SHARE_DIR, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
output_pdb = os.path.join(os.getcwd(), "test.pdb")
simbad.db.convert_dat_to_pdb(input_dat, output_pdb)

Expand All @@ -88,14 +96,14 @@ def test_convert_dat_to_pdb(self):

def test_is_valid_dat(self):
"""Test case for simbad.db.is_valid_dat"""
input_dat = os.path.join(SIMBAD_ROOT, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
input_dat = os.path.join(SHARE_DIR, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
data = simbad.db.is_valid_dat(input_dat)

self.assertTrue(data)

def test_read_dat(self):
"""Test case for simbad.db.read_dat"""
input_dat = os.path.join(SIMBAD_ROOT, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
input_dat = os.path.join(SHARE_DIR, "static", "contaminants", "CHICK", "LYSC_CHICK", "P6122", "2fbb.dat")
output_str = simbad.db.read_dat(input_dat)

data = output_str.split("\n")[0]
Expand Down
8 changes: 6 additions & 2 deletions simbad/lattice/tests/test_latticesearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,19 @@
import unittest
from simbad.lattice.lattice_search import LatticeSearch

SIMBAD_ROOT = os.environ['SIMBAD_ROOT']
try:
SHARE_DIR = os.environ['SIMBAD_ROOT']
except KeyError:
from simbad.command_line import CCP4RootDirectory
SHARE_DIR = os.path.join(str(CCP4RootDirectory()), "share", "simbad")


class Test(unittest.TestCase):
"""Unit test"""

@classmethod
def setUpClass(cls):
lattice_db = os.path.join(SIMBAD_ROOT, "static", "niggli_database.npz")
lattice_db = os.path.join(SHARE_DIR, "static", "niggli_database.npz")
cls.LS = LatticeSearch(lattice_db, os.getcwd())

@unittest.skipIf('THIS_IS_TRAVIS' in os.environ, "not implemented in Travis CI")
Expand Down
10 changes: 8 additions & 2 deletions simbad/rotsearch/tests/test_rotation_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,21 @@
import simbad.rotsearch.amore_search
import simbad.rotsearch.phaser_search

SIMBAD_ROOT = os.environ['SIMBAD_ROOT']
try:
ROOT_DIR = os.environ['SIMBAD_ROOT']
EXAMPLE_DIR = os.path.join(ROOT_DIR, "test_data")
except KeyError:
from simbad.command_line import CCP4RootDirectory
ROOT_DIR = str(CCP4RootDirectory())
EXAMPLE_DIR = os.path.join(ROOT_DIR, "examples")


class Test(unittest.TestCase):
"""Unit test"""

@classmethod
def setUpClass(cls):
mtz = os.path.join(SIMBAD_ROOT, "test_data", "toxd.mtz")
mtz = os.path.join(EXAMPLE_DIR, "toxd", "toxd.mtz")
cls.AS = simbad.rotsearch.amore_search.AmoreRotationSearch(mtz, "molrep", "tmp_dir", "work_dir")
cls.PS = simbad.rotsearch.phaser_search.PhaserRotationSearch(mtz, "molrep", "tmp_dir", "work_dir")

Expand Down
4 changes: 2 additions & 2 deletions simbad/util/mtz_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def reindex(hklin, hklout, sg):
cexec(cmd, stdin=stdin)


@deprecate('0.2.1', msg="Use simbad.parsers.mtz_parser.MtzParser instead")
@deprecate('0.2.2', msg="Use simbad.parsers.mtz_parser.MtzParser instead")
class GetLabels(object):
def __init__(self, hklin):
self.f = None
Expand Down Expand Up @@ -154,7 +154,7 @@ def run(self, hklin):
self.free = mp.free


@deprecate('0.2.1', msg="Use simbad.parsers.mtz_parser.MtzParser instead")
@deprecate('0.2.2', msg="Use simbad.parsers.mtz_parser.MtzParser instead")
def crystal_data(hklin):
mp = MtzParser(hklin)
space_group = "".join(mp.spacegroup_symbol.encode("ascii").split())
Expand Down
1 change: 1 addition & 0 deletions simbad/util/pdb_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def assert_structure(self):
@staticmethod
def get_pdb_content(pdb_code):
import iotbx.pdb.fetch
import urllib2
try:
try:
content = iotbx.pdb.fetch.fetch(pdb_code, data_type="pdb", format="pdb", mirror="pdb-redo")
Expand Down
12 changes: 9 additions & 3 deletions simbad/util/tests/test_matthews_prob.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
import unittest
from simbad.util import matthews_prob

SIMBAD_ROOT = os.environ['SIMBAD_ROOT']
try:
ROOT_DIR = os.environ['SIMBAD_ROOT']
EXAMPLE_DIR = os.path.join(ROOT_DIR, "test_data")
except KeyError:
from simbad.command_line import CCP4RootDirectory
ROOT_DIR = str(CCP4RootDirectory())
EXAMPLE_DIR = os.path.join(ROOT_DIR, "examples")


class Test(unittest.TestCase):
Expand All @@ -17,7 +23,7 @@ class Test(unittest.TestCase):
def test_solvent_content(self):
"""Test case for matthews_prob.SolventContent.calculate_from_file"""

input_model = os.path.join(SIMBAD_ROOT, "test_data", "toxd.pdb")
input_model = os.path.join(EXAMPLE_DIR, "toxd", "toxd.pdb")
volume = 16522.4616729
SC = matthews_prob.SolventContent(volume)
data = SC.calculate_from_file(input_model)
Expand All @@ -29,7 +35,7 @@ def test_solvent_content(self):
def test_matthews_prob(self):
"""Test case for matthews_prob.MatthewsProbability.calculate_from_file"""

input_model = os.path.join(SIMBAD_ROOT, "test_data", "toxd.pdb")
input_model = os.path.join(EXAMPLE_DIR, "toxd", "toxd.pdb")
volume = 16522.4616729
MC = matthews_prob.MatthewsProbability(volume)
data = MC.calculate_from_file(input_model)
Expand Down
18 changes: 12 additions & 6 deletions simbad/util/tests/test_mtz_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
from simbad.parsers import mtz_parser
from simbad.util import mtz_util

SIMBAD_ROOT = os.environ['SIMBAD_ROOT']
try:
ROOT_DIR = os.environ['SIMBAD_ROOT']
EXAMPLE_DIR = os.path.join(ROOT_DIR, "test_data")
except KeyError:
from simbad.command_line import CCP4RootDirectory
ROOT_DIR = str(CCP4RootDirectory())
EXAMPLE_DIR = os.path.join(ROOT_DIR, "examples")


class Test(unittest.TestCase):
Expand All @@ -17,7 +23,7 @@ class Test(unittest.TestCase):
def test_crystal_data_1(self):
"""Test case for mtz_util.crystal_data"""

input_mtz = os.path.join(SIMBAD_ROOT, "test_data", "toxd.mtz")
input_mtz = os.path.join(EXAMPLE_DIR, "toxd", "toxd.mtz")
mtz_obj = mtz_parser.MtzParser(input_mtz)
data = (
"".join(mtz_obj.spacegroup_symbol.encode("ascii").split()),
Expand Down Expand Up @@ -53,7 +59,7 @@ def test_crystal_data_1(self):
def test_crystal_data_2(self):
"""Test case for mtz_util.crystal_data"""

input_mtz = os.path.join(SIMBAD_ROOT, "test_data", "rnase25.mtz")
input_mtz = os.path.join(EXAMPLE_DIR, "rnase", "rnase25.mtz")
mtz_obj = mtz_parser.MtzParser(input_mtz)
data = (
"".join(mtz_obj.spacegroup_symbol.encode("ascii").split()),
Expand Down Expand Up @@ -90,7 +96,7 @@ def test_crystal_data_2(self):
def test_get_labels_1(self):
"""Test case for mtz_util.get_labels"""

input_mtz = os.path.join(SIMBAD_ROOT, "test_data", "toxd.mtz")
input_mtz = os.path.join(EXAMPLE_DIR, "toxd", "toxd.mtz")
temp_mtz = os.path.join(os.getcwd(), "input.mtz")
temp_log = os.path.join(os.getcwd(), "input.log")
mtz_util.ctruncate(input_mtz, temp_mtz)
Expand All @@ -109,7 +115,7 @@ def test_get_labels_1(self):
def test_get_labels_2(self):
"""Test case for mtz_util.get_labels"""

input_mtz = os.path.join(SIMBAD_ROOT, "test_data", "rnase25F+F-.mtz")
input_mtz = os.path.join(EXAMPLE_DIR, "rnase", "rnase25F+F-.mtz")
temp_mtz = os.path.join(os.getcwd(), "input.mtz")
temp_log = os.path.join(os.getcwd(), "input.log")
mtz_util.ctruncate(input_mtz, temp_mtz)
Expand All @@ -128,7 +134,7 @@ def test_get_labels_2(self):
@unittest.skipIf('THIS_IS_TRAVIS' in os.environ, "not implemented in Travis CI")
def test_change_space_group_1(self):
"""Test case for mtz_util.ExperimentalData.change_space_group"""
input_mtz = os.path.join(SIMBAD_ROOT, "test_data", "toxd.mtz")
input_mtz = os.path.join(EXAMPLE_DIR, "toxd", "toxd.mtz")
temp_mtz = os.path.join(os.getcwd(), "input.mtz")
mtz_util.reindex(input_mtz, temp_mtz, "18")
mtz_obj = mtz_parser.MtzParser(temp_mtz)
Expand Down
16 changes: 11 additions & 5 deletions simbad/util/tests/test_pdb_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
from urllib.request import urlopen
from urllib.error import URLError

SIMBAD_ROOT = os.environ['SIMBAD_ROOT']
try:
ROOT_DIR = os.environ['SIMBAD_ROOT']
EXAMPLE_DIR = os.path.join(ROOT_DIR, "test_data")
except KeyError:
from simbad.command_line import CCP4RootDirectory
ROOT_DIR = str(CCP4RootDirectory())
EXAMPLE_DIR = os.path.join(ROOT_DIR, "examples")


def internet_on():
Expand All @@ -35,7 +41,7 @@ class Test(unittest.TestCase):
def test_calculate_integration_box(self):
"""Test case for PdbStructure.integration_box"""

input_model = os.path.join(SIMBAD_ROOT, "test_data", "toxd.pdb")
input_model = os.path.join(EXAMPLE_DIR, "toxd", "toxd.pdb")
pdb_struct = PdbStructure.from_file(input_model)
data = pdb_struct.integration_box
reference_data = (48.306749999999994, 56.73474999999999, 48.589749999999995, 19.84575)
Expand All @@ -45,7 +51,7 @@ def test_calculate_integration_box(self):
def test_molecular_weight_1(self):
"""Test case for PdbStructure.molecular_weight"""

input_model = os.path.join(SIMBAD_ROOT, "test_data", "toxd.pdb")
input_model = os.path.join(EXAMPLE_DIR, "toxd", "toxd.pdb")
pdb_struct = PdbStructure.from_file(input_model)
data = pdb_struct.molecular_weight
reference_data = 6855.978639999951
Expand All @@ -55,7 +61,7 @@ def test_molecular_weight_1(self):
def test_molecular_weight_2(self):
"""Test case for PdbStructure.molecular_weight"""

input_model = os.path.join(SIMBAD_ROOT, "test_data", "rnase.pdb")
input_model = os.path.join(EXAMPLE_DIR, "rnase", "rnase.pdb")
pdb_struct = PdbStructure.from_file(input_model)
data = pdb_struct.molecular_weight
reference_data = 21163.001080955823
Expand All @@ -65,7 +71,7 @@ def test_molecular_weight_2(self):
def test_molecular_weight_3(self):
"""Test case for PdbStructure.molecular_weight"""

input_model = os.path.join(SIMBAD_ROOT, "test_data", "3a22.pdb")
input_model = os.path.join(EXAMPLE_DIR, "data", "3a22.pdb")
pdb_struct = PdbStructure.from_file(input_model)
data = pdb_struct.molecular_weight
reference_data = 128535.91044924183
Expand Down
2 changes: 1 addition & 1 deletion simbad/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Maintain sematantic versioning. Further information can
# be found here [http://semver.org/]
__version_info__ = (0, 2, 0)
__version_info__ = (0, 2, 1)

# ======================================================
# Do __NOT__ change anything below here
Expand Down
File renamed without changes.

0 comments on commit edc8000

Please sign in to comment.