1010import glob
1111import random
1212import string
13- import sys
13+ # import sys
1414import shutil
1515
1616from prepmd import download
2020
2121parser = argparse .ArgumentParser (prog = "prepmd" ,
2222 description = "Get structures from the PDB ready for "
23- "molecular dynamics runs" ,
24- epilog = "Also, run 'prepmd test' for the test suite" )
23+ "molecular dynamics runs" )
24+ # epilog="Also, run 'prepmd test' for the test suite")
2525parser .add_argument ("code" , help = "4 or 12-character PDB code" )
2626parser .add_argument ("out" , help = "Output filename" )
2727parser .add_argument ("-w" , "--wdir" , help = "Working directory" )
@@ -94,14 +94,16 @@ def prep(code, outmodel, workingdir, folder=None, fastafile=None, inmodel=None,
9494 Returns:
9595 nothing, but writes out a file to outmodel.
9696 """
97-
97+
9898 # infer download format from output format
9999 if not download_format :
100100 if (".pdb" ) in outmodel :
101101 download_format = "pdb"
102+ print ("No download format specified, downloading PDB." )
102103 elif (".cif" ) in outmodel or ".mmcif" in outmodel or (
103104 ".pdbx" ) in outmodel :
104105 download_format = "mmCif"
106+ print ("No download format specified, downloading mmCif." )
105107
106108 # check that input/output are specified in the same format
107109 # i'm not against converting the files but it shouldn't happen implicitly
@@ -148,6 +150,7 @@ def prep(code, outmodel, workingdir, folder=None, fastafile=None, inmodel=None,
148150 print ("Downloading structure file" )
149151 inmodel = download .get_structure (
150152 code , workingdir , file_format = download_format )
153+ print ("Downloaded to " + inmodel )
151154
152155 # fix
153156 if not fix_after :
@@ -201,9 +204,9 @@ def prep(code, outmodel, workingdir, folder=None, fastafile=None, inmodel=None,
201204
202205def entry_point ():
203206 "CLI entry point function. Uses sys.argv and argparse args object."
204- if len (sys .argv ) == 2 :
205- if sys .argv [1 ] == "test" :
206- tests ()
207+ # if len(sys.argv) == 2:
208+ # if sys.argv[1] == "test":
209+ # tests()
207210 args = parser .parse_args ()
208211 fix_after = not args .fixstart
209212 if args .wdir is None :
@@ -228,80 +231,82 @@ def test_minimise():
228231 os .getcwd ()+ os .path .sep + "6TY4" + "_" + genid + ".cif" ,
229232 os .getcwd ()+ os .path .sep + "testout" + os .path .sep + "6TY4" + "_" + genid )
230233
231- def tests ():
232- os .system ("" )
233- class style ():
234- RED = '\033 [31m'
235- GREEN = '\033 [32m'
236- YELLOW = '\033 [33m'
237- BLUE = '\033 [34m'
238- MAGENTA = '\033 [35m'
239- CYAN = '\033 [36m'
240- WHITE = '\033 [37m'
241- UNDERLINE = '\033 [4m'
242- RESET = '\033 [0m'
243234
244- #testinputs = ["6xov", "9CS5", "8RM8", ]#"8VV2", "9B8B", "8CAE", "8QZA", "8RTL", "8RTO", "9A9W"] # regular pdbs
245- #testinputs = ["6TY4", "6XOV", "9CS5", "8CAE", "8QZA", "8RTO"]
235+ # note: deprecated now that ctest support has been added
236+ # will be removed!!!
237+
238+ # def tests():
239+ # os.system("")
240+ # class style():
241+ # RED = '\033[31m'
242+ # GREEN = '\033[32m'
243+ # YELLOW = '\033[33m'
244+ # BLUE = '\033[34m'
245+ # MAGENTA = '\033[35m'
246+ # CYAN = '\033[36m'
247+ # WHITE = '\033[37m'
248+ # UNDERLINE = '\033[4m'
249+ # RESET = '\033[0m'
246250
247- tests = [
248- {"id" : "6TY4" , "format" :"pdb" },
249- {"id" : "6XOV" , "format" :"pdb" },
250- {"id" : "9CS5" , "format" :"pdb" },
251- {"id" : "8CAE" , "format" :"pdb" },
252- {"id" : "8QZA" , "format" :"pdb" },
253- {"id" : "8RTO" , "format" :"mmCif" },
254- {"id" : "7IB8" , "format" :"mmCif" },
255- {"id" : "9A9G" , "format" :"mmCif" },
256- {"id" : "9I3U" , "format" :"pdb" },
257- #test_minimise,
258- #test_mmcif_support
259- ]
260- #testinputs = ["8rto"]
251+ # tests = [
252+ # # {"id": "6TY4", "format":"pdb"},
253+ # # {"id": "6XOV", "format":"pdb"},
254+ # {"id": "9CS5", "format":"pdb"},
255+ # {"id": "8CAE", "format":"pdb"},
256+ # {"id": "8QZA", "format":"pdb"},
257+ # {"id": "8RTO", "format":"mmCif"},
258+ # {"id": "7IB8", "format":"mmCif"},
259+ # {"id": "9A9G", "format":"mmCif"},
260+ # {"id": "9I3U", "format":"pdb"},
261+ # #test_minimise,
262+ # #test_mmcif_support
263+ # ]
261264
262- results = {}
263- state = 0
264- cwd = os .getcwd ()
265+ # types = {"mmCif":"cif", "cif":"cif", "pdb":"pdb"}
266+
267+ # results = {}
268+ # state = 0
269+ # cwd = os.getcwd()
265270
266- for test in range (len (tests )):
267- try :
268- os .chdir (cwd )
269- code = tests [test ]["id" ]
270- curr_format = tests [test ]["format" ]
271- print (f"Testing { code } ({ test } /{ len (tests )} )" )
272- genid = id_generator (6 )
273- pathlib .Path (os .getcwd ()+ os .path .sep + "testout" ).mkdir (
274- parents = True , exist_ok = True )
275- if type (tests [test ]) == dict :
276- prep (code ,
277- os .getcwd ()+ os .path .sep + code + "_" + genid + "." + "cif" ,
278- os .getcwd ()+ os .path .sep + "testout" + os .path .sep + code + "_" + genid ,
279- download_format = curr_format )
280- elif callable (tests [test ]):
281- test ()
282- print (f"{ style .GREEN } PASSED: { test } { style .RESET } " )
283- results [code ] = "PASS"
284- except Exception as e :
285- print (f"{ style .RED } FAILED: { test } { style .RESET } " )
286- results [code ] = e
287- state = 1
288- print ("" )
289- print ("RESULTS:" )
290- for name , result in results .items ():
291- if result == "PASS" :
292- print (f"{ name } : { style .GREEN } { result } { style .RESET } " )
293- else :
294- errtype = type (result ).__name__ , # TypeError
295- errfile = __file__ , # /tmp/example.py
296- errline = result .__traceback__ .tb_lineno # 2
297- error = str (errtype )+ " on line " + \
298- str (errline )+ " in " + str (errfile )
299- print (f"{ name } : { style .RED } { error } { style .RESET } " )
300- for name , result in results .items ():
301- if result != "PASS" :
302- print (f"{ style .YELLOW } { name } exception: { result } { style .RESET } " )
271+ # for test in range(len(tests)):
272+ # try:
273+ # os.chdir(cwd)
274+ # code = tests[test]["id"]
275+ # curr_format = tests[test]["format"]
276+ # print(f"Testing {code} ({test}/{len(tests)})")
277+ # genid = id_generator(6)
278+ # pathlib.Path(os.getcwd()+os.path.sep+"testout").mkdir(
279+ # parents=True, exist_ok=True)
280+ # if type(tests[test]) == dict:
281+ # prep(code,
282+ # os.getcwd()+os.path.sep+code+"_"+genid+"."+types[curr_format] ,
283+ # os.getcwd()+os.path.sep+"testout"+os.path.sep+code+"_"+genid,
284+ # download_format=curr_format)
285+ # elif callable(tests[test]):
286+ # test()
287+ # print(f"{style.GREEN}PASSED: {test} {style.RESET}")
288+ # results[code] = "PASS"
289+ # except Exception as e:
290+ # print(f"{style.RED}FAILED: {test}{style.RESET}")
291+ # results[code] = e
292+ # state = 1
293+ # print("")
294+ # print("RESULTS:")
295+ # for name, result in results.items():
296+ # if result == "PASS":
297+ # print(f"{name}: {style.GREEN}{result}{style.RESET}")
298+ # else:
299+ # errtype = type(result).__name__, # TypeError
300+ # errfile = __file__, # /tmp/example.py
301+ # errline = result.__traceback__.tb_lineno # 2
302+ # error = str(errtype)+" on line " + \
303+ # str(errline)+" in "+str(errfile)
304+ # print(f"{name}: {style.RED}{error}{style.RESET}")
305+ # for name, result in results.items():
306+ # if result != "PASS":
307+ # print(f"{style.YELLOW}{name} exception: {result}{style.RESET}")
303308
304- sys .exit (state )
309+ # sys.exit(state)
305310
306311if __name__ == "__main__" :
307312 entry_point ()
0 commit comments