Ejemplo n.º 1
0
    def modelling(self, optd, rosetta_modeller=None):
        if not (optd['make_frags'] or optd['make_models']
                or optd['nmr_remodel']):
            return
        # Set the direcotry where the final models will end up
        optd['models_dir'] = os.path.join(optd['work_dir'], 'models')
        if not os.path.isdir(optd['models_dir']):
            os.mkdir(optd['models_dir'])
        if not rosetta_modeller:
            rosetta_modeller = options_processor.process_rosetta_options(optd)
        # Make Rosetta fragments
        if optd['make_frags']:
            rosetta_modeller.generate_fragments(optd)
            optd['frags_3mers'] = rosetta_modeller.frags_3mers
            optd['frags_9mers'] = rosetta_modeller.frags_9mers
            optd['psipred_ss2'] = rosetta_modeller.psipred_ss2

        con_util = self.handle_contacts(optd)
        if optd['restraints_file']:
            rosetta_modeller.restraints_file = optd['restraints_file']

        if optd['make_models']:
            logger.info('----- making Rosetta models--------')
            logger.info('Making %s models...', optd['nmodels'])
            try:
                optd['processed_models'] = rosetta_modeller.ab_initio_model(
                    processed_models=optd['processed_models'])
            except Exception as e:
                msg = "Error running ROSETTA to create models: {0}".format(e)
                exit_util.exit_error(msg, sys.exc_info()[2])
            logger.info('Modelling complete - models stored in: %s',
                        optd['models_dir'])

        # Sub-select the decoys using contact information
        if con_util and optd['subselect_mode'] and not (optd['nmr_model_in'] or
                                                        optd['nmr_remodel']):
            logger.info(
                'Subselecting models from directory using provided contact information'
            )
            subselect_data = con_util.subselect_decoys(
                optd['processed_models'],
                'pdb',
                mode=optd['subselect_mode'],
                **optd)
            optd['processed_models'] = zip(*subselect_data)[0]
            optd['subselect_data'] = dict(subselect_data)
Ejemplo n.º 2
0
    def modelling(self, optd, rosetta_modeller=None):
        if not (optd['make_frags'] or optd['make_models'] or optd['nmr_remodel']):
            return
        # Set the direcotry where the final models will end up
        optd['models_dir'] = os.path.join(optd['work_dir'], 'models')
        if not os.path.isdir(optd['models_dir']):
            os.mkdir(optd['models_dir'])
        if not rosetta_modeller:
            rosetta_modeller = options_processor.process_rosetta_options(optd)
        # Make Rosetta fragments
        if optd['make_frags']:
            rosetta_modeller.generate_fragments(optd)
            optd['frags_3mers'] = rosetta_modeller.frags_3mers
            optd['frags_9mers'] = rosetta_modeller.frags_9mers
            optd['psipred_ss2'] = rosetta_modeller.psipred_ss2

        con_util = self.handle_contacts(optd)
        if optd['restraints_file']:
            rosetta_modeller.restraints_file = optd['restraints_file']

        if optd['make_models']:
            logger.info('----- making Rosetta models--------')
            logger.info('Making %s models...', optd['nmodels'])
            try:
                optd['processed_models'] = rosetta_modeller.ab_initio_model(processed_models = optd['processed_models'])
            except Exception as e:
                msg = "Error running ROSETTA to create models: {0}".format(e)
                exit_util.exit_error(msg, sys.exc_info()[2])
            logger.info('Modelling complete - models stored in: %s', optd['models_dir'])

        # Sub-select the decoys using contact information
        if con_util and optd['subselect_mode'] and not (optd['nmr_model_in'] or optd['nmr_remodel']):
            logger.info('Subselecting models from directory using provided contact information')
            subselect_data = con_util.subselect_decoys(optd['processed_models'], 'pdb', mode=optd['subselect_mode'], **optd)
            optd['processed_models'] = zip(*subselect_data)[0]
            optd['subselect_data'] = dict(subselect_data)
