-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_ndx.m
120 lines (84 loc) · 2.34 KB
/
make_ndx.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function make_ndx(pdbFileName,sysOnly)
pdb = parsePDBfile(pdbFileName);
groups = cell(1,1);
indices = cell(1,1);
groups{1} = 'System';
indices{1} = [];
for ipdb =1:pdb.number
grpIdx = 1;
indices{grpIdx} = [indices{grpIdx}; pdb.serial(ipdb)];
if ~sysOnly
for igroup = 2:numel(groups)
if strcmp(groups{igroup}, pdb.resName{ipdb})
grpIdx = igroup;
break;
end
end
if grpIdx==1
grpIdx = numel(groups)+1;
groups{grpIdx} = { pdb.resName{ipdb}};
indices{grpIdx} = {[]};
end
indices{grpIdx} = [indices{grpIdx}; pdb.serial(ipdb)];
end
end
outfilename = [pdbFileName(1:end-4),'.ndx'];
fileID = fopen(outfilename,'w');
for ii=1:numel(groups)
indices{ii} = sort(unique(indices{ii}));
groupStr = ['\n[ ',groups{ii}, ' ]\n'];
%disp(groupStr);
fprintf(fileID,groupStr);
for iline =1:10:numel(indices{ii})
line = '';
for jj = 1:10
if iline+jj-1 > numel(indices{ii})
break;
end
line = [line, num2str(indices{ii}(iline+jj-1)),' '];
end
line = [line,'\n'];
%disp(line);
fprintf(fileID,line);
end
end
end
%{
function make_ndx(particles,uniqueResidueList,pdbID,pdb_number)
groups = cell(numel(uniqueResidueList) + 1,1);
indices = cell(numel(uniqueResidueList) + 1,1);
groups{1} = 'System';
indices{1} = [];
for itype = 1:numel(particle)
indices{1} = [indices{1}; particles{itype}.members];
end
for ii =1:numel(uniqueResidueList)
groups{ii+1} = uniqueResidueList{ii};
indices{ii+1} = [];
for itype = 1:numel(particle)
if strcmp(uniqueResidueList{ii},particles{itype}.resName)
newIndices = pdbID(particles{itype}.members);
newIndices(newIndices>pdb_number) = [];
indices{ii+1} = [indices{ii+1}; newIndices];
end
end
end
fileID = fopen(outfilename,'w');
for ii=1:numel(groups)
indices{ii} = sort(unique(indices{ii}));
groupStr = ['\n[ ',groups{ii}, ' ]\n'];
fprintf(fileID,groupStr);
line = '';
for iline =1:10:numel(indices{ii})
for jj = 1:10
if iline+jj-1 > numel(indices{ii})
break;
end
line = [line, num2str(indices{ii}(iline+jj-1)),' '];
end
line = [line,'\n'];
fprintf(fileID,line);
end
end
end
%}