def generate_defect_structure(self, supercell=(1, 1, 1)): """ Returns Defective Substitution structure, decorated with charge. If bulk structure had any site properties, all of these properties are removed in the resulting defect structure. Args: supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix """ defect_structure = Structure( self.bulk_structure.copy().lattice, [site.specie for site in self.bulk_structure], [site.frac_coords for site in self.bulk_structure], to_unit_cell=True, coords_are_cartesian = False, site_properties = None) #remove all site_properties defect_structure.make_supercell(supercell) #create a trivial defect structure to find where supercell transformation moves the defect struct_for_defect_site = Structure( self.bulk_structure.copy().lattice, [self.site.specie], [self.site.frac_coords], to_unit_cell=True, coords_are_cartesian = False) struct_for_defect_site.make_supercell(supercell) defect_site = struct_for_defect_site[0] poss_deflist = sorted( defect_structure.get_sites_in_sphere(defect_site.coords, 0.1, include_index=True), key=lambda x: x[1]) defindex = poss_deflist[0][2] subsite = defect_structure.pop(defindex) defect_structure.append(self.site.specie.symbol, subsite.coords, coords_are_cartesian=True, properties = None) defect_structure.set_charge(self.charge) return defect_structure
def generate_defect_structure(self, supercell=(1, 1, 1)): """ Returns Defective Interstitial structure, decorated with charge If bulk structure had any site properties, all of these properties are removed in the resulting defect structure Args: supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix """ defect_structure = Structure( self.bulk_structure.copy().lattice, [site.specie for site in self.bulk_structure], [site.frac_coords for site in self.bulk_structure], to_unit_cell=True, coords_are_cartesian = False, site_properties = None) #remove all site_properties defect_structure.make_supercell(supercell) #create a trivial defect structure to find where supercell transformation moves the defect site struct_for_defect_site = Structure( self.bulk_structure.copy().lattice, [self.site.specie], [self.site.frac_coords], to_unit_cell=True, coords_are_cartesian = False) struct_for_defect_site.make_supercell(supercell) defect_site = struct_for_defect_site[0] defect_structure.append(self.site.specie.symbol, defect_site.coords, coords_are_cartesian=True, properties = None) defect_structure.set_charge(self.charge) return defect_structure
def trilayer(doped = None): a = 5.43 fcc = Lattice([[a/2,a/2,0],[a/2,0,a/2],[0,a/2,a/2]]) trilayer = Structure(fcc,['Si']*2,[[0.00,0.00,0.00],[0.25,0.25,0.25]]) # Make the cell cubic trilayer.make_supercell([[1,1,-1],[1,-1,1],[-1,1,1]]) trilayer.make_supercell([[1,1,0],[1,-1,0],[0,0,4]]) # Rotate the cell rt = 0.70710678118654746 symmop = SymmOp.from_rotation_and_translation([[rt,rt,0],[rt,-rt,0],[0,0,1]]) trilayer.apply_operation(symmop) if doped is not None: frac_coords = numpy.array([0.5,0.0,0.5]) for i,atom in enumerate(trilayer): if numpy.linalg.norm(atom.frac_coords-frac_coords) < 0.001: trilayer.replace(i,doped,frac_coords) for z in [0.375,0.625]: for xy in [0.00,0.50]: trilayer.append('Mn',[xy,xy,z]) return trilayer
def SiMn_Isite(): a = 5.43 fcc = Lattice([[a/2,a/2,0],[a/2,0,a/2],[0,a/2,a/2]]) isite = Structure(fcc,['Si']*2,[[0.00,0.00,0.00],[0.25,0.25,0.25]]) # Make the cell cubic isite.make_supercell([[1,1,-1],[1,-1,1],[-1,1,1]]) # Insert Mn atom isite.append('Mn',[0.50,0.50,0.50]) return isite
def test_propertied_structure_mod(self): prop_structure = Structure( self.structure.lattice, ["Si"] * 2, self.structure.frac_coords, site_properties={"magmom": [5, -5]} ) prop_structure.append("C", [0.25, 0.25, 0.25]) d = prop_structure.to_dict with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") s2 = Structure.from_dict(d) self.assertEqual(len(w), 1) self.assertEqual( str(w[0].message), "Not all sites have property magmom. Missing values are set " "to None." )
def SiMn_Ssite(): a = 5.43 fcc = Lattice([[a/2,a/2,0],[a/2,0,a/2],[0,a/2,a/2]]) ssite = Structure(fcc,['Si']*2,[[0.00,0.00,0.00],[0.25,0.25,0.25]]) # Make the cell cubic ssite.make_supercell([[1,1,-1],[1,-1,1],[-1,1,1]]) # Insert Mn atom Mnsite = numpy.array([0.25,0.25,0.25]); for i,atom in enumerate(ssite): if numpy.linalg.norm(atom.frac_coords-Mnsite) < 0.01: del ssite[i] ssite.append('Mn',Mnsite) return ssite
def Si512Mn(): a = 5.43 fcc = Lattice([[a/2,a/2,0],[a/2,0,a/2],[0,a/2,a/2]]) supercell = Structure(fcc,['Si']*2,[[0.00,0.00,0.00],[0.25,0.25,0.25]]) # Make the cell cubic supercell.make_supercell([[1,1,-1],[1,-1,1],[-1,1,1]]) supercell.make_supercell([4,4,4]) # Insert Mn atom Mnsite = numpy.array([0.50,0.50,0.50]) for i,atom in enumerate(supercell): if numpy.linalg.norm(atom.frac_coords - Mnsite) < 0.01: supercell.translate_sites([i],[1./8,1./8,1./8]) supercell.append('Mn',[0.50,0.50,0.50]) break return supercell
def generate_defect_structure(self, supercell=(1, 1, 1)): """ Returns Defective Substitution structure, decorated with charge. If bulk structure had any site properties, all of these properties are removed in the resulting defect structure. Args: supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix """ defect_structure = Structure( self.bulk_structure.copy().lattice, [site.specie for site in self.bulk_structure], [site.frac_coords for site in self.bulk_structure], to_unit_cell=True, coords_are_cartesian=False, site_properties=None) # remove all site_properties defect_structure.make_supercell(supercell) # create a trivial defect structure to find where supercell transformation moves the defect struct_for_defect_site = Structure(self.bulk_structure.copy().lattice, [self.site.specie], [self.site.frac_coords], to_unit_cell=True, coords_are_cartesian=False) struct_for_defect_site.make_supercell(supercell) defect_site = struct_for_defect_site[0] poss_deflist = sorted(defect_structure.get_sites_in_sphere( defect_site.coords, 0.1, include_index=True), key=lambda x: x[1]) defindex = poss_deflist[0][2] subsite = defect_structure.pop(defindex) defect_structure.append(self.site.specie.symbol, subsite.coords, coords_are_cartesian=True, properties=None) defect_structure.set_charge(self.charge) return defect_structure
def generate_defect_structure(self, supercell=(1, 1, 1)): """ Returns Defective Interstitial structure, decorated with charge If bulk structure had any site properties, all of these properties are removed in the resulting defect structure Args: supercell (int, [3x1], or [[]] (3x3)): supercell integer, vector, or scaling matrix """ defect_structure = Structure( self.bulk_structure.copy().lattice, [site.specie for site in self.bulk_structure], [site.frac_coords for site in self.bulk_structure], to_unit_cell=True, coords_are_cartesian=False, site_properties=None, ) # remove all site_properties defect_structure.make_supercell(supercell) # create a trivial defect structure to find where supercell transformation moves the defect site struct_for_defect_site = Structure( self.bulk_structure.copy().lattice, [self.site.specie], [self.site.frac_coords], to_unit_cell=True, coords_are_cartesian=False, ) struct_for_defect_site.make_supercell(supercell) defect_site = struct_for_defect_site[0] defect_structure.append( self.site.specie.symbol, defect_site.coords, coords_are_cartesian=True, properties=None, ) defect_structure.set_charge(self.charge) return defect_structure
def make_trilayer(xyscale = 2, zscale = 4): a = Length(5.431,"ang") fcc_lattice = np.array([[.0,.5,.5],[.5,.0,.5],[.5,.5,.0]]) lattice = Lattice(fcc_lattice * a) trilayer = Structure(lattice, ['Si','Si'], [[0.00,0.00,0.00],[0.25,0.25,0.25]]) trilayer.make_supercell([[0,0,1],[1,-1,0],[1,1,-1]]) trilayer.make_supercell([[xyscale,0,0],[0,xyscale,0],[0,0,zscale]]) # Dope the Ga sites for idx,site in enumerate(trilayer): if np.linalg.norm(site.frac_coords - np.array([+.0,+.5,.0])) < 1e-10: trilayer.replace(idx,Element('Ga')) if np.linalg.norm(site.frac_coords - np.array([+.5,+.0,.0])) < 1e-10: trilayer.replace(idx,Element('Ga')) # Insert the Mn sites trilayer.append('Mn', [0.0,0.0,zscale*a-a/2], coords_are_cartesian=True) trilayer.append('Mn', [0,a,zscale*a-a/2], coords_are_cartesian=True) trilayer.append('Mn', [0.0,0.0,a/2], coords_are_cartesian=True) trilayer.append('Mn', [0,a,a/2], coords_are_cartesian=True) return trilayer.get_sorted_structure()
def convert(bulk, slab, index, output, generate=True, print_M=True): if type(bulk) == str: primitiveCell = Structure.from_file(bulk) else: primitiveCell = bulk if type(slab) == str: refSlab = Structure.from_file(slab) else: refSlab = slab sa = SpacegroupAnalyzer(primitiveCell) conventionalCell = sa.get_conventional_standard_structure() conventionalCell.to(filename='POSCAR.conventional') bulk = read('POSCAR.conventional') os.remove('POSCAR.conventional') slab = surface(bulk, index, layers=2, vacuum=10) lattice, _, _ = spglib.standardize_cell(cell=(slab.get_cell(), slab.get_scaled_positions(), slab.get_atomic_numbers()), no_idealize=True) lattice_params = np.sort(np.linalg.norm(lattice, axis=1))[:2] scales = np.round( np.array([refSlab.lattice.a, refSlab.lattice.b] / lattice_params), 2) newLattice = [] oldLattice = refSlab.lattice for length, scale in zip([oldLattice.a, oldLattice.b], scales): for j in range(len(lattice)): if abs((np.linalg.norm(lattice[j]) * scale) - length) < 1e-1: newLattice.append(copy.copy(scale * lattice[j][:])) lattice[j] = [0, 0, 0] break for i in range(len(lattice)): norm = np.linalg.norm(lattice[i]) if norm > 1e-1: newLattice.append(lattice[i] / norm * oldLattice.c) break newLattice = Lattice(np.array(newLattice)) for x, y in zip(oldLattice.angles, newLattice.angles): assert abs( x - y ) < 1e-2, "The converted lattice has incorrect angles: {} compared with reference slab: {}".format( " ".join(str(x) for x in newLattice.angles), " ".join(str(x) for x in oldLattice.angles)) newSlab = Structure(newLattice, [], []) for atom in refSlab: newSlab.append(atom.specie, atom.frac_coords[:]) if generate: Poscar(newSlab.get_sorted_structure()).write_file(output, direct=True) transformMat = newSlab.lattice.matrix.dot( np.linalg.inv(primitiveCell.lattice.matrix)) transformMat = transformMat.round().astype(int) if print_M: print('-------------------------------------------') print('Your Transformtaion Matrix is:') print(' ') print(transformMat) print('-------------------------------------------') return transformMat