def generate_vaspinput(ele1="Ti", ele2="O", a_ref=5.05): # C1 CaF2 a = a_ref atoms = crystal([ele1, ele2], [(0.0, 0.5, 0.5), (0.25, 0.25, 0.25)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("C1"): os.mkdir("C1") os.chdir("C1") write_vasp("POSCAR", atoms, label="C1", direct=True, long_format=True, vasp5=True) os.chdir("..") # C2 FeS2 a = a_ref atoms = crystal( [ele1, ele2], [(0.0, 0.0, 0.0), (0.38504, 0.38504, 0.38504)], spacegroup=205, cellpar=[a, a, a, 90, 90, 90] ) if not os.path.exists("C2"): os.mkdir("C2") os.chdir("C2") write_vasp("POSCAR", atoms, label="C2", direct=True, long_format=True, vasp5=True) os.chdir("..") # C3 Cu2O a = a_ref * 0.917 atoms = crystal([ele1, ele2], [(0.0, 0.0, 0.0), (0.25, 0.25, 0.25)], spacegroup=224, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("C3"): os.mkdir("C3") os.chdir("C3") write_vasp("POSCAR", atoms, label="C3", direct=True, long_format=True, vasp5=True) os.chdir("..") # C4 TiO2 (rutile) a = a_ref * 0.9278 c = a * 0.6440 atoms = crystal( [ele1, ele2], [(0.0, 0.0, 0.0), (0.3057, 0.3057, 0.0)], spacegroup=136, cellpar=[a, a, c, 90, 90, 90] ) if not os.path.exists("C4"): os.mkdir("C4") os.chdir("C4") write_vasp("POSCAR", atoms, label="C4", direct=True, long_format=True, vasp5=True) os.chdir("..") # C5 TiO2 (anatase) a = a_ref * 0.7798 c = a * 2.514 atoms = crystal([ele1, ele2], [(0.0, 0.0, 0.0), (0.0, 0.0, 0.2081)], spacegroup=141, cellpar=[a, a, c, 90, 90, 90]) if not os.path.exists("C5"): os.mkdir("C5") os.chdir("C5") write_vasp("POSCAR", atoms, label="C5", direct=True, long_format=True, vasp5=True) os.chdir("..")
def __getitem__(self, name): d = self.data[name] # the index of label in labels less one # (compound is already as key in d) a = d[self.labels.index("aexp") - 1] if name in ["Cr2CoGa", "Mn2CoAl", "Mn2CoGe", "Fe2CoSi"]: # http://en.wikipedia.org/wiki/Space_group sg = 216 else: sg = 225 symbols = string2symbols(name) symbols.pop(0) b = crystal( symbols=symbols, basis=[(1.0 / 4, 1.0 / 4, 1.0 / 4), (0.0, 0.0, 0.0), (1.0 / 2, 1.0 / 2, 1.0 / 2)], spacegroup=sg, cellpar=[a, a, a, 90, 90, 90], primitive_cell=True, ) # set average moments on all atoms (add + 2.0) magmom = d[self.labels.index("mexp") - 1] + 2.0 m = [magmom / len(b)] * len(b) # break spin symmetry between atoms no. 1 and 2 m[1] = m[1] + m[2] m[2] = -m[2] b.set_initial_magnetic_moments(m) if 0: from ase.visualize import view view(b) return b
def generate_vaspinput(element="Li", a_ref=3.05): # HCP a = a_ref c = 1.62 * a_ref atoms = crystal(element, [(1.0 / 3.0, 2.0 / 3.0, 3.0 / 4.0)], spacegroup=194, cellpar=[a, a, c, 90, 90, 120]) if not os.path.exists("HCP"): os.mkdir("HCP") os.chdir("HCP") write_vasp("POSCAR", atoms, label="HCP", direct=True, long_format=True, vasp5=True) os.chdir("..") # FCC structure a = a_ref * 1.42 atoms = crystal(element, [(0, 0, 0)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("FCC"): os.mkdir("FCC") os.chdir("FCC") write_vasp("POSCAR", atoms, label="FCC", direct=True, long_format=True, vasp5=True) os.chdir("..") # BCC structure a = a_ref * 1.13 atoms = crystal(element, [(0, 0, 0)], spacegroup=229, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("BCC"): os.mkdir("BCC") os.chdir("BCC") write_vasp("POSCAR", atoms, label="BCC", direct=True, long_format=True, vasp5=True) os.chdir("..") # SCC structure a = a_ref * 0.90 atoms = crystal(element, [(0, 0, 0)], spacegroup=221, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("SCC"): os.mkdir("SCC") os.chdir("SCC") write_vasp("POSCAR", atoms, label="SCC", direct=True, long_format=True, vasp5=True) os.chdir("..") # Diamond a = a_ref * 1.93 atoms = crystal(element, [(0, 0, 0)], spacegroup=227, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("DIAMOND"): os.mkdir("DIAMOND") os.chdir("DIAMOND") write_vasp("POSCAR", atoms, label="DIAMOND", direct=True, long_format=True, vasp5=True) os.chdir("..")
def lmp_structure(self): if self.type=='rutile': a = 4.584 c = 2.953 atoms =crystal(self.elements, basis=[(0, 0, 0), (0.3, 0.3, 0.0)],spacegroup='P4_2/mnm', cellpar=[a, a, c, 90, 90, 90]) elif self.type=='anatase': a=3.7842 c=9.5146 atoms=crystal(self.elements, basis=[(0, 0, 0), (0 ,0 ,.2081)],spacegroup=141, cellpar=[a, a, c, 90, 90, 90]) else: raise Exception('unkown TiO2 type!') return atoms
def generate_vaspinput(ele1="Ca", ele2="O", a_ref=3.05): # B1 NaCl a = a_ref atoms = crystal([ele1, ele2], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("B1"): os.mkdir("B1") os.chdir("B1") write_vasp("POSCAR", atoms, label="B1", direct=True, long_format=True, vasp5=True) os.chdir("..") # B2 CsCl a = a_ref * 0.6975 atoms = crystal([ele1, ele2], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=221, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("B2"): os.mkdir("B2") os.chdir("B2") write_vasp("POSCAR", atoms, label="B2", direct=True, long_format=True, vasp5=True) os.chdir("..") # B3 ZnS Sphalerite (F43m) a = a_ref * 1.086 atoms = crystal([ele1, ele2], [(0, 0, 0), (0.25, 0.25, 0.25)], spacegroup=216, cellpar=[a, a, a, 90, 90, 90]) if not os.path.exists("B3"): os.mkdir("B3") os.chdir("B3") write_vasp("POSCAR", atoms, label="B3", direct=True, long_format=True, vasp5=True) os.chdir("..") # B4 ZnS Wurtzite (p6mc) a = a_ref * 0.8272 c = a * 1.635 atoms = crystal([ele1, ele2], [(0.3333, 0.6667, 0), (0.3333, 0.6667, 0.3748)], spacegroup=186, cellpar=[a, a, c, 90, 90, 120]) if not os.path.exists("B4"): os.mkdir("B4") os.chdir("B4") write_vasp("POSCAR", atoms, label="B4", direct=True, long_format=True, vasp5=True) os.chdir("..")
def cubic_perovskite(species,cell_par=[6,6,6,90,90,90],repetitions=[1,1,1]): system = crystal((species), basis=[(0,0,0), (0.5, 0.5, 0.5), (0.5, 0.5, 0)], spacegroup=221, size = repetitions, cellpar=cell_par) sites_list = [] oxidation_states = [[2]] + [[4]] + [[-2]]*3 for site in zip(system.get_scaled_positions(),oxidation_states): sites_list.append(Site(site[0],site[1])) return Lattice(sites_list, oxidation_states), system
def halfheusler(symbols, a): # See page 21 of http://d-nb.info/1021065781/34 # The inequivalent “stuffing atom” (Wycoff position 4c) third. b = crystal(symbols=symbols, basis=[(0., 0., 0.), (1./2, 1./2, 1./2), (1./4, 1./4, 1./4)], spacegroup=216, cellpar=[a, a, a, 90, 90, 90], primitive_cell=False) return b.copy()
def wurtzite(species, cell_par=[2,2,6,90,90,120],repetitions=[1,1,1]): system = crystal((species), basis=[(2./3.,1./3.,0),(2./3.,1./3.,5./8.)], spacegroup=186, size = repetitions, cellpar=[3, 3, 6, 90,90,120]) sites_list = [] oxidation_states = [[1],[2],[3],[4]] + [[-1],[-2],[-3],[-4]] for site in zip(system.get_scaled_positions(),oxidation_states): sites_list.append(Site(site[0],site[1])) return Lattice(sites_list, oxidation_states), system
from ase.lattice.spacegroup import crystal a = 4.05 al = crystal('Al', [(0,0,0)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90])
def banner(msg): print() print(60*'=') print(max(0,(60-len(msg))//2-1)*' ',msg) print(60*'=') def secban(msg): print() print(max(0,(60-len(msg))//2-1)*' ',msg) print(60*'-') banner('Structure optimization on MgO') a = 4.291 MgO = crystal(['Mg', 'O'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) ################################## # Provide your own calculator here ################################## calc=ClusterVasp(nodes=1,ppn=8) # The calculator must be runnable in an isolated directory # Without disturbing other running instances of the same calculator # They are run in separate processes (not threads!) MgO.set_calculator(calc) calc.set(prec = 'Accurate', xc = 'PBE', lreal = False, isif=2, nsw=20, ibrion=2, kpts=[1,1,1]) print("Residual pressure: %.3f GPa" % (MgO.get_pressure()/GPa)) calc.clean()
def make_eta_c4(names,sizes): #work out the expansion factor #dist0 = furthest_dummy(mol0) #dist1 = furthest_dummy(mol1) factor = sum(sizes) #dist0 + dist1 factor = factor * 2 #factor = 3.0 print "factor = " , factor a = 3.1018 * factor b = 0.4373 * factor #b = 0.5466 * factor #RCSR value, incorrect? # C -> triangles, N => midpoints #eta_c4 = crystal(['C', 'N' , 'N'], [(0.4069, 0.8138, 0.0), (0.5, 0.0, 0.0), (0.2965, 0.7035, 0.6667)], spacegroup=180, #P6(2)22 #RCSR incorrect? eta_c4 = crystal(['C', 'N' , 'F'], [(0.4069, 0.8138, 0.0), (0.5, 0.0, 0.0), (0.7035, 0.4070, 0.5)], spacegroup=180, #P6(2)22 cellpar=[a, a, b, 90, 90, 120]) #write('test.xyz',eta_c4) write('test.cif',eta_c4) eps = 0.9 model_molecule={} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding cov_rad=[] for atom in eta_c4: #cov_rad.append(covalent_radii[atom.number]) cov_rad.append(factor / 4) print cov_rad nlist = NeighborList(cov_rad,skin=3.0,self_interaction=False,bothways=True) nlist.build(eta_c4) #To sort out tags, we need to label each bond nbond = 1 bond_matrix = np.zeros( (len(eta_c4),len(eta_c4)) ) pbc_bond_matrix = np.zeros( (len(eta_c4),len(eta_c4)) ) bond_dict = {} #Something funky, missing bonds, #for atom in eta_c4: # print "---------------------Atom",atom.index,"--------------------" # for ind in range(len(eta_c4)): # print atom.index, ind, eta_c4.get_distance(atom.index,ind,mic=True), eta_c4.get_distance(atom.index,ind) for atom in eta_c4: print "---------------------" indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): print atom.index, index, atom.symbol, eta_c4[index].symbol, offset, eta_c4.get_distance(atom.index,index,mic=True) if atom.index <= index:# and eta_c4[index].symbol != 'F': #F require special treatment this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond #Now we need to find the same bond the other direction to get the offsets right indices2,offsets2 = nlist.get_neighbors(index) for i2,o2 in zip(indices2,offsets2): if i2 == atom.index: #print "sum of offsets = ", offset, o2, sum(offset + o2) if sum(offset + o2) == 0: #same bond this_bond = [index, atom.index] for o in o2: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond nbond +=1 print "Bond dict:" print nbond for k,v in bond_dict.items(): print k,v print "End Bond dict:" #Now we want to delete C-F bonds that are not of length factor/2 for k,v in bond_dict.items(): i1,i2,o1,o2,o3 = k position1 = eta_c4.positions[i1] position2 = eta_c4.positions[i2] position2_mic = eta_c4.positions[i2] + np.dot([o1,o2,o3], eta_c4.get_cell()) this_dist = np.linalg.norm(position1 - position2) this_dist_mic = np.linalg.norm(position1 - position2_mic) print i1,i2, this_dist, this_dist_mic, (this_dist - factor/2), this_dist_mic - factor/2 if abs(this_dist - factor/2) > eps and all(o == 0 for o in [o1,o2,o3]): print "deleting", k del bond_dict[k] elif abs(this_dist_mic - factor/2) > eps and any(o != 0 for o in [o1,o2,o3]) : print "deleting", k del bond_dict[k] #print "New Bond dict:" #print len(bond_dict) #for k,v in sorted(bond_dict.items()): # i1,i2,o1,o2,o3 = k # position1 = eta_c4.positions[i1] # position2 = eta_c4.positions[i2] # position2_mic = eta_c4.positions[i2] + np.dot([o1,o2,o3], eta_c4.get_cell()) # this_dist = np.linalg.norm(position1 - position2) # this_dist_mic = np.linalg.norm(position1 - position2_mic) # print k,v, this_dist,this_dist_mic #print "End New Bond dict:" #Start with C (triangles) for atom in eta_c4: if atom.symbol == 'C': print'=======================================' print 'C Atom ',atom.index n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'F' indices, offsets = nlist.get_neighbors(atom.index) #Just checking the symbols here print indices print offsets symbols = ([eta_c4[index].symbol for index in indices]) symbol_string = ''.join(sorted([eta_c4[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index,offset in zip(indices,offsets): print atom.index, index, offset this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #print bond_dict[bond] print abs(eta_c4.get_distance(atom.index,index,mic=True)), abs(eta_c4.get_distance(atom.index,index,mic=True) - factor) #if eta_c4[index].symbol == 'N' and abs(eta_c4.get_distance(atom.index,index,mic=True) - factor) < eps: #necessary check, because some atoms are closer than unit distance: if bond in bond_dict: if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj].positions[-1] = eta_c4.positions[index] + np.dot(offset, eta_c4.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[-1] = eta_c4.positions[index] + np.dot(offset, eta_c4.get_cell()) n_centers = n_obj # # ##Now we do the N (edges) for atom in eta_c4: if atom.symbol == 'N' or atom.symbol =='F': #print'=======================================' #print 'N Atom ',atom.index, " finding edges" n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): print index, offset, eta_c4[index].symbol this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #if not bond_dict.has_key(bond): #Then #if eta_c4[index].symbol == 'C' and abs(eta_c4.get_distance(atom.index,index,mic=True) - factor) < eps: #necessary check, because some atoms are closer than unit distance: if bond in bond_dict: if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj].positions[-1] = eta_c4.positions[index] + np.dot(offset, eta_c4.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[-1] = eta_c4.positions[index] + np.dot(offset, eta_c4.get_cell()) # # # f = open('eta_c4.model','w') g = open('control-mofgen.txt','w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' %('Number of objects =',n_obj+1)) f.write('%-20s\n' %('build = systre')) f.write('%5s\n' %('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (eta_c4.get_cell()[0][0], eta_c4.get_cell()[0][1], eta_c4.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (eta_c4.get_cell()[1][0], eta_c4.get_cell()[1][1], eta_c4.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (eta_c4.get_cell()[2][0], eta_c4.get_cell()[2][1], eta_c4.get_cell()[2][2])) g.write('%-20s\n' %('model = eta_c4')) #Now write stuff for obj in xrange(n_centers+1): f.write('\n%-8s %-3d\n' %('Center: ', obj+1)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = triangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('center =', names[0])) for obj in xrange(n_centers+1,n_obj+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = linear')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('linker =', names[1]))
"""Test the ase.utils.geometry module""" import numpy as np from ase.lattice.spacegroup import crystal from ase.utils.geometry import get_layers, cut, stack from ase.atoms import Atoms np.set_printoptions(suppress=True) al = crystal("Al", [(0, 0, 0)], spacegroup=225, cellpar=4.05) # Cut out slab of 5 Al(001) layers al001 = cut(al, nlayers=5) correct_pos = np.array( [ [0.0, 0.0, 0.0], [0.0, 0.5, 0.2], [0.5, 0.0, 0.2], [0.5, 0.5, 0.0], [0.0, 0.0, 0.4], [0.0, 0.5, 0.6], [0.5, 0.0, 0.6], [0.5, 0.5, 0.4], [0.0, 0.0, 0.8], [0.5, 0.5, 0.8], ] ) assert np.allclose(correct_pos, al001.get_scaled_positions())
#Test 2 - Test in all 3 dimensions ssize=[2,2,2] fsize=[4,4,4] psize=[1,1,1] defectstructure = BCC('Fe', size = ssize) primordialstructure = BCC('Fe', size = psize) f = BCC('Fe', size = fsize) write('POSCAR_defect2',defectstructure) write('POSCAR_prim2',primordialstructure) final = finite_size_scale('POSCAR_defect2', ssize, 'POSCAR_prim2', fsize, psize) write(fil,f,'xyz') write(fil,final,'xyz') fil.flush() #Test 3 - Test for not cubic lattice from ase.lattice.spacegroup import crystal a = 3.21 c = 5.21 mg = crystal('Mg', [(1./3., 2./3., 3./4.)], spacegroup=194,cellpar=[a, a, c, 90, 90, 120]) defectstructure = mg.repeat(ssize) primordialstructure = mg.repeat(psize) f = mg.repeat(fsize) write('POSCAR_defect3',defectstructure) write('POSCAR_prim3',primordialstructure) final = finite_size_scale('POSCAR_defect3', ssize, 'POSCAR_prim3', fsize, psize) write(fil,f,'xyz') write(fil,final,'xyz') fil.flush() fil.close()
import numpy as np from ase.lattice.spacegroup import crystal # A diamond unit cell diamond = crystal('C', [(0,0,0)], spacegroup=227, cellpar=[3.57, 3.57, 3.57, 90, 90, 90]) assert len(diamond) == 8 correct_pos = np.array([[ 0. , 0. , 0. ], [ 0. , 0.5 , 0.5 ], [ 0.5 , 0.5 , 0. ], [ 0.5 , 0. , 0.5 ], [ 0.75, 0.25, 0.75], [ 0.25, 0.25, 0.25], [ 0.25, 0.75, 0.75], [ 0.75, 0.75, 0.25]]) assert np.allclose(diamond.get_scaled_positions(), correct_pos) # A CoSb3 skutterudite unit cell containing 32 atoms skutterudite = crystal(('Co', 'Sb'), basis=[(0.25,0.25,0.25), (0.0, 0.335, 0.158)], spacegroup=204, cellpar=[9.04, 9.04, 9.04, 90, 90, 90]) assert len(skutterudite) == 32 correct_pos = np.array([[ 0.25 , 0.25 , 0.25 ], [ 0.75 , 0.75 , 0.25 ],
def make_mil53(names,sizes): #work out the expansion factor factor = sizes[1] #linker is the only thing that matters #sum(sizes) #print sizes[0] a = 6.6085 #We'll form the bondlist and then enlarge the cell. b = 16.0 #16.675 c = 12.0 #12.813 #These cell dimensions are rigged to a linker length of 5 (circa size of benzene) # Al -> centre of mil53, N -> centre of rectangle linker , C -> dummies mil53 = crystal(['Al', 'N', 'C'], [(0.25, 0.25, 0.25), (0.5, 0.0, 0.5), (0.5, 0.1292, 0.383 )], spacegroup=74, #Imma cellpar=[a, b, c, 90, 90, 90]) write('test.xyz',mil53) eps = 0.05 model_molecule={} n_obj = -1 #initialise to -1 such that it can be indexed at start of add #First detect global bonding cov_rad=[] for atom in mil53: if atom.symbol == 'Al': cov_rad.append(covalent_radii[atom.number]*2) #Rigged to suck in C, but not N elif atom.symbol == 'N': cov_rad.append(covalent_radii[atom.number]*3) #Rigged to suck in C, but not Al else: cov_rad.append(covalent_radii[atom.number]) #print cov_rad nlist = NeighborList(cov_rad,skin=0.1,self_interaction=False,bothways=True) nlist.build(mil53) #Now we exapnd the cell. The factor given is half the hypotenuse of a right triangle with angle 35 deg print "factor = " , factor print b,c a = 2* sizes[0] b = b + (2*factor * sin(35*pi/180.0)) c = c + (2*factor * cos(35*pi/180.0)) print b,c # Al -> centre of mil53, N -> centre of rectangle linker , C -> dummies mil53 = crystal(['Al', 'N', 'C'], [(0.25, 0.25, 0.25), (0.5, 0.0, 0.5), (0.5, 0.1292, 0.383 )], spacegroup=74, #Imma cellpar=[a, b, c, 90, 90, 90]) #a (height) is fixed #To sort out tags, we need to label each bond nbond = 1 #Now in this case, the C atoms directly represent our dummy atoms, so we number them for atom in mil53: if atom.symbol == 'C': atom.tag = nbond nbond += 1 #Al also need to be tagged to each other for atom in mil53: if atom.symbol == 'Al': indices, offsets = nlist.get_neighbors(atom.index) #symbol_string = ''.join(sorted([mil53[index].symbol for index in indices])) #print symbol_string for index,offset in zip(indices,offsets): if mil53[index].symbol == 'Al' and all(o == 0 for o in offset) and index > atom.index: #interesting because it the same bond is both internal and pbc #print "atom ", atom.index, " and atom ",index, " are bonded, non-pbc ", nbond atom.tag = nbond mil53[index].tag = nbond nbond += 1 #Now we loop over the N, just to find which carbons go over PBC for atom in mil53: if atom.symbol == 'N': indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): #Should only be C if mil53[index].symbol == 'C': if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag mil53[index].tag = -mil53[index].tag #print mil53.get_tags() used_carbon = [] #Now we build the model #Start with Al for atom in mil53: if atom.symbol == 'Al': #print'=======================================' #print 'Al Atom ',atom.index indices, offsets = nlist.get_neighbors(atom.index) C_count = 0 for index,offset in zip(indices,offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all(o == 0 for o in offset): # and mil53[index].tag not in model_molecule[n_obj].get_tags(): C_count += 1 #print "Al atom, ", atom.index, "has c-count in this cell", C_count if C_count == 2: n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom for index,offset in zip(indices,offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all(o == 0 for o in offset): # and mil53[index].tag not in model_molecule[n_obj].get_tags(): model_molecule[n_obj] += mil53[index] model_molecule[n_obj][-1].tag = mil53[index].tag model_molecule[n_obj].positions[-1] = mil53.positions[index] + np.dot(offset, mil53.get_cell()) used_carbon.append(index) #We need to put the other Al as an anchor for index,offset in zip(indices,offsets): if mil53[index].symbol =='Al' and all(o == 0 for o in offset): model_molecule[n_obj] += mil53[index] #model_molecule[n_obj][-1].tag = None #No tag model_molecule[n_obj].positions[-1] = mil53.positions[index] + np.dot(offset, mil53.get_cell()) #That gives us two Al centres, now the other two #These are the two that have 4 in-cell C for atom in mil53: if atom.symbol == 'Al': #print'=======================================' #print 'Al Atom ',atom.index indices, offsets = nlist.get_neighbors(atom.index) C_count = 0 for index,offset in zip(indices,offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all(o == 0 for o in offset): # and mil53[index].tag not in model_molecule[n_obj].get_tags(): C_count += 1 #print "Al atom, ", atom.index, "has c-count in this cell", C_count if C_count == 4: n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom for index,offset in zip(indices,offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all(o == 0 for o in offset) and index not in used_carbon: model_molecule[n_obj] += mil53[index] model_molecule[n_obj][-1].tag = mil53[index].tag model_molecule[n_obj].positions[-1] = mil53.positions[index] + np.dot(offset, mil53.get_cell()) #We need to put the other Al as an anchor for index,offset in zip(indices,offsets): if mil53[index].symbol =='Al' and any(o != 0 for o in offset): model_molecule[n_obj] += mil53[index] #model_molecule[n_obj][-1].tag = None #No tag model_molecule[n_obj].positions[-1] = mil53.positions[index] + np.dot(offset, mil53.get_cell()) # #We need to interrogate our C further as two of them belong to both Al in the same cell # C_indices,C_offsets = nlist.get_neighbors(index) # symbol_string = ''.join(sorted([mil53[index].symbol for index in C_indices])) # print symbol_string # # model_molecule[n_obj] += mil53[index] # model_molecule[n_obj][-1].tag = mil53[index].tag # model_molecule[n_obj].positions[-1] = mil53.positions[index] + np.dot(offset, mil53.get_cell()) n_centers = n_obj # # ##Now we do the N (linear) for atom in mil53: if atom.symbol == 'N': #print'=======================================' #print 'N Atom ',atom.index, " finding squares1" n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): #Should only be C if mil53[index].symbol == 'C': model_molecule[n_obj] += mil53[index] model_molecule[n_obj][-1].tag = mil53[index].tag model_molecule[n_obj].positions[-1] = mil53.positions[index] + np.dot(offset, mil53.get_cell()) # # # f = open('mil53.model','w') g = open('control-mofgen.txt','w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it test_mol = Atoms() for obj in model_molecule: test_mol += model_molecule[obj] #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' %('Number of objects =',n_obj+1)) f.write('%-20s\n' %('build = systre')) f.write('%-13s\n' %('ExtraDummies')) f.write('%5s\n' %('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (mil53.get_cell()[0][0], mil53.get_cell()[0][1], mil53.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (mil53.get_cell()[1][0], mil53.get_cell()[1][1], mil53.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (mil53.get_cell()[2][0], mil53.get_cell()[2][1], mil53.get_cell()[2][2])) g.write('%-20s\n' %('model = mil53')) # Print the centers and linkers for obj in xrange(n_centers+1): f.write('\n%-8s %-3d\n' %('Center: ', obj+1)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = mil53')) #process positions to make it a bit more ideal #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(atom.index,0,2.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.symbol == 'C': #can't use tags as a marker here, because we've given a tag to 'Q' as well f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) elif atom.symbol == 'Al': f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('Q', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('center =', names[0])) for obj in xrange(n_centers+1,n_obj+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = linear')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('linker =', names[1])) # # test_mol = Atoms() for obj in model_molecule: test_mol += model_molecule[obj] write('test_model2.xyz',test_mol)
def tags2atoms(tags, **kwargs): """Returns an Atoms object from a cif tags dictionary.""" a = tags['_cell_length_a'] b = tags['_cell_length_b'] c = tags['_cell_length_c'] alpha = tags['_cell_angle_alpha'] beta = tags['_cell_angle_beta'] gamma = tags['_cell_angle_gamma'] scaled_positions = np.array([ tags['_atom_site_fract_x'], tags['_atom_site_fract_y'], tags['_atom_site_fract_z'] ]).T symbols = [] if '_atom_site_type_symbol' in tags: labels = tags['_atom_site_type_symbol'] else: labels = tags['_atom_site_label'] for s in labels: # Strip off additional labeling on chemical symbols m = re.search(r'([A-Z][a-z]?)', s) symbol = m.group(0) symbols.append(symbol) # Symmetry specification, see # http://www.iucr.org/resources/cif/dictionaries/cif_sym for a # complete list of official keys. In addition we also try to # support some commonly used depricated notations no = None if '_space_group.IT_number' in tags: no = tags['_space_group.IT_number'] elif '_symmetry_int_tables_number' in tags: no = tags['_symmetry_int_tables_number'] symbolHM = None if '_space_group.Patterson_name_H-M' in tags: symbolHM = tags['_space_group.Patterson_name_H-M'] elif '_symmetry_space_group_name_H-M' in tags: symbolsHM = tags['_symmetry_space_group_name_H-M'] sitesym = None if '_space_group_symop.operation_xyz' in tags: sitesym = tags['_space_group_symop.operation_xyz'] elif '_symmetry_equiv_pos_as_xyz' in tags: sitesym = tags['_symmetry_equiv_pos_as_xyz'] spacegroup = 1 if sitesym is not None: spacegroup = spacegroup_from_data(no=no, symbol=symbolHM, sitesym=sitesym) elif no is not None: spacegroup = no elif symbolHM is not None: spacegroup = symbolHM else: spacegroup = 1 atoms = crystal(symbols, basis=scaled_positions, cellpar=[a, b, c, alpha, beta, gamma], spacegroup=spacegroup, **kwargs) return atoms
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)
#!/usr/bin/env python from ase import io from ase.lattice import bulk from ase.lattice.surface import surface from ase.io.trajectory import Trajectory from ase.lattice.spacegroup import crystal from ase.optimize import QuasiNewton import numpy as np from ase.io.trajectory import PickleTrajectory from ase.build import cut #import cut a = 8.171 Bulk = crystal(('Mg', 'Al', 'O'), basis=[(0, 0, 0), (0.625, 0.625, 0.625), (0.375, 0.375, 0.375)], spacegroup=227, cellpar=[a, a, a, 90, 90, 90]) Bulk.set_initial_magnetic_moments([0.0 for atom in Bulk]) #atoms = Bulk.repeat((2,2,2)) #atoms.rattle(stdev=0.001, seed=42) io.write('1_1_1.traj', Bulk) #al111 = surface(Bulk, (1,1,1),4, vacuum = 7.5) #al111 = cut(Bulk,(1,0,0),(0,1,0),(0,0,1),nlayers=3) #io.write('surface_111.traj',al111)
from ase.lattice.spacegroup import crystal # FCC aluminum a = 4.05 al = crystal('Al', [(0, 0, 0)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) print(al)
def make_sqp_B2(names, sizes): #ax110628-sr (ax110826.cif) personal communication from Prof. Dr. Jens Beckmann a = 10.9770 b = 18.569 c = 21.098 alpha = 79.640 beta = 76.060 gamma = 85.670 # P => central Si # Si => peripheral Si, actually using carbons from the original cif # N => centre of 4 Si/O # C => peripheral Si sqp_B2 = crystal( ['P', 'Si', 'Si', 'Si', 'Si', 'N', 'C', 'C', 'C', 'C'], [(0.65363, 0.82095, 0.14843), (0.4953, 0.8025, 0.2043), (0.7693, 0.7437, 0.1638), (0.7189, 0.9026, 0.1681), (0.6395, 0.8366, 0.0605), (0.240400, 0.263825, 0.376473), (-0.26884, 0.7000, 0.46936), (1.37428, 0.43072, 0.28200), (0.99881, 1.28479, 0.29492), (0.66767, 0.91355, -0.37629)], spacegroup=2, #P-1 cellpar=[a, b, c, alpha, beta, gamma]) write('test.xyz', sqp_B2) write('test.cif', sqp_B2) eps = 0.10 model_molecule = {} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 # First detect global bonding # N-C distance is 3.5A cov_rad = [] for atom in sqp_B2: if atom.symbol == 'P': cov_rad.append(covalent_radii[atom.number]) elif atom.symbol == 'Si': cov_rad.append(covalent_radii[atom.number]) elif atom.symbol == 'N': cov_rad.append(2.0) elif atom.symbol == 'C': cov_rad.append(2.0) nlist = NeighborList(cov_rad, skin=0.01, self_interaction=False, bothways=True) nlist.build(sqp_B2) #To sort out tags, we need to label each bond, we get a bunch of extra bonds here that we need to filter out bond_matrix = np.zeros((len(sqp_B2), len(sqp_B2)), dtype=bool) for atom in sqp_B2: indices, offsets = nlist.get_neighbors(atom.index) if atom.symbol == 'P': #Here we go, suck in all Si for index, offset in zip(indices, offsets): if sqp_B2[ index].symbol == 'Si': # and sqp_B2.get_distance(atom.index,index,mic=True) >10.0: print "Atom ", atom.index, atom.symbol, " bonded to atom ", index, sqp_B2[ index].symbol, " distance = ", sqp_B2.get_distance( atom.index, index, mic=True), "offset = ", offset bond_matrix[index, atom.index] = True bond_matrix[atom.index, index] = True if atom.symbol == 'N': #Here we go, suck in all Si for index, offset in zip(indices, offsets): if sqp_B2[ index].symbol == 'C': #and sqp_B2.get_distance(atom.index,index,mic=True) >10.0: print "Atom ", atom.index, atom.symbol, " bonded to atom ", index, sqp_B2[ index].symbol, " distance = ", sqp_B2.get_distance( atom.index, index, mic=True), "offset = ", offset bond_matrix[index, atom.index] = True bond_matrix[atom.index, index] = True #Now we have a dirty trick, expand all the P-Si4 tetrahedra and find Si-C bonds for atom in sqp_B2: if atom.symbol == 'P': print '=======================================' print 'P Atom ', atom.index indices, offsets = nlist.get_neighbors(atom.index) #print offsets #for i,o in zip(indices, offsets): # print i,o for index, offset in zip(indices, offsets): sqp_B2.set_distance(index, atom.index, 10.0, fix=1) write('test2.xyz', sqp_B2) write('test2.cif', sqp_B2) nlist_CSi = NeighborList(cov_rad, skin=0.01, self_interaction=False, bothways=True) nlist_CSi.build(sqp_B2) print "Here" nbond = 1 for atom in sqp_B2: indices, offsets = nlist_CSi.get_neighbors(atom.index) if atom.symbol == 'C': #Here we go, suck in all Si for index, offset in zip(indices, offsets): print "Atom ", atom.index, atom.symbol, " bonded to atom ", index, sqp_B2[ index].symbol, " distance = ", sqp_B2.get_distance( atom.index, index, mic=True), "offset = ", offset if sqp_B2[ index].symbol == 'Si': # and sqp_B2.get_distance(atom.index,index,mic=True) >10.0: print "Adding bond" bond_matrix[index, atom.index] = True bond_matrix[atom.index, index] = True atom.tag = -nbond sqp_B2[index].tag = -nbond nbond += 1 tags = sqp_B2.get_tags() print tags #Now build scaled model #base size factor = sum(sizes) #(sizes[0] + sizes[2])/2.0 print "factor = ", factor orig_a = a scale = factor / orig_a b = b * scale c = c * scale # P => central Si # Si => peripheral Si, actually using carbons from the original cif # N => centre of 4 Si/O # C => peripheral Si sqp_B2 = crystal( ['P', 'Si', 'Si', 'Si', 'Si', 'N', 'C', 'C', 'C', 'C'], [(0.65363, 0.82095, 0.14843), (0.4953, 0.8025, 0.2043), (0.7693, 0.7437, 0.1638), (0.7189, 0.9026, 0.1681), (0.6395, 0.8366, 0.0605), (0.240400, 0.263825, 0.376473), (-0.26884, 0.7000, 0.46936), (1.37428, 0.43072, 0.28200), (0.99881, 1.28479, 0.29492), (0.66767, 0.91355, -0.37629)], spacegroup=2, #P-1 cellpar=[a, b, c, alpha, beta, gamma]) sqp_B2.set_tags(tags) n_obj = -1 #re-initialise to -1 such that it can be indexed at start of add #Now we start assembling the model #We have only tetrahedra for atom in sqp_B2: if atom.symbol == 'P': print '=======================================' print 'P Atom ', atom.index n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'P' indices, offsets = nlist.get_neighbors(atom.index) #print offsets symbols = ([sqp_B2[index].symbol for index in indices]) symbol_string = ''.join( sorted([sqp_B2[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index, offset in zip(indices, offsets): if bond_matrix[index, atom.index]: model_molecule[n_obj] += sqp_B2[index] model_molecule[n_obj].positions[ -1] = sqp_B2.positions[index] + np.dot( offset, sqp_B2.get_cell()) model_molecule[n_obj][-1].tag = sqp_B2[index].tag print sqp_B2[index].symbol, sqp_B2[index].position, sqp_B2[ index].tag print sqp_B2[index].index, sqp_B2[index].symbol, sqp_B2[ index].position, sqp_B2[index].tag n_centers = n_obj # H-bond "square pyramids" are actually tetrahedra wrt centre of mass for atom in sqp_B2: if atom.symbol == 'N': print '=======================================' print 'N Atom ', atom.index n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'N' indices, offsets = nlist.get_neighbors(atom.index) #print offsets symbols = ([sqp_B2[index].symbol for index in indices]) symbol_string = ''.join( sorted([sqp_B2[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index, offset in zip(indices, offsets): if bond_matrix[index, atom.index]: model_molecule[n_obj] += sqp_B2[index] model_molecule[n_obj].positions[ -1] = sqp_B2.positions[index] + np.dot( offset, sqp_B2.get_cell()) model_molecule[n_obj][-1].tag = sqp_B2[index].tag print sqp_B2[index].symbol, sqp_B2[index].position, sqp_B2[ index].tag print sqp_B2[index].index, sqp_B2[index].symbol, sqp_B2[ index].position, sqp_B2[index].tag f = open('sqp_B2.model', 'w') g = open('control-mofgen.txt', 'w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] # #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' % ('Number of objects =', n_obj + 1)) f.write('%-20s\n' % ('build = systre')) f.write('%5s\n' % ('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (sqp_B2.get_cell()[0][0], sqp_B2.get_cell()[0][1], sqp_B2.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (sqp_B2.get_cell()[1][0], sqp_B2.get_cell()[1][1], sqp_B2.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (sqp_B2.get_cell()[2][0], sqp_B2.get_cell()[2][1], sqp_B2.get_cell()[2][2])) g.write('%-20s\n' % ('model = sqp_B2')) # for obj in xrange(n_centers + 1): f.write('\n%-8s %-3d\n' % ('Center: ', obj + 1)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = tetrahedral')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('center =', names[0])) for obj in xrange(n_centers + 1, n_obj + 1): f.write('\n%-8s %-3d\n' % ('Linker: ', obj - n_centers)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = tetrahedral')) #process positions to make it a bit more ideal #this_dist = model_molecule[obj].get_distance(0,1) #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(0,atom.index,this_dist+1.0,fix=0) #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(0,atom.index,1.0,fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('linker =', names[1])) # # test_mol = Atoms() for obj in model_molecule: #for obj in xrange(n_centers+1):#,n_obj+1): #triangles only test_mol += model_molecule[obj] test_mol.set_cell(sqp_B2.get_cell()) test_mol.set_pbc(sqp_B2.get_pbc()) write('test_model2.xyz', test_mol) write('test_model2.cif', test_mol)
#!/Users/michalplucinski/Virtualenvs/ase-3.6.0.2515/bin/python from ase.lattice.spacegroup import crystal a = 5.431 diamond = crystal('C', [(0,0,0)], spacegroup=227, cellpar=[a, a, a, 90, 90, 90]) print diamond.positions
def make_sqp_B2(names,sizes): #ax110628-sr (ax110826.cif) personal communication from Prof. Dr. Jens Beckmann a = 10.9770 b = 18.569 c = 21.098 alpha = 79.640 beta = 76.060 gamma = 85.670 # P => central Si # Si => peripheral Si, actually using carbons from the original cif # N => centre of 4 Si/O # C => peripheral Si sqp_B2 = crystal(['P', 'Si', 'Si', 'Si', 'Si', 'N', 'C', 'C', 'C', 'C'], [(0.65363, 0.82095, 0.14843), (0.4953, 0.8025, 0.2043), (0.7693, 0.7437, 0.1638), (0.7189, 0.9026, 0.1681), (0.6395, 0.8366, 0.0605), (0.240400, 0.263825, 0.376473), (-0.26884, 0.7000, 0.46936), (1.37428, 0.43072, 0.28200), (0.99881, 1.28479, 0.29492), (0.66767, 0.91355, -0.37629)], spacegroup=2, #P-1 cellpar=[a, b, c, alpha, beta, gamma]) write('test.xyz',sqp_B2) write('test.cif',sqp_B2) eps = 0.10 model_molecule={} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 # First detect global bonding # N-C distance is 3.5A cov_rad=[] for atom in sqp_B2: if atom.symbol == 'P': cov_rad.append(covalent_radii[atom.number]) elif atom.symbol == 'Si': cov_rad.append(covalent_radii[atom.number]) elif atom.symbol == 'N': cov_rad.append(2.0) elif atom.symbol == 'C': cov_rad.append(2.0) nlist = NeighborList(cov_rad,skin=0.01,self_interaction=False,bothways=True) nlist.build(sqp_B2) #To sort out tags, we need to label each bond, we get a bunch of extra bonds here that we need to filter out bond_matrix = np.zeros( (len(sqp_B2),len(sqp_B2)) , dtype=bool) for atom in sqp_B2: indices, offsets = nlist.get_neighbors(atom.index) if atom.symbol == 'P': #Here we go, suck in all Si for index,offset in zip(indices,offsets): if sqp_B2[index].symbol == 'Si':# and sqp_B2.get_distance(atom.index,index,mic=True) >10.0: print "Atom ",atom.index, atom.symbol, " bonded to atom ", index, sqp_B2[index].symbol, " distance = ", sqp_B2.get_distance(atom.index,index,mic=True), "offset = ", offset bond_matrix[index,atom.index] = True bond_matrix[atom.index,index] = True if atom.symbol == 'N': #Here we go, suck in all Si for index,offset in zip(indices,offsets): if sqp_B2[index].symbol == 'C': #and sqp_B2.get_distance(atom.index,index,mic=True) >10.0: print "Atom ",atom.index, atom.symbol, " bonded to atom ", index, sqp_B2[index].symbol, " distance = ", sqp_B2.get_distance(atom.index,index,mic=True), "offset = ", offset bond_matrix[index,atom.index] = True bond_matrix[atom.index,index] = True #Now we have a dirty trick, expand all the P-Si4 tetrahedra and find Si-C bonds for atom in sqp_B2: if atom.symbol == 'P': print'=======================================' print 'P Atom ',atom.index indices, offsets = nlist.get_neighbors(atom.index) #print offsets #for i,o in zip(indices, offsets): # print i,o for index,offset in zip(indices,offsets): sqp_B2.set_distance(index,atom.index,10.0,fix=1) write('test2.xyz',sqp_B2) write('test2.cif',sqp_B2) nlist_CSi = NeighborList(cov_rad,skin=0.01,self_interaction=False,bothways=True) nlist_CSi.build(sqp_B2) print "Here" nbond = 1 for atom in sqp_B2: indices, offsets = nlist_CSi.get_neighbors(atom.index) if atom.symbol == 'C': #Here we go, suck in all Si for index,offset in zip(indices,offsets): print "Atom ",atom.index, atom.symbol, " bonded to atom ", index, sqp_B2[index].symbol, " distance = ", sqp_B2.get_distance(atom.index,index,mic=True), "offset = ", offset if sqp_B2[index].symbol == 'Si':# and sqp_B2.get_distance(atom.index,index,mic=True) >10.0: print "Adding bond" bond_matrix[index,atom.index] = True bond_matrix[atom.index,index] = True atom.tag = -nbond sqp_B2[index].tag = -nbond nbond += 1 tags = sqp_B2.get_tags() print tags #Now build scaled model #base size factor = sum(sizes) #(sizes[0] + sizes[2])/2.0 print "factor = ",factor orig_a = a scale = factor/orig_a b = b * scale c = c * scale # P => central Si # Si => peripheral Si, actually using carbons from the original cif # N => centre of 4 Si/O # C => peripheral Si sqp_B2 = crystal(['P', 'Si', 'Si', 'Si', 'Si', 'N', 'C', 'C', 'C', 'C'], [(0.65363, 0.82095, 0.14843), (0.4953, 0.8025, 0.2043), (0.7693, 0.7437, 0.1638), (0.7189, 0.9026, 0.1681), (0.6395, 0.8366, 0.0605), (0.240400, 0.263825, 0.376473), (-0.26884, 0.7000, 0.46936), (1.37428, 0.43072, 0.28200), (0.99881, 1.28479, 0.29492), (0.66767, 0.91355, -0.37629)], spacegroup=2, #P-1 cellpar=[a, b, c, alpha, beta, gamma]) sqp_B2.set_tags(tags) n_obj = -1 #re-initialise to -1 such that it can be indexed at start of add #Now we start assembling the model #We have only tetrahedra for atom in sqp_B2: if atom.symbol == 'P': print'=======================================' print 'P Atom ',atom.index n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'P' indices, offsets = nlist.get_neighbors(atom.index) #print offsets symbols = ([sqp_B2[index].symbol for index in indices]) symbol_string = ''.join(sorted([sqp_B2[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index,offset in zip(indices,offsets): if bond_matrix[index,atom.index]: model_molecule[n_obj] += sqp_B2[index] model_molecule[n_obj].positions[-1] = sqp_B2.positions[index] + np.dot(offset, sqp_B2.get_cell()) model_molecule[n_obj][-1].tag = sqp_B2[index].tag print sqp_B2[index].symbol, sqp_B2[index].position, sqp_B2[index].tag print sqp_B2[index].index, sqp_B2[index].symbol, sqp_B2[index].position, sqp_B2[index].tag n_centers = n_obj # H-bond "square pyramids" are actually tetrahedra wrt centre of mass for atom in sqp_B2: if atom.symbol == 'N': print'=======================================' print 'N Atom ',atom.index n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'N' indices, offsets = nlist.get_neighbors(atom.index) #print offsets symbols = ([sqp_B2[index].symbol for index in indices]) symbol_string = ''.join(sorted([sqp_B2[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index,offset in zip(indices,offsets): if bond_matrix[index,atom.index]: model_molecule[n_obj] += sqp_B2[index] model_molecule[n_obj].positions[-1] = sqp_B2.positions[index] + np.dot(offset, sqp_B2.get_cell()) model_molecule[n_obj][-1].tag = sqp_B2[index].tag print sqp_B2[index].symbol, sqp_B2[index].position, sqp_B2[index].tag print sqp_B2[index].index, sqp_B2[index].symbol, sqp_B2[index].position, sqp_B2[index].tag f = open('sqp_B2.model','w') g = open('control-mofgen.txt','w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] # #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' %('Number of objects =',n_obj+1)) f.write('%-20s\n' %('build = systre')) f.write('%5s\n' %('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (sqp_B2.get_cell()[0][0], sqp_B2.get_cell()[0][1], sqp_B2.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (sqp_B2.get_cell()[1][0], sqp_B2.get_cell()[1][1], sqp_B2.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (sqp_B2.get_cell()[2][0], sqp_B2.get_cell()[2][1], sqp_B2.get_cell()[2][2])) g.write('%-20s\n' %('model = sqp_B2')) # for obj in xrange(n_centers+1): f.write('\n%-8s %-3d\n' %('Center: ', obj+1)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = tetrahedral')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('center =', names[0])) for obj in xrange(n_centers+1,n_obj+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = tetrahedral')) #process positions to make it a bit more ideal #this_dist = model_molecule[obj].get_distance(0,1) #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(0,atom.index,this_dist+1.0,fix=0) #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(0,atom.index,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('linker =', names[1])) # # test_mol = Atoms() for obj in model_molecule: #for obj in xrange(n_centers+1):#,n_obj+1): #triangles only test_mol += model_molecule[obj] test_mol.set_cell(sqp_B2.get_cell()) test_mol.set_pbc(sqp_B2.get_pbc()) write('test_model2.xyz',test_mol) write('test_model2.cif',test_mol)
print(60 * '=') print(max(0, (60 - len(msg)) // 2 - 1) * ' ', msg) print(60 * '=') def secban(msg): print() print(max(0, (60 - len(msg)) // 2 - 1) * ' ', msg) print(60 * '-') banner('Structure optimization on MgO') a = 4.291 MgO = crystal(['Mg', 'O'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) ################################## # Provide your own calculator here ################################## calc = ClusterVasp(nodes=1, ppn=8) # The calculator must be runnable in an isolated directory # Without disturbing other running instances of the same calculator # They are run in separate processes (not threads!) MgO.set_calculator(calc) calc.set(prec='Accurate', xc='PBE', lreal=False, isif=2,
return [r for ns,s in enumerate(sysl) for nr,r in res if nr==ns] # Testing routines using VASP as a calculator in the cluster environment. # TODO: Make it calculator/environment agnostic if __name__ == '__main__': from ase.lattice.spacegroup import crystal from ase.units import GPa import elastic from elastic.parcalc import ParCalculate, ClusterVasp import numpy from pylab import * a = 4.291 MgO = crystal(['Mg', 'O'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) ################################## # Provide your own calculator here ################################## calc=ClusterVasp(nodes=1,ppn=8) # The calculator must be runnable in an isolated directory # Without disturbing other running instances of the same calculator # They are run in separate processes (not threads!) MgO.set_calculator(calc) calc.set(prec = 'Accurate', xc = 'PBE', lreal = False, isif=2, nsw=20, ibrion=2, kpts=[1,1,1]) print("Residual pressure: %.3f GPa" % (MgO.get_pressure()/GPa)) calc.clean()
def make_eta_c4(names, sizes): #work out the expansion factor #dist0 = furthest_dummy(mol0) #dist1 = furthest_dummy(mol1) factor = sum(sizes) #dist0 + dist1 factor = factor * 2 #factor = 3.0 print "factor = ", factor a = 3.1018 * factor b = 0.4373 * factor #b = 0.5466 * factor #RCSR value, incorrect? # C -> triangles, N => midpoints #eta_c4 = crystal(['C', 'N' , 'N'], [(0.4069, 0.8138, 0.0), (0.5, 0.0, 0.0), (0.2965, 0.7035, 0.6667)], spacegroup=180, #P6(2)22 #RCSR incorrect? eta_c4 = crystal( ['C', 'N', 'F'], [(0.4069, 0.8138, 0.0), (0.5, 0.0, 0.0), (0.7035, 0.4070, 0.5)], spacegroup=180, #P6(2)22 cellpar=[a, a, b, 90, 90, 120]) #write('test.xyz',eta_c4) write('test.cif', eta_c4) eps = 0.9 model_molecule = {} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding cov_rad = [] for atom in eta_c4: #cov_rad.append(covalent_radii[atom.number]) cov_rad.append(factor / 4) print cov_rad nlist = NeighborList(cov_rad, skin=3.0, self_interaction=False, bothways=True) nlist.build(eta_c4) #To sort out tags, we need to label each bond nbond = 1 bond_matrix = np.zeros((len(eta_c4), len(eta_c4))) pbc_bond_matrix = np.zeros((len(eta_c4), len(eta_c4))) bond_dict = {} #Something funky, missing bonds, #for atom in eta_c4: # print "---------------------Atom",atom.index,"--------------------" # for ind in range(len(eta_c4)): # print atom.index, ind, eta_c4.get_distance(atom.index,ind,mic=True), eta_c4.get_distance(atom.index,ind) for atom in eta_c4: print "---------------------" indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): print atom.index, index, atom.symbol, eta_c4[ index].symbol, offset, eta_c4.get_distance(atom.index, index, mic=True) if atom.index <= index: # and eta_c4[index].symbol != 'F': #F require special treatment this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond #Now we need to find the same bond the other direction to get the offsets right indices2, offsets2 = nlist.get_neighbors(index) for i2, o2 in zip(indices2, offsets2): if i2 == atom.index: #print "sum of offsets = ", offset, o2, sum(offset + o2) if sum(offset + o2) == 0: #same bond this_bond = [index, atom.index] for o in o2: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond nbond += 1 print "Bond dict:" print nbond for k, v in bond_dict.items(): print k, v print "End Bond dict:" #Now we want to delete C-F bonds that are not of length factor/2 for k, v in bond_dict.items(): i1, i2, o1, o2, o3 = k position1 = eta_c4.positions[i1] position2 = eta_c4.positions[i2] position2_mic = eta_c4.positions[i2] + np.dot([o1, o2, o3], eta_c4.get_cell()) this_dist = np.linalg.norm(position1 - position2) this_dist_mic = np.linalg.norm(position1 - position2_mic) print i1, i2, this_dist, this_dist_mic, ( this_dist - factor / 2), this_dist_mic - factor / 2 if abs(this_dist - factor / 2) > eps and all(o == 0 for o in [o1, o2, o3]): print "deleting", k del bond_dict[k] elif abs(this_dist_mic - factor / 2) > eps and any( o != 0 for o in [o1, o2, o3]): print "deleting", k del bond_dict[k] #print "New Bond dict:" #print len(bond_dict) #for k,v in sorted(bond_dict.items()): # i1,i2,o1,o2,o3 = k # position1 = eta_c4.positions[i1] # position2 = eta_c4.positions[i2] # position2_mic = eta_c4.positions[i2] + np.dot([o1,o2,o3], eta_c4.get_cell()) # this_dist = np.linalg.norm(position1 - position2) # this_dist_mic = np.linalg.norm(position1 - position2_mic) # print k,v, this_dist,this_dist_mic #print "End New Bond dict:" #Start with C (triangles) for atom in eta_c4: if atom.symbol == 'C': print '=======================================' print 'C Atom ', atom.index n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'F' indices, offsets = nlist.get_neighbors(atom.index) #Just checking the symbols here print indices print offsets symbols = ([eta_c4[index].symbol for index in indices]) symbol_string = ''.join( sorted([eta_c4[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index, offset in zip(indices, offsets): print atom.index, index, offset this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #print bond_dict[bond] print abs(eta_c4.get_distance( atom.index, index, mic=True)), abs( eta_c4.get_distance(atom.index, index, mic=True) - factor) #if eta_c4[index].symbol == 'N' and abs(eta_c4.get_distance(atom.index,index,mic=True) - factor) < eps: #necessary check, because some atoms are closer than unit distance: if bond in bond_dict: if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj].positions[ -1] = eta_c4.positions[index] + np.dot( offset, eta_c4.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[ -1] = eta_c4.positions[index] + np.dot( offset, eta_c4.get_cell()) n_centers = n_obj # # ##Now we do the N (edges) for atom in eta_c4: if atom.symbol == 'N' or atom.symbol == 'F': #print'=======================================' #print 'N Atom ',atom.index, " finding edges" n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): print index, offset, eta_c4[index].symbol this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #if not bond_dict.has_key(bond): #Then #if eta_c4[index].symbol == 'C' and abs(eta_c4.get_distance(atom.index,index,mic=True) - factor) < eps: #necessary check, because some atoms are closer than unit distance: if bond in bond_dict: if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj].positions[ -1] = eta_c4.positions[index] + np.dot( offset, eta_c4.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += eta_c4[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[ -1] = eta_c4.positions[index] + np.dot( offset, eta_c4.get_cell()) # # # f = open('eta_c4.model', 'w') g = open('control-mofgen.txt', 'w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' % ('Number of objects =', n_obj + 1)) f.write('%-20s\n' % ('build = systre')) f.write('%5s\n' % ('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (eta_c4.get_cell()[0][0], eta_c4.get_cell()[0][1], eta_c4.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (eta_c4.get_cell()[1][0], eta_c4.get_cell()[1][1], eta_c4.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (eta_c4.get_cell()[2][0], eta_c4.get_cell()[2][1], eta_c4.get_cell()[2][2])) g.write('%-20s\n' % ('model = eta_c4')) #Now write stuff for obj in xrange(n_centers + 1): f.write('\n%-8s %-3d\n' % ('Center: ', obj + 1)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = triangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('center =', names[0])) for obj in xrange(n_centers + 1, n_obj + 1): f.write('\n%-8s %-3d\n' % ('Linker: ', obj - n_centers)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = linear')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('linker =', names[1]))
alat3=alat2/2 from aiida.orm.data.array.kpoints import KpointsData kpoints = KpointsData() kpoints_mesh = 2 kpoints.set_kpoints_mesh([kpoints_mesh,kpoints_mesh,kpoints_mesh]) StructureData = DataFactory("structure") the_cell = [[alat/2,alat/2,0.],[alat/2,0.,alat/2],[0.,alat/2,alat/2]] structure = StructureData(cell=the_cell) structure.cell structure.append_atom(position=(alat/4.,alat/4.,alat/4.),symbols="Si") structure.sites from ase.lattice.spacegroup import crystal ase_structure = crystal('Si', [(0,0,0)], spacegroup=227, cellpar=[alat, alat, alat, 90, 90, 90],primitive_cell=True) structure=StructureData(ase=ase_structure) structure.store() nameCode='pw@local-seb' code=Code.get_from_string(nameCode) calc=code.new_calc() calc.label="PW test" calc.description="First calculus on BaTiO3" calc.set_resources({"num_machines": 1}) calc.set_max_wallclock_seconds(30*60) calc.use_structure(structure) calc.use_kpoints(kpoints)
def make_spn(names, sizes): #work out the expansion factor factor = sum(sizes) a = 4.8990 * factor # C -> triangles, N => octahedra spn = crystal(['C', 'N'], [(0.16667, 0.16667, 0.16667), (0.0, 0.0, 0.0)], spacegroup=227, setting=2, cellpar=[a, a, a, 90, 90, 90]) #write('test.xyz',spn) eps = 0.05 model_molecule = {} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding cov_rad = [] for atom in spn: #cov_rad.append(covalent_radii[atom.number]) cov_rad.append(factor / 2) print cov_rad nlist = NeighborList(cov_rad, skin=0.1, self_interaction=False, bothways=True) nlist.build(spn) #To sort out tags, we need to label each bond nbond = 1 bond_matrix = np.zeros((len(spn), len(spn))) pbc_bond_matrix = np.zeros((len(spn), len(spn))) bond_dict = {} for atom in spn: print "---------------------" indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): print atom.index, index, atom.symbol, spn[ index].symbol, offset, spn.get_distance(atom.index, index, mic=True) if atom.index < index: this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond #Now we need to find the same bond the other direction to get the offsets right indices2, offsets2 = nlist.get_neighbors(index) for i2, o2 in zip(indices2, offsets2): if i2 == atom.index: #print "sum of offsets = ", offset, o2, sum(offset + o2) if sum(offset + o2) == 0: #same bond this_bond = [index, atom.index] for o in o2: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond nbond += 1 print nbond for k, v in bond_dict.items(): print k, v #Now we look for all the things with unit*factor bondlengths #Start with N (octahedra) for atom in spn: if atom.symbol == 'N': print '=======================================' print 'N Atom ', atom.index n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'F' indices, offsets = nlist.get_neighbors(atom.index) #Just checking the symbols here print indices print offsets symbols = ([spn[index].symbol for index in indices]) symbol_string = ''.join( sorted([spn[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index, offset in zip(indices, offsets): print atom.index, index, offset this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond_dict[bond] if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += spn[index] model_molecule[n_obj].positions[ -1] = spn.positions[index] + np.dot( offset, spn.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += spn[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[ -1] = spn.positions[index] + np.dot( offset, spn.get_cell()) n_centers = n_obj # # ##Now we do the C (triangles) for atom in spn: if atom.symbol == 'C': #print'=======================================' #print 'N Atom ',atom.index, " finding squares1" n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): print index, offset, spn[index].symbol this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #if not bond_dict.has_key(bond): #Then if spn[index].symbol == 'N': if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += spn[index] model_molecule[n_obj].positions[ -1] = spn.positions[index] + np.dot( offset, spn.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += spn[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[ -1] = spn.positions[index] + np.dot( offset, spn.get_cell()) # # # f = open('spn.model', 'w') g = open('control-mofgen.txt', 'w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] # #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' % ('Number of objects =', n_obj + 1)) f.write('%-20s\n' % ('build = systre')) f.write('%5s\n' % ('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (spn.get_cell()[0][0], spn.get_cell()[0][1], spn.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (spn.get_cell()[1][0], spn.get_cell()[1][1], spn.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (spn.get_cell()[2][0], spn.get_cell()[2][1], spn.get_cell()[2][2])) g.write('%-20s\n' % ('model = spn')) # for obj in xrange(n_centers + 1): f.write('\n%-8s %-3d\n' % ('Center: ', obj + 1)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = octahedral_2')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('center =', names[0])) for obj in xrange(n_centers + 1, n_obj + 1): f.write('\n%-8s %-3d\n' % ('Linker: ', obj - n_centers)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = triangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('linker =', names[1]))
from ase.lattice.spacegroup import crystal from ase.calculators.emt import EMT from ase.optimize import QuasiNewton from ase.phonons import Phonons from ase.thermochemistry import CrystalThermo # Set up gold bulk and attach EMT calculator a = 4.078 atoms = crystal('Au', (0.,0.,0.), spacegroup = 225, cellpar = [a, a, a, 90, 90, 90], pbc = (1, 1, 1)) calc = EMT() atoms.set_calculator(calc) qn = QuasiNewton(atoms) qn.run(fmax = 0.05) electronicenergy = atoms.get_potential_energy() # Phonon analysis N = 5 ph = Phonons(atoms, calc, supercell=(N, N, N), delta=0.05) ph.run() ph.read(acoustic=True) phonon_energies, phonon_DOS = ph.dos(kpts=(40, 40, 40), npts=3000, delta=5e-4) # Calculate the Helmholtz free energy thermo = CrystalThermo(phonon_energies=phonon_energies, phonon_DOS = phonon_DOS, electronicenergy = electronicenergy, formula_units = 4)
from ase.lattice.spacegroup import crystal a = 3.21 c = 5.21 mg = crystal('Mg', [(1./3., 2./3., 3./4.)], spacegroup=194, cellpar=[a, a, c, 90, 90, 120])
Example of elastic tensor calculation using VASP calculator and elastic module. ''' from ase.lattice.spacegroup import crystal from parcalc import ClusterVasp, ParCalculate from elastic import Crystal import ase.units as units from numpy import array, linspace import matplotlib.pyplot as plt import numpy # Create the MgO crystal a = 4.194 cryst = Crystal(crystal(['Mg', 'O'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90])) # Create the calculator running on one, eight-core node. # This is specific to the setup on my cluster. # You have to adapt this part to your environment calc=ClusterVasp(nodes=1,ppn=8) # Assign the calculator to the crystal cryst.set_calculator(calc) # Set the calculation parameters calc.set(prec = 'Accurate', xc = 'PBE', lreal = False, nsw=30,
from ase.lattice.spacegroup import crystal a = 4.6 c = 2.95 rutile = crystal(['Ti', 'O'], basis=[(0, 0, 0), (0.3, 0.3, 0.0)], spacegroup=136, cellpar=[a, a, c, 90, 90, 90]) print rutile
from ase.lattice.spacegroup import crystal from gpaw import GPAW, PW a = 4.0351 # Experimental lattice constant in Angstrom Ecut = 250 # Energy cut off for PW calculation k = 5 # Number of kpoints per each direction # This gives the typical NaCl structure: LiF = crystal(['Li', 'F'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) calc = GPAW(mode=PW(Ecut), xc='LDA', kpts=(k, k, k), txt='LiF_out_gs.txt') LiF.set_calculator(calc) LiF.get_potential_energy() # With the full diagonalization we calculate all the single particle states # needed for the response calculation: calc.diagonalize_full_hamiltonian(nbands=100) calc.write('LiF_fulldiag.gpw', 'all')
def make_chs1(names, sizes): #CRYSTAL # NAME "UHM-7 - simplified - 12 - classiified as chs-1" # GROUP I4/mmm # CELL 4.14300 4.14300 4.66569 90.0000 90.0000 90.0000 # NODE 5 4 0.00000 0.26972 0.00000 # NODE 1 3 0.06146 0.28112 0.20686 # NODE 4 4 0.10690 0.10690 0.21827 # NODE 2 3 0.00000 0.19156 0.39361 # EDGE 0.06146 0.28112 0.20686 0.21888 0.43854 0.29314 # EDGE 0.00000 0.26972 0.00000 0.06146 0.28112 0.20686 # EDGE 0.00000 0.19156 0.39361 0.00000 0.19156 0.60639 # EDGE 0.00000 0.19156 0.39361 0.10690 0.10690 0.21827 # EDGE 0.10690 0.10690 0.21827 0.28112 -0.06146 0.20686 ## EDGE_CENTER 0.14017 0.35983 0.25000 ## EDGE_CENTER 0.03073 0.27542 0.10343 ## EDGE_CENTER 0.00000 0.19156 0.50000 ## EDGE_CENTER 0.05345 0.14923 0.30594 ## EDGE_CENTER 0.19401 0.02272 0.21257 #END # So the node numbering above sucks... # The edges go between (using the above numbering) # 1-1 # 5-1 # 2-2 # 2-4 # 4-1 # The same-same edges between triangles are where we need to dump the SiH2X2 units # Even though SiH2X2 is "linear" (two dummy atoms), in reality it is tetrahedral, and we need to orient it, three points on a line isn't enough # We'll use some H atoms to give the direction #So the cgd coordinates actually suck if you want ot build a framework... #work out the expansion factor #print "sizes =",sizes #factor = sizes[2]#/2.0 a = 28.7527 c = 35.4316 #uhm-7 crystal dimensions # Ne => centre of PW # C => corner of PW # N => triangles, first two corresponds to C1 linker, second one to Cs linker # Ca => corners of triangles (base end) i.e. adjacent to C_PW # F => SiH2X2 locations, (COM) # H => SiH2H2 dummies chs1 = crystal( [ 'Ne', 'Ne', 'N', 'N', 'N', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'F', 'F', 'H', 'H', 'H' ], [(0.451210, 0.820105, 0.5), (0.311875, 0.630620, 0.317373), (0.5465, 0.0705, 0.8418), (0.3923, 0.1906, 0.8322), (0.22825, 0.05125, 0.344895), (0.990100, 0.816000, 0.238990), (0.072300, 0.830500, 0.236450), (0.306260, 0.914300, 0.135060), (0.339440, 0.960790, 0.085750), (0.177400, 0.748400, 0.129220), (0.141300, 0.699100, 0.082930), (0.429660, 0.821690, 0.288870), (0.648970, 0.890710, 0.5), (0.093000, 0.684300, 0.457300), (0.115400, 0.430400, 0.304160), (0.185300, 0.478500, 0.254260)], # chs1 = crystal(['Ne', 'Ne', 'C', 'C', 'C', 'C', 'C', 'C', 'N', 'N', 'N', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'F', 'F', 'H', 'H', 'H'], # [(0.451210, 0.820105, 0.5), (0.311875, 0.630620, 0.317373), # (0.893560, 0.736500, 0.153530), (0.991400, 0.666667, 0.052070), (0.845300, 0.885700, 0.215570), (0.795100, 0.815000, 0.146220), (0.692700, 0.891700, 0.050790), (0.944500, 0.813800, 0.219330), # (0.5465, 0.0705, 0.8418), (0.3923, 0.1906, 0.8322), (0.22825, 0.05125, 0.344895), # (0.990100, 0.816000, 0.238990), (0.072300, 0.830500, 0.236450), (0.306260, 0.914300, 0.135060), (0.339440, 0.960790, 0.085750), (0.177400, 0.748400, 0.129220), (0.141300, 0.699100, 0.082930), # (0.429660, 0.821690, 0.288870), (0.648970, 0.890710, 0.5), # (0.093000, 0.684300, 0.457300), (0.115400, 0.430400, 0.304160), (0.185300, 0.478500, 0.254260)], spacegroup=87, #I4/m cellpar=[a, a, c, 90, 90, 90]) write('test.xyz', chs1) write('test.cif', chs1) eps = 0.10 model_molecule = {} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding #Rigged such that each cov_rad = [] for atom in chs1: #if atom.symbol == 'C': # cov_rad.append(1.8) if atom.symbol == 'H': cov_rad.append(1.4) elif atom.symbol == 'N': cov_rad.append(3.7) elif atom.symbol == 'Ne': cov_rad.append(1.0) elif atom.symbol == 'Ca': cov_rad.append(3.0) elif atom.symbol == 'F': cov_rad.append(0.6) else: cov_rad.append(covalent_radii[atom.number]) print cov_rad nlist = NeighborList(cov_rad, skin=0.01, self_interaction=False, bothways=True) nlist.build(chs1) #To sort out tags, we need to label each bond, we get a bunch of extra bonds here that we need to filter out bond_matrix = np.zeros((len(chs1), len(chs1)), dtype=bool) for atom in chs1: indices, offsets = nlist.get_neighbors(atom.index) if atom.symbol == 'Ne': #or atom.symbol == 'F': #these two aren't affected by evil crossover business for index in indices: if chs1[index].symbol == 'Ca': bond_matrix[index, atom.index] = True bond_matrix[atom.index, index] = True elif atom.symbol == 'F': #or atom.symbol == 'F': #these two aren't affected by evil crossover business for index in indices: if chs1[index].symbol == 'H': bond_matrix[index, atom.index] = True bond_matrix[atom.index, index] = True elif atom.symbol == 'N': #Here we go, suck in both Ca for index in indices: if chs1[index].symbol == 'Ca' and chs1.get_distance( atom.index, index, mic=True ) < 5.0: #Fudgy, but rigging the covalent radii was a pain bond_matrix[index, atom.index] = True bond_matrix[atom.index, index] = True elif chs1[index].symbol == 'H' and chs1.get_distance( atom.index, index, mic=True ) > 4.8: #This is a fudge that works. Better test would be take max H distance bond_matrix[index, atom.index] = True bond_matrix[atom.index, index] = True else: pass #No other bonds get counted ##Now we loop over the N, just to find which carbons go over PBC #for atom in chs1: # if atom.symbol == 'N': # indices, offsets = nlist.get_neighbors(atom.index) # for index,offset in zip(indices,offsets): #Should only be C # if chs1[index].symbol == 'C': # if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # chs1[index].tag = -chs1[index].tag factor = sum(sizes) / 2.0 + 2 #(sizes[0] + sizes[2])/2.0 print "factor = ", factor a = 4.14300 * factor c = 4.66569 * factor # Ne => centre of PW # N => triangles, first two corresponds to C1 linker, second one to Cs linker # Ca => corners of triangles (base end) i.e. adjacent to C_PW # F => SiH2X2 locations, (COM) # H => SiH2H2 dummies chs1 = crystal( [ 'Ne', 'Ne', 'N', 'N', 'N', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'F', 'F', 'H', 'H', 'H' ], [(0.451210, 0.820105, 0.5), (0.311875, 0.630620, 0.317373), (0.5465, 0.0705, 0.8418), (0.3923, 0.1906, 0.8322), (0.22825, 0.05125, 0.344895), (0.990100, 0.816000, 0.238990), (0.072300, 0.830500, 0.236450), (0.306260, 0.914300, 0.135060), (0.339440, 0.960790, 0.085750), (0.177400, 0.748400, 0.129220), (0.141300, 0.699100, 0.082930), (0.429660, 0.821690, 0.288870), (0.648970, 0.890710, 0.5), (0.093000, 0.684300, 0.457300), (0.115400, 0.430400, 0.304160), (0.185300, 0.478500, 0.254260)], spacegroup=87, #I4/m cellpar=[a, a, c, 90, 90, 90]) #Now that we've decided the bonds on the master structure, move them across to the scaled structure nbond = 1 #Now our test will involve using indices,offsets and bond_matrix=True #In this case, the Ca and H atoms directly represent our dummy atoms, so we number them for atom in chs1: if atom.symbol == 'Ca' or atom.symbol == 'H': atom.tag = nbond nbond += 1 #Now that we have our t/f matrix, we need to number the bonds, taking into account PBC bond_ids = np.zeros((len(chs1), len(chs1))) for atom in chs1: if atom.symbol == 'Ca' or atom.symbol == 'H': indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): if bond_matrix[ index, atom.index]: #If we've already identified it a a bond if any(o != 0 for o in offset): #Then we're going over PBC atom.tag = -atom.tag #for atom in chs1: # print atom.index, atom.symbol, atom.position, atom.tag #Now we start assembling the model #Start with Ne (rectangles) for atom in chs1: if atom.symbol == 'Ne': print '=======================================' print 'Ne Atom ', atom.index n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'Ne' indices, offsets = nlist.get_neighbors(atom.index) #print offsets symbols = ([chs1[index].symbol for index in indices]) symbol_string = ''.join( sorted([chs1[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index, offset in zip(indices, offsets): if bond_matrix[index, atom.index]: model_molecule[n_obj] += chs1[index] model_molecule[n_obj].positions[ -1] = chs1.positions[index] + np.dot( offset, chs1.get_cell()) model_molecule[n_obj][-1].tag = chs1[index].tag print chs1[index].symbol, chs1[index].position, chs1[ index].tag print chs1[index].index, chs1[index].symbol, chs1[ index].position, chs1[index].tag #if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # model_molecule[n_obj][-1].tag = -bond_dict[bond] #else: # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj][-1].tag = bond_dict[bond] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) n_centers = n_obj # # ##Now we do the F (SiX2H2) for atom in chs1: if atom.symbol == 'F': #print'=======================================' #print 'F Atom ',atom.index, " finding SiH2X2 anchor points" n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): if bond_matrix[index, atom.index]: model_molecule[n_obj] += chs1[index] model_molecule[n_obj].positions[ -1] = chs1.positions[index] + np.dot( offset, chs1.get_cell()) model_molecule[n_obj][-1].tag = chs1[index].tag #if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # model_molecule[n_obj][-1].tag = -bond_dict[bond] #else: # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj][-1].tag = bond_dict[bond] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) n_linkers = n_obj ##Now we do the N (triangles) for atom in chs1: if atom.symbol == 'N': #print'=======================================' #print 'N Atom ',atom.index, " finding triangles" n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): if bond_matrix[index, atom.index]: model_molecule[n_obj] += chs1[index] model_molecule[n_obj].positions[ -1] = chs1.positions[index] + np.dot( offset, chs1.get_cell()) model_molecule[n_obj][-1].tag = chs1[index].tag #if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # model_molecule[n_obj][-1].tag = -bond_dict[bond] #else: # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj][-1].tag = bond_dict[bond] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # # # f = open('chs1.model', 'w') g = open('control-mofgen.txt', 'w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] # #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' % ('Number of objects =', n_obj + 1)) f.write('%-20s\n' % ('build = systre')) f.write('%5s\n' % ('Cell:')) f.write( '%8.3f %8.3f %8.3f \n' % (chs1.get_cell()[0][0], chs1.get_cell()[0][1], chs1.get_cell()[0][2])) f.write( '%8.3f %8.3f %8.3f \n' % (chs1.get_cell()[1][0], chs1.get_cell()[1][1], chs1.get_cell()[1][2])) f.write( '%8.3f %8.3f %8.3f \n' % (chs1.get_cell()[2][0], chs1.get_cell()[2][1], chs1.get_cell()[2][2])) g.write('%-20s\n' % ('model = chs1')) # for obj in xrange(n_centers + 1): f.write('\n%-8s %-3d\n' % ('Center: ', obj + 1)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = rectangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('center =', names[0])) for obj in xrange(n_centers + 1, n_linkers + 1): f.write('\n%-8s %-3d\n' % ('Linker: ', obj - n_centers)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = linear_triangle')) #process positions to make it a bit more ideal #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) elif atom.symbol == 'F': f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) elif atom.symbol == 'H': f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Bq', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('linker =', names[1])) # for obj in xrange(n_linkers + 1, n_obj + 1): f.write('\n%-8s %-3d\n' % ('Linker: ', obj - n_centers)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = triangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 2.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('linker =', names[2])) # # test_mol = Atoms() for obj in model_molecule: #for obj in xrange(n_linkers+1,n_obj+1): #triangles only test_mol += model_molecule[obj] test_mol.set_cell(chs1.get_cell()) test_mol.set_pbc(chs1.get_pbc()) write('test_model2.xyz', test_mol) write('test_model2.cif', test_mol)
def make_mil53(names, sizes): #work out the expansion factor factor = sizes[1] #linker is the only thing that matters #sum(sizes) #print sizes[0] a = 6.6085 #We'll form the bondlist and then enlarge the cell. b = 16.0 #16.675 c = 12.0 #12.813 #These cell dimensions are rigged to a linker length of 5 (circa size of benzene) # Al -> centre of mil53, N -> centre of rectangle linker , C -> dummies mil53 = crystal( ['Al', 'N', 'C'], [(0.25, 0.25, 0.25), (0.5, 0.0, 0.5), (0.5, 0.1292, 0.383)], spacegroup=74, #Imma cellpar=[a, b, c, 90, 90, 90]) write('test.xyz', mil53) eps = 0.05 model_molecule = {} n_obj = -1 #initialise to -1 such that it can be indexed at start of add #First detect global bonding cov_rad = [] for atom in mil53: if atom.symbol == 'Al': cov_rad.append(covalent_radii[atom.number] * 2) #Rigged to suck in C, but not N elif atom.symbol == 'N': cov_rad.append(covalent_radii[atom.number] * 3) #Rigged to suck in C, but not Al else: cov_rad.append(covalent_radii[atom.number]) #print cov_rad nlist = NeighborList(cov_rad, skin=0.1, self_interaction=False, bothways=True) nlist.build(mil53) #Now we exapnd the cell. The factor given is half the hypotenuse of a right triangle with angle 35 deg print "factor = ", factor print b, c a = 2 * sizes[0] b = b + (2 * factor * sin(35 * pi / 180.0)) c = c + (2 * factor * cos(35 * pi / 180.0)) print b, c # Al -> centre of mil53, N -> centre of rectangle linker , C -> dummies mil53 = crystal( ['Al', 'N', 'C'], [(0.25, 0.25, 0.25), (0.5, 0.0, 0.5), (0.5, 0.1292, 0.383)], spacegroup=74, #Imma cellpar=[a, b, c, 90, 90, 90]) #a (height) is fixed #To sort out tags, we need to label each bond nbond = 1 #Now in this case, the C atoms directly represent our dummy atoms, so we number them for atom in mil53: if atom.symbol == 'C': atom.tag = nbond nbond += 1 #Al also need to be tagged to each other for atom in mil53: if atom.symbol == 'Al': indices, offsets = nlist.get_neighbors(atom.index) #symbol_string = ''.join(sorted([mil53[index].symbol for index in indices])) #print symbol_string for index, offset in zip(indices, offsets): if mil53[index].symbol == 'Al' and all( o == 0 for o in offset ) and index > atom.index: #interesting because it the same bond is both internal and pbc #print "atom ", atom.index, " and atom ",index, " are bonded, non-pbc ", nbond atom.tag = nbond mil53[index].tag = nbond nbond += 1 #Now we loop over the N, just to find which carbons go over PBC for atom in mil53: if atom.symbol == 'N': indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): #Should only be C if mil53[index].symbol == 'C': if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag mil53[index].tag = -mil53[index].tag #print mil53.get_tags() used_carbon = [] #Now we build the model #Start with Al for atom in mil53: if atom.symbol == 'Al': #print'=======================================' #print 'Al Atom ',atom.index indices, offsets = nlist.get_neighbors(atom.index) C_count = 0 for index, offset in zip(indices, offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all( o == 0 for o in offset ): # and mil53[index].tag not in model_molecule[n_obj].get_tags(): C_count += 1 #print "Al atom, ", atom.index, "has c-count in this cell", C_count if C_count == 2: n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom for index, offset in zip(indices, offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all( o == 0 for o in offset ): # and mil53[index].tag not in model_molecule[n_obj].get_tags(): model_molecule[n_obj] += mil53[index] model_molecule[n_obj][-1].tag = mil53[index].tag model_molecule[n_obj].positions[ -1] = mil53.positions[index] + np.dot( offset, mil53.get_cell()) used_carbon.append(index) #We need to put the other Al as an anchor for index, offset in zip(indices, offsets): if mil53[index].symbol == 'Al' and all(o == 0 for o in offset): model_molecule[n_obj] += mil53[index] #model_molecule[n_obj][-1].tag = None #No tag model_molecule[n_obj].positions[ -1] = mil53.positions[index] + np.dot( offset, mil53.get_cell()) #That gives us two Al centres, now the other two #These are the two that have 4 in-cell C for atom in mil53: if atom.symbol == 'Al': #print'=======================================' #print 'Al Atom ',atom.index indices, offsets = nlist.get_neighbors(atom.index) C_count = 0 for index, offset in zip(indices, offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all( o == 0 for o in offset ): # and mil53[index].tag not in model_molecule[n_obj].get_tags(): C_count += 1 #print "Al atom, ", atom.index, "has c-count in this cell", C_count if C_count == 4: n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom for index, offset in zip(indices, offsets): #Should only be C or Al if mil53[index].symbol == 'C' and all( o == 0 for o in offset) and index not in used_carbon: model_molecule[n_obj] += mil53[index] model_molecule[n_obj][-1].tag = mil53[index].tag model_molecule[n_obj].positions[ -1] = mil53.positions[index] + np.dot( offset, mil53.get_cell()) #We need to put the other Al as an anchor for index, offset in zip(indices, offsets): if mil53[index].symbol == 'Al' and any(o != 0 for o in offset): model_molecule[n_obj] += mil53[index] #model_molecule[n_obj][-1].tag = None #No tag model_molecule[n_obj].positions[ -1] = mil53.positions[index] + np.dot( offset, mil53.get_cell()) # #We need to interrogate our C further as two of them belong to both Al in the same cell # C_indices,C_offsets = nlist.get_neighbors(index) # symbol_string = ''.join(sorted([mil53[index].symbol for index in C_indices])) # print symbol_string # # model_molecule[n_obj] += mil53[index] # model_molecule[n_obj][-1].tag = mil53[index].tag # model_molecule[n_obj].positions[-1] = mil53.positions[index] + np.dot(offset, mil53.get_cell()) n_centers = n_obj # # ##Now we do the N (linear) for atom in mil53: if atom.symbol == 'N': #print'=======================================' #print 'N Atom ',atom.index, " finding squares1" n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): #Should only be C if mil53[index].symbol == 'C': model_molecule[n_obj] += mil53[index] model_molecule[n_obj][-1].tag = mil53[index].tag model_molecule[n_obj].positions[ -1] = mil53.positions[index] + np.dot( offset, mil53.get_cell()) # # # f = open('mil53.model', 'w') g = open('control-mofgen.txt', 'w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it test_mol = Atoms() for obj in model_molecule: test_mol += model_molecule[obj] #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' % ('Number of objects =', n_obj + 1)) f.write('%-20s\n' % ('build = systre')) f.write('%-13s\n' % ('ExtraDummies')) f.write('%5s\n' % ('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (mil53.get_cell()[0][0], mil53.get_cell()[0][1], mil53.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (mil53.get_cell()[1][0], mil53.get_cell()[1][1], mil53.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (mil53.get_cell()[2][0], mil53.get_cell()[2][1], mil53.get_cell()[2][2])) g.write('%-20s\n' % ('model = mil53')) # Print the centers and linkers for obj in xrange(n_centers + 1): f.write('\n%-8s %-3d\n' % ('Center: ', obj + 1)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = mil53')) #process positions to make it a bit more ideal #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(atom.index,0,2.0,fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.symbol == 'C': #can't use tags as a marker here, because we've given a tag to 'Q' as well f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) elif atom.symbol == 'Al': f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('Q', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('center =', names[0])) for obj in xrange(n_centers + 1, n_obj + 1): f.write('\n%-8s %-3d\n' % ('Linker: ', obj - n_centers)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = linear')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('linker =', names[1])) # # test_mol = Atoms() for obj in model_molecule: test_mol += model_molecule[obj] write('test_model2.xyz', test_mol)
def make_nbo(names, sizes): #work out the expansion factor #dist0 = furthest_dummy(mol0) #dist1 = furthest_dummy(mol1) factor = sum(sizes) #dist0 + dist1 factor = factor * 2 a = 2.0 * factor #a = 4.0 # C -> squares, N => midpoints nbo = crystal(['C', 'N'], [(0.0, 0.5, 0.5), (0.25, 0.0, 0.5)], spacegroup=229, cellpar=[a, a, a, 90, 90, 90]) #write('test.xyz',nbo) eps = 0.05 model_molecule = {} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding cov_rad = [] for atom in nbo: #cov_rad.append(covalent_radii[atom.number]) cov_rad.append(factor / 4) nlist = NeighborList(cov_rad, self_interaction=False, bothways=True) nlist.build(nbo) #To sort out tags, we need to label each bond nbond = 1 bond_matrix = np.zeros((len(nbo), len(nbo))) for atom in nbo: indices, offsets = nlist.get_neighbors(atom.index) for index in indices: if atom.index < index: bond_matrix[index, atom.index] = nbond bond_matrix[atom.index, index] = nbond print atom.index, index, nbond nbond += 1 print nbond print bond_matrix #Now we look for all the things with unit*factor bondlengths #Start with C (squares) for atom in nbo: if atom.symbol == 'C': print '=======================================' print 'C Atom ', atom.index n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'F' indices, offsets = nlist.get_neighbors(atom.index) #Just checking the symbols here symbols = ([nbo[index].symbol for index in indices]) symbol_string = ''.join( sorted([nbo[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index, offset in zip(indices, offsets): dist_mic = nbo.get_distance(atom.index, index, mic=True) dist_no_mic = nbo.get_distance(atom.index, index, mic=False) print index, dist_no_mic ##Cell expands by the factor, but we're halving it because the N represesnt midpoints of CC bonds. Default systre bondlength is 1.0 if (abs(dist_mic - dist_no_mic) <= eps) and (abs(dist_mic - factor / 2.0) < eps): model_molecule[n_obj] += nbo[index] model_molecule[n_obj][-1].tag = bond_matrix[atom.index, index] elif abs(dist_mic - factor / 2.0) < eps: #If we're going over a periodic boundary, we need to negate the tag print "Tag, ", nbo[index].tag, " goes over pbc" nbo[index].tag = -(nbo[index].tag) model_molecule[n_obj] += nbo[index] model_molecule[n_obj].positions[ -1] = nbo.positions[index] + np.dot( offset, nbo.get_cell()) model_molecule[n_obj][-1].tag = -bond_matrix[atom.index, index] n_centers = n_obj # # ##Now we do the edges / N/ (linear things) for atom in nbo: if atom.symbol == 'N': print '=======================================' print 'N Atom ', atom.index, " finding edges" n_obj += 1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index, offset in zip(indices, offsets): dist_mic = nbo.get_distance(atom.index, index, mic=True) dist_no_mic = nbo.get_distance(atom.index, index, mic=False) ##Cell expands by the factor, but we're halving it because the N represesnt midpoints of CC bonds. Default systre bondlength is 1.0 if (abs(dist_mic - dist_no_mic) <= eps) and (abs(dist_mic - factor / 2.0) < eps): model_molecule[n_obj] += nbo[index] model_molecule[n_obj][-1].tag = bond_matrix[atom.index, index] elif abs(dist_mic - factor / 2.0) < eps: #If we're going over a periodic boundary, we need to negate the tag print "Tag, ", nbo[index].tag, " goes over pbc" nbo[index].tag = -(nbo[index].tag) model_molecule[n_obj] += nbo[index] model_molecule[n_obj].positions[ -1] = nbo.positions[index] + np.dot( offset, nbo.get_cell()) model_molecule[n_obj][-1].tag = -bond_matrix[atom.index, index] f = open('nbo.model', 'w') g = open('control-mofgen.txt', 'w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] # #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' % ('Number of objects =', n_obj + 1)) f.write('%-20s\n' % ('build = systre')) f.write('%5s\n' % ('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (nbo.get_cell()[0][0], nbo.get_cell()[0][1], nbo.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (nbo.get_cell()[1][0], nbo.get_cell()[1][1], nbo.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (nbo.get_cell()[2][0], nbo.get_cell()[2][1], nbo.get_cell()[2][2])) g.write('%-20s\n' % ('model = nbo')) for obj in xrange(n_centers + 1): f.write('\n%-8s %-3d\n' % ('Centre: ', obj + 1)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = square')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: if atom.symbol == 'N': model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('center =', names[0])) for obj in xrange(n_centers + 1, n_obj + 1): f.write('\n%-8s %-3d\n' % ('Linker: ', obj - n_centers)) f.write('%-3d\n' % (len(model_molecule[obj]))) f.write('%-20s\n' % ('type = linear')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: if atom.symbol == 'C': model_molecule[obj].set_distance(atom.index, 0, 1.0, fix=1) for atom in model_molecule[obj]: (x, y, z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' % ('linker =', names[1]))
# Spacegroup/symmetry library from pyspglib import spglib # The qe-util package from qeutil import QuantumEspresso # iPython utility function from IPython.core.display import Image # Configure qe-util for local execution of the Quantum Espresso on four processors # QuantumEspresso.pw_cmd='mpiexec -n 4 pw.x < pw.in > pw.out' a=4.3596 # Lattice constant in Angstrom cryst = crystal(['Si', 'C'], # Atoms in the crystal [(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)
# You should have received a copy of the GNU General Public License # along with Elastic. If not, see <http://www.gnu.org/licenses/>. ''' Example of parallel volume scan using VASP calculator and parcalc module. ''' from ase.lattice.spacegroup import crystal from parcalc import ClusterVasp, ParCalculate import ase.units as units import numpy import matplotlib.pyplot as plt a = 4.194 cryst = crystal(['Mg', 'O'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) # Create the calculator running on one, eight-core node. # This is specific to the setup on my cluster. # You have to adapt this part to your environment calc=ClusterVasp(nodes=1,ppn=8) # Assign the calculator to the crystal cryst.set_calculator(calc) # Set the calculation parameters calc.set(prec = 'Accurate', xc = 'PBE', lreal = False, nsw=30,
from ase.lattice.spacegroup import crystal a = 2.87 fe = crystal('Fe', [(0,0,0)], spacegroup=229, cellpar=[a, a, a, 90, 90, 90])
elastic module. ''' from ase.lattice.spacegroup import crystal from parcalc import ClusterVasp, ParCalculate from elastic import Crystal import ase.units as units from numpy import array, linspace import matplotlib.pyplot as plt import numpy # Create the MgO crystal a = 4.194 cryst = Crystal( crystal(['Mg', 'O'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90])) # Create the calculator running on one, eight-core node. # This is specific to the setup on my cluster. # You have to adapt this part to your environment calc = ClusterVasp(nodes=1, ppn=8) # Assign the calculator to the crystal cryst.set_calculator(calc) # Set the calculation parameters calc.set(prec='Accurate', xc='PBE', lreal=False, nsw=30,
def make_iac(names,sizes): #work out the expansion factor factor = sum(sizes) # a = 3.5777 * factor # C -> tetrahedra, N => octahedra iac = crystal(['C', 'N'], [(0.125, 0.0, 0.25), (0.0,0.0,0.0)], spacegroup=230, cellpar=[a, a, a, 90, 90, 90]) #write('test.xyz',iac) eps = 0.05 model_molecule={} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding cov_rad=[] for atom in iac: #cov_rad.append(covalent_radii[atom.number]) cov_rad.append(factor / 2) print cov_rad nlist = NeighborList(cov_rad,skin=0.1,self_interaction=False,bothways=True) nlist.build(iac) #To sort out tags, we need to label each bond nbond = 1 bond_matrix = np.zeros( (len(iac),len(iac)) ) pbc_bond_matrix = np.zeros( (len(iac),len(iac)) ) bond_dict = {} for atom in iac: print "---------------------" indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): print atom.index, index, atom.symbol, iac[index].symbol, offset, iac.get_distance(atom.index,index,mic=True) if atom.index < index: this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond #Now we need to find the same bond the other direction to get the offsets right indices2,offsets2 = nlist.get_neighbors(index) for i2,o2 in zip(indices2,offsets2): if i2 == atom.index: #print "sum of offsets = ", offset, o2, sum(offset + o2) if sum(offset + o2) == 0: #same bond this_bond = [index, atom.index] for o in o2: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond nbond +=1 #print nbond #for k,v in bond_dict.items(): # print k,v #Now we look for all the things with unit*factor bondlengths #Start with N (octahedra) for atom in iac: if atom.symbol == 'N': print'=======================================' print 'N Atom ',atom.index n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'F' indices, offsets = nlist.get_neighbors(atom.index) #Just checking the symbols here print indices print offsets symbols = ([iac[index].symbol for index in indices]) symbol_string = ''.join(sorted([iac[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index,offset in zip(indices,offsets): print atom.index, index, offset this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond_dict[bond] if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += iac[index] model_molecule[n_obj].positions[-1] = iac.positions[index] + np.dot(offset, iac.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += iac[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[-1] = iac.positions[index] + np.dot(offset, iac.get_cell()) n_centers = n_obj # # ##Now we do the C (tetrahedra) for atom in iac: if atom.symbol == 'C': #print'=======================================' #print 'N Atom ',atom.index, " finding squares1" n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): print index, offset, iac[index].symbol this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #if not bond_dict.has_key(bond): #Then if iac[index].symbol == 'N': if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += iac[index] model_molecule[n_obj].positions[-1] = iac.positions[index] + np.dot(offset, iac.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += iac[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[-1] = iac.positions[index] + np.dot(offset, iac.get_cell()) # # # f = open('iac.model','w') g = open('control-mofgen.txt','w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] # #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' %('Number of objects =',n_obj+1)) f.write('%-20s\n' %('build = systre')) f.write('%5s\n' %('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (iac.get_cell()[0][0], iac.get_cell()[0][1], iac.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (iac.get_cell()[1][0], iac.get_cell()[1][1], iac.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (iac.get_cell()[2][0], iac.get_cell()[2][1], iac.get_cell()[2][2])) g.write('%-20s\n' %('model = iac')) # for obj in xrange(n_centers+1): f.write('\n%-8s %-3d\n' %('Center: ', obj+1)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = octahedral_2')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('center =', names[0])) for obj in xrange(n_centers+1,n_obj+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = tetrahedral')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('linker =', names[1]))
def make_chs1(names,sizes): #CRYSTAL # NAME "UHM-7 - simplified - 12 - classiified as chs-1" # GROUP I4/mmm # CELL 4.14300 4.14300 4.66569 90.0000 90.0000 90.0000 # NODE 5 4 0.00000 0.26972 0.00000 # NODE 1 3 0.06146 0.28112 0.20686 # NODE 4 4 0.10690 0.10690 0.21827 # NODE 2 3 0.00000 0.19156 0.39361 # EDGE 0.06146 0.28112 0.20686 0.21888 0.43854 0.29314 # EDGE 0.00000 0.26972 0.00000 0.06146 0.28112 0.20686 # EDGE 0.00000 0.19156 0.39361 0.00000 0.19156 0.60639 # EDGE 0.00000 0.19156 0.39361 0.10690 0.10690 0.21827 # EDGE 0.10690 0.10690 0.21827 0.28112 -0.06146 0.20686 ## EDGE_CENTER 0.14017 0.35983 0.25000 ## EDGE_CENTER 0.03073 0.27542 0.10343 ## EDGE_CENTER 0.00000 0.19156 0.50000 ## EDGE_CENTER 0.05345 0.14923 0.30594 ## EDGE_CENTER 0.19401 0.02272 0.21257 #END # So the node numbering above sucks... # The edges go between (using the above numbering) # 1-1 # 5-1 # 2-2 # 2-4 # 4-1 # The same-same edges between triangles are where we need to dump the SiH2X2 units # Even though SiH2X2 is "linear" (two dummy atoms), in reality it is tetrahedral, and we need to orient it, three points on a line isn't enough # We'll use some H atoms to give the direction #So the cgd coordinates actually suck if you want ot build a framework... #work out the expansion factor #print "sizes =",sizes #factor = sizes[2]#/2.0 a = 28.7527 c = 35.4316 #uhm-7 crystal dimensions # Ne => centre of PW # C => corner of PW # N => triangles, first two corresponds to C1 linker, second one to Cs linker # Ca => corners of triangles (base end) i.e. adjacent to C_PW # F => SiH2X2 locations, (COM) # H => SiH2H2 dummies chs1 = crystal(['Ne', 'Ne', 'N', 'N', 'N', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'F', 'F', 'H', 'H', 'H'], [(0.451210, 0.820105, 0.5), (0.311875, 0.630620, 0.317373), (0.5465, 0.0705, 0.8418), (0.3923, 0.1906, 0.8322), (0.22825, 0.05125, 0.344895), (0.990100, 0.816000, 0.238990), (0.072300, 0.830500, 0.236450), (0.306260, 0.914300, 0.135060), (0.339440, 0.960790, 0.085750), (0.177400, 0.748400, 0.129220), (0.141300, 0.699100, 0.082930), (0.429660, 0.821690, 0.288870), (0.648970, 0.890710, 0.5), (0.093000, 0.684300, 0.457300), (0.115400, 0.430400, 0.304160), (0.185300, 0.478500, 0.254260)], # chs1 = crystal(['Ne', 'Ne', 'C', 'C', 'C', 'C', 'C', 'C', 'N', 'N', 'N', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'F', 'F', 'H', 'H', 'H'], # [(0.451210, 0.820105, 0.5), (0.311875, 0.630620, 0.317373), # (0.893560, 0.736500, 0.153530), (0.991400, 0.666667, 0.052070), (0.845300, 0.885700, 0.215570), (0.795100, 0.815000, 0.146220), (0.692700, 0.891700, 0.050790), (0.944500, 0.813800, 0.219330), # (0.5465, 0.0705, 0.8418), (0.3923, 0.1906, 0.8322), (0.22825, 0.05125, 0.344895), # (0.990100, 0.816000, 0.238990), (0.072300, 0.830500, 0.236450), (0.306260, 0.914300, 0.135060), (0.339440, 0.960790, 0.085750), (0.177400, 0.748400, 0.129220), (0.141300, 0.699100, 0.082930), # (0.429660, 0.821690, 0.288870), (0.648970, 0.890710, 0.5), # (0.093000, 0.684300, 0.457300), (0.115400, 0.430400, 0.304160), (0.185300, 0.478500, 0.254260)], spacegroup=87, #I4/m cellpar=[a, a, c, 90, 90, 90]) write('test.xyz',chs1) write('test.cif',chs1) eps = 0.10 model_molecule={} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding #Rigged such that each cov_rad=[] for atom in chs1: #if atom.symbol == 'C': # cov_rad.append(1.8) if atom.symbol == 'H': cov_rad.append(1.4) elif atom.symbol == 'N': cov_rad.append(3.7) elif atom.symbol == 'Ne': cov_rad.append(1.0) elif atom.symbol == 'Ca': cov_rad.append(3.0) elif atom.symbol == 'F': cov_rad.append(0.6) else: cov_rad.append(covalent_radii[atom.number]) print cov_rad nlist = NeighborList(cov_rad,skin=0.01,self_interaction=False,bothways=True) nlist.build(chs1) #To sort out tags, we need to label each bond, we get a bunch of extra bonds here that we need to filter out bond_matrix = np.zeros( (len(chs1),len(chs1)) , dtype=bool) for atom in chs1: indices, offsets = nlist.get_neighbors(atom.index) if atom.symbol == 'Ne': #or atom.symbol == 'F': #these two aren't affected by evil crossover business for index in indices: if chs1[index].symbol == 'Ca': bond_matrix[index,atom.index] = True bond_matrix[atom.index,index] = True elif atom.symbol == 'F': #or atom.symbol == 'F': #these two aren't affected by evil crossover business for index in indices: if chs1[index].symbol == 'H': bond_matrix[index,atom.index] = True bond_matrix[atom.index,index] = True elif atom.symbol == 'N': #Here we go, suck in both Ca for index in indices: if chs1[index].symbol == 'Ca' and chs1.get_distance(atom.index,index,mic=True) <5.0: #Fudgy, but rigging the covalent radii was a pain bond_matrix[index,atom.index] = True bond_matrix[atom.index,index] = True elif chs1[index].symbol == 'H' and chs1.get_distance(atom.index,index,mic=True) >4.8: #This is a fudge that works. Better test would be take max H distance bond_matrix[index,atom.index] = True bond_matrix[atom.index,index] = True else: pass #No other bonds get counted ##Now we loop over the N, just to find which carbons go over PBC #for atom in chs1: # if atom.symbol == 'N': # indices, offsets = nlist.get_neighbors(atom.index) # for index,offset in zip(indices,offsets): #Should only be C # if chs1[index].symbol == 'C': # if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # chs1[index].tag = -chs1[index].tag factor = sum(sizes)/2.0 + 2#(sizes[0] + sizes[2])/2.0 print "factor = ",factor a = 4.14300 * factor c = 4.66569 * factor # Ne => centre of PW # N => triangles, first two corresponds to C1 linker, second one to Cs linker # Ca => corners of triangles (base end) i.e. adjacent to C_PW # F => SiH2X2 locations, (COM) # H => SiH2H2 dummies chs1 = crystal(['Ne', 'Ne', 'N', 'N', 'N', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'Ca', 'F', 'F', 'H', 'H', 'H'], [(0.451210, 0.820105, 0.5), (0.311875, 0.630620, 0.317373), (0.5465, 0.0705, 0.8418), (0.3923, 0.1906, 0.8322), (0.22825, 0.05125, 0.344895), (0.990100, 0.816000, 0.238990), (0.072300, 0.830500, 0.236450), (0.306260, 0.914300, 0.135060), (0.339440, 0.960790, 0.085750), (0.177400, 0.748400, 0.129220), (0.141300, 0.699100, 0.082930), (0.429660, 0.821690, 0.288870), (0.648970, 0.890710, 0.5), (0.093000, 0.684300, 0.457300), (0.115400, 0.430400, 0.304160), (0.185300, 0.478500, 0.254260)], spacegroup=87, #I4/m cellpar=[a, a, c, 90, 90, 90]) #Now that we've decided the bonds on the master structure, move them across to the scaled structure nbond = 1 #Now our test will involve using indices,offsets and bond_matrix=True #In this case, the Ca and H atoms directly represent our dummy atoms, so we number them for atom in chs1: if atom.symbol == 'Ca' or atom.symbol == 'H': atom.tag = nbond nbond += 1 #Now that we have our t/f matrix, we need to number the bonds, taking into account PBC bond_ids = np.zeros( (len(chs1),len(chs1)) ) for atom in chs1: if atom.symbol == 'Ca' or atom.symbol == 'H': indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): if bond_matrix[index,atom.index]: #If we've already identified it a a bond if any(o != 0 for o in offset): #Then we're going over PBC atom.tag = -atom.tag #for atom in chs1: # print atom.index, atom.symbol, atom.position, atom.tag #Now we start assembling the model #Start with Ne (rectangles) for atom in chs1: if atom.symbol == 'Ne': print'=======================================' print 'Ne Atom ',atom.index n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'Ne' indices, offsets = nlist.get_neighbors(atom.index) #print offsets symbols = ([chs1[index].symbol for index in indices]) symbol_string = ''.join(sorted([chs1[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index,offset in zip(indices,offsets): if bond_matrix[index,atom.index]: model_molecule[n_obj] += chs1[index] model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) model_molecule[n_obj][-1].tag = chs1[index].tag print chs1[index].symbol, chs1[index].position, chs1[index].tag print chs1[index].index, chs1[index].symbol, chs1[index].position, chs1[index].tag #if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # model_molecule[n_obj][-1].tag = -bond_dict[bond] #else: # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj][-1].tag = bond_dict[bond] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) n_centers = n_obj # # ##Now we do the F (SiX2H2) for atom in chs1: if atom.symbol == 'F': #print'=======================================' #print 'F Atom ',atom.index, " finding SiH2X2 anchor points" n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): if bond_matrix[index,atom.index]: model_molecule[n_obj] += chs1[index] model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) model_molecule[n_obj][-1].tag = chs1[index].tag #if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # model_molecule[n_obj][-1].tag = -bond_dict[bond] #else: # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj][-1].tag = bond_dict[bond] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) n_linkers = n_obj ##Now we do the N (triangles) for atom in chs1: if atom.symbol == 'N': #print'=======================================' #print 'N Atom ',atom.index, " finding triangles" n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): if bond_matrix[index,atom.index]: model_molecule[n_obj] += chs1[index] model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) model_molecule[n_obj][-1].tag = chs1[index].tag #if any(o != 0 for o in offset): # #If we're going over a periodic boundary, we need to negate the tag # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # model_molecule[n_obj][-1].tag = -bond_dict[bond] #else: # model_molecule[n_obj] += chs1[index] # model_molecule[n_obj][-1].tag = bond_dict[bond] # model_molecule[n_obj].positions[-1] = chs1.positions[index] + np.dot(offset, chs1.get_cell()) # # # f = open('chs1.model','w') g = open('control-mofgen.txt','w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] # #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' %('Number of objects =',n_obj+1)) f.write('%-20s\n' %('build = systre')) f.write('%5s\n' %('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (chs1.get_cell()[0][0], chs1.get_cell()[0][1], chs1.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (chs1.get_cell()[1][0], chs1.get_cell()[1][1], chs1.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (chs1.get_cell()[2][0], chs1.get_cell()[2][1], chs1.get_cell()[2][2])) g.write('%-20s\n' %('model = chs1')) # for obj in xrange(n_centers+1): f.write('\n%-8s %-3d\n' %('Center: ', obj+1)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = rectangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('center =', names[0])) for obj in xrange(n_centers+1,n_linkers+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = linear_triangle')) #process positions to make it a bit more ideal #for atom in model_molecule[obj]: # #if atom.symbol == 'C': # if atom.index != 0: # model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) elif atom.symbol == 'F': f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) elif atom.symbol == 'H': f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Bq', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('linker =', names[1])) # for obj in xrange(n_linkers+1,n_obj+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = triangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,2.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('linker =', names[2])) # # test_mol = Atoms() for obj in model_molecule: #for obj in xrange(n_linkers+1,n_obj+1): #triangles only test_mol += model_molecule[obj] test_mol.set_cell(chs1.get_cell()) test_mol.set_pbc(chs1.get_pbc()) write('test_model2.xyz',test_mol) write('test_model2.cif',test_mol)
from ase.calculators.vasp import Vasp from ase.lattice.spacegroup import crystal import matplotlib.pyplot as plt def primitive_from_conventional_cell(atoms, spacegroup=1, setting=1): """Returns primitive cell given an Atoms object for a conventional cell and it's spacegroup.""" from ase.lattice.spacegroup import Spacegroup from ase.utils.geometry import cut sg = Spacegroup(spacegroup, setting) prim_cell = sg.scaled_primitive_cell # Check if we need to transpose return cut(atoms, a=prim_cell[0], b=prim_cell[1], c=prim_cell[2]) #Define the coordinates a = 5.459 si_c = crystal('Si', [(0,0,0)], spacegroup=227, cellpar=[a, a, a, 90, 90, 90]) si = primitive_from_conventional_cell(si_c,spacegroup=227, setting=1) # Define KPOINTS for special points points = ibz_points['fcc'] G = points['Gamma'] X = points['X'] W = points['W'] K = points['K'] L = points['L'] #kpoints, x, X = get_bandpath(['L','G','W','K'], si.cell,10) kpoints, x, X = get_bandpath([W, L, G, X, W, K], si.cell, npoints=60) # Point names for plot axis point_names = ['W','L','G','W','K'] # FROM HERE ON NO REAL INPUT IS NEEDED, UNLESS ONE WISHES TO # CHANGE SOME VASP INCAR PARAMETERS
"Test the ase.utils.geometry module" import numpy as np import ase from ase.lattice.spacegroup import crystal from ase.utils.geometry import get_layers, cut, stack np.set_printoptions(suppress=True) al = crystal('Al', [(0,0,0)], spacegroup=225, cellpar=4.05) # Cut out slab of 5 Al(001) layers al001 = cut(al, nlayers=5) correct_pos = np.array([[ 0. , 0. , 0. ], [ 0. , 0.5, 0.2], [ 0.5, 0. , 0.2], [ 0.5, 0.5, 0. ], [ 0. , 0. , 0.4], [ 0. , 0.5, 0.6], [ 0.5, 0. , 0.6], [ 0.5, 0.5, 0.4], [ 0. , 0. , 0.8], [ 0.5, 0.5, 0.8]]) assert np.allclose(correct_pos, al001.get_scaled_positions()) # Check layers along 001 tags, levels = get_layers(al001, (0, 0, 1)) assert np.allclose(tags, [0, 1, 1, 0, 2, 3, 3, 2, 4, 4]) assert np.allclose(levels, [ 0., 2.025, 4.05, 6.075, 8.1])
def make_ntt(names,sizes): #factor = sum(sizes) #dist0 + dist1 factor = sizes[0] +sizes[1] factor = factor a = 7.3485 * factor # C -> rectangle (square), N => central triangles, O => outer triangles ntt = crystal(['C', 'N', 'O'], [(0.0, 0.16667, 0.16667), (0.1668, 0.1668, 0.3332), (0.1111, 0.1111, 0.2222 )], spacegroup=225, #Fm-3m cellpar=[a, a, a, 90, 90, 90]) #write('test.xyz',ntt) eps = 0.05 model_molecule={} n_obj = -1 #initialise to -1 such that it can be indexed at start of add n_tags = 0 #First detect global bonding cov_rad=[] for atom in ntt: #cov_rad.append(covalent_radii[atom.number]) cov_rad.append(factor / 2) print cov_rad nlist = NeighborList(cov_rad,skin=0.1,self_interaction=False,bothways=True) nlist.build(ntt) #To sort out tags, we need to label each bond nbond = 1 bond_matrix = np.zeros( (len(ntt),len(ntt)) ) pbc_bond_matrix = np.zeros( (len(ntt),len(ntt)) ) bond_dict = {} for atom in ntt: print "---------------------" indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): print atom.index, index, atom.symbol, ntt[index].symbol, offset, ntt.get_distance(atom.index,index,mic=True) if atom.index < index: this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond #Now we need to find the same bond the other direction to get the offsets right indices2,offsets2 = nlist.get_neighbors(index) for i2,o2 in zip(indices2,offsets2): if i2 == atom.index: #print "sum of offsets = ", offset, o2, sum(offset + o2) if sum(offset + o2) == 0: #same bond this_bond = [index, atom.index] for o in o2: this_bond.append(o) bond = tuple(this_bond) print bond bond_dict[bond] = nbond nbond +=1 print nbond for k,v in bond_dict.items(): print k,v #Start with C (rectangles) for atom in ntt: if atom.symbol == 'C': print'=======================================' print 'C Atom ',atom.index n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom model_molecule[n_obj][0].original_index = atom.index model_molecule[n_obj][0].symbol = 'F' indices, offsets = nlist.get_neighbors(atom.index) #Just checking the symbols here print indices print offsets symbols = ([ntt[index].symbol for index in indices]) symbol_string = ''.join(sorted([ntt[index].symbol for index in indices])) #print symbol_string #for i,o in zip(indices, offsets): # print i,o for index,offset in zip(indices,offsets): print atom.index, index, offset this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) print bond_dict[bond] if ntt[index].symbol == 'O': #C is only bound to O, (outer triangles) if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += ntt[index] model_molecule[n_obj].positions[-1] = ntt.positions[index] + np.dot(offset, ntt.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += ntt[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[-1] = ntt.positions[index] + np.dot(offset, ntt.get_cell()) n_centers = n_obj # # ##Now we do the N (inner triangles) for atom in ntt: if atom.symbol == 'N': #print'=======================================' #print 'N Atom ',atom.index, " finding edges" n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): print index, offset, ntt[index].symbol this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #if not bond_dict.has_key(bond): #Then if ntt[index].symbol == 'O': if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += ntt[index] model_molecule[n_obj].positions[-1] = ntt.positions[index] + np.dot(offset, ntt.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += ntt[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[-1] = ntt.positions[index] + np.dot(offset, ntt.get_cell()) n_inner_triangle = n_obj # ##Now we do the O (outer triangles) for atom in ntt: if atom.symbol == 'O': #print'=======================================' #print 'N Atom ',atom.index, " finding edges" n_obj+=1 model_molecule[n_obj] = Atoms() model_molecule[n_obj] += atom indices, offsets = nlist.get_neighbors(atom.index) for index,offset in zip(indices,offsets): print index, offset, ntt[index].symbol this_bond = [atom.index, index] for o in offset: this_bond.append(o) bond = tuple(this_bond) #if not bond_dict.has_key(bond): #Then if ntt[index].symbol == 'N' or ntt[index].symbol =='C': if any(o != 0 for o in offset): #If we're going over a periodic boundary, we need to negate the tag model_molecule[n_obj] += ntt[index] model_molecule[n_obj].positions[-1] = ntt.positions[index] + np.dot(offset, ntt.get_cell()) model_molecule[n_obj][-1].tag = -bond_dict[bond] else: model_molecule[n_obj] += ntt[index] model_molecule[n_obj][-1].tag = bond_dict[bond] model_molecule[n_obj].positions[-1] = ntt.positions[index] + np.dot(offset, ntt.get_cell()) # # # f = open('ntt.model','w') g = open('control-mofgen.txt','w') #Just for checking, now lets gather everything in the model_molecule dict into one big thing and print it #test_mol = Atoms() #for obj in model_molecule: # test_mol += model_molecule[obj] #write('test_model.xyz',test_mol) #print n_centers, n_model, n_obj #Headers and cell f.write('%-20s %-3d\n' %('Number of objects =',n_obj+1)) f.write('%-20s\n' %('build = systre')) f.write('%5s\n' %('Cell:')) f.write('%8.3f %8.3f %8.3f \n' % (ntt.get_cell()[0][0], ntt.get_cell()[0][1], ntt.get_cell()[0][2])) f.write('%8.3f %8.3f %8.3f \n' % (ntt.get_cell()[1][0], ntt.get_cell()[1][1], ntt.get_cell()[1][2])) f.write('%8.3f %8.3f %8.3f \n' % (ntt.get_cell()[2][0], ntt.get_cell()[2][1], ntt.get_cell()[2][2])) g.write('%-20s\n' %('model = ntt')) #Now write stuff for obj in xrange(n_centers+1): f.write('\n%-8s %-3d\n' %('Center: ', obj+1)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = rectangle')) #Yep it's a rectangle #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('center =', names[0])) for obj in xrange(n_centers+1,n_inner_triangle+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = triangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) g.write('%-9s %-50s\n' %('linker =', names[1])) for obj in xrange(n_inner_triangle+1,n_obj+1): f.write('\n%-8s %-3d\n' %('Linker: ', obj-n_centers)) f.write('%-3d\n' %(len(model_molecule[obj]))) f.write('%-20s\n' %('type = triangle')) #process positions to make it a bit more ideal for atom in model_molecule[obj]: #if atom.symbol == 'C': if atom.index != 0: model_molecule[obj].set_distance(atom.index,0,1.0,fix=1) for atom in model_molecule[obj]: (x,y,z) = atom.position #print atom.symbol, atom.position, atom.tag if atom.tag: f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % ('X', x, y, z, atom.tag)) #f.write('%-2s %15.8f %15.8f %15.8f %-4s\n' % (atom.symbol, x, y, z, atom.tag)) else: f.write('%-2s %15.8f %15.8f %15.8f\n' % ('Q', x, y, z)) #f.write('%-2s %15.8f %15.8f %15.8f\n' % (atom.symbol, x, y, z)) if(len(names)) == 3: g.write('%-9s %-50s\n' %('linker =', names[2])) else: g.write('%-9s %-50s\n' %('linker =', names[1]))
from ase.lattice.spacegroup import crystal from gpaw import GPAW, PW a = 4.0351 # Experimental lattice constant in Angstrom Ecut = 250 # Energy cut off for PW calculation k = 4 # Number of kpoints per each direction # This gives the typical NaCl structure: LiF = crystal(['Li', 'F'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) calc = GPAW(mode=PW(Ecut), xc='LDA', kpts=(k, k, k), txt='LiF_out_gs.txt') LiF.set_calculator(calc) LiF.get_potential_energy() # With the full diagonalization we calculate all the single particle states # needed for the response calculation: calc.diagonalize_full_hamiltonian(nbands=100) calc.write('LiF_fulldiag.gpw', 'all')
if __name__ == '__main__': ''' file = sys.argv[1] q_dict = {'Cu':1, 'Sn':4, 'S':-2, 'Zn':2, 'In':3, 'O':-2} str = io.read(file, format = 'vasp_out') U = get_lattice_energy(str, q_dict) Utot = np.sum(U) import pickle print Utot f = open('madelung.pckl', 'w') pickle.dump([Utot, U], f) f.close() ''' from ase.lattice.spacegroup import crystal a = 4.6 c = 2.95 str =crystal(['Ti', 'O'], basis=[(0, 0, 0), (0.3, 0.3, 0.0)], spacegroup=136, cellpar=[a, a, c, 90, 90, 90]) q_dict = {'Ti': 4, 'O':-2} U = get_lattice_energy(str, q_dict) print 'TiO2', U a = 5.64 str = crystal(['Na', 'Cl'], [(0, 0, 0), (0.5, 0.5, 0.5)], spacegroup=225, cellpar=[a, a, a, 90, 90, 90]) q_dict = {'Na': 1, 'Cl':-1} U = get_lattice_energy(str, q_dict) print 'NaCl', U
def wurtzite(species, cell_par=[2,2,6,90,90,120],repititions=[1,1,1]): system = crystal((species), basis=[(2./3.,1./3.,0),(2./3.,1./3.,5./8.)], spacegroup=186, size = repititions, cellpar=cell_par) return system
from ase.lattice.spacegroup import crystal from gpaw import GPAW from gpaw import PW from gpaw.test import equal name = 'quartz' # no. 152 - trigonal a = 5.032090 c = a * 1.0968533 p0 = (0.4778763, 0.0, 1. / 3.) p1 = (0.4153076, 0.2531340, 0.2029893) atoms = crystal(['Si', 'O'], basis=[p0, p1], spacegroup=152, cellpar=[a, a, c, 90, 90, 120]) ## with fractional translations calc = GPAW(mode=PW(), xc='LDA', kpts=(3, 3, 3), nbands=42, symmetry={'symmorphic': False}, gpts=(20, 20, 24), eigensolver='rmm-diis') atoms.set_calculator(calc) energy_fractrans = atoms.get_potential_energy() assert(len(calc.wfs.kd.ibzk_kc) == 7) assert(len(calc.wfs.kd.symmetry.op_scc) == 6)
print "n2:", n2 est_nnd = 2.5 # assume cubic packing to estimate lp from nnd, down 0.9 vpa = 0.95 * est_nnd * est_nnd * est_nnd # per cell vpc = abs(np.linalg.det(primc)) numatpc = len(elems) lp = pow(vpa * numatpc / vpc, 1 / 3.) print "initlp:", lp print "initvpa:", vpa lat0 = lp * primc mys = crystal(elems, poss, cell=lat0) mys.set_calculator(calc) epa0 = mys.get_potential_energy() / mys.get_number_of_atoms() vpa0 = mys.get_volume() / mys.get_number_of_atoms() print "epa0:", epa0 print "vpa0:", vpa0, "\n" from ase.units import kJ from ase.utils.eos import EquationOfState lestim = lat0 volumes = [] energies = [] elstr = el1 + el2 + '-' + str for x in np.linspace(0.98, 1.02, 5):