Beispiel #1
0
def xyPlot(xPlotFunc,
           yPlotFunc,
           table,
           filterList,
           ax,
           legendLabel=None,
           labelFunc=None,
           title=None,
           commonConstraints=[completed],
           codeList=[
               'ro--', 'gx--', 'b^--', 'ms--', 'y*--', 'ko--', 'co--', 'ro:',
               'gx:', 'b^:', 'ms:', 'y*:', 'ko:', 'co:', 'ro-', 'gx-', 'b^-',
               'ms-', 'y*-', 'ko-', 'co-'
           ]):
    """
	Plots a specified function (Job -> Double) vs another function, possibly over many sets of data (multiple lines) 
	"""
    xys = []
    for i, constraintList in enumerate(filterList):
        xs = [
            xPlotFunc.func(*x)
            for x in plotQuery(table, xPlotFunc.cols, constraintList +
                               commonConstraints)
        ]
        ys = [
            yPlotFunc.func(*y)
            for y in plotQuery(table, yPlotFunc.cols, constraintList +
                               commonConstraints)
        ]
        if labelFunc is not None:
            label = [
                labelFunc.func(*l)
                for l in plotQuery(table, labelFunc.cols, constraintList +
                                   commonConstraints)
            ]
        try:
            xy = sorted(zip(xs, ys))  #order the pairs
            x, y = zip(*xy)
            ax.plot(x,
                    y,
                    codeList[i % len(codeList)],
                    label='' if legendLabel is None else legendLabel[i])
            if labelFunc is not None:
                for i in range(len(x)):
                    ax.annotate(label[i], xy=(x[i], y[i]), fontsize=9)
        except ValueError:
            print "Warning, no data found for constraint #" + str(i + 1)
        xys.append(xy)
    if title is not None: ax.set_title(title)

    ax.set_xlabel(xPlotFunc.axisLabel)
    ax.set_ylabel(yPlotFunc.axisLabel)

    if legendLabel is not None:
        legend = ax.legend(loc='best', shadow=True)
        legend.get_frame().set_facecolor('#00FFCC')
        legend.draggable()
    return xys
Beispiel #2
0
def getStoichVec(jobid):
    stoich = literal_eval(plotQuery(['symbols'], [JOBID(jobid)])[0][0])
    stoichNum = [toAtomicNum[x] for x in stoich]
    output = [0] * nELEM
    for n in stoichNum:
        output[n - 1] += 1
    return np.array(output)
Beispiel #3
0
def applyDetails(tentative=False, overwrite=False):
    """To-do: Time doing overwrite vs checking and overwriting if new """
    global jobtable  #make global so that functions like fromJobObject() can access correct one
    jobtable = 'tentativejob' if tentative else 'job'
    querytable = tentativetable if tentative else defaulttable

    newjobs = [
        i[0] for i in plotQuery(['jobid'], [], jobtable)
        if i[0] > countDB('details')
    ]
    for i in newjobs:
        sqlexecute('INSERT INTO details (jobtableid) VALUES (%d)' % i)

    for i, d in enumerate(activeDetails):
        print d.name, " %d/%d" % (i + 1, len(activeDetails))

        try:
            addCol(d.name, d.kind, 'details')
        except OperationalError:
            pass

        vals = d.apply(querytable)
        ids = allJobIDs()
        for ID, val in zip(ids, vals):
            if overwrite or (val is not None and query1(
                    d.name, 'jobtableid', ID, 'details') is None):
                updateDB(d.name, 'jobtableid', ID, val, None, 'details')
Beispiel #4
0
def increaseConvergence():
    kohnsham = [x[0] for x in plotQuery(['jobid'], [KOHNSHAM])]
    new = 0
    for k in kohnsham:
        jobj = db2object(k)
        jobj.convid += 1
        jobj.status = 'initialized'
        jobj.error, jobj.comments = None, None
        id, status = insertObject(jobj)
        if status == 'inserted': new += 1
    print 'added %d new jobs' % new
