forked from NANIMproj/NANIM_PNNL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDWN_atom.cpp
More file actions
368 lines (306 loc) · 9.58 KB
/
Copy pathDWN_atom.cpp
File metadata and controls
368 lines (306 loc) · 9.58 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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#include "stdafx.h"
#include "DWN_atom.h"
//Constructors and destructors---
atom::atom()
//Basic constructor.
{
Set_Atom_Name(DUMMY_NAME);
Zero_XYZ(atom_location);
//Default to the origin.
Set_Atom_Properties(0, 0.0, 0.0, -5.0);
/*Prevent dummy atom from having any default
spatial effects (i.e. other atoms should not
not even see dummy atom). This is best ensured by
having a large negative radius value.*/
group_tag = -1;
//Initialize group tag to -1 (not in a molecule).
}
atom::atom(const char* name, int num, double rel_mass, double charge, double radius)
{
Set_Atom_Name(name);
Zero_XYZ(atom_location);
//Default to the origin.
Set_Atom_Properties(num, rel_mass, charge, radius);
group_tag = -1;
//Initialize group tag to -1 (not in a molecule).
}
atom::atom(const char* name, const double* loc, int num,
double rel_mass, double charge, double radius)
{
Set_Atom_Specifics(name, loc);
Set_Atom_Properties(num, rel_mass, charge, radius);
group_tag = -1;
//Initialize group tag to -1 (not in a molecule).
}
atom::atom(const char* name, const double* loc, int num, double rel_mass,
double charge, double radius, int tag)
{
Set_Atom_Specifics(name, loc);
Set_Atom_Properties(num, rel_mass, charge, radius);
Set_Atom_Group_Tag(tag);
}
atom::atom(const atom& ze_atom)
{
*this = ze_atom;
}
atom::~atom()
//Destructor.
{
}
//Properties settings (non-spatial)---
void atom::Set_Atom_Specifics(const char* name, const double* loc)
{
Set_Atom_Name(name);
Set_Atom_Location(loc);
}
void atom::Set_Atom_Properties(int num, double rel_mass, double charge, double radius)
{
Set_Atom_Number(num);
Set_Atom_Rel_Mass(rel_mass);
Set_Atom_Charge(charge);
Set_Atom_Radius(radius);
}
void atom::Set_Atom_Name(const char* name)
{
strcpy(atom_name, name);
}
void atom::Set_Atom_Name(const char* name, bool only_first_capital)
//E.g. If bool = TRUEV, Name of "CG1" (.pdb) becomes "C."
{
if (only_first_capital == FALSEV)
{
Set_Atom_Name(name);
}
else
{
String_Copy_StopAt_NotInitial_Captial(atom_name, name);
}
}
void atom::Index_Atom_Name(int index)
{
Remove_Number(atom_name);
//Make sure no index is currently present.
Add_Number(atom_name, index);
}
void atom::Set_Atom_Number(int at_num)
{
atomic_number = at_num;
if (at_num >= MAX_ATOMIC_NUMBER)
//Atomic numbers must be confied to the periodic table.
{
Show_Warning("ASSIGNED ATOMIC NUMBER IS TOO LARGE!");
}
}
void atom::Set_Atom_Rel_Mass(double mass)
{
rel_atomic_mass = mass;
}
void atom::Set_Atom_Charge(double charge)
{
atomic_charge = charge;
}
void atom::Set_Atom_Radius(double radius)
{
atomic_radius = radius;
}
void atom::Set_Atom_Group_Tag(int tag)
{
group_tag = tag;
}
//Properties setting (spatial)---
void atom::Set_Atom_Location(double x, double y, double z)
{
atom_location[0] = x;
atom_location[1] = y;
atom_location[2] = z;
}
void atom::Set_Atom_Location(const double* loc)
{
Set_XYZ(atom_location, loc);
}
void atom::AddTo_Atom_Location(double del_x, double del_y, double del_z)
{
atom_location[0] += del_x;
atom_location[1] += del_y;
atom_location[2] += del_z;
}
void atom::AddTo_Atom_Location(const double* del)
{
Add_XYZ(atom_location, del);
}
void atom::SubFrom_Atom_Location(double del_x, double del_y, double del_z)
{
atom_location[0] -= del_x;
atom_location[1] -= del_y;
atom_location[2] -= del_z;
}
void atom::SubFrom_Atom_Location(const double* del)
{
Sub_XYZ(atom_location, del);
}
//Information retriveal---
void atom::Get_Atom_Name(char* ze_name) const
{
strcpy(ze_name, atom_name);
}
bool atom::Same_Name(const atom& ze_atom) const
{
return ( strcmp(atom_name, ze_atom.atom_name) == 0 );
}
int atom::Get_Atom_Number() const
{
return atomic_number;
}
double atom::Get_Atom_Rel_Mass() const
{
return rel_atomic_mass;
}
double atom::Get_Atom_Charge() const
{
return atomic_charge;
}
double atom::Get_Atom_Radius() const
{
return atomic_radius;
}
int atom::Get_Atom_Group_Tag() const
{
return group_tag;
}
void atom::Get_Atom_Location(double& x, double& y, double& z) const
{
x = atom_location[0];
y = atom_location[1];
z = atom_location[2];
}
void atom::Get_Atom_Location(double* loc) const
{
Set_XYZ(loc, atom_location);
}
//Distance logic---
double atom::Get_Distance_To_Origin() const
{
return (Get_VecMag(atom_location));
}
double atom::Get_Distance(const atom& ze_atom) const
{
double dist_val = Get_Dist(atom_location, ze_atom.atom_location);
return dist_val;
}
double atom::Get_Distance(const atom& ze_atom, int periodicity,
const double* box_size) const
{
double dist_val = Get_Dist_OrthoPBC(atom_location, ze_atom.atom_location,
periodicity, box_size);
return dist_val;
}
double atom::Get_Distance(const double* spatial_coors) const
{
double dist_val = Get_Dist(atom_location, spatial_coors);
return dist_val;
}
double atom::Get_Distance(const double* spatial_coors,
int periodicity, const double* box_size) const
{
double dist_val = Get_Dist_OrthoPBC(atom_location, spatial_coors,
periodicity, box_size);
return dist_val;
}
bool atom::Covalent_Overlap(const atom& ze_atom) const
{
double radii_sum = RADII_SCALING_FACTOR *
(atomic_radius + ze_atom.atomic_radius);
bool bond = Dist_In_Bounds(atom_location, ze_atom.atom_location, radii_sum);
return bond;
}
bool atom::Covalent_Overlap(const atom& ze_atom, int periodicity,
const double* box_size) const
{
double radii_sum = RADII_SCALING_FACTOR *
(atomic_radius + ze_atom.atomic_radius);
bool bond = Dist_In_Bounds(atom_location, ze_atom.atom_location, radii_sum,
periodicity, box_size);
return bond;
}
bool atom::Same_Molecule(const atom& ze_atom) const
{
return ( (group_tag == ze_atom.group_tag) && (group_tag != -1) );
}
//Specific identity functions---
bool atom::Is_Hydrogen() const
{
bool is_hydro = (atomic_number == 1);
return is_hydro;
}
bool atom::Is_Dummy_Atom() const
{
bool is_dummy = Name_Check(atom_name, const_cast<char*>(DUMMY_NAME));
return is_dummy;
}
bool atom::Is_Invisible(bool include_hydrogens) const
{
bool invisi = FALSEV;
if (!include_hydrogens && Is_Hydrogen())
{
invisi = TRUEV;
}
else if (Is_Dummy_Atom())
{
invisi = TRUEV;
}
return invisi;
}
//Operator overloads---
void atom::operator = (const atom& ze_atom)
{
strcpy(atom_name, ze_atom.atom_name);
Set_XYZ(atom_location, ze_atom.atom_location);
Set_Atom_Properties(ze_atom.atomic_number, ze_atom.rel_atomic_mass,
ze_atom.atomic_charge, ze_atom.atomic_radius);
Set_Atom_Group_Tag(ze_atom.group_tag);
}
bool atom::operator == (const atom& ze_atom)
//Does comparison operation by location alone!
{
bool same_location = Same_XYZ(atom_location, ze_atom.atom_location);
return same_location;
}
//Information output---
void atom::Print_Atom_Location() const
{
cout << endl << atom_name << " ";
Show_XYZ(atom_location, DIST_CONV);
}
void atom::Store_Atom_Location(ofstream& out_file) const
{
out_file << endl << atom_name << " ";
Write_XYZ(out_file, atom_location, DIST_CONV);
}
void atom::Store_Atom_Location_With_Charge(ofstream& out_file) const
{
out_file << endl << atom_name << " ";
Write_XYZ(out_file, atom_location, DIST_CONV);
out_file << " " << atomic_charge;
}
void atom::Store_Atom_Location_With_CoreShell(ofstream& out_file) const
{
out_file << endl << atom_name << " core ";
Write_XYZ(out_file, atom_location, DIST_CONV);
out_file << endl << atom_name << " shel ";
Write_XYZ(out_file, atom_location, DIST_CONV);
}
void atom::Store_Atom_Info(ofstream& Wfile) const
{
Wfile << endl << atom_name << " ";
Write_XYZ(Wfile, atom_location, 1.0);
Wfile << " " << atomic_number << " " << rel_atomic_mass
<< " " << atomic_charge << " " << atomic_radius
<< " " << group_tag;
}
void atom::Load_Atom_Info(ifstream& Rfile)
{
Rfile >> atom_name;
Read_XYZ(Rfile, atom_location, 1.0);
Rfile >> atomic_number >> rel_atomic_mass >> atomic_charge
>> atomic_radius >> group_tag;
}