Skip to content

Commit

Permalink
Merge pull request #117 from rigdenlab/minor-updates
Browse files Browse the repository at this point in the history
Minor updates
  • Loading branch information
hlasimpk committed Aug 20, 2019
2 parents ee457a5 + a08534d commit c6302f4
Show file tree
Hide file tree
Showing 51 changed files with 1,611 additions and 1,955 deletions.
13 changes: 12 additions & 1 deletion scripts/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
__date__ = "22 Mar 2016"
__version__ = "1.0"

import contextlib
import glob
import logging
import os
Expand Down Expand Up @@ -70,7 +71,17 @@ def _load_suite(self, cases, pattern, directory):
return suite


@contextlib.contextmanager
def mock_import_path():
"""Patch CCP4 to ignore shipped SIMBAD."""
org_path = sys.path
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
yield
sys.path = org_path


if __name__ == "__main__":
args = get_cli_args()
m = SIMBADUnittestFramework()
m.run(buffer=args.buffer, cases=args.test_cases, verbosity=args.verbosity)
with mock_import_path():
m.run(buffer=args.buffer, cases=args.test_cases, verbosity=args.verbosity)
10 changes: 5 additions & 5 deletions simbad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from distutils.version import StrictVersion
from simbad import version

__version__ = version.__version__

import os
Expand All @@ -18,11 +19,10 @@
if "CCP4" not in os.environ:
raise RuntimeError("Cannot find CCP4 root directory")

if StrictVersion(pyjob.__version__) < StrictVersion('0.1.3'):
if StrictVersion(pyjob.__version__) < StrictVersion("0.1.3"):
raise RuntimeError("Please upgrade PyJOB")

SIMBAD_SHARE_STATIC_DIR = os.path.join(os.environ["CCP4"], "share",
"simbad", "static")
SIMBAD_SHARE_STATIC_DIR = os.path.join(os.environ["CCP4"], "share", "simbad", "static")
LATTICE_DB = os.path.join(SIMBAD_SHARE_STATIC_DIR, "niggli_database.npz")
CONTAMINANT_MODELS = os.path.join(SIMBAD_SHARE_STATIC_DIR, 'contaminants')
MORDA_MODELS = os.path.join(SIMBAD_SHARE_STATIC_DIR, 'morda')
CONTAMINANT_MODELS = os.path.join(SIMBAD_SHARE_STATIC_DIR, "contaminants")
MORDA_MODELS = os.path.join(SIMBAD_SHARE_STATIC_DIR, "morda")
297 changes: 146 additions & 151 deletions simbad/chemistry.py

Large diffs are not rendered by default.

381 changes: 179 additions & 202 deletions simbad/command_line/__init__.py

Large diffs are not rendered by default.

27 changes: 11 additions & 16 deletions simbad/command_line/simbad_contaminant.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,29 @@

def contaminant_argparse():
"""Create the argparse options"""
p = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
p = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
simbad.command_line._argparse_core_options(p)
simbad.command_line._argparse_job_submission_options(p)
simbad.command_line._argparse_contaminant_options(p)
simbad.command_line._argparse_rot_options(p)
simbad.command_line._argparse_mtz_options(p)
simbad.command_line._argparse_mr_options(p)
p.add_argument('mtz', help="The path to the input mtz file")
p.add_argument("mtz", help="The path to the input mtz file")
return p


def main():
"""Main function to run SIMBAD's contaminant search"""
args = contaminant_argparse().parse_args()

args.work_dir = simbad.command_line.get_work_dir(
args.run_dir, work_dir=args.work_dir, ccp4_jobid=args.ccp4_jobid, ccp4i2_xml=args.ccp4i2_xml
)
args.work_dir = simbad.command_line.get_work_dir(args.run_dir, work_dir=args.work_dir, ccp4_jobid=args.ccp4_jobid, ccp4i2_xml=args.ccp4i2_xml)

log_file = os.path.join(args.work_dir, 'simbad.log')
debug_log_file = os.path.join(args.work_dir, 'debug.log')
log_file = os.path.join(args.work_dir, "simbad.log")
debug_log_file = os.path.join(args.work_dir, "debug.log")
log_class = simbad.command_line.LogController()
log_class.add_console(level=args.debug_lvl)
log_class.add_logfile(log_file, level="info", format="%(message)s")
log_class.add_logfile(debug_log_file, level="notset",
format="%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s")
log_class.add_logfile(debug_log_file, level="notset", format="%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s")
global logger
logger = log_class.get_logger()