Beispiel #5
0
def getJobCalcConstraints(jobid):
    """Constraints that isolate all jobs done with same calculator/convergence parameters"""
    xc, pw, kptden, psp, xtol, strain, convid, precalc, dftcode = plotQuery([
        'xc', 'pw', 'kptden', 'psp', 'xtol', 'strain', 'convid', 'precalc',
        'dftcode'
    ], [JOBID(jobid)])[0]
    return [
        XC(xc),
        PW(pw),
        KPTDEN(kptden),
        PSP(psp),
        XTOL(xtol),
        STRAIN(strain),
        CONVID(convid),
        PRECALC(precalc),
        DFTCODE(dftcode)
    ]
Beispiel #6
0
def barResults(summaryFunc,
               filterList,
               labelList,
               ax,
               commonConstraints=[COMPLETED]):
    #Plots summaries of data as a bar graph
    y_pos = np.arange(len(filterList))  # bar locations
    y = [
        summaryFunc.kind(
            plotQuery([d.name for d in summaryFunc.details],
                      constraintList + commonConstraints))
        for constraintList in filterList
    ]

    ax.bar(y_pos, y, align='center', alpha=0.5)
    ax.set_ylabel(summaryFunc.name)
    ax.set_xticks(y_pos)
    ax.set_xticklabels(labelList)
def main():

    try:
        deleteTable('tentative')  #WHAT IS GOING ON HERE?
    except:
        pass
    try:
        createTentativeBulkTable()
    except:
        pass

    domains = [
        filteredTrajDomain, filteredXCDomain, filteredPSPDomain,
        filteredPWDomain, filteredKPTDomain, filteredPreCalcXCDomain,
        filteredDFTDomain
    ]
    combos = product(*domains)
    ncombo = reduce(mul, [len(x) for x in domains])
    for i, c in enumerate(combos):
        print '%f%' % (i / float(ncombo) * 100)
        tentativeInput = c[:5] + tuple(defaults) + c[5:]
        tentativeBulkjob = BulkJob(*tentativeInput)

        if tentativeBulkjob.xc == 'mBEEF':  #defaults slightly different for mBEEF
            tentativeBulkjob.sigma += 0.1
            tentativeBulkjob.sigma -= 0.05

        ID, status = insertObject(tentativeBulkjob, tentative=True)
    print "%d tentative jobs" % countDB('tentative')

    valid = [
        db2BulkJob(x[0], tentative=True)
        for x in plotQuery('tentative', ['tentative.id'], constraints)
    ]
    new = 0

    for z in range(len(valid)):
        ID, status = insertObject(valid[z])
        if status == 'inserted': new += 1
    print "%d valid jobs, %d are new" % (len(valid), new)
    deleteTable('tentative')
def main():
	dropTable('tentativejob')
	dropTable('tentativedetails')
	sqlexecute(jobTable('tentativejob'))
	sqlexecute('INSERT INTO tentativejob SELECT * FROM job')
	sqlexecute(tentativedetailstable)

	for i,sID in enumerate(surfs):
		p 		= asedb.get(sID).get('parent')

		cols 	= ['xc','pw','kptden','psp','convid','precalc','dftcode']
		allInfo = queryManyFromOne(cols,'aseid',p)
		
		xc,pw,kptden,psp,convid,precalc,dftcode = allInfo

		tentativeInput	 = [None,'surfrelax',sID,None,None,xc,pw,kptden,psp,None,None,convid,precalc,dftcode,None,None,'initialized']
		tentativeSurfjob = Job(*tentativeInput)
		
		insertObject(tentativeSurfjob,tentative=True)
		
	applyDetails(tentative=True) #populate details table so that plotQuery works

	valid 	= [db2object(x[0],'tentativejob','job') for x in plotQuery(['jobid'],constraints,tentativetable)] 
	new 	= 0

	
	print "%d valid jobs, %d are new"%(len(valid),new)

	question = "Do you want to insert %d new surface jobs?"%new

	if raw_input(question) in ['y','yes']:

		for z in range(len(valid)): 
			ID,status = insertObject(valid[z])
			if status == 'inserted': new +=1

		print "%d jobs are new"%new
		applyDetails()
		dropTable('tentativejob')
		dropTable('tentativedetails')
