| 查看: 3426 | 回復: 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ā)表 | |
|---|---|---|---|---|
|
[考研] 一志愿華中科技大學071000,求調(diào)劑 +4 | 沿岸有貝殼6 2026-03-21 | 4/200 |
|
|---|---|---|---|---|
|
[考研] 生物學調(diào)劑 +4 | Surekei 2026-03-21 | 4/200 |
|
|
[考研] 材料求調(diào)劑 +5 | @taotao 2026-03-21 | 5/250 |
|
|
[考研] 302求調(diào)劑 +12 | 呼呼呼。。。。 2026-03-17 | 12/600 |
|
|
[考研] 299求調(diào)劑 +5 | shxchem 2026-03-20 | 7/350 |
|
|
[考研] 求調(diào)劑 +3 | .m.. 2026-03-21 | 4/200 |
|
|
[考研] 0805材料320求調(diào)劑 +3 | 深海物語 2026-03-20 | 3/150 |
|
|
[考研] 332求調(diào)劑 +3 | 鳳凰院丁真 2026-03-20 | 3/150 |
|
|
[考研] 一志愿天津大學化學工藝專業(yè)(081702)315分求調(diào)劑 +12 | yangfz 2026-03-17 | 12/600 |
|
|
[考研] 化學求調(diào)劑 +4 | 臨澤境llllll 2026-03-17 | 5/250 |
|
|
[考研]
|
.6lL 2026-03-18 | 8/400 |
|
|
[考研] 一志愿中南化學(0703)總分337求調(diào)劑 +8 | niko- 2026-03-19 | 9/450 |
|
|
[考研] 260求調(diào)劑 +3 | 朱芷琳 2026-03-20 | 3/150 |
|
|
[考研] 261求B區(qū)調(diào)劑,科研經(jīng)歷豐富 +3 | 牛奶很忙 2026-03-20 | 4/200 |
|
|
[考研] 材料學碩318求調(diào)劑 +5 | February_Feb 2026-03-19 | 5/250 |
|
|
[考研] 本科鄭州大學物理學院,一志愿華科070200學碩,346求調(diào)劑 +4 | 我不是一根蔥 2026-03-18 | 4/200 |
|
|
[考研] 【同濟軟件】軟件(085405)考研求調(diào)劑 +3 | 2026eternal 2026-03-18 | 3/150 |
|
|
[考研] 有沒有道鐵/土木的想調(diào)劑南林,給自己招師弟中~ +3 | TqlXswl 2026-03-16 | 7/350 |
|
|
[考研] 275求調(diào)劑 +4 | 太陽花天天開心 2026-03-16 | 4/200 |
|
|
[考研] 302求調(diào)劑 +4 | 小賈同學123 2026-03-15 | 8/400 |
|