Exemplo n.º 1
0
    def binary_avail(binary):
        """Check if TM binary is available

        Paramaters
        ----------
        binary : str
           The binary name of `TMscore` or `TMalign`

        Returns
        -------
        bool
        
        Raises
        ------
        ValueError
           The binary is not `TMalign` or `TMscore`

        """
        if binary.lower() == 'tmalign':
            exe_name = "TMalign" + ample_util.EXE_EXT
        elif binary.lower() == 'tmscore':
            exe_name = "TMscore" + ample_util.EXE_EXT
        else:
            raise ValueError('Provide one of TMalign or TMscore')
        try:
            ample_util.find_exe(exe_name)
        except:
            return False
        return True
Exemplo n.º 2
0
 def test_find_exe(self):
     gesamt_exe = os.path.basename(ample_util.find_exe("gesamt" + ample_util.EXE_EXT))
     self.assertEqual("gesamt" + ample_util.EXE_EXT, gesamt_exe)
     spicker_exe = os.path.basename(ample_util.find_exe("spicker" + ample_util.EXE_EXT))
     self.assertEqual("spicker" + ample_util.EXE_EXT, spicker_exe)
     theseus_exe = os.path.basename(ample_util.find_exe("theseus" + ample_util.EXE_EXT))
     self.assertEqual("theseus" + ample_util.EXE_EXT, theseus_exe)
Exemplo n.º 3
0
 def test_find_exe(self):
     gesamt_exe = os.path.basename(
         ample_util.find_exe("gesamt" + ample_util.EXE_EXT))
     self.assertEqual("gesamt" + ample_util.EXE_EXT, gesamt_exe)
     spicker_exe = os.path.basename(
         ample_util.find_exe("spicker" + ample_util.EXE_EXT))
     self.assertEqual("spicker" + ample_util.EXE_EXT, spicker_exe)
     theseus_exe = os.path.basename(
         ample_util.find_exe("theseus" + ample_util.EXE_EXT))
     self.assertEqual("theseus" + ample_util.EXE_EXT, theseus_exe)
Exemplo n.º 4
0
 def found_ccmpred_contact_prediction_deps(self):
     from ample.util.ample_util import FileNotFoundError
     found_ccmpred_exe = False
     found_hhblits_exe = False
     try:
         ample_util.find_exe("ccmpred")
         found_ccmpred_exe = True
         ample_util.find_exe("hhblits")
         found_hhblits_exe = True
     except FileNotFoundError:
         pass
     found_hhblitsdb = "HHBLITSDB" in os.environ
     return found_ccmpred_exe and found_hhblits_exe and found_hhblitsdb
Exemplo n.º 5
0
 def found_ccmpred_contact_prediction_deps(self):
     from ample.util.ample_util import FileNotFoundError
     found_ccmpred_exe = False
     found_hhblits_exe = False
     try:
         ample_util.find_exe("ccmpred")
         found_ccmpred_exe = True
         ample_util.find_exe("hhblits")
         found_hhblits_exe = True
     except FileNotFoundError:
         pass
     found_hhblitsdb = "HHBLITSDB" in os.environ
     return found_ccmpred_exe and found_hhblits_exe and found_hhblitsdb
Exemplo n.º 6
0
    def test_gesamt_radius(self):
        # Test we can reproduce the original thresholds
        gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
        clusterer = subcluster.GesamtClusterer(executable=gesamt_exe)
        pdb_list = glob.glob(
            os.path.join(self.testfiles_dir, "models", '*.pdb'))

        radius = 4
        clusterer.generate_distance_matrix(pdb_list, purge=True)
        cluster_files1 = set(
            [os.path.basename(x) for x in clusterer.cluster_by_radius(radius)])
        ref = set([
            '1_S_00000002.pdb',
            '1_S_00000004.pdb',
            '1_S_00000005.pdb',
            '2_S_00000001.pdb',
            '2_S_00000005.pdb',
            '3_S_00000003.pdb',
            '3_S_00000004.pdb',
            '3_S_00000006.pdb',
            '4_S_00000002.pdb',
            '4_S_00000005.pdb',
            '5_S_00000004.pdb',
            '5_S_00000005.pdb',
        ])
        # clusterer.dump_pdb_matrix('foo')
        self.assertEqual(0, len(ref - cluster_files1))
        return
Exemplo n.º 7
0
def ccmtzOrigin( nativeMap, mrPdb  ):
    """Use the phenix get_cc_mtz_pdb script to determine the origin of a MR pdb using the supplied map"""
    
    # resolve can only handle file names < 75 characters so we need to truncate
    # We copy the file rather than symlink so that this works on windows and then delete afterwards
    tempnam=None
    if len( os.path.basename(mrPdb) ) >= 75:
        tempnam = os.tempnam()
        # Need to add .pdb extension or it doesn't work
        tempnam += ".pdb"
        assert len(tempnam) < 75
        shutil.copy( mrPdb, tempnam )
        mrPdb = tempnam
        
    # make sure we can find the program
    get_cc_mtz_pdb=ample_util.find_exe('phenix.get_cc_mtz_pdb')
    cmd = [get_cc_mtz_pdb , nativeMap, mrPdb ]
    ret = ample_util.run_command(cmd=cmd, logfile="get_cc_mtz_pdb.log", dolog=False )
    assert ret == 0, "phenix.get_cc_mtz_pdb refmac failed!"
    
    ofile = "temp_dir/resolve.offset"
    with open( ofile ) as o:
        line = o.readline().strip()
    
    t = line.split()
    assert t[0] == "OFFSET"
    origin = [ float( t[1] ) * -1, float( t[2] ) * -1, float( t[3] ) * -1 ]
    
    # remove temp file if we created it
    if tempnam:
        os.unlink(tempnam)
    
    return origin