Beispiel #9
0
def main():
	
	try: dropTable('tentativejob') # uncomment if script fails in the middle
	except: pass

	sqlexecute(jobTable('tentativejob'))
	copyTable('job','tentativejob')
	
	combos 	= product(*domains)
	nTot 	= reduce(mul,[len(x) for x in [trajDomain,xcDomain,pspDomain,pwDomain,kptDomain,preXcDomain,dftDomain]])
	ncombo 	= reduce(mul,[len(x) for x in domains])
	for i,c in enumerate(combos):	
		print '%f %%'%(i/float(ncombo)*100)
							# jobid jobkind 	aseid vib neb   xc   pw kpt  psp   xtol  strain   convergence ID        precalc dft comm err stat
		tentativeInput 		= [None,'bulkrelax',c[0],None,None,c[1],c[2],c[3],c[4],0.005,0.03, 2 if c[1]=='mBEEF' else 1,c[5],c[6],None,None,'initialized']
		tentativejob 	= Job(*tentativeInput)
		insertObject(tentativejob,tentative=True)

	nJobsInit,nJobsTent = countDB('job'),countDB('tentativejob')

	print "%d tentative jobs after filtering %d jobs"%(ncombo,nTot)

	applyDetails(tentative=True) #populate details table so that plotQuery works

	valid 	= [db2object(x[0],'tentativejob') for x in plotQuery(['jobid'],CONSTRAINTS,tentativetable)] 
	new 	= 0

	question = "Do you want to insert %d valid bulk jobs?\n(y/n)--> "%len(valid)

	if raw_input(question) in ['y','yes']:

		for z in range(len(valid)): 
			ID,status = insertObject(valid[z])
			if status == 'inserted': new +=1
		
		print "%d jobs are new"%new
	
		applyDetails()
		
		dropTable('tentativejob')
Beispiel #10
0
def barResults(summaryFunc,
               table,
               filterList,
               labelList,
               ax,
               commonConstraints=[completed]):
    """
	Plots summaries of data as a bar graph
	"""
    y_pos = np.arange(len(filterList))  # bar locations

    y = [
        summaryFunc.kind([
            summaryFunc.func.func(*x)
            for x in plotQuery(table, summaryFunc.func.cols, constraintList +
                               commonConstraints)
        ]) for constraintList in filterList
    ]  #this could've been clearer ....

    ax.bar(y_pos, y, align='center', alpha=0.5)
    ax.set_ylabel(summaryFunc.name)
    ax.set_xticks(y_pos)
    ax.set_xticklabels(labelList)
Beispiel #11
0
def main():

    deleteTable('tentativesurf')

    for i, sID in enumerate(surfs):

        p = asedb.get(sID).get('parent')

        table = ' bulkjob INNER JOIN bulkresult ON bulkresult.jobid=bulkjob.id '
        cols = [
            'xc', 'psp', 'pw', 'kptden', 'kpt', 'econv', 'mixing', 'nmix',
            'maxstep', 'nbands', 'sigma', 'fmax', 'precalcxc', 'dftcode'
        ]
        allInfo = queryManyFromOne(table, cols, 'aseid', p)
        xc, psp, pw, kptden, kpt, econv, mixing, nmix, maxstep, nbands, sigma, fmax, precalcxc, dftcode = allInfo

        tentativeInput = [
            sID, xc, psp, pw, 10, kptden, None, econv, mixing, nmix, maxstep,
            nbands, sigma, fmax, precalcxc, dftcode
        ]
        tentativeSurfjob = SurfaceJob(*tentativeInput)

        ID, status = insertObject(tentativeSurfjob, tentative=True)

    valid = [
        db2SurfaceJob(x[0], tentative=True)
        for x in plotQuery('tentativesurf', ['tentativesurf.id'], constraints)
    ]  # SurfaceJob objects that satisfy constraints
    tot, new = len(valid), 0
    question = '%d job(s) meet these criteria. Do you want to add them to surfacejobs in data.db?\n(y/n)--->' % tot
    if raw_input(question).lower() in ['y', 'yes']:
        for z in range(len(valid)):
            ID, status = insertObject(valid[z])
            if status == 'inserted': new += 1

    deleteTable('tentativesurf')
    print '%d jobs considered, %d are new' % (tot, new)
