예제 #1
0
파일: main.py 프로젝트: tiger-tiger/ample
    def setup(self, optd):
        """We take and return an ample dictionary as an argument.

        This is required because options_processor.process_restart_options Changes what
        optd points at, and this means that if we just use the reference, we end up
        pointing at the old, obsolete dictionary

        """
        optd = options_processor.restart_amoptd(optd)

        # Make a work directory - this way all output goes into this directory
        if optd['work_dir'] and not optd['restart_pkl']:
            logger.info('Making a named work directory: %s', optd['work_dir'])
            try:
                os.mkdir(optd['work_dir'])
            except Exception as e:
                msg = "Cannot create work_dir {0}: {1}".format(
                    optd['work_dir'], e)
                exit_util.exit_error(msg, sys.exc_info()[2])

        if not optd['work_dir']:
            if not os.path.exists(optd['run_dir']):
                msg = 'Cannot find run directory: {0}'.format(optd['run_dir'])
                exit_util.exit_error(msg, sys.exc_info()[2])

            if bool(optd['rvapi_document']):
                # With JSCOFE we run in the run directory
                optd['work_dir'] = optd['run_dir']
            else:
                logger.info('Making a run directory: '
                            'checking for previous runs...')
                optd['work_dir'] = ample_util.make_workdir(
                    optd['run_dir'], ccp4i2=bool(optd['ccp4i2_xml']))

        os.chdir(optd['work_dir'])

        ample_log = os.path.join(optd['work_dir'], 'AMPLE.log')
        debug_log = os.path.join(optd['work_dir'], 'debug.log')
        optd['ample_log'] = ample_log

        logging_util.setup_file_logging(ample_log, level=logging.INFO)
        logging_util.setup_file_logging(debug_log, level=logging.DEBUG)

        optd['ccp4_version'] = ample_util.CCP4.version.version

        logger.info(reference_manager.header)
        logger.info("AMPLE version: %s", str(version.__version__))
        logger.info("Running with CCP4 version: %s from directory: %s",
                    ample_util.CCP4.version, ample_util.CCP4.root)
        logger.info("Running on host: %s", platform.node())
        logger.info("Running on platform: %s", platform.platform())
        logger.info("Job started at: %s",
                    time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
        logger.info("Invoked with command-line:\n%s\n", " ".join(sys.argv))
        logger.info("Running in directory: %s\n", optd['work_dir'])

        if pyrvapi_results.pyrvapi:
            self.ample_output = pyrvapi_results.AmpleOutput(optd)
            self.ample_output.display_results(optd)

        options_processor.check_mandatory_options(optd)

        optd = options_processor.process_restart_options(optd)
        if not optd['restart_pkl']:
            options_processor.process_options(optd)

        if optd['dry_run']:
            logger.info('Dry run finished checking options - cleaning up...')
            os.chdir(optd['run_dir'])
            shutil.rmtree(optd['work_dir'])
            sys.exit(0)

        logger.info('All needed programs are found, continuing...')
        return optd
예제 #2
0
    def setup(self, optd):
        """We take and return an ample dictionary as an argument. This is required because options_processor.process_restart_options
        Changes what optd points at, and this means that if we just use the reference, we end up pointing at the old, obselete dictionary"""

        # Update the ample dictionary in case we are restarting
        optd = options_processor.restart_amoptd(optd)

        # Make a work directory - this way all output goes into this directory
        if optd['work_dir'] and not optd['restart_pkl']:
            logger.info('Making a named work directory: {0}'.format(
                optd['work_dir']))
            try:
                os.mkdir(optd['work_dir'])
            except Exception as e:
                msg = "Cannot create work_dir {0}: {1}".format(
                    optd['work_dir'], e)
                exit_util.exit_error(msg, sys.exc_info()[2])

        if not optd['work_dir']:
            if not os.path.exists(optd['run_dir']):
                msg = 'Cannot find run directory: {0}'.format(optd['run_dir'])
                exit_util.exit_error(msg, sys.exc_info()[2])

            if bool(optd['rvapi_document']):
                # With JSCOFE we run in the run directory
                optd['work_dir'] = optd['run_dir']
            else:
                logger.info(
                    'Making a run directory: checking for previous runs...')
                optd['work_dir'] = ample_util.make_workdir(
                    optd['run_dir'], ccp4i2=bool(optd['ccp4i2_xml']))
        # Go to the work directory
        os.chdir(optd['work_dir'])

        # Set up logging
        ample_log = os.path.join(optd['work_dir'], 'AMPLE.log')
        debug_log = os.path.join(optd['work_dir'], 'debug.log')
        optd['ample_log'] = ample_log

        # Set up ample output file and debug log file.
        logging_util.setup_file_logging(ample_log, level=logging.INFO)
        logging_util.setup_file_logging(debug_log, level=logging.DEBUG)

        # Make sure the CCP4 environment is set up properly
        ccp4_home = self.setup_ccp4(optd)
        ccp4_version = ".".join([str(x) for x in optd['ccp4_version']])

        # Print out Version and invocation
        logger.info(ample_util.header)
        logger.info("AMPLE version: {0}".format(version.__version__))
        logger.info(
            "Running with CCP4 version: {0} from directory: {1}".format(
                ccp4_version, ccp4_home))
        logger.info("Running on host: {0}".format(platform.node()))
        logger.info("Running on platform: {0}".format(platform.platform()))
        logger.info("Job started at: {0}".format(
            time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())))
        logger.info("Invoked with command-line:\n{0}\n".format(" ".join(
            sys.argv)))
        logger.info("Running in directory: {0}\n".format(optd['work_dir']))

        # Display pyrvapi results
        if pyrvapi_results.pyrvapi:
            self.ample_output = pyrvapi_results.AmpleOutput(optd)
            self.ample_output.display_results(optd)

        # Check mandatory/exclusive options
        options_processor.check_mandatory_options(optd)

        # Check if we are restarting from an existing pkl file - we don't process the options from this
        # run if so
        optd = options_processor.process_restart_options(optd)
        if not optd['restart_pkl']:
            # Only process the remaining options if we aren't in restart mode
            options_processor.process_options(optd)

        # Bail and clean up if we were only checking the options
        if optd['dry_run']:
            logger.info('Dry run finished checking options - cleaning up...')
            os.chdir(optd['run_dir'])
            shutil.rmtree(optd['work_dir'])
            sys.exit(0)

        logger.info('All needed programs are found, continuing...')

        return optd
