24小时热门版块排行榜    

查看: 1015  |  回复: 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的回帖
相关版块跳转 我要订阅楼主 雁儿霏霏 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[找工作] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 Vi50GxzrFcSG 2026-08-07 4/200 2026-08-08 10:39 by 3OOjAIS77qg2
[硕博家园] 售SCI-T0P文章,我:8O.5.5.1.O.54,科目齐全,可+急 +3 Vi50GxzrFcSG 2026-08-07 6/300 2026-08-08 10:19 by 3OOjAIS77qg2
[教师之家] 售SCI一区T0P文章,我:8.O.55.1.O54,科目全,可伽急 +3 HEQlVqMTIA7d 2026-08-07 4/200 2026-08-08 08:27 by 6vVgjDL4CnGu
[基金申请] 娱乐 +6 Tide man 2026-08-03 6/300 2026-08-07 22:40 by 铁帽子农民
[基金申请] 关于代码变化问题,想知道的进来 +9 且听虎啸 2026-08-07 12/600 2026-08-07 21:53 by 理想三旬2025
[基金申请] 固定端突然变了,今天 +6 archvillain 2026-08-06 10/500 2026-08-07 16:03 by 医学老男孩
[基金申请] 听说今天filecode变了 +24 布布和一二 2026-08-06 47/2350 2026-08-07 16:02 by zhiyanjiang
[基金申请] filecode与中标关系的预测 +3 布布和一二 2026-08-07 3/150 2026-08-07 15:09 by gltch
[基金申请] filecode变化情况 +6 布布和一二 2026-08-07 22/1100 2026-08-07 14:45 by 且听虎啸
[基金申请] 大家散了吧,后缀研究没有意义,别浪费时间了,过好目前的每一天,不要焦虑 +5 Tide man 2026-08-06 7/350 2026-08-07 13:11 by 医学老男孩
[基金申请] 关于豆爷回答的JTJC与%2F数量 +4 yang182083 2026-08-06 6/300 2026-08-07 12:43 by 虫友是什么虫
[基金申请] filecode +14 等待解的谜 2026-08-06 19/950 2026-08-07 12:20 by wlwhappy
[基金申请] filecode +8 布布和一二 2026-08-06 11/550 2026-08-06 20:41 by tangpu318
[基金申请] 影响面上的因素 +8 布布和一二 2026-08-05 11/550 2026-08-06 10:41 by 宝贝虫子
[基金申请] 好消息?这个有何含义??? +8 Tide man 2026-08-05 10/500 2026-08-05 16:14 by xmuxiaoyu
[考博] 【2027博士申请】纳米药物递送方向 20+3 13586093586 2026-08-03 4/200 2026-08-05 09:59 by lfy8008
[基金申请] 有没有H口的?有收到消息的吗? +3 超级海虾 2026-08-04 3/150 2026-08-04 17:26 by 学教育滴
[基金申请] 纯娱乐,不喜欢勿喷 +7 Tide man 2026-08-04 10/500 2026-08-04 15:10 by loufangrui
[基金申请] 面上提前没消息,有中的吗 +14 archvillain 2026-08-02 18/900 2026-08-04 14:42 by archvillain
[基金申请] 什么时候能放榜呀? +3 Jacob678 2026-08-03 3/150 2026-08-03 16:14 by gltch
信息提示
请填处理意见