Exemplo n.º 8
0
def run(nativePdb, nativeMtz=None, nativeMap=None, mrPdbs=None, outDir=None):

    logging.info("Using native PDB file: %s", os.path.abspath(nativePdb))
    logging.info("Using native MTZ file: %s", os.path.abspath(nativeMtz))
    logging.info("Wrapping the following MTZ files to the native: %s",
                 " ".join(mrPdbs))

    phenix = False

    if outDir is not None:
        if not os.path.isdir(outDir):
            msg = "Cannot find output directory: {}".format(outDir)
            raise RuntimeError(msg)
        outDir = os.path.abspath(outDir)
    else:
        outDir = os.getcwd()

    if phenix:
        if nativeMap is None:
            nativeMap = generateMap(nativePdb, nativeMtz)
        if not os.path.isfile(nativeMap):
            msg = "Cannot find nativeMap: {}".format(nativeMap)
            raise RuntimeError(msg)
    else:
        shelxeExe = ample_util.find_exe('shelxe')

    removables = []
    for mrPdb in mrPdbs:
        if phenix:
            logging.debug("Searching for origin shift using: %s %s", nativeMap,
                          mrPdb)
            origin = phenixer.ccmtzOrigin(nativeMap, mrPdb)
            # offset.pdb is the mrPdb moved onto the new origin
            offsetPdb = "offset.pdb"
            logging.debug("Found origin: %s\nOffset pdb is: %s", origin,
                          offsetPdb)
        else:

            mrinfo = shelxe.MRinfo(shelxeExe, nativePdb, nativeMtz)
            mrinfo.analyse(mrPdb)
            originShift = mrinfo.originShift
            logging.debug("Found origin: {0}".format(originShift))
            offsetPdb = ample_util.filename_append(mrPdb,
                                                   astr='offset',
                                                   directory=os.getcwd())
            pdb_edit.translate(mrPdb, offsetPdb, originShift)

        csymmPdb = ample_util.filename_append(filename=mrPdb,
                                              astr="csymmatch",
                                              directory=outDir)
        logging.debug("Running csymmatch to wrap %s onto native %s", offsetPdb,
                      nativePdb)
        csymmatch.Csymmatch().run(refPdb=nativePdb,
                                  inPdb=offsetPdb,
                                  outPdb=csymmPdb,
                                  originHand=False)
        removables += [offsetPdb]
        logging.info("Matched PDB is: %s", csymmPdb)

    map(os.remove, removables + ["shelxe-input.hkl", "shelxe-input.ent"])
Exemplo n.º 9
0
def ccmtzOrigin(nativeMap, mrPdb):
    """Use the phenix get_cc_mtz_pdb script to determine the origin of a MR pdb using the supplied map"""

    # resolve can only handle file names < 75 characters so we need to truncate
    # We copy the file rather than symlink so that this works on windows and then delete afterwards
    tempnam = None
    if len(os.path.basename(mrPdb)) >= 75:
        tempnam = os.tempnam()
        # Need to add .pdb extension or it doesn't work
        tempnam += ".pdb"
        assert len(tempnam) < 75
        shutil.copy(mrPdb, tempnam)
        mrPdb = tempnam

    # make sure we can find the program
    get_cc_mtz_pdb = ample_util.find_exe('phenix.get_cc_mtz_pdb')
    cmd = [get_cc_mtz_pdb, nativeMap, mrPdb]
    ret = ample_util.run_command(cmd=cmd,
                                 logfile="get_cc_mtz_pdb.log",
                                 dolog=False)
    assert ret == 0, "phenix.get_cc_mtz_pdb refmac failed!"

    ofile = "temp_dir/resolve.offset"
    with open(ofile) as o:
        line = o.readline().strip()

    t = line.split()
    assert t[0] == "OFFSET"
    origin = [float(t[1]) * -1, float(t[2]) * -1, float(t[3]) * -1]

    # remove temp file if we created it
    if tempnam:
        os.unlink(tempnam)

    return origin
Exemplo n.º 10
0
 def test_mustang(self):
     mustang_exe = ample_util.find_exe("mustang" + ample_util.EXE_EXT)
     pdb_list = [ '1ujbA.pdb', '2a6pA.pdb', '3c7tA.pdb']
     models = [ os.path.join(self.ample_share, 'examples', 'homologs', 'input', pdb) for pdb in pdb_list ]
     work_dir = os.path.join(self.tests_dir, "mustang_test")
     alignment_file = align_mustang(models, mustang_exe=mustang_exe, work_dir=work_dir)
     self.assertTrue(os.path.isfile(alignment_file))
     shutil.rmtree(work_dir)
Exemplo n.º 11
0
 def test_mustang(self):
     mustang_exe = ample_util.find_exe("mustang" + ample_util.EXE_EXT)
     pdb_list = ['1ujbA.pdb', '2a6pA.pdb', '3c7tA.pdb']
     models = [os.path.join(self.ample_share, 'examples', 'homologs', 'input', pdb) for pdb in pdb_list]
     work_dir = os.path.join(self.tests_dir, "mustang_test")
     alignment_file = align_mustang(models, mustang_exe=mustang_exe, work_dir=work_dir)
     self.assertTrue(os.path.isfile(alignment_file))
     shutil.rmtree(work_dir)
Exemplo n.º 12
0
 def test_gesamt(self):
     gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
     pdb_list = [ '1ujbA.pdb', '2a6pA.pdb', '3c7tA.pdb']
     models = [ os.path.join(self.ample_share, 'examples', 'homologs', 'input', pdb) for pdb in pdb_list ]
     work_dir = os.path.join(self.tests_dir, "gesamt_test")
     alignment_file = align_gesamt(models, gesamt_exe=gesamt_exe, work_dir=work_dir)
     self.assertTrue(os.path.isfile(alignment_file))
     # TODO: fix this error on Windows...not sure how this arises
     try: shutil.rmtree(work_dir)
     except WindowsError: pass
Exemplo n.º 13
0
    def test_cluster_score(self):
        maxcluster_exe = ample_util.find_exe('maxcluster' + ample_util.EXE_EXT)
        radius = 4
        clusterer = subcluster.MaxClusterer(maxcluster_exe)
        pdb_list = glob.glob(os.path.join(self.testfiles_dir, "models",'*.pdb'))

        clusterer.generate_distance_matrix(pdb_list)
        clusterer.cluster_by_radius(radius)
        variance = clusterer.cluster_score
        ref = 4.748
        self.assertLessEqual(abs(ref-variance), 0.001, "Incorrect variance: {0} -> {1}".format(variance, ref))
