-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcellLAMMPS.cpp
More file actions
190 lines (149 loc) · 4.54 KB
/
cellLAMMPS.cpp
File metadata and controls
190 lines (149 loc) · 4.54 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#include "cellFile.h"
#include "input.h"
#include "gfun.h"
bool CellFile::CheckGeometry_LAMMPS( Cell &cel )
{
TITLE("CellFile","CheckGeometry_LAMMPS");
const int ntype = INPUT.ntype;
// (1) open the file.
stringstream ss;
ss << INPUT.geo_directory;
ss << cel.file_name;
ifstream ifs(ss.str().c_str());
if(!ifs) return false;
else return true;
}
bool CellFile::ReadGeometry_LAMMPS( Cell &cel )
{
TITLE("CellFile","ReadGeometry_LAMMPS");
const int ntype = INPUT.ntype;
cout << "BE CAREFUL !!!!!!!!! ONLY WORK FOR ONE ELEMENT NOW." << endl;
// (1) open the file.
stringstream ss;
ss << INPUT.geo_directory << "/";
ss << cel.file_name;
cout << " ReadGeometry : " << ss.str() << endl;
ifstream ifs(ss.str().c_str());
if(!ifs) return false;
// many files does not exist, so we don't print
// every file's name.
cout << " File name is " << ss.str() << endl;
cel.atom = new Atoms[ntype];
getline(ifs, cel.system_name);
cout << " Name is " << cel.system_name << endl;
cel.nat = 0;
for(int it=0; it<ntype; ++it)
{
READ_VALUE(ifs, cel.atom[it].na);
cel.nat+=cel.atom[it].na;
cout << " Element : " << cel.atom[it].id << " Atom Number : " << cel.atom[it].na << endl;
}
cout << " Total atom number is " << cel.nat << endl;
int tmp_ntype = 0;
READ_VALUE(ifs, tmp_ntype);
// (2) read in cell
double x0, x1;
double y0, y1;
double z0, z1;
double xy=0.00; // mohan add 2015-06-15
double xz=0.00;
double yz=0.00;
ifs >> x0;
READ_VALUE(ifs, x1);
ifs >> y0;
READ_VALUE(ifs, y1);
ifs >> z0;
READ_VALUE(ifs, z1);
// mohan add 2015-06-15
if( INPUT.triclinic == 1 )
{
ifs >> xy >> xz;
READ_VALUE(ifs, yz);
}
cel.a1.x = x1-x0; cel.a1.y = 0.00; cel.a1.z = 0.00;
cel.a2.x = xy; cel.a2.y = y1-y0; cel.a2.z = 0.00;
cel.a3.x = xz; cel.a3.y = yz; cel.a3.z = z1-z0;
cout << " Cell: " << endl;
cout << " " << cel.a1.x << " " << cel.a1.y << " " << cel.a1.z << endl;
cout << " " << cel.a2.x << " " << cel.a2.y << " " << cel.a2.z << endl;
cout << " " << cel.a3.x << " " << cel.a3.y << " " << cel.a3.z << endl;
// (3) calculate the volume of the cell.
cel.volume = cel.a1.x*cel.a2.y*cel.a3.z + cel.a1.y*cel.a2.z*cel.a3.x + cel.a1.z*cel.a2.x*cel.a3.y -
cel.a1.x*cel.a2.z*cel.a3.y - cel.a1.y*cel.a2.x*cel.a3.z - cel.a1.z*cel.a2.y*cel.a3.x;
cout << " volume of the cell is " << cel.volume << " (Angstrom^3)" << endl;
// (4) read in atom species and the pseudopotential file.
for(int it=0; it<ntype; ++it)
{
stringstream ss;
ss << "ELE" << it+1;
cel.atom[it].id = ss.str();
}
string tmp_name;
READ_VALUE(ifs, tmp_name);
for(int it=0; it<ntype; ++it)
{
cel.atom[it].pos = new Vector3<double>[cel.atom[it].na];
cel.atom[it].posd = new Vector3<double>[cel.atom[it].na];
}
cout << " This is Cartesian coordinates" << endl;
bool frac = false;
int atom_index;
int type_index;
for(int ia=0; ia<cel.nat; ++ia)
{
ifs >> atom_index >> type_index;
--atom_index; // because this starts from 1
--type_index; // because this starts from 1
cout << "ia=" << ia << " atom_index=" << atom_index << " type_index=" << type_index << endl;
ifs >> cel.atom[type_index].pos[atom_index].x
>> cel.atom[type_index].pos[atom_index].y
>> cel.atom[type_index].pos[atom_index].z;
cel.cartesian2direct(type_index, atom_index);
}
return true;
}
void CellFile::WriteGeometry_LAMMPS( Cell &cel )
{
TITLE("CellFile","WriteGeometry_LAMMPS");
ofstream ofs(INPUT.geo_out.c_str());
ofs << setprecision(16);
ofs << "COMMENT" << endl;
ofs << endl;
ofs << cel.nat << " atoms" << endl;
ofs << endl;
ofs << INPUT.ntype << " atom types" << endl;
ofs << endl;
ofs << "0 " << cel.a1.x << " xlo xhi" << endl;
ofs << "0 " << cel.a2.y << " ylo yhi" << endl;
ofs << "0 " << cel.a3.z << " zlo zhi" << endl;
// mohan add 2015-06-15
if( INPUT.triclinic == 1 )
{
ofs << cel.a2.x << " " << cel.a3.x << " " << cel.a3.y << " xy xz yz" << endl;
}
assert(cel.a1.y == 0.0);
assert(cel.a1.z == 0.0);
assert(cel.a2.z == 0.0);
ofs << endl;
ofs << "Atoms" << endl;
ofs << endl;
bool frac = true;
int ia2=0;
for(int it=0; it<INPUT.ntype; ++it)
{
cout << " printing geometry for type " << it+1 << endl;
cout << " there are " << cel.atom[it].na << " atoms for thie type of atom" << endl;
for(int ia=0; ia<cel.atom[it].na; ++ia)
{
cel.direct2cartesian(it, ia);
//ofs << ia2+1 << " " << it+1
ofs << ia2+1 << " " << "change_me" // mohan update 2015-06-15
<< " " << cel.atom[it].pos[ia].x
<< " " << cel.atom[it].pos[ia].y
<< " " << cel.atom[it].pos[ia].z << endl;
++ia2;
}
}
ofs.close();
return;
}