24小时热门版块排行榜    

查看: 1027  |  回复: 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的回帖
相关版块跳转 我要订阅楼主 雁儿霏霏 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[基金申请] 哪位老哥知道今年的国自然具体哪一天放榜? +9 Ldrop2023 2026-08-13 9/450 2026-08-16 13:24 by wukun_007
[基金申请] 咱们一起用铁证分析2026国家社科基金中标与否 +7 启萌科技 2026-08-12 26/1300 2026-08-16 12:35 by 启萌科技
[精细化工] 招聘 金属平磨液,抛光液研发工程师 +3 小天0311 2026-08-14 3/150 2026-08-16 07:31 by H9PLUS
[基金申请] 时间戳又变了8-15 +12 archvillain 2026-08-15 23/1150 2026-08-15 20:47 by foyo404
[基金申请] filecode=后面第一个是大写字母 +6 wangze12014 2026-08-14 7/350 2026-08-15 20:12 by gltch
[基金申请] 各位道友,我要去昆明玩几天,回来见。 +7 Tide man 2026-08-14 8/400 2026-08-15 01:11 by arzu_hma
[基金申请] 是这周出结果还是下周出结果? +4 yuleib84 2026-08-11 4/200 2026-08-14 23:05 by lfy8008
[基金申请] 奇怪,两个人的filecode固定段从头到尾一模一样 +8 布布和一二 2026-08-10 11/550 2026-08-14 14:58 by Equinoxhua
[硕博家园] 请教兼职经验 +3 是阿文鸭 2026-08-09 3/150 2026-08-14 12:07 by HER12025
[硕博家园] 读博的好处 +4 lnee 2026-08-11 4/200 2026-08-14 10:20 by ahsoarli
[基金申请] filecode +15 documentary 2026-08-10 17/850 2026-08-14 10:08 by kissu88
[基金申请] 静等基金结果 +8 gjjjzhong 2026-08-10 21/1050 2026-08-13 17:56 by 且听虎啸
[基金申请] 不应该看fileCode +7 且听虎啸 2026-08-12 9/450 2026-08-13 14:27 by flydreamws
[基金申请] 分享一下我之前已中青C的计划书的filecode +4 布布和一二 2026-08-11 5/250 2026-08-13 12:56 by cratir
[基金申请] 2019年青年基金涵评意见,大家看看几个A,几个B? +11 Tide man 2026-08-11 11/550 2026-08-13 07:35 by 撸猫猫
[基金申请] 综述论文作为代表作会不会影响评审专家的印象分? +11 yufeiwaner 2026-08-09 13/650 2026-08-12 08:17 by yufeiwaner
[基金申请] 为什么网上很多人说本周 12号出结果 +6 瞬息宇宙 2026-08-10 7/350 2026-08-11 19:25 by Tide man
[基金申请] 确定了,国自然21号放榜 +6 布布和一二 2026-08-10 7/350 2026-08-10 19:15 by 2000zf36392
[基金申请] 国自然结果 +4 Vierhys 2026-08-10 8/400 2026-08-10 15:06 by Vierhys
[基金申请] 据悉今年马上要出结果了 +7 瞬息宇宙 2026-08-10 8/400 2026-08-10 12:42 by Vivilian
信息提示
请填处理意见