Ejemplo n.º 1
0
def importEXP(request):

    #load db with an initial value, if first time user
    defEXP = dbEXPupload(username=request.user.username, EXPupload='none chosen')
    defEXP.save()

    #get loaded Results data, if any, for the Testing Refresh, otherwise it will blank
    rerun = getLoadDict(request.user.username)


    # maybe use UploadDataForm and have def to chunk: https://docs.djangoproject.com/en/1.8/topics/http/file-uploads/
    if request.method == 'GET':
       EXP = EXPuploadForm(initial={'username': request.user.username,'EXPupload': 'none chosen'})

    else:
        EXP = EXPuploadForm(request.POST, request.FILES)
        if EXP.is_valid():
            entry=dbEXPupload(username = request.POST.get('username'),
                        EXPupload = request.FILES['EXPupload']
                        )                           #this is name of col in DB
            entry.save()
        else:
            EXP = EXPuploadForm(initial={'username': request.user.username,'EXPupload': 'none chosen'})

    #update newrundict.txt (to-be-run-parameters) via the toberun function
    query = 'SELECT * FROM Inputs_dbexpupload WHERE username = "******" ORDER BY id DESC LIMIT 1'
    object = dbEXPupload.objects.raw(query)[0]
    ToBeRunDict = toberun(object)

    return render(request, 'main.html',
          {'EXPHTML' : EXP,
            'ToBeRunHTML' : ToBeRunDict, 'resultsHTML': rerun})
Ejemplo n.º 2
0
def importPDBup(request):

    #load db with an initial value, if first time user
    defUp = dbPDBup(username=request.user.username, PDBup='none chosen')
    defUp.save()
    
    #get loaded Results data, if any, for the Testing Refresh, otherwise it will blank
    rerun = getLoadDict(request.user.username)

    # maybe use UploadDataForm and have def to chunk: https://docs.djangoproject.com/en/1.8/topics/http/file-uploads/
    if request.method == 'GET':
        PDBup = PDBupForm(initial={'username': request.user.username,'PDBup': 'none chosen'})

    else:
        PDBup = PDBupForm(request.POST, request.FILES)
        if PDBup.is_valid():
            entry=dbPDBup(username = request.POST.get('username'),
                        PDBup = request.FILES['PDBup']
                        ) #obj containing files
            entry.save()
        else:
            PDBup = PDBupForm(initial={'username': request.user.username,'PDBup': 'none chosen'})


    #update dbtoberun via the toberun function
    query = 'SELECT * FROM Inputs_dbpdbup WHERE username = "******" ORDER BY id DESC LIMIT 1'
    object = dbPDBup.objects.raw(query)[0]
    ToBeRunDict = toberun(object)


    return render(request, 'main.html',
          {'PDBupHTML' : PDBup,
            'ToBeRunHTML' : ToBeRunDict, 'resultsHTML': rerun})
Ejemplo n.º 3
0
def Clear(request):
    #get -loaded- Results data, if any, for the Refresh, otherwise it will blank
    rerun = getLoadDict(request.user.username)
    if request.method == 'POST':   #if clear is pressed....
        #default all possible choices, save to appropriate db
        defDown = dbPDBdown(username=request.user.username, PDBdown='none chosen')
        defDown.save()
        defUp = dbPDBup(username=request.user.username, PDBup='none chosen')
        defUp.save()
        defEXP = dbEXPupload(username=request.user.username, EXPupload='none chosen')
        defEXP.save()
        defPara = dbPara(username=request.user.username, jobname=' ', turns=5, units=27, rise=2.9, rescutL=0.0833333333, rescutH=0.3333333333, LorR='R')
        defPara.save()
        defPara2 = dbPara2(username=request.user.username, bfactor=20.0, bfactorSolv=400, bfactorSolvK=0.4, gridPhi=128,
                           gridR=256, gridZ=128, qfhtK1=2.0, qfhtK2=2.2, rfactor='False', scscaling=0.92, R_step=0.001,
                           layer_lines=20)
        defPara2.save()

        #now make a new newrundict.txt with default values
        newrundict(request.user.username)

        #retrieve the newrundict.txt to display 'to be run' files and parameters
        import json
        thefile = PathMaker(request.user.username, 'newrundict.txt')
        FHin = open(thefile, 'r')  #now open the new file
        #take out the dict
        defaultDict = json.load(FHin)
        FHin.close()
        #now run to default everything
        return render(request, 'main.html', {
            'ToBeRunHTML' : defaultDict, 'resultsHTML': rerun})
Ejemplo n.º 4
0
def importPara2(request):

    #load db with an initial value, if first time user
    defPara2 = dbPara2(username=request.user.username, bfactor=20.0, bfactorSolv=400, bfactorSolvK=0.4, gridPhi=128,
                           gridR=256, gridZ=128, qfhtK1=2.0, qfhtK2=2.2, rfactor='False', scscaling=0.92, R_step=0.001,
                           layer_lines=20)
    defPara2.save()

    #get loaded Results data, if any, for the Testing Refresh, otherwise it will blank
    rerun = getLoadDict(request.user.username)

    if request.method == 'GET':
        Parameters = AddParaForm(initial={'username': request.user.username, 'rfactor':'False', 'bfactor':20.0, 'bfactorSolv':400, 'bfactorSolvK':0.4, 'qfhtK1':2.0, 'qfhtK2':2.2, 'scscaling':0.92, 'gridR':256, 'gridZ':128, 'gridPhi':128,'R_step':0.001, 'layer_lines':20})
    else:
        Parameters = AddParaForm(request.POST)
        if Parameters.is_valid():
            entry=dbPara2(username = request.POST.get('username'),
                        rfactor = request.POST.get('rfactor'),
                        bfactor = request.POST.get('bfactor'),
                        bfactorSolv = request.POST.get('bfactorSolv'),
                        bfactorSolvK = request.POST.get('bfactorSolvK'),
                        qfhtK1 = request.POST.get('qfhtK1'),
                        qfhtK2 = request.POST.get('qfhtK2'),
                        scscaling = request.POST.get('scscaling'),
                        gridR =request.POST.get('gridR'),
                        gridZ= request.POST.get('gridZ'),
                        gridPhi = request.POST.get('gridPhi'),
                        R_step= request.POST.get('R_step'),
                        layer_lines = request.POST.get('layer_lines'))
            entry.save()
        else:
           Parameters = AddParaForm(initial={'username': request.user.username, 'rfactor':'False', 'bfactor':20.0, 'bfactorSolv':400, 'bfactorSolvK':0.4, 'qfhtK1':2.0, 'qfhtK2':2.2, 'scscaling':0.92, 'gridR':256, 'gridZ':128, 'gridPhi':128, 'R_step':0.001, 'layer_lines':20})

    #update newrundict.txt (to-be-run-parameters) via the toberun function
    query = 'SELECT * FROM Inputs_dbpara2 WHERE username = "******" ORDER BY id DESC LIMIT 1'
    object = dbPara2.objects.raw(query)[0]
    ToBeRunDict = toberun(object)

    #RENDER
    return render(request, 'main.html',
              {'AddHTML' : Parameters,
                'ToBeRunHTML' : ToBeRunDict, 'resultsHTML': rerun})
Ejemplo n.º 5
0
def importParameters(request):

    #load db with an initial value, if first time user
    defPara = dbPara(username=request.user.username, jobname=' ', turns=5, units=27, rise=2.9, rescutL=0.0833333333, rescutH=0.3333333333, LorR='R')
    defPara.save()

    #get loaded Results data, if any, for the Testing Refresh, otherwise it will blank
    rerun = getLoadDict(request.user.username)

    if request.method == 'GET':
        Parameters = ParaForm(initial={'username': request.user.username, 'jobname': ' ', 'turns':5, 'units':27, 'rise':2.9, 'rescutL':0.0833333333, 'rescutH':0.3333333333, 'LorR':'R'})
    else:
        Parameters = ParaForm(request.POST)
        if Parameters.is_valid():
            entry=dbPara(username = request.POST.get('username'),
                        jobname = request.POST.get('jobname'),
                        turns = request.POST.get('turns'),
                        units = request.POST.get('units'),
                        rise = request.POST.get('rise'),
                        rescutL = request.POST.get('rescutL'),
                        rescutH = request.POST.get('rescutH'),
                        LorR = request.POST.get('LorR')
                        )
            entry.save()
        else:
           Parameters = ParaForm(initial={'username': request.user.username, 'jobname': ' ', 'turns':5, 'units':27, 'rise':2.9, 'rescutL':0.0833333333, 'rescutH':0.3333333333, 'LorR':'R'})

    #update newrundict.txt (to-be-run-parameters) via the toberun function
    query = 'SELECT * FROM Inputs_dbpara WHERE username = "******" ORDER BY id DESC LIMIT 1'
    object = dbPara.objects.raw(query)[0]
    ToBeRunDict = toberun(object)

    #RENDER
    return render(request, 'main.html',
              {'ParaHTML' : Parameters,
              'ToBeRunHTML' : ToBeRunDict, 'resultsHTML': rerun})
Ejemplo n.º 6
0
def Testing(request):

    #get loaded Results data, if any, for the Testing Refresh, otherwise it will blank
    #should be blank prior to first load request
    rerun = getLoadDict(request.user.username)

    #include ToBeRun dictionary from inputs
    ToBeRunDict = getRunDict(request.user.username)

    #if Run is pressed....
    if request.method == 'POST':   

        #check here if no PDB
        #if ...

        #SQL to make query objects for each table
        #****************************************
        #download
        query = 'SELECT * FROM Inputs_dbpdbdown WHERE username = "******" ORDER BY id DESC LIMIT 1'
        Qobject = dbResults.objects.raw(query)[0]

        #upload
        query = 'SELECT * FROM Inputs_dbpdbup WHERE username = "******" ORDER BY id DESC LIMIT 1'
        Qobject2 = dbPDBup.objects.raw(query)[0]

        #Experimental
        query = 'SELECT * FROM Inputs_dbexpupload WHERE username = "******" ORDER BY id DESC LIMIT 1'
        Qobject3 = dbEXPupload.objects.raw(query)[0]

        #Parameters
        query = 'SELECT * FROM Inputs_dbpara WHERE username = "******" ORDER BY id DESC LIMIT 1'
        Qobject4 = dbPara.objects.raw(query)[0]

        #Additional Parameters
        query = 'SELECT * FROM Inputs_dbpara2 WHERE username = "******" ORDER BY id DESC LIMIT 1'
        Qobject4B = dbPara2.objects.raw(query)[0]

        #Identify the most current upload or download by timestamp, choose most recent
        if Qobject.timestamp > Qobject2.timestamp:
            chosenPDB = fetch_pdb(Qobject)
        else:
            chosenPDB = 'static_in_pro/media_root/' + str(Qobject2.PDBup)

        #make grid.dat
        #*************
        #default expLL: Need Hcutoff and Lcutoff (as floating numbers)
        #output is grid.dat, which is used to for making EXP in flag file
        makeDefExp(Qobject.username, float(Qobject4.rescutH), float(Qobject4.rescutL), int(Qobject4B.layer_lines), float(Qobject4B.R_step))

        #Make FlagsFile using the query objects
        #**************************************
        #overwrite for reruns
        overwrite = '-out:overwrite'
        #db path for rosetta, otherwise its default, somewhere on server
        db = '-database /home/stephen/Project/trydjango/static_in_pro/media_root/Storage/database'
        #add sdef from helix_denovo output
        sdef = '-symmetry:symmetry_definition ' + '/home/stephen/Project/trydjango/' + PathMaker(Qobject.username, 'helix_denovo.sdef')
        #needed for some reason
        extra = '-symmetry:initialize_rigid_body_dofs'      
        #the chosen PDB, based on most recent timestamp
        PDB = '-in:file:s '+ '/home/stephen/Project/trydjango/' + str(chosenPDB)   
        #if experimental is 'none chosen', grid.dat needs to be used in its place
        if 'none chosen' in str(Qobject3.EXPupload):
            EXP = '-fiber_diffraction:layer_lines ' + '/home/stephen/Project/trydjango/' + PathMaker(Qobject.username, 'grid.dat')
        else:
            EXP = '-fiber_diffraction:layer_lines ' + 'static_in_pro/media_root/' + str(Qobject3.EXPupload)
        #generic inputs
        Units = '-fiber_diffraction:a '+ str(Qobject4.units)     #number of units
        Turns = '-fiber_diffraction:b '+ str(Qobject4.turns)    #number of turns
        Rise = '-fiber_diffraction:p '+ str(Qobject4.rise)     #If specified, subunit rise is taken from input, otherwise is calculated by the program
        Lcutoff = '-fiber_diffraction:resolution_cutoff_low '+ str(Qobject4.rescutL)  #Resolution cutoff 12�
        Hcutoff = '-fiber_diffraction:resolution_cutoff_high '+ str(Qobject4.rescutH)  #Resolution cutoff 3�
        #Additional Parameters
        Rfac = '-fiber_diffraction:rfactor_refinement '+ str(Qobject4B.rfactor)    #If set R factor instead of chi2 is used in scoring and derivatives calculations
        AtomicBF = '-fiber_diffraction::b_factor '+ str(Qobject4B.bfactor)    #Atomic B-factor
        Solv = '-fiber_diffraction::b_factor_solv '+ str(Qobject4B.bfactorSolv)   #temperature factor that accounts for the disordered solvent
        SolvK = '-fiber_diffraction::b_factor_solv_K '+ str(Qobject4B.bfactorSolvK)   #scale factor that adjust average solvent scattering intensity
        K1 = '-fiber_diffraction:qfht_K1 '+ str(Qobject4B.qfhtK1)    #Hankel transform K1 parameter
        K2 = '-fiber_diffraction:qfht_K2 '+ str(Qobject4B.qfhtK2)      #Hankel transform K1 parameter
        SC = '-edensity:sc_scaling '+ str(Qobject4B.scscaling)    #Hankel transform K1 parameter
        GridR = '-fiber_diffraction:grid_r '+ str(Qobject4B.gridR)     #Grid size r, should be bigger than radius of molecule
        GridZ = '-fiber_diffraction:grid_z '+ str(Qobject4B.gridZ)     #Grid size z, should be bigger than molecule span in z direction
        GridPhi = '-fiber_diffraction:grid_phi '+ str(Qobject4B.gridPhi)    #Grid size phi, change if higher accuracy is needed
        #output for Rosetta_programs
        fibPDBout = '-out:output ' 
        outputpath = '-out:path:pdb ' + PathMaker(Qobject.username, '')  #Rosetta decides name of fibrilPDB, we can only prefix it
        prefix = '-out:prefix ' + 'RUN' + str(tagOutput(request)) + '_'
        LLout = '-fiber_diffraction:output_fiber_spectra' #+ PathMaker(Qobject.username, 'Intensity.txt')   #to make LLpic, stored in user's folder'
        Score = '-out:file:scorefile ' + '/home/stephen/Project/trydjango/' + PathMaker(Qobject.username, 'score.sc')
        scoreWeights = '-score:weights /home/stephen/Project/trydjango/static_in_pro/media_root/Rosetta_files/fiberdiffraction.txt'  #text file is only “fiberdiffraction 1”
               
        #make a list of the above variables
        ParameterList = [
                         overwrite,
                         db,
                         sdef,
                         extra,
                         PDB,
                         EXP,
                         Units,
                         Turns,
                         Rise,
                         Lcutoff,
                         Hcutoff,
                         Rfac,
                         AtomicBF,
                         Solv,
                         SolvK,
                         K1,
                         K2,
                         SC,
                         GridR,
                         GridZ,
                         GridPhi,
                         fibPDBout,
                         LLout,
                         Score,
                         prefix,
                         outputpath,
                         scoreWeights]

        #make the Flags file, tagged with username, placed in user's folder
        filename = str(Qobject.username) + '_Flags'
        Path = PathMaker(Qobject.username, filename)
        FHout = open(Path, 'w')
        for item in ParameterList:
            FHout.write("%s\n" % item)
        FHout.close()
        #now save path to dbFlags
        addFlag = dbFlag(username=Qobject.username, FlagFile=Path)
        addFlag.save()

        #Path variables for dbResults  **make sure their -creation- also points to same user dir
        #Paths needed for make_helix_denovo
        denovoPath = str(PathMaker(Qobject.username, 'helix_denovo.sdef'))
        virtualsPath = str(PathMaker(Qobject.username, 'virtuals.pdb'))
        #for Rosetta     
        fibrilPDBPath = str(PathMaker(Qobject.username, fibRename(request, chosenPDB))) #Rosetta outputs odd name, so need function to match it for db
        intensityPath = str(PathMaker3(Qobject.username, 'Intensity_' + str(tagOutput(request)) + '.txt')) #need special path correction; see PathMaker3
        scorePath = str(PathMaker(Qobject.username, 'score.sc'))
        #for layerlinestoimage
        LLpicPath = str(PathMaker(Qobject.username, 'layerlines_run' + str(tagOutput(request)) + '.png')) #note: need to save this file for future load requests

        #Run make_helix_denovo:
        #*********************
        #input: units/rise/turns/N=40, plus path to .sdef output, path to virtualPDB
        helixer = Helixer(float(Qobject4.rise), int(40), int(Qobject4.turns), int(Qobject4.units), denovoPath, virtualsPath)
        #Executing pipeline
        helixer.execute()
        helixer.write()
        helixer.writePDBlines()
        #output of helix_denovo.sdef 'symmetry definition file'
        #output of virtuals.pdb: virtual_residues_file also made each run: for diagnostics

        #run Rosetta
        #***********
        #query dbFlag and make an object containing everything
        query = 'SELECT * FROM Run_dbflag WHERE username = "******" ORDER BY id DESC LIMIT 1'
        Qobject5 = dbFlag.objects.raw(query)[0]

        #inputs: see Flagfile
        program = '/home/stephen/Project/trydjango/static_in_pro/media_root/Rosetta_programs/score.static.linuxgccrelease'
        addflag = '@' + '/home/stephen/Project/trydjango/' + str(Qobject5.FlagFile) #need to add prefix path, since not django       
        together = program + ' ' + addflag
        Path2 = PathMaker(Qobject.username, 'cmd')
        FHout2 = open(Path2, 'w')
        FHout2.write("%s\n" % together)
        FHout2.close()
        os.system('chmod 775 ' + Path2)
        os.system(Path2)
        #outputs: fibril.pdb, intensity.txt(LLout), score.sc (for making chi-sq)+ scoreweights (ignore)
       
        #move intensity.txt from Project/tryjango to user dir and rename (to intensityPath)
        moveInten(request)
       
        #Run LayerLinesToImage
        #*********************
        #output: layerlines.png stored in LLpic attribute
        output = PathMaker(Qobject.username, 'layerlines_run' + str(tagOutput(request)) + '.png')
        experimental = str(Qobject3.EXPupload)
        layerlines = LLTI(intensityPath, experimental, output, str(tagOutput(request)))
        layerlines.convert_to_image(str(tagOutput(request))) #need to include RUNX here as well...

        #Derive Chisq
        #************
        #note! if no expLL (just grid.dat) , then score should be empty and no chisq made!!!!!
        Chisq=findChisq(scorePath, Qobject.username)   #parses Score file, which was produced by Rosetta_programs
        
        #add to most recent run
        mostrecent = int(tagOutput(request))
        
        #Save Results
        #************
        #load inputs and  results to dbResults
        addResults = dbResults(mostRes=mostrecent,  #Add to mostRec runcount
                               username=Qobject.username,
                               PDBused=chosenPDB,
                               experimentalData= Qobject3.EXPupload,
                               jobname=Qobject4.jobname,
                               turns=Qobject4.turns,
                               units=Qobject4.units,
                               rise=Qobject4.rise,
                               rescutL=Qobject4.rescutL,
                               rescutH=Qobject4.rescutH,
                               LorR=Qobject4.LorR,
                               rfactor=Qobject4B.rfactor,
                               bfactor=Qobject4B.bfactor,
                               bfactorSolv=Qobject4B.bfactorSolv,
                               bfactorSolvK=Qobject4B.bfactorSolvK,
                               qfhtK1 = Qobject4B.qfhtK1,
                               qfhtK2 = Qobject4B.qfhtK2,
                               scscaling = Qobject4B.scscaling,
                               gridR = Qobject4B.gridR,
                               gridZ= Qobject4B.gridZ,
                               gridPhi = Qobject4B.gridPhi,
                               R_step= Qobject4B.R_step,
                               layer_lines = Qobject4B.layer_lines,
                               fibrilPDB = fibrilPDBPath,
                               intensity = intensityPath,
                               LLoutputPic=LLpicPath,  #derived from LLtoImage
                               chisq = Chisq)  #derived from Score (see chisq function)
        addResults.save()

    
        #need to remove hydrogens from fibril pdb or Jsmol is slow
        removeHydrogen(fibrilPDBPath) 
    
    #RENDER
    #toreturn= UsedParam(Qobject6)      #note! UsedParam also includes newrundict.txt results for 'to be run' files/para
    return render(request, 'main.html', {'ToBeRunHTML' : ToBeRunDict, 'resultsHTML': rerun})