Source code for schrodinger.application.phase.packages.hypo_refine.job_utils
"""
Module with phase_hypo_refine job control functionality.
Copyright Schrodinger LLC, All Rights Reserved.
"""
from schrodinger.application.phase.packages import phase_utils
from schrodinger.application.phase.packages.hypo_refine import project_utils
from schrodinger.infra import phase
from schrodinger.job import jobcontrol
from schrodinger.utils import fileutils
[docs]def get_common_args(args):
"""
Returns a command containing arguments that are common to all subjobs.
:param args: argparser.Namespace with command line options
:type args: argparser.Namespace
:return: Command with common arguments
:rtype: list(str)
"""
common_args = []
for key, value in args.__dict__.items():
if key not in ("hypo", "actives", "decoys", "host"):
flag = "-" + key
if value is not None:
if value is True:
common_args.append(flag)
elif value is not False:
common_args.extend([flag, str(value)])
return common_args
[docs]def get_output_hypo(args):
"""
Returns the name of the hypothesis file to create.
:param args: Command line arguments
:type args: argparse.Namespace
:return: Output hypothesis file name
:rtype: str
"""
if args.subjob:
hypo_out = args.subjob + "-out" + phase.PHASE_HYPO_FILE_EXT
else:
hypo_out = args.o
if not hypo_out:
jobname = phase_utils.get_jobname(args, args.hypo)
hypo_out = jobname + "-out" + phase.PHASE_HYPO_FILE_EXT
return hypo_out
[docs]def get_output_projects(args):
"""
Returns the names of any zipped projects that would be created.
:param args: Command line arguments
:type args: argparse.Namespace
:return: Output zipped project names
:rtype: list(str)
"""
zipped_projects = []
for key, infile in project_utils.get_screen_dict(args).items():
if not phase_utils.is_phase_project_path(infile, zipped=True):
zipped_projects.append(
project_utils.derive_project_name(infile, zipped=True))
return zipped_projects
[docs]def remove_output_files(args):
"""
Removes output files that would be created in the launch directory by the
parent job.
:param args: Command line arguments
:type args: argparse.Namespace
"""
if not jobcontrol.under_job_control():
jobname = phase_utils.get_jobname(args, args.hypo)
fileutils.force_remove(jobname + ".log")
# Don't remove output hypothesis if the job is being run solely to
# create zipped active/decoy projects.
if not args.exit:
fileutils.force_remove(get_output_hypo(args))
# Remove any zipped projects that would be returned.
if args.save_projects:
for zipped_project in get_output_projects(args):
fileutils.force_remove(zipped_project)
[docs]def save_hypo_for_job(args, hypo):
"""
Saves the provided hypothesis as <jobname>.phypo and replaces args.hypo
with this file name.
:param args: Command line arguments
:type args: argparse.Namespace
:param hypo: Hypothesis
:type hypo: phase.PhpHypoAdaptor
"""
jobname = phase_utils.get_jobname(args, args.hypo)
args.hypo = jobname + phase.PHASE_HYPO_FILE_EXT
hypo.save(args.hypo, True)