24小时热门版块排行榜    

北京石油化工学院2026年研究生招生接收调剂公告
查看: 932  |  回复: 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的回帖
相关版块跳转 我要订阅楼主 雁儿霏霏 的主题更新
普通表情 高级回复 (可上传附件)
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[电化学] 070300化学调剂 +7 山顶见α 2026-03-25 7/350 2026-03-31 22:21 by piaoyi415
[考研] 一志愿西交大080500材料学硕349 +6 jqx1258 2026-03-31 7/350 2026-03-31 21:08 by yuq
[考研] 一志愿北京科技大学085601材料工程英一数二初试总分335求调剂 +4 双马尾痞老板2 2026-03-31 4/200 2026-03-31 21:08 by Wang200018
[考研] 086000生物与医药298调剂求助 +3 元元青青 2026-03-31 5/250 2026-03-31 19:58 by vgtyfty
[考研] 0856求调剂 +9 楒桉 2026-03-28 9/450 2026-03-31 19:06 by 暮泽12
[考研] 环境工程 085701,267求调剂 +13 minht 2026-03-29 13/650 2026-03-31 17:47 by 544594351
[考研] 材料求调剂 一志愿哈工大总分298分,前三科223分 +11 dongfang59 2026-03-27 11/550 2026-03-31 16:51 by Wang200018
[考研] 322求调剂 +3 熹僖XX 2026-03-31 3/150 2026-03-31 16:32 by 记事本2026
[考研] 297 地理学070500 复试求调剂 +3 小圆圈圈ooo 2026-03-30 3/150 2026-03-30 21:05 by 余震yz
[考研] 一志愿南昌大学324求调剂 +9 hanamiko 2026-03-27 9/450 2026-03-30 20:10 by 无际的草原
[考研] 0703化学321分求调剂 +10 三dd. 2026-03-30 11/550 2026-03-30 19:24 by markhwc
[考研] 求调剂 +10 家佳佳佳佳佳 2026-03-29 10/500 2026-03-30 18:34 by 544594351
[考研] 292求调剂 +13 是妍子也是研子 2026-03-30 13/650 2026-03-30 18:01 by 小徐0109
[考研] 317分 一志愿南理工材料工程 本科湖工大 求调剂 +12 芋泥小铃铛 2026-03-28 12/600 2026-03-30 17:06 by wangjy2002
[考研] 290求调剂 +3 dfffsar 2026-03-29 3/150 2026-03-29 22:38 by 毛毛毛阿莫2
[考研] 085600,专业课化工原理,321分求调剂 +5 大馋小子 2026-03-28 5/250 2026-03-29 08:56 by qingfeng258
[考研] 283求调剂 +3 A child 2026-03-28 3/150 2026-03-28 15:41 by ms629
[考研] 308求调剂 +7 墨墨漠 2026-03-27 7/350 2026-03-28 07:43 by 热情沙漠
[考研] 考研调剂 +9 小蜡新笔 2026-03-26 9/450 2026-03-27 11:10 by 不吃魚的貓
[考研] 081200-11408-276学硕求调剂 +3 崔wj 2026-03-26 3/150 2026-03-26 19:57 by nihaoar
信息提示
请填处理意见