Expand All @@ -64,19 +60,17 @@ def main():

solution_found = simbad.command_line._simbad_contaminant_search(args)
if solution_found:
logger.info(
"Check you out, crystallizing contaminants! But don't worry, SIMBAD figured it out and found a solution.")
logger.info("Check you out, crystallizing contaminants! But don't worry, SIMBAD figured it out and found a solution.")
else:
logger.info("No results found - contaminant search was unsuccessful")

if args.output_pdb and args.output_mtz:
csv = os.path.join(args.work_dir, 'cont', 'cont_mr.csv')
result = simbad.util.result_by_score_from_csv(csv, 'final_r_free', ascending=True)
csv = os.path.join(args.work_dir, "cont", "cont_mr.csv")
result = simbad.util.result_by_score_from_csv(csv, "final_r_free", ascending=True)
simbad.util.output_files(args.work_dir, result, args.output_pdb, args.output_mtz)

stopwatch.stop()
logger.info("All processing completed in %d days, %d hours, %d minutes, and %d seconds",
*stopwatch.time_pretty)
logger.info("All processing completed in %d days, %d hours, %d minutes, and %d seconds", *stopwatch.time_pretty)

gui.display_results(True, args.results_to_display)
if args.rvapi_document:
Expand All @@ -86,6 +80,7 @@ def main():

if __name__ == "__main__":
import logging

logging.basicConfig(level=logging.NOTSET)
try:
main()
Expand Down
24 changes: 2 additions & 22 deletions simbad/command_line/simbad_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
__version__ = "1.0"

import argparse
import collections
import datetime
import glob
import json
Expand Down Expand Up @@ -61,28 +62,7 @@
os.environ["SSL_CERT_FILE"] = os.path.join(os.environ["CCP4"], 'etc', 'ssl', 'cacert.pem')


class ContaminantSearchResult(object):
"""A basic contabase storing class"""

__slots__ = ('pdb_code', 'space_group', 'uniprot_name', 'uniprot_mnemonic')

def __init__(self, pdb_code, space_group, uniprot_name, uniprot_mnemonic):
self.pdb_code = pdb_code
self.space_group = space_group
self.uniprot_name = uniprot_name
self.uniprot_mnemonic = uniprot_mnemonic

def __repr__(self):
template = "{name}(pdb_code={pdb_code} space_group={space_group} " \
"uniprot_name={uniprot_name} uniprot_mnemonic={uniprot_mnemonic})"
return template.format(name=self.__class__.__name__, **{k: getattr(self, k) for k in self.__class__.__slots__})

def _as_dict(self):
"""Convert the :obj: BlastSearchResult object to a dictionary"""
dictionary = {}
for k in self.__slots__:
dictionary[k] = getattr(self, k)
return dictionary
ContaminantSearchResult = collections.namedtuple("ContaminantSearchResult", ["pdb_code", "space_group", "uniprot_name", "uniprot_mnemonic"])


def is_valid_db_location(database):
Expand Down
36 changes: 14 additions & 22 deletions simbad/command_line/simbad_lattice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,36 @@
def lattice_argparse():
"""Create the argparse options"""
prep = argparse.ArgumentParser(add_help=False)
prep.add_argument('-sg', dest="space_group", type=str, default=None,
help='The space group to use')
prep.add_argument('-uc', dest="unit_cell", type=str, default=None,
help="The unit cell, format 'a,b,c,alpha,beta,gamma'")
prep.add_argument("-sg", dest="space_group", type=str, default=None, help="The space group to use")
prep.add_argument("-uc", dest="unit_cell", type=str, default=None, help="The unit cell, format 'a,b,c,alpha,beta,gamma'")
args, _ = prep.parse_known_args()

p = argparse.ArgumentParser(
parents=[prep], formatter_class=argparse.ArgumentDefaultsHelpFormatter)
p = argparse.ArgumentParser(parents=[prep], formatter_class=argparse.ArgumentDefaultsHelpFormatter)
simbad.command_line._argparse_core_options(p)
simbad.command_line._argparse_job_submission_options(p)
simbad.command_line._argparse_lattice_options(p)
simbad.command_line._argparse_mtz_options(p)
simbad.command_line._argparse_mr_options(p)
if args.space_group and args.unit_cell:
# Add to the namespace as we're looking for it later
p.add_argument('-mtz', dest="mtz", default=None,
help=argparse.SUPPRESS)
p.add_argument("-mtz", dest="mtz", default=None, help=argparse.SUPPRESS)
else:
p.add_argument('mtz', help="The path to the input mtz file")
p.add_argument("mtz", help="The path to the input mtz file")
return p


