예제 #1
0
def calculateInteractions(job,
                          localExe=True,
                          killer=None,
                          sshConn=None,
                          dock_soft='PLANTS',
                          timemd=2.5,
                          clean=False,
                          remoteSettings=None,
                          modelFN='model.dat'):
    logging.info("Calculating interactions for job: %s" % job.filename)
    logging.info("State job %s: %s" % (job.filename, job.status))
    if job.status == 'COMPLETED':
        return
    if killer == None:
        killer = jobHandler.WarmKiller()
    killSig = os.path.join(job.dirTemp, 'KILL')
    initialStatus = job.status

    #LOAD MODEL INFO
    success, model = loadModel(os.path.join(modelDir, job.modelProt))
    if not success:
        job.status = 'FAILED'
        job.results = model

    # START CHECK/OPERATIONS
    try:
        if not os.path.isdir(job.dirTemp):
            os.mkdir(job.dirTemp)
    except Exception, e:
        job.status = 'FAILED'
        job.results = "Working directory not found or its creation failed: %s " % (
            e)
        logging.error('{0} {1}'.format(job.status, job.results))
예제 #2
0
def modelDesc(prot):
    protDir = os.path.join(settings.get('etoxlie_model_dir'), prot)
    success, model = modelHandler.loadModel(protDir,
                                            prediction=False,
                                            verModel=0,
                                            modelFN='model.dat')
    if not success:
        return "Model not found :'-("
    logging.debug('Load model {0} version {1} from: {2}'.format(
        prot, 0, protDir))

    # Source model parameters
    return render_template('modelDesc.html', model=model)
예제 #3
0
def modelDescVer(prot, ver):
    protDir = os.path.join(settings.get('etoxlie_model_dir'), prot)
    success, (model, params) = modelHandler.loadModel(protDir,
                                                      prediction=True,
                                                      verModel=int(ver),
                                                      modelFN='model.dat')
    logging.debug('Load model {0} version {1} from: {2}'.format(
        prot, ver, protDir))

    # compute pearson r, spearman s
    Gcalc = [float(x['Gcalc']) for x in params['trainSet']]
    Gexp = [float(x['Gexp']) for x in params['trainSet']]

    idxs = sorted(list(range(len(Gcalc))), key=lambda x: Gcalc[x])
    rankGcalc = [0] * len(idxs)
    for i, x in enumerate(idxs):
        rankGcalc[x] = i

    idxs = sorted(list(range(len(Gexp))), key=lambda x: Gexp[x])
    rankGexp = [0] * len(idxs)
    for i, x in enumerate(idxs):
        rankGexp[x] = i

    s = corrcoef(rankGexp, rankGcalc)[0, 1]
    r = corrcoef(Gexp, Gcalc)[0, 1]

    params['r'] = r
    params['s'] = s
    params['date'] = time.strftime("%Y/%m/%d\n%H:%M:%S",
                                   time.localtime(params['creation_date']))

    img = plotting.plotLIE(params['trainSet'])
    svg = plotting.fixSVG(img, h=400)

    return render_template('modelVersDesc.html', param=params,
                           plot=svg)  #send_file(a, mimetype='image/svg+xml'))
예제 #4
0
def submitScreen(sdfFn,
                 modelId,
                 prediction,
                 etoxlie_folder='.',
                 fieldExp='Activity',
                 misc=None,
                 jobid=None):
    # sdfFn: filename sdf
    # modelId: {'modelProt': 1A2; 'modelProtVer':1}
    # prediction: True or False
    # in case of prediction=False: misc={'isGamma':True|False,'fixBeta':True|False}
    # 1. check sdf
    status = 'SUBMITTED'
    if os.path.exists(sdfFn):
        with open(sdfFn, 'r') as infile:
            sdf = infile.read()

    else:
        results = "File not found: %s" % sdfFn
        status = 'FAILED'
        sdf = ''

    # 2 Checking consistency of work and models
    if status != 'FAILED':
        # A. check other runs, in case start
        listJobs = jobHandler.collectJobs(cpd=False, sort=True)
        for job in listJobs:
            if job.status != 'FAILED':
                if sdf == job.sdf:
                    if modelId['modelProt'] == job.modelProt:
                        if modelId['modelProtVer'] == job.modelProtVer:
                            if prediction == job.prediction:
                                if not prediction:
                                    if misc == job.experiment:
                                        status = 'FAILED'
                                        results = 'SDF screen is already in process (jobID: %s)' % job.filename

    if status != 'FAILED':
        # B. check model in case quit
        success, results = loadModel(os.path.join(modelDir,
                                                  modelId['modelProt']),
                                     prediction=prediction,
                                     verModel=modelId['modelProtVer'])
        if success:
            if prediction:
                model, params = results
            else:
                model = results
        else:
            results = results
            status = 'FAILED'

    # 3 Create job
    if status != 'FAILED':
        jobSDR = jobHandler.jobCpd()
        jobSDR.create(sdf,
                      modelId['modelProt'],
                      modelId['modelProtVer'],
                      prediction=prediction,
                      jobid=jobid)
        jobSDR.sdf = sdf
        jobSDR.experiment = misc

    # 4 Now submit jobs (if already submitted, link to the existing
    if status != 'FAILED':
        success, results = submitCPD(sdf, modelId['modelProt'],
                                     modelId['modelProtVer'], prediction,
                                     fieldExp)
        if success:
            jobSDR.results = results
        else:
            jobSDR.status = 'FAILED'
            jobSDR.results = results

        jobSDR.update()

    if status == 'FAILED':
        return (False, results)
    else:
        return (True, jobSDR.filename)
예제 #5
0
def screenSDF(listCpds, prediction, modelProt, modelProtVer, misc):
    # Check all the processes of a sdf screening, update status job and status single cpds runs in results
    updated = False
    status = 'SUBMITTED'
    try:
        completed = True
        for nc, cpd in enumerate(listCpds):
            # Check status single cpd (only if not already finished)
            if cpd['Status'] not in statEndJob:
                completed = False
                jobCpd = jobHandler.jobCpd()
                jobCpd.load(os.path.join(modelDir, cpd['JobName']))
                #Update progress
                if cpd['Status'] != jobCpd.status:
                    updated = True
                    listCpds[nc]['Status'] = jobCpd.status
                    listCpds[nc]['Results'] = jobCpd.results
                    if jobCpd.status == 'DONE':
                        if prediction:
                            ### PREDICT COMPOUND AND UPDATE RESULTS WITH PREDICTION
                            #here function for pred and AD. Results is a list of dictionaries containing energies for each simulation
                            data = getEnergies([listCpds[nc]])
                            success, results = loadModel(os.path.join(
                                modelDir, modelProt),
                                                         prediction=True,
                                                         verModel=modelProtVer)
                            if not success:
                                print results
                                listCpds[nc]['Status'] = 'FAILED'
                                #raise Exception, results
                                continue
                            else:
                                modelLIE, params = results
                            try:
                                Gcalc, idposes, wi, sdep, sspred = predictLie(
                                    data, params['LIE'])
                                listCpds[nc]
                                listCpds[nc]['DGexp'] = None
                                listCpds[nc]['DGcalc'] = Gcalc[0]
                                listCpds[nc]['idpose'] = idposes[0]
                                listCpds[nc]['wi'] = wi[0]

                                CI = predictAD(data, {
                                    'DGcalc': Gcalc,
                                    'idposes': idposes,
                                    'wi': wi
                                }, params['AD'])
                                listCpds[nc]['CI_analysis'] = CI[0]
                                listCpds[nc]['CI'] = sum(CI[0].values())
                                listCpds[nc]['Err'] = predictError(
                                    sum(CI[0].values()), params['LIE']['sdep'])
                                logging.info('RESULTS:')
                                for item in listCpds[nc]:
                                    logging.info("{0} {1}".format(
                                        item, listCpds[nc][item]))

                                logging.info('END RESULTS')
                            except Exception, e:
                                logging.error(
                                    'Error in computing energy for job %s: %s'
                                    % (cpd['JobName'], e))
                                listCpds[nc]['Status'] = 'FAILED'
                                continue

        if completed:
            logging.info('Job completed')
            if not prediction:
                # check type of calibration for backward compatibility:
                if misc == None:
                    misc = {'isGamma': False, 'fixBeta': False}
                # Here collect energies
                print 'GET ENERGIES'
                data = getEnergies(
                    listCpds
                )  # results is a dictionary with {ids, Y, ene, smi, decVdw, decEle}
                logging.info(
                    'Starting calibration for protein %s, version %s' %
                    (modelProt, modelProtVer))
                # Here create model
                print 'CALIBRATE LIE'
                LIEmodel = calibrateLie(data,
                                        gamma=misc['isGamma'],
                                        fixBeta=misc['fixBeta'])
                print 'CALIBRATE AD'
                ADmodel = calibrateAD(data, LIEmodel)
                modelId = {
                    'modelProt': modelProt,
                    'modelProtVer': '%04d' % modelProtVer
                }
                print 'SAVE MODEL'
                success, out = saveModel(modelDir, modelId, LIEmodel, ADmodel)
                if not success:
                    status = 'FAILED'
                    raise Exception, out

                logging.info('New model saved on file %s' % out)
                deltaId = 0
                for n, id in enumerate(data['ids']):
                    if listCpds[id + deltaId]['Status'] == 'DONE':
                        listCpds[id + deltaId]['DGcalc'] = LIEmodel['Gcalc'][n]
                        listCpds[id + deltaId]['idpose'] = LIEmodel['idx'][n]
                        listCpds[id + deltaId]['wi'] = LIEmodel['wi'][n]
                    else:
                        deltaId += 1

            status = 'DONE'
            updated = True

        results = listCpds