Beispiel #12
0
def main():
    jIDs = [x[0] for x in plotQuery(['jobid'], CONSTRAINTS)]

    question = "Going to add an %s interstitial to %d bulk objects.\n(y/n)--> " % (
        inter, len(jIDs))

    if raw_input(question).lower() in ['y', 'yes']:
        for j in jIDs:
            aseinitID = query1('aseid', 'jobid', j)
            aseinit = asedb.get_atoms(id=aseinitID)

            # Access information about previous Job / Atoms object
            jobinit = db2object(j)
            xc, pw, kptden = jobinit.xc, jobinit.pw, jobinit.kptden
            psp, xtol, strain = jobinit.psp, jobinit.xtol, jobinit.strain
            precalc, dftcode = jobinit.precalc, jobinit.dftcode
            nameinit = jobinit.name()
            structure = jobinit.structure()
            vacancies = jobinit.vacancies()

            # Create conventional PyMatGen Object
            pmg_init = AseAtomsAdaptor.get_structure(aseinit)
            pmg_init2 = SpacegroupAnalyzer(
                pmg_init).get_conventional_standard_structure()

            interstitial = Interstitial(
                pmg_init2, None, covalent_radii)  #accuracy=high breaks...
            os.system('cls' if os.name == 'nt' else 'clear')

            for i, site in enumerate(interstitial.enumerate_defectsites()):
                coordination = int(
                    round(interstitial.get_defectsite_coordination_number(i)))
                mult = 0  # interstitial.get_defectsite_multiplicity(i) -- broken ???
                insert = InsertSitesTransformation([inter], [site.coords],
                                                   coords_are_cartesian=True)
                pmg_new = insert.apply_transformation(pmg_init2.copy())
                ase_new = AseAtomsAdaptor.get_atoms(pmg_new)

                ase_new.set_calculator(EMT())
                emt = ase_new.get_potential_energy()

                if coordination == 4: siteName = 'T'
                elif coordination == 6: siteName = 'O'
                else: siteName = '%d-fold' % coordination

                question = ('site: %s\ncoordination: %s\nmultiplicity: %s' %
                            (site.coords, coordination, mult) +
                            '\ninitial ase id: %d \nxc: %s \npw: %d ' %
                            (aseinitID, xc, pw) +
                            '\nkptden: %f \npsp: %s\nxtol: %f\nstrain: %f' %
                            (kptden, psp, xtol, strain) +
                            '\nprecalc: %s \ndftcode: %s' %
                            (precalc, dftcode) +
                            '\n\nDoes this structure look good?\n(y/n)--> ')

                view(ase_new)
                if raw_input(question).lower() in ['y', 'yes']:
                    if checkForDuplicates(ase_new, structure, emt):

                        newquestion = 'What structure does this have?\n(leave blank for general triclinic case)\n--> '
                        structure = raw_input(newquestion)
                        if structure is '': structure = 'triclinic'

                        info = {
                            'name': nameinit + '_%s-%s' % (inter, siteName),
                            'emt':
                            emt  # EMT for relaxed structures useless, only relevant for deciding when to relax something
                            ,
                            'relaxed':
                            False  # Could always doing this be a problem?
                            ,
                            'comments': 'Generated from initializeHydride.py',
                            'parent': aseinitID,
                            'kind': 'bulk',
                            'structure': structure,
                            'interstitial': siteName
                        }
                        if vacancies is not None: info['vacancies'] = vacancies

                        newaseid = asedb.write(ase_new, key_value_pairs=info)

                        newjob = Job(None, 'bulkrelax', newaseid, None, None,
                                     xc, pw, kptden, psp, xtol, strain,
                                     2 if xc == 'mBEEF' else 1, precalc,
                                     dftcode, None, None, 'initialized')

                        insertObject(newjob)
