24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 931  |  回复: 2

雁儿霏霏

兑换贵宾

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


[交流] 【求助】紧急求教读取CHGCAR的matlab脚本,谢谢

现在需要深入研究vasp的CHGCAR,希望用matlab读取它,但对矩阵的读取一直没查到相关资料,求教哪位有读能提供取CHGCAR的matlab小脚本,谢谢。
回复此楼

» 猜你喜欢

» 本主题相关价值贴推荐,对您同样有帮助:

» 抢金币啦!回帖就可以得到:

查看全部散金贴

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

liangab_234620

兑换贵宾

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!


★ ★
sunyang1988(金币+2): 谢谢帮助。这样直接粘贴可能有格式错误,如果方便请上传到网盘 2011-01-16 14:10:22
雁儿霏霏(金币+20): 谢谢大虾,能给提供个程序文件吗?粘贴有一些格式错误。邮箱:shangyan2009@gmail.com ,谢谢! 2011-01-16 19:37:24
% Read in CHG file to 3D matrix.

fid = fopen('CHG','r');

% Read POSCAR part of CHG file:
sysname = fgetl(fid);
lconst = fscanf(fid,'%f',1);
basisvec = fscanf(fid,'%f',[3,3])';
temp1 = fgetl(fid);
temp2 = fgetl(fid);
species = sscanf(temp2,'%i');
Natoms = sum(species);
temp3 = fgetl(fid);
atompos_f3 = fscanf(fid,'%f',[3,Natoms])';

