-
Notifications
You must be signed in to change notification settings - Fork 1
/
mdstate.cpp
102 lines (83 loc) · 3.08 KB
/
mdstate.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
#include "mdstate.h"
#include <iostream>
// double color_list[7][3] = {{1,1,1},{230.0/255,230.0/255,0},{0,0,1},{1.0,1.0,1.0},{1,0,0},{9.0/255,92.0/255,0},{95.0/255,216.0/255,250.0/255}};
MDState::MDState(QObject *parent) :
QObject(parent),
m_showWater(1)
{
colorMap.insert("Si", QColor(230,230,0));
sizeMap.insert("Si",QVector2D(1.11, 1.11));
colorMap.insert("A", QColor(0,0,255));
sizeMap.insert("A",QVector2D(0.66, 0.66));
colorMap.insert("H", QColor(255,255,255));
sizeMap.insert("H",QVector2D(0.35, 0.35));
colorMap.insert("O", QColor(255,0,0));
sizeMap.insert("O",QVector2D(0.66, 0.66));
colorMap.insert("Na", QColor(9,92,0));
sizeMap.insert("Na",QVector2D(1.86, 1.86));
colorMap.insert("Cl", QColor(95,216,250));
sizeMap.insert("Cl",QVector2D(1.02, 1.02));
colorMap.insert("N", QColor(95,216,250));
sizeMap.insert("N",QVector2D(0.66, 0.66));
colorMap.insert("C", QColor(95,75,85));
sizeMap.insert("C",QVector2D(0.66, 0.66));
}
MDState::~MDState() {
}
int MDState::numberOfAtoms() {
int sum = 0;
for(DataBundle* bundle : m_dataBundles) {
sum += bundle->positions().count();
}
return sum;
}
void MDState::addAtom(QVector3D positions, char *atomType, bool addPeriodicCopy, QVector3D systemSize) {
if(strcmp(atomType,"Na") == 0 || strcmp(atomType,"Cl") == 0) return;
if(!m_atomTypeToDataBundle.contains(atomType)) {
DataBundle *bundle = new DataBundle();
m_dataBundles.append(bundle);
if(!(strcmp(atomType, "H") == 0 || strcmp(atomType, "O") == 0)) {
m_dataBundlesNoWater.append(bundle);
}
m_atomTypeToDataBundle.insert(atomType,bundle);
qDebug() << atomType;
qDebug() << colorMap.value(atomType);
bundle->setColor(colorMap.value(atomType, QColor(255, 255, 255, 255)));
bundle->setSystemSize(systemSize);
bundle->setSize(sizeMap.value(atomType, QVector2D(0.1, 0.1)));
}
DataBundle* bundle = m_atomTypeToDataBundle.value(atomType);
Q_ASSERT(bundle);
bundle->positions().append(positions);
if(addPeriodicCopy) {
for(int i=-1; i<=1; i++) {
for(int j=-1; j<=1; j++) {
for(int k=-1; k<=1; k++) {
if(i== 0 && j==0 && k==0) continue;
QVector3D positionCopy = positions + QVector3D(i,j,k)*systemSize;
addAtom(positionCopy, atomType);
}
}
}
}
}
void MDState::addAtoms(QArray<QVector3D> positions, QArray<char *>atomTypes, bool addPeriodicCopy, QVector3D systemSize) {
// Increase length of all arrays
// reserveMemory(getNumberOfAtoms() + positions.size());
for(int i=0; i<positions.size(); i++) {
addAtom(positions.at(i), atomTypes.at(i), addPeriodicCopy, systemSize);
}
}
void MDState::buildVertexBundle() {
for(DataBundle *bundle : m_dataBundles) {
bundle->generateVertexBundle();
}
}
QArray<DataBundle*> *MDState::dataBundles()
{
if(m_showWater) {
return &m_dataBundles;
} else {
return &m_dataBundlesNoWater;
}
}