calctop.py
def evaluate_fold(testfile, caffemodel, modelname,root_folder):
    '''Evaluate the passed model and the specified test set.
    Assumes the .model file is named a certain way.
    Returns tuple:
    (correct, prediction, receptor, ligand, label (optional), posescore (optional))
    label and posescore are only provided is trained on pose data
    ''' 
    caffe.set_mode_gpu()
    test_model = ('predict.%d.prototxt' % os.getpid())
    print(("test_model:" + test_model))
    train.write_model_file(test_model, modelname, testfile, testfile, root_folder)
    test_net = caffe.Net(test_model, caffemodel, caffe.TEST)
    lines = open(testfile).readlines()

    res = None
    i = 0 #index in batch
    correct = 0
    prediction = 0
    receptor = ''
    ligand = ''
    label = 0
    posescore = -1
    ret = []
    
    for line in lines:
        #check if we need a new batch of results
        if not res or i >= batch_size:
            res = test_net.forward()
            if 'output' in res:
                batch_size = res['output'].shape[0]
            else:
                batch_size = res['affout'].shape[0]
            i = 0

        if 'labelout' in res:
            label = float(res['labelout'][i])
        if 'output' in res:
            posescore = float(res['output'][i][1])
        if 'affout' in res:
            correct = float(res['affout'][i])
        if 'predaff' in res:
            prediction = float(res['predaff'][i])
            if not np.isfinite(prediction).all():
                os.remove(test_model)
                return [] #gracefully handle nan?

        #extract ligand/receptor for input file
        tokens = line.split()
        linelabel = int(tokens[0])
        for t in range(len(tokens)):
            if tokens[t].endswith('gninatypes'):
                receptor = tokens[t]
                ligand = tokens[t+1]
                break
        
        #(correct, prediction, receptor, ligand, label (optional), posescore (optional))       
        if posescore < 0:
            ret.append((correct, prediction, receptor, ligand))
        else:
            ret.append((correct, prediction, receptor, ligand, label, posescore))
            
        if int(label) != linelabel: #sanity check
            print("Mismatched labels in calctop:",(label,linelabel,correct, prediction, receptor, ligand))
            sys.exit(-1)
        i += 1 #batch index
        
    os.remove(test_model)
    return ret
Evaluate the passed model and the specified test set.
    Assumes the .model file is named a certain way.
    Returns tuple:
    (correct, prediction, receptor, ligand, label (optional), posescore (optional))
    label and posescore are only provided is trained on pose data
    
Evaluate the passed model and the specified test set.
Assumes the .model file is named a certain way.
Returns tuple:
(correct, prediction, receptor, ligand, label (optional), posescore (optional))
label and posescore are only provided is trained on pose data
Evaluate the passed model and the specified test set . Assumes the . model file is named a certain way . Returns tuple : ( correct prediction receptor ligand label ( optional ) posescore ( optional )) label and posescore are only provided is trained on pose data
def evaluate_fold(testfile, caffemodel, modelname,root_folder):
    caffe.set_mode_gpu()
    test_model = ('predict.%d.prototxt' % os.getpid())
    print(("test_model:" + test_model))
    train.write_model_file(test_model, modelname, testfile, testfile, root_folder)
    test_net = caffe.Net(test_model, caffemodel, caffe.TEST)
    lines = open(testfile).readlines()
    res = None
    i = 0 
    correct = 0
    prediction = 0
    receptor = ''
    ligand = ''
    label = 0
    posescore = -1
    ret = []
    for line in lines:
        if not res or i >= batch_size:
            res = test_net.forward()
            if 'output' in res:
                batch_size = res['output'].shape[0]
            else:
                batch_size = res['affout'].shape[0]
            i = 0
        if 'labelout' in res:
            label = float(res['labelout'][i])
        if 'output' in res:
            posescore = float(res['output'][i][1])
        if 'affout' in res:
            correct = float(res['affout'][i])
        if 'predaff' in res:
            prediction = float(res['predaff'][i])
            if not np.isfinite(prediction).all():
                os.remove(test_model)
                return [] 
        tokens = line.split()
        linelabel = int(tokens[0])
        for t in range(len(tokens)):
            if tokens[t].endswith('gninatypes'):
                receptor = tokens[t]
                ligand = tokens[t+1]
                break
        if posescore < 0:
            ret.append((correct, prediction, receptor, ligand))
        else:
            ret.append((correct, prediction, receptor, ligand, label, posescore))
        if int(label) != linelabel: 
            print("Mismatched labels in calctop:",(label,linelabel,correct, prediction, receptor, ligand))
            sys.exit(-1)
        i += 1 
    os.remove(test_model)
    return ret
def evaluate_fold ( testfile , caffemodel , modelname , root_folder ) : caffe . set_mode_gpu ( ) test_model = ( 'predict.%d.prototxt' % os . getpid ( ) ) print ( ( "test_model:" + test_model ) ) train . write_model_file ( test_model , modelname , testfile , testfile , root_folder ) test_net = caffe . Net ( test_model , caffemodel , caffe . TEST ) lines = open ( testfile ) . readlines ( ) res = None i = 0 correct = 0 prediction = 0 receptor = '' ligand = '' label = 0 posescore = - 1 ret = [ ] for line in lines : if not res or i >= batch_size : res = test_net . forward ( ) if 'output' in res : batch_size = res [ 'output' ] . shape [ 0 ] else : batch_size = res [ 'affout' ] . shape [ 0 ] i = 0 if 'labelout' in res : label = float ( res [ 'labelout' ] [ i ] ) if 'output' in res : posescore = float ( res [ 'output' ] [ i ] [ 1 ] ) if 'affout' in res : correct = float ( res [ 'affout' ] [ i ] ) if 'predaff' in res : prediction = float ( res [ 'predaff' ] [ i ] ) if not np . isfinite ( prediction ) . all ( ) : os . remove ( test_model ) return [ ] tokens = line . split ( ) linelabel = int ( tokens [ 0 ] ) for t in range ( len ( tokens ) ) : if tokens [ t ] . endswith ( 'gninatypes' ) : receptor = tokens [ t ] ligand = tokens [ t + 1 ] break if posescore < 0 : ret . append ( ( correct , prediction , receptor , ligand ) ) else : ret . append ( ( correct , prediction , receptor , ligand , label , posescore ) ) if int ( label ) != linelabel : print ( "Mismatched labels in calctop:" , ( label , linelabel , correct , prediction , receptor , ligand ) ) sys . exit ( - 1 ) i += 1 os . remove ( test_model ) return ret
Evaluate the passed model and the specified test set.
Evaluate the passed model and the specified test set .
'''Evaluate the passed model and the specified test set.
    Assumes the .model file is named a certain way.
    Returns tuple:
    (correct, prediction, receptor, ligand, label (optional), posescore (optional))
    label and posescore are only provided is trained on pose data
    ''' #index in batch #check if we need a new batch of results #gracefully handle nan? #extract ligand/receptor for input file #(correct, prediction, receptor, ligand, label (optional), posescore (optional))        #sanity check #batch index
testfile
caffemodel
modelname
root_folder