| 查看: 3430 | 回復(fù): 10 | ||
[求助]
求救,如何將xyz格式的文件轉(zhuǎn)化為可以讓lammps讀的data文件,求大神,感激不盡 。 已有2人參與
|
||
如題/ |
鐵桿木蟲 (正式寫手)
|
僅僅.xyz轉(zhuǎn)過去是不完整的(見下),還有bond, angle, dihedral的定義。 xyz2lmp.m -------------- function xyz2lmp(f_xyz) % This script converts .xyz file to lammps data file. % Input: % f_xyz: name of the input .xyz file. % Example: % xyz2lmp('PdAu.xyz') % NOTE: The second line must be in specified format as: % PdAu xlo xhi ylo yhi zlo zhi % Poweed by Xianbao Duan % Email: xianbao.d@gmail.com % Website: http://www.52souji.net/ % open the .xyz file fidin = fopen(f_xyz,'r'); if fidin == -1 error('Failed to open the file. Please check!'); end % number of all the atoms atom_num_a = fscanf(fidin,'%d'); % comment comment = textscan(fidin,'%s %f %f %f %f %f %f',1); xlo = comment{2}; xhi= comment{3}; ylo = comment{4}; yhi= comment{5}; zlo = comment{6}; zhi= comment{7}; % coordinates of the atoms atoms = textscan(fidin,'%s %f %f %f',atom_num_a); fclose(fidin); % initialize type_name = atoms{1}(1); % names of types atom_num(1) = 1; % atom number of each type % sort the atoms according to their types for i = 2: length(atoms{1}) flag = 0; for j = 1:length(type_name) if strcmp(atoms{1}(i),type_name(j)) == 1 atom_num(j) = atom_num(j) + 1; flag = 1; break; end end if flag == 0 type_name(end+1) = atoms{1}(i); atom_num(end+1) = 1; end end type_num = length(type_name); % write the lammps file outfilename = strrep(f_xyz,'.xyz','.lmp'); fidout = fopen(outfilename, 'w'); new_comment = ['Converted from .xyz to .lmp @ ',datestr(now) ]; fprintf(fidout,'%s\n\n',new_comment); fprintf(fidout,'%d \t %s\n',atom_num_a,'atoms'); fprintf(fidout,'%d \t %s\n',type_num,'atom types'); fprintf(fidout,'%f %f \t%s\n',xlo,xhi,'xlo xhi'); fprintf(fidout,'%f %f \t%s\n',ylo,yhi,'ylo yhi'); fprintf(fidout,'%f %f \t%s\n\n',zlo,zhi,'zlo zhi'); fprintf(fidout,'%s\n\n','Atoms'); % the data for i = 1:length(atoms{1}) for j = 1:type_num if strcmp(atoms{1}(i),type_name(j)) == 1 fprintf(fidout,'%d \t %d \t %f \t %f \t %f \n',... i,j,atoms{2}(i),atoms{3}(i),atoms{4}(i)); break; end end end fclose(fidout); |
木蟲 (正式寫手)
至尊木蟲 (著名寫手)
鐵桿木蟲 (正式寫手)
鐵桿木蟲 (正式寫手)
|
為什么不自己建: units metal boundary p p p atom_style molecular lattice custom 2.4595 a1 1 0 0 a2 0 1.73203 0 a3 0.0 0.0 10 basis 0 0 0 basis 0.5 0.16666666666666666 0 basis 0.5 0.5 0 basis 0 0.6666666666666666 0 region box block 0 80 0 120 -0.5 0.5 create_box 1 box create_atoms 1 box region coldest block INF INF 0 1.5 INF INF region hottest block INF INF 60 61.5 INF INF mass 1 12 pair_style tersoff pair_coeff * * SiC_1994.tersoff C |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|
|
[考研] 317求調(diào)劑 +12 | 申子申申 2026-03-19 | 18/900 |
|
|---|---|---|---|---|
|
[考研] 298求調(diào)劑 +6 | 上岸6666@ 2026-03-20 | 6/300 |
|
|
[考研] 291 求調(diào)劑 +3 | 化工2026屆畢業(yè)?/a> 2026-03-21 | 3/150 |
|
|
[考研] 303求調(diào)劑 +5 | 安憶靈 2026-03-22 | 6/300 |
|
|
[考研] 生物學(xué)一志愿985,分?jǐn)?shù)349求調(diào)劑 +4 | zxts12 2026-03-21 | 7/350 |
|
|
[考研] 297求調(diào)劑 +11 | 戲精丹丹丹 2026-03-17 | 12/600 |
|
|
[考研] 336求調(diào)劑 +5 | rmc8866 2026-03-21 | 5/250 |
|
|
[考研] 求調(diào)劑 +3 | .m.. 2026-03-21 | 4/200 |
|
|
[考研] 070300化學(xué)319求調(diào)劑 +7 | 錦鯉0909 2026-03-17 | 7/350 |
|
|
[考研] 一志愿中國石油大學(xué)(華東) 本科齊魯工業(yè)大學(xué) +3 | 石能偉 2026-03-17 | 3/150 |
|
|
[考研] 324分 085600材料化工求調(diào)劑 +4 | llllkkkhh 2026-03-18 | 4/200 |
|
|
[考研] 一志愿華中科技大學(xué),080502,354分求調(diào)劑 +5 | 守候夕陽CF 2026-03-18 | 5/250 |
|
|
[考研] 304求調(diào)劑 +7 | 司空. 2026-03-18 | 7/350 |
|
|
[考研] 材料學(xué)碩297已過四六級求調(diào)劑推薦 +11 | adaie 2026-03-19 | 11/550 |
|
|
[考研] 281求調(diào)劑(0805) +14 | 煙汐憶海 2026-03-16 | 25/1250 |
|
|
[考研] 招收調(diào)劑碩士 +4 | lidianxing 2026-03-19 | 12/600 |
|
|
[考研] 286求調(diào)劑 +6 | lemonzzn 2026-03-16 | 10/500 |
|
|
[考研] 一志愿福大288有機(jī)化學(xué),求調(diào)劑 +3 | 小木蟲200408204 2026-03-18 | 3/150 |
|
|
[考研] 085600材料與化工求調(diào)劑 +6 | 緒幸與子 2026-03-17 | 6/300 |
|
|
[考研] 一志愿南京大學(xué),080500材料科學(xué)與工程,調(diào)劑 +4 | Jy? 2026-03-16 | 4/200 |
|