Exemplo n.º 14
0
 def test_gesamt(self):
     gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
     pdb_list = ['1ujbA.pdb', '2a6pA.pdb', '3c7tA.pdb']
     models = [os.path.join(self.ample_share, 'examples', 'homologs', 'input', pdb) for pdb in pdb_list]
     work_dir = os.path.join(self.tests_dir, "gesamt_test")
     alignment_file = align_gesamt(models, gesamt_exe=gesamt_exe, work_dir=work_dir)
     self.assertTrue(os.path.isfile(alignment_file))
     # TODO: fix this error on Windows...not sure how this arises
     try:
         shutil.rmtree(work_dir)
     except WindowsError:
         pass
Exemplo n.º 15
0
    def test_shelxe_1BYZ(self):
        shelxe_exe = ample_util.find_exe('shelxe' + ample_util.EXE_EXT)
        pdb = os.path.join(self.testfiles_dir, "1BYZ.pdb")
        mtz = os.path.join(self.testfiles_dir, "1BYZ-cad.mtz")
        mrPdb = os.path.join(self.testfiles_dir,
                            "1BYZ_phaser_loc0_ALL_poly_ala_trunc_0.486615_rad_1_UNMOD.1.pdb")
        mrinfo = shelxe.MRinfo(shelxe_exe, pdb, mtz)
        mrinfo.analyse(mrPdb, cleanup=True)

        self.assertEqual(mrinfo.originShift,[0.326, 0.19, 0.275])
        # Need MRBUMP to be updated
        #self.assertEqual(mrinfo.MPE,78.5)
        self.assertEqual(mrinfo.wMPE,74.5)
Exemplo n.º 16
0
    def test_shelxe_1BYZ(self):
        shelxe_exe = ample_util.find_exe('shelxe' + ample_util.EXE_EXT)
        pdb = os.path.join(self.testfiles_dir, "1BYZ.pdb")
        mtz = os.path.join(self.testfiles_dir, "1BYZ-cad.mtz")
        mrPdb = os.path.join(
            self.testfiles_dir,
            "1BYZ_phaser_loc0_ALL_poly_ala_trunc_0.486615_rad_1_UNMOD.1.pdb")
        mrinfo = shelxe.MRinfo(shelxe_exe, pdb, mtz)
        mrinfo.analyse(mrPdb)

        self.assertEqual(mrinfo.originShift, [0.326, 0.19, 0.275])
        # Need MRBUMP to be updated
        #self.assertEqual(mrinfo.MPE,78.5)
        self.assertEqual(mrinfo.wMPE, 74.5)
Exemplo n.º 17
0
    def test_shelxe_1D7M(self):
        shelxe_exe = ample_util.find_exe('shelxe' + ample_util.EXE_EXT)
        pdb = os.path.join(self.testfiles_dir, "1D7M.pdb")
        mtz = os.path.join(self.testfiles_dir, "1D7M-cad.mtz")
        mrPdb = os.path.join(self.testfiles_dir,
                            "1D7M_phaser_loc0_ALL_SCWRL_reliable_sidechains_trunc_5.241154_rad_1_UNMOD.1.pdb")

        mrinfo = shelxe.MRinfo(shelxe_exe, pdb, mtz)
        mrinfo.analyse(mrPdb)

        self.assertEqual(mrinfo.originShift,[-0.0, -0.0, 0.5])
        # Need MRBUMP to be updated
        #self.assertEqual(mrinfo.MPE,65.5)
        self.assertEqual(mrinfo.wMPE,57.4)
Exemplo n.º 18
0
 def test_radius_maxcluster(self):
     # Test we can reproduce the original thresholds
     maxcluster_exe = ample_util.find_exe('maxcluster' + ample_util.EXE_EXT)
     radius = 4
     clusterer = subcluster.MaxClusterer(maxcluster_exe)
     pdb_list = glob.glob(os.path.join(self.testfiles_dir, "models",'*.pdb'))
     clusterer.generate_distance_matrix(pdb_list)
     cluster_files1 = [os.path.basename(x) for x in clusterer.cluster_by_radius(radius)]
     ref=['4_S_00000003.pdb', '2_S_00000005.pdb', '2_S_00000001.pdb', '3_S_00000006.pdb',
          '5_S_00000005.pdb', '3_S_00000003.pdb', '1_S_00000004.pdb', '4_S_00000005.pdb',
          '3_S_00000004.pdb', '1_S_00000002.pdb', '5_S_00000004.pdb', '4_S_00000002.pdb', '1_S_00000005.pdb']
     self.assertItemsEqual(ref,cluster_files1)
     os.unlink('files.list')
     os.unlink('maxcluster.log')
Exemplo n.º 19
0
    def test_gesamt_radius(self):
        # Test we can reproduce the original thresholds
        gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
        clusterer = subcluster.GesamtClusterer(executable=gesamt_exe)
        pdb_list = glob.glob(os.path.join(self.testfiles_dir, "models",'*.pdb'))

        radius = 4
        clusterer.generate_distance_matrix(pdb_list, purge=True)
        cluster_files1 = set([os.path.basename(x) for x in clusterer.cluster_by_radius(radius)])
        ref = set(['1_S_00000002.pdb', '1_S_00000004.pdb', '1_S_00000005.pdb', '2_S_00000001.pdb',
              '2_S_00000005.pdb', '3_S_00000003.pdb', '3_S_00000004.pdb', '3_S_00000006.pdb',
              '4_S_00000002.pdb', '4_S_00000005.pdb', '5_S_00000004.pdb', '5_S_00000005.pdb'])
        #clusterer.dump_pdb_matrix('foo')
        self.assertEqual(0, len(ref - cluster_files1))
        return