Ejemplo n.º 3
0
    def main(self, args=None):
        """Main AMPLE routine.

        We require this as the multiprocessing module (only on **!!*%$$!! Windoze)
        requires that the main module can be imported. We there need ample to be
        a python script that can be imported, hence the main routine with its
        calling protected by the if __name__=="__main__":...

        args is an option argument that can contain the command-line arguments
        for the program - required for testing.
        """
        argso = argparse_util.process_command_line(args=args)

        self.amopt = amopt = config_util.AMPLEConfigOptions()
        amopt.populate(argso)

        # Setup things like logging, file structure, etc...
        amopt.d = self.setup(amopt.d)
        rosetta_modeller = options_processor.process_rosetta_options(amopt.d)

        # Display the parameters used
        logger.debug(amopt.prettify_parameters())

        amopt.write_config_file()
        #######################################################
        # SCRIPT PROPER STARTS HERE
        time_start = time.time()

        # Create function for monitoring jobs - static function decorator?
        if self.ample_output:

            def monitor():
                return self.ample_output.display_results(amopt.d)
        else:
            monitor = None

        if amopt.d['benchmark_mode'] and amopt.d['native_pdb']:
            # Process the native before we do anything else
            benchmark_util.analysePdb(amopt.d)

        # Create constituent models from an NMR ensemble
        if amopt.d['nmr_model_in']:
            nmr_mdir = os.path.join(amopt.d['work_dir'], 'nmr_models')
            amopt.d['modelling_workdir'] = nmr_mdir
            logger.info(
                'Splitting NMR ensemble into constituent models in directory: {0}'
                .format(nmr_mdir))
            amopt.d['models'] = pdb_edit.split_pdb(amopt.d['nmr_model_in'],
                                                   directory=nmr_mdir,
                                                   strip_hetatm=True,
                                                   same_size=True)
            logger.info('NMR ensemble contained {0} models'.format(
                len(amopt.d['models'])))

        # Modelling business happens here
        self.modelling(amopt.d, rosetta_modeller)
        amopt.write_config_file()

        # Ensembling business next
        if amopt.d['make_ensembles']:
            self.ensembling(amopt.d)
            amopt.write_config_file()

        # Some MR here
        if amopt.d['do_mr']:
            self.molecular_replacement(amopt.d)
            amopt.write_config_file()

        # Timing data
        time_stop = time.time()
        elapsed_time = time_stop - time_start
        run_in_min = elapsed_time / 60
        run_in_hours = run_in_min / 60
        msg = os.linesep + \
            'All processing completed  (in {0:6.2F} hours)'.format(
                run_in_hours) + os.linesep
        msg += '----------------------------------------' + os.linesep
        logging.info(msg)

        # Benchmark mode
        if amopt.d['benchmark_mode']:
            self.benchmarking(amopt.d)
            amopt.write_config_file()

        amopt.write_config_file()
        # Flag to show that we reached the end without error - useful for integration testing
        amopt.d['AMPLE_finished'] = True
        ample_util.save_amoptd(amopt.d)

        logger.info("AMPLE finished at: %s",
                    time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
        ref_mgr = reference_manager.ReferenceManager(amopt.d)
        ref_mgr.save_citations_to_file(amopt.d)
        logger.info(ref_mgr.citations_as_text)
        logger.info(reference_manager.footer)

        # Finally update pyrvapi results
        if self.ample_output:
            self.ample_output.display_results(amopt.d)
            self.ample_output.rvapi_shutdown(amopt.d)

        self.cleanup(amopt.d)
        return
Ejemplo n.º 4
0
    def modelling(self, optd, rosetta_modeller=None):
        if not (optd['import_models'] or optd['make_frags']
                or optd['make_models'] or optd['nmr_remodel']):
            return
        # Set the direcotry where the final models will end up
        optd['models_dir'] = os.path.join(optd['work_dir'], 'models')
        if not os.path.isdir(optd['models_dir']):
            os.mkdir(optd['models_dir'])
        if not rosetta_modeller:
            rosetta_modeller = options_processor.process_rosetta_options(optd)
        # Make Rosetta fragments
        if optd['make_frags']:
            rosetta_modeller.generate_fragments(optd)
            optd['frags_3mers'] = rosetta_modeller.frags_3mers
            optd['frags_9mers'] = rosetta_modeller.frags_9mers
            optd['psipred_ss2'] = rosetta_modeller.psipred_ss2

        if optd["use_contacts"] and not optd['restraints_file']:
            con_util = contact_util.ContactUtil(
                optd['fasta'],
                'fasta',
                contact_file=optd['contact_file'],
                contact_format=optd['contact_format'],
                bbcontacts_file=optd['bbcontacts_file'],
                bbcontacts_format=optd["bbcontacts_format"],
                cutoff_factor=optd['restraints_factor'],
                distance_to_neighbor=optd['distance_to_neighbour'])

            optd["contacts_dir"] = os.path.join(optd["work_dir"], "contacts")
            if not os.path.isdir(optd["contacts_dir"]):
                os.mkdir(optd["contacts_dir"])
            if con_util.require_contact_prediction:
                if con_util.found_ccmpred_contact_prediction_deps:
                    con_util.predict_contacts_from_sequence(
                        wdir=optd["contacts_dir"])
                    optd["contact_file"] = con_util.contact_file
                    optd["contact_format"] = con_util.contact_format

            if con_util.do_contact_analysis:
                plot_file = os.path.join(optd['contacts_dir'],
                                         optd['name'] + ".cm.png")
                if optd['native_pdb'] and optd['native_pdb_std']:
                    structure_file = optd['native_pdb_std']
                elif optd["native_pdb"]:
                    structure_file = optd['native_std']
                else:
                    structure_file = None
                optd['contact_map'], optd['contact_ppv'] = con_util.summarize(
                    plot_file, structure_file, 'pdb', optd['native_cutoff'])

                restraints_file = os.path.join(optd['contacts_dir'],
                                               optd['name'] + ".cst")
                optd['restraints_file'] = con_util.write_restraints(
                    restraints_file, optd['restraints_format'],
                    optd['energy_function'])
            else:
                con_util = None
        else:
            con_util = None

        if optd['make_models'] and optd['restraints_file']:
            rosetta_modeller.restraints_file = optd['restraints_file']

        if optd['make_models']:
            logger.info('----- making Rosetta models--------')
            if optd['nmr_remodel']:
                try:
                    optd['models'] = rosetta_modeller.nmr_remodel(
                        models=optd['models'],
                        ntimes=optd['nmr_process'],
                        alignment_file=optd['alignment_file'],
                        remodel_fasta=optd['nmr_remodel_fasta'],
                        monitor=monitor)
                except Exception as e:
                    msg = "Error remodelling NMR ensemble: {0}".format(e)
                    exit_util.exit_error(msg, sys.exc_info()[2])
            else:
                logger.info('making %s models...', optd['nmodels'])
                try:
                    optd['models'] = rosetta_modeller.ab_initio_model(
                        monitor=monitor)
                except Exception as e:
                    msg = "Error running ROSETTA to create models: {0}".format(
                        e)
                    exit_util.exit_error(msg, sys.exc_info()[2])
                if not pdb_edit.check_pdb_directory(optd['models_dir'],
                                                    sequence=optd['sequence']):
                    msg = "Problem with rosetta pdb files - please check the log for more information"
                    exit_util.exit_error(msg)
                logger.info('Modelling complete - models stored in: %s\n',
                            optd['models_dir'])

        elif optd['import_models']:
            logger.info('Importing models from directory: %s\n',
                        optd['models_dir'])
            if optd['homologs']:
                optd['models'] = ample_util.extract_and_validate_models(
                    optd, sequence=None, single=True, allsame=False)
            else:
                optd['models'] = ample_util.extract_and_validate_models(optd)
                # Need to check if Quark and handle things accordingly
                if optd['quark_models']:
                    # We always add sidechains to QUARK models if SCWRL is installed
                    if ample_util.is_exe(optd['scwrl_exe']):
                        optd['use_scwrl'] = True
                    else:
                        # No SCWRL so don't do owt with the side chains
                        logger.info(
                            'Using QUARK models but SCWRL is not installed '
                            'so only using %s sidechains', UNMODIFIED)
                        optd['side_chain_treatments'] = [UNMODIFIED]

        # Sub-select the decoys using contact information
        if con_util and optd['subselect_mode'] and not (optd['nmr_model_in'] or
                                                        optd['nmr_remodel']):
            logger.info('Subselecting models from directory using '
                        'provided contact information')
            subselect_data = con_util.subselect_decoys(
                optd['models'], 'pdb', mode=optd['subselect_mode'], **optd)
            optd['models'] = zip(*subselect_data)[0]
            optd['subselect_data'] = dict(subselect_data)

        ample_util.save_amoptd(optd)
Ejemplo n.º 5
0
    def main(self, args=None):
        """Main AMPLE routine.

        We require this as the multiprocessing module (only on **!!*%$$!! Windoze)
        requires that the main module can be imported. We there need ample to be
        a python script that can be imported, hence the main routine with its
        calling protected by the if __name__=="__main__":...

        args is an option argument that can contain the command-line arguments
        for the program - required for testing.
        """
        argso = argparse_util.process_command_line(args=args)
        # Work directory and loggers need to be setup before we do anything else
        self.setup_workdir(argso)
        global logger
        logger = logging_util.setup_logging(argso)

        # Logging and work directories in place so can start work
        self.amopt = amopt = config_util.AMPLEConfigOptions()
        amopt.populate(argso)
        amopt.d = self.setup(amopt.d)
        rosetta_modeller = options_processor.process_rosetta_options(amopt.d)
        logger.debug(
            amopt.prettify_parameters())  # Display the parameters used
        amopt.write_config_file()
        time_start = time.time()
        if self.ample_output:

            def monitor():
                return self.ample_output.display_results(amopt.d)

        else:
            monitor = None

        # Highlight deprecated command line arguments
        if amopt.d['submit_cluster']:
            message = "-%s has been deprecated and will be removed in version %s!" % (
                'submit_cluster', 1.6)
            warnings.warn(message, DeprecationWarning)
        if amopt.d["submit_pe_lsf"]:
            message = "-%s has been deprecated and will be removed in version %s! Use -submit_pe instead" % (
                'submit_pe_lsf', 1.6)
            warnings.warn(message, DeprecationWarning)
        if amopt.d["submit_pe_sge"]:
            message = "-%s has been deprecated and will be removed in version %s! Use -submit_pe instead" % (
                'submit_pe_sge', 1.6)
            warnings.warn(message, DeprecationWarning)

        # Process any files we may have been given
        model_results = process_models.extract_and_validate_models(amopt.d)
        if model_results:
            process_models.handle_model_import(amopt.d, model_results)
        if amopt.d['benchmark_mode'] and amopt.d['native_pdb']:
            # Process the native before we do anything else
            benchmark_util.analysePdb(amopt.d)

        # Create constituent models from an NMR ensemble
        if amopt.d['nmr_model_in']:
            nmr_mdir = os.path.join(amopt.d['work_dir'], 'nmr_models')
            amopt.d['modelling_workdir'] = nmr_mdir
            logger.info(
                'Splitting NMR ensemble into constituent models in directory: {0}'
                .format(nmr_mdir))
            amopt.d['processed_models'] = pdb_edit.split_pdb(
                amopt.d['nmr_model_in'],
                directory=nmr_mdir,
                strip_hetatm=True,
                same_size=True)
            logger.info('NMR ensemble contained {0} models'.format(
                len(amopt.d['processed_models'])))

        # Modelling business happens here
        if self.modelling_required(amopt.d):
            self.modelling(amopt.d, rosetta_modeller)
            ample_util.save_amoptd(amopt.d)
            amopt.write_config_file()

        # Ensembling business next
        if amopt.d['make_ensembles']:
            self.ensembling(amopt.d)
            amopt.write_config_file()

        # Some MR here
        if amopt.d['do_mr']:
            self.molecular_replacement(amopt.d)
            amopt.write_config_file()

        # Timing data
        time_stop = time.time()
        elapsed_time = time_stop - time_start
        run_in_min = elapsed_time / 60
        run_in_hours = run_in_min / 60
        msg = os.linesep + 'All processing completed  (in {0:6.2F} hours)'.format(
            run_in_hours) + os.linesep
        msg += '----------------------------------------' + os.linesep
        logging.info(msg)

        # Benchmark mode
        if amopt.d['benchmark_mode']:
            self.benchmarking(amopt.d)
            amopt.write_config_file()

        amopt.write_config_file()
        # Flag to show that we reached the end without error - useful for integration testing
        amopt.d['AMPLE_finished'] = True
        ample_util.save_amoptd(amopt.d)

        logger.info("AMPLE finished at: %s",
                    time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
        ref_mgr = reference_manager.ReferenceManager(amopt.d)
        ref_mgr.save_citations_to_file(amopt.d)
        logger.info(ref_mgr.citations_as_text)
        logger.info(reference_manager.footer)

        # Finally update pyrvapi results
        if self.ample_output:
            self.ample_output.display_results(amopt.d)
            self.ample_output.rvapi_shutdown(amopt.d)

        self.cleanup(amopt.d)
        return
Ejemplo n.º 6
0
    def main(self, args=None):
        """Main AMPLE routine.

        We require this as the multiprocessing module (only on **!!*%$$!! Windoze)
        requires that the main module can be imported. We there need ample to be
        a python script that can be imported, hence the main routine with its
        calling protected by the if __name__=="__main__":...

        args is an option argument that can contain the command-line arguments
        for the program - required for testing.
        """
        argso = argparse_util.process_command_line(args=args)
        # SWork directory and loggers need to be setup before we do anything else
        self.setup_workdir(argso)
        global logger
        logger = logging_util.setup_logging(argso)
        
        # Logging and work directories in place so can start work
        self.amopt = amopt = config_util.AMPLEConfigOptions()
        amopt.populate(argso)
        amopt.d = self.setup(amopt.d)
        rosetta_modeller = options_processor.process_rosetta_options(amopt.d)

        # Display the parameters used
        logger.debug(amopt.prettify_parameters())

        amopt.write_config_file()
        #######################################################
        # SCRIPT PROPER STARTS HERE
        time_start = time.time()

        # Create function for monitoring jobs - static function decorator?
        if self.ample_output:
            def monitor():
                return self.ample_output.display_results(amopt.d)
        else:
            monitor = None
            
        # Process any files we may have been given
        model_results = process_models.extract_and_validate_models(amopt.d)
        if model_results:
            process_models.handle_model_import(amopt.d, model_results)
        
        if amopt.d['benchmark_mode'] and amopt.d['native_pdb']:
            # Process the native before we do anything else
            benchmark_util.analysePdb(amopt.d)

        # Create constituent models from an NMR ensemble
        if amopt.d['nmr_model_in']:
            nmr_mdir = os.path.join(amopt.d['work_dir'], 'nmr_models')
            amopt.d['modelling_workdir'] = nmr_mdir
            logger.info('Splitting NMR ensemble into constituent models in directory: {0}'.format(nmr_mdir))
            amopt.d['processed_models'] = pdb_edit.split_pdb(
                amopt.d['nmr_model_in'], directory=nmr_mdir, strip_hetatm=True, same_size=True)
            logger.info('NMR ensemble contained {0} models'.format(len(amopt.d['processed_models'])))

        # Modelling business happens here
        if self.modelling_required(amopt.d):
            self.modelling(amopt.d, rosetta_modeller)
            ample_util.save_amoptd(amopt.d)
            amopt.write_config_file()

        # Ensembling business next
        if amopt.d['make_ensembles']:
            self.ensembling(amopt.d)
            amopt.write_config_file()

        # Some MR here
        if amopt.d['do_mr']:
            self.molecular_replacement(amopt.d)
            amopt.write_config_file()

        # Timing data
        time_stop = time.time()
        elapsed_time = time_stop - time_start
        run_in_min = elapsed_time / 60
        run_in_hours = run_in_min / 60
        msg = os.linesep + \
            'All processing completed  (in {0:6.2F} hours)'.format(
                run_in_hours) + os.linesep
        msg += '----------------------------------------' + os.linesep
        logging.info(msg)

        # Benchmark mode
        if amopt.d['benchmark_mode']:
            self.benchmarking(amopt.d)
            amopt.write_config_file()

        amopt.write_config_file()
        # Flag to show that we reached the end without error - useful for integration testing
        amopt.d['AMPLE_finished'] = True
        ample_util.save_amoptd(amopt.d)

        logger.info("AMPLE finished at: %s", time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()))
        ref_mgr = reference_manager.ReferenceManager(amopt.d)
        ref_mgr.save_citations_to_file(amopt.d)
        logger.info(ref_mgr.citations_as_text)
        logger.info(reference_manager.footer)

        # Finally update pyrvapi results
        if self.ample_output:
            self.ample_output.display_results(amopt.d)
            self.ample_output.rvapi_shutdown(amopt.d)
        
        self.cleanup(amopt.d)
        return