volume = abs(dot(basisvec(1,,cross(basisvec(2,,basisvec(3,)))*lconst^3;


% Read charge density data. (i,j,k) value in i+(j+k*Ny)*Nx, with coordinate
% system defined by basis vectors!:
gridsize = fscanf(fid,'%i',3);
Nx = gridsize(1);
Ny = gridsize(2);
Nz = gridsize(3);

temp4 = fscanf(fid,'%f',[Nx*Ny*Nz,1]);

density_sub_h1_surf=reshape(temp4,Nx,Ny,Nz)/volume;

% % Magnitization (if present):
% temp5 = fscanf(fid,'%i',3);
% temp6 = fscanf(fid,'%f',[Nx*Ny*Nz,1]);
% magn_lowacc_t2_N�蕆eshape(temp6,Nx,Ny,Nz)/volume;

% minval = min(min(min(density)));
% maxval = max(max(max(density)));


% For rectangular unit cell, unit axes:
% Plot isosurface:
% prect = patch(isosurface(density,7.5), 'FaceColor', 'red', 'EdgeColor', 'none');
% isonormals(density,prect);
% %axis tight;
% camlight; lighting phong;

% Non-rectangular (general) unit cell:
% Need to created position 3D matrices
xtemp = zeros(Nx*Ny*Nz,1);
ytemp = zeros(Nx*Ny*Nz,1);
ztemp = zeros(Nx*Ny*Nz,1);

for k = 0:Nz-1
    for j = 0:Ny-1
        for i = 0:Nx-1
            xtemp(1+i+(j+k*Ny)*Nx) = i/Nx*basisvec(1,1)+j/Ny*basisvec(2,1)+k/Nz*basisvec(3,1);
            ytemp(1+i+(j+k*Ny)*Nx) = i/Nx*basisvec(1,2)+j/Ny*basisvec(2,2)+k/Nz*basisvec(3,2);
            ztemp(1+i+(j+k*Ny)*Nx) = i/Nx*basisvec(1,3)+j/Ny*basisvec(2,3)+k/Nz*basisvec(3,3);
        end
    end
end

X = reshape(xtemp,Nx,Ny,Nz)*lconst;
Y = reshape(ytemp,Nx,Ny,Nz)*lconst;
Z = reshape(ztemp,Nx,Ny,Nz)*lconst;

z = squeeze(Z(1,1,);
ave_z_h1 = squeeze(sum(sum(density_sub_h1_surf,1),2))/(Nx*Ny); %(sqrt(2)*Nx*Ny)*lconst^2;

figure
%subplot(211)
plot(z,ave_z_h1,'k')
      
% figure
% p = patch(isosurface(X,Y,Z,density,7.5), 'FaceColor', 'red', 'EdgeColor', 'none');
% isonormals(density,p);
% % maxx = max(basisvec(:,1))*lconst;
% % minx = min(basisvec(:,1))*lconst;
% % maxy = max(basisvec(:,2))*lconst;
% % miny = min(basisvec(:,2))*lconst;
% % maxz = max(basisvec(:,3))*lconst;
% % minz = min(basisvec(:,3))*lconst;
% % axis([minx maxx miny maxy minz maxz])
% camlight; lighting phong;

% Extract charge density along certain lines:

------------------------------
2楼2011-01-16 12:51:04
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

09njtpw

专家顾问

优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!优秀!!有木有!!!



小木虫(金币+0.5):给个红包,谢谢回帖
引用回帖:
1楼: Originally posted by 雁儿霏霏 at 2011-01-15 10:33:48:
现在需要深入研究vasp的CHGCAR,希望用matlab读取它,但对矩阵的读取一直没查到相关资料,求教哪位有读能提供取CHGCAR的matlab小脚本,谢谢。

不懂楼主问题解决了没有??方便传一份脚本给我么?贴的那个有点乱
3楼2011-12-30 22:59:32
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 雁儿霏霏 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 调剂申请 +7 张张张张zy 2026-03-31 7/350 2026-03-31 22:25 by piaoyi415
[考研] 0856求调剂 +9 楒桉 2026-03-28 9/450 2026-03-31 19:06 by 暮泽12
[考研] 336材料求调剂 +10 陈滢莹 2026-03-26 12/600 2026-03-31 17:59 by jp9609
[考研] 070300一志愿211,312分求调剂院校 +12 小黄鸭宝 2026-03-30 12/600 2026-03-31 17:53 by 544594351
[考研] 353求调剂 +3 江上枫_26 2026-03-28 3/150 2026-03-31 15:53 by jp9609
[考研] 调剂310 +13 温柔的晚安 2026-03-25 14/700 2026-03-31 13:03 by 记事本2026
[考研] 0817化工学硕调剂 +7 努力上岸中! 2026-03-31 7/350 2026-03-31 09:58 by nalakaiqi
[考研] 一志愿 南京航空航天大学 ,080500材料科学与工程学硕 +5 @taotao 2026-03-30 5/250 2026-03-31 09:41 by zhshch
[考研] 293分求调剂,外语为俄语 +5 加一一九 2026-03-31 5/250 2026-03-31 09:39 by zhshch
[考研] 一志愿大连理工大学材料求调剂 +6 Gymno 2026-03-30 6/300 2026-03-31 07:26 by 无际的草原
[考研] 抱歉 +4 田洪有 2026-03-30 4/200 2026-03-30 21:26 by mumin1990
[考研] 303求调剂 +7 DLkz1314. 2026-03-30 7/350 2026-03-30 21:07 by peike
[考研] 317分 一志愿南理工材料工程 本科湖工大 求调剂 +12 芋泥小铃铛 2026-03-28 12/600 2026-03-30 17:06 by wangjy2002
[考研] 085701求调剂初试286分 +5 secret0328 2026-03-28 5/250 2026-03-30 12:54 by fangnagu
[考研] 283求调剂(080500) +14 A child 2026-03-27 14/700 2026-03-30 12:06 by 探123
[考研] 340求调剂 +6 Amber00 2026-03-26 6/300 2026-03-29 12:06 by 无际的草原
[考研] 305求调剂 +8 RuiFairyrui 2026-03-28 8/400 2026-03-29 08:22 by fmesaito
[考研] 312,生物学求调剂 +3 小译同学abc 2026-03-28 3/150 2026-03-28 15:32 by 落睿可思
[考研] 一志愿上海理工能源动力(085800)310分求调剂 +3 zhangmingc 2026-03-27 4/200 2026-03-27 19:01 by 给你你注意休息
[考研] 各位老师您好:本人初试372分 +5 jj涌77 2026-03-25 6/300 2026-03-25 14:15 by mapenggao
信息提示
请填处理意见