Exemplo n.º 20
0
    def test_shelxe_1D7M(self):
        shelxe_exe = ample_util.find_exe('shelxe' + ample_util.EXE_EXT)
        pdb = os.path.join(self.testfiles_dir, "1D7M.pdb")
        mtz = os.path.join(self.testfiles_dir, "1D7M-cad.mtz")
        mrPdb = os.path.join(
            self.testfiles_dir,
            "1D7M_phaser_loc0_ALL_SCWRL_reliable_sidechains_trunc_5.241154_rad_1_UNMOD.1.pdb"
        )

        mrinfo = shelxe.MRinfo(shelxe_exe, pdb, mtz)
        mrinfo.analyse(mrPdb)

        self.assertEqual(mrinfo.originShift, [-0.0, -0.0, 0.5])
        # Need MRBUMP to be updated
        #self.assertEqual(mrinfo.MPE,65.5)
        self.assertEqual(mrinfo.wMPE, 57.4)
Exemplo n.º 21
0
def process_benchmark_options(optd):
    # Benchmark Mode
    if optd['native_pdb'] or optd['benchmark_mode']:
        if optd['native_pdb'] and not os.path.isfile(optd['native_pdb']):
            raise RuntimeError("Cannot find crystal structure PDB: {0}".format(optd['native_pdb']))
        optd['benchmark_mode'] = True
        optd['benchmark_dir'] = os.path.join(optd['work_dir'], "benchmark")
        logger.info("*** AMPLE running in benchmark mode ***")
        # See if we can find TMscore
        if not optd['tmscore_exe']:
            optd['tmscore_exe'] = 'TMscore' + ample_util.EXE_EXT
        try:
            optd['tmscore_exe'] = ample_util.find_exe(optd['tmscore_exe'])
        except ample_util.FileNotFoundError:
            logger.warning("Cannot find TMScore executable: %s", optd['tmscore_exe'])
            optd['have_tmscore'] = False
        else:
            optd['have_tmscore'] = True
Exemplo n.º 22
0
def process_benchmark_options(optd):
    # Benchmark Mode
    if optd['native_pdb'] or optd['benchmark_mode']:
        if optd['native_pdb'] and not os.path.isfile(optd['native_pdb']):
            raise RuntimeError("Cannot find crystal structure PDB: {0}".format(optd['native_pdb']))
        optd['benchmark_mode'] = True
        optd['benchmark_dir'] = os.path.join(optd['work_dir'], "benchmark")
        logger.info("*** AMPLE running in benchmark mode ***")
        # See if we can find TMscore
        if not optd['tmscore_exe']:
            optd['tmscore_exe'] = 'TMscore' + ample_util.EXE_EXT
        try:
            optd['tmscore_exe'] = ample_util.find_exe(optd['tmscore_exe'])
        except ample_util.FileNotFoundError:
            logger.warning("Cannot find TMScore executable: %s", optd['tmscore_exe'])
            optd['have_tmscore'] = False
        else:
            optd['have_tmscore'] = True
Exemplo n.º 23
0
    def test_gesamt_matrix_generic(self):
        # Test we can reproduce the original thresholds
        gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
        clusterer = subcluster.GesamtClusterer(executable=gesamt_exe)
        pdb_list = sorted(
            glob.glob(os.path.join(self.testfiles_dir, "models", '*.pdb')))
        clusterer._generate_distance_matrix_generic(pdb_list, purge_all=True)
        # Test two files manually
        index1 = 2
        index2 = 25
        f1 = pdb_list[index1]
        f2 = pdb_list[index2]
        # Run gesamt to get the score between the two
        logfile = 'gesamt.log'
        ample_util.run_command([gesamt_exe, f1, f2], logfile=logfile)
        qscore = None
        with open(logfile) as f:
            for l in f.readlines():
                if l.startswith(' Q-score'):
                    qscore = float(l.split()[2])

        self.assertIsNotNone(qscore, "No q-score found")
        # read score matrix
        matrix = []
        with open(subcluster.SCORE_MATRIX_NAME) as f:
            for l in f.readlines():
                if not l.strip():
                    continue
                fields = l.split()
                matrix.append(
                    (int(fields[0]), int(fields[1]), float(fields[2])))
        # Make sure the score matches
        for l in matrix:
            if l[0] == index1 and l[1] == index2:
                # Gesamt log and out file formats have different precisions
                self.assertAlmostEqual(
                    l[2], qscore, 3,
                    "Q-scores differ: {0} - {1}".format(l[2], qscore))
        os.unlink(logfile)
        os.unlink(subcluster.SCORE_MATRIX_NAME)
        os.unlink(subcluster.FILE_LIST_NAME)
        return
Exemplo n.º 24
0
    def test_gesamt_matrix_generic(self):
        # Test we can reproduce the original thresholds
        gesamt_exe = ample_util.find_exe("gesamt" + ample_util.EXE_EXT)
        clusterer = subcluster.GesamtClusterer(executable=gesamt_exe)
        pdb_list = sorted(glob.glob(os.path.join(self.testfiles_dir, "models",'*.pdb')))
        clusterer._generate_distance_matrix_generic(pdb_list, purge_all=True)
        # Test two files manually
        index1 = 2
        index2 = 25
        f1 = pdb_list[index1]
        f2 = pdb_list[index2]
        # Run gesamt to get the score between the two
        logfile = 'gesamt.log'
        ample_util.run_command([gesamt_exe, f1, f2], logfile=logfile)
        qscore = None
        with open(logfile) as f:
            for l in f.readlines():
                if l.startswith(' Q-score'):
                    qscore = float(l.split()[2])

        self.assertIsNotNone(qscore, "No q-score found")
        # read score matrix
        matrix = []
        with open(subcluster.SCORE_MATRIX_NAME) as f:
            for l in f.readlines():
                if not l.strip(): continue
                fields = l.split()
                matrix.append((int(fields[0]),int(fields[1]), float(fields[2])))
        # Make sure the score matches
        for l in matrix:
            if l[0] == index1 and l[1] == index2:
                # Gesamt log and out file formats have different precisions
                self.assertAlmostEqual(l[2], qscore, 3, "Q-scores differ: {0} - {1}".format(l[2], qscore))
        os.unlink(logfile)
        os.unlink(subcluster.SCORE_MATRIX_NAME)
        os.unlink(subcluster.FILE_LIST_NAME)
        return
