⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 readxyz.m

📁 扫描电镜(stem)的matlab模拟程序代码
💻 M
字号:
function M=readxyz(filename)
%READXYZ Read atomic coordinates from a EJK .xyz formatted file 
%   intended for use in Earl Kirland's multislice simulation.
%   usage: M = READXYZ(FILENAME) 
%      reads the data from the ASCII textfile FILENAME.  
%      Parsing is done by str2num.
%
%   M is a structure containing:
%   M.head :  The header from the .xyz file (and all other text)
%   M.xlen :  The length of the supercell along x
%   M.ylen :  The length of the supercell along x
%   M.Znum :  n x 1 atomic numbers of the atoms
%   M.xpos :  n x 1 x-coordinates of the atoms
%   M.ypos :  n x 1 y-coordinates of the atoms
%   M.zpos :  n x 1 z-coordinates of the atoms
%   M.wt   :  n x 1 weightings of the atoms 
%   M.tds  :  n x 1 rms phonon amplitude (optional)
%   All distances are in Angstroms
%
%   Written by David Muller, 10 May 1997

% test for proper filename
if nargin<1, error('Not enough input arguments.'); end
if ~isstr(filename), error('Filename must be a string.'); end

% open the file 
fid = fopen(filename,'r');
if fid == (-1)
    error(['readtxt: Could not open file filename ']);
end

M.head = '';  

line = fgets(fid); % get the 1st line, if any...

i=1;
% read till eof
while ~isequal(line,-1)
   nline = str2num(line);
   if size(nline,2) == 5    % reading data    
      M.Znum(i)  = nline(1);
      M.xpos(i)  = nline(2);
      M.ypos(i)  = nline(3);
      M.zpos(i)  = nline(4);
      M.wt(i)    = nline(5);
      M.tds(i)   = 0;
      i = i +1;
   elseif size(nline,2) == 6    % reading data with thermal vibrations 
      M.Znum(i)  = nline(1);
      M.xpos(i)  = nline(2);
      M.ypos(i)  = nline(3);
      M.zpos(i)  = nline(4);
      M.wt(i)    = nline(5);
      M.tds(i)   = nline(6);
      i = i +1;
   elseif ~isempty(nline) & nline(1) == -1    % EOF marker
      break;
   elseif ( size(nline,2) == 2  & i == 1)  % xlen,ylen at top of file
      M.xlen = nline(1);
      M.ylen = nline(2);
   elseif ( size(nline,2) == 3  & i == 1)  % xlen,ylen at top of file
      M.xlen = nline(1);
      M.ylen = nline(2);
      M.zlen = nline(3);
   else    % store line as text header
      M.head = [ M.head ':' line];
   end
   % get next line of file
   line = fgets(fid); 
end
% close file
fclose(fid);



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -