Ejemplo n.º 1
0
def parameters_input(request, JobID):
    clientStatistics(request)
    item = get_object_or_404(LogKJob, JobID=JobID)
    if request.method == 'POST':
        form = paraInputForm(request.POST, instance=item)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "2.1"
            model_instance.Successful = True
            model_instance.save()
            return redirect('/logk/review/%d' % int(model_instance.JobID))

    else:
        form = paraInputForm(instance=item)

    seqences = [
        'QMSoftware', 'QMTitle', 'QMCalType', 'QMProcessors', 'QMMemory',
        'QMFunctional', 'QMBasisSet', 'QMCharge', 'QMMultiplicity',
        'QMCoordinateFormat', 'QMSolvationModel', 'QMSolvent',
        'QMCavitySurface', 'QMScalingFactor'
    ]

    return render(request, 'logk/parameters_input.html', {
        'form': form,
        'JobID': JobID,
        'Fields': seqences
    })
Ejemplo n.º 2
0
def smiles_single(request, JobID, Mol):
    clientStatistics(request)

    # get job handle
    try:
        SPJob = pKaJob.objects.get(JobID=JobID)
    except:
        SPJob = pKaJob(JobID=JobID)

    if request.method == 'POST':
        if Mol in ['A']:
            form = SmilesForm(request.POST, request.FILES, instance=SPJob)
        elif Mol in ['HA']:
            form = SmilesFormP1(request.POST, request.FILES, instance=SPJob)

        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
            return redirect('/pka/parameters/%d' % int(JobID))
    else:
        if Mol in ['A']:
            form = SmilesForm(instance=SPJob)
        elif Mol in ['HA']:
            form = SmilesFormP1(instance=SPJob)

    return_dict = {'form': form, 'JobID': JobID, 'Mol': Mol}
    return render(request, 'pka/smiles_single.html', return_dict)
Ejemplo n.º 3
0
def trans(request, JobType, JobID):
    clientStatistics(request)
    '''to transfer the job from toolkit to other modules'''
    item = get_object_or_404(ToolkitJob, JobID=JobID)
    item_dict = model_to_dict(item)
    item_dict.pop('id', None)

    # copy the job infor to the module
    if JobType in ['csearch']:
        CSearchJob.objects.update_or_create(**item_dict)
        # report to all job id DB
        # same job from AllJobIDs
        obj = get_object_or_404(AllJobIDs, JobID=JobID)
        obj.SubJobType = JobType
        obj.save()
        return redirect('/%s/parameters/%s/' % (JobType, JobID))
    elif JobType in ['gsolv']:
        GSolvJob.objects.update_or_create(**item_dict)
        # report to all job id DB
        # same job from AllJobIDs
        obj = get_object_or_404(AllJobIDs, JobID=JobID)
        obj.SubJobType = JobType
        obj.CurrentStatus = 2
        obj.save()
        return redirect('/%s/parameters/%s/' % (JobType, JobID))
    elif JobType in ['pka', 'logk']:
        # report to all job id DB
        # same job from AllJobIDs
        obj = get_object_or_404(AllJobIDs, JobID=JobID)
        obj.SubJobType = JobType
        obj.CurrentStatus = 2
        obj.save()
        return redirect('/%s/trans2a/%s/' % (JobType, JobID))
Ejemplo n.º 4
0
def smiles(request, JobID):
    clientStatistics(request)

    # get job handle
    try:
        SPJob = pKaJob.objects.get(JobID=JobID)
    except:
        SPJob = pKaJob(JobID=JobID)

    if request.method == 'POST':
        form = SmilesForm(request.POST, request.FILES, instance=SPJob)
        formP1 = SmilesFormP1(request.POST, request.FILES, instance=SPJob)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
        if formP1.is_valid():
            model_instance = formP1.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
        return redirect('/pka/parameters/%d' % int(JobID))
    else:
        form = SmilesForm(instance=SPJob)
        formP1 = SmilesFormP1(instance=SPJob)

    return render(request, 'pka/smiles.html', {'form': form, 'formP1': formP1, 'JobID': JobID})
Ejemplo n.º 5
0
def calculate(request, JobID):
    clientStatistics(request)

    # get job handle
    try:
        SPJob = GSolvJob.objects.get(JobID=JobID)
    except:
        SPJob = GSolvJob(JobID=JobID)

    if request.method == 'POST':
        form = UploadOutputForm(request.POST, request.FILES, instance=SPJob)
        formP1 = UploadOutputFormP1(request.POST, request.FILES, instance=SPJob)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "5"
            model_instance.Successful = True
            model_instance.save()
        if formP1.is_valid():
            model_instance = formP1.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "5"
            model_instance.Successful = True
            model_instance.save()
        return redirect('/gsolv/results/%d/%s/' % (int(JobID), 'gsolv_output'))
    else:
        form = UploadOutputForm(instance=SPJob)
        formP1 = UploadOutputFormP1(instance=SPJob)

    return render(request, 'gsolv/calculate.html', {'form': form, 'formP1': formP1, 'JobID': JobID})
Ejemplo n.º 6
0
def revise(request, JobID):
    clientStatistics(request)
    item = get_object_or_404(HgSpeciJob, JobID=JobID)

    jobmanger = JobManagement()
    jobmanger.HgspeciJobClean(obj=item)

    return redirect('/hgspeci/parameters/%d/' % int(JobID))
Ejemplo n.º 7
0
def smiles(request, JobID):
    clientStatistics(request)

    # get job handle
    try:
        SPJob = LogKJob.objects.get(JobID=JobID)
    except:
        SPJob = LogKJob(JobID=JobID)

    if request.method == 'POST':
        form = SmilesForm(request.POST, request.FILES, instance=SPJob)
        formP1 = SmilesFormP1(request.POST, request.FILES, instance=SPJob)
        formMetal = SmilesFormM(request.POST, request.FILES, instance=SPJob)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
        if formP1.is_valid():
            model_instance = formP1.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
        if formMetal.is_valid():
            model_instance = formMetal.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()

        if form.is_valid() and formP1.is_valid() and formMetal.is_valid():
            # convert smi to xyz
            jobmanger = JobManagement()
            try:
                jobmanger.Convert2XYZ(SPJob, JobType='logk')
                jobmanger.CheckElements(SPJob, JobType='logk')
            except Exception as e:
                SPJob.FailedReason += 'Could not convert smi to xyz, the reason is %s ' % (
                    e)
                SPJob.CurrentStatus = '1'
                SPJob.Successful = False
                SPJob.save()
                pass

        return redirect('/logk/parameters/%d' % int(JobID))
    else:
        form = SmilesForm(instance=SPJob)
        formP1 = SmilesFormP1(instance=SPJob)
        formMetal = SmilesFormM(instance=SPJob)

    return render(request, 'logk/smiles.html', {
        'form': form,
        'formP1': formP1,
        'formMetal': formMetal,
        'JobID': JobID
    })
Ejemplo n.º 8
0
def index(request):
    clientStatistics(request)
    NumElements = CalcSolutionMasterSpecies.objects.count()
    NumSpecies = CalcSolutionSpecies.objects.count()

    return render(request, 'calcdata/index.html',
                  {'NumElements': NumElements,
                  'NumSpecies': NumSpecies,
                   })
Ejemplo n.º 9
0
def trans2a(request, JobID):
    clientStatistics(request)
    item = get_object_or_404(ToolkitJob, JobID=JobID)

    # get job handle
    try:
        SPJob = LogKJob.objects.get(JobID=JobID)
    except:
        SPJob = LogKJob(JobID=JobID)

    if request.method == 'POST':
        form = TransToAForm(request.POST, request.FILES, instance=SPJob)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
            if model_instance.TransToA in ['A']:
                # copy the data to A
                model_instance.CurrentStep = item.CurrentStep
                model_instance.CurrentStatus = item.CurrentStatus
                model_instance.Name = item.Name
                model_instance.Successful = item.Successful
                model_instance.FailedReason = item.FailedReason

                model_instance.SmilesStr = item.SmilesStr
                model_instance.UploadedFile = item.UploadedFile
                model_instance.UploadedFileType = item.UploadedFileType
                model_instance.Note = item.Note

                model_instance.save()

                #return HttpResponse('upload HA')
                return redirect('/logk/smiles_single/%s/%s/' % (JobID, 'HA'))
            elif model_instance.TransToA in ['HA']:
                # copy the data to HA
                model_instance.CurrentStep = item.CurrentStep
                model_instance.CurrentStatus = item.CurrentStatus
                model_instance.Name = item.Name
                model_instance.Successful = item.Successful
                model_instance.FailedReason = item.FailedReason

                model_instance.SmilesStrP1 = item.SmilesStr
                model_instance.UploadedFileP1 = item.UploadedFile
                model_instance.UploadedFileTypeP1 = item.UploadedFileType
                model_instance.NoteP1 = item.Note

                model_instance.save()
                #return HttpResponse('upload A-')
                return redirect('/logk/smiles_single/%s/%s/' % (JobID, 'A'))
            elif model_instance.TransToA in ['None']:
                return redirect('/logk/start/')
    else:
        form = TransToAForm(instance=SPJob)

    return render(request, 'logk/trans2a.html', {'form': form})
Ejemplo n.º 10
0
def basic(request):
    clientStatistics(request)
    all_compounds = Compound.objects.all()
    return render(
        request,
        'expdata/basic.html',
        {
            'cpds': all_compounds,
        },
    )
Ejemplo n.º 11
0
def species(request):
    clientStatistics(request)
    all_species = CalcSolutionSpecies.objects.all()
    # get refs
    all_refs = []
    for p in all_species:
        all_refs.append(p.Ref)

    return render(request, 'calcdata/species.html',
                  {'all_species': all_species, 'refs': list(set(all_refs))})
Ejemplo n.º 12
0
def master(request):
    clientStatistics(request)
    all_master = CalcSolutionMasterSpecies.objects.all()
    all_master = sorted(all_master, key=lambda x: x.Element)
    # get refs
    all_refs = []
    for p in all_master:
        all_refs.append(p.Ref)

    return render(request, 'calcdata/master.html',
                  {'all_master': all_master, 'refs': list(set(all_refs))})
Ejemplo n.º 13
0
def parameters_input(request, JobID):
    clientStatistics(request)
    # get job handle
    try:
        SPJob = HgSpeciJob.objects.get(JobID=JobID)
    except:
        SPJob = HgSpeciJob(JobID=JobID)

    # determine how many input areas should provide
    if len(SPElements.objects.filter(JobID=JobID)) > 0:
        SPElementsInlineFormSet = inlineformset_factory(HgSpeciJob, SPElements, form=SPElementsForm, extra=0,
                                                        can_delete=False)
    else:
        SPElementsInlineFormSet = inlineformset_factory(HgSpeciJob, SPElements, form=SPElementsForm, extra=1,
                                                        can_delete=False)

    if request.method == 'POST':
        paraform = ParameterForm(request.POST, request.FILES, instance=SPJob, prefix='main')
        formset = SPElementsInlineFormSet(request.POST, request.FILES, instance=SPJob, prefix='spelements')
        dbform = SPDBtoUseForm(request.POST, request.FILES, instance=SPJob, prefix='db')

        if dbform.is_valid():
            model_instance = dbform.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1.1"
            model_instance.Successful = True
            model_instance.save()
            dbform.save()

        if paraform.is_valid() and formset.is_valid():
            model_instance = paraform.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
            paraform.save()

            for form in formset.forms:
                form_instance = form.save(commit=False)
                form_instance.JobID = JobID
                #form_instance.save() # will be saved after submitted
            formset.save()

            return redirect('/hgspeci/review/%d' % int(JobID))
    else:
        paraform = ParameterForm(instance=SPJob, prefix='main')
        formset = SPElementsInlineFormSet(instance=SPJob, prefix='spelements')
        dbform = SPDBtoUseForm(instance=SPJob, prefix='db')

    return render(request, 'hgspeci/parameters_input.html',
                  {'paraform': paraform, 'formset': formset, 'dbform': dbform, 'JobID': JobID})
Ejemplo n.º 14
0
def smiles(request):
    clientStatistics(request)
    if request.method == 'POST':
        form = SmilesForm(request.POST, request.FILES)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = generate_JobID()
            model_instance.CurrentStep = "1"
            model_instance.Successful = True
            model_instance.save()
            return redirect('/toolkit/reviewcoors/%d' % int(model_instance.JobID))
    else:
        form = SmilesForm()

    return render(request, 'toolkit/smiles.html', {'form': form})
Ejemplo n.º 15
0
def index(request):
    clientStatistics(request)
    all_compounds = Compound.objects.all()
    all_pkas = PKA.objects.all()
    all_stabilities = StabilityConstants.objects.all()
    all_dgsov = dGsolv.objects.all()
    return render(
        request,
        'expdata/index.html',
        {
            'NumBasicInfo': len(all_compounds),
            'Numpka': len(all_pkas),
            'Numstabilities': len(all_stabilities),
            'Numdgsolv': len(all_dgsov),
        },
    )
Ejemplo n.º 16
0
def parameters_input(request, JobID):
    clientStatistics(request)
    item = get_object_or_404(GSolvJob, JobID=JobID)
    if request.method == 'POST':
        form = GsolvInputForm(request.POST, instance=item)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "2.1"
            model_instance.Successful = True
            model_instance.save()
            return redirect('/gsolv/review/%d' % int(model_instance.JobID))

    else:
        form = GsolvInputForm()
    return render(request, 'gsolv/parameters_input.html', {'form': form, 'JobID': JobID})
Ejemplo n.º 17
0
def inputcoor(request, JobID, JobType='toolkit'):
    """
    convert input files to xyz and show
    """
    clientStatistics(request)
    item = get_object_or_404(ToolkitJob, JobID=JobID)
    # convert smi to xyz
    jobmanger = JobManagement()
    jobmanger.Convert2XYZ(item, JobType=JobType)

    # read xyz file
    job_dir = get_job_dir(JobID)
    xyzfile = '%s/%s-%s.xyz' % (job_dir, JobType, JobID)
    fcon = ''.join(open(xyzfile).readlines())

    return HttpResponse(fcon, content_type='text/plain')
Ejemplo n.º 18
0
def parameters_replica(request, JobID):
    clientStatistics(request)
    item = get_object_or_404(CSearchJob, JobID=JobID)
    if request.method == 'POST':
        form = ReplicaSearchForm(request.POST, instance=item)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "2.2"
            model_instance.Successful = True
            model_instance.save()
            return redirect('/csearch/review/%d' % int(model_instance.JobID))

    else:
        form = ReplicaSearchForm()
    return render(request, 'csearch/parameters_replica.html', {'form': form, 'JobID': JobID})
Ejemplo n.º 19
0
def start(request, type='new'):
    clientStatistics(request)
    # delete empty jobs that longer then 2 hours
    for j in GSolvJob.objects.filter(CurrentStep=0):
        deltaT = int(datetime.datetime.now().strftime('%s')) - int(j.CreatedDate.strftime('%s'))
        if deltaT > 3600 * 2:
            j.delete()

    JobID = generate_JobID()
    # occupy this JobID for 2 hours
    SPJob = pKaJob(JobID=JobID)
    SPJob.save()

    if type in ['new']:
        return redirect('/gsolv/smiles/%d/' % JobID)
    elif type in ['output']:
        return redirect('/gsolv/calculate/%d/' % JobID)
Ejemplo n.º 20
0
def phases(request):
    clientStatistics(request)
    all_phases = Phases.objects.filter(~Q(DBSource__DBID__contains='test'))
    # get refs
    all_refs = []
    for p in all_phases:
        all_refs.append(p.Ref)
    # get DBs
    all_DBs = []
    for p in all_phases:
        all_DBs.append(p.DBSource)

    return render(
        request, 'phreeqcdb/phases.html', {
            'all_phases': all_phases,
            'refs': list(set(all_refs)),
            'dbs': list(set(all_DBs))
        })
Ejemplo n.º 21
0
def onecpd(request, args, value):
    clientStatistics(request)
    # get the compound
    if args in ['id', 'pk']:
        try:
            cpds = Compound.objects.filter(id=value)
        except:
            return HttpResponse('Compound does not exist.')
    elif args in [
            'pubchem', 'pub', 'pubid', 'pubchemid', 'PubChemID', 'PubChem'
    ]:
        try:
            cpds = Compound.objects.filter(PubChemID=value)
        except:
            return HttpResponse('Compound does not exist.')

    all_pkas = PKA.objects.filter(MolID=cpds)
    all_stabilities = StabilityConstants.objects.filter(MolID=cpds)
    all_dgsov = dGsolv.objects.filter(MolID=cpds)

    # get refs
    all_refs = []
    for p in all_dgsov:
        all_refs.append(p.dGsolvReference)
    for p in all_pkas:
        all_refs.append(p.pKaReference)
        all_refs.append(p.ThermalReference)
    for p in all_stabilities:
        all_refs.append(p.ThermalReference)

    all_refs = set(all_refs)

    return render(
        request,
        'expdata/onecpd.html',
        {
            'cpds': cpds,
            'pkas': all_pkas,
            'stabilities': all_stabilities,
            'dgsolvs': all_dgsov,
            'refs': all_refs,
            'MolID': value,
        },
    )
Ejemplo n.º 22
0
def dgsolv(request):
    clientStatistics(request)
    all_dgsov = dGsolv.objects.all()
    #all_refs = Refs.objects.all()
    # get refs
    all_refs = []
    for p in all_dgsov:
        all_refs.append(p.dGsolvReference)

    all_refs = set(all_refs)

    return render(
        request,
        'expdata/dgsolv.html',
        {
            'dgsolvs': all_dgsov,
            'refs': all_refs,
        },
    )
Ejemplo n.º 23
0
def pka(request):
    clientStatistics(request)
    all_pkas = PKA.objects.all()

    # get refs
    all_refs = []
    for p in all_pkas:
        all_refs.append(p.pKaReference)
        all_refs.append(p.ThermalReference)

    all_refs = set(all_refs)
    return render(
        request,
        'expdata/pka.html',
        {
            'pkas': all_pkas,
            'refs': all_refs,
        },
    )
Ejemplo n.º 24
0
def stability(request):
    clientStatistics(request)
    all_stabilities = StabilityConstants.objects.all()
    #all_refs = Refs.objects.all()
    # get refs
    all_refs = []
    for p in all_stabilities:
        all_refs.append(p.ThermalReference)

    all_refs = set(all_refs)

    return render(
        request,
        'expdata/stability.html',
        {
            'stabilities': all_stabilities,
            'refs': all_refs,
        },
    )
Ejemplo n.º 25
0
def surfacemaster(request):
    clientStatistics(request)
    all_master = SurfaceMasterSpecies.objects.filter(~Q(
        DBSource__DBID__contains='test'))
    # get refs
    all_refs = []
    for p in all_master:
        all_refs.append(p.Ref)
    # get DBs
    all_DBs = []
    for p in all_master:
        all_DBs.append(p.DBSource)

    return render(
        request, 'phreeqcdb/surfacemaster.html', {
            'all_master': all_master,
            'refs': list(set(all_refs)),
            'dbs': list(set(all_DBs))
        })
Ejemplo n.º 26
0
def master(request):
    clientStatistics(request)
    all_master = SolutionMasterSpecies.objects.filter(~Q(
        DBSource__DBID__contains='test'))
    all_master = sorted(all_master, key=lambda x: x.Element)
    # get refs
    all_refs = []
    for p in all_master:
        all_refs.append(p.Ref)
    # get DBs
    all_DBs = []
    for p in all_master:
        all_DBs.append(p.DBSource)

    return render(
        request, 'phreeqcdb/master.html', {
            'all_master': all_master,
            'refs': list(set(all_refs)),
            'dbs': list(set(all_DBs))
        })
Ejemplo n.º 27
0
def parameters_cstype(request, JobID):
    clientStatistics(request)
    item = get_object_or_404(CSearchJob, JobID=JobID)
    if request.method == 'POST':
        form = SearchTypeForm(request.POST, instance=item)
        if form.is_valid():
            model_instance = form.save(commit=False)
            model_instance.JobID = JobID
            model_instance.CurrentStep = "2.0"
            model_instance.Successful = True
            model_instance.save()
            if model_instance.CSearchType == 'Random':
                return redirect('/csearch/parameters_random/%d' % int(model_instance.JobID))
            elif model_instance.CSearchType == 'Replica':
                return redirect('/csearch/parameters_replica/%d' % int(model_instance.JobID))
            elif model_instance.CSearchType == 'DFT':
                return redirect('/csearch/parameters_dft/%d' % int(model_instance.JobID))
    else:
        form = SearchTypeForm()
    return render(request, 'csearch/parameters.html', {'form': form, 'JobID': JobID})
Ejemplo n.º 28
0
def parameters(request):
    clientStatistics(request)
    # delete empty jobs that longer then 2 hours
    for j in HgSpeciJob.objects.filter(CurrentStep=0):
        deltaT = int(datetime.datetime.now().strftime('%s')) - int(j.CreatedDate.strftime('%s'))
        if deltaT > 3600 * 2:
            j.delete()
    '''
    # generate JobID
    try:
        lastjobid = HgSpeciJob.objects.last().id
    except AttributeError:
        lastjobid = 0
    JobID = lastjobid + 1
    '''
    JobID = generate_JobID()
    # occupy this JobID for 2 hours
    SPJob = HgSpeciJob(JobID=JobID)
    SPJob.save()

    return redirect('/hgspeci/parameters/%d/' % JobID)
