How do I import a .itp file from molecular dynamics simulation

조회 수: 1 (최근 30일)
I have been trying to import a .itp file from molecular dynamics simulation but the format specifications seems not work.
Below is the sample code I a have been trying to utilize.
close all; clear all; clc;
filename = 'Input correct filename';
path = 'Input correct Path';
a = [path '/' filename];
readstartrow = 16; % start reading after row 16
fileID = fopen(a);
format = '%d%5s%5d%5s%5s%5d%8.2f%8.4f%8s%8.4f%*[^ ;]'; % Format specs for the
All = textscan(fileID,format, 100,'Delimiter','','WhiteSpace', '', 'EmptyValue' ,NaN,'HeaderLines', readstartrow,'ReturnOnError', false);
fclose(fileID)
I have attached a screenshot of how the file appears

채택된 답변

Anthony Owusu-Mensah
Anthony Owusu-Mensah 2020년 2월 17일
편집: Anthony Owusu-Mensah 2020년 2월 24일
Path = 'Type in the correct path'
filename = 'Input the correct filename'
fileloc =[Path '/' filename];
fileID = fopen(fileloc); %openFile for reading
readstartrow = 16; %skip the first 16 rows
natoms = 134; % number of atoms in POPC file
format = '%10d%15s%8d%8s%8s%8d%8.2f%8.3f%10s%4.4f%*[^\n]';
AllColumns = textscan(fileID, format, natoms, 'Delimiter', '',...
WhiteSpace', '', 'EmptyValue' ,NaN,'HeaderLines', readstartrow, 'ReturnOnError', false); %Reads all columns of POPC.itp file
fclose(fileID);
charge = AllColumns{7}; %Returns all charges

추가 답변 (1개)

Walter Roberson
Walter Roberson 2020년 2월 22일
>> celldisp(textscan('; qtot', '%8s'))
ans{1}{1} =
;
ans{1}{2} =
qtot
When you use %s without a width, scanning stops at the first whitespace or delimiter.
When you use %s with a width, scanning stops at the first whitespace or delimiter, or the width, whichever happens first.
You cannot use %s with or without a width to read exactly a certain number of characters.
You can use %c with a width to read exactly that many characters (partial reads at the end of input are discarded though.)

카테고리

Help CenterFile Exchange에서 Biological Physics에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by