Exemplo n.º 25
0
 def setUpClass(cls):
     cls.thisd =  os.path.abspath( os.path.dirname( __file__ ) )
     cls.ample_share = constants.SHARE_DIR
     cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
     cls.tests_dir = tempfile.gettempdir()
     cls.spicker_exe = ample_util.find_exe('spicker' + ample_util.EXE_EXT)
Exemplo n.º 26
0
 def setUpClass(cls):
     cls.thisd = os.path.abspath(os.path.dirname(__file__))
     cls.ample_share = constants.SHARE_DIR
     cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
     cls.fpc_exe = ample_util.find_exe("fast_protein_cluster" + ample_util.EXE_EXT)
Exemplo n.º 27
0
    # Benchmark Mode
    #
    ###############################################################################
    if optd['native_pdb'] or optd['benchmark_mode']:
        if optd['native_pdb'] and not os.path.isfile(optd['native_pdb']):
            msg = "Cannot find crystal structure PDB: {0}".format(
                optd['native_pdb'])
            exit_util.exit_error(msg)
        optd['benchmark_mode'] = True
        optd['benchmark_dir'] = os.path.join(optd['work_dir'], "benchmark")
        logger.info("*** AMPLE running in benchmark mode ***")
        # See if we can find TMscore
        if not optd['tmscore_exe']:
            optd['tmscore_exe'] = 'TMscore' + ample_util.EXE_EXT
        try:
            optd['tmscore_exe'] = ample_util.find_exe(optd['tmscore_exe'])
            optd['have_tmscore'] = True
        except ample_util.FileNotFoundError:
            logger.debug("Cannot find TMScore executable: {0}".format(
                optd['tmscore_exe']))
            # No TMscore so try and find Maxcluster
            optd['maxcluster_exe'] = maxcluster.find_maxcluster(optd)
            optd['have_tmscore'] = False

    ###############################################################################
    #
    # Program defaults
    #
    #
    ###############################################################################
    if optd['shelxe_rebuild']:
Exemplo n.º 28
0
def process_mr_options(optd):
    # Molecular Replacement Options
    if optd['molrep_only']:
        optd['phaser_only'] = False
    if optd['molrep_only']:
        optd['mrbump_programs'] = ['molrep']
    elif optd['phaser_only']:
        optd['mrbump_programs'] = ['phaser']
    else:
        optd['mrbump_programs'] = ['molrep', 'phaser']
    if optd['phaser_rms'] != 'auto':
        try:
            phaser_rms = float(optd['phaser_rms'])
        except ValueError as e:
            msg = "Error converting phaser_rms '{0}' to floating point: {1}".format(
                optd['phaser_rms'], e)
            exit_util.exit_error(msg)
        else:
            optd['phaser_rms'] = phaser_rms

    # Disable all rebuilding if the resolution is too poor
    if optd['mtz_min_resolution'] >= mrbump_util.REBUILD_MAX_PERMITTED_RESOLUTION:
        logger.warn(
            "!!! Disabling all rebuilding as maximum resolution of %f is too poor!!!"
            .format(optd['mtz_min_resolution']))
        optd['use_shelxe'] = False
        optd['shelxe_rebuild'] = False
        optd['shelxe_rebuild_arpwarp'] = False
        optd['shelxe_rebuild_buccaneer'] = False
        optd['refine_rebuild_arpwarp'] = False
        optd['refine_rebuild_buccaneer'] = False

    if optd['shelxe_max_resolution'] < 0.0:
        if optd['coiled_coil']:
            optd[
                'shelxe_max_resolution'] = mrbump_util.SHELXE_MAX_PERMITTED_RESOLUTION_CC
        else:
            optd[
                'shelxe_max_resolution'] = mrbump_util.SHELXE_MAX_PERMITTED_RESOLUTION

    # We use shelxe by default so if we can't find it we just warn and set use_shelxe to False
    if optd['use_shelxe']:
        if optd['mtz_min_resolution'] > optd['shelxe_max_resolution']:
            logger.warn(
                "Disabling use of SHELXE as min resolution of %f is < accepted limit of %f",
                optd['mtz_min_resolution'],
                optd['shelxe_max_resolution'],
            )
            optd['use_shelxe'] = False
            optd['shelxe_rebuild'] = False
    if optd['use_shelxe']:
        if not optd['shelxe_exe']:
            optd['shelxe_exe'] = os.path.join(os.environ['CCP4'], 'bin',
                                              'shelxe' + ample_util.EXE_EXT)
        try:
            optd['shelxe_exe'] = ample_util.find_exe(optd['shelxe_exe'])
        except ample_util.FileNotFoundError:
            msg = """*** Cannot find shelxe executable in PATH - turning off use of SHELXE. ***
    SHELXE is recommended for the best chance of success. We recommend you install shelxe from:
    http://shelx.uni-ac.gwdg.de/SHELX/
    and install it in your PATH so that AMPLE can use it.
    """
            logger.warn(msg)
            optd['use_shelxe'] = False
    if optd['shelxe_rebuild']:
        optd['shelxe_rebuild_arpwarp'] = True
        optd['shelxe_rebuild_buccaneer'] = True

    # If shelxe_rebuild is set we need use_shelxe to be set
    if (optd['shelxe_rebuild'] or optd['shelxe_rebuild_arpwarp']
            or optd['shelxe_rebuild_buccaneer']) and not optd['use_shelxe']:
        raise RuntimeError(
            'shelxe_rebuild is set but use_shelxe is False. Please make sure you have shelxe installed.'
        )

    if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
        auto_tracing_sh = None
        if 'warpbin' in os.environ:
            _path = os.path.join(os.environ['warpbin'], "auto_tracing.sh")
            if os.path.isfile(_path):
                auto_tracing_sh = _path
        if auto_tracing_sh:
            logger.info('Using arpwarp script: %s', auto_tracing_sh)
        else:
            logger.warn(
                'Cannot find arpwarp script! Disabling use of arpwarp.')
            optd['refine_rebuild_arpwarp'] = False
            optd['shelxe_rebuild_arpwarp'] = False

    if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
        logger.info('Rebuilding in ARP/wARP')
    else:
        logger.info('Not rebuilding in ARP/wARP')

    if optd['refine_rebuild_buccaneer'] or optd['shelxe_rebuild_buccaneer']:
        logger.info('Rebuilding in Buccaneer')
    else:
        logger.info('Not rebuilding in Buccaneer')