def main():
"""Main function to run SIMBAD's lattice search"""
args = lattice_argparse().parse_args()

args.work_dir = simbad.command_line.get_work_dir(
args.run_dir, work_dir=args.work_dir, ccp4_jobid=args.ccp4_jobid, ccp4i2_xml=args.ccp4i2_xml
)
args.work_dir = simbad.command_line.get_work_dir(args.run_dir, work_dir=args.work_dir, ccp4_jobid=args.ccp4_jobid, ccp4i2_xml=args.ccp4i2_xml)

log_file = os.path.join(args.work_dir, 'simbad.log')
debug_log_file = os.path.join(args.work_dir, 'debug.log')
log_file = os.path.join(args.work_dir, "simbad.log")
debug_log_file = os.path.join(args.work_dir, "debug.log")
log_class = simbad.command_line.LogController()
log_class.add_console(level=args.debug_lvl)
log_class.add_logfile(log_file, level="info", format="%(message)s")
log_class.add_logfile(debug_log_file, level="notset",
format="%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s")
log_class.add_logfile(debug_log_file, level="notset", format="%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s")
global logger
logger = log_class.get_logger()

Expand All @@ -74,22 +67,20 @@ def main():
if args.space_group and args.unit_cell:
display_summary = False
elif solution_found:
logger.info(
"Lucky you! SIMBAD worked its charm and found a lattice match for you.")
logger.info("Lucky you! SIMBAD worked its charm and found a lattice match for you.")
display_summary = True
else:
logger.info("No results found - lattice search was unsuccessful")
display_summary = True

if args.output_pdb and args.output_mtz:
csv = os.path.join(args.work_dir, 'latt', 'lattice_mr.csv')
csv = os.path.join(args.work_dir, "latt", "lattice_mr.csv")
if os.path.exists(csv):
result = simbad.util.result_by_score_from_csv(csv, 'final_r_free', ascending=True)
result = simbad.util.result_by_score_from_csv(csv, "final_r_free", ascending=True)
simbad.util.output_files(args.work_dir, result, args.output_pdb, args.output_mtz)

stopwatch.stop()
logger.info("All processing completed in %d days, %d hours, %d minutes, and %d seconds",
*stopwatch.time_pretty)
logger.info("All processing completed in %d days, %d hours, %d minutes, and %d seconds", *stopwatch.time_pretty)

gui.display_results(display_summary, args.results_to_display)
if args.rvapi_document:
Expand All @@ -99,6 +90,7 @@ def main():

if __name__ == "__main__":
import logging

logging.basicConfig(level=logging.NOTSET)
try:
main()
Expand Down
24 changes: 10 additions & 14 deletions simbad/command_line/simbad_morda.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,29 @@

def morda_argparse():
"""Create the argparse options"""
p = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
p = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
simbad.command_line._argparse_core_options(p)
simbad.command_line._argparse_job_submission_options(p)
simbad.command_line._argparse_morda_options(p)
simbad.command_line._argparse_rot_options(p)
simbad.command_line._argparse_mtz_options(p)
simbad.command_line._argparse_mr_options(p)
p.add_argument('mtz', help="The path to the input mtz file")
p.add_argument("mtz", help="The path to the input mtz file")
return p


def main():
"""Main function to run SIMBAD's MoRDa search"""
args = morda_argparse().parse_args()

args.work_dir = simbad.command_line.get_work_dir(
args.run_dir, work_dir=args.work_dir, ccp4_jobid=args.ccp4_jobid, ccp4i2_xml=args.ccp4i2_xml
)
args.work_dir = simbad.command_line.get_work_dir(args.run_dir, work_dir=args.work_dir, ccp4_jobid=args.ccp4_jobid, ccp4i2_xml=args.ccp4i2_xml)

log_file = os.path.join(args.work_dir, 'simbad.log')
debug_log_file = os.path.join(args.work_dir, 'debug.log')
log_file = os.path.join(args.work_dir, "simbad.log")
debug_log_file = os.path.join(args.work_dir, "debug.log")
log_class = simbad.command_line.LogController()
log_class.add_console(level=args.debug_lvl)
log_class.add_logfile(log_file, level="info", format="%(message)s")
log_class.add_logfile(debug_log_file, level="notset",
format="%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s")
log_class.add_logfile(debug_log_file, level="notset", format="%(asctime)s\t%(name)s [%(lineno)d]\t%(levelname)s\t%(message)s")
global logger
logger = log_class.get_logger()

