def get_interstitials(structure, ttol=0.5): """ Function to return unique interstitial sites in the given structure Parameters structure = poscar file (using read.poscar) ttol = tolerance Returns unique_int_list = list of unique intestital sites (cartesian (x,y,z) as list) in the given structure """ s = deepcopy(structure) prim = primitive(s) spg = spglib.get_spacegroup(prim, 0.1) ### Step 1: get unique sites in the primitive of the given structure uniq_sites = get_unique_wyckoff(prim) ### Step 2: get all interstitial sites from Voronoi method ints2 = get_all_interstitials(prim, uniq_sites) ### get interstital sites within primitive cell ints_prim = get_ints_in_prim_cell(prim, ints2) ### Step 3: get unique interstitials after symmetry analysis ints3 = get_unique_ints(prim, ints_prim, ttol=ttol) return ints3
def prepareet(self): atoms = io.read('POSCAR') from pyspglib import spglib s = spglib.get_spacegroup(atoms) from aces.scanf import sscanf sgN = sscanf(s, '%s (%d)')[1] sg = Spacegroup(sgN) atoms.info = {'spacegroup': sg} nelect = self.getNelect(outcar='band/OUTCAR') # The remaining part takes care of writing the files required by # BoltzTraP. bandstructure = vasp2boltz.get_vasp_bandstructure(pathname='band/') tl.mkcd('et') vasp2boltz.write_bandstructure_boltztrap( bandstructure, filename='et.energy') vasp2boltz.write_structure_boltztrap(atoms, filename='et.struct') vasp2boltz.write_intrans_boltztrap( n_electrons=nelect, filename='et.intrans') s = tl.read('et.energy') s = s.replace('HTE', 'et') tl.write(s, 'et.energy') s = tl.read('et.struct') s = s.replace('HTE', 'et') tl.write(s, 'et.struct') tl.cd('..')
def prepareet(self): atoms = io.read('POSCAR') from pyspglib import spglib s = spglib.get_spacegroup(atoms) from aces.scanf import sscanf sgN = sscanf(s, '%s (%d)')[1] sg = Spacegroup(sgN) atoms.info = {'spacegroup': sg} nelect = self.getNelect(outcar='band/OUTCAR') # The remaining part takes care of writing the files required by # BoltzTraP. bandstructure = vasp2boltz.get_vasp_bandstructure(pathname='band/') tl.mkcd('et') vasp2boltz.write_bandstructure_boltztrap(bandstructure, filename='et.energy') vasp2boltz.write_structure_boltztrap(atoms, filename='et.struct') vasp2boltz.write_intrans_boltztrap(n_electrons=nelect, filename='et.intrans') s = tl.read('et.energy') s = s.replace('HTE', 'et') tl.write(s, 'et.energy') s = tl.read('et.struct') s = s.replace('HTE', 'et') tl.write(s, 'et.struct') tl.cd('..')
def spglib_get_spacegroup(struct, **kwds): """Find spacegroup for given Structure. Uses pyspglib. Parameters ---------- struct : Structure **kwds : keywords passed to ``spglib.get_spacegroup()``, e.g. `symprec` and `angle_tolerance` last time I checked Returns ------- spg_num, spg_sym spg_num : int space group number spg_sym : str space group symbol Notes ----- The used function ``spglib.get_spacegroup()`` returns a string, which we split into `spg_num` and `spg_sym`. """ ret = spglib.get_spacegroup(struct.get_fake_ase_atoms(), **kwds) spl = ret.split() spg_sym = spl[0] spg_num = spl[1] spg_num = spg_num.replace('(','').replace(')','') spg_num = int(spg_num) return spg_num,spg_sym
def get_duplicates(massextr, te_diff=0.01): """ function to identify unique intersitials Parameters massextr = Pylada mass extraction object (directory with all intersitials directories) te_diff = difference in total energy among interstitials, default = 0.01 eV Returns dict = {key='foldername', total_energy, index} Note" index = all the foldername (intersitials) with same index are effectively considered equivalent Criteria for duplicates 1. Total_energy_difference <= 0.01 eV 2. Space_group 3. comparing first neighbor list for all the sites in the structure """ dict_E = massextr.total_energies dict_Str = massextr.structure dict2 = {} g = 0 for k in dict_E.keys(): g = g + 1 dict2[k] = [dict_E[k]] dict2[k].append(g) folder_list = [l for l in massextr] folder_combs = combinations(folder_list, 2) for i in folder_combs: diff_E = abs(dict2[i[0]][0] - dict2[i[1]][0]) str1 = dict_Str[i[0]] str2 = dict_Str[i[1]] spg1 = spglib.get_spacegroup(str1) spg2 = spglib.get_spacegroup(str2) ngh_list_1 = sorted( [len(neighbors(str1, 1, atom.pos, 0.2)) for atom in str1]) ngh_list_2 = sorted( [len(neighbors(str2, 1, atom.pos, 0.2)) for atom in str2]) if diff_E <= te_diff: if spg1 == spg2: if ngh_list_1 == ngh_list_2: dict2[i[1]][1] = dict2[i[0]][1] return (dict2)
def analysis(struct, symprec=1e-5): ensure_pyspg_is_imported() atoms = structure_to_spglib_atoms(struct) val = spglib.get_spacegroup(atoms) print("Spacegroup is:", val) val = spglib.refine_cell(atoms, symprec=symprec) print("Primitive", val)
def primitive(struct, symprec=1e-5): ensure_pyspg_is_imported() atoms = structure_to_spglib_atoms(struct) prim = spglib.refine_cell(atoms, symprec=symprec) sg = spglib.get_spacegroup(atoms) struct = httk.iface.spglib_if.spglib_out_to_struct(prim) struct.comment = "Spacegroup: " + sg return struct
def get_sg(lattice): """ Get the space-group of the system. Args: lattice: the ASE crystal class Returns: sg (int): integer number of the spacegroup """ spacegroup = spglib.get_spacegroup(lattice, symprec=1e-5) space_split=spacegroup.split() spg_num = space_split[1].replace('(','').replace(')','') sg = Spacegroup(int(spg_num)) return sg
def writeCIF (cell, prec, basename): # Find spacegroup name and number sg = spglib.get_spacegroup(cell, symprec=prec) sg, sgid = sg.split(" (") sgid = sgid.replace(")", "") # Find detailed info about the refined cell lattice, scaled_positions, numbers = spglib.refine_cell (cell, prec) a, b, c, alpha, beta, gamma = cellParameters (lattice) f = open((basename + " " + sg + ".cif").replace("/","|"), "w") f.write ("# Symmetrized structure with precision = %g\n" % prec) f.write (("data_" + basename + sg + "\n").replace(" ", "_")) f.write ("_cell_length_a %.7g\n" % a) f.write ("_cell_length_b %.7g\n" % b) f.write ("_cell_length_c %.7g\n" % c) f.write ("_cell_angle_alpha %.7g\n" % alpha) f.write ("_cell_angle_beta %.7g\n" % beta) f.write ("_cell_angle_gamma %.7g\n" % gamma) f.write ("_symmetry_space_group_name_H-M '" + sg + "'\n") f.write ("_symmetry_Int_Tables_number " + str(sgid) + "\n") # Write out atomic positions f.write (""" loop_ _atom_site_label _atom_site_type_symbol _atom_site_occupancy _atom_site_fract_x _atom_site_fract_y _atom_site_fract_z """) for pos, at in zip(scaled_positions, numbers): sym = element_symbols[at] f.write ("%s %s 1.0 %.7f %.7f %.7f\n" % (sym, sym, pos[0], pos[1], pos[2])) f.close()
def get_lattice_type(self): ''' Find the symmetry of the crystal using spglib symmetry finder. Assign to sg_name i sg_nr members name of the space group and its number extracted from the result. Based on the group number identify also the lattice type (assigned to sg_type member) and the Bravais lattice of the crystal (assigned to bravais member). The returned value is the lattice type number. The lattice type numbers are (see also Crystal.ls, the numbering starts from 1): Triclinic (1), Monoclinic (2), Orthorombic (3), Tetragonal (4) Trigonal (5), Hexagonal (6), Cubic (7) ''' # Table of lattice types and correcponding group numbers dividing # the ranges. See get_lattice_type method for precise definition. lattice_types=[ [3, "Triclinic"], [16, "Monoclinic"], [75, "Orthorombic"], [143, "Tetragonal"], [168, "Trigonal"], [195, "Hexagonal"], [231, "Cubic"] ] sg=spg.get_spacegroup(self) m=re.match('([A-Z].*\\b)\s*\(([0-9]*)\)',sg) self.sg_name=m.group(1) self.sg_nr=string.atoi(m.group(2)) for n,l in enumerate(lattice_types) : if self.sg_nr < l[0] : lattice=l[1] lattype=n+1 break self.sg_type=lattype self.bravais=lattice return lattype
def test_shift(src): from pylada.crystal.iterator import equivalence as equivalence_iterator from pmpaths import my_space_group, my_equivalence_iterator from copy import deepcopy src0 = deepcopy(src) src_sg = my_space_group(src) dofmin = 1000 dmin = 1e10 groups = [u for u in my_equivalence_iterator(src, src_sg)] print "groups of equiv atom indices in src:", groups nshift = len(groups) for igroup in range(nshift): src1 = deepcopy(src0) iorg = groups[igroup][0] shift = deepcopy(src[iorg].pos) # note, uncentered sourc here for ia in range(len(src)): src1[ia].pos = src0[ia].pos - shift sg = spglib.get_spacegroup(src1, symprec=1e-5, angle_tolerance=-1.0) print "shift, sg", shift, sg
[(0, 0, 0), (0.25, 0.25, 0.25)], # Atomic positions (fractional coordinates) spacegroup=216, # International number of the spacegroup of the crystal cellpar=[a, a, a, 90, 90, 90]) # Unit cell (a, b, c, alpha, beta, gamma) in Angstrom, Degrees # Write the image to disk file ase.io.write('crystal.png', # The file where the picture get stored cryst, # The object holding the crystal definition format='png', # Format of the file show_unit_cell=2, # Draw the unit cell boundaries rotation='115y,15x', # Rotate the scene by 115deg around Y axis and 15deg around X axis scale=30) # Scale of the picture # Display the image Image(filename='crystal.png') print 'Space group:', spglib.get_spacegroup(cryst) # Create a Quantum Espresso calculator for our work. # This object encapsulates all parameters of the calculation, # not the system we are investigating. qe=QuantumEspresso(label='SiC', # Label for calculations wdir='.', # Working directory pseudo_dir='/usr/share/espresso/pseudo', # Directory with pseudopotentials kpts=[2,2,2], # K-space sampling for the SCF calculation xc='pz', # Exchange functional type in the name of the pseudopotentials pp_type='vbc', # Variant of the pseudopotential pp_format='UPF', # Format of the pseudopotential files ecutwfc=20, # Energy cut-off (in Rydberg) use_symmetry=False, procs=8) # Use symmetry in the calculation ? print qe.directory
import os, sys def wait_for_results(systems): for n,r in enumerate(systems): print(n+1,end='') while not r.get_calculator().calc_finished() : print('.',end='') sys.stdout.flush() sleep(10) print(end=' ') sys.stdout.flush() print() a=4 ; c=crystal('Si',[(0,0,0)],spacegroup=221,cellpar=[a,a,a,90,90,90]) spglib.get_spacegroup(c) block=False calc = ClusterVasp(block=block) calc.set(prec = 'Accurate', xc = 'PBE', lreal = False, nsw=30, ediff=1e-8, ibrion=2, kpts=[3,3,3]) calc.set(isif=3) c.set_calculator(calc) l=ParCalculate(c,calc,cleanup=False,block=block) s = l[0]
from jasp import * with jasp('bulk/tio2/step2-1.05') as calc: calc.clone('bulk/tio2/step3') with jasp('bulk/tio2/step3', isif=3) as calc: calc.calculate() atoms = calc.get_atoms() print calc from pyspglib import spglib print '\nThe spacegroup is {0}'.format(spglib.get_spacegroup(atoms))
print('created new file.') with open('fit.out') as fh: for line in fh: fields = line.split() X = float(fields[0]) formation_energy = float(fields[1]) id1 = fields[-1] # get number of rows. since we use 0-indexing, the next row is NROWS NROWS0 = len(sh0.get_rows()) NROWS1 = len(sh1.get_rows()) with jasp(id1) as calc: atoms = calc.get_atoms() composition = atoms.get_chemical_symbols(reduce=True) spacegroup = spglib.get_spacegroup(atoms, symprec=1e-5) natoms = len(atoms) try: x, V0, e0, B = analyze_eos() except TypeError: x, V0, e0, B = None, None, None, None magmom = atoms.get_magnetic_moment() # now we want to write out a row of data = [ id1, composition, spacegroup, natoms, formation_energy, B, magmom ] for i, d in enumerate(data): sh0.write(NROWS0, i, d)
try: cell = ase.io.read(sys.argv[1]) except Exception as e: print("Could not read CIF structure from file '" + sys.argv[1] + "'") print("Error message is: " + str(e)) sys.exit(1) if sys.argv[1][-4:] == ".cif": basename = sys.argv[1][:-4] else: basename = sys.argv[1] l = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ] l = ( [ 1e-10, 1e-9, 1e-8, 1e-7, 1e-6 ] + [ i*j for i in [ 1e-5, 1e-4, 1e-3, 1e-2, 1e-1 ] for j in l ] ) old = "" print("# Tolerance\tSpace group") for prec in l: s = spglib.get_spacegroup(cell, symprec=prec) if s != old: print("%g\t\t%s" % (prec, s)) writeCIF (cell, prec, basename) old = s sys.exit(0)
def anim_main(options): sgnum = [] sgfull = [] dat = [] c2dat = [] c2 = False for iter in range(options.frames): fname = "traj.%d.POSCAR" % iter fname = os.path.join(options.trajdir, fname) structure = pcread.poscar(fname) row = [] if (c2): c2row = [] for i in range(len(structure)): ## should just be doing this and be done: # nb = neighbors(structure, 1, structure[i].pos, options.tol) ## but not quite working, so do this: nnb = get_nnb(structure, i, options.tol) if (c2): #vladan cs = coordination_shells(structure, 2, structure[i].pos, options.tol) cs = get_2shells(structure, i, options.tol) # print "cs = ", cs # print "nb = ", nb # row.append(len(nb)) row.append(nnb) #row.append(len(cs[0])) # size of of 1st shell if (c2): #vladan c2row.append([len(cs[0]),len(cs[0])]) # size of of 2nd shell c2row.append([len(cs[0]), len(cs[1])]) # size of of 2nd shell sg = spglib.get_spacegroup(structure, symprec=1e-4, angle_tolerance=2.0) sgfull.append(sg) sg = sg.split("(")[1].split(")")[0] sgnum.append(int(sg)) dat.append(row) if (c2): c2dat.append(c2row) tot_coord_lost = 0 tot_coord_gained = 0 natoms = len(structure) if options.verbose > 0: print "#coordination for %s to %s transition:" % (options.B, options.A) if (options.verbose > 1): s = "#frame spacegroup : " for i in range(len(structure)): s += "atom%d " % i print s for i in range(len(dat)): s = "%d %s %d : " % (i, sgfull[i], sgnum[i]) row = dat[i] if (c2): c2row = c2dat[i] for j in range(len(row)): if (i > 0): tot_coord_lost += max( 0, last_row[j] - row[j] ) ## counting how many total bonds have broken, not how many restored tot_coord_gained += max( 0, row[j] - last_row[j] ) ## counting how many total bonds gained, not how many broken if (c2): s += "%d/%d,%d " % (row[j], c2row[j][0], c2row[j][1]) else: s += "%d " % (row[j]) if (options.verbose > 1): print s last_row = row speed = "FAST" if (tot_coord_lost == 0 or tot_coord_gained == 0) else "SLOW" if (options.verbose > 0): print "#Total of %.2f (%.2f) bonds per atom broken (resp.,made) in %s to %s transition." % ( tot_coord_lost / float(natoms), tot_coord_gained / float(natoms), options.B, options.A) print "This transition is likely to be ", speed if (options.A != None and options.verbose > 1): structure = pcread.poscar(options.A) sg = spglib.get_spacegroup(structure, symprec=1e-5, angle_tolerance=-1.0) # sg = sg.split("(")[1].split(")")[0] s = "#A %s " % (sg) for i in range(len(structure)): nnb = get_nnb(structure, i, options.tol) s += "%d " % nnb print s # test_shift(structure) if (options.B != None and options.verbose > 1): structure = pcread.poscar(options.B) sg = spglib.get_spacegroup(structure, symprec=1e-5, angle_tolerance=-1.0) # sg = sg.split("(")[1].split(")")[0] s = "#B %s " % (sg) for i in range(len(structure)): nnb = get_nnb(structure, i, options.tol) s += "%d " % nnb print s return speed == "FAST"
#!/usr/bin/env python import ase.io.vasp as io from pyspglib import spglib from optparse import OptionParser parser = OptionParser() parser.add_option("-f", "--file", action="store", type="string", dest="file", default="POSCAR", help="Path to input file [default: ./POSCAR]") parser.add_option("-p", "--prec", action="store", type="float", dest="prec", default=0.001, help="Precision for symmetry test [default: 0.001]") (options, args) = parser.parse_args() bulk = io.read_vasp(options.file) spacegroup = spglib.get_spacegroup(bulk, symprec=options.prec) print "Spacegroup information." print "-----------------------" print spacegroup print "-----------------------"
def write_cell_params(fh, a, p): ''' Write the specification of the cell using a traditional A,B,C, alpha, beta, gamma scheme. The symmetry and parameters are determined from the atoms (a) object. The atoms object is translated into a primitive unit cell but *not* converted. This is just an internal procedure. If you wish to work with primitive unit cells in ASE, you need to make a conversion yourself. The cell params are in angstrom. Input ----- fh file handle of the opened pw.in file a atoms object p parameters dictionary Output ------ Primitive cell tuple of arrays: (lattice, atoms, atomic numbers) ''' assert(p['use_symmetry']) # Get a spacegroup name and number for the a sg,sgn=spglib.get_spacegroup(a).split() # Extract the number sgn=int(sgn[1:-1]) # Extract the lattice type ltyp=sg[0] # Find a primitive unit cell for the system # puc is a tuple of (lattice, atoms, atomic numbers) puc=spglib.find_primitive(a) cell=puc[0] apos=puc[1] anum=puc[2] icell=a.get_cell() A=norm(icell[0]) B=norm(icell[1]) C=norm(icell[2]) # Select appropriate ibrav if sgn >= 195 : # Cubic lattice if ltyp=='P': p['ibrav']=1 # Primitive qepc=array([[1,0,0],[0,1,0],[0,0,1]]) elif ltyp=='F': p['ibrav']=2 # FCC qepc=array([[-1,0,1],[0,1,1],[-1,1,0]])/2.0 elif ltyp=='I': p['ibrav']=3 # BCC qepc=array([[1,1,1],[-1,1,1],[-1,-1,1]])/2.0 else : print 'Impossible lattice symmetry! Contact the author!' raise NotImplementedError #a=sqrt(2)*norm(cell[0]) qepc=A*qepc fh.write(' A = %f,\n' % (A,)) elif sgn >= 143 : # Hexagonal and trigonal if ltyp=='P' : p['ibrav']=4 # Primitive qepc=array([[1,0,0],[-1/2,sqrt(3)/2,0],[0,0,C/A]]) elif ltyp=='R' : p['ibrav']=5 # Trigonal rhombohedral raise NotImplementedError else : print 'Impossible lattice symmetry! Contact the author!' raise NotImplementedError qepc=A*qepc fh.write(' A = %f,\n' % (A,)) fh.write(' C = %f,\n' % (C,)) elif sgn >= 75 : raise NotImplementedError elif sgn ==1 : # P1 symmetry - no special primitive cell signal to the caller p['ibrav']=0 return None else : raise NotImplementedError cp=Atoms(cell=puc[0], scaled_positions=puc[1], numbers=puc[2], pbc=True) qepc=Atoms(cell=qepc, positions=cp.get_positions(), numbers=cp.get_atomic_numbers(), pbc=True) return qepc.get_cell(), qepc.get_scaled_positions(), qepc.get_atomic_numbers()
from vasp import Vasp calc = Vasp('bulk/tio2/step2-1.05') calc.clone('bulk/tio2/step3') calc = Vasp('bulk/tio2/step3', isif=3) calc.wait() print calc from pyspglib import spglib print '\nThe spacegroup is {0}'.format(spglib.get_spacegroup(calc.atoms))
def make_anim(A, B, Tm, shift, pairs, options): # combined view of the unit call and atom transforms # A is target, B is src, after src has been rotated and its unit cell axes permuted so that they # "most align" with those of A. Then transform is just two parts: first is unit cell Tform "Tm" # next is mapping in pairs ### no longer true: which is expressed in 3N-dim space as bigA. from copy import deepcopy from util import write_struct, write_xyz, transform_cell, write_tcl if options.verbose > 1: print "Exploring minimal path we have discovered..." # the results come out a little convoluated b/c of all the steps, so here we gather the # actual start and finish positions. details = False print B.cell print "maps to" print A.cell print "with internal atom shift" print shift print "and atom idx pairing" ppidx = pairs[0] ppos = pairs[1] ainv = npl.inv(A.cell) apos = [] bpos = [] for i in range(len(ppidx)): p = ppidx[i] q = ppos[i] print p, q ##, into_cell(np.dot(B.cell, np.dot(ainv, q[4])), B.cell) apos.append(q[3]) # target atom position bpos.append(q[4]) # src atom position if (options.verbose > 2): print "and A is just" print A.cell for a in A: print a.pos, into_cell(a.pos, A.cell) print "and B is just" print B.cell for b in B: print b.pos, into_cell(b.pos, B.cell) if (not os.path.exists(options.trajdir)): os.mkdir(options.trajdir) savedir = os.getcwd() os.chdir(options.trajdir) if (options.verbose > 1): print "saving starting anim" Bpath = deepcopy(B) tag = "Bpath0" write_xyz(options, Bpath, tag, options.output_tiles) fout = file("%s.tcl" % tag, "w") write_struct(fout, Bpath, "%s.xyz" % tag, 0, center=False, bonds=True, bond_len=options.bond_len) fout.close() # now write frames eye2 = 2.0 * np.identity(3) # for writing a big cell if we want dt = 1.0 / (options.frames - 1) t = 0 iter = 0 eps = 1e-6 curpos = [] while t <= 1 + eps: Bpath = deepcopy(B) Bpath.cell = t * A.cell + (1.0 - t) * B.cell for i in range(len(apos)): p = t * apos[i] + (1.0 - t) * bpos[ i] # this is an abs position, but in A's frame of reference (both apos and bpos are created with # B.cell transformed to A.cell. Here we are mapping to cells in between original B.cell and A.cell) # Note apos and bpos are not taken directly from A, B input cells but are part of the "pairing" data c = np.dot(ainv, p) # so get the coords pos = np.dot(Bpath.cell, c) # and express it w.r.t. evolving Bpath frame if (iter == 0): Bpath[i].pos = into_cell( pos, Bpath.cell) # then make sure it's _in_ the unit cell curpos.append(Bpath[i].pos) else: Bpath[i].pos = closest_to(pos, Bpath.cell, curpos[i]) curpos[i] = Bpath[i].pos if (iter == 0): ## testing/bug fixing Bstart = deepcopy(Bpath) if (options.verbose > 2): from pylada.crystal import space_group, primitive from pylada.math import gruber Btest = primitive(Bpath) g = gruber(Btest.cell) print "src has primitive cell:" print Btest.cell # print g Btest = supercell(Btest, g) spacegroup = space_group(Btest) sg = spglib.get_spacegroup(Btest, symprec=1e-4, angle_tolerance=2.0) print "src has %d syms and sg %s" % (len(spacegroup), str(sg)) sg = spglib.get_spacegroup(Bpath, symprec=1e-4, angle_tolerance=2.0) # sg = spglib.get_spacegroup(Bpath, symprec=1e-1, angle_tolerance=10.0) ### debugging if (options.verbose > 1): print t, sg, tag if (iter == options.frames - 1): ## testing/bug fixing Bend = deepcopy(Bpath) if (options.verbose > 2): from pylada.crystal import space_group, primitive from pylada.math import gruber Btest = primitive(Bpath) g = gruber(Btest.cell) print "target has primitive cell:" print Btest.cell # print g Btest = supercell(Btest, g) spacegroup = space_group(Btest) sg = spglib.get_spacegroup(Btest, symprec=1e-4, angle_tolerance=2.0) print "target has %d syms and sg %s" % (len(spacegroup), str(sg)) tag = "traj.%d" % iter write_xyz(options, Bpath, tag, options.output_tiles) fout = file("%s.tcl" % tag, "w") write_struct(fout, Bpath, "%s.xyz" % tag, 0, center=False, bonds=True, bond_len=options.bond_len) fout.close() # write poscar we can analyze later # bigB = supercell(Bpath, np.dot(eye2,Bpath.cell)) # for writing a big poscar with open("%s.POSCAR" % tag, "w") as f: pcwrite.poscar(Bpath, f, vasp5=True) t += dt iter += 1 os.chdir(savedir) if (options.verbose > 2): write_tcl(options, Bend, Bstart, pairs[1], "pairs") # some special work to verify we really arrived at B: # Borig = pcread.poscar(options.A) # M = np.dot(Borig.cell, npl.inv(Bpath.cell)) # Bfinal = transform_cell(M,Bpath) # bigB = supercell(Bfinal, np.dot(eye2,Bfinal.cell)) ## this is a special "doubling" test # with open("final.POSCAR", "w") as f: pcwrite.poscar(bigB, f, vasp5=True) # with open("final.POSCAR", "w") as f: pcwrite.poscar(Bfinal, f, vasp5=True) # sg = spglib.get_spacegroup(Bfinal, symprec=1e-4, angle_tolerance=2.0) ## this is "B in A coords" # print "spacegroup of final structure: ", sg sg = spglib.get_spacegroup(B, symprec=1e-4, angle_tolerance=2.0) if (options.verbose > 0): print "spacegroup of initial structure (B, [Bflip in code]) ", sg sg = spglib.get_spacegroup(A, symprec=1e-4, angle_tolerance=2.0) if (options.verbose > 1): print "spacegroup of target structure (A) ", sg
c = 3.52 MgB2 = Atoms( symbols=['Mg']+['B']*2, cell=[ ( a, 0, 0 ), ( -a/2, a/2*np.sqrt(3), 0 ), ( 0, 0, c ) ], scaled_positions=[ ( 0, 0, 0 ), ( 1.0/3, 2.0/3, 0.5 ), ( 2.0/3, 1.0/3, 0.5 ) ], pbc=True ) # For VASP case # import vasp # bulk = vasp.read_vasp(sys.argv[1]) print "[get_spacegroup]" print " Spacegroup of Silicon is ", spglib.get_spacegroup(silicon) print "" print "[get_spacegroup]" print " Spacegroup of Rutile is ", spglib.get_spacegroup(rutile) print "" print "[get_spacegroup]" print " Spacegroup of MgB2 is ", spglib.get_spacegroup(MgB2) print "" print "[get_symmetry]" print " Symmetry operations of Rutile unitcell are:" print "" symmetry = spglib.get_symmetry( rutile ) for i in range(symmetry['rotations'].shape[0]): print " --------------- %4d ---------------" % (i+1) rot = symmetry['rotations'][i] trans = symmetry['translations'][i]
print("created new file.") with open("fit.out") as fh: for line in fh: fields = line.split() X = float(fields[0]) formation_energy = float(fields[1]) id1 = fields[-1] # get number of rows. since we use 0-indexing, the next row is NROWS NROWS0 = len(sh0.get_rows()) NROWS1 = len(sh1.get_rows()) with jasp(id1) as calc: atoms = calc.get_atoms() composition = atoms.get_chemical_symbols(reduce=True) spacegroup = spglib.get_spacegroup(atoms, symprec=1e-5) natoms = len(atoms) try: x, V0, e0, B = analyze_eos() except TypeError: x, V0, e0, B = None, None, None, None magmom = atoms.get_magnetic_moment() # now we want to write out a row of data = [id1, composition, spacegroup, natoms, formation_energy, B, magmom] for i, d in enumerate(data): sh0.write(NROWS0, i, d) # now for sheet 1 - unit cell parameters uc = atoms.get_cell()
def raw_anim(A, B, options): # just animate between A and B, straight up! ### this option is under development savedir = os.getcwd() os.chdir(options.trajdir) structure = pcread.poscar(options.A) structure = pcread.poscar(options.B) print "saving starting anim" Bpath = deepcopy(B) tag = "Bpath0" write_xyz(options, Bpath, tag, options.output_tiles) fout = file("%s.tcl" % tag, "w") write_struct(fout, Bpath, "%s.xyz" % tag, 0, center=False, bonds=True, bond_len=options.bond_len) fout.close() # now write frames dt = 1.0 / (options.frames - 1) t = 0 iter = 0 eps = 1e-6 curpos = [] while t <= 1 + eps: Bpath = deepcopy(B) Bpath.cell = t * A.cell + (1.0 - t) * B.cell for i in range(len(apos)): pos = t * A[i].pos[i] + (1.0 - t) * B[i].pos[i] if (iter == 0): Bpath[i].pos = into_cell( pos, Bpath.cell) # then make sure it's _in_ the unit cell curpos.append(Bpath[i].pos) else: Bpath[i].pos = closest_to(pos, Bpath.cell, curpos[i]) curpos[i] = Bpath[i].pos if (iter == 0): ## testing/bug fixing from pylada.crystal import space_group, primitive from pylada.math import gruber Btest = primitive(Bpath) g = gruber(Btest.cell) print "src has cell:" print Btest.cell # print g Btest = supercell(Btest, g) spacegroup = space_group(Btest) sg = spglib.get_spacegroup(Btest, symprec=1e-4, angle_tolerance=2.0) print "src has %d syms and sg %s" % (len(spacegroup), str(sg)) Bstart = deepcopy(Bpath) sg = spglib.get_spacegroup(Bpath, symprec=1e-4, angle_tolerance=2.0) # sg = spglib.get_spacegroup(Bpath, symprec=1e-1, angle_tolerance=10.0) ### debugging print t, sg, tag if (iter == options.frames - 1): ## testing/bug fixing from pylada.crystal import space_group, primitive from pylada.math import gruber Btest = primitive(Bpath) g = gruber(Btest.cell) print "target has cell:" print Btest.cell # print g Btest = supercell(Btest, g) spacegroup = space_group(Btest) sg = spglib.get_spacegroup(Btest, symprec=1e-4, angle_tolerance=2.0) print "target has %d syms and sg %s" % (len(spacegroup), str(sg)) Bend = deepcopy(Bpath) tag = "traj.%d" % iter write_xyz(options, Bpath, tag, options.output_tiles) fout = file("%s.tcl" % tag, "w") write_struct(fout, Bpath, "%s.xyz" % tag, 0, center=False, bonds=True, bond_len=options.bond_len) fout.close() # write poscar we can analyze later # bigB = supercell(Bpath, np.dot(eye2,Bpath.cell)) # for writing a big poscar with open("%s.POSCAR" % tag, "w") as f: pcwrite.poscar(Bpath, f, vasp5=True) t += dt iter += 1 os.chdir(savedir) if (options.verbose > 2): write_tcl(options, Bend, Bstart, pairs[1], "pairs") # some special work to verify we really arrived at B: # Borig = pcread.poscar(options.A) # M = np.dot(Borig.cell, npl.inv(Bpath.cell)) # Bfinal = transform_cell(M,Bpath) # bigB = supercell(Bfinal, np.dot(eye2,Bfinal.cell)) ## this is a special "doubling" test # with open("final.POSCAR", "w") as f: pcwrite.poscar(bigB, f, vasp5=True) # with open("final.POSCAR", "w") as f: pcwrite.poscar(Bfinal, f, vasp5=True) # sg = spglib.get_spacegroup(Bfinal, symprec=1e-4, angle_tolerance=2.0) ## this is "B in A coords" # print "spacegroup of final structure: ", sg sg = spglib.get_spacegroup(B, symprec=1e-4, angle_tolerance=2.0) print "spacegroup of initial structure (B, [Bflip in code]) ", sg sg = spglib.get_spacegroup(A, symprec=1e-4, angle_tolerance=2.0) print "spacegroup of target structure (A) ", sg
pbc=True) a = 3.07 c = 3.52 MgB2 = Atoms(symbols=['Mg'] + ['B'] * 2, cell=[(a, 0, 0), (-a / 2, a / 2 * np.sqrt(3), 0), (0, 0, c)], scaled_positions=[(0, 0, 0), (1.0 / 3, 2.0 / 3, 0.5), (2.0 / 3, 1.0 / 3, 0.5)], pbc=True) # For VASP case # import vasp # bulk = vasp.read_vasp(sys.argv[1]) print "[get_spacegroup]" print " Spacegroup of Silicon is ", spglib.get_spacegroup(silicon) print "" print "[get_spacegroup]" print " Spacegroup of Rutile is ", spglib.get_spacegroup(rutile) print "" print "[get_spacegroup]" print " Spacegroup of MgB2 is ", spglib.get_spacegroup(MgB2) print "" print "[get_symmetry]" print " Symmetry operations of Rutile unitcell are:" print "" symmetry = spglib.get_symmetry(rutile) for i in range(symmetry['rotations'].shape[0]): print " --------------- %4d ---------------" % (i + 1) rot = symmetry['rotations'][i] trans = symmetry['translations'][i]
def view_spacegroup(filename='POSCAR',symprec=1e-3): atoms=read_vasp(filename) print("SPACEGROUP: %s"%spglib.get_spacegroup(atoms,symprec=symprec))