Exemplo n.º 29
0
def process_ensemble_options(optd):
    from ample.ensembler.truncation_util import TRUNCATION_METHODS

    if optd['single_model_mode'] and optd['truncation_scorefile'] and optd[
            'truncation_scorefile_header']:
        # optd['truncation_method'] = "scores"
        optd['truncation_method'] = TRUNCATION_METHODS.SCORES
    elif optd['percent_fixed_intervals']:
        optd['truncation_method'] = TRUNCATION_METHODS.PERCENT_FIXED
    else:
        try:
            optd['truncation_method'] = TRUNCATION_METHODS(
                optd['truncation_method'])
        except ValueError:
            raise RuntimeError(
                "{} is not a valid truncation method. Use one of: {}".format(
                    optd['truncation_method'],
                    [e.value for e in TRUNCATION_METHODS]))

    # Check we can find all the required programs
    if optd['subcluster_program'] == 'gesamt':
        if not optd['gesamt_exe']:
            optd['gesamt_exe'] = os.path.join(os.environ['CCP4'], 'bin',
                                              'gesamt' + ample_util.EXE_EXT)
        try:
            optd['gesamt_exe'] = ample_util.find_exe(optd['gesamt_exe'])
        except ample_util.FileNotFoundError:
            raise RuntimeError("Cannot find Gesamt executable: {0}".format(
                optd['gesamt_exe']))
    # Ensemble options
    if optd['cluster_method'] in [SPICKER_RMSD, SPICKER_TM]:
        if not optd['spicker_exe']:
            if optd['cluster_method'] == SPICKER_TM and optd['nproc'] > 1:
                # We need to use the multicore version of SPICKER
                optd['spicker_exe'] = 'spicker_omp' + ample_util.EXE_EXT
            else:
                optd['spicker_exe'] = 'spicker' + ample_util.EXE_EXT
        try:
            optd['spicker_exe'] = ample_util.find_exe(optd['spicker_exe'])
        except ample_util.FileNotFoundError:
            raise RuntimeError("Cannot find spicker executable: {0}".format(
                optd['spicker_exe']))
    elif optd['cluster_method'] in ['fast_protein_cluster']:
        if not optd['fast_protein_cluster_exe']:
            optd['fast_protein_cluster_exe'] = 'fast_protein_cluster'
        try:
            optd['fast_protein_cluster_exe'] = ample_util.find_exe(
                optd['fast_protein_cluster_exe'])
        except ample_util.FileNotFoundError:
            raise RuntimeError(
                "Cannot find fast_protein_cluster executable: {0}".format(
                    optd['fast_protein_cluster_exe']))
    elif optd['cluster_method'] in ['import', 'random', 'skip']:
        pass
    else:
        raise RuntimeError("Unrecognised cluster_method: {0}".format(
            optd['cluster_method']))
    if not optd['theseus_exe']:
        optd['theseus_exe'] = os.path.join(os.environ['CCP4'], 'bin',
                                           'theseus' + ample_util.EXE_EXT)
    try:
        optd['theseus_exe'] = ample_util.find_exe(optd['theseus_exe'])
    except ample_util.FileNotFoundError:
        raise RuntimeError("Cannot find theseus executable: {0}".format(
            optd['theseus_exe']))
    # SCRWL - we always check for SCRWL as if we are processing QUARK models we want to add sidechains to them
    if not optd['scwrl_exe']:
        optd['scwrl_exe'] = os.path.join(os.environ['CCP4'], 'bin',
                                         'Scwrl4' + ample_util.EXE_EXT)
    try:
        optd['scwrl_exe'] = ample_util.find_exe(optd['scwrl_exe'])
    except ample_util.FileNotFoundError as e:
        logger.info("Cannot find Scwrl executable: %s", optd['scwrl_exe'])
        if optd['use_scwrl']:
            raise (e)
    if "subcluster_radius_thresholds" in optd and not optd[
            "subcluster_radius_thresholds"]:
        optd["subcluster_radius_thresholds"] = SUBCLUSTER_RADIUS_THRESHOLDS
    # REM: This should really be disentangled and moved up to definition of all homologs options
    # REM: but could cause confusion with defaults down here.
    if "side_chain_treatments" in optd and not optd["side_chain_treatments"]:
        if optd["homologs"]:
            optd["side_chain_treatments"] = [POLYALA, RELIABLE, ALLATOM]
        else:
            optd["side_chain_treatments"] = SIDE_CHAIN_TREATMENTS
    else:
        optd["side_chain_treatments"] = map(str.lower,
                                            optd["side_chain_treatments"])
    unrecognised_sidechains = set(
        optd["side_chain_treatments"]) - set(ALLOWED_SIDE_CHAIN_TREATMENTS)
    if unrecognised_sidechains:
        raise ("Unrecognised side_chain_treatments: {0}".format(
            unrecognised_sidechains))
    return
Exemplo n.º 30
0
def find_maxcluster(amoptd):
    """Return path to maxcluster binary.
    If we can't find one in the path, we create a $HOME/.ample
    directory and downlod it to there
    """

    if amoptd['maxcluster_exe'] and ample_util.is_exe(
            amoptd['maxcluster_exe']):
        return amoptd['maxcluster_exe']

    if not amoptd['maxcluster_exe']:
        if sys.platform.startswith("win"):
            amoptd['maxcluster_exe'] = 'maxcluster.exe'
        else:
            amoptd['maxcluster_exe'] = 'maxcluster'

    try:
        maxcluster_exe = ample_util.find_exe(amoptd['maxcluster_exe'],
                                             dirs=[amoptd['rcdir']])
    except ample_util.FileNotFoundError:
        # Cannot find so we need to try and download it
        rcdir = amoptd['rcdir']
        logger.info(
            "Cannot find maxcluster binary in path so attempting to download it directory: {0}"
            .format(rcdir))
        if not os.path.isdir(rcdir):
            logger.info(
                "No ample rcdir found so creating in: {0}".format(rcdir))
            os.mkdir(rcdir)
        url = None
        maxcluster_exe = os.path.join(rcdir, 'maxcluster')
        if sys.platform.startswith("linux"):
            bit = platform.architecture()[0]
            if bit == '64bit':
                url = 'http://www.sbg.bio.ic.ac.uk/~maxcluster/maxcluster64bit'
            elif bit == '32bit':
                url = 'http://www.sbg.bio.ic.ac.uk/~maxcluster/maxcluster'
            else:
                msg = "Unrecognised system type: {0} {1}".format(
                    sys.platform, bit)
                exit_util.exit_error(msg)
        elif sys.platform.startswith("darwin"):
            url = 'http://www.sbg.bio.ic.ac.uk/~maxcluster/maxcluster_i686_32bit.bin'
            #OSX PPC: http://www.sbg.bio.ic.ac.uk/~maxcluster/maxcluster_PPC_32bit.bin
        elif sys.platform.startswith("win"):
            url = 'http://www.sbg.bio.ic.ac.uk/~maxcluster/maxcluster.exe'
            maxcluster_exe = os.path.join(rcdir, 'maxcluster.exe')
        else:
            msg = "Unrecognised system type: {0}".format(sys.platform)
            exit_util.exit_error(msg)
        logger.info(
            "Attempting to download maxcluster binary from: {0}".format(url))
        try:
            urllib.urlretrieve(url, maxcluster_exe)
        except Exception, e:
            msg = "Error downloading maxcluster executable: {0}\n{1}".format(
                url, e)
            exit_util.exit_error(msg)

        # make executable
        os.chmod(maxcluster_exe, 0o777)
Exemplo n.º 31
0
def found_exe(e):
    try:
        ample_util.find_exe(e)
    except:
        return False
    return True
Exemplo n.º 32
0
 def setUpClass(cls):
     cls.thisd =  os.path.abspath( os.path.dirname( __file__ ) )
     cls.ample_share = constants.SHARE_DIR
     cls.testfiles_dir = os.path.join(cls.ample_share,'testfiles')
     cls.fpc_exe = ample_util.find_exe("fast_protein_cluster" + ample_util.EXE_EXT)   
Exemplo n.º 33
0
 def setUpClass(cls):
     cls.thisd = os.path.abspath(os.path.dirname(__file__))
     cls.ample_share = constants.SHARE_DIR
     cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
     cls.tests_dir = tempfile.gettempdir()
     cls.theseus_exe = ample_util.find_exe('theseus' + ample_util.EXE_EXT)
Exemplo n.º 34
0
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)
except Exception as e:
    msg = "Error running ensembling: {0}".format(e.message)
    exit_util.exit_error(msg, sys.exc_info()[2])
Exemplo n.º 35
0
def process_mr_options(optd):
    # Molecular Replacement Options
    if optd['molrep_only']:
        optd['phaser_only'] = False
    if optd['molrep_only']:
        optd['mrbump_programs'] = ['molrep']
    elif optd['phaser_only']:
        optd['mrbump_programs'] = ['phaser']
    else:
        optd['mrbump_programs'] = ['molrep', 'phaser']
    if optd['phaser_rms'] != 'auto':
        try:
            phaser_rms = float(optd['phaser_rms'])
        except ValueError as e:
            msg = "Error converting phaser_rms '{0}' to floating point: {1}".format(optd['phaser_rms'], e)
            exit_util.exit_error(msg)
        else:
            optd['phaser_rms'] = phaser_rms

    # Disable all rebuilding if the resolution is too poor
    if optd['mtz_min_resolution'] >= mrbump_util.REBUILD_MAX_PERMITTED_RESOLUTION:
        logger.warn("!!! Disabling all rebuilding as maximum resolution of %f is too poor!!!".format(optd['mtz_min_resolution']))
        optd['use_shelxe'] = False
        optd['shelxe_rebuild'] = False
        optd['shelxe_rebuild_arpwarp'] = False
        optd['shelxe_rebuild_buccaneer'] = False
        optd['refine_rebuild_arpwarp'] = False
        optd['refine_rebuild_buccaneer'] = False
        
    # We use shelxe by default so if we can't find it we just warn and set use_shelxe to False
    if optd['use_shelxe']:
        if optd['mtz_min_resolution'] > mrbump_util.SHELXE_MAX_PERMITTED_RESOLUTION:
            logger.warn("Disabling use of SHELXE as min resolution of %f is < accepted limit of %f",
                        optd['mtz_min_resolution'],
                        mrbump_util.SHELXE_MAX_PERMITTED_RESOLUTION)
            optd['use_shelxe'] = False
            optd['shelxe_rebuild'] = False
    if optd['use_shelxe']:
        if not optd['shelxe_exe']:
            optd['shelxe_exe'] = os.path.join(os.environ['CCP4'], 'bin', 'shelxe' + ample_util.EXE_EXT)
        try:
            optd['shelxe_exe'] = ample_util.find_exe(optd['shelxe_exe'])
        except ample_util.FileNotFoundError:
            msg = """*** Cannot find shelxe executable in PATH - turning off use of SHELXE. ***
    SHELXE is recommended for the best chance of success. We recommend you install shelxe from:
    http://shelx.uni-ac.gwdg.de/SHELX/
    and install it in your PATH so that AMPLE can use it.
    """
            logger.warn(msg)
            optd['use_shelxe'] = False
    if optd['shelxe_rebuild']:
        optd['shelxe_rebuild_arpwarp'] = True
        optd['shelxe_rebuild_buccaneer'] = True
        
    # If shelxe_rebuild is set we need use_shelxe to be set
    if (optd['shelxe_rebuild'] or optd['shelxe_rebuild_arpwarp']  or optd['shelxe_rebuild_buccaneer']) and not optd['use_shelxe']:
        raise RuntimeError('shelxe_rebuild is set but use_shelxe is False. Please make sure you have shelxe installed.')

    if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
        auto_tracing_sh = None
        if 'warpbin' in os.environ:
            _path = os.path.join(os.environ['warpbin'], "auto_tracing.sh")
            if os.path.isfile(_path):
                auto_tracing_sh = _path
        if auto_tracing_sh:
            logger.info('Using arpwarp script: %s', auto_tracing_sh)
        else:
            logger.warn('Cannot find arpwarp script! Disabling use of arpwarp.')
            optd['refine_rebuild_arpwarp'] = False
            optd['shelxe_rebuild_arpwarp'] = False

    if optd['refine_rebuild_arpwarp'] or optd['shelxe_rebuild_arpwarp']:
        logger.info('Rebuilding in ARP/wARP')
    else:
        logger.info('Not rebuilding in ARP/wARP')

    if optd['refine_rebuild_buccaneer'] or optd['shelxe_rebuild_buccaneer']:
        logger.info('Rebuilding in Bucaneer')
    else:
        logger.info('Not rebuilding in Bucaneer')
Exemplo n.º 36
0
 def setUpClass(cls):
     cls.ample_share = constants.SHARE_DIR
     cls.testfiles_dir = os.path.join(cls.ample_share, 'testfiles')
     cls.tests_dir = tempfile.gettempdir()
     cls.theseus_exe = ample_util.find_exe("theseus" + ample_util.EXE_EXT)
Exemplo n.º 37
0
def process_ensemble_options(optd):
    from ample.ensembler.truncation_util import TRUNCATION_METHODS
    if optd['single_model_mode'] and optd['truncation_scorefile'] and optd['truncation_scorefile_header']:
        #optd['truncation_method'] = "scores"
        optd['truncation_method'] = TRUNCATION_METHODS.SCORES
    elif optd['percent_fixed_intervals']:
        optd['truncation_method'] = TRUNCATION_METHODS.PERCENT_FIXED
    else:
        try:
            optd['truncation_method'] = TRUNCATION_METHODS(optd['truncation_method'])
        except ValueError:
            raise RuntimeError("{} is not a valid truncation method. Use one of: {}".format(optd['truncation_method'],
                                                                                            [e.value for e in TRUNCATION_METHODS]))
        
    # Check we can find all the required programs
    if optd['subcluster_program'] == 'gesamt':
        if not optd['gesamt_exe']:
            optd['gesamt_exe'] = os.path.join(os.environ['CCP4'], 'bin', 'gesamt' + ample_util.EXE_EXT)
        try:
            optd['gesamt_exe'] = ample_util.find_exe(optd['gesamt_exe'])
        except ample_util.FileNotFoundError:
            raise RuntimeError("Cannot find Gesamt executable: {0}".format(optd['gesamt_exe']))
    # Ensemble options
    if optd['cluster_method'] in [SPICKER_RMSD, SPICKER_TM]:
        if not optd['spicker_exe']:
            if optd['cluster_method'] == SPICKER_TM and optd['nproc'] > 1:
                # We need to use the multicore version of SPICKER
                optd['spicker_exe'] = 'spicker_omp' + ample_util.EXE_EXT
            else:
                optd['spicker_exe'] = 'spicker' + ample_util.EXE_EXT
        try:
            optd['spicker_exe'] = ample_util.find_exe(optd['spicker_exe'])
        except ample_util.FileNotFoundError:
            raise RuntimeError("Cannot find spicker executable: {0}".format(optd['spicker_exe']))
    elif optd['cluster_method'] in ['fast_protein_cluster']:
        if not optd['fast_protein_cluster_exe']:
            optd['fast_protein_cluster_exe'] = 'fast_protein_cluster'
        try:
            optd['fast_protein_cluster_exe'] = ample_util.find_exe(optd['fast_protein_cluster_exe'])
        except ample_util.FileNotFoundError:
            raise RuntimeError("Cannot find fast_protein_cluster executable: {0}".format(optd['fast_protein_cluster_exe']))
    elif optd['cluster_method'] in ['import', 'random', 'skip']:
        pass
    else:
        raise RuntimeError("Unrecognised cluster_method: {0}".format(optd['cluster_method']))
    if not optd['theseus_exe']:
        optd['theseus_exe'] = os.path.join(os.environ['CCP4'], 'bin', 'theseus' + ample_util.EXE_EXT)
    try:
        optd['theseus_exe'] = ample_util.find_exe(optd['theseus_exe'])
    except ample_util.FileNotFoundError:
        raise RuntimeError("Cannot find theseus executable: {0}".format(optd['theseus_exe']))
    # SCRWL - we always check for SCRWL as if we are processing QUARK models we want to add sidechains to them
    if not optd['scwrl_exe']:
        optd['scwrl_exe'] = os.path.join(os.environ['CCP4'], 'bin', 'Scwrl4' + ample_util.EXE_EXT)
    try:
        optd['scwrl_exe'] = ample_util.find_exe(optd['scwrl_exe'])
    except ample_util.FileNotFoundError as e:
        logger.info("Cannot find Scwrl executable: %s", optd['scwrl_exe'])
        if optd['use_scwrl']:
            raise (e)
    if "subcluster_radius_thresholds" in optd and not optd["subcluster_radius_thresholds"]:
        optd["subcluster_radius_thresholds"] = SUBCLUSTER_RADIUS_THRESHOLDS
    # REM: This should really be disentangled and moved up to definition of all homologs options
    # REM: but could cause confusion with defaults down here.
    if "side_chain_treatments" in optd and not optd["side_chain_treatments"]:
        if optd["homologs"]:
            optd["side_chain_treatments"] = [POLYALA, RELIABLE, ALLATOM]
        else:
            optd["side_chain_treatments"] = SIDE_CHAIN_TREATMENTS
    else:
        optd["side_chain_treatments"] = map(str.lower, optd["side_chain_treatments"])
    unrecognised_sidechains = set(optd["side_chain_treatments"]) - set(ALLOWED_SIDE_CHAIN_TREATMENTS)
    if unrecognised_sidechains:
        raise("Unrecognised side_chain_treatments: {0}".format(unrecognised_sidechains))
    return