def test_apply_transformation(self): t = InsertSitesTransformation(["Fe", "Mn"], [[0.0, 0.5, 0], [0.5, 0.2, 0.2]]) s = t.apply_transformation(self.struct) self.assertEqual(s.formula, "Li4 Mn1 Fe1 O4") t = InsertSitesTransformation(["Fe", "Mn"], [[0.001, 0, 0], [0.1, 0.2, 0.2]]) # Test validate proximity self.assertRaises(ValueError, t.apply_transformation, self.struct)
def getInterstitials(ase_in,inter,spinpol): pmg_init = AseAtomsAdaptor.get_structure(ase_in) 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') output = [] 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) try: pmg_new = insert.apply_transformation(pmg_init2.copy()) ase_new = AseAtomsAdaptor.get_atoms(pmg_new) if coordination == 4: siteName='T' elif coordination == 6: siteName='O' else: siteName = '%d-fold'%coordination strname = '_%s-%s'%(inter,siteName) if spinpol: new_magmoms = [3 if e in misc.magElems else 0 for e in ase_new.get_chemical_symbols()] ase_new.set_initial_magnetic_moments(new_magmoms) output.append((ase_new,strname)) except ValueError: pass #ValueError: New site is too close to an existing site! return output
def test_apply_transformation(self): t = InsertSitesTransformation(["Fe", "Mn"], [[0.1, 0, 0], [0.1, 0.2, 0.2]]) s = t.apply_transformation(self.struct) self.assertEqual(s.formula, "Li4 Mn1 Fe1 O4") t = InsertSitesTransformation(["Fe", "Mn"], [[0.001, 0, 0], [0.1, 0.2, 0.2]]) #Test validate proximity self.assertRaises(ValueError, t.apply_transformation, self.struct)
def test_to_from_dict(self): d = InsertSitesTransformation( ["Fe", "Mn"], [[0.5, 0, 0], [0.1, 0.5, 0.2]]).as_dict() t = InsertSitesTransformation.from_dict(d) s = t.apply_transformation(self.struct) self.assertEqual(s.formula, "Li4 Mn1 Fe1 O4")
def test_to_from_dict(self): d = InsertSitesTransformation(["Fe", "Mn"], [[0.1, 0, 0], [0.1, 0.2, 0.2]]).as_dict() t = InsertSitesTransformation.from_dict(d) s = t.apply_transformation(self.struct) self.assertEqual(s.formula, "Li4 Mn1 Fe1 O4")
def adsorb_atom(cls, structure_a, site_a, atom, distance, surface=[0, 0, 1], xyz=0): """ Gets the structure of single atom adsorption. Args: structure_a: the slab structure for adsorption site_a: given sites for adsorption. default(xyz=0): site_a = [a, b, c], within [0,1]; xyz=1: site_a = [x, y, z], in Angstroms. atom: adsorbed atom species distance: between centers of the adsorbed atom and the given site. in Angstroms surface: direction of the surface where atoms are adsorbed to default: surface = [0, 0, 1] xyz: default is 0. 1 means site_a = [x, y, z], in Angstroms. """ from pymatgen.transformations.site_transformations import \ InsertSitesTransformation lattice_s = structure_a.lattice abc_s = lattice_s.abc # a123_s = lattice_s.matrix b123_s = lattice_s.inv_matrix.T # print surface vector_o = np.dot(surface, b123_s) print vector_o lens_v = np.sqrt(np.dot(vector_o, vector_o.T)) V_o = vector_o / lens_v * distance if xyz == 0: # site_a = [a, b, c] for i in xrange(3): if site_a[i]> 1 or site_a[i] < 0: raise ValueError("site_a is outsite the cell.") site_abc = V_o / abc_s + site_a else: # site_a = [x, y, z] for i in xrange(3): if site_a[i] > abc_s[i]: raise ValueError("sites_a is outside the cell.") site_a1 = np.array(site_a) # convert to a1, a2, a3 #< site_a2 = np.dot(a123_s, site_a1.T) / abc_s #< site_abc = (V_o+site_a2) / abc_s site_a2 = np.dot(b123_s, site_a1.T) site_abc = V_o/abc_s+site_a2 for i in xrange(3): if site_abc[i] < 0 or site_abc[i] > 1: raise ValueError("wrong distance, atom will be outside the cell.") print 'add_site:', site_abc, atom ist = InsertSitesTransformation(species=atom, coords=[site_abc]) structure_ad = ist.apply_transformation(structure_a) return structure_ad
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)