def __init__(self, hud, urls, linkedin_user='******'): self.bh = hud self.urls = urls self.current_url = self.urls[0] from os import environ as os_environ from os import path as os_path from sys import path as py_path py_path.append(os_path.join(os_environ['GIT_REPOS'], 'emt/src')) from emt import EMT self.x = EMT() self.x.pg.check_db_config() self.x.web.initiate_web_session(linkedin_user) self.pg = self.x.pg self.T = self.pg.T
def main(): asedb = connect('/scratch/users/ksb/db/ase.db') initialQuestion = ( '\n%d relaxed bulk structure(s) passed filters+constraints.' % (nBulk) + '\nDo you want to create %d slabs?\n(y/n)--> ' % (ncombo)) if raw_input(initialQuestion).lower() in ['y', 'yes']: for combo in domainProduct: print combo ind, fac, xy, l, c, sym, vac, vacancy = combo facList = [int(z) for z in str(fac)] bare = makeSlab(ind, facList, l, sym, xy, vac) img = plot(bare) aseAtoms = AseAtomsAdaptor.get_atoms(bare) taggedAtoms = tag_atoms(aseAtoms) taggedAtoms.set_constraint( FixAtoms(indices=constrainAtoms(taggedAtoms, c, sym))) magmoms = [ magmomInit if (magmomInit and e in magElems) else 0 for e in taggedAtoms.get_chemical_symbols() ] taggedAtoms.set_initial_magnetic_moments(magmoms) taggedAtoms.set_calculator(EMT()) taggedAtoms.wrap() for i in vacancy: del taggedAtoms[i] prettyfacet = '-'.join([x for x in str(fac)]) prettyxy = '%sx%s' % (str(xy)[0], str(xy)[1]) name = '%s_%s_%s' % (asedb.get(ind).get('name'), prettyfacet, prettyxy) info = { 'name': name, 'relaxed': False, 'emt': taggedAtoms.get_potential_energy() / len(taggedAtoms) # normalize to per-atom basis , 'comments': 'Autogenerated by initializeBareSurf', 'kind': 'surface' # vs bulk/molecule , 'structure': asedb.get(ind).get('structure'), 'parent': ind #ase object surface was generated from , 'sites': img, 'facet': fac, 'xy': xy, 'layers': l, 'constrained': c, 'symmetric': sym, 'vacuum': vac, 'vacancies': str(vacancy) } parentJob = db2object(query1('jobtableid', 'aseid', ind, 'result')) if USER_APPROVAL: view(taggedAtoms) question = ( 'Does this structure look right?\nfacet= %s\nlayers = %d\nfixed = %d\n' % (prettyfacet, l, c) + 'vacuum = %d\nxy = %s\n %s\n\n(y/n) --> ' % (vac, prettyxy, parentJob.summary())) if not USER_APPROVAL or raw_input(question).lower() in [ 'y', 'yes' ]: n = sum([ 1 for x in asedb.select(parent=ind, facet=fac, xy=xy, layers=l, constrained=c, symmetric=sym, vacuum=vac, vacancies=str(vacancy)) ]) if n > 1: raise ValueError, 'Two things already in database have same parameters???' elif n == 1: print "matching structure already in database!" else: asedb.write(taggedAtoms, key_value_pairs=info)
def main(): asedb = connect('/scratch/users/ksb/db/ase.db') initialQuestion = ('\n%d relaxed surface structure(s) passed constraints.'%(len(surfaceDomain)) +'\nDo you want to create %d slabs?\n(y/n)--> '%(ncombo)) if raw_input(initialQuestion).lower() in ['y','yes']: for combo in domainProduct: ind,ads = combo parent = asedb.get(ind).get('parent') sites = asedb.get(ind).get('sites') structure = asedb.get(ind).get('structure') grandparent = asedb.get(ind).get('parent') facet = asedb.get(ind).get('facet') xy = asedb.get(ind).get('xy') layers = asedb.get(ind).get('layers') constrained = asedb.get(ind).get('constrained') symmetric = asedb.get(ind).get('symmetric') vacuum = asedb.get(ind).get('vacuum') vacancies = literal_eval(asedb.get(ind).get('vacancies')) facList = [int(z) for z in str(facet)] bare = makeSlab(grandparent,facList,layers,symmetric,xy,vacuum) adsSurf = adsorbedSurface(bare,ads) aseAtoms = AseAtomsAdaptor.get_atoms(adsSurf) taggedAtoms = tag_atoms(aseAtoms) taggedAtoms.set_constraint(FixAtoms(indices=constrainAtoms(taggedAtoms,constrained,symmetric))) magmoms = [magmomInit if (magmomInit and e in magElems) else 0 for e in taggedAtoms.get_chemical_symbols()] taggedAtoms.set_initial_magnetic_moments(magmoms) taggedAtoms.set_calculator(EMT()) taggedAtoms.wrap() for i in vacancies: del taggedAtoms[i] # hopefu prettyfacet = '-'.join([x for x in str(facet)]) prettyxy = '%sx%s'%(str(xy)[0],str(xy)[1]) prettyAds = printAds(ads) name = '%s_%s_%s'%(asedb.get(parent).get('name'),prettyfacet,prettyxy) info = {'name': name ,'relaxed': False ,'emt': taggedAtoms.get_potential_energy()/len(taggedAtoms) # normalize to per-atom basis ,'comments': 'Autogenerated by initializeAdsSurf' ,'kind': 'surface' # vs bulk/molecule ,'structure': structure ,'parent': parent #ase object surface was generated from ,'sites': sites ,'facet': facet ,'xy': xy ,'layers': layers ,'constrained': constrained ,'symmetric': symmetric ,'vacuum': vacuum ,'vacancies': vacancies ,'adsorbates': prettyAds} if USER_APPROVAL: view(taggedAtoms) question = ('Does this structure look right?\nfacet= %s\nlayers = %d\nfixed = %d\n'%(prettyfacet,layers,constrained) +'vacuum = %d\nxy = %s\nads = %s\n\n(y/n) --> '%(vacuum,prettyxy,prettyAds)) if not USER_APPROVAL or raw_input(question).lower() in ['y','yes']: n = sum([1 for x in asedb.select(parent=ind,facet=fac,xy=xy,layers=l ,constrained=constrained,symmetric=symmetric,vacuum=vacuum,vacancies=str(vacancies),adsorbates= prettyAds)]) if n > 1: raise ValueError, 'Two things already in database have same parameters???' elif n == 1: print "matching structure already in database!" else: asedb.write(taggedAtoms,key_value_pairs=info)
def main(): for x in fccs + bccs + hcps + diamonds + rocksalts + zincblendes + cscls: f = x in fccs b = x in bccs h = x in hcps d = x in diamonds r = x in rocksalts z = x in zincblendes c = x in cscls try: if f: a = FaceCenteredCubic(x[0]).get_cell()[0][0] / 2 elif b: a = BodyCenteredCubic(x[0]).get_cell()[0][0] / 2 elif d: a = Diamond(x[0]).get_cell()[0][0] / 2 elif h: cell = HexagonalClosedPacked(x[0]).get_cell() a, c = cell[0][0], cell[2][2] elif r | z | c: a = dataLookup(x[0]) else: raise NotImplementedError except ValueError: a = dataLookup(x[0]) / 2 #a = sum([radDict[e] for e in elems])/len(elems) print "Had to guess lattice constant of " + x[0] if f: name, struc, pos, cell, n = '-fcc', 'fcc', [[0, 0, 0]], [[0, a, a], [a, 0, a], [a, a, 0]], 1 elif b: name, struc, pos, cell, n = '-bcc', 'bcc', [[0, 0, 0]], [[a, a, -a], [-a, a, a], [a, -a, a]], 1 elif h: name, struc, pos, cell, n = '-hcp', 'hexagonal', [[ 0, 0, 0 ], [2. / 3, 1. / 3, 1. / 2]], [a, a, c, 90, 90, 120], 2 elif d: name, struc, pos, cell, n = '-diamond', 'diamond', [[ 0, 0, 0 ], [0.25, 0.25, 0.25]], [[0, a, a], [a, 0, a], [a, a, 0]], 2 elif z: name, struc, pos, cell, n = '-zincblende', 'zincblende', [[ 0, 0, 0 ], [0.25, 0.25, 0.25]], [[0, a, a], [a, 0, a], [a, a, 0]], 1 elif r: name, struc, pos, cell, n = '-rocksalt', 'rocksalt', [[ 0, 0, 0 ], [0.5, 0.5, 0.5]], [[0, a, a], [a, 0, a], [a, a, 0]], 1 elif c: name, struc, pos, cell, n = '-cscl', 'cubic', [[0, 0, 0], [0.5, 0.5, 0.5]], [ a, a, a, 90, 90, 90 ], 1 mag = magLookup(x[0]) elems = parseChemicalFormula(x[0]).keys() * n magmoms = [magmomInit if e in magElems else 0 for e in elems] atoms = Atoms(elems, scaled_positions=pos, cell=cell, pbc=[1, 1, 1], magmoms=magmoms, calculator=EMT()) info = { 'name': x[0] + name, 'relaxed': False, 'emt': atoms.get_potential_energy() / len(elems) #normalized to per-atom basis , 'comments': 'Autogenerated by createTrajs', 'kind': 'bulk' # vs surface/molecules , 'structure': struc } db.write(atoms, key_value_pairs=info)
def __init__(self, id, pth, name=None, stoich=None, bravais=None, inita=None, initb=None, initc=None, initalpha=None, initbeta=None, initgamma=None, initpos=None, mag=None, emt=None, comments=None): if id is None: # Creating object for first time traj = io.read(pth) traj.set_calculator(EMT()) cell = traj.get_cell() atomList = traj.get_chemical_symbols() self.atomList = atomList self.initPos = traj.get_scaled_positions() self.pth = pth self.name = (pth.split('.traj')[0]).split('traj/')[1] self.traj = traj try: self.bravais = traj.info['bravais'] except KeyError: self.bravais = 'triclinic' # default is most general (and expensive) case try: self.mag = traj.info['mag'] except KeyError: self.mag = False # Default nonmag try: self.comments = traj.info['comments'] except KeyError: self.comments = None self.initEMT = traj.get_potential_energy() a, b, c, alpha, beta, gamma = cell2param(cell) self.inita = a self.initb = b self.initc = c self.initalpha = alpha self.initbeta = beta self.initgamma = gamma else: self.id = id self.pth = pth self.name = name self.stoich = stoich self.bravais = bravais self.inita = inita self.initb = initb self.initc = initc self.initalpha = initalpha self.initbeta = initbeta self.initgamma = initgamma self.initpos = initpos self.mag = mag self.emt = emt self.comments = comments traj = io.read(pth) atomList = traj.get_chemical_symbols() self.atomList = atomList
def main(): asedb = connect('/scratch/users/ksb/db/ase.db') initialQuestion = ( '\n%d relaxed bulk structure(s) passed filters+constraints.' % (nBulk) + '\nDo you want to create %d slabs?\n(y/n)--> ' % (ncombo)) if raw_input(initialQuestion).lower() in ['y', 'yes']: for combo in domainProduct: ind, fac, xy, l, c, sym, vac, vacancy = combo a = asedb.get_atoms(id=ind) pmg_a = AseAtomsAdaptor.get_structure(a) unit = SpacegroupAnalyzer( pmg_a, symprec=0.1, angle_tolerance=5).get_conventional_standard_structure() gen = SlabGenerator(unit, fac, findHeight(unit, fac, l, sym), vac, center_slab=sym, primitive=True, lll_reduce=True) slabs = gen.get_slabs() if len(slabs) > 1: print "Warning, multiple slabs generated..." slab = slabs[0] slab.make_supercell(list(xy) + [1]) bare = reorient_z(slab) img = plot(bare) aseAtoms = AseAtomsAdaptor.get_atoms(bare) taggedAtoms = tag_atoms(aseAtoms) taggedAtoms.set_constraint( FixAtoms(indices=constrainAtoms(taggedAtoms, c, sym))) magmoms = [ magmomInit if (magmomInit and e in magElems) else 0 for e in taggedAtoms.get_chemical_symbols() ] taggedAtoms.set_initial_magnetic_moments(magmoms) taggedAtoms.set_calculator(EMT()) taggedAtoms.wrap() for i in vacancy: del taggedAtoms[i] info = { 'name': '%s_%s_%s' % (asedb.get(ind).get('name'), '-'.join( [str(x) for x in fac]), 'x'.join([str(x) for x in xy])), 'kind': 'surface', 'structure': asedb.get(ind).get('structure'), 'sites': img, 'bare': True, 'parent': ind #ase object surface was generated from , 'facet': str(fac), 'xy': str(xy), 'layers': l, 'constrained': c, 'symmetric': sym, 'vacuum': vac, 'vacancies': str(vacancy), 'surfcomments': 'Autogenerated by initializeBareSurf', 'emt': taggedAtoms.get_potential_energy(), 'relaxed': False } if USER_APPROVAL: view(taggedAtoms) question = ( 'Does this structure look right?\nfacet= %s\nlayers = %d\nfixed = %d\n' % ('-'.join([str(x) for x in fac]), l, c) + 'vacuum = %d\nxy = %s\n(y/n) --> ' % (vac, 'x'.join([str(x) for x in xy]))) if raw_input(question).lower() in ['y', 'yes']: asedb.write(taggedAtoms, key_value_pairs=info) else: asedb.write(taggedAtoms, key_value_pairs=info)
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)
eDict={} for i in range(9): eDict[i]=[] for i,c in enumerate(list(configs)): print i a = Atoms(c,positions=positions,cell=cell,pbc=1,calculator=EMT()) e = a.get_potential_energy() nPd = c.count('Pd') eDict[nPd].append(e) """ positions = np.array([[0, 0, 0], [0, 0.5, 0.5], [0.5, 0, 0.5], [0.5, 0.5, 0]]) cell = np.array([[0, 2, 2], [2, 0, 2], [2, 2, 0]]) elements = ['Pd', 'Au'] configs = itertools.product(elements, repeat=4) eDict = {} for i in range(5): eDict[i] = [] for i, c in enumerate(list(configs)): print i a = Atoms(c, positions=positions, cell=cell, pbc=1, calculator=EMT()) e = a.get_potential_energy() nPd = c.count('Pd') eDict[nPd].append(e) print eDict # plt.hist(eDict[3],nbins=256)