-
Notifications
You must be signed in to change notification settings - Fork 0
/
atoms.cpp
124 lines (105 loc) · 2.55 KB
/
atoms.cpp
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
#include "atoms.h"
#include "input.h"
Atoms::Atoms()
{
}
Atoms::~Atoms()
{
}
// read the 'fractional' coordinates of atoms
// or the 'cartesian' coordinates of atoms.
void Atoms::read_pos(ifstream &ifs,bool frac)
{
assert(na>0);
string idtmp;
pos = new Vector3<double>[na];
posd = new Vector3<double>[na];
for(int i=0; i<na; ++i)
{
ifs >> idtmp;
if(frac) // fractional coordinates
{
ifs >> posd[i].x >> posd[i].y >> posd[i].z;
//cout << " pos=" << posd[i].x << " " << posd[i].y << " " << posd[i].z << endl;
// cout << ifs.good() << " " << ifs.bad() << " " << ifs.fail() << endl;
}
else // cartesian coordinates
{
ifs >> pos[i].x >> pos[i].y >> pos[i].z;
// right now only works for cartesian coordinates 2015-06-22
if(INPUT.movement_x != 0 || INPUT.movement_y !=0 || INPUT.movement_z !=0)
{
pos[i].x += INPUT.movement_x;
pos[i].y += INPUT.movement_y;
pos[i].z += INPUT.movement_z;
}
//cout << " pos=" << pos[i].x << " " << pos[i].y << " " << pos[i].z << endl;
}
if( ifs.fail() )
{
cout << " Reading atom " << i+1 << endl;
QUIT("Error in reading atom positions");
}
}
return;
}
// read the 'fractional' coordinates of atoms
// or the 'cartesian' coordinates of atoms.
void Atoms::read_pos_2(ifstream &ifs,bool frac)
{
assert(na>0);
string tmp;
pos = new Vector3<double>[na];
posd = new Vector3<double>[na];
for(int i=0; i<na; ++i)
{
if(frac)
{
ifs >> posd[i].x >> posd[i].y >> posd[i].z;
getline(ifs, tmp);
//cout << " posd=" << posd[i].x << " " << posd[i].y << " " << posd[i].z << endl;
// cout << ifs.good() << " " << ifs.bad() << " " << ifs.fail() << endl;
if( ifs.fail() )
{
cout << " Reading atom " << i+1 << endl;
QUIT("Error in reading atom positions 2");
}
}
else
{
ifs >> pos[i].x >> pos[i].y >> pos[i].z;
getline(ifs, tmp);
}
}
return;
}
void Atoms::read_pos_3(ifstream &ifs)
{
assert(na>0);
string tmp;
pos = new Vector3<double>[na];
posd = new Vector3<double>[na];
for(int i=0; i<na; ++i)
{
ifs >> id >> posd[i].x >> posd[i].y >> posd[i].z;
getline(ifs, tmp);
// cout << id << " " << posd[i].x << " " << posd[i].y << " " << posd[i].z << endl;
}
return;
}
void Atoms::read_vel(ifstream &ifs)
{
assert(na>0);
this->vel = new Vector3<double>[na];
// cout << " atom number is " << na << endl;
for(int i=0; i<na; ++i)
{
ifs >> vel[i].x >> vel[i].y >> vel[i].z;
//cout << " vel=" << vel[i].x << " " << vel[i].y << " " << vel[i].z << endl;
}
return;
}
void Atoms::clear()
{
// delete[] vel;
}