Expand All @@ -70,13 +66,12 @@ def main():
logger.info("No results found - full search was unsuccessful")

if args.output_pdb and args.output_mtz:
csv = os.path.join(args.work_dir, 'morda', 'morda_mr.csv')
result = simbad.util.result_by_score_from_csv(csv, 'final_r_free', ascending=True)
csv = os.path.join(args.work_dir, "morda", "morda_mr.csv")
result = simbad.util.result_by_score_from_csv(csv, "final_r_free", ascending=True)
simbad.util.output_files(args.work_dir, result, args.output_pdb, args.output_mtz)

stopwatch.stop()
logger.info("All processing completed in %d days, %d hours, %d minutes, and %d seconds",
*stopwatch.time_pretty)
logger.info("All processing completed in %d days, %d hours, %d minutes, and %d seconds", *stopwatch.time_pretty)

gui.display_results(True, args.results_to_display)
if args.rvapi_document:
Expand All @@ -86,6 +81,7 @@ def main():

if __name__ == "__main__":
import logging

logging.basicConfig(level=logging.NOTSET)
try:
main()
Expand Down
15 changes: 0 additions & 15 deletions simbad/core/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
__author__ = "Adam Simpkin"
__date__ = "16 April 2018"
__version__ = "0.1"

import abc


class ScoreBase(object):
"""Abstract class for storing scores"""
__metaclass__ = abc.ABCMeta

@abc.abstractmethod
def _as_dict(self):
"""Convert the object to a dictionary"""
return
58 changes: 21 additions & 37 deletions simbad/core/amore_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,24 @@
__date__ = "10 Oct 2017"
__version__ = "0.1"

from simbad.core import ScoreBase


class AmoreRotationScore(ScoreBase):
"""An amore rotation scoring class"""

__slots__ = ("pdb_code", "dat_path", "ALPHA", "BETA", "GAMMA", "CC_F", "RF_F", "CC_I", "CC_P", "Icp",
"CC_F_Z_score", "CC_P_Z_score", "Number_of_rotation_searches_producing_peak")

def __init__(self, pdb_code, dat_path, ALPHA, BETA, GAMMA, CC_F, RF_F, CC_I, CC_P, Icp,
CC_F_Z_score, CC_P_Z_score, Number_of_rotation_searches_producing_peak):
self.pdb_code = pdb_code
self.dat_path = dat_path
self.ALPHA = ALPHA
self.BETA = BETA
self.GAMMA = GAMMA
self.CC_F = CC_F
self.RF_F = RF_F
self.CC_I = CC_I
self.CC_P = CC_P
self.Icp = Icp
self.CC_F_Z_score = CC_F_Z_score
self.CC_P_Z_score = CC_P_Z_score
self.Number_of_rotation_searches_producing_peak = Number_of_rotation_searches_producing_peak

def __repr__(self):
string = "{name}(pdb_code={pdb_code} dat_path={dat_path} " \
"ALPHA={ALPHA} BETA={BETA} GAMMA={GAMMA} " \
"CC_F=CC_F RF_F={RF_F} CC_I={CC_I} CC_P={CC_P} Icp={Icp} " \
"CC_F_Z_score={CC_F_Z_score} CC_P_Z_score={CC_P_Z_score} " \
"Number_of_rotation_searches_producing_peak={Number_of_rotation_searches_producing_peak})"
return string.format(name=self.__class__.__name__, **{k: getattr(self, k) for k in self.__slots__})

def _as_dict(self):
"""Convert the :obj:`AmoreRotationScore <simbad.score.amore_score.AmoreRotationScore>`
object to a dictionary"""
return {k: getattr(self, k) for k in self.__slots__}
from collections import namedtuple


AmoreRotationScore = namedtuple(
"AmoreRotationScore",
[
"pdb_code",
"dat_path",
"ALPHA",
"BETA",
"GAMMA",
"CC_F",
"RF_F",
"CC_I",
"CC_P",
"Icp",
"CC_F_Z_score",
"CC_P_Z_score",
"Number_of_rotation_searches_producing_peak",
],
)

0 comments on commit c6302f4

Please sign in to comment.