This repository has been archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
LammpsStrWrite.m
147 lines (120 loc) · 3.45 KB
/
LammpsStrWrite.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
function LammpsStrWrite(data,name_output)
%% Description
%
% *Command*:
% LammpsStrWrite(data,name_output);
%
% *Input*:
% data is the structure generated by LammpsStrGenerate.
% name_output is the name of .data file that you will write.
%% Setting Variables
desc_data = [
data.num_atoms
0
0
0
0
data.num_atom_types
0
0
0
0
];
try % Detecting whether bonds information are contained in data.
desc_data(2) = [data.num_bonds];
desc_data(7) = [data.num_bond_types];
end
try % Detecting whether angles information are contained in data.
desc_data(3) = [data.num_angles];
desc_data(8) = [data.num_angle_types];
end
desc_name = [
"atoms"
"bonds"
"angles"
"dihedrals"
"impropers"
"atom types"
"bond types"
"angle types"
"dihedral types"
"improper types"
];
num_desc = length(desc_data);
fidout = fopen(name_output, 'w');
%% File Date
col_first = ['Lammps file creat at ',datestr(now),'\n\n'];
fprintf(fidout,col_first);
%% File Information
for desc = 1:num_desc
fprintf(fidout,"%-6d\t%s\n",desc_data(desc),desc_name(desc));
end
fprintf(fidout,'%f %f \t%s\n',data.box_size(1,1),data.box_size(1,2),'xlo xhi');
fprintf(fidout,'%f %f \t%s\n',data.box_size(2,1),data.box_size(2,2),'ylo yhi');
fprintf(fidout,'%f %f \t%s\n\n',data.box_size(3,1),data.box_size(3,2),'zlo zhi');
try
fprintf(fidout,'%f\t%f\t%f \t%s\n',data.box_tilt(1),data.box_tilt(2),data.box_tilt(3),'xy xz yz');
end
try
fprintf(fidout,'\n\nMasses\n\n');
for type = 1 : data.num_atom_types
fprintf(fidout,'%i\t%f # %s\n',type,data.atom_mass(type),data.atom_name(type));
end
end
%% Parameters
try
data.para.pair_coeff;
fprintf(fidout,'\n\nPair Coeffs\n\n');
for atom = 1 : data.num_atom_types
fprintf(fidout,'%i\t%f\t%f\n',atom,data.para.pair_coeff(atom,1),data.para.pair_coeff(atom,2));
end
end
try
data.para.bond_coeff;
fprintf(fidout,'\n\nBond Coeffs\n\n');
for bond = 1 : data.num_bond_types
fprintf(fidout,'%i\t%f\t%f\n',bond,data.para.bond_coeff(bond,1),data.para.bond_coeff(bond,2));
end
end
try
data.para.angle_coeff;
fprintf(fidout,'\n\nAngle Coeffs\n\n');
for angle = 1 : data.num_bond_types
fprintf(fidout,'%i\t%f\t%f\n',angle,data.para.angle_coeff(angle,1),data.para.angle_coeff(angle,2));
end
end
%% Atoms Information
fprintf(fidout,'\n\nAtoms # %s\n',data.atom_style);
for atom = 1 : data.num_atoms
fprintf(fidout,'\n%-5d %-5d %-5d %-8.4f %-10f %-10f %-10f',...
data.data_atom(atom,1),data.data_atom(atom,2),data.data_atom(atom,3),...
data.data_atom(atom,4),data.data_atom(atom,5),data.data_atom(atom,6),data.data_atom(atom,7));
end
%% Bonds Information
try
data.data_bond;
flag = 1;
catch
flag = 0;
end
if flag == 1
fprintf(fidout,'\n\nBonds\n\n');
for bond = 1 : data.num_bonds
fprintf(fidout,'%i\t%i\t%i\t%i\n',data.data_bond(bond,1),data.data_bond(bond,2),...
data.data_bond(bond,3),data.data_bond(bond,4));
end
end
%% Angle Information
try
data.data_angle;
flag = 1;
catch
flag = 0;
end
if flag == 1
fprintf(fidout,'\n\nAngles\n\n');
for angle = 1 : data.num_angles
fprintf(fidout,'%i\t%i\t%i\t%i\t%i\n',data.data_angle(angle,1),data.data_angle(angle,2),...
data.data_angle(angle,3),data.data_angle(angle,4),data.data_angle(angle,5));
end
end