예제 #3
0
if not restart and not ('models' in optd and optd['models'] and os.path.exists(optd['models'])):
    msg = 'AMPLE ensembler requires a -models argument with a file/directory of pdbs'
    exit_util.exit_error(msg, sys.exc_info()[2])

# Set up the working directory if one doesn't already exist
if not ('work_dir' in optd and optd['work_dir']):
    optd['work_dir'] = os.path.join(os.path.abspath(os.path.curdir), ENSEMBLE_DIRNAME)
if not os.path.isdir(optd['work_dir']):
    try:
        os.mkdir(optd['work_dir'])
    except OSError as e:
        msg = 'Error making ensemble workdir {0} : {1}'.format(optd['work_dir'], e)
        exit_util.exit_error(msg, sys.exc_info()[2])

assert os.path.isdir(optd['work_dir'])

# Start logging to a file
logging_util.setup_file_logging(os.path.join(optd['work_dir'], "ensemble.log"))
try:
    if not restart:
        results = process_models.extract_and_validate_models(optd)
        process_models.handle_model_import(optd, results)
        process_ensemble_options(optd)
        optd['ensemble_ok'] = os.path.join(optd['work_dir'], 'ensemble.ok')
        optd['results_path'] = os.path.join(optd['work_dir'], AMPLE_PKL)
    ensembler.create_ensembles(optd)
    ample_util.save_amoptd(optd)
except Exception as e:
    msg = "Error running ensembling: {0}".format(e.message)
    exit_util.exit_error(msg, sys.exc_info()[2])
예제 #4
0
# Set up the working directory if one doesn't already exist
if not ('work_dir' in optd and optd['work_dir']):
    optd['work_dir'] = os.path.join(os.path.abspath(os.path.curdir),
                                    ENSEMBLE_DIRNAME)
if not os.path.isdir(optd['work_dir']):
    try:
        os.mkdir(optd['work_dir'])
    except OSError as e:
        msg = 'Error making ensemble workdir {0} : {1}'.format(
            optd['work_dir'], e)
        exit_util.exit_error(msg, sys.exc_info()[2])

assert os.path.isdir(optd['work_dir'])

# Start logging to a file
logging_util.setup_file_logging(os.path.join(optd['work_dir'], "ensemble.log"))
try:
    if not restart:
        optd['models'] = ample_util.extract_models(optd)
        if optd['subcluster_program'] == 'gesamt':
            optd['gesamt_exe'] = ample_util.find_exe('gesamt')
        elif optd['subcluster_program'] == 'maxcluster':
            optd['maxcluster_exe'] = ample_util.find_exe('maxcluster')
        else:
            raise RuntimeError("Unknown subcluster_program: {0}".format(
                optd['subcluster_program']))
        optd['theseus_exe'] = ample_util.find_exe('theseus')
        optd['ensemble_ok'] = os.path.join(optd['work_dir'], 'ensemble.ok')
        optd['results_path'] = os.path.join(optd['work_dir'], AMPLE_PKL)
    ensembler.create_ensembles(optd)
    ample_util.save_amoptd(optd)