-
Notifications
You must be signed in to change notification settings - Fork 0
/
Atomic.cpp
126 lines (86 loc) · 2.28 KB
/
Atomic.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
//
// Atomic.cpp
// OpenGL
//
// Created by Andrew Diggs on 8/31/22.
//
#include "Atomic.hpp"
#include "FileIO.hpp"
int num_atoms;
Atom::Atom()
: m_coords(AMD::Vec3()), m_neighbors(nullptr), m_type(0), m_rad(0.0), m_num_neighbors(0)
{}
Atom::Atom(std::string line)
:m_num_neighbors(0)
{
// LAMMPS dump looks like At.num At.type x y z
std::stringstream ss;
float x, y, z;
ss << line;
ss >> m_num >> m_type >> x >> y >> z;
m_coords = AMD::Vec3(x*dx - 0.5*dx ,y*dy - 0.5*dy,z*dz - 0.5*dz);
}
Atom::~Atom() {
//free(m_neighbors);
}
AMD::Vec3 Atom::get_coords(){
return m_coords;
}
Bond::Bond()
:m_len(0.0)
{
m_vec = m_end - m_start;
}
Bond::Bond(Atom A, Atom B)
{
m_start = A.get_coords();
m_end = B.get_coords();
m_vec = m_end - m_start;
set_len();
set_angles();
}
Bond::~Bond() {}
void Bond::set_len(){
m_len = m_vec.len();
}
void Bond::set_angles(){
float Pi_2 = 1.5707963;
angle.x = Pi_2 - AMD::Get_angle(m_vec, AMD::Vec3(1.0, 0.0, 0.0));
angle.y = Pi_2 - AMD::Get_angle(m_vec, AMD::Vec3(0.0, 1.0, 0.0));
angle.z = Pi_2 - AMD::Get_angle(m_vec, AMD::Vec3(0.0, 0.0, 1.0));
return;
}
Atom* atoms(std::string file){
std::ifstream infile (file);
std::string line;
std::string item_type;
std::string item;
std::stringstream ss, ss2;
std::string temp;
std::string temp2;
num_atoms = 0;
Atom* local_atoms = nullptr;
if (infile.is_open()) {
while (getline(infile,line)) {
if (ITEM(line, "ITEM:")){
ss << line;
ss >> item >> item_type;
if (ITEM(item_type, "NUMBER")){
getline(infile, line);
num_atoms = atoi(line.c_str());
local_atoms = (Atom*)malloc(num_atoms*sizeof(Atom));
continue;
}
else if (ITEM(item_type, "ATOMS")){
for (int i = 0; i<num_atoms; i++){
getline(infile,line);
local_atoms[i] = Atom(line);
}
}
ss.str(std::string());
ss.clear();
}
}
}
return local_atoms;
}