Beispiel #13
0
 def apply(self, table):
     return [self.func(x) for x in plotQuery(self.cols, [], table)]
Beispiel #14
0
def referenceIDs():
    return [
        x[0] for x in plotQuery(['jobid'], REF_CONSTRAINTS)
    ]  #THE REFERENCES MUST ALREADY HAVE RANK 1 RESULTS - need to run twice if a new references is added?
Beispiel #15
0
def submitAll():
    initializedJobs = [x[0] for x in plotQuery(['jobid'], [INITIALIZED])]
    if raw_input('Submit %d jobs?\n(y/n)--> ' %
                 len(initializedJobs)).lower() in ['y', 'yes']:
        for jid in initializedJobs:
            db2object(jid).submit()
USER_APPROVAL = True

#############################
# Constraints on Job that
# Generated Initial Structure
##############################
essentialConstraints = [completed]
otherConstraints = []

initialConstraints = essentialConstraints + otherConstraints
#################
# Surface domains
#################
bulkDomain = [
    x[0] for x in plotQuery('bulkresult', ['aseid'], initialConstraints)
]
facetDomain = [[1, 1, 1], [1, 0, 0]]
xyDomain = [[1, 1], [2, 2]]
layerDomain = [3, 4]
constrainedDomain = [2]
symmetricDomain = [True, False]
vacuumDomain = [10]
vacancyDomain = [[], [
    1
]]  #indices of Atoms objects. Will I ever need to consider multiple vacancies?
adsDomain = [{}, {'H': ['H1']}]

###########
# Filters #
###########
Beispiel #17
0
errA = Detail('errA', 'numeric', 4, ['a', 'a_expt', 'name'], errAFunc,
              r'Error in Lattice A, $\AA$')


###################################################
# DEPENDENT ON REFERENCE (defined in constraint.py)
###################################################
def referenceIDs():
    return [
        x[0] for x in plotQuery(['jobid'], REF_CONSTRAINTS)
    ]  #THE REFERENCES MUST ALREADY HAVE RANK 1 RESULTS - need to run twice if a new references is added?


isRef = Detail(
    'isref', 'integer', 2, ['name'], lambda jobid: int(
        jobid in [x[0] for x in plotQuery(['jobid'], REF_CONSTRAINTS)]))


def getStoichVec(jobid):
    stoich = literal_eval(plotQuery(['symbols'], [JOBID(jobid)])[0][0])
    stoichNum = [toAtomicNum[x] for x in stoich]
    output = [0] * nELEM
    for n in stoichNum:
        output[n - 1] += 1
    return np.array(output)


def getReferenceMatrix(refIDs, keyword):
    mat = np.transpose(np.matrix([getStoichVec(j) for j in refIDs]))
    vec = np.array([query1(keyword, 'jobid', x) for x in refIDs])
    return mat, vec
magmomInit = 3
magElems = ['Fe', 'Mn', 'Cr', 'Co', 'Ni']

#############################
# Constraints on Job that
# Generated Initial Structure
##############################
essentialConstraints = [COMPLETED]  #don't change
constraintsDuJour = [QE]  #al,rpbe,qe]

initialConstraints = essentialConstraints + constraintsDuJour

#################
# Surface domains
#################
bulkDomain = [x[0] for x in plotQuery(['aseid'], initialConstraints)]

###########
# Filters #
###########

filtsDuJour = [
    facetFilter(100),
    xyFilter(22),
    layerFilter(4),
    constrainedFilter(2),
    slabSymFilter(False),
    vacuumFilter(10),
    vacancyFilter([])
]
Beispiel #19
0
def similarJobs(jobid):
    return [
        x[0] for x in plotQuery(['jobid'], getJobCalcConstraints(jobid[0]))
    ]