Ejemplo n.º 29
0
def reclustering(request, JobID):
    '''
    TODO: This function did not start the job, need to be fixed.

    '''
    # if the job hasn't been started, start the job.
    # if the job is running, check every 5 seconds.
    # if the job has finished, display the results.
    item = get_object_or_404(CSearchJob, JobID=JobID)

    JobType = 'csearch'
    # check the job status
    jobmanger = JobManagement()
    jobmanger.CheckJob(obj=item, JobType=JobType)


    if item.CurrentStatus == '0':
        clientStatistics(request)
        # the job is 'to be start', submit the job and jump to '1'

        # generate command line file
        if item.RandomReclustering:
            jobmanger.CSearchJobReclustering(obj=item)
        # submit the job
        PBSoutput = jobmanger.JobExec_v1(obj=item, JobType=JobType)

        # change the status in the database
        item.CurrentStatus = '1'
        item.PBSID = PBSoutput
        item.save()
        # redirect to the result page
        return redirect('/csearch/reclustering/%d' % int(item.JobID))

    if item.CurrentStatus == '1':
        # the job is 'running', keep checking the status
        return render(request, 'csearch/results_jobrunning.html', {'JobID': JobID, 'Item': item})
    if item.CurrentStatus == '2':
        clientStatistics(request)
        # the job is finished.
        if request.method == 'POST':
            form = ReclusteringForm(request.POST, instance=item)
            if form.is_valid():
                model_instance = form.save(commit=False)
                model_instance.JobID = JobID
                model_instance.CurrentStep = "2.1.1"
                model_instance.Successful = True
                model_instance.RandomReclustering = True
                # change the status to "to be start" to run the jobs
                model_instance.CurrentStatus = '0'
                model_instance.save()
                return redirect('/csearch/results/%d' % int(model_instance.JobID))

        else:
            form = ReclusteringForm()
        return render(request, 'csearch/reclustering_para.html', {'form': form, 'JobID': JobID})
    if item.CurrentStatus == '3':
        clientStatistics(request)
        # there is some error in the job, display the error message.
        return render(request, 'csearch/results_error.html', {'JobID': JobID, 'Item': item})
Ejemplo n.º 30
0
def results(request, JobID, JobType='gsolv'):
    # if the job hasn't been started, start the job.
    # if the job is running, check every 5 seconds.
    # if the job has finished, display the results.
    item = get_object_or_404(GSolvJob, JobID=JobID)

    if item.CurrentStatus == '0':
        clientStatistics(request)
        # the job is 'to be start', submit the job and jump to '1'

        # change the status in the database
        item.CurrentStatus = '1'
        item.save()

        # a function to start the job
        #### call some function here ####
        # a. generate input file
        # b. submit the job
        # generate input file

        jobmanger = JobManagement()
        if JobType in ['gsolv']:
            jobmanger.GsolvJobPrepare(obj=item, JobType=JobType)
        elif JobType in ['gsolv_output']:
            jobmanger.GsolvCollectResults(obj=item, JobType=JobType)

        # run the calculations in background
        #Exec_thread = threading.Thread(target=jobmanger.GSolvJobExec, kwargs={"obj": item})
        #Exec_thread.start()

        # redirect to the result page
        return redirect('/gsolv/results/%d/%s/' % (int(item.JobID), JobType))

    if item.CurrentStatus == '1':
        # the job is 'running', keep checking the status
        return render(request, 'gsolv/results_jobrunning.html', {'JobID': JobID, 'Item': item})
    if item.CurrentStatus == '2':
        clientStatistics(request)
        # the job is finished, display the results.
        job_dir = get_job_dir(JobID)
        output_cluster_png = '%s/%s-%s/%s-%s.cluster.png' % (job_dir, JobType, JobID, JobType, JobID)

        # read the figure file
        try:
            fig_in_base64 = "data:image/png;base64,%s" % base64.encodestring(open(output_cluster_png).read())
        except:
            fig_in_base64 = base64.encodestring('Figure is not available.')
            pass

        if JobType in ['gsolv']:
            return render(request, 'gsolv/results.html', {'JobID': JobID, 'Item': item, 'chart': fig_in_base64})
        elif JobType in ['gsolv_output']:
            return render(request, 'gsolv/results_output.html', {'JobID': JobID, 'Item': item, 'chart': fig_in_base64})

    if item.CurrentStatus == '3':
        clientStatistics(request)
        # there is some error in the job, display the error message.
        return render(request, 'gsolv/results_error.html', {'JobID': JobID, 'Item': item})