Ejemplo n.º 1
0
 def test_helix5(self):
     logfile = os.path.join(self.testfiles_dir, "ncont5.log")
     dssplog = os.path.join(self.testfiles_dir, "3RA3.dssp")
     c = rio.Rio()
     contactData = rio.RioData()
     c.parseNcontLog(contactData, logfile=logfile, clean_up=False)
     sequence = c.helixFromContacts(contactData.contacts, dssplog)
     self.assertEqual("NARLKQEIAALEYEIAAL", sequence)
Ejemplo n.º 2
0
 def test_parse8(self):
     logfile = os.path.join(self.testfiles_dir, "ncont8.log")
     c = rio.Rio()
     contactData = rio.RioData()
     c.parseNcontLog(contactData, logfile=logfile, clean_up=False)
     c.analyseRio(contactData)
     self.assertEqual(contactData.numContacts, 9)
     self.assertEqual(contactData.rioInRegister, 0)
     self.assertEqual(contactData.rioOoRegister, 0)
     self.assertEqual(contactData.rioBackwards, 0)
Ejemplo n.º 3
0
def analyseSolution(amoptd, d, mrinfo):

    logger.info("Benchmark: analysing result: {0}".format(d['ensemble_name']))

    mrPdb = None
    if d['MR_program'] == "PHASER":
        mrPdb = d['PHASER_pdbout']
        mrMTZ = d['PHASER_mtzout']
    elif d['MR_program'] == "MOLREP":
        mrPdb = d['MOLREP_pdbout']
    elif d['MR_program'] == "unknown":
        return

    if mrPdb is None or not os.path.isfile(mrPdb):
        #logger.critical("Cannot find mrPdb {0} for solution {1}".format(mrPdb,d))
        return

    # debug - copy into work directory as reforigin struggles with long pathnames
    shutil.copy(
        mrPdb,
        os.path.join(fixpath(amoptd['benchmark_dir']),
                     os.path.basename(mrPdb)))

    mrPdbInfo = pdb_edit.get_info(mrPdb)

    d['num_placed_chains'] = mrPdbInfo.numChains()
    d['num_placed_atoms'] = mrPdbInfo.numAtoms()
    d['num_placed_CA'] = mrPdbInfo.numCalpha()

    if amoptd['native_pdb']:
        if not d['SHELXE_os']:
            logger.critical(
                "mrPdb {0} has no SHELXE_os origin shift. Calculating...".
                format(mrPdb))
            mrinfo.analyse(mrPdb)
            mrOrigin = mrinfo.originShift
            d['SHELXE_MPE'] = mrinfo.MPE
            d['SHELXE_wMPE'] = mrinfo.wMPE
        else:
            mrOrigin = [c * -1 for c in d['SHELXE_os']]

        # Move pdb onto new origin
        originPdb = ample_util.filename_append(mrPdb,
                                               astr='offset',
                                               directory=fixpath(
                                                   amoptd['benchmark_dir']))
        #print(mrPdb, originPdb, mrOrigin)
        pdb_edit.translate(mrPdb, originPdb, mrOrigin)

        # offset.pdb is the mrModel shifted onto the new origin use csymmatch to wrap onto native
        csymmatch.Csymmatch().wrapModelToNative(
            originPdb,
            amoptd['native_pdb'],
            csymmatchPdb=os.path.join(
                fixpath(amoptd['benchmark_dir']),
                "phaser_{0}_csymmatch.pdb".format(d['ensemble_name'])))
        # can now delete origin pdb
        os.unlink(originPdb)

        # Calculate phase error for the MR PDB
        try:
            mrinfo.analyse(mrPdb)
            d['MR_MPE'] = mrinfo.MPE
            d['MR_wMPE'] = mrinfo.wMPE
        except Exception as e:
            logger.critical("Error analysing mrPdb: {0}\n{1}".format(mrPdb, e))

        # We cannot calculate the Reforigin RMSDs or RIO scores for runs where we don't have a full initial model
        # to compare to the native to allow us to determine which parts of the ensemble correspond to which parts of
        # the native structure.
        if not (amoptd['homologs'] or \
                amoptd['ideal_helices'] or \
                amoptd['import_ensembles'] or \
                amoptd['single_model_mode']):

            # Get reforigin info
            rmsder = reforigin.ReforiginRmsd()
            try:
                rmsder.getRmsd(nativePdbInfo=amoptd['native_pdb_info'],
                               placedPdbInfo=mrPdbInfo,
                               refModelPdbInfo=amoptd['ref_model_pdb_info'],
                               cAlphaOnly=True,
                               workdir=fixpath(amoptd['benchmark_dir']))
                d['reforigin_RMSD'] = rmsder.rmsd
            except Exception as e:
                logger.critical("Error calculating RMSD: {0}".format(e))
                d['reforigin_RMSD'] = 999

            # Score the origin with all-atom and rio
            rioData = rio.Rio().scoreOrigin(
                mrOrigin,
                mrPdbInfo=mrPdbInfo,
                nativePdbInfo=amoptd['native_pdb_info'],
                resSeqMap=amoptd['res_seq_map'],
                workdir=fixpath(amoptd['benchmark_dir']))

            # Set attributes
            d['AA_num_contacts'] = rioData.aaNumContacts
            d['RIO_num_contacts'] = rioData.rioNumContacts
            d['RIO_in_register'] = rioData.rioInRegister
            d['RIO_oo_register'] = rioData.rioOoRegister
            d['RIO_backwards'] = rioData.rioBackwards
            d['RIO'] = rioData.rioInRegister + rioData.rioOoRegister
            d['RIO_no_cat'] = rioData.rioNumContacts - (rioData.rioInRegister +
                                                        rioData.rioOoRegister)
            d['RIO_norm'] = float(d['RIO']) / float(
                d['native_pdb_num_residues'])
        else:
            d['AA_num_contacts'] = None
            d['RIO_num_contacts'] = None
            d['RIO_in_register'] = None
            d['RIO_oo_register'] = None
            d['RIO_backwards'] = None
            d['RIO'] = None
            d['RIO_no_cat'] = None
            d['RIO_norm'] = None

    #     # Now get the helix
    #     helixSequence = contacts.Rio().helixFromContacts( contacts=rioData.contacts,
    #                                                            dsspLog=dsspLog )
    #     if helixSequence is not None:
    #         ampleResult.rioHelixSequence = helixSequence
    #         ampleResult.rioLenHelix      = len( helixSequence )
    #         hfile = os.path.join( workdir, "{0}.helix".format( ampleResult.ensembleName ) )
    #         with open( hfile, 'w' ) as f:
    #             f.write( helixSequence+"\n" )

    #
    # This purely for checking and so we have pdbs to view
    #
    # Wrap shelxe trace onto native using Csymmatch
        if not d['SHELXE_pdbout'] is None and os.path.isfile(
                fixpath(d['SHELXE_pdbout'])):
            csymmatch.Csymmatch().wrapModelToNative(
                fixpath(d['SHELXE_pdbout']),
                amoptd['native_pdb'],
                origin=mrOrigin,
                workdir=fixpath(amoptd['benchmark_dir']))

        if not ('SHELXE_wMPE' in d and d['SHELXE_wMPE']):
            try:
                mrinfo.analyse(d['SHELXE_pdbout'])
                d['SHELXE_MPE'] = mrinfo.MPE
                d['SHELXE_wMPE'] = mrinfo.wMPE
            except Exception as e:
                logger.critical(
                    "Error analysing SHELXE_pdbout: {0}\n{1}".format(
                        d['SHELXE_pdbout'], e))

        # Wrap parse_buccaneer model onto native
        if d['SXRBUCC_pdbout'] and os.path.isfile(fixpath(
                d['SXRBUCC_pdbout'])):
            # Need to rename Pdb as is just called buccSX_output.pdb
            csymmatchPdb = os.path.join(
                fixpath(amoptd['benchmark_dir']),
                "buccaneer_{0}_csymmatch.pdb".format(d['ensemble_name']))

            csymmatch.Csymmatch().wrapModelToNative(
                fixpath(d['SXRBUCC_pdbout']),
                amoptd['native_pdb'],
                origin=mrOrigin,
                csymmatchPdb=csymmatchPdb,
                workdir=fixpath(amoptd['benchmark_dir']))
            # Calculate phase error
            try:
                mrinfo.analyse(d['SXRBUCC_pdbout'])
                d['SXRBUCC_MPE'] = mrinfo.MPE
                d['SXRBUCC_wMPE'] = mrinfo.wMPE
            except Exception as e:
                logger.critical(
                    "Error analysing SXRBUCC_pdbout: {0}\n{1}".format(
                        d['SXRBUCC_pdbout'], e))

        # Wrap parse_buccaneer model onto native
        if d['SXRARP_pdbout'] and os.path.isfile(fixpath(d['SXRARP_pdbout'])):
            # Need to rename Pdb as is just called buccSX_output.pdb
            csymmatchPdb = os.path.join(
                fixpath(amoptd['benchmark_dir']),
                "arpwarp_{0}_csymmatch.pdb".format(d['ensemble_name']))

            csymmatch.Csymmatch().wrapModelToNative(
                fixpath(d['SXRARP_pdbout']),
                amoptd['native_pdb'],
                origin=mrOrigin,
                csymmatchPdb=csymmatchPdb,
                workdir=fixpath(amoptd['benchmark_dir']))
            # Calculate phase error
            try:
                mrinfo.analyse(d['SXRARP_pdbout'])
                d['SXRARP_MPE'] = mrinfo.MPE
                d['SXRARP_wMPE'] = mrinfo.wMPE
            except Exception as e:
                logger.critical(
                    "Error analysing SXRARP_pdbout: {0}\n{1}".format(
                        d['SXRARP_pdbout'], e))
    return