def generate_shell(structs,fnames,center_atom,radius,shell=None,vacuum=15): for struct,fname in zip(structs,fnames): center_coord=struct[center_atom].coords if shell is None: sites=struct.get_neighbors_in_shell(center_coord,0,radius) file_name="sphere_"+fname+".vasp" else: sites=struct.get_neighbors_in_shell(center_coord,radius,shell) file_name="shell_"+fname+".vasp" coords=[site[0].coords for site in sites] species=[site[0].specie for site in sites] mol=Molecule(coords=coords,species=species) max_dist=np.max(mol.distance_matrix) a=b=c=max_dist+vacuum box_struct=mol.get_boxed_structure(a,b,c) box_struct.to(filename=file_name,fmt='poscar')
[-0.513360, 0.889165, -0.363000]] mol = Molecule(["C", "H", "H", "H", "H"], coords) print("mol:", mol) print("\n") print("mol[0]:", mol[0]) print("mol[1]:", mol[1]) print("\n") #断连index为0和1两个原子之间的化学键,有上面的输出可以看到这两个位c和H,但是很奇怪为何会出现如下的结果?可能与空间结构有关系? for frag in mol.break_bond(0, 1): print("frag:", frag) print("\n") print("neighbors of mol[0]:", mol.get_neighbors(mol[0], 3)) #得到分子中的共价键 print("covalent_bonds of:", mol.get_covalent_bonds()) print("\n") #Creates a Structure from a Molecule by putting the Molecule in #the center of a orthorhombic box. Useful for creating Structure #for calculating molecules using periodic codes. #通过把分子放在正交晶(orthorhombic)的盒子box里,从分子Molecule生存结构Structure。 #创建结构Structure,用于通过周期代码计算分子。 structure = mol.get_boxed_structure(10, 10, 10) print("structure:", structure) #xyz format是用来表示分子几何结构的文件,需要定分子中原子的坐标。 from pymatgen.io.xyz import XYZ xyz = XYZ(mol) xyz.write_file("methane.xyz")
#scaling fator ,default 1.0 factor=1.0 all_sts={} for i in atom_range: print('---------'+str(i)+'-----------------') sts=[] #numatom atoms numIons=[i] while True: try: st=gen_cluster(system,numIons,sg=None,dimension=0,factor=1.0) if st is not None: opted=opt(st) if opted is not None: mol=Molecule(opted.species,opted.cart_coords) a=max(mol.cart_coords[:,0])-min(mol.cart_coords[:,0]) b=max(mol.cart_coords[:,1])-min(mol.cart_coords[:,1]) c=max(mol.cart_coords[:,2])-min(mol.cart_coords[:,2]) opted=mol.get_boxed_structure(a+vac,b+vac,c+vac) min_dist=(np.eye(len(opted))*1000+opted.distance_matrix).min() if min_dist <2.0: continue opted.to('poscar','init_clusters/N-'+str(i)+'-sg-'+str(len(sts))+'.vasp') sts.append({'origin':st,'opted':opted}) except: pass if len(sts)>=sg_numb: break all_sts[i]=sts dumpfn(all_sts,'all.json',indent=4)
all_sts = {} for i in atom_range: print('---------' + str(i) + '-----------------') sts = [] # for j in range(sg_numb): #numatom atoms numIons = [i] while True: try: st = gen_cluster(system, numIons, sg=None, dimension=0, factor=1.0) if st is not None: opted = opt(st) if opted is not None: mol = Molecule(opted.species, opted.cart_coords) a = b = c = np.max(mol.distance_matrix) + 10 opted = mol.get_boxed_structure(a, b, c) opted.to( 'poscar', 'structs/N-' + str(i) + '-sg-' + str(len(sts)) + '.vasp') sts.append({'origin': st, 'opted': opted}) except Exception as e: traceback.print_exc() info = traceback.format_exc() print(info) if len(sts) >= sg_numb: break all_sts[i] = sts dumpfn(all_sts, 'all.json', indent=4)