Commit 9c281e04 authored by Jacob Durrant's avatar Jacob Durrant

Scripts now accept --test parameter for easy testing.

parent 7f404aec
......@@ -15,6 +15,8 @@ Changes
7. Moved examples directory to `povme/examples/`.
8. Can now read both Windows and POSIX path names seamlessly (no need for
separate ini files).
9. Easy testing now available: `python POVME2.py --test` and `python
POVME_pocket_id.py --test`
2.0.3
-----
......
......@@ -15,6 +15,7 @@
from pathlib import Path
import gzip
import os
import shutil
try:
from pathlib import WindowsPath as WinPath
......@@ -88,3 +89,43 @@ def gzopenfile(path, mode="r"):
The file object.
"""
return gzip.open(fix_filename(path, "r" in mode), mode)
def setup_testing_dir(files_to_copy_relative_to__file__):
"""Create a temporary directory.
files_to_copy_relative_to__file__ -- A list of files to copy, relative to
the python file calling this function.
"""
# Create a temporary directory.
test_dir = "./testing.tmp/"
if os.path.exists(test_dir):
raise IOError("Delete " + test_dir + " before running the test.")
os.mkdir(test_dir)
# Copy example files to this directory.
for fl in files_to_copy_relative_to__file__:
shutil.copy2(os.path.dirname(__file__) + fl, test_dir)
# Change into testing directory.
os.chdir(test_dir)
def delete_testing_dir():
"""Assuming you are already in the temporary directory, this will delete
it."""
# Assumes you are already in the temporary directory.
os.chdir("..")
shutil.rmtree("./testing.tmp/")
def test_passed():
"""Shows a message saying that a test passed."""
print("")
print("-----------------")
print("Passed all tests!")
print("-----------------")
print("")
# To run the POVME Pocket ID example, type the following into
# the unix command line from the current directory:
python ../../POVME_pocket_id.py --filename rel1_example.pdb --pocket_detection_resolution 4.0 --pocket_measuring_resolution 1.0 --clashing_cutoff 3.0 --number_of_neighbors 4 --processors 4 --number_of_spheres 5 --sphere_padding 5.0
python ../../../POVME_pocket_id.py --filename rel1_example.pdb --pocket_detection_resolution 4.0 --pocket_measuring_resolution 1.0 --clashing_cutoff 3.0 --number_of_neighbors 4 --processors 4 --number_of_spheres 5 --sphere_padding 5.0
......@@ -14,7 +14,7 @@ import getopt
from numpy.lib.recfunctions import append_fields
import multiprocessing
import warnings
from .common import openfile
from .common import openfile, setup_testing_dir, delete_testing_dir, test_passed
# POVME Pocket ID 1.0 is a program for identifying protein pockets and
# generating appropriate pocket-encompassing inclusion spheres. These spheres,
......@@ -1293,6 +1293,41 @@ params = {}
def run_pocket_id(parameters):
####### Now the meat of the program ########
# Make sure running Python3
if sys.version_info[0] < 3:
raise Exception("Please use Python 3 to run this version of POVME.")
# First, check if running in test mode.
testing_mode = False
if "--test" in parameters:
setup_testing_dir(
["/examples/POVME_Pocket_ID_example/" + f for f in ["rel1_example.pdb"]]
)
# Keep track that running in testing mode.
testing_mode = True
# Change the argv list to run the copied ini file.
parameters = [
parameters[0],
"--filename",
"rel1_example.pdb",
"--pocket_detection_resolution",
"4.0",
"--pocket_measuring_resolution",
"1.0",
"--clashing_cutoff",
"3.0",
"--number_of_neighbors",
"4",
"--processors",
"4",
"--number_of_spheres",
"5",
"--sphere_padding",
"5.0",
]
# First, show a brief help file describing the command-line arguments.
help_lines = []
help_lines.append("")
......@@ -1583,6 +1618,22 @@ def run_pocket_id(parameters):
)
print("")
if testing_mode:
import glob
with open("pocket1.pdb") as f:
if not "PointsInclusionSphere" in f.read():
raise Exception(
"pocket1.pdb did not contain substring 'PointsInclusionSphere'"
)
num_output_files = len(glob.glob("*.pdb")) - 1
if num_output_files != 9:
raise Exception("Expected 9 output files, but got " + str(num_output_files))
delete_testing_dir()
test_passed()
if __name__ == "__main__":
dorun = run_pocket_id(sys.argv)
......@@ -18,13 +18,13 @@ import time
import numpy
from . import pymolecule
import os
import shutil
import random
import multiprocessing
import platform
from functools import reduce
from .__init__ import __version__
from .common import openfile, gzopenfile, fix_filename
from .common import openfile, gzopenfile, fix_filename, setup_testing_dir, delete_testing_dir, test_passed
import shutil
try:
from io import StringIO
......@@ -1093,9 +1093,7 @@ class MultithreadingStringToMoleculeTask(MultithreadingTaskGeneral):
if parameters["UseDiskNotMemory"] == False:
self.results.append((index, tmp))
else: # save to disk, record filename
pym_filename = (
"./.povme_tmp/frame_" + str(index) + ".pym"
)
pym_filename = "./.povme_tmp/frame_" + str(index) + ".pym"
tmp.fileio.save_pym(pym_filename, False, False, False, False, False)
self.results.append((index, pym_filename))
......@@ -1393,11 +1391,22 @@ class RunPOVME:
"""
# Make sure running Python3
if sys.version_info[0] < 3:
raise Exception("Please use Python 3 to run this version of POVME.")
start_time = time.time()
# First, check if running in test mode.
testing_mode = False
if "--test" in sys.argv:
print("Hi")
setup_testing_dir(["/examples/POVME_example/" + f for f in ["4NSS.pdb", "sample_POVME_input.ini"]])
# Keep track that running in testing mode.
testing_mode = True
# Change the argv list to run the copied ini file.
sys.argv[1] = "sample_POVME_input.ini"
# Load the configuration file
if len(argv) == 1:
......@@ -1431,7 +1440,8 @@ class RunPOVME:
"POVME_output."
+ time.strftime("%m-%d-%y")
+ "."
+ time.strftime("%H-%M-%S") + "/"
+ time.strftime("%H-%M-%S")
+ "/"
)
parameters["SaveIndividualPocketVolumes"] = False
parameters["SavePocketVolumesTrajectory"] = False
......@@ -1875,6 +1885,26 @@ class RunPOVME:
# import cPickle as pickle
# pickle.dump(all_pts, open('dill.pickle', 'w'))
# If running in testing mode, make sure things look alright.
if testing_mode:
import glob
expected_vols = set([1673.0, 1493.0, 1711.0, 1854.0, 2023.0])
actual_vols = set(results_dic.values())
if len(actual_vols - expected_vols) > 0:
raise Exception(
"Expected volumes to be "
+ str(expected_vols)
+ ", but got "
+ str(actual_vols)
)
num_output_files = len(glob.glob("POVME_test_run/*"))
if num_output_files != 12:
raise Exception(
"Expected 12 output files, but got " + str(num_output_files)
)
# Remove testing directory.
delete_testing_dir()
if __name__ == "__main__":
dorun = RunPOVME(sys